]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
IAX/SIP shrinkcallerid option
authorDavid Vossel <dvossel@digium.com>
Wed, 21 Oct 2009 14:37:04 +0000 (14:37 +0000)
committerDavid Vossel <dvossel@digium.com>
Wed, 21 Oct 2009 14:37:04 +0000 (14:37 +0000)
The shrinking of caller id removes '(', ' ', ')', non-trailing '.',
and '-' from the string.  This means values such as 555.5555 and
test-test result in 555555 and testtest.  There are instances,
such as Skype integration, where a specific value is passed via
caller id that must be preserved unmodified.  This patch makes
the shrinking of caller id optional in chan_sip and chan_iax in
order to support such cases.  By default this option is on to
preserve previous expected behavior.

(closes issue #15940)
Reported by: dimas
Patches:
      v2-15940.patch uploaded by dimas (license 88)
      15940_shrinkcallerid_trunk.c uploaded by dvossel (license 671)
Tested by: dvossel

Review: https://reviewboard.asterisk.org/r/408/

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@225032 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_iax2.c
channels/chan_sip.c
configs/iax.conf.sample
configs/sip.conf.sample

index ccf316273bce6bd987e14e84c3179ac43a51c431..442acbf53fa22c0fe34848ae2dd190101cd396b2 100644 (file)
@@ -269,6 +269,7 @@ enum {
                                                     response, so that we've achieved a three-way handshake with
                                                     them before sending voice or anything else*/
        IAX_ALLOWFWDOWNLOAD = (1 << 26),        /*!< Allow the FWDOWNL command? */
+       IAX_SHRINKCALLERID  = (1 << 27),   /*!< Turn on and off caller id shrinking */
 } iax2_flags;
 
 static int global_rtautoclear = 120;
@@ -6315,7 +6316,9 @@ static int check_access(int callno, struct sockaddr_in *sin, struct iax_ies *ies
        if (ies->called_number)
                ast_string_field_set(iaxs[callno], exten, ies->called_number);
        if (ies->calling_number) {
-               ast_shrink_phone_number(ies->calling_number);
+               if (ast_test_flag(&globalflags, IAX_SHRINKCALLERID)) { 
+                       ast_shrink_phone_number(ies->calling_number);
+               }
                ast_string_field_set(iaxs[callno], cid_num, ies->calling_number);
        }
        if (ies->calling_name)
@@ -11298,6 +11301,7 @@ static int set_config(const char *config_file, int reload)
        /* Reset Global Flags */
        memset(&globalflags, 0, sizeof(globalflags));
        ast_set_flag(&globalflags, IAX_RTUPDATE);
+       ast_set_flag((&globalflags), IAX_SHRINKCALLERID);
 
 #ifdef SO_NO_CHECK
        nochecksums = 0;
@@ -11512,10 +11516,18 @@ static int set_config(const char *config_file, int reload)
                        if (sscanf(v->value, "%10hu", &global_maxcallno_nonval) != 1) {
                                ast_log(LOG_WARNING, "maxcallnumbers_nonvalidated must be set to a valid number.  %s is not valid at line %d.\n", v->value, v->lineno);
                        }
-               } else if(!strcasecmp(v->name, "calltokenoptional")) {
+               } else if (!strcasecmp(v->name, "calltokenoptional")) {
                        if (add_calltoken_ignore(v->value)) {
                                ast_log(LOG_WARNING, "Invalid calltokenoptional address range - '%s' line %d\n", v->value, v->lineno);
                        }
+               } else if (!strcasecmp(v->name, "shrinkcallerid")) {
+                       if (ast_true(v->value)) {
+                               ast_set_flag((&globalflags), IAX_SHRINKCALLERID);
+                       } else if (ast_false(v->value)) {
+                               ast_clear_flag((&globalflags), IAX_SHRINKCALLERID);
+                       } else {
+                               ast_log(LOG_WARNING, "shrinkcallerid value %s is not valid at line %d.\n", v->value, v->lineno);
+                       }
                }/*else if (strcasecmp(v->name,"type")) */
                /*      ast_log(LOG_WARNING, "Ignoring %s\n", v->name); */
                v = v->next;
index bb49cd72e9a8def7f3587ff960e8c64c13e7443e..f5a45b2a5f192aa12179419bd776f872f9e718e0 100644 (file)
@@ -554,6 +554,7 @@ static int global_rtpholdtimeout;
 static int global_rtpkeepalive;                /*!< Send RTP keepalives */
 static int global_reg_timeout; 
 static int global_regattempts_max;     /*!< Registration attempts before giving up */
+static int global_shrinkcallerid;      /*!< enable or disable shrinking of caller id  */
 static int global_allowguest;          /*!< allow unauthenticated users/peers to connect? */
 static int global_allowsubscribe;      /*!< Flag for disabling ALL subscriptions, this is FALSE only if all peers are FALSE 
                                            the global setting is in globals_flags[1] */
@@ -10014,7 +10015,7 @@ static enum check_auth_result check_user_full(struct sip_pvt *p, struct sip_requ
                        <sip:8164444422;phone-context=+1@1.2.3.4:5060;user=phone;tag=SDadkoa01-gK0c3bdb43>
                */
                tmp = strsep(&tmp, ";");
-               if (ast_is_shrinkable_phonenumber(tmp))
+               if (global_shrinkcallerid && ast_is_shrinkable_phonenumber(tmp))
                        ast_shrink_phone_number(tmp);
                ast_string_field_set(p, cid_num, tmp);
        }
@@ -10047,7 +10048,7 @@ static enum check_auth_result check_user_full(struct sip_pvt *p, struct sip_requ
                        if (*calleridname)
                                ast_string_field_set(p, cid_name, calleridname);
                        tmp = ast_strdupa(rpid_num);
-                       if (ast_is_shrinkable_phonenumber(tmp))
+                       if (global_shrinkcallerid && ast_is_shrinkable_phonenumber(tmp))
                                ast_shrink_phone_number(tmp);
                        ast_string_field_set(p, cid_num, tmp);
                }
@@ -10070,7 +10071,7 @@ static enum check_auth_result check_user_full(struct sip_pvt *p, struct sip_requ
                                ast_string_field_set(p, context, user->context);
                        if (!ast_strlen_zero(user->cid_num)) {
                                char *tmp = ast_strdupa(user->cid_num);
-                               if (ast_is_shrinkable_phonenumber(tmp))
+                               if (global_shrinkcallerid && ast_is_shrinkable_phonenumber(tmp))
                                        ast_shrink_phone_number(tmp);
                                ast_string_field_set(p, cid_num, tmp);
                        }
@@ -10157,7 +10158,7 @@ static enum check_auth_result check_user_full(struct sip_pvt *p, struct sip_requ
                                char *tmp = ast_strdupa(rpid_num);
                                if (*calleridname)
                                        ast_string_field_set(p, cid_name, calleridname);
-                               if (ast_is_shrinkable_phonenumber(tmp))
+                               if (global_shrinkcallerid && ast_is_shrinkable_phonenumber(tmp))
                                        ast_shrink_phone_number(tmp);
                                ast_string_field_set(p, cid_num, tmp);
                        }
@@ -10207,7 +10208,7 @@ static enum check_auth_result check_user_full(struct sip_pvt *p, struct sip_requ
                                }
                                if (!ast_strlen_zero(peer->cid_num)) {
                                        char *tmp = ast_strdupa(peer->cid_num);
-                                       if (ast_is_shrinkable_phonenumber(tmp))
+                                       if (global_shrinkcallerid && ast_is_shrinkable_phonenumber(tmp))
                                                ast_shrink_phone_number(tmp);
                                        ast_string_field_set(p, cid_num, tmp);
                                }
@@ -10257,10 +10258,10 @@ static enum check_auth_result check_user_full(struct sip_pvt *p, struct sip_requ
                                char *tmp = ast_strdupa(rpid_num);
                                if (*calleridname)
                                        ast_string_field_set(p, cid_name, calleridname);
-                               if (ast_is_shrinkable_phonenumber(tmp))
+                               if (global_shrinkcallerid && ast_is_shrinkable_phonenumber(tmp))
                                        ast_shrink_phone_number(tmp);
                                ast_string_field_set(p, cid_num, tmp);
-                        }
+                       }
                }
 
        }
