pjsip: new endpoint's options to control Connected Line updates
authorAlexei Gradinari <alex2grad@gmail.com>
Mon, 22 Oct 2018 16:49:37 +0000 (12:49 -0400)
committerRichard Mudgett <rmudgett@digium.com>
Tue, 30 Oct 2018 15:39:28 +0000 (10:39 -0500)
This patch adds new options 'trust_connected_line' and 'send_connected_line'
to the endpoint.

The option 'trust_connected_line' is to control if connected line updates
are accepted from this endpoint.

The option 'send_connected_line' is to control if connected line updates
can be sent to this endpoint.

The default value is 'yes' for both options.

Change-Id: I16af967815efd904597ec2f033337e4333d097cd

CHANGES
channels/chan_pjsip.c
configs/samples/pjsip.conf.sample
contrib/ast-db-manage/config/versions/1ac563b350a8_add_pjsip_trust_send__connected_line.py [new file with mode: 0644]
include/asterisk/res_pjsip.h
res/res_pjsip.c
res/res_pjsip/pjsip_configuration.c
res/res_pjsip_caller_id.c

diff --git a/CHANGES b/CHANGES
index bd1a7a7..e00c16f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
 --- Functionality changes from Asterisk 16.0.0 to Asterisk 16.1.0 ------------
 ------------------------------------------------------------------------------
 
+res_pjsip
+------------------
+ * New options 'trust_connected_line' and 'send_connected_line' have been
+   added to the endpoint. The option 'trust_connected_line' is to control
+   if connected line updates are accepted from this endpoint.
+   The option 'send_connected_line' is to control if connected line updates
+   can be sent to this endpoint.
+   The default value is 'yes' for both options.
+
 res_rtp_asterisk
 ------------------
  * The existing strictrtp option in rtp.conf has a new choice availabe, called
index 21941eb..c28d8ca 100644 (file)
@@ -1380,7 +1380,8 @@ static int is_colp_update_allowed(struct ast_sip_session *session)
        struct ast_party_id connected_id;
        int update_allowed = 0;
 
