[Freeswitch-svn] [commit] r5926 - in freeswitch/trunk: conf src/mod/applications/mod_enum

Freeswitch SVN anthm at freeswitch.org
Wed Oct 17 11:20:52 EDT 2007


Author: anthm
Date: Wed Oct 17 11:20:52 2007
New Revision: 5926

Modified:
   freeswitch/trunk/conf/enum.conf.xml
   freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c

Log:
ISN for enum

Modified: freeswitch/trunk/conf/enum.conf.xml
==============================================================================
--- freeswitch/trunk/conf/enum.conf.xml	(original)
+++ freeswitch/trunk/conf/enum.conf.xml	Wed Oct 17 11:20:52 2007
@@ -1,6 +1,7 @@
 <configuration name="enum.conf" description="ENUM Module">
   <settings>
     <param name="default-root" value="e164.org"/>
+    <param name="default-isn-root" value="freenum.org"/>
   </settings>
 
   <routes>

Modified: freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c	Wed Oct 17 11:20:52 2007
@@ -71,15 +71,16 @@
 
 static struct {
 	char *root;
+	char *isn_root;
 	switch_hash_t *routes;
 	enum_route_t *route_order;
 	switch_memory_pool_t *pool;
 } globals;
 
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_root, globals.root)
+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_root, globals.root);
+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_isn_root, globals.isn_root);
 
-
-	 static void add_route(char *service, char *regex, char *replace)
+static void add_route(char *service, char *regex, char *replace)
 {
 	enum_route_t *route, *rp;
 
@@ -126,6 +127,8 @@
 			char *val = (char *) switch_xml_attr_soft(param, "value");
 			if (!strcasecmp(var, "default-root")) {
 				set_global_root(val);
+			} else if (!strcasecmp(var, "default-isn-root")) {
+				set_global_isn_root(val);
 			} else if (!strcasecmp(var, "log-level-trace")) {
 
 			}
@@ -156,6 +159,10 @@
 		set_global_root("e164.org");
 	}
 
+	if (!globals.isn_root) {
+		set_global_isn_root("freenum.org");
+	}
+
 	return status;
 
 }
@@ -428,15 +435,21 @@
 	struct timeval tv = { 0 };
 	time_t now = 0;
 	struct dns_ctx *nctx = NULL;
-	char *num, *mnum = NULL;
+	char *num, *mnum = NULL, *mroot = NULL, *p;
 
-	if (*in != '+') {
-		mnum = switch_mprintf("+%s", in);
-		num = mnum;
-	} else {
-		num = in;
+	mnum = switch_mprintf("%s%s", *in == '+' ? "" : "+", in);
+	
+	if ((p = strchr(mnum, '*'))) {
+		*p++ = '\0';
+		mroot = switch_mprintf("%s.%s", p, root ? root : globals.isn_root);
+		root = mroot;
 	}
 
+	if (switch_strlen_zero(root)) {
+		root = globals.root;
+	}
+
+	num = mnum;
 	if (!(name = reverse_number(num, root))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Parse Error!\n");
 		sstatus = SWITCH_STATUS_FALSE;
@@ -510,6 +523,7 @@
 
 	switch_safe_free(name);
 	switch_safe_free(mnum);
+	switch_safe_free(mroot);
 
 	return sstatus;
 }
@@ -531,7 +545,7 @@
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "ENUM Lookup on %s\n", caller_profile->destination_number);
 
-	if (enum_lookup(switch_strlen_zero(dp) ? globals.root : dp, caller_profile->destination_number, &results) == SWITCH_STATUS_SUCCESS) {
+	if (enum_lookup(dp, caller_profile->destination_number, &results) == SWITCH_STATUS_SUCCESS) {
 		if ((extension = switch_caller_extension_new(session, caller_profile->destination_number, caller_profile->destination_number)) == 0) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
 			free_results(&results);
@@ -581,7 +595,7 @@
 
 	if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
 		dest = argv[0];
-		root = argv[1] ? argv[1] : globals.root;
+		root = argv[1];
 		if (enum_lookup(root, dest, &results) == SWITCH_STATUS_SUCCESS) {
 			switch_event_header_t *hi;
 			if ((hi = switch_channel_variable_first(channel))) {
@@ -633,13 +647,13 @@
 	}
 
 	if (!cmd || !(mydata = strdup(cmd))) {
-		stream->write_function(stream, "Error!\n");
-		return SWITCH_STATUS_FALSE;
+		stream->write_function(stream, "Usage: enum <number> [<root>]\n");
+		return SWITCH_STATUS_SUCCESS;
 	}
 
 	if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
 		dest = argv[0];
-		root = argv[1] ? argv[1] : globals.root;
+		root = argv[1];
 
 		if (!enum_lookup(root, dest, &results) == SWITCH_STATUS_SUCCESS) {
 			stream->write_function(stream, "No Match!\n");



More information about the Freeswitch-svn mailing list