[Asterisk-code-review] res pjsip session: add new flag use callerid contact (asterisk[13])
Torrey Searle
asteriskteam at digium.com
Tue Oct 2 07:33:28 CDT 2018
Torrey Searle has uploaded this change for review. ( https://gerrit.asterisk.org/10357
Change subject: res_pjsip_session: add new flag use_callerid_contact
......................................................................
res_pjsip_session: add new flag use_callerid_contact
Add a new global flag to res_pjsip to allow the callerid to be used
as the username in the contact header. This allows chan_pjsip to have
the same behavour as chan_sip
AST-28087 #close
Change-Id: I9a720e058323f6862a91c62f8a8c1a4b5c087b95
---
M include/asterisk/res_pjsip.h
M res/res_pjsip/config_global.c
M res/res_pjsip_session.c
3 files changed, 40 insertions(+), 0 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/57/10357/1
diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index 17282d6..eb0905b 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -2774,6 +2774,14 @@
unsigned int ast_sip_get_mwi_disable_initial_unsolicited(void);
/*!
+ * \brief Retrieve the global setting 'use_callerid_contact'.
+ * \since 13.24.0
+ *
+ * \retval non zero if CALLERID(num) is to be used as the default username in the contact
+ */
+unsigned int ast_sip_get_use_callerid_contact(void);
+
+/*!
* \brief Retrieve the global setting 'ignore_uri_user_options'.
* \since 13.12.0
*
diff --git a/res/res_pjsip/config_global.c b/res/res_pjsip/config_global.c
index b3d6fa2..6e2260a 100644
--- a/res/res_pjsip/config_global.c
+++ b/res/res_pjsip/config_global.c
@@ -48,6 +48,7 @@
#define DEFAULT_MWI_TPS_QUEUE_LOW -1
#define DEFAULT_MWI_DISABLE_INITIAL_UNSOLICITED 0
#define DEFAULT_IGNORE_URI_USER_OPTIONS 0
+#define DEFAULT_USE_CALLERID_CONTACT 0
/*!
* \brief Cached global config object
@@ -103,6 +104,8 @@
} mwi;
/*! Nonzero if URI user field options are ignored. */
unsigned int ignore_uri_user_options;
+ /*! Nonzero if CALLERID(num) is to be used as the default contact username instead of default_from_user */
+ unsigned int use_callerid_contact;
};
static void global_destructor(void *obj)
@@ -402,6 +405,21 @@
return ignore_uri_user_options;
}
+unsigned int ast_sip_get_use_callerid_contact(void)
+{
+ unsigned int use_callerid_contact;
+ struct global_config *cfg;
+
+ cfg = get_global_cfg();
+ if (!cfg) {
+ return DEFAULT_USE_CALLERID_CONTACT;
+ }
+
+ use_callerid_contact = cfg->use_callerid_contact;
+ ao2_ref(cfg, -1);
+ return use_callerid_contact;
+}
+
/*!
* \internal
* \brief Observer to set default global object if none exist.
@@ -553,6 +571,9 @@
ast_sorcery_object_field_register(sorcery, "global", "ignore_uri_user_options",
DEFAULT_IGNORE_URI_USER_OPTIONS ? "yes" : "no",
OPT_BOOL_T, 1, FLDSET(struct global_config, ignore_uri_user_options));
+ ast_sorcery_object_field_register(sorcery, "global", "use_callerid_contact",
+ DEFAULT_USE_CALLERID_CONTACT ? "yes" : "no",
+ OPT_BOOL_T, 1, FLDSET(struct global_config, use_callerid_contact));
if (ast_sorcery_instance_observer_add(sorcery, &observer_callbacks_global)) {
return -1;
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index ff40e55..c92933a 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -761,8 +761,10 @@
struct ast_party_id connected_id;
pj_pool_t *dlg_pool;
pjsip_fromto_hdr *dlg_info;
+ pjsip_contact_hdr *dlg_contact;
pjsip_name_addr *dlg_info_name_addr;
pjsip_sip_uri *dlg_info_uri;
+ pjsip_sip_uri *dlg_contact_uri;
int restricted;
if (!session->channel || session->saved_from_hdr) {
@@ -783,11 +785,16 @@
dlg_pool = session->inv_session->dlg->pool;
dlg_info = session->inv_session->dlg->local.info;
+ dlg_contact = session->inv_session->dlg->local.contact;
dlg_info_name_addr = (pjsip_name_addr *) dlg_info->uri;
dlg_info_uri = pjsip_uri_get_uri(dlg_info_name_addr);
+ dlg_contact_uri = (pjsip_sip_uri*)pjsip_uri_get_uri(dlg_contact->uri);
if (session->endpoint->id.trust_outbound || !restricted) {
ast_sip_modify_id_header(dlg_pool, dlg_info, &connected_id);
+ if (ast_sip_get_use_callerid_contact() && ast_strlen_zero(session->endpoint->contact_user)) {
+ pj_strdup2(dlg_pool, &dlg_contact_uri->user, connected_id.number.str);
+ }
}
ast_party_id_free(&connected_id);
@@ -817,6 +824,10 @@
pj_strdup2(dlg_pool, &dlg_info_uri->user, "anonymous");
}
+ if (ast_sip_get_use_callerid_contact() && ast_strlen_zero(session->endpoint->contact_user)) {
+ pj_strdup2(dlg_pool, &dlg_contact_uri->user, "anonymous");
+ }
+
if (ast_strlen_zero(session->endpoint->fromdomain)) {
pj_strdup2(dlg_pool, &dlg_info_uri->host, "anonymous.invalid");
}
--
To view, visit https://gerrit.asterisk.org/10357
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9a720e058323f6862a91c62f8a8c1a4b5c087b95
Gerrit-Change-Number: 10357
Gerrit-PatchSet: 1
Gerrit-Owner: Torrey Searle <tsearle at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20181002/327f62c5/attachment.html>
More information about the asterisk-code-review
mailing list