[asterisk-commits] kmoore: branch kmoore/pjsip_path_support r403158 - in /team/kmoore/pjsip_path...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Nov 26 13:05:20 CST 2013


Author: kmoore
Date: Tue Nov 26 13:05:18 2013
New Revision: 403158

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=403158
Log:
Move path storage to the contact and support_path to the AoR

Modified:
    team/kmoore/pjsip_path_support/include/asterisk/res_pjsip.h
    team/kmoore/pjsip_path_support/res/res_pjsip/location.c
    team/kmoore/pjsip_path_support/res/res_pjsip/pjsip_configuration.c
    team/kmoore/pjsip_path_support/res/res_pjsip_registrar.c

Modified: team/kmoore/pjsip_path_support/include/asterisk/res_pjsip.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/pjsip_path_support/include/asterisk/res_pjsip.h?view=diff&rev=403158&r1=403157&r2=403158
==============================================================================
--- team/kmoore/pjsip_path_support/include/asterisk/res_pjsip.h (original)
+++ team/kmoore/pjsip_path_support/include/asterisk/res_pjsip.h Tue Nov 26 13:05:18 2013
@@ -144,6 +144,8 @@
 	AST_DECLARE_STRING_FIELDS(
 		/*! Full URI of the contact */
 		AST_STRING_FIELD(uri);
+		/*! Path information to place in Route headers */
+		AST_STRING_FIELD(path);
 	);
 	/*! Absolute time that this contact is no longer valid after */
 	struct timeval expiration_time;
@@ -216,6 +218,8 @@
 	unsigned int remove_existing;
 	/*! Any permanent configured contacts */
 	struct ao2_container *permanent_contacts;
+	/*! Determines whether SIP Path headers are supported */
+	unsigned int support_path;
 };
 
 /*!
@@ -541,8 +545,6 @@
 		AST_STRING_FIELD(fromuser);
 		/*! Domain to place in From header */
 		AST_STRING_FIELD(fromdomain);
-		/*! Path information to place in the Route header */
-		AST_STRING_FIELD(path);
 	);
 	/*! Configuration for extensions */
 	struct ast_sip_endpoint_extensions extensions;
@@ -576,8 +578,6 @@
 	unsigned int faxdetect;
 	/*! Determines if transfers (using REFER) are allowed by this endpoint */
 	unsigned int allowtransfer;
-	/*! Determines whether SIP Path headers are supported */
-	unsigned int support_path;
 };
 
 /*!
@@ -919,11 +919,13 @@
  * \param aor Pointer to the AOR
  * \param uri Full contact URI
  * \param expiration_time Optional expiration time of the contact
+ * \param path_info Path information
  *
  * \retval -1 failure
  * \retval 0 success
  */
-int ast_sip_location_add_contact(struct ast_sip_aor *aor, const char *uri, struct timeval expiration_time);
+int ast_sip_location_add_contact(struct ast_sip_aor *aor, const char *uri,
+	struct timeval expiration_time, pj_str_t *path_info);
 
 /*!
  * \brief Update a contact

Modified: team/kmoore/pjsip_path_support/res/res_pjsip/location.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/pjsip_path_support/res/res_pjsip/location.c?view=diff&rev=403158&r1=403157&r2=403158
==============================================================================
--- team/kmoore/pjsip_path_support/res/res_pjsip/location.c (original)
+++ team/kmoore/pjsip_path_support/res/res_pjsip/location.c Tue Nov 26 13:05:18 2013
@@ -222,7 +222,7 @@
 	return ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "contact", contact_name);
 }
 
-int ast_sip_location_add_contact(struct ast_sip_aor *aor, const char *uri, struct timeval expiration_time)
+int ast_sip_location_add_contact(struct ast_sip_aor *aor, const char *uri, struct timeval expiration_time, pj_str_t *path_info)
 {
 	char name[AST_UUID_STR_LEN];
 	RAII_VAR(struct ast_sip_contact *, contact, NULL, ao2_cleanup);
@@ -237,6 +237,9 @@
 	contact->expiration_time = expiration_time;
 	contact->qualify_frequency = aor->qualify_frequency;
 	contact->authenticate_qualify = aor->authenticate_qualify;
+	if (path_info && aor->support_path) {
+		ast_string_field_build(contact, path, "%.*s", (int)path_info->slen, path_info->ptr);
+	}
 
 	return ast_sorcery_create(ast_sip_get_sorcery(), contact);
 }
@@ -444,6 +447,7 @@
 	ast_sorcery_object_field_register(sorcery, "aor", "remove_existing", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_aor, remove_existing));
 	ast_sorcery_object_field_register_custom(sorcery, "aor", "contact", "", permanent_uri_handler, NULL, 0, 0);
 	ast_sorcery_object_field_register(sorcery, "aor", "mailboxes", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_aor, mailboxes));
+	ast_sorcery_object_field_register(sorcery, "aor", "support_path", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_aor, support_path));
 
 	ast_sip_register_endpoint_formatter(&endpoint_aor_formatter);
 	return 0;

Modified: team/kmoore/pjsip_path_support/res/res_pjsip/pjsip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/pjsip_path_support/res/res_pjsip/pjsip_configuration.c?view=diff&rev=403158&r1=403157&r2=403158
==============================================================================
--- team/kmoore/pjsip_path_support/res/res_pjsip/pjsip_configuration.c (original)
+++ team/kmoore/pjsip_path_support/res/res_pjsip/pjsip_configuration.c Tue Nov 26 13:05:18 2013
@@ -1353,7 +1353,6 @@
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "dtls_ca_path", "", dtls_handler, dtlscapath_to_str, 0, 0);
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "dtls_setup", "", dtls_handler, dtlssetup_to_str, 0, 0);
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "srtp_tag_32", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, media.rtp.srtp_tag_32));
-	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "support_path", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, support_path));
 
 	if (ast_sip_initialize_sorcery_transport(sip_sorcery)) {
 		ast_log(LOG_ERROR, "Failed to register SIP transport support with sorcery\n");

Modified: team/kmoore/pjsip_path_support/res/res_pjsip_registrar.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/pjsip_path_support/res/res_pjsip_registrar.c?view=diff&rev=403158&r1=403157&r2=403158
==============================================================================
--- team/kmoore/pjsip_path_support/res/res_pjsip_registrar.c (original)
+++ team/kmoore/pjsip_path_support/res/res_pjsip_registrar.c Tue Nov 26 13:05:18 2013
@@ -347,20 +347,37 @@
 	return task_data;
 }
 
-static void update_path_data(struct rx_task_data *task_data)
-{
-	const pj_str_t path_name = { "Path", 4 };
-	pjsip_generic_string_hdr *hdr;
-
-	if (!task_data->endpoint->support_path) {
-		return;
-	}
-
-	if (!(hdr = pjsip_msg_find_hdr_by_name(task_data->rdata->msg_info.msg, &path_name, NULL))) {
-		return;
-	}
-
-	ast_string_field_build(task_data->endpoint, path, "%.*s", (int)hdr->hvalue.slen, hdr->hvalue.ptr);
+static const pj_str_t path_hdr_name = { "Path", 4 };
+
+static int registrar_validate_path(struct rx_task_data *task_data, pjsip_generic_string_hdr **path_hdr)
+{
+	const pj_str_t path_supported_name = { "path", 4 };
+	pjsip_supported_hdr *supported_hdr;
+	int i;
+
+	if (!task_data->aor->support_path) {
+		return 0;
+	}
+
+	*path_hdr = pjsip_msg_find_hdr_by_name(task_data->rdata->msg_info.msg, &path_hdr_name, NULL);
+	if (!*path_hdr) {
+		return 0;
+	}
+
+	supported_hdr = pjsip_msg_find_hdr(task_data->rdata->msg_info.msg, PJSIP_H_SUPPORTED, NULL);
+	if (!supported_hdr) {
+		return -1;
+	}
+
+	/* Find advertised path support */
+	for (i = 0; i < supported_hdr->count; i++) {
+		if (!pj_stricmp(&supported_hdr->values[i], &path_supported_name)) {
+			return 0;
+		}
+	}
+
+	/* Path header present, but support not advertised */
+	return -1;
 }
 
 static int rx_task(void *data)
