]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Disable multiple registrations on a per-device basis (MODENDP-117)
authorMichael Jerris <mike@jerris.com>
Tue, 15 Jul 2008 18:04:17 +0000 (18:04 +0000)
committerMichael Jerris <mike@jerris.com>
Tue, 15 Jul 2008 18:04:17 +0000 (18:04 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9042 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_utils.h
src/mod/endpoints/mod_sofia/sofia_reg.c

index 06ae775c3143a4937b04cef479a35841b5b37c66..0acc2ad2b05bca5f40acc7cd286fb08a3ee3222a 100644 (file)
@@ -104,6 +104,22 @@ SWITCH_DECLARE(switch_size_t) switch_fd_read_line(int fd, char *buf, switch_size
 !strcasecmp(expr, "active") ||\
 !strcasecmp(expr, "allow") ||\
 atoi(expr))) ? SWITCH_TRUE : SWITCH_FALSE
+
+/*!
+  \brief Evaluate the falsefullness of a string expression
+  \param expr a string expression
+  \return true or false 
+*/
+#define switch_false(expr)\
+(expr && ( !strcasecmp(expr, "no") ||\
+!strcasecmp(expr, "off") ||\
+!strcasecmp(expr, "false") ||\
+!strcasecmp(expr, "disabled") ||\
+!strcasecmp(expr, "inactive") ||\
+!strcasecmp(expr, "disallow") ||\
+!atoi(expr))) ? SWITCH_TRUE : SWITCH_FALSE
+
+
 /*!
   \brief find local ip of the box
   \param buf the buffer to write the ip adress found into
index 644a1ecc8804593e5b463b2642be629f898137c0..b2c493cd088bd59a30c939f01532387931e4b6fd 100644 (file)
@@ -413,6 +413,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
        const char *to_host = NULL;
        char contact_str[1024] = "";
        int nat_hack = 0;
+       uint8_t multi_reg = 0, avoid_multi_reg = 0;
        //char buf[512];
        uint8_t stale = 0, forbidden = 0;
        auth_res_t auth_res;
@@ -564,6 +565,12 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
 
                if (exptime && v_event && *v_event) {
                        char *exp_var;
+                       char *allow_multireg = NULL;
+
+                       allow_multireg = switch_event_get_header(*v_event, "sip-allow-multiple-registrations");
+                       if ( allow_multireg && switch_false(allow_multireg) ) {
+                               avoid_multi_reg = 1;
+                       }
 
                        register_gateway = switch_event_get_header(*v_event, "sip-register-gateway");
 
@@ -643,6 +650,16 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
        call_id = sip->sip_call_id->i_id;       //sip_header_as_string(profile->home, (void *) sip->sip_call_id);
        switch_assert(call_id);
 
+       /* Does this profile supports multiple registrations ? */
+       multi_reg = ( sofia_test_pflag(profile, PFLAG_MULTIREG) ) ? 1 : 0;
+
+       if ( multi_reg && avoid_multi_reg ) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, 
+                                       "Disabling multiple registrations on a per-user basis for %s@%s\n", 
+                                       switch_str_nil(to_user), switch_str_nil(to_host) );
+               multi_reg = 0;
+       }
+
        if (exptime) {
                const char *agent = "dunno";
 
@@ -650,7 +667,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                        agent = sip->sip_user_agent->g_string;
                }
 
-               if (sofia_test_pflag(profile, PFLAG_MULTIREG)) {
+               if (multi_reg) {
                        sql = switch_mprintf("delete from sip_registrations where call_id='%q'", call_id);
                } else {
                        sql = switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q'", to_user, to_host);
@@ -695,7 +712,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                        switch_event_fire(&event);
                }
        } else {
-               if (sofia_test_pflag(profile, PFLAG_MULTIREG)) {
+               if (multi_reg) {
                        char *icontact, *p;
                        icontact = sofia_glue_get_url_from_contact(contact_str, 1);
                        if ((p = strchr(icontact, ';'))) {