Index: CHANGES =================================================================== --- CHANGES (revision 91174) +++ CHANGES (working copy) @@ -4,6 +4,8 @@ AMI - The manager (TCP/TLS/HTTP) -------------------------------- + * Added a new action 'CoreShowChannels' to list currently defined channels + and some information about them. * Added a new action 'SIPshowregistry' to list SIP registrations. * Added TLS support for the manager interface and HTTP server * Added the URI redirect option for the built-in HTTP server Index: main/manager.c =================================================================== --- main/manager.c (revision 91174) +++ main/manager.c (working copy) @@ -1894,6 +1894,68 @@ return 0; } +static char mandescr_coreshowchannels[] = +"Description: List currently defined channels and some information\n" +" about them.\n" +"Variables:\n" +" ActionID: Optional Action id for message matching.\n"; + +/*! \brief Manager command "CoreShowChannels" - List currently defined channels + * and some information about them. */ +static int action_coreshowchannels(struct mansession *s, const struct message *m) +{ + const char *actionid = astman_get_header(m, "ActionID"); + char actionidtext[256] = ""; + struct ast_channel *c; + int numchans = 0; + int duration, durh, durm, durs; + + if (!ast_strlen_zero(actionid)) + snprintf(actionidtext, sizeof(actionidtext), "ActionID: %s\r\n", actionid); + + astman_send_listack(s, m, "Channels will follow", "start"); + + while ((c = ast_channel_walk_locked(c)) != NULL) { + struct ast_channel *bc = ast_bridged_channel(c); + char durbuf[10] = "-"; + + if (c->cdr && !ast_tvzero(c->cdr->start)) { + duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000); + durh = duration / 3600; + durm = (duration % 3600) / 60; + durs = duration % 60; + snprintf(durbuf, sizeof(durbuf), "%02d:%02d:%02d", durh, durm, durs); + } + + astman_append(s, + "Channel: %s\r\n" + "Context: %s\r\n" + "Extension: %s\r\n" + "Priority: %d\r\n" + "State: %s\r\n" + "Application: %s\r\n" + "Data: %s\r\n" + "CallerID: %s\r\n" + "Duration: %s\r\n" + "AccountCode: %s\r\n" + "BridgedTo: %s\r\n" + "\r\n", c->name, c->context, c->exten, c->priority, ast_state2str(c->_state), + c->appl ? c->appl : "(None)", c->data ? S_OR(c->data, "(Empty)"): "(None)", + S_OR(c->cid.cid_num, ""), durbuf, S_OR(c->accountcode, ""), bc ? bc->name : "(None)"); + ast_channel_unlock(c); + numchans++; + } + + astman_append(s, + "Event: ChannelsComplete\r\n" + "EventList: Complete\r\n" + "ListItems: %d\r\n" + "%s" + "\r\n", numchans, actionidtext); + + return 0; +} + /* helper function for originate */ struct fast_originate_helper { char tech[AST_MAX_EXTENSION]; @@ -3372,6 +3434,7 @@ ast_manager_register2("WaitEvent", 0, action_waitevent, "Wait for an event to occur", mandescr_waitevent); ast_manager_register2("CoreSettings", EVENT_FLAG_SYSTEM, action_coresettings, "Show PBX core settings (version etc)", mandescr_coresettings); ast_manager_register2("CoreStatus", EVENT_FLAG_SYSTEM, action_corestatus, "Show PBX core status variables", mandescr_corestatus); + ast_manager_register2("CoreShowChannels", EVENT_FLAG_SYSTEM, action_coreshowchannels, "List currently defined channels", mandescr_coreshowchannels); ast_manager_register2("Reload", EVENT_FLAG_CONFIG, action_reload, "Send a reload event", mandescr_reload); ast_cli_register_multiple(cli_manager, sizeof(cli_manager) / sizeof(struct ast_cli_entry));