@@ -374,6 +391,7 @@
 	pjsip_tx_data *tdata;
 	pjsip_response_addr addr;
 	const char *aor_name = ast_sorcery_object_get_id(task_data->aor);
+	pjsip_generic_string_hdr *path_hdr = NULL;
 
 	/* Retrieve the current contacts, we'll need to know whether to update or not */
 	contacts = ast_sip_location_retrieve_aor_contacts(task_data->aor);
@@ -386,6 +404,14 @@
 		pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), task_data->rdata, 400, NULL, NULL, NULL);
 		ast_sip_report_failed_acl(task_data->endpoint, task_data->rdata, "registrar_invalid_contacts_provided");
 		ast_log(LOG_WARNING, "Failed to validate contacts in REGISTER request from '%s'\n",
+				ast_sorcery_object_get_id(task_data->endpoint));
+		return PJ_TRUE;
+	}
+
+	if (registrar_validate_path(task_data, &path_hdr)) {
+		/* Ensure that intervening proxies did not make invalid modifications to the request */
+		pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), task_data->rdata, 420, NULL, NULL, NULL);
+		ast_log(LOG_WARNING, "Invalid modifications made to REGISTER request from '%s' by intervening proxy\n",
 				ast_sorcery_object_get_id(task_data->endpoint));
 		return PJ_TRUE;
 	}
@@ -433,7 +459,8 @@
 				continue;
 			}
 
-			ast_sip_location_add_contact(task_data->aor, contact_uri, ast_tvadd(ast_tvnow(), ast_samp2tv(expiration, 1)));
+			ast_sip_location_add_contact(task_data->aor, contact_uri, ast_tvadd(ast_tvnow(),
+				ast_samp2tv(expiration, 1)), &path_hdr->hvalue);
 			ast_verb(3, "Added contact '%s' to AOR '%s' with expiration of %d seconds\n",
 				contact_uri, aor_name, expiration);
 			ast_test_suite_event_notify("AOR_CONTACT_ADDED",
@@ -448,6 +475,9 @@
 			updated->expiration_time = ast_tvadd(ast_tvnow(), ast_samp2tv(expiration, 1));
 			updated->qualify_frequency = task_data->aor->qualify_frequency;
 			updated->authenticate_qualify = task_data->aor->authenticate_qualify;
+			if (path_hdr) {
+				ast_string_field_build(updated, path, "%.*s", (int)path_hdr->hvalue.slen, path_hdr->hvalue.ptr);
+			}
 
 			ast_sip_location_update_contact(updated);
 			ast_debug(3, "Refreshed contact '%s' on AOR '%s' with new expiration of %d seconds\n",
@@ -479,9 +509,6 @@
 		ao2_callback(contacts, OBJ_NODATA | OBJ_MULTIPLE, registrar_delete_contact, NULL);
 	}
 
-	/* Process Path information */
-	update_path_data(task_data);
-
 	/* Update the contacts as things will probably have changed */
 	ao2_cleanup(contacts);
 	contacts = ast_sip_location_retrieve_aor_contacts(task_data->aor);




More information about the asterisk-commits mailing list