Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 89189) +++ channels/chan_sip.c (working copy) @@ -11867,6 +11867,8 @@ #define FORMAT3 "%-15.15s %-10.10s %-11.11s %-15.15s %-13.13s %-15.15s %-10.10s\n" #define FORMAT2 "%-15.15s %-10.10s %-11.11s %-11.11s %-4.4s %-7.7s %-15.15s\n" #define FORMAT "%-15.15s %-10.10s %-11.11s %5.5d/%5.5d %-4.4s %-3.3s %-3.3s %-15.15s %-10.10s\n" +#define CONCISE_FORMAT_CHAN "%s!%s!%s!%5.5d/%5.5d!%s!%s!%s!%s!%s\n" +#define CONCISE_FORMAT_SUB "%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) @@ -11880,31 +11882,58 @@ /* set if SIP transfer in progress */ const char *referstatus = cur->refer ? referstatus2str(cur->refer->status) : ""; - ast_cli(arg->fd, FORMAT, ast_inet_ntoa(dst->sin_addr), - S_OR(cur->username, S_OR(cur->cid_num, "(None)")), - cur->callid, - cur->ocseq, cur->icseq, - ast_getformatname(cur->owner ? cur->owner->nativeformats : 0), - cli_yesno(ast_test_flag(&cur->flags[1], SIP_PAGE2_CALL_ONHOLD)), - cur->needdestroy ? "(d)" : "", - cur->lastmsg , - referstatus - ); + if (flags) { + ast_cli(arg->fd, CONCISE_FORMAT_CHAN, ast_inet_ntoa(dst->sin_addr), + S_OR(cur->username, S_OR(cur->cid_num, "(None)")), + cur->callid, + cur->ocseq, cur->icseq, + ast_getformatname(cur->owner ? cur->owner->nativeformats : 0), + cli_yesno(ast_test_flag(&cur->flags[1], SIP_PAGE2_CALL_ONHOLD)), + cur->needdestroy ? "(d)" : "", + cur->lastmsg , + referstatus + ); + } + else { + ast_cli(arg->fd, FORMAT, ast_inet_ntoa(dst->sin_addr), + S_OR(cur->username, S_OR(cur->cid_num, "(None)")), + cur->callid, + cur->ocseq, cur->icseq, + ast_getformatname(cur->owner ? cur->owner->nativeformats : 0), + cli_yesno(ast_test_flag(&cur->flags[1], SIP_PAGE2_CALL_ONHOLD)), + cur->needdestroy ? "(d)" : "", + cur->lastmsg , + referstatus + ); + } arg->numchans++; } if (cur->subscribed != NONE && arg->subscriptions) { 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), - 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 */ - cur->subscribed == MWI_NOTIFICATION ? "--" : cur->subscribeuri, - cur->subscribed == MWI_NOTIFICATION ? "" : ast_extension_state2str(cur->laststate), - subscription_type2str(cur->subscribed), - cur->subscribed == MWI_NOTIFICATION ? S_OR(mailbox_str->str, "") : "" -); + if (flags) { + ast_cli(arg->fd, CONCISE_FORMAT_SUB, 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 */ + cur->subscribed == MWI_NOTIFICATION ? "--" : cur->subscribeuri, + cur->subscribed == MWI_NOTIFICATION ? "" : ast_extension_state2str(cur->laststate), + subscription_type2str(cur->subscribed), + cur->subscribed == MWI_NOTIFICATION ? S_OR(mailbox_str->str, "") : "" + ); + } + else { + ast_cli(arg->fd, FORMAT3, 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 */ + cur->subscribed == MWI_NOTIFICATION ? "--" : cur->subscribeuri, + cur->subscribed == MWI_NOTIFICATION ? "" : ast_extension_state2str(cur->laststate), + subscription_type2str(cur->subscribed), + cur->subscribed == MWI_NOTIFICATION ? S_OR(mailbox_str->str, "") : "" + ); + } arg->numchans++; } @@ -11920,41 +11949,54 @@ { struct sip_pvt *cur; struct __show_chan_arg arg = { .fd = a->fd, .numchans = 0 }; + int 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" - " Lists all currently active SIP channels.\n" - "Usage: sip show subscriptions\n" - " Lists active SIP subscriptions for extension states\n"; + "Usage: sip show channels [concise]\n" + " Lists all currently active SIP channels. If 'concise' is specified,\n" + " the format is abridged and in a more easily machine parsable format.\n" + "Usage: sip show subscriptions [concise]\n" + " Lists active SIP subscriptions for extension states. If 'concise' is\n" + " specified, the format is abridged and in a more easily machine\n" + " parsable format.\n"; return NULL; } else if (cmd == CLI_GENERATE) return NULL; - if (a->argc != e->args) + if (a->argc == e->args) { + if (!strcasecmp(a->argv[e->args - 1], "concise")) + concise = 1; + } else if (a->argc != e->args - 1) return CLI_SHOWUSAGE; - arg.subscriptions = !strcasecmp(a->argv[e->args - 1], "subscriptions"); - if (!arg.subscriptions) - ast_cli(arg.fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Seq (Tx/Rx)", "Format", "Hold", "Last Message"); - else - ast_cli(arg.fd, FORMAT3, "Peer", "User", "Call ID", "Extension", "Last state", "Type", "Mailbox"); + arg.subscriptions = !strcasecmp(a->argv[e->args - 2], "subscriptions"); + if (!concise) { + if (!arg.subscriptions) + ast_cli(arg.fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Seq (Tx/Rx)", "Format", "Hold", "Last Message"); + 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, concise); } dialoglist_unlock(); /* print summary information */ - ast_cli(arg.fd, "%d active SIP %s%s\n", arg.numchans, - (arg.subscriptions ? "subscription" : "channel"), - ESS(arg.numchans)); /* ESS(n) returns an "s" if n>1 */ + if (!concise) + ast_cli(arg.fd, "%d active SIP %s%s\n", arg.numchans, + (arg.subscriptions ? "subscription" : "channel"), + ESS(arg.numchans)); /* ESS(n) returns an "s" if n>1 */ return CLI_SUCCESS; #undef FORMAT #undef FORMAT2 #undef FORMAT3 +#undef CONCISE_FORMAT_SUB +#undef CONCISE_FORMAT_CHAN } /*! \brief Support routine for 'sip show channel' and 'sip show history' CLI