added filtering options to 'zap show channels' to implement functionality described...
authorDwayne M. Hubbard <dwayne.hubbard@gmail.com>
Wed, 28 Mar 2007 00:09:25 +0000 (00:09 +0000)
committerDwayne M. Hubbard <dwayne.hubbard@gmail.com>
Wed, 28 Mar 2007 00:09:25 +0000 (00:09 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@59286 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_zap.c

index 8dd5d09..30f74d7 100644 (file)
@@ -10714,6 +10714,8 @@ static int zap_show_channels(int fd, int argc, char **argv)
 {
 #define FORMAT "%7s %-10.10s %-15.15s %-10.10s %-20.20s %-10.10s %-10.10s\n"
 #define FORMAT2 "%7s %-10.10s %-15.15s %-10.10s %-20.20s %-10.10s %-10.10s\n"
+       unsigned int targetnum = 0;
+       int filtertype = 0;
        struct zt_pvt *tmp = NULL;
        char tmps[20] = "";
        char statestr[20] = "";
@@ -10729,27 +10731,42 @@ static int zap_show_channels(int fd, int argc, char **argv)
        lock = &iflock;
        start = iflist;
 
+       /* syntax: zap show channels [ group <group> | context <context> | trunkgroup <trunkgroup> ] */
+
+       if (!((argc == 3) || (argc == 5)))
+               return RESULT_SHOWUSAGE;
+
+       if (argc == 5) {
 #ifdef HAVE_PRI
-       if (argc == 4) {
-               if ((trunkgroup = atoi(argv[3])) < 1)
-                       return RESULT_SHOWUSAGE;
-               for (x = 0; x < NUM_SPANS; x++) {
-                       if (pris[x].trunkgroup == trunkgroup) {
-                               pri = pris + x;
-                               break;
+               if (!strcasecmp(argv[3], "trunkgroup")) {
+                       /* this option requires no special handling, so leave filtertype to zero */
+                       if ((trunkgroup = atoi(argv[4])) < 1)
+                               return RESULT_SHOWUSAGE;
+                       for (x = 0; x < NUM_SPANS; x++) {
+                               if (pris[x].trunkgroup == trunkgroup) {
+                                       pri = pris + x;
+                                       break;
+                               }
                        }
+                       if (pri) {
+                               start = pri->crvs;
+                               lock = &pri->lock;
+                       } else {
+                               ast_cli(fd, "No such trunk group %d\n", trunkgroup);
+                               return RESULT_FAILURE;
+                       }
+               } else
+#endif 
+               if (!strcasecmp(argv[3], "group")) {
+                       targetnum = atoi(argv[4]);
+                       if ((targetnum < 0) || (targetnum > 63))
+                               return RESULT_SHOWUSAGE;
+                       targetnum = 1 << targetnum;
+                       filtertype = 1;
+               } else if (!strcasecmp(argv[3], "context")) {
+                       filtertype = 2;
                }
-               if (pri) {
-                       start = pri->crvs;
-                       lock = &pri->lock;
-               } else {
-                       ast_cli(fd, "No such trunk group %d\n", trunkgroup);
-                       return RESULT_FAILURE;
-               }
-       } else
-#endif
-       if (argc != 3)
-               return RESULT_SHOWUSAGE;
+       }
 
        ast_mutex_lock(lock);
 #ifdef HAVE_PRI
@@ -10760,6 +10777,24 @@ static int zap_show_channels(int fd, int argc, char **argv)
        
        tmp = start;
        while (tmp) {
+               if (filtertype) {
+                       switch(filtertype) {
+                       case 1: /* zap show channels group <group> */
+                               if (tmp->group != targetnum) {
+                                       tmp = tmp->next;
+                                       continue;
+                               }
+                               break;
+                       case 2: /* zap show channels context <context> */
+                               if (strcasecmp(tmp->context, argv[4])) {
+                                       tmp = tmp->next;
+                                       continue;
+                               }
+                               break;
+                       default:
+                               ;
+                       }
+               }
                if (tmp->channel > 0) {
                        snprintf(tmps, sizeof(tmps), "%d", tmp->channel);
                } else
@@ -11039,8 +11074,9 @@ static int zap_show_version(int fd, int argc, char *argv[])
 }
 
 static const char show_channels_usage[] =
-       "Usage: zap show channels\n"
-       "       Shows a list of available channels\n";
+       "Usage: zap show channels [ trunkgroup <trunkgroup> | group <group> | context <context> ]\n"
+       "       Shows a list of available channels with optional filtering\n"
+       "       <group> must be a number between 0 and 63\n";
 
 static const char show_channel_usage[] =
        "Usage: zap show channel <chan num>\n"