]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_pjsip: Added a norefersub configuration setting
authorDan Cropp <dan@amtelco.com>
Mon, 8 Apr 2019 22:04:48 +0000 (17:04 -0500)
committerGeorge Joseph <gjoseph@digium.com>
Thu, 18 Apr 2019 14:05:39 +0000 (08:05 -0600)
Added a new PJSIP global setting called norefersub.
Default is true to keep support working as before.

res_pjsip_refer:  Configures PJSIP norefersub capability accordingly.

Checks the PJSIP global setting value.
If it is true (default) it adds the norefersub capability to PJSIP.
If it is false (disabled) it does not add the norefersub capability
to PJSIP.

This is useful for Cisco switches that do not follow RFC4488.

ASTERISK-28375 #close
Reported-by: Dan Cropp
Change-Id: I0b1c28ebc905d881f4a16e752715487a688b30e9

configs/samples/pjsip.conf.sample
contrib/ast-db-manage/config/versions/3a094a18e75b_pjsip_add_norefersub.py [new file with mode: 0644]
doc/CHANGES-staging/res_pjsip_add_norefersub_global_config.txt [new file with mode: 0644]
include/asterisk/res_pjsip.h
res/res_pjsip.c
res/res_pjsip/config_global.c
res/res_pjsip_refer.c

index 574efeef9dae0e3ac10b83d5b458cd0d025cfae1..bbd0317e798db80606ced91f6ed7f4aa9c6ba371 100644 (file)
                 ; with extreme caution and only to mitigate specific issues.
                 ; Under certain conditions they could make things worse.
 
+;norefersub=yes     ; Enable sending norefersub option tag in Supported header to advertise
+                    ; that the User Agent is capable of accepting a REFER request with
+                    ; creating an implicit subscription (see RFC 4488).
+                    ; (default: "yes")
+
 ; MODULE PROVIDING BELOW SECTION(S): res_pjsip_acl
 ;==========================ACL SECTION OPTIONS=========================
 ;[acl]
