static int handle_showchan(int fd, int argc, char *argv[]) { struct opbx_channel *c=NULL; struct timeval now; char buf[2048]; char cdrtime[256]; long elapsed_seconds=0; int hour=0, min=0, sec=0; if (argc != 3) return RESULT_SHOWUSAGE; now = opbx_tvnow(); c = opbx_get_channel_by_name_locked(argv[2]); if (!c) { opbx_cli(fd, "%s is not a known channel\n", argv[2]); return RESULT_SUCCESS; } if(c->cdr) { elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec; hour = elapsed_seconds / 3600; min = (elapsed_seconds % 3600) / 60; sec = elapsed_seconds % 60; snprintf(cdrtime, sizeof(cdrtime), "%dh%dm%ds", hour, min, sec); } else strcpy(cdrtime, "N/A"); opbx_cli(fd, " -- General --\n" " Name: %s\n" " Type: %s\n" " UniqueID: %s\n" " Caller ID: %s\n" " Caller ID Name: %s\n" " DNID Digits: %s\n" " State: %s (%d)\n" " Rings: %d\n" " NativeFormat: %d\n" " WriteFormat: %d\n" " ReadFormat: %d\n" "1st File Descriptor: %d\n" " Frames in: %d%s\n" " Frames out: %d%s\n" " Time to Hangup: %ld\n" " Elapsed Time: %s\n" " Direct Bridge: %s\n" "Indirect Bridge: %s\n" " -- PBX --\n" " Context: %s\n" " Extension: %s\n" " Priority: %d\n" " Call Group: %d\n" " Pickup Group: %d\n" " Application: %s\n" " Data: %s\n" " Blocking in: %s\n", c->name, c->type, c->uniqueid, (c->cid.cid_num ? c->cid.cid_num : "(N/A)"), (c->cid.cid_name ? c->cid.cid_name : "(N/A)"), (c->cid.cid_dnid ? c->cid.cid_dnid : "(N/A)" ), opbx_state2str(c->_state), c->_state, c->rings, c->nativeformats, c->writeformat, c->readformat, c->fds[0], c->fin & 0x7fffffff, (c->fin & 0x80000000) ? " (DEBUGGED)" : "", c->fout & 0x7fffffff, (c->fout & 0x80000000) ? " (DEBUGGED)" : "", (long)c->whentohangup, cdrtime, c->_bridge ? c->_bridge->name : "", opbx_bridged_channel(c) ? opbx_bridged_channel(c)->name : "", c->context, c->exten, c->priority, c->callgroup, c->pickupgroup, ( c->appl ? c->appl : "(N/A)" ), ( c-> data ? (!opbx_strlen_zero(c->data) ? c->data : "(Empty)") : "(None)"), (opbx_test_flag(c, OPBX_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)")); if(pbx_builtin_serialize_variables(c,buf,sizeof(buf))) opbx_cli(fd," Variables:\n%s\n",buf); if(c->cdr && opbx_cdr_serialize_variables(c->cdr,buf, sizeof(buf), '=', '\n', 1)) opbx_cli(fd," CDR Variables:\n%s\n",buf); opbx_mutex_unlock(&c->lock); return RESULT_SUCCESS; }