From 7144c739e97aca9e69b2067238deeedeafbc478f Mon Sep 17 00:00:00 2001 From: Joshua Colp Date: Fri, 17 Oct 2014 11:30:23 +0000 Subject: res_pjsip: Add 'user_eq_phone' option to add a 'user=phone' parameter when applicable. This change adds a configuration option which adds a 'user=phone' parameter if the user portion of the request URI or the From URI is determined to be a number. Review: https://reviewboard.asterisk.org/r/4073/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@425804 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- res/res_pjsip.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'res/res_pjsip.c') diff --git a/res/res_pjsip.c b/res/res_pjsip.c index 69feabafb..354c43d07 100644 --- a/res/res_pjsip.c +++ b/res/res_pjsip.c @@ -35,6 +35,7 @@ #include "asterisk/taskprocessor.h" #include "asterisk/uuid.h" #include "asterisk/sorcery.h" +#include "asterisk/file.h" /*** MODULEINFO pjproject @@ -573,6 +574,9 @@ Determines whether SIP REFER transfers are allowed for this endpoint + + Determines whether a user=phone parameter is placed into the request URI if the user is determined to be a phone number + String placed as the username portion of an SDP origin (o=) line. @@ -1545,6 +1549,9 @@ + + + @@ -2104,6 +2111,41 @@ static int sip_get_tpselector_from_endpoint(const struct ast_sip_endpoint *endpo return 0; } +void ast_sip_add_usereqphone(const struct ast_sip_endpoint *endpoint, pj_pool_t *pool, pjsip_uri *uri) +{ + pjsip_sip_uri *sip_uri; + int i = 0; + pjsip_param *param; + const pj_str_t STR_USER = { "user", 4 }; + const pj_str_t STR_PHONE = { "phone", 5 }; + + if (!endpoint || !endpoint->usereqphone || (!PJSIP_URI_SCHEME_IS_SIP(uri) && !PJSIP_URI_SCHEME_IS_SIPS(uri))) { + return; + } + + sip_uri = pjsip_uri_get_uri(uri); + + if (!pj_strlen(&sip_uri->user)) { + return; + } + + /* Test URI user against allowed characters in AST_DIGIT_ANY */ + for (; i < pj_strlen(&sip_uri->user); i++) { + if (!strchr(AST_DIGIT_ANYNUM, pj_strbuf(&sip_uri->user)[i])) { + break; + } + } + + if (i < pj_strlen(&sip_uri->user)) { + return; + } + + param = PJ_POOL_ALLOC_T(pool, pjsip_param); + param->name = STR_USER; + param->value = STR_PHONE; + pj_list_insert_before(&sip_uri->other_param, param); +} + pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint, const char *uri, const char *request_user) { char enclosed_uri[PJSIP_MAX_URL_SIZE]; @@ -2151,6 +2193,9 @@ pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint, } } + /* Add the user=phone parameter if applicable */ + ast_sip_add_usereqphone(endpoint, dlg->pool, dlg->target); + /* We have to temporarily bump up the sess_count here so the dialog is not prematurely destroyed */ dlg->sess_count++; @@ -2350,6 +2395,9 @@ static int create_out_of_dialog_request(const pjsip_method *method, struct ast_s return -1; } + /* Add the user=phone parameter if applicable */ + ast_sip_add_usereqphone(endpoint, (*tdata)->pool, (*tdata)->msg->line.req.uri); + /* If an outbound proxy is specified on the endpoint apply it to this request */ if (endpoint && !ast_strlen_zero(endpoint->outbound_proxy) && ast_sip_set_outbound_proxy((*tdata), endpoint->outbound_proxy)) { -- cgit v1.2.3