]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add count optional arg to show calls and show channels (MODAPP-103)
authorMichael Jerris <mike@jerris.com>
Mon, 23 Jun 2008 15:43:27 +0000 (15:43 +0000)
committerMichael Jerris <mike@jerris.com>
Mon, 23 Jun 2008 15:43:27 +0000 (15:43 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8816 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/applications/mod_commands/mod_commands.c

index a1a5010b7d3b5b01dccd1d81e899e7c25d14bebb..2a2663658193af5caa6cbaa621e86d540e556646 100644 (file)
@@ -1789,6 +1789,7 @@ struct holder {
        int print_title;
        switch_xml_t xml;
        int rows;
+       int justcount;
 };
 
 static int show_as_xml_callback(void *pArg, int argc, char **argv, char **columnNames)
@@ -1803,7 +1804,12 @@ static int show_as_xml_callback(void *pArg, int argc, char **argv, char **column
                        return -1;
                }
        }
-
+       
+       if (holder->justcount) {
+           holder->count++;
+           return 0;
+       }
+               
        if (!(row = switch_xml_add_child_d(holder->xml, "row", holder->rows++))) {
                return -1;
        }
@@ -1836,7 +1842,12 @@ static int show_callback(void *pArg, int argc, char **argv, char **columnNames)
 {
        struct holder *holder = (struct holder *) pArg;
        int x;
-
+       
+       if (holder->justcount) {
+           holder->count++;
+           return 0;
+       }
+       
        if (holder->print_title && holder->count == 0) {
                if (holder->http) {
                        holder->stream->write_function(holder->stream, "\n<tr>");
@@ -1911,7 +1922,7 @@ SWITCH_STANDARD_API(alias_function)
        return SWITCH_STATUS_SUCCESS;
 }
 
-#define SHOW_SYNTAX "codec|application|api|dialplan|file|timer|calls|channels|aliases|complete"
+#define SHOW_SYNTAX "codec|application|api|dialplan|file|timer|calls [count]|channels [count]|aliases|complete"
 SWITCH_STANDARD_API(show_function)
 {
        char sql[1024];
@@ -1929,13 +1940,16 @@ SWITCH_STANDARD_API(show_function)
        }
 
        db = switch_core_db_handle();
-
+       
+       holder.justcount = 0;
+       
        if (cmd && (mydata = strdup(cmd))) {
                argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
                command = argv[0];
                if (argv[2] && !strcasecmp(argv[1], "as")) {
                        as = argv[2];
                }
+               
        }
 
        if (stream->param_event) {
@@ -1962,8 +1976,20 @@ SWITCH_STANDARD_API(show_function)
                sprintf(sql, "select name, description, syntax from interfaces where type = '%s' and description != '' order by type,name", command);
        } else if (!strcasecmp(command, "calls")) {
                sprintf(sql, "select * from calls order by created_epoch");
+               if (argv[1] && !strcasecmp(argv[1],"count")) {
+                   holder.justcount = 1;
+                   if (argv[3] && !strcasecmp(argv[2], "as")) {
+                       as = argv[3];
+                   }
+               }
        } else if (!strcasecmp(command, "channels")) {
                sprintf(sql, "select * from channels order by created_epoch");
+               if (argv[1] && !strcasecmp(argv[1],"count")) {
+                   holder.justcount = 1;
+                   if (argv[3] && !strcasecmp(argv[2], "as")) {
+                       as = argv[3];
+                   }
+               }
        } else if (!strcasecmp(command, "aliases")) {
                sprintf(sql, "select * from aliases order by alias");
        } else if (!strcasecmp(command, "complete")) {