Merged revisions 81410 via svnmerge from
authorPhilippe Sultan <philippe.sultan@gmail.com>
Fri, 31 Aug 2007 17:43:50 +0000 (17:43 +0000)
committerPhilippe Sultan <philippe.sultan@gmail.com>
Fri, 31 Aug 2007 17:43:50 +0000 (17:43 +0000)
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r81410 | phsultan | 2007-08-31 19:38:26 +0200 (Fri, 31 Aug 2007) | 3 lines

Make the 'gtalk show channels' CLI command available.

Closes issue 10548, reported by keepitcool.
........

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@81411 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_gtalk.c

index 42e8401..e3e17df 100644 (file)
@@ -1568,13 +1568,54 @@ static struct ast_channel *gtalk_request(const char *type, int format, void *dat
 /*! \brief CLI command "gtalk show channels" */
 static int gtalk_show_channels(int fd, int argc, char **argv)
 {
+#define FORMAT  "%-30.30s  %-30.30s  %-15.15s  %-5.5s %-5.5s \n"
+       struct gtalk_pvt *p;
+       struct ast_channel *chan;
+       int numchans = 0;
+       char them[100];
+       char *jid = NULL;
+       char *resource = NULL;
+
        if (argc != 3)
                return RESULT_SHOWUSAGE;
+
        ast_mutex_lock(&gtalklock);
-//     if (!gtalk_list->p)
-               ast_cli(fd, "No gtalk channels in use\n");
+       ast_cli(fd, FORMAT, "Channel", "Jabber ID", "Resource", "Read", "Write");
+       ASTOBJ_CONTAINER_TRAVERSE(&gtalk_list, 1, {
+               ASTOBJ_WRLOCK(iterator);
+               p = iterator->p;
+               while(p) {
+                       chan = p->owner;
+                       ast_copy_string(them, p->them, sizeof(them));
+                       jid = them;
+                       resource = strchr(them, '/');
+                       if (!resource)
+                               resource = "None";
+                       else {
+                               *resource = '\0';
+                               resource ++;
+                       }
+                       if (chan)
+                               ast_cli(fd, FORMAT, 
+                                       chan->name,
+                                       jid,
+                                       resource,
+                                       ast_getformatname(chan->readformat),
+                                       ast_getformatname(chan->writeformat)                                    
+                                       );
+                       else 
+                               ast_log(LOG_WARNING, "No available channel\n");
+                       numchans ++;
+                       p = p->next;
+               }
+               ASTOBJ_UNLOCK(iterator);
+       });
+
        ast_mutex_unlock(&gtalklock);
+
+       ast_cli(fd, "%d active gtalk channel%s\n", numchans, (numchans != 1) ? "s" : "");
        return RESULT_SUCCESS;
+#undef FORMAT
 }
 
 /*! \brief CLI command "gtalk show channels" */