--- /dev/null
+"""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 = '7f85dd44c775'
+
+from alembic import op
+import sqlalchemy as sa
+from sqlalchemy.dialects.postgresql import ENUM
+
+AST_BOOL_NAME = 'ast_bool_values'
+# We'll just ignore the n/y and f/t abbreviations as Asterisk does not write
+# those aliases.
+AST_BOOL_VALUES = [ '0', '1',
+ 'off', 'on',
+ 'false', 'true',
+ 'no', 'yes' ]
+
+
+def upgrade():
+ # Create the new enum
+ ast_bool_values = ENUM(*AST_BOOL_VALUES, name=AST_BOOL_NAME, create_type=False)
+ if op.get_context().bind.dialect.name == 'postgresql':
+ ast_bool_values.create(op.get_bind(), checkfirst=False)
+
+
+ op.add_column('ps_globals', sa.Column('use_callerid_contact', ast_bool_values))
+
+
+def downgrade():
+ if op.get_context().bind.dialect.name == 'mssql':
+ op.drop_constraint('ck_ps_globals_use_callerid_contact_ast_bool_values','ps_globals')
+ op.drop_column('ps_globals', 'use_callerid_contact')
+
+ if op.get_context().bind.dialect.name == 'postgresql':
+ ENUM(name=AST_BOOL_NAME).drop(op.get_bind(), checkfirst=False)
*/
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
#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
} 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)
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.
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;
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) {
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);
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");
}