--- orig/asterisk-1.6.0.10/channels/chan_sip.c 2009-04-06 12:48:51.000000000 -0400 +++ asterisk-1.6.0.10/channels/chan_sip.c 2009-07-14 14:11:09.000000000 -0400 @@ -13623,27 +13623,34 @@ static const struct cfsubscription_types struct __show_chan_arg { int fd; int subscriptions; - int numchans; /* return value */ + int concise; + int numchans; /* return value */ }; #define FORMAT3 "%-15.15s %-10.10s %-15.15s %-15.15s %-13.13s %-15.15s %-10.10s\n" #define FORMAT2 "%-15.15s %-10.10s %-15.15s %-15.15s %-7.7s %-15.15s\n" #define FORMAT "%-15.15s %-10.10s %-15.15s %-15.15s %-3.3s %-3.3s %-15.15s %-10.10s\n" +#define FORMATC "%s|%s|%s|%s|%s|%s|%s\n" /*! \brief callback for show channel|subscription */ -static int show_channels_cb(void *__cur, void *__arg, int flags) +static int show_channels_cb(void *__cur, void *__arg, int flags, int concise) { struct sip_pvt *cur = __cur; struct __show_chan_arg *arg = __arg; const struct sockaddr_in *dst = sip_real_dst(cur); - + char *output_format = FORMAT; + /* XXX indentation preserved to reduce diff. Will be fixed later */ if (cur->subscribed == NONE && !arg->subscriptions) { /* set if SIP transfer in progress */ const char *referstatus = cur->refer ? referstatus2str(cur->refer->status) : ""; char formatbuf[SIPBUFSIZE/2]; - ast_cli(arg->fd, FORMAT, ast_inet_ntoa(dst->sin_addr), + output_format = FORMAT; + if (concise) + output_format = FORMATC; + + ast_cli(arg->fd, output_format, ast_inet_ntoa(dst->sin_addr), S_OR(cur->username, S_OR(cur->cid_num, "(None)")), cur->callid, ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->owner ? cur->owner->nativeformats : 0), @@ -13658,7 +13665,12 @@ static int show_channels_cb(void *__cur, struct ast_str *mailbox_str = ast_str_alloca(512); if (cur->subscribed == MWI_NOTIFICATION && cur->relatedpeer) peer_mailboxes_to_str(&mailbox_str, cur->relatedpeer); - ast_cli(arg->fd, FORMAT3, ast_inet_ntoa(dst->sin_addr), + + output_format = FORMAT3; + if (concise) + output_format = FORMATC; + + ast_cli(arg->fd, output_format, ast_inet_ntoa(dst->sin_addr), S_OR(cur->username, S_OR(cur->cid_num, "(None)")), cur->callid, /* the 'complete' exten/context is hidden in the refer_to field for subscriptions */ @@ -13681,38 +13693,48 @@ static int show_channels_cb(void *__cur, static char *sip_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct sip_pvt *cur; - struct __show_chan_arg arg = { .fd = a->fd, .numchans = 0 }; + struct __show_chan_arg arg = { .fd = a->fd, .numchans = 0, .concise = 0 }; if (cmd == CLI_INIT) { - e->command = "sip show {channels|subscriptions}"; + e->command = "sip show {channels|subscriptions} [concise]"; e->usage = - "Usage: sip show channels\n" + "Usage: sip show channels [concise]\n" " Lists all currently active SIP calls (dialogs).\n" - "Usage: sip show subscriptions\n" + "Usage: sip show subscriptions [concise]\n" " Lists active SIP subscriptions.\n"; return NULL; } else if (cmd == CLI_GENERATE) return NULL; - if (a->argc != e->args) + if (a->argc < 3) return CLI_SHOWUSAGE; - arg.subscriptions = !strcasecmp(a->argv[e->args - 1], "subscriptions"); - if (!arg.subscriptions) + + arg.subscriptions = !strcasecmp(a->argv[2], "subscriptions"); + + if (a->argc > 3) + arg.concise = !strcasecmp(a->argv[3], "concise"); + + if (!arg.concise) { + if (!arg.subscriptions) ast_cli(arg.fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Format", "Hold", "Last Message"); - else + else ast_cli(arg.fd, FORMAT3, "Peer", "User", "Call ID", "Extension", "Last state", "Type", "Mailbox"); - + } + /* iterate on the container and invoke the callback on each item */ dialoglist_lock(); for (cur = dialoglist; cur; cur = cur->next) { - show_channels_cb(cur, &arg, 0); + show_channels_cb(cur, &arg, 0, arg.concise); } dialoglist_unlock(); /* print summary information */ - ast_cli(arg.fd, "%d active SIP %s%s\n", arg.numchans, - (arg.subscriptions ? "subscription" : "dialog"), - ESS(arg.numchans)); /* ESS(n) returns an "s" if n>1 */ + if (!arg.concise) { + ast_cli(arg.fd, "%d active SIP %s%s\n", arg.numchans, + (arg.subscriptions ? "subscription" : "dialog"), + ESS(arg.numchans)); /* ESS(n) returns an "s" if n>1 */ + } + return CLI_SUCCESS; #undef FORMAT #undef FORMAT2