Revision
16698
Author
anthm
Date
2010-02-18 16:39:08 -0600 (Thu, 18 Feb 2010)

Log Message

add ability for multiple profiles to share the same gateway names via profile::gwname syntax for normT

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c (16697 => 16698)


--- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	2010-02-18 21:55:46 UTC (rev 16697)
+++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	2010-02-18 22:39:08 UTC (rev 16698)
@@ -1712,7 +1712,6 @@
 		stream->write_function(stream, "+OK module unloaded\n");
 	} else {
 		stream->write_function(stream, "-ERR unloading module [%s]\n", err);
-		return SWITCH_STATUS_SUCCESS;
 	}
 
 	if (switch_loadable_module_load_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) cmd, SWITCH_TRUE, &err) == SWITCH_STATUS_SUCCESS) {

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c (16697 => 16698)


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	2010-02-18 21:55:46 UTC (rev 16697)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	2010-02-18 22:39:08 UTC (rev 16698)
@@ -2282,7 +2282,7 @@
 		return SWITCH_STATUS_SUCCESS;
 	}
 
-	stream->write_function(stream, "%25s\t%s\t  %32s\t%s\n", "Name", "   Type", "Data", "State");
+	stream->write_function(stream, "%25s\t%s\t  %40s\t%s\n", "Name", "   Type", "Data", "State");
 	stream->write_function(stream, "%s\n", line);
 	switch_mutex_lock(mod_sofia_globals.hash_mutex);
 	for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
