mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-29 18:19:30 +00:00
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
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
#include "asterisk/taskprocessor.h"
|
||||
#include "asterisk/uuid.h"
|
||||
#include "asterisk/sorcery.h"
|
||||
#include "asterisk/file.h"
|
||||
|
||||
/*** MODULEINFO
|
||||
<depend>pjproject</depend>
|
||||
@@ -573,6 +574,9 @@
|
||||
<configOption name="allow_transfer" default="yes">
|
||||
<synopsis>Determines whether SIP REFER transfers are allowed for this endpoint</synopsis>
|
||||
</configOption>
|
||||
<configOption name="user_eq_phone" default="no">
|
||||
<synopsis>Determines whether a user=phone parameter is placed into the request URI if the user is determined to be a phone number</synopsis>
|
||||
</configOption>
|
||||
<configOption name="sdp_owner" default="-">
|
||||
<synopsis>String placed as the username portion of an SDP origin (o=) line.</synopsis>
|
||||
</configOption>
|
||||
@@ -1545,6 +1549,9 @@
|
||||
<parameter name="AllowTransfer">
|
||||
<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='allow_transfer']/synopsis/node())"/></para>
|
||||
</parameter>
|
||||
<parameter name="UserEqPhone">
|
||||
<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='user_eq_phone']/synopsis/node())"/></para>
|
||||
</parameter>
|
||||
<parameter name="SdpOwner">
|
||||
<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='sdp_owner']/synopsis/node())"/></para>
|
||||
</parameter>
|
||||
@@ -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)) {
|
||||
|
Reference in New Issue
Block a user