-       if (!session->endpoint->id.send_pai && !session->endpoint->id.send_rpid) {
+       if (!session->endpoint->id.send_connected_line
+               || (!session->endpoint->id.send_pai && !session->endpoint->id.send_rpid)) {
                return 0;
        }
 
index dc0679b..4750260 100644 (file)
 ;direct_media_glare_mitigation=none     ; Mitigation of direct media re INVITE
                                         ; glare (default: "none")
 ;direct_media_method=invite     ; Direct Media method type (default: "invite")
+;trust_connected_line=yes       ; Accept Connected Line updates from this endpoint
+                                ; (default: "yes")
+;send_connected_line=yes        ; Send Connected Line updates to this endpoint
+                                ; (default: "yes")
 ;connected_line_method=invite   ; Connected line method type.
                                 ; When set to "invite", check the remote's
                                 ; Allow header and if UPDATE is allowed, send
diff --git a/contrib/ast-db-manage/config/versions/1ac563b350a8_add_pjsip_trust_send__connected_line.py b/contrib/ast-db-manage/config/versions/1ac563b350a8_add_pjsip_trust_send__connected_line.py
new file mode 100644 (file)
index 0000000..6ca6d23
--- /dev/null
@@ -0,0 +1,40 @@
+"""add pjsip trust/send _connected_line
+
+Revision ID: 1ac563b350a8
+Revises: 2bb1a85135ad
+Create Date: 2018-10-12 17:10:34.530282
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '1ac563b350a8'
+down_revision = '2bb1a85135ad'
+
+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():
+    ############################# Enums ##############################
+
+    # ast_bool_values has already been created, so use postgres enum object
+    # type to get around "already created" issue - works okay with mysql
+    ast_bool_values = ENUM(*AST_BOOL_VALUES, name=AST_BOOL_NAME, create_type=False)
+
+    op.add_column('ps_endpoints', sa.Column('trust_connected_line', ast_bool_values))
+    op.add_column('ps_endpoints', sa.Column('send_connected_line', ast_bool_values))
+
+def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_endpoints_trust_connected_line_ast_bool_values', 'ps_endpoints')
+        op.drop_constraint('ck_ps_endpoints_send_connected_line_ast_bool_values', 'ps_endpoints')
+    op.drop_column('ps_endpoints', 'trust_connected_line')
+    op.drop_column('ps_endpoints', 'send_connected_line')
index 41314c5..fc4f809 100644 (file)
@@ -593,6 +593,10 @@ struct ast_sip_endpoint_id_configuration {
        unsigned int rpid_immediate;
        /*! Do we add Diversion headers to applicable outgoing requests/responses? */
        unsigned int send_diversion;
+       /*! Do we accept connected line updates from this endpoint? */
+       unsigned int trust_connected_line;
+       /*! Do we send connected line updates to this endpoint? */
+       unsigned int send_connected_line;
        /*! When performing connected line update, which method should be used */
        enum ast_sip_session_refresh_method refresh_method;
 };
index a61208f..cd0f854 100644 (file)
                                                </enumlist>
                                        </description>
                                </configOption>
+                               <configOption name="trust_connected_line">
+                                       <synopsis>Accept Connected Line updates from this endpoint</synopsis>
+                               </configOption>
+                               <configOption name="send_connected_line">
+                                       <synopsis>Send Connected Line updates to this endpoint</synopsis>
+                               </configOption>
                                <configOption name="connected_line_method" default="invite">
                                        <synopsis>Connected line method type</synopsis>
                                        <description>
                                <parameter name="DirectMediaMethod">
                                        <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='direct_media_method']/synopsis/node())"/></para>
                                </parameter>
+                               <parameter name="TrustConnectedLine">
+                                       <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='trust_connected_line']/synopsis/node())"/></para>
+                               </parameter>
+                               <parameter name="SendConnectedLine">
+                                       <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='send_connected_line']/synopsis/node())"/></para>
+                               </parameter>
                                <parameter name="ConnectedLineMethod">
                                        <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='connected_line_method']/synopsis/node())"/></para>
                                </parameter>
index ee37fc2..41195be 100644 (file)
@@ -1819,6 +1819,8 @@ int ast_res_pjsip_initialize_configuration(void)
        ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "identify_by", "username,ip", ident_handler, ident_to_str, NULL, 0, 0);
        ast_sorcery_object_field_register(sip_sorcery, "endpoint", "direct_media", "yes", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, media.direct_media.enabled));
        ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "direct_media_method", "invite", direct_media_method_handler, direct_media_method_to_str, NULL, 0, 0);
+       ast_sorcery_object_field_register(sip_sorcery, "endpoint", "trust_connected_line", "yes", OPT_YESNO_T, 1, FLDSET(struct ast_sip_endpoint, id.trust_connected_line));
+       ast_sorcery_object_field_register(sip_sorcery, "endpoint", "send_connected_line", "yes", OPT_YESNO_T, 1, FLDSET(struct ast_sip_endpoint, id.send_connected_line));
        ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "connected_line_method", "invite", connected_line_method_handler, connected_line_method_to_str, NULL, 0, 0);
        ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "direct_media_glare_mitigation", "none", direct_media_glare_mitigation_handler, direct_media_glare_mitigation_to_str, NULL, 0, 0);
        ast_sorcery_object_field_register(sip_sorcery, "endpoint", "disable_direct_media_on_nat", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, media.direct_media.disable_on_nat));
index 2481a3f..bc5ad8c 100644 (file)
@@ -341,7 +341,8 @@ static void update_incoming_connected_line(struct ast_sip_session *session, pjsi
 {
        struct ast_party_id id;
 
-       if (!session->endpoint->id.trust_inbound) {
+       if (!session->endpoint->id.trust_connected_line
+               || !session->endpoint->id.trust_inbound) {
                return;
        }
 
@@ -749,7 +750,10 @@ static void caller_id_outgoing_response(struct ast_sip_session *session, pjsip_t
        struct ast_party_id effective_id;
        struct ast_party_id connected_id;
 
-       if (!session->channel) {
+       if (!session->channel
+               || (!session->endpoint->id.send_connected_line
+                       && session->inv_session
+                       && session->inv_session->state >= PJSIP_INV_STATE_EARLY)) {
                return;
        }