@@ -2292,21 +2292,27 @@
 
 			if (strcmp(vvar, profile->name)) {
 				ac++;
-				stream->write_function(stream, "%25s\t%s\t  %32s\t%s\n", vvar, "  alias", profile->name, "ALIASED");
+				stream->write_function(stream, "%25s\t%s\t  %40s\t%s\n", vvar, "  alias", profile->name, "ALIASED");
 			} else {
-				stream->write_function(stream, "%25s\t%s\t  %32s\t%s (%u)\n", profile->name, "profile", profile->url,
+				stream->write_function(stream, "%25s\t%s\t  %40s\t%s (%u)\n", profile->name, "profile", profile->url,
 									   sofia_test_pflag(profile, PFLAG_RUNNING) ? "RUNNING" : "DOWN", profile->inuse);
 
 				if (sofia_test_pflag(profile, PFLAG_TLS)) {
-					stream->write_function(stream, "%25s\t%s\t  %32s\t%s (%u) (TLS)\n", profile->name, "profile", profile->tls_url,
+					stream->write_function(stream, "%25s\t%s\t  %40s\t%s (%u) (TLS)\n", profile->name, "profile", profile->tls_url,
 										   sofia_test_pflag(profile, PFLAG_RUNNING) ? "RUNNING" : "DOWN", profile->inuse);
 				}
 
 				c++;
 
 				for (gp = profile->gateways; gp; gp = gp->next) {
+					char *pkey = switch_mprintf("%s::%s", profile->name, gp->name);
+
 					switch_assert(gp->state < REG_STATE_LAST);
-					stream->write_function(stream, "%25s\t%s\t  %32s\t%s", gp->name, "gateway", gp->register_to, sofia_state_names[gp->state]);
+					
+					stream->write_function(stream, "%25s\t%s\t  %40s\t%s",
+										   pkey, "gateway", gp->register_to, sofia_state_names[gp->state]);
+					free(pkey);
+
 					if (gp->state == REG_STATE_FAILED || gp->state == REG_STATE_TRYING) {
 						time_t now = switch_epoch_time_now(NULL);
 						if (gp->retry > now) {

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (16697 => 16698)


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	2010-02-18 21:55:46 UTC (rev 16697)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	2010-02-18 22:39:08 UTC (rev 16698)
@@ -842,7 +842,7 @@
 #define sofia_glue_profile_rdlock(x) sofia_glue_profile_rdlock__(__FILE__, __SWITCH_FUNC__, __LINE__, x)
 switch_status_t sofia_glue_profile_rdlock__(const char *file, const char *func, int line, sofia_profile_t *profile);
 
-switch_status_t sofia_reg_add_gateway(char *key, sofia_gateway_t *gateway);
+switch_status_t sofia_reg_add_gateway(const char *profile_name, const char *key, sofia_gateway_t *gateway);
 sofia_gateway_t *sofia_reg_find_gateway__(const char *file, const char *func, int line, const char *key);
 #define sofia_reg_find_gateway(x) sofia_reg_find_gateway__(__FILE__, __SWITCH_FUNC__, __LINE__,  x)
 

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (16697 => 16698)


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	2010-02-18 21:55:46 UTC (rev 16697)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	2010-02-18 22:39:08 UTC (rev 16698)
@@ -1702,17 +1702,20 @@
 	for (gateway_tag = switch_xml_child(gateways_tag, "gateway"); gateway_tag; gateway_tag = gateway_tag->next) {
 		char *name = (char *) switch_xml_attr_soft(gateway_tag, "name");
 		sofia_gateway_t *gateway;
+		char *pkey = switch_mprintf("%s-%s", profile->name, name);
 
 		if (zstr(name)) {
 			name = "anonymous";
 		}
 
 		switch_mutex_lock(mod_sofia_globals.hash_mutex);
-		if ((gp = switch_core_hash_find(mod_sofia_globals.gateway_hash, name))) {
+		if ((gp = switch_core_hash_find(mod_sofia_globals.gateway_hash, name)) && (gp = switch_core_hash_find(mod_sofia_globals.gateway_hash, pkey))) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring duplicate gateway '%s'\n", name);
 			switch_mutex_unlock(mod_sofia_globals.hash_mutex);
+			free(pkey);
 			goto skip;
 		}
+		free(pkey);
 		switch_mutex_unlock(mod_sofia_globals.hash_mutex);
 
 		if ((gateway = switch_core_alloc(profile->pool, sizeof(*gateway)))) {
@@ -2009,7 +2012,7 @@
 
 			gateway->next = profile->gateways;
 			profile->gateways = gateway;
-			sofia_reg_add_gateway(gateway->name, gateway);
+			sofia_reg_add_gateway(profile->name, gateway->name, gateway);
 		}
 
 	  skip:

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (16697 => 16698)


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	2010-02-18 21:55:46 UTC (rev 16697)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	2010-02-18 22:39:08 UTC (rev 16698)
@@ -223,6 +223,7 @@
 {
 	sofia_gateway_t *gateway_ptr, *last = NULL;
 	switch_event_t *event;
+	char *pkey;
 
 	for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) {
 		if (gateway_ptr->deleted && gateway_ptr->state == REG_STATE_NOREG) {
@@ -231,10 +232,15 @@
 			} else {
 				profile->gateways = gateway_ptr->next;
 			}
+			
+			pkey = switch_mprintf("%s::%s", profile->name, gateway_ptr->name);
 
+			switch_snprintf(pkey, sizeof(pkey), "%s::%s", profile->name, gateway_ptr->name);
+			switch_core_hash_delete(mod_sofia_globals.gateway_hash, pkey);
 			switch_core_hash_delete(mod_sofia_globals.gateway_hash, gateway_ptr->name);
-			switch_core_hash_delete(mod_sofia_globals.gateway_hash, gateway_ptr->register_from);
-			switch_core_hash_delete(mod_sofia_globals.gateway_hash, gateway_ptr->register_contact);
+
+			free(pkey);
+
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleted gateway %s\n", gateway_ptr->name);
 			if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_GATEWAY_DEL) == SWITCH_STATUS_SUCCESS) {
 				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "profile-name", gateway_ptr->profile->name);
@@ -2414,16 +2420,22 @@
 #endif
 }
 
-switch_status_t sofia_reg_add_gateway(char *key, sofia_gateway_t *gateway)
+switch_status_t sofia_reg_add_gateway(const char *profile_name, const char *key, sofia_gateway_t *gateway)
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
+	char *pkey = switch_mprintf("%s::%s", profile_name, key);
 
 	switch_mutex_lock(mod_sofia_globals.hash_mutex);
 	if (!switch_core_hash_find(mod_sofia_globals.gateway_hash, key)) {
 		status = switch_core_hash_insert(mod_sofia_globals.gateway_hash, key, gateway);
 	}
+	if (!switch_core_hash_find(mod_sofia_globals.gateway_hash, pkey)) {
+		status = switch_core_hash_insert(mod_sofia_globals.gateway_hash, pkey, gateway);
+	}
 	switch_mutex_unlock(mod_sofia_globals.hash_mutex);
 
+	free(pkey);
+
 	if (status == SWITCH_STATUS_SUCCESS) {
 		switch_event_t *s_event;
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Added gateway '%s' to profile '%s'\n", gateway->name, gateway->profile->name);