From 4d2cbfe19704502422345b138f8a36110ba47d64 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 15 Jul 2008 18:04:17 +0000 Subject: [PATCH] Disable multiple registrations on a per-device basis (MODENDP-117) git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9042 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_utils.h | 16 ++++++++++++++++ src/mod/endpoints/mod_sofia/sofia_reg.c | 21 +++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index 06ae775c31..0acc2ad2b0 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -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 diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 644a1ecc88..b2c493cd08 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -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, ';'))) {