[Freeswitch-svn] [commit] r11908 - freeswitch/trunk/src/mod/applications/mod_lcr

FreeSWITCH SVN rupa at freeswitch.org
Wed Feb 11 17:18:43 PST 2009


Author: rupa
Date: Wed Feb 11 19:18:43 2009
New Revision: 11908

Log:
actually dedup based on endpoints when doing sorted insert to lcr list


Modified:
   freeswitch/trunk/src/mod/applications/mod_lcr/mod_lcr.c

Modified: freeswitch/trunk/src/mod/applications/mod_lcr/mod_lcr.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_lcr/mod_lcr.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_lcr/mod_lcr.c	Wed Feb 11 19:18:43 2009
@@ -116,6 +116,7 @@
 
 struct callback_obj {
 	lcr_route head;
+	switch_hash_t *dedup_hash;
 	int matches;
 	switch_memory_pool_t *pool;
 	char *lookup_number;
@@ -321,6 +322,7 @@
 	lcr_route additional = NULL;
 	lcr_route current = NULL;
 	callback_t *cbt = (callback_t *) pArg;
+	char *key = NULL;
 	
 	switch_memory_pool_t *pool = cbt->pool;
 	
@@ -358,19 +360,25 @@
 	additional->dialstring = get_bridge_data(pool, cbt->lookup_number, additional);
 
 	if (cbt->head == NULL) {
+		key = switch_core_sprintf(pool, "%s:%s", additional->gw_prefix, additional->gw_suffix);
 		additional->next = cbt->head;
 		cbt->head = additional;
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding %s to head of list\n", additional->carrier_name);
-
+		if(switch_core_hash_insert(cbt->dedup_hash, key, additional) != SWITCH_STATUS_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error inserting into dedup hash\n");
+			return SWITCH_STATUS_GENERR;
+		}
 		return SWITCH_STATUS_SUCCESS;
 	}
 
+	
 	for (current = cbt->head; current; current = current->next) {
-			
-		if (!strcmp(current->gw_prefix, additional->gw_prefix) && !strcmp(current->gw_suffix, additional->gw_suffix)) {
+	
+		key = switch_core_sprintf(pool, "%s:%s", additional->gw_prefix, additional->gw_suffix);
+		if(switch_core_hash_find(cbt->dedup_hash, key)) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
-								"Ignoring Duplicate route for termination point (%s:%s)\n",
-								additional->gw_prefix, additional->gw_suffix);
+								"Ignoring Duplicate route for termination point (%s)\n",
+								key);
 			break;
 		}
 
@@ -380,6 +388,10 @@
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding %s to end of list\n", additional->carrier_name);
 				current->next = additional;
 				additional->prev = current;
+				if(switch_core_hash_insert(cbt->dedup_hash, key, additional) != SWITCH_STATUS_SUCCESS) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error inserting into dedup hash\n");
+					return SWITCH_STATUS_GENERR;
+				}
 				break;
 			}
 		} else {
@@ -397,12 +409,20 @@
 				}
 				additional->next = current;
 				current->prev = additional;
+				if(switch_core_hash_insert(cbt->dedup_hash, key, additional) != SWITCH_STATUS_SUCCESS) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error inserting into dedup hash\n");
+					return SWITCH_STATUS_GENERR;
+				}
 				break;
 			} else if(current->next == NULL) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "adding %s to end of list after %s\n",
 									additional->carrier_name, current->carrier_name);
 				current->next = additional;
 				additional->prev = current;
+				if(switch_core_hash_insert(cbt->dedup_hash, key, additional) != SWITCH_STATUS_SUCCESS) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error inserting into dedup hash\n");
+					return SWITCH_STATUS_GENERR;
+				}
 				break;
 			}
 		}
@@ -424,6 +444,12 @@
 		return SWITCH_FALSE;
 	}
 	
+	/* allocate the dedup hash */
+	if(switch_core_hash_init(&cb_struct->dedup_hash, cb_struct->pool) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error initializing the dedup hash\n");
+		return SWITCH_STATUS_FALSE;
+	}
+	
 	/* SWITCH_STANDARD_STREAM doesn't use pools.  but we only have to free sql_stream.data */
 	SWITCH_STANDARD_STREAM(sql_stream);
 
@@ -459,8 +485,10 @@
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s\n", (char *)sql_stream.data);    
 	
 	lookup_status = lcr_execute_sql_callback((char *)sql_stream.data, route_add_callback, cb_struct);
+
 	switch_safe_free(sql_stream.data);
-	
+	switch_core_hash_destroy(&cb_struct->dedup_hash);
+
 	if(lookup_status) {
 		return SWITCH_STATUS_SUCCESS;
 	} else {



More information about the Freeswitch-svn mailing list