[Freeswitch-trunk] [commit] r6499 - in freeswitch/trunk/src: . mod/applications/mod_commands

Freeswitch SVN anthm at freeswitch.org
Tue Dec 4 13:52:13 EST 2007


Author: anthm
Date: Tue Dec  4 13:52:13 2007
New Revision: 6499

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

Log:
add vars

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 13:52:13 2007
@@ -48,23 +48,31 @@
     char *mydata = NULL, *argv[3];
 	char *key, *user, *domain;
 	char *xmlstr;
-
-	if (stream->event && switch_event_get_header(stream->event, "http-host")) {
+	char *path_info = NULL;
+	char delim = ' ';
+	char *host = NULL;
+	const char *err = NULL;
+	
+	if (stream->event && (host = switch_event_get_header(stream->event, "http-host"))) {
 		stream->write_function(stream,  "Content-Type: text/xml\r\n\r\n");
+		if ((path_info = switch_event_get_header(stream->event, "http-path-info"))) {
+			cmd = path_info;
+			delim = '/';
+		}
 	}
-
+	
     if (!cmd) {
-		stream->write_function(stream,  "-ERR bad args\n");
+		err = "bad args";
         goto end;
     }
 
     mydata = strdup(cmd);
     assert(mydata);
 	
-    argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+    argc = switch_separate_string(mydata, delim, argv, (sizeof(argv) / sizeof(argv[0])));
 
     if (argc < 3) {
-		stream->write_function(stream,  "-ERR bad args\n");
+		err = "bad args";
         goto end;
     }
 
@@ -73,18 +81,26 @@
 	domain = argv[2];
 
     if (!(key && user && domain)) {
-		stream->write_function(stream,  "-ERR bad args\n");
+		err = "bad args";
         goto end;
     }
 
 	if (switch_xml_locate_user(key, user, domain, NULL, &xml, &x_domain, &x_user, NULL) != SWITCH_STATUS_SUCCESS) {
-		stream->write_function(stream,  "-ERR can't find user [%s@%s]\n", user, domain);
+		err = "can't find user";
 		goto end;
 	}
 
 
  end:
 
+	if (err) {
+		if (host) {
+			stream->write_function(stream,  "<error>%s</error>\n", err);
+		} else {
+			stream->write_function(stream,  "-Error %s\n", err);
+		}
+	}
+
 	if (xml && x_user) {
 		xmlstr = switch_xml_toxml(x_user, SWITCH_FALSE);
 		assert(xmlstr);
@@ -108,21 +124,28 @@
     char *mydata = NULL, *argv[4];
 	char *section, *tag, *tag_attr_name, *tag_attr_val, *params = NULL;
 	char *xmlstr;
+	char *path_info, delim = ' ';
+	char *host = NULL;
+	const char *err = NULL;
+
+	if (stream->event && (host = switch_event_get_header(stream->event, "http-host"))) {
+		stream->write_function(stream,  "Content-Type: text/xml\r\n\r\n");
+		if ((path_info = switch_event_get_header(stream->event, "http-path-info"))) {
+			cmd = path_info;
+			delim = '/';
+		}
+	}
 
     if (!cmd) {
-		stream->write_function(stream,  "-ERR bad args\n");
+		err = "bad args";
         goto end;
     }
 
 
-	if (stream->event && switch_event_get_header(stream->event, "http-host")) {
-		stream->write_function(stream,  "Content-Type: text/xml\r\n\r\n");
-	}
-
     mydata = strdup(cmd);
     assert(mydata);
 	
-    argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+    argc = switch_separate_string(mydata, delim, argv, (sizeof(argv) / sizeof(argv[0])));
 
     if (argc == 1 && !strcasecmp(argv[0], "root")) {
 		const char *err;
@@ -132,7 +155,7 @@
     }
 
     if (argc < 4) {
-		stream->write_function(stream,  "-ERR bad args\n");
+		err = "bad args";
         goto end;
     }
 
@@ -144,13 +167,21 @@
 	params = switch_mprintf("section=%s&tag=%s&tag_attr_name=%s&tag_attr_val=%s", section, tag, tag_attr_name, tag_attr_val);
 	assert(params);
 	if (switch_xml_locate(section, tag, tag_attr_name, tag_attr_val, &xml, &obj, params) != SWITCH_STATUS_SUCCESS) {
-		stream->write_function(stream,  "-ERR can't find anything\n");
+		stream->write_function(stream,  "can't find anything\n");
 		goto end;
 	}
 
 
  end:
 
+	if (err) {
+		if (host) {
+			stream->write_function(stream,  "<error>%s</error>\n", err);
+		} else {
+			stream->write_function(stream,  "-Error %s\n", err);
+		}
+	}
+
 	switch_safe_free(params);
 
 	if (xml && obj) {
@@ -168,7 +199,6 @@
 
 }
 
-
 SWITCH_STANDARD_API(regex_function)
 {
 	switch_regex_t *re = NULL;
@@ -652,7 +682,8 @@
 	char *mydata = NULL;
 	time_t to = 0;
 	switch_core_session_t *rsession;
-	
+
+
 	if (!cmd) {
 		stream->write_function(stream, "-USAGE: %s\n", TONE_DETECT_SYNTAX);
 		return SWITCH_STATUS_SUCCESS;
@@ -665,11 +696,13 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "-ERR INVALID ARGS!\n");
 	}
 
+
 	if (!(rsession = switch_core_session_locate(argv[0]))) {
 		stream->write_function(stream, "-ERR Error Cannot locate session!\n");
 		return SWITCH_STATUS_SUCCESS;
 	}
 
+
 	if (argv[4]) {
 		uint32_t mto;
 		if (*argv[4] == '+') {

Modified: freeswitch/trunk/src/switch_core_codec.c
==============================================================================
--- freeswitch/trunk/src/switch_core_codec.c	(original)
+++ freeswitch/trunk/src/switch_core_codec.c	Tue Dec  4 13:52:13 2007
@@ -37,8 +37,11 @@
 SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_session_t *session, switch_codec_t *codec)
 {
 	switch_event_t *event;
+	switch_channel_t *channel;
+	char tmp[30];
 
 	assert(session != NULL);
+	channel = switch_core_session_get_channel(session);
 
 	if (switch_event_create(&event, SWITCH_EVENT_CODEC) == SWITCH_STATUS_SUCCESS) {
 		switch_channel_event_set_data(session->channel, event);
@@ -50,6 +53,10 @@
 		switch_event_fire(&event);
 	}
 
+	switch_channel_set_variable(channel, "read_codec", codec->implementation->iananame);
+	snprintf(tmp, sizeof(tmp), "%d", codec->implementation->actual_samples_per_second);
+	switch_channel_set_variable(channel, "read_rate", tmp);
+
 	session->read_codec = codec;
 	session->raw_read_frame.codec = session->read_codec;
 	session->raw_write_frame.codec = session->read_codec;
@@ -67,7 +74,12 @@
 SWITCH_DECLARE(switch_status_t) switch_core_session_set_write_codec(switch_core_session_t *session, switch_codec_t *codec)
 {
 	switch_event_t *event;
+	switch_channel_t *channel;
+	char tmp[30];
+
 	assert(session != NULL);
+	channel = switch_core_session_get_channel(session);
+
 
 	if (switch_event_create(&event, SWITCH_EVENT_CODEC) == SWITCH_STATUS_SUCCESS) {
 		switch_channel_event_set_data(session->channel, event);
@@ -79,6 +91,10 @@
 		switch_event_fire(&event);
 	}
 
+	switch_channel_set_variable(channel, "write_codec", codec->implementation->iananame);
+	snprintf(tmp, sizeof(tmp), "%d", codec->implementation->actual_samples_per_second);
+	switch_channel_set_variable(channel, "write_rate", tmp);
+
 	session->write_codec = codec;
 	return SWITCH_STATUS_SUCCESS;
 }



More information about the Freeswitch-trunk mailing list