@@ -18212,7 +18213,8 @@ static int reload_config(enum channelreloadreason reason)
        /* Misc settings for the channel */
        global_relaxdtmf = FALSE;
        global_callevents = FALSE;
-       global_t1min = DEFAULT_T1MIN;           
+       global_t1min = DEFAULT_T1MIN;
+       global_shrinkcallerid = 1;
 
        global_matchexterniplocally = FALSE;
 
@@ -18467,6 +18469,14 @@ static int reload_config(enum channelreloadreason reason)
                        global_matchexterniplocally = ast_true(v->value);
                } else if (!strcasecmp(v->name, "constantssrc")) {
                        ast_set2_flag(&global_flags[1], ast_true(v->value), SIP_PAGE2_CONSTANT_SSRC);
+               } else if (!strcasecmp(v->name, "shrinkcallerid")) {
+                       if (ast_true(v->value)) {
+                               global_shrinkcallerid = 1;
+                       } else if (ast_false(v->value)) {
+                               global_shrinkcallerid = 0;
+                       } else {
+                               ast_log(LOG_WARNING, "shrinkcallerid value %s is not valid at line %d.\n", v->value, v->lineno);
+                       }
                }
        }
 
index f783615df9b29e5bdb2f550504beab7c2ceafd76..1e4d8cea16cc7a860565e9e6787f623463b3fa94 100644 (file)
@@ -324,6 +324,15 @@ autokill=yes
 ;10.1.2.0/255.255.255.0 = 32
 ;
 
+; The shrinkcallerid function removes '(', ' ', ')', non-trailing '.', and '-' not
+; in square brackets.  For example, the caller id value 555.5555 becomes 5555555
+; when this option is enabled.  Disabling this option results in no modification
+; of the caller id value, which is necessary when the caller id represents something
+; that must be preserved.  This option can only be used in the [general] section.
+; By default this option is on.
+;
+;shrinkcallerid=yes     ; on by default
+
 ; Guest sections for unauthenticated connection attempts.  Just specify an
 ; empty secret, or provide no secret section.
 ;
index bfabeb63a3fc7c01667e3eef45d72ee78163bea1..186ebd8f65ebb12258e32f3beea40150a6fa19a4 100644 (file)
@@ -189,6 +189,16 @@ srvlookup=yes                   ; Enable DNS SRV lookups on outbound calls
 ;
 ;regcontext=sipregistrations
 ;
+
+; The shrinkcallerid function removes '(', ' ', ')', non-trailing '.', and '-' not
+; in square brackets.  For example, the caller id value 555.5555 becomes 5555555
+; when this option is enabled.  Disabling this option results in no modification
+; of the caller id value, which is necessary when the caller id represents something
+; that must be preserved.  This option can only be used in the [general] section.
+; By default this option is on.
+;
+;shrinkcallerid=yes     ; on by default
+
 ;--------------------------- RTP timers ----------------------------------------------------
 ; These timers are currently used for both audio and video streams. The RTP timeouts
 ; are only applied to the audio channel.