[asterisk-commits] kmoore: branch kmoore/pjsip_path_support r403701 - /team/kmoore/pjsip_path_su...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Dec 12 07:29:06 CST 2013


Author: kmoore
Date: Thu Dec 12 07:29:02 2013
New Revision: 403701

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=403701
Log:
Address Matt's comments

Modified:
    team/kmoore/pjsip_path_support/res/res_pjsip.c
    team/kmoore/pjsip_path_support/res/res_pjsip_path.c
    team/kmoore/pjsip_path_support/res/res_pjsip_registrar.c

Modified: team/kmoore/pjsip_path_support/res/res_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/pjsip_path_support/res/res_pjsip.c?view=diff&rev=403701&r1=403700&r2=403701
==============================================================================
--- team/kmoore/pjsip_path_support/res/res_pjsip.c (original)
+++ team/kmoore/pjsip_path_support/res/res_pjsip.c Thu Dec 12 07:29:02 2013
@@ -1730,10 +1730,11 @@
 	return pj_stristr(&method, message_method) ? PJ_TRUE : PJ_FALSE;
 }
 
+/*! \brief Structure to hold information about an outbound request */
 struct send_request_data {
-	struct ast_sip_endpoint *endpoint;
-	void *token;
-	void (*callback)(void *token, pjsip_event *e);
+	struct ast_sip_endpoint *endpoint;		/*! The endpoint associated with this request */
+	void *token;					/*! Information to be provided to the callback upon receipt of a response */
+	void (*callback)(void *token, pjsip_event *e);	/*! The callback to be called upon receipt of a response */
 };
 
 static void send_request_data_destroy(void *obj)
@@ -1790,7 +1791,11 @@
 	void *token, void (*callback)(void *token, pjsip_event *e))
 {
 	struct ast_sip_supplement *supplement;
-	RAII_VAR(struct send_request_data *, req_data, send_request_data_alloc(endpoint, token, callback), ao2_cleanup);
+	struct send_request_data *req_data = send_request_data_alloc(endpoint, token, callback);
+
+	if (!req_data) {
+		return -1;
+	}
 
 	AST_RWLIST_RDLOCK(&supplements);
 	AST_LIST_TRAVERSE(&supplements, supplement, next) {
@@ -1800,13 +1805,12 @@
 	}
 	AST_RWLIST_UNLOCK(&supplements);
 
-	ao2_ref(req_data, +1);
 	if (pjsip_endpt_send_request(ast_sip_get_pjsip_endpoint(), tdata, -1, req_data, send_request_cb) != PJ_SUCCESS) {
 		ast_log(LOG_ERROR, "Error attempting to send outbound %.*s request to endpoint %s\n",
 				(int) pj_strlen(&tdata->msg->line.req.method.name),
 				pj_strbuf(&tdata->msg->line.req.method.name),
 				ast_sorcery_object_get_id(endpoint));
-		ao2_ref(req_data, -1);
+		ao2_cleanup(req_data);
 		return -1;
 	}
 

Modified: team/kmoore/pjsip_path_support/res/res_pjsip_path.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/pjsip_path_support/res/res_pjsip_path.c?view=diff&rev=403701&r1=403700&r2=403701
==============================================================================
--- team/kmoore/pjsip_path_support/res/res_pjsip_path.c (original)
+++ team/kmoore/pjsip_path_support/res/res_pjsip_path.c Thu Dec 12 07:29:02 2013
@@ -40,36 +40,41 @@
 {
 	char *configured_aors, *aor_name;
 	pjsip_sip_uri *sip_uri;
-	char user_name[64], domain_name[64];
+	char *domain_name;
+	RAII_VAR(struct ast_str *, id, NULL, ast_free);
 
 	if (ast_strlen_zero(endpoint->aors)) {
 		return NULL;
 	}
 
 	sip_uri = pjsip_uri_get_uri(uri);
-	ast_copy_pj_str(user_name, &sip_uri->user, sizeof(user_name));
-	ast_copy_pj_str(domain_name, &sip_uri->host, sizeof(domain_name));
+	domain_name = ast_alloca(sip_uri->host.slen + 1);
+	ast_copy_pj_str(domain_name, &sip_uri->host, sip_uri->host.slen + 1);
 
 	configured_aors = ast_strdupa(endpoint->aors);
 
 	/* Iterate the configured AORs to see if the user or the user+domain match */
 	while ((aor_name = strsep(&configured_aors, ","))) {
-		char id[AST_UUID_STR_LEN];
-		RAII_VAR(struct ast_sip_domain_alias *, alias, NULL, ao2_cleanup);
-
-		snprintf(id, sizeof(id), "%s@%s", user_name, domain_name);
-		if (!strcmp(aor_name, id)) {
+		struct ast_sip_domain_alias *alias = NULL;
+
+		if (!pj_strcmp2(&sip_uri->user, aor_name)) {
 			break;
 		}
 
+		if (!id && !(id = ast_str_create(sip_uri->user.slen + sip_uri->host.slen + 2))) {
+			return NULL;
+		}
+
+		ast_str_set(&id, 0, "%.*s@", (int)sip_uri->user.slen, sip_uri->user.ptr);
 		if ((alias = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "domain_alias", domain_name))) {
-			snprintf(id, sizeof(id), "%s@%s", user_name, alias->domain);
-			if (!strcmp(aor_name, id)) {
-				break;
-			}
-		}
-
-		if (!strcmp(aor_name, user_name)) {
+			ast_str_append(&id, 0, "%s", alias->domain);
+			ao2_cleanup(alias);
+		} else {
+			ast_str_append(&id, 0, "%s", domain_name);
+		}
+
+		if (!strcmp(aor_name, ast_str_buffer(id))) {
+			ast_free(id);
 			break;
 		}
 	}
@@ -77,7 +82,7 @@
 	if (ast_strlen_zero(aor_name)) {
 		return NULL;
 	}
-	
+
 	return ast_sip_location_retrieve_aor(aor_name);
 }
 
@@ -112,7 +117,7 @@
 		return -1;
 	}
 