diff --git a/contrib/ast-db-manage/config/versions/3a094a18e75b_pjsip_add_norefersub.py b/contrib/ast-db-manage/config/versions/3a094a18e75b_pjsip_add_norefersub.py
new file mode 100644 (file)
index 0000000..1209ae2
--- /dev/null
@@ -0,0 +1,39 @@
+"""pjsip add norefersub
+
+Revision ID: 3a094a18e75b
+Revises: 80473bad3c16
+Create Date: 2019-04-17 09:25:42.040269
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '3a094a18e75b'
+down_revision = '80473bad3c16'
+
+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=True)
+
+    op.add_column('ps_globals', sa.Column('norefersub', ast_bool_values))
+
+
+def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_globals_norefersub_ast_bool_values', 'ps_globals')
+    op.drop_column('ps_globals', 'norefersub')
diff --git a/doc/CHANGES-staging/res_pjsip_add_norefersub_global_config.txt b/doc/CHANGES-staging/res_pjsip_add_norefersub_global_config.txt
new file mode 100644 (file)
index 0000000..4e07672
--- /dev/null
@@ -0,0 +1,13 @@
+res_pjsip:  Added a norefersub configuration setting
+
+Added a new PJSIP global setting called norefersub.
+Default is true to keep support working as before.
+
+res_pjsip_refer:  Configures PJSIP norefersub capability accordingly.
+
+Checks the PJSIP global setting value.
+If it is true (default) it adds the norefersub capability to PJSIP.
+If it is false (disabled) it does not add the norefersub capability
+to PJSIP.
+
+This is useful for Cisco switches that do not follow RFC4488.
index 79c29cc90a1123058f3ebccacdd7ce2965db4be8..5e8dd3a24f653199832ee4cb5f5959dfddd80d83 100644 (file)
@@ -2787,6 +2787,13 @@ unsigned int ast_sip_get_mwi_disable_initial_unsolicited(void);
  */
 unsigned int ast_sip_get_use_callerid_contact(void);
 
+/*!
+ * \brief Retrieve the global setting 'norefersub'.
+ *
+ * \retval non zero if norefersub is to be sent in "Supported" Headers
+ */
+unsigned int ast_sip_get_norefersub(void);
+
 /*!
  * \brief Retrieve the global setting 'ignore_uri_user_options'.
  * \since 13.12.0
index 2d5f0da1ac2910a1e03a1f8d57dd074c77604d01..7773549adfd3ce701b104e57a57cd0eff5d13e93 100644 (file)
                                                </para></warning>
                                        </description>
                                </configOption>
+                               <configOption name="norefersub" default="yes">
+                                       <synopsis>Advertise support for RFC4488 REFER subscription suppression</synopsis>
+                               </configOption>
                        </configObject>
                </configFile>
        </configInfo>
index 365d9aa41f865939c3211716864033d1d970c798..25a0b51691a36111d3f47e8248417a66446e8d3f 100644 (file)
@@ -52,6 +52,7 @@
 #define DEFAULT_USE_CALLERID_CONTACT 0
 #define DEFAULT_SEND_CONTACT_STATUS_ON_UPDATE_REGISTRATION 1
 #define DEFAULT_TASKPROCESSOR_OVERLOAD_TRIGGER TASKPROCESSOR_OVERLOAD_TRIGGER_GLOBAL
+#define DEFAULT_NOREFERSUB 1
 
 /*!
  * \brief Cached global config object
@@ -113,6 +114,8 @@ struct global_config {
        unsigned int send_contact_status_on_update_registration;
        /*! Trigger the distributor should use to pause accepting new dialogs */
        enum ast_sip_taskprocessor_overload_trigger overload_trigger;
+       /*! Nonzero if norefersub is to be sent in Supported header */
+       unsigned int norefersub;
 };
 
 static void global_destructor(void *obj)
@@ -501,6 +504,21 @@ enum ast_sip_taskprocessor_overload_trigger ast_sip_get_taskprocessor_overload_t
        return trigger;
 }
 
+unsigned int ast_sip_get_norefersub(void)
+{
+       unsigned int norefersub;
+       struct global_config *cfg;
+
+       cfg = get_global_cfg();
+       if (!cfg) {
+               return DEFAULT_NOREFERSUB;
+       }
+
+       norefersub = cfg->norefersub;
+       ao2_ref(cfg, -1);
+       return norefersub;
+}
+
 static int overload_trigger_handler(const struct aco_option *opt,
        struct ast_variable *var, void *obj)
 {
@@ -704,6 +722,9 @@ int ast_sip_initialize_sorcery_global(void)
        ast_sorcery_object_field_register_custom(sorcery, "global", "taskprocessor_overload_trigger",
                overload_trigger_map[DEFAULT_TASKPROCESSOR_OVERLOAD_TRIGGER],
                overload_trigger_handler, overload_trigger_to_str, NULL, 0, 0);
+       ast_sorcery_object_field_register(sorcery, "global", "norefersub",
+               DEFAULT_NOREFERSUB ? "yes" : "no",
+               OPT_YESNO_T, 1, FLDSET(struct global_config, norefersub));
 
        if (ast_sorcery_instance_observer_add(sorcery, &observer_callbacks_global)) {
                return -1;
index 9b35c6aabab3f92f830f38698676e9b38786483d..3c73801e8ba6a58541c93d7ef96180efb9cd1159 100644 (file)
@@ -1232,7 +1232,10 @@ static int load_module(void)
 
        pjsip_replaces_init_module(ast_sip_get_pjsip_endpoint());
        pjsip_xfer_init_module(ast_sip_get_pjsip_endpoint());
-       pjsip_endpt_add_capability(ast_sip_get_pjsip_endpoint(), NULL, PJSIP_H_SUPPORTED, NULL, 1, &str_norefersub);
+
+       if (ast_sip_get_norefersub()) {
+               pjsip_endpt_add_capability(ast_sip_get_pjsip_endpoint(), NULL, PJSIP_H_SUPPORTED, NULL, 1, &str_norefersub);
+       }
 
        ast_sip_register_service(&refer_progress_module);
        ast_sip_session_register_supplement(&refer_supplement);