]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add vars
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 4 Dec 2007 18:52:13 +0000 (18:52 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 4 Dec 2007 18:52:13 +0000 (18:52 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6499 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/applications/mod_commands/mod_commands.c
src/switch_core_codec.c

index 4db06cccc39695a45280b4cbdf7baad733cee553..2b44abc05bafd2760797fabb522a3f7db7636aca 100644 (file)
@@ -48,23 +48,31 @@ SWITCH_STANDARD_API(find_user_function)
     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 @@ SWITCH_STANDARD_API(find_user_function)
        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 @@ SWITCH_STANDARD_API(xml_locate_function)
     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 @@ SWITCH_STANDARD_API(xml_locate_function)
     }
 
     if (argc < 4) {
-               stream->write_function(stream,  "-ERR bad args\n");
+               err = "bad args";
         goto end;
     }
 
@@ -144,13 +167,21 @@ SWITCH_STANDARD_API(xml_locate_function)
        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(xml_locate_function)
 
 }
 
-
 SWITCH_STANDARD_API(regex_function)
 {
        switch_regex_t *re = NULL;
@@ -652,7 +682,8 @@ SWITCH_STANDARD_API(tone_detect_session_function)
        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_STANDARD_API(tone_detect_session_function)
                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] == '+') {
index cde67a1ce09c92c9540aca25bf17eb64e0d01def..cc01e55d8e5e344e0dd9fb8827f004422df293b9 100644 (file)
 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_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_s
                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_codec_t *) switch_core_session_get_read_codec(switch_core_
 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_DECLARE(switch_status_t) switch_core_session_set_write_codec(switch_core_
                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;
 }