-	contact = ao2_callback_data(contacts, OBJ_UNLINK, find_contact, pjsip_uri_get_uri(contact_uri), pool);
+	contact = ao2_callback_data(contacts, 0, find_contact, pjsip_uri_get_uri(contact_uri), pool);
 	if (!contact) {
 		return -1;
 	}
@@ -207,7 +212,9 @@
 	pjsip_cseq_hdr *cseq = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CSEQ, NULL);
 	const pj_str_t REGISTER_METHOD = {"REGISTER", 8};
 
-	if (!endpoint) {
+	if (!endpoint
+		|| !pj_stristr(&REGISTER_METHOD, &cseq->method.name)
+		|| !PJSIP_IS_STATUS_IN_CLASS(status.code, 200)) {
 		return;
 	}
 
@@ -217,27 +224,17 @@
 	}
 
 	aor = find_aor(endpoint, contact_hdr->uri);
-	if (!aor || !aor->support_path) {
-		return;
-	}
-
-	if (add_supported(tdata)) {
-		return;
-	}
-
-	if (pj_stristr(&REGISTER_METHOD, &cseq->method.name) && status.code == 200) {
-		if (path_get_string(tdata->pool, aor, contact_hdr->uri, &path_dup)) {
-			return;
-		}
-
-		path_hdr = pjsip_generic_string_hdr_create(tdata->pool, &path_name, &path_dup);
-		if (!path_hdr) {
-			return;
-		}
-
-		pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)path_hdr);
-	}
-
+	if (!aor || !aor->support_path || add_supported(tdata)
+		|| path_get_string(tdata->pool, aor, contact_hdr->uri, &path_dup)) {
+		return;
+	}
+
+	path_hdr = pjsip_generic_string_hdr_create(tdata->pool, &path_name, &path_dup);
+	if (!path_hdr) {
+		return;
+	}
+
+	pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)path_hdr);
 }
 
 static void path_session_outgoing_response(struct ast_sip_session *session, pjsip_tx_data *tdata)
