[Freeswitch-svn] [commit] r9042 - in freeswitch/trunk/src: include mod/endpoints/mod_sofia

Freeswitch SVN mikej at freeswitch.org
Tue Jul 15 14:04:17 EDT 2008


Author: mikej
Date: Tue Jul 15 14:04:17 2008
New Revision: 9042

Modified:
   freeswitch/trunk/src/include/switch_utils.h
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c

Log:
Disable multiple registrations on a per-device basis (MODENDP-117)

Modified: freeswitch/trunk/src/include/switch_utils.h
==============================================================================
--- freeswitch/trunk/src/include/switch_utils.h	(original)
+++ freeswitch/trunk/src/include/switch_utils.h	Tue Jul 15 14:04:17 2008
@@ -104,6 +104,22 @@
 !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

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	Tue Jul 15 14:04:17 2008
@@ -413,6 +413,7 @@
 	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 @@
 
 		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 @@
 	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 @@
 			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 @@
 			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, ';'))) {



More information about the Freeswitch-svn mailing list