From: Igor Goncharovsky Date: Fri, 4 Nov 2022 10:11:07 +0000 (+0600) Subject: res_pjsip: Fix path usage in case dialing with '@' X-Git-Tag: 18.17.0-rc1~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=997a2d70b9b95d32f01d79f4555d48931c2d4003;p=thirdparty%2Fasterisk.git 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 --- diff --git a/res/res_pjsip_path.c b/res/res_pjsip_path.c index 5272a5c424..9492ef1697 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; } - - 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)) { + if (ast_strlen_zero(contact->aor)) { return NULL; } - return ast_sip_location_retrieve_aor(aor_name); + return ast_sip_location_retrieve_aor(contact->aor); } /*! @@ -173,7 +118,7 @@ static void path_outgoing_request(struct ast_sip_endpoint *endpoint, struct ast_ return; } - aor = find_aor(endpoint, tdata->msg->line.req.uri); + aor = find_aor(contact); if (!aor || !aor->support_path) { return; } @@ -205,7 +150,6 @@ static void path_outgoing_response(struct ast_sip_endpoint *endpoint, struct ast 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 @@ static void path_outgoing_response(struct ast_sip_endpoint *endpoint, struct ast 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;