Merge "res_pjsip_notify: improve realtime performance on CLI completion on the endpoint"
authorGeorge Joseph <gjoseph@digium.com>
Mon, 29 Oct 2018 18:23:05 +0000 (13:23 -0500)
committerGerrit Code Review <gerrit2@gerrit.digium.api>
Mon, 29 Oct 2018 18:23:05 +0000 (13:23 -0500)
contrib/ast-db-manage/config/versions/2bb1a85135ad_pjsip_add_use_callerid_contact.py [new file with mode: 0644]
include/asterisk/res_pjsip.h
res/res_pjsip/config_global.c
res/res_pjsip_session.c

diff --git a/contrib/ast-db-manage/config/versions/2bb1a85135ad_pjsip_add_use_callerid_contact.py b/contrib/ast-db-manage/config/versions/2bb1a85135ad_pjsip_add_use_callerid_contact.py
new file mode 100644 (file)
index 0000000..86f48c4
--- /dev/null
@@ -0,0 +1,34 @@
+"""pjsip add use_callerid_contact
+
+Revision ID: 2bb1a85135ad
+Revises: 7f85dd44c775
+Create Date: 2018-10-18 15:13:40.462354
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '2bb1a85135ad'
+down_revision = '465f47f880be'
+
+from alembic import op
+import sqlalchemy as sa
+from sqlalchemy.dialects.postgresql import ENUM
+
+YESNO_NAME = 'yesno_values'
+YESNO_VALUES = ['yes', 'no']
+
+
+def upgrade():
+    ############################# Enums ##############################
+
+    # yesno_values have already been created, so use postgres enum object
+    # type to get around "already created" issue - works okay with mysql
+    yesno_values = ENUM(*YESNO_VALUES, name=YESNO_NAME, create_type=False)
+
+    op.add_column('ps_globals', sa.Column('use_callerid_contact', yesno_values))
+
+
+def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_globals_use_callerid_contact_yesno_values','ps_globals')
+    op.drop_column('ps_globals', 'use_callerid_contact')
index 20af039..41314c5 100644 (file)
@@ -2775,6 +2775,14 @@ int ast_sip_get_mwi_tps_queue_low(void);
 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
  *
index b3d6fa2..a02cacd 100644 (file)
@@ -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 @@ struct global_config {
        } 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 @@ unsigned int ast_sip_get_ignore_uri_user_options(void)
        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 @@ int ast_sip_initialize_sorcery_global(void)
        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_YESNO_T, 1, FLDSET(struct global_config, use_callerid_contact));
 
        if (ast_sorcery_instance_observer_add(sorcery, &observer_callbacks_global)) {
                return -1;
index 1dd8ce9..4ce35c9 100644 (file)
@@ -1404,8 +1404,10 @@ static void set_from_header(struct ast_sip_session *session)
        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) {
@@ -1426,11 +1428,16 @@ static void set_from_header(struct ast_sip_session *session)
 
        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, S_COR(connected_id.number.valid, connected_id.number.str, ""));
+               }
        }
 
        ast_party_id_free(&connected_id);
@@ -1460,6 +1467,10 @@ static void set_from_header(struct ast_sip_session *session)
                        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");
                }