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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Dec 18 10:37:28 CST 2013


Author: kmoore
Date: Wed Dec 18 10:37:21 2013
New Revision: 404197

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=404197
Log:
Handle multiple Path headers

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_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=404197&r1=404196&r2=404197
==============================================================================
--- team/kmoore/pjsip_path_support/include/asterisk/res_pjsip.h (original)
+++ team/kmoore/pjsip_path_support/include/asterisk/res_pjsip.h Wed Dec 18 10:37:21 2013
@@ -895,7 +895,7 @@
  * \retval 0 success
  */
 int ast_sip_location_add_contact(struct ast_sip_aor *aor, const char *uri,
-	struct timeval expiration_time, pj_str_t *path_info);
+	struct timeval expiration_time, const char *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=404197&r1=404196&r2=404197
==============================================================================
--- team/kmoore/pjsip_path_support/res/res_pjsip/location.c (original)
+++ team/kmoore/pjsip_path_support/res/res_pjsip/location.c Wed Dec 18 10:37:21 2013
@@ -177,7 +177,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, pj_str_t *path_info)
+int ast_sip_location_add_contact(struct ast_sip_aor *aor, const char *uri, struct timeval expiration_time, const char *path_info)
 {
 	char name[AST_UUID_STR_LEN];
 	RAII_VAR(struct ast_sip_contact *, contact, NULL, ao2_cleanup);
@@ -193,7 +193,7 @@
 	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);
+		ast_string_field_set(contact, path, path_info);
 	}
 
 	if (!ast_strlen_zero(aor->outbound_proxy)) {

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=404197&r1=404196&r2=404197
==============================================================================
--- team/kmoore/pjsip_path_support/res/res_pjsip_registrar.c (original)
+++ team/kmoore/pjsip_path_support/res/res_pjsip_registrar.c Wed Dec 18 10:37:21 2013
@@ -349,7 +349,29 @@
 
 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)
+static int build_path_data(struct rx_task_data *task_data, struct ast_str **path_str)
+{
+	pjsip_generic_string_hdr *path_hdr = pjsip_msg_find_hdr_by_name(task_data->rdata->msg_info.msg, &path_hdr_name, NULL);
+
+	if (!path_hdr) {
+		return 0;
+	}
+
+	*path_str = ast_str_create(64);
+	if (!path_str) {
+		return -1;
+	}
+
+	ast_str_set(path_str, 0, "%.*s", (int)path_hdr->hvalue.slen, path_hdr->hvalue.ptr);
+
+	while ((path_hdr = (pjsip_generic_string_hdr *) pjsip_msg_find_hdr_by_name(task_data->rdata->msg_info.msg, &path_hdr_name, path_hdr->next))) {
+		ast_str_append(path_str, 0, ",%.*s", (int)path_hdr->hvalue.slen, path_hdr->hvalue.ptr);
+	}
+
+	return 0;
+}
+
+static int registrar_validate_path(struct rx_task_data *task_data, struct ast_str **path_str)
 {
 	const pj_str_t path_supported_name = { "path", 4 };
 	pjsip_supported_hdr *supported_hdr;
@@ -359,8 +381,11 @@
 		return 0;
 	}
 
-	*path_hdr = pjsip_msg_find_hdr_by_name(task_data->rdata->msg_info.msg, &path_hdr_name, NULL);
-	if (!*path_hdr) {
+	if (build_path_data(task_data, path_str)) {
+		return -1;
+	}
+
+	if (!*path_str) {
 		return 0;
 	}
 
@@ -391,7 +416,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;
+	RAII_VAR(struct ast_str *, path_str, NULL, ast_free);
 
 	/* Retrieve the current contacts, we'll need to know whether to update or not */
 	contacts = ast_sip_location_retrieve_aor_contacts(task_data->aor);
@@ -408,7 +433,7 @@
 		return PJ_TRUE;
 	}
 
-	if (registrar_validate_path(task_data, &path_hdr)) {
+	if (registrar_validate_path(task_data, &path_str)) {
 		/* 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",
@@ -460,7 +485,7 @@
 			}
 
 			ast_sip_location_add_contact(task_data->aor, contact_uri, ast_tvadd(ast_tvnow(),
-				ast_samp2tv(expiration, 1)), (path_hdr ? &path_hdr->hvalue : NULL));
+				ast_samp2tv(expiration, 1)), path_str ? ast_str_buffer(path_str) : NULL);
 			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",
@@ -475,8 +500,8 @@
 			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);
+			if (path_str) {
+				ast_string_field_set(updated, path, ast_str_buffer(path_str));
 			}
 
 			ast_sip_location_update_contact(updated);




More information about the asterisk-commits mailing list