@@ -282,4 +279,4 @@
 		.load = load_module,
 		.unload = unload_module,
 		.load_pri = AST_MODPRI_APP_DEPEND,
-	       );
+);

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=403701&r1=403700&r2=403701
==============================================================================
--- team/kmoore/pjsip_path_support/res/res_pjsip_registrar.c (original)
+++ team/kmoore/pjsip_path_support/res/res_pjsip_registrar.c Thu Dec 12 07:29:02 2013
@@ -541,8 +541,9 @@
 		 ast_pjsip_rdata_get_endpoint(rdata), ao2_cleanup);
 	RAII_VAR(struct ast_sip_aor *, aor, NULL, ao2_cleanup);
 	pjsip_sip_uri *uri;
-	char user_name[64], domain_name[64];
+	char *domain_name;
 	char *configured_aors, *aor_name;
+	RAII_VAR(struct ast_str *, id, NULL, ast_free);
 
 	if (pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, &pjsip_register_method) || !endpoint) {
 		return PJ_FALSE;
@@ -564,29 +565,33 @@
 	}
 
 	uri = pjsip_uri_get_uri(rdata->msg_info.to->uri);
-	ast_copy_pj_str(user_name, &uri->user, sizeof(user_name));
-	ast_copy_pj_str(domain_name, &uri->host, sizeof(domain_name));
+	domain_name = ast_alloca(uri->host.slen + 1);
+	ast_copy_pj_str(domain_name, &uri->host, uri->host.slen + 1);
 
 	configured_aors = ast_strdupa(endpoint->aors);
 
 	/* Iterate the configured AORs to see if the user or the user+domain match */
 	while ((aor_name = strsep(&configured_aors, ","))) {
-		char id[AST_UUID_STR_LEN];
-		RAII_VAR(struct ast_sip_domain_alias *, alias, NULL, ao2_cleanup);
-
-		snprintf(id, sizeof(id), "%s@%s", user_name, domain_name);
-		if (!strcmp(aor_name, id)) {
+		struct ast_sip_domain_alias *alias = NULL;
+
+		if (!pj_strcmp2(&uri->user, aor_name)) {
 			break;
 		}
 
+		if (!id && !(id = ast_str_create(uri->user.slen + uri->host.slen + 2))) {
+			return PJ_TRUE;
+		}
+
+		ast_str_set(&id, 0, "%.*s@", (int)uri->user.slen, uri->user.ptr);
 		if ((alias = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "domain_alias", domain_name))) {
-			snprintf(id, sizeof(id), "%s@%s", user_name, alias->domain);
-			if (!strcmp(aor_name, id)) {
-				break;
-			}
-		}
-
-		if (!strcmp(aor_name, user_name)) {
+			ast_str_append(&id, 0, "%s", alias->domain);
+			ao2_cleanup(alias);
+		} else {
+			ast_str_append(&id, 0, "%s", domain_name);
+		}
+
+		if (!strcmp(aor_name, ast_str_buffer(id))) {
+			ast_free(id);
 			break;
 		}
 	}
@@ -595,7 +600,7 @@
 		/* The provided AOR name was not found (be it within the configuration or sorcery itself) */
 		pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 404, NULL, NULL, NULL);
 		ast_sip_report_req_no_support(endpoint, rdata, "registrar_requested_aor_not_found");
-		ast_log(LOG_WARNING, "AOR '%s' not found for endpoint '%s'\n", user_name, ast_sorcery_object_get_id(endpoint));
+		ast_log(LOG_WARNING, "AOR '%.*s' not found for endpoint '%s'\n", (int)uri->user.slen, uri->user.ptr, ast_sorcery_object_get_id(endpoint));
 		return PJ_TRUE;
 	}
 




More information about the asterisk-commits mailing list