2 * Asterisk -- A telephony toolkit for Linux.
4 * Application to dump channel variables
6 * Copyright (C) 2004, Anthony Minessale II.
8 * Anthony Minessale <anthmct@yahoo.com>
10 * This program is free software, distributed under the terms of
11 * the GNU General Public License (and disclaimed to Digium)
14 #include <asterisk/file.h>
15 #include <asterisk/logger.h>
16 #include <asterisk/channel.h>
17 #include <asterisk/pbx.h>
18 #include <asterisk/module.h>
19 #include <asterisk/options.h>
20 #include <asterisk/utils.h>
21 #include <asterisk/lock.h>
26 static char *tdesc = "Dump Info About The Calling Channel";
27 static char *app = "DumpChan";
28 static char *synopsis = "Dump Info About The Calling Channel";
30 " DumpChan([<min_verbose_level>])\n"
31 "Displays information on channel and listing of all channel\n"
32 "variables. If min_verbose_level is specified, output is only\n"
33 "displayed when the verbose level is currently set to that number\n"
34 "or greater. Always returns 0.\n\n";
40 static int ast_serialize_showchan(struct ast_channel *c, char *buf, size_t size)
43 long elapsed_seconds=0;
44 int hour=0, min=0, sec=0;
45 gettimeofday(&now, NULL);
51 elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
52 hour = elapsed_seconds / 3600;
53 min = (elapsed_seconds % 3600) / 60;
54 sec = elapsed_seconds % 60;
69 "1stFileDescriptor=%d\n"
73 "ElapsedTime=%dh%dm%ds\n"
85 (c->cid.cid_num ? c->cid.cid_num : "(N/A)"),
86 (c->cid.cid_name ? c->cid.cid_name : "(N/A)"),
87 (c->cid.cid_dnid ? c->cid.cid_dnid : "(N/A)" ),
88 ast_state2str(c->_state),
94 c->fds[0], c->fin & 0x7fffffff, (c->fin & 0x80000000) ? " (DEBUGGED)" : "",
95 c->fout & 0x7fffffff, (c->fout & 0x80000000) ? " (DEBUGGED)" : "", (long)c->whentohangup,
104 ( c->appl ? c->appl : "(N/A)" ),
105 ( c-> data ? (!ast_strlen_zero(c->data) ? c->data : "(Empty)") : "(None)"),
106 (ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)"));
111 static int dumpchan_exec(struct ast_channel *chan, void *data)
118 static char *line = "================================================================================";
125 pbx_builtin_serialize_variables(chan, vars, sizeof(vars));
126 ast_serialize_showchan(chan, info, sizeof(info));
127 if (option_verbose >= level)
128 ast_verbose("\nDumping Info For Channel: %s:\n%s\nInfo:\n%s\nVariables:\n%s%s\n",chan->name,line,info,vars,line);
130 LOCAL_USER_REMOVE(u);
134 int unload_module(void)
136 STANDARD_HANGUP_LOCALUSERS;
137 return ast_unregister_application(app);
140 int load_module(void)
142 return ast_register_application(app, dumpchan_exec, synopsis, desc);
145 char *description(void)
153 STANDARD_USECOUNT(res);
159 return ASTERISK_GPL_KEY;