[Freeswitch-svn] [commit] r6501 - in freeswitch/trunk/src/mod/applications: mod_commands mod_dptools

Freeswitch SVN anthm at freeswitch.org
Tue Dec 4 14:39:14 EST 2007


Author: anthm
Date: Tue Dec  4 14:39:14 2007
New Revision: 6501

Modified:
   freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
   freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c

Log:
add some user stuff

Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	Tue Dec  4 14:39:14 2007
@@ -41,6 +41,84 @@
 SWITCH_MODULE_DEFINITION(mod_commands, mod_commands_load, NULL, NULL);
 
 
+SWITCH_STANDARD_API(user_data_function)
+{
+	switch_xml_t x_domain, xml = NULL, x_user, x_param, x_params;	
+	int argc;
+    char *mydata = NULL, *argv[3];
+	char *key = NULL, *type = NULL, *user, *domain;
+	char delim = ' ';
+	const char *err = NULL;
+	const char *container = "params", *elem = "param";
+	char *params = NULL;
+
+    if (!cmd) {
+		err = "bad args";
+        goto end;
+    }
+
+    mydata = strdup(cmd);
+    assert(mydata);
+	
+    argc = switch_separate_string(mydata, delim, argv, (sizeof(argv) / sizeof(argv[0])));
+
+    if (argc < 3) {
+		err = "bad args";
+        goto end;
+    }
+
+	user = argv[0];
+	type = argv[1];
+	key = argv[2];
+
+	if ((domain = strchr(user, '@'))) {
+		*domain++ = '\0';
+	} else {
+		domain = "cluecon.com";
+	}
+	
+	params = switch_mprintf("user=%s&domain=%s&type=%s&key=%s", user, domain, type, key);
+
+	if (switch_xml_locate_user("id", user, domain, NULL, &xml, &x_domain, &x_user, params) != SWITCH_STATUS_SUCCESS) {
+		err = "can't find user";
+		goto end;
+	}
+
+
+ end:
+
+	if (xml) {
+		if (err) {
+			//stream->write_function(stream,  "-Error %s\n", err);
+		} else {
+			if (!strcmp(type, "var")) {
+				container = "variables";
+				elem = "variable";
+			}
+
+			if ((x_params = switch_xml_child(x_user, container))) {
+				for (x_param = switch_xml_child(x_params, elem); 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 (!strcasecmp(var, key)) {
+						stream->write_function(stream, "%s", val);
+						break;
+					}
+				
+				}
+			}
+		}
+		switch_xml_free(xml);
+	}
+
+	free(mydata);
+	switch_safe_free(params);
+
+	return SWITCH_STATUS_SUCCESS;
+
+}
+
 SWITCH_STANDARD_API(find_user_function)
 {
 	switch_xml_t x_domain = NULL, x_user = NULL, xml = NULL;
@@ -1949,6 +2027,7 @@
 	SWITCH_ADD_API(commands_api_interface, "uuid_chat", "Send a chat message", uuid_chat, UUID_CHAT_SYNTAX);
 	SWITCH_ADD_API(commands_api_interface, "find_user_xml", "find a user", find_user_function, "<key> <user>@<domain>");
 	SWITCH_ADD_API(commands_api_interface, "xml_locate", "find some xml", xml_locate_function, "[root | <section> <tag> <tag_attr_name> <tag_attr_val>]");
+	SWITCH_ADD_API(commands_api_interface, "user_data", "find user data", user_data_function, "<user>@<domain> [var|param] <name>");
 
 	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_NOUNLOAD;

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 Dec  4 14:39:14 2007
@@ -1420,6 +1420,78 @@
 }
 
 
+
+/* fake chan_user */
+switch_endpoint_interface_t *user_endpoint_interface;
+static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session,
+												 switch_caller_profile_t *outbound_profile,
+												 switch_core_session_t **new_session, switch_memory_pool_t **pool);
+switch_io_routines_t user_io_routines = {
+	/*.outgoing_channel */ user_outgoing_channel
+};
+
+static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session,
+												 switch_caller_profile_t *outbound_profile,
+												 switch_core_session_t **new_session, switch_memory_pool_t **pool)
+{
+	switch_xml_t x_domain, xml = NULL, x_user, x_param, x_params;	
+	char *user = NULL, *domain = NULL;
+	const char *dest = NULL;
+	static switch_call_cause_t cause;
+	unsigned int timelimit = 60;
+
+	user = switch_core_session_strdup(session, outbound_profile->destination_number);
+
+	if (!(domain = strchr(user, '@'))) {
+		goto done;
+	}
+
+	*domain++ = '\0';
+	
+	if (switch_xml_locate_user("id", user, domain, NULL, &xml, &x_domain, &x_user, "as_channel=true") != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", user, domain);
+		goto done;
+	}
+
+	if ((x_params = switch_xml_child(x_user, "params"))) {
+		for (x_param = switch_xml_child(x_params, "param"); 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 (!strcasecmp(var, "dial-string")) {
+				dest = val;
+				break;
+			}
+
+		}
+	}
+
+ done:
+
+	if (dest) {
+		const char *var;
+		switch_channel_t *channel;
+
+		channel = switch_core_session_get_channel(session);
+		if ((var = switch_channel_get_variable(channel, "call_timeout"))) {
+			timelimit = atoi(var);
+		}
+
+		if (switch_ivr_originate(session, new_session, &cause, dest, timelimit, NULL, NULL, NULL, NULL) == SWITCH_STATUS_SUCCESS) {
+			switch_core_session_rwunlock(*new_session);
+		}
+	}
+
+	if (xml) {
+		switch_xml_free(xml);
+	}
+	
+
+	return cause;
+
+}
+
+
 #define SPEAK_DESC "Speak text to a channel via the tts interface"
 #define DISPLACE_DESC "Displace audio from a file to the channels input"
 #define SESS_REC_DESC "Starts a background recording of the entire session"
@@ -1443,6 +1515,11 @@
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 
+	user_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
+    user_endpoint_interface->interface_name = "USER";
+    user_endpoint_interface->io_routines = &user_io_routines;
+
+
  	SWITCH_ADD_API(api_interface, "strepoch", "Convert a date string into epoch time", strepoch_api_function, "<string>");
 	SWITCH_ADD_API(api_interface, "chat", "chat", chat_api_function, "<proto>|<from>|<to>|<message>");
 	SWITCH_ADD_API(api_interface, "strftime", "strftime", strftime_api_function, "<format_string>");



More information about the Freeswitch-svn mailing list