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 ASTERISK-28087 #close Change-Id: I9a720e058323f6862a91c62f8a8c1a4b5c087b95
This commit is contained in:
parent
3f4f31fed6
commit
3ba66b8a9d
|
@ -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 = '7f85dd44c775'
|
||||
|
||||
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')
|
|
@ -2747,6 +2747,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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue