From 398e5ec16c5b919e17708e26d2e045c389afbd1c Mon Sep 17 00:00:00 2001 From: Richard Begg Date: Wed, 15 Mar 2017 08:45:06 +1100 Subject: res_pjsip_session: Enable RFC3578 overlap dialing support. Support for RFC3578 overlap dialling (i.e. 484 Response to partially matched destinations) as currently provided by chan_sip is missing from res_pjsip. This patch adds a new endpoint attribute (allow_overlap) [defaults to yes] which when set to yes enables 484 responses to partial destination matches rather than the current 404. ASTERISK-26864 Change-Id: Iea444da3ee7c7d4f1fde1d01d138a3d7b0fe40f6 --- CHANGES | 4 +++ configs/samples/pjsip.conf.sample | 1 + .../8fce4c573e15_add_pjsip_allow_overlap.py | 31 ++++++++++++++++++++++ include/asterisk/res_pjsip.h | 2 ++ res/res_pjsip.c | 6 +++++ res/res_pjsip/pjsip_configuration.c | 1 + res/res_pjsip_session.c | 24 ++++++++++++++--- 7 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 contrib/ast-db-manage/config/versions/8fce4c573e15_add_pjsip_allow_overlap.py diff --git a/CHANGES b/CHANGES index 08c9185b6..2304d09d7 100644 --- a/CHANGES +++ b/CHANGES @@ -57,6 +57,10 @@ res_pjsip added to both transport and subscription_persistence, an alembic upgrade should be run to bring the database tables up to date. + * A new option, allow_overlap, has been added to endpoints which allows + overlap dialing functionality to be enabled or disabled. The option defaults + to enabled. + res_pjsip_transport_websocket ------------------ * Removed non-secure websocket support. Firefox and Chrome have not allowed diff --git a/configs/samples/pjsip.conf.sample b/configs/samples/pjsip.conf.sample index 82da311a0..82cfc09ae 100644 --- a/configs/samples/pjsip.conf.sample +++ b/configs/samples/pjsip.conf.sample @@ -595,6 +595,7 @@ ; "yes") ;aggregate_mwi=yes ; (default: "yes") ;allow= ; Media Codec s to allow (default: "") +;allow_overlap=yes ; Enable RFC3578 overlap dialing support. (default: "yes") ;aors= ; AoR s to be used with the endpoint (default: "") ;auth= ; Authentication Object s associated with the endpoint (default: "") ;callerid= ; CallerID information for the endpoint (default: "") diff --git a/contrib/ast-db-manage/config/versions/8fce4c573e15_add_pjsip_allow_overlap.py b/contrib/ast-db-manage/config/versions/8fce4c573e15_add_pjsip_allow_overlap.py new file mode 100644 index 000000000..24057ecc8 --- /dev/null +++ b/contrib/ast-db-manage/config/versions/8fce4c573e15_add_pjsip_allow_overlap.py @@ -0,0 +1,31 @@ +"""add pjsip allow_overlap + +Revision ID: 8fce4c573e15 +Revises: f638dbe2eb23 +Create Date: 2017-03-21 15:14:27.612945 + +""" + +# revision identifiers, used by Alembic. +revision = '8fce4c573e15' +down_revision = 'f638dbe2eb23' + +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_endpoints', sa.Column('allow_overlap', yesno_values)) + + +def downgrade(): + op.drop_column('ps_endpoints', 'allow_overlap') diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h index 05a3eea44..59122b987 100644 --- a/include/asterisk/res_pjsip.h +++ b/include/asterisk/res_pjsip.h @@ -759,6 +759,8 @@ struct ast_sip_endpoint { unsigned int asymmetric_rtp_codec; /*! Use RTCP-MUX */ unsigned int rtcp_mux; + /*! Do we allow overlap dialling? */ + unsigned int allow_overlap; }; /*! URI parameter for symmetric transport */ diff --git a/res/res_pjsip.c b/res/res_pjsip.c index 7b10f47f6..fc4985657 100644 --- a/res/res_pjsip.c +++ b/res/res_pjsip.c @@ -100,6 +100,9 @@ Media Codec(s) to allow + + Enable RFC3578 overlap dialing support. + AoR(s) to be used with the endpoint @@ -2122,6 +2125,9 @@ + + + diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c index eb8e19712..511ea41c1 100644 --- a/res/res_pjsip/pjsip_configuration.c +++ b/res/res_pjsip/pjsip_configuration.c @@ -1939,6 +1939,7 @@ int ast_res_pjsip_initialize_configuration(const struct ast_module_info *ast_mod ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "contact_user", "", contact_user_handler, contact_user_to_str, NULL, 0, 0); ast_sorcery_object_field_register(sip_sorcery, "endpoint", "asymmetric_rtp_codec", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, asymmetric_rtp_codec)); ast_sorcery_object_field_register(sip_sorcery, "endpoint", "rtcp_mux", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, rtcp_mux)); + ast_sorcery_object_field_register(sip_sorcery, "endpoint", "allow_overlap", "yes", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, allow_overlap)); if (ast_sip_initialize_sorcery_transport()) { ast_log(LOG_ERROR, "Failed to register SIP transport support with sorcery\n"); diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c index efdce8aa2..53841c44a 100644 --- a/res/res_pjsip_session.c +++ b/res/res_pjsip_session.c @@ -1984,10 +1984,17 @@ static enum sip_get_destination_result get_destination(struct ast_sip_session *s return SIP_GET_DEST_EXTEN_FOUND; } - /* XXX In reality, we'll likely have further options so that partial matches - * can be indicated here, but for getting something up and running, we're going - * to return a "not exists" error here. + + /* + * Check for partial match via overlap dialling (if enabled) */ + if (session->endpoint->allow_overlap && ( + !strncmp(session->exten, pickupexten, strlen(session->exten)) || + ast_canmatch_extension(NULL, session->endpoint->context, session->exten, 1, NULL))) { + /* Overlap partial match */ + return SIP_GET_DEST_EXTEN_PARTIAL; + } + return SIP_GET_DEST_EXTEN_NOT_FOUND; } @@ -2104,8 +2111,17 @@ static int new_invite(void *data) pjsip_inv_terminate(invite->session->inv_session, 416, PJ_TRUE); } goto end; - case SIP_GET_DEST_EXTEN_NOT_FOUND: case SIP_GET_DEST_EXTEN_PARTIAL: + ast_debug(1, "Call from '%s' (%s:%s:%d) to extension '%s' - partial match\n", ast_sorcery_object_get_id(invite->session->endpoint), + invite->rdata->tp_info.transport->type_name, invite->rdata->pkt_info.src_name, invite->rdata->pkt_info.src_port, invite->session->exten); + + if (pjsip_inv_initial_answer(invite->session->inv_session, invite->rdata, 484, NULL, NULL, &tdata) == PJ_SUCCESS) { + ast_sip_session_send_response(invite->session, tdata); + } else { + pjsip_inv_terminate(invite->session->inv_session, 484, PJ_TRUE); + } + goto end; + case SIP_GET_DEST_EXTEN_NOT_FOUND: default: ast_log(LOG_NOTICE, "Call from '%s' (%s:%s:%d) to extension '%s' rejected because extension not found in context '%s'.\n", ast_sorcery_object_get_id(invite->session->endpoint), invite->rdata->tp_info.transport->type_name, invite->rdata->pkt_info.src_name, -- cgit v1.2.3