]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
enhance the show command
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 20 Jul 2006 03:55:07 +0000 (03:55 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 20 Jul 2006 03:55:07 +0000 (03:55 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@2011 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/applications/mod_commands/mod_commands.c
src/switch_channel.c
src/switch_core.c

index e2599f9c73a5666198ce9fdb25503cf5ff8576be..a21bcc39daa9e849de939ab31fa7ab90f0b85aa7 100644 (file)
@@ -186,15 +186,46 @@ static switch_status_t pause_function(char *cmd, switch_stream_handle_t *stream)
 
 struct holder {
        switch_stream_handle_t *stream;
+       char *http;
        uint32_t count;
 };
 
-
-
 static int show_callback(void *pArg, int argc, char **argv, char **columnNames){
        struct holder *holder = (struct holder *) pArg;
+       int x;
+
+
+       if (holder->count == 0) {
+               if (holder->http) {
+                       holder->stream->write_function(holder->stream, "\n<tr>");
+               }
+
+               for(x = 0; x < argc; x++) {
+                       if (holder->http) {
+                               holder->stream->write_function(holder->stream, "<td>");
+                               holder->stream->write_function(holder->stream, "<b>%s</b>%s", columnNames[x], x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
+                       } else {
+                               holder->stream->write_function(holder->stream, "%s%s", columnNames[x], x == (argc - 1) ? "\n" : ",");
+                       }
+               }
+       } 
+
+       if (holder->http) {
+               holder->stream->write_function(holder->stream, "<tr bgcolor=%s>", holder->count % 2 == 0 ? "eeeeee" : "ffffff");
+       }
+
+       for(x = 0; x < argc; x++) {
+               if (holder->http) {
+                       holder->stream->write_function(holder->stream, "<td>");
+                       holder->stream->write_function(holder->stream, "%s%s", argv[x], x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
+               } else {
+                       holder->stream->write_function(holder->stream, "%s%s", argv[x], x == (argc - 1) ? "\n" : ",");
+               }
+       }
+       
+
+
 
-       holder->stream->write_function(holder->stream, "%s|%s\n", argv[0], argv[1] ? argv[1] : "NULL");
        holder->count++;
        return 0;
 }
@@ -204,8 +235,12 @@ static switch_status_t show_function(char *cmd, switch_stream_handle_t *stream)
        char sql[1024];
        char *errmsg;
        switch_core_db_t *db = switch_core_db_handle();
-       struct holder holder;
-       
+       struct holder holder = {0};
+
+       if (stream->event) {
+        holder.http = switch_event_get_header(stream->event, "http-host");
+    } 
+
     if (!cmd) {
         sprintf (sql, "select * from interfaces");
     }
@@ -231,14 +266,23 @@ static switch_status_t show_function(char *cmd, switch_stream_handle_t *stream)
        holder.stream = stream;
        holder.count = 0;
 
+       if (holder.http) {
+               holder.stream->write_function(holder.stream, "<table cellpadding=1 cellspacing=4 border=1>\n");
+       }
+
        switch_core_db_exec(db, sql, show_callback, &holder, &errmsg);
 
+       if (holder.http) {
+               holder.stream->write_function(holder.stream, "</table>");
+       }
+
+
        if (errmsg) {
                stream->write_function(stream, "SQL ERR [%s]\n",errmsg);
                switch_core_db_free(errmsg);
                errmsg = NULL;
        } else {
-               stream->write_function(stream, "%u total.\n", holder.count);
+               stream->write_function(stream, "\n%u total.\n", holder.count);
        }
 
        switch_core_db_close(db);
index 69926368bcb70ea0a3adb08e07f6981f9da95672..d6ad600b17bdb6196f97060044e4c686723a1114 100644 (file)
@@ -593,6 +593,7 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel_t *channel, sw
 {
        switch_caller_profile_t *caller_profile, *originator_caller_profile, *originatee_caller_profile;
        switch_hash_index_t *hi;
+       switch_codec_t *codec;
        void *val;
        const void *var;
        char state_num[25];
@@ -606,7 +607,16 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel_t *channel, sw
        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-State-Number", (char *) state_num);
        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Name", switch_channel_get_name(channel));
        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(channel->session));
-
+       
+       if ((codec = switch_core_session_get_read_codec(channel->session))) {
+               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Read-Codec-Name", codec->implementation->iananame);
+               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Read-Codec-Rate", "%u", codec->implementation->samples_per_second);
+       }
+       
+       if ((codec = switch_core_session_get_write_codec(channel->session))) {
+               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Name", codec->implementation->iananame);
+               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Rate", "%u", codec->implementation->samples_per_second);
+       }
 
        /* Index Caller's Profile */
        if (caller_profile) {
index 7126abb0e290aaa5972fd0a6d94a897ba954acf0..886a4af3442f68f51ba7e1494bd0b17361d39d38 100644 (file)
@@ -2821,9 +2821,13 @@ static void core_event_handler(switch_event_t *event)
                                                                         );
                break;
        case SWITCH_EVENT_CHANNEL_EXECUTE:
-               sql = switch_core_db_mprintf("update channels set application='%q',application_data='%q' where uuid='%q'",
+               sql = switch_core_db_mprintf("update channels set application='%q',application_data='%q', read_codec='%q',read_rate='%q',write_codec='%q',write_rate='%q' where uuid='%q'",
                                                                         switch_event_get_header(event, "application"),
                                                                         switch_event_get_header(event, "application-data"),
+                                                                        switch_event_get_header(event, "channel-read-codec-name"),
+                                                                        switch_event_get_header(event, "channel-read-codec-rate"),
+                                                                        switch_event_get_header(event, "channel-write-codec-name"),
+                                                                        switch_event_get_header(event, "channel-write-codec-rate"),
                                                                         switch_event_get_header(event, "unique-id")
                                                                         );
                break;
@@ -3018,7 +3022,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(char *console, const char **err
                        "   ip_addr  VARCHAR(255),\n"
                        "   dest  VARCHAR(255),\n"
                        "   application  VARCHAR(255),\n"
-                       "   application_data  VARCHAR(255)\n"
+                       "   application_data  VARCHAR(255),\n"
+                       "   read_codec  VARCHAR(255),\n"
+                       "   read_rate  VARCHAR(255),\n"
+                       "   write_codec  VARCHAR(255),\n"
+                       "   write_rate  VARCHAR(255)\n"
                        ");\n";
                char create_calls_sql[] =
                        "CREATE TABLE calls (\n"