[Freeswitch-svn] [commit] r6239 - in freeswitch/trunk/src/mod: applications/mod_dptools applications/mod_limit endpoints/mod_sofia

Freeswitch SVN anthm at freeswitch.org
Tue Nov 13 14:58:44 EST 2007


Author: anthm
Date: Tue Nov 13 14:58:44 2007
New Revision: 6239

Modified:
   freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
   freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c

Log:
fix some stuff and add set_user func

Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	Tue Nov 13 14:58:44 2007
@@ -86,6 +86,67 @@
 	}
 }
 
+
+#define SET_USER_SYNTAX "<user>@<domain>"
+SWITCH_STANDARD_APP(set_user_function)
+{
+	switch_xml_t x_domain, xml = NULL, x_user, x_param, x_params;	
+	char *user, *mailbox, *domain;
+	switch_channel_t *channel;
+
+	channel = switch_core_session_get_channel(session);
+	assert(channel != NULL);
+
+	if (switch_strlen_zero(data)) {
+		goto error;
+	}
+
+	user = switch_core_session_strdup(session, data);
+
+	if (!(domain = strchr(user, '@'))) {
+		goto error;
+	}
+
+	*domain++ = '\0';
+	
+	if (switch_xml_locate_user(user, domain, NULL, &xml, &x_domain, &x_user, NULL) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", user, domain);
+		goto done;
+	}
+
+	if ((mailbox = (char *)switch_xml_attr(x_user, "mailbox"))) {
+		switch_channel_set_variable(channel, "mailbox", mailbox);
+	}
+	
+	if ((x_params = switch_xml_child(x_user, "variables"))) {
+		for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) {
+			const char *var = switch_xml_attr(x_param, "name");
+			const char *val = switch_xml_attr(x_param, "value");
+			
+			if (var && val) {
+				switch_channel_set_variable(channel, var, val);
+			}
+		}
+	}
+
+	switch_channel_set_variable(channel, "user_name", user);
+	switch_channel_set_variable(channel, "domain_name", domain);
+
+	goto done;
+
+ error:
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No user at domain specified.\n");
+
+ done:
+	
+	if (xml) {
+		switch_xml_free(xml);
+	}
+
+
+}
+
+
 SWITCH_STANDARD_APP(ring_ready_function)
 {
 	switch_channel_t *channel;
@@ -1390,6 +1451,7 @@
 	SWITCH_ADD_APP(app_interface, "sched_broadcast", SCHED_BROADCAST_DESCR, SCHED_BROADCAST_DESCR, sched_broadcast_function, "[+]<time> <path> [aleg|bleg|both]", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "sched_transfer", SCHED_TRANSF_DESCR, SCHED_TRANSF_DESCR, sched_transfer_function, "[+]<time> <extension> <dialplan> <context>", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "execute_extension", "Execute an extension", "Execute an extension", exe_function, EXE_SYNTAX, SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "set_user", "Set a User", "Set a User", set_user_function, SET_USER_SYNTAX, SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "stop_dtmf", "stop inband dtmf", "Stop detecting inband dtmf.", stop_dtmf_session_function, "", SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "start_dtmf", "Detect dtmf", "Detect inband dtmf on the session", dtmf_session_function, "", SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "stop_dtmf_generate", "stop inband dtmf generation", "Stop generating inband dtmf.", 

Modified: freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c	Tue Nov 13 14:58:44 2007
@@ -390,14 +390,14 @@
 }
 
 
-#define DB_USAGE "[add|del]/<realm>/<key>/<val>"
+#define DB_USAGE "[insert|delete]/<realm>/<key>/<val>"
 #define DB_DESC "save data"
 
 SWITCH_STANDARD_APP(db_function)
 {
     switch_channel_t *channel;
     int argc = 0;
-    char *argv[3] = { 0 };
+    char *argv[4] = { 0 };
     char *mydata = NULL;
     char *sql = NULL;
 
@@ -408,15 +408,15 @@
         mydata = switch_core_session_strdup(session, data);
         argc = switch_separate_string(mydata, '/', argv, (sizeof(argv) / sizeof(argv[0])));
     }
-
+    printf("WTF [%s] %d\n", argv[0], argc);
     if (argc < 4) {
         goto error;
     }
-
     
-    if (!strcasecmp(argv[0], "add")) {
+    
+    if (!strcasecmp(argv[0], "insert")) {
         sql = switch_mprintf("insert into db_data values('%q','%q','%q','%q');", globals.hostname, argv[1], argv[2], argv[3]);
-    } else if (!strcasecmp(argv[0], "del")) {
+    } else if (!strcasecmp(argv[0], "delete")) {
         sql = switch_mprintf("delete from db_data where realm='%q' and data_key='%q'", argv[1], argv[2]);
     }
 
@@ -454,7 +454,7 @@
         goto error;
     }
 
-    if (!strcasecmp(argv[0], "add")) {
+    if (!strcasecmp(argv[0], "insert")) {
         if (argc < 3) {
             goto error;
         }
@@ -468,7 +468,7 @@
         switch_safe_free(sql);
         stream->write_function(stream, "+OK");
         goto done;
-    } else if (!strcasecmp(argv[0], "del")) {
+    } else if (!strcasecmp(argv[0], "delete")) {
         if (argc < 3) {
             goto error;
         }
@@ -515,7 +515,7 @@
     
 }
 
-#define GROUP_USAGE "[add|del]:<group name>:<val>"
+#define GROUP_USAGE "[insert|delete]:<group name>:<val>"
 #define GROUP_DESC "save data"
 
 SWITCH_STANDARD_APP(group_function)
@@ -539,12 +539,12 @@
         return;
     }
 
-    if (!strcasecmp(argv[0], "add")) {
+    if (!strcasecmp(argv[0], "insert")) {
         sql = switch_mprintf("insert into group_data values('%q','%q','%q');", globals.hostname, argv[1], argv[2]);
         assert(sql);
         limit_execute_sql(sql, globals.mutex);
         switch_safe_free(sql);
-    } else if (!strcasecmp(argv[0], "del")) {
+    } else if (!strcasecmp(argv[0], "delete")) {
         sql = switch_mprintf("delete from group_data where groupname='%q' and url='%q';", argv[1], argv[2]);
         assert(sql);
         limit_execute_sql(sql, globals.mutex);
@@ -643,11 +643,11 @@
     *module_interface = switch_loadable_module_create_module_interface(pool, modname);
 
 	SWITCH_ADD_APP(app_interface, "limit", "Limit", LIMIT_DESC, limit_function, LIMIT_USAGE, SAF_NONE);
-	SWITCH_ADD_APP(app_interface, "db_insert", "Insert to the db", DB_DESC, db_function, DB_USAGE, SAF_NONE);
+	SWITCH_ADD_APP(app_interface, "db", "Insert to the db", DB_DESC, db_function, DB_USAGE, SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "group", "Manage a group", GROUP_DESC, group_function, GROUP_USAGE, SAF_NONE);
 
 	SWITCH_ADD_API(commands_api_interface, "db", "db get/set", db_api_function, "[get|set]/<realm>/<key>/<value>");
-	SWITCH_ADD_API(commands_api_interface, "group", "group [add|del|call]", group_api_function, "[add|del|call] <group name> <url>");
+	SWITCH_ADD_API(commands_api_interface, "group", "group [insert|delete|call]", group_api_function, "[insert|delete|call] <group name> <url>");
 
     /* indicate that the module should continue to be loaded */
     return SWITCH_STATUS_SUCCESS;

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	Tue Nov 13 14:58:44 2007
@@ -1994,8 +1994,6 @@
 		
 		
 		if (!switch_strlen_zero(from_user)) {
-			switch_channel_set_variable(channel, "sip_mailbox", from_user);
-
 			if (*from_user == '+') {
 				switch_channel_set_variable(channel, "sip_from_user_stripped", (const char *) (from_user + 1));
 			} else {

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 Nov 13 14:58:44 2007
@@ -981,6 +981,9 @@
 			switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "sip_mailbox", "%s", mailbox);
 			switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "sip_auth_username", "%s", username);
 			switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "sip_auth_realm", "%s", realm);
+			switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "mailbox", "%s", mailbox);
+			switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "user_name", "%s", username);
+			switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "domain_name", "%s", realm);
 			
 			if ((xparams = switch_xml_child(user, "variables"))) {
 				for (param = switch_xml_child(xparams, "variable"); param; param = param->next) {



More information about the Freeswitch-svn mailing list