[Asterisk-code-review] res_pjsip: Fix path usage in case dialing with '@' (asterisk[20])

George Joseph asteriskteam at digium.com
Tue Dec 20 08:52:50 CST 2022


George Joseph has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/19692 )

Change subject: res_pjsip: Fix path usage in case dialing with '@'
......................................................................

res_pjsip: Fix path usage in case dialing with '@'

Fix aor lookup on sip path addition. Issue happens in case of dialing
with @ and overriding user part of RURI.

ASTERISK-30100 #close
Reported-by: Yury Kirsanov

Change-Id: I3f2c42a583578c94397b113e32ca3ebf2d600e13
---
M res/res_pjsip_path.c
1 file changed, 23 insertions(+), 69 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit
  N A: Looks good to me, but someone else must approve




diff --git a/res/res_pjsip_path.c b/res/res_pjsip_path.c
index 5272a5c..9492ef1 100644
--- a/res/res_pjsip_path.c
+++ b/res/res_pjsip_path.c
@@ -36,71 +36,16 @@
 static const pj_str_t PATH_NAME = { "Path", 4 };
 static pj_str_t PATH_SUPPORTED_NAME = { "path", 4 };
 
-static struct ast_sip_aor *find_aor(struct ast_sip_endpoint *endpoint, pjsip_uri *uri)
+static struct ast_sip_aor *find_aor(struct ast_sip_contact *contact)
 {
-	char *configured_aors, *aor_name;
-	const pj_str_t *uri_username;
-	const pj_str_t *uri_hostname;
-	char *domain_name;
-	char *username;
-	struct ast_str *id = NULL;
-
-	if (ast_strlen_zero(endpoint->aors)) {
+	if (!contact) {
+		return NULL;
+	}
+	if (ast_strlen_zero(contact->aor)) {
 		return NULL;
 	}
 
-	uri_hostname = ast_sip_pjsip_uri_get_hostname(uri);
-	domain_name = ast_alloca(uri_hostname->slen + 1);
-	ast_copy_pj_str(domain_name, uri_hostname, uri_hostname->slen + 1);
-
-	uri_username = ast_sip_pjsip_uri_get_username(uri);
-	username = ast_alloca(uri_username->slen + 1);
-	ast_copy_pj_str(username, uri_username, uri_username->slen + 1);
-
-	/*
-	 * We may want to match without any user options getting
-	 * in the way.
-	 */
-	AST_SIP_USER_OPTIONS_TRUNCATE_CHECK(username);
-
-	configured_aors = ast_strdupa(endpoint->aors);
-
-	/* Iterate the configured AORs to see if the user or the user+domain match */
-	while ((aor_name = ast_strip(strsep(&configured_aors, ",")))) {
-		struct ast_sip_domain_alias *alias = NULL;
-
-		if (ast_strlen_zero(aor_name)) {
-			continue;
-		}
-
-		if (!strcmp(username, aor_name)) {
-			break;
-		}
-
-		if (!id && !(id = ast_str_create(strlen(username) + uri_hostname->slen + 2))) {
-			aor_name = NULL;
-			break;
-		}
-
-		ast_str_set(&id, 0, "%s@", username);
-		if ((alias = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "domain_alias", domain_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))) {
-			break;
-		}
-	}
-	ast_free(id);
-
-	if (ast_strlen_zero(aor_name)) {
-		return NULL;
-	}
-
-	return ast_sip_location_retrieve_aor(aor_name);
+	return ast_sip_location_retrieve_aor(contact->aor);
 }
 
 /*!
@@ -173,7 +118,7 @@
 		return;
 	}
 
-	aor = find_aor(endpoint, tdata->msg->line.req.uri);
+	aor = find_aor(contact);
 	if (!aor || !aor->support_path) {
 		return;
 	}
@@ -205,7 +150,6 @@
 	struct pjsip_status_line status = tdata->msg->line.status;
 	pj_str_t path_dup;
 	pjsip_generic_string_hdr *path_hdr;
-	pjsip_contact_hdr *contact_hdr;
 	RAII_VAR(struct ast_sip_aor *, aor, NULL, ao2_cleanup);
 	pjsip_cseq_hdr *cseq = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CSEQ, NULL);
 	const pj_str_t REGISTER_METHOD = {"REGISTER", 8};
@@ -216,12 +160,7 @@
 		return;
 	}
 
-	contact_hdr = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL);
-	if (!contact_hdr) {
-		return;
-	}
-
-	aor = find_aor(endpoint, contact_hdr->uri);
+	aor = find_aor(contact);
 	if (!aor || !aor->support_path || add_supported(tdata)
 		|| path_get_string(tdata->pool, contact, &path_dup)) {
 		return;

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/19692
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 20
Gerrit-Change-Id: I3f2c42a583578c94397b113e32ca3ebf2d600e13
Gerrit-Change-Number: 19692
Gerrit-PatchSet: 2
Gerrit-Owner: Igor Goncharovsky <igor.goncharovsky at gmail.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: N A <asterisk at phreaknet.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20221220/3ab2d6ae/attachment.html>


More information about the asterisk-code-review mailing list