2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2004 - 2005, Anthony Minessale II.
6 * Anthony Minessale <anthmct@yahoo.com>
8 * A license has been granted to Digium (via disclaimer) for the use of
11 * See http://www.asterisk.org for more information about
12 * the Asterisk project. Please do not directly contact
13 * any of the maintainers of this project for assistance;
14 * the project provides a web site, mailing lists and IRC
15 * channels for your use.
17 * This program is free software, distributed under the terms of
18 * the GNU General Public License Version 2. See the LICENSE file
19 * at the top of the source tree.
24 * \brief Application to dump channel variables
26 * \author Anthony Minessale <anthmct@yahoo.com>
28 * \ingroup applications
32 <support_level>core</support_level>
37 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
39 #include "asterisk/pbx.h"
40 #include "asterisk/module.h"
41 #include "asterisk/channel.h"
42 #include "asterisk/app.h"
43 #include "asterisk/translate.h"
44 #include "asterisk/bridge.h"
47 <application name="DumpChan" language="en_US">
49 Dump Info About The Calling Channel.
52 <parameter name="level">
53 <para>Minimum verbose level</para>
57 <para>Displays information on channel and listing of all channel
58 variables. If <replaceable>level</replaceable> is specified, output is only
59 displayed when the verbose level is currently set to that number
63 <ref type="application">NoOp</ref>
64 <ref type="application">Verbose</ref>
69 static const char app[] = "DumpChan";
71 static int serialize_showchan(struct ast_channel *c, char *buf, size_t size)
73 long elapsed_seconds = 0;
74 int hour = 0, min = 0, sec = 0;
75 struct ast_str *format_buf = ast_str_alloca(64);
78 struct ast_str *write_transpath = ast_str_alloca(256);
79 struct ast_str *read_transpath = ast_str_alloca(256);
80 struct ast_bridge *bridge;
86 elapsed_seconds = ast_channel_get_duration(c);
87 hour = elapsed_seconds / 3600;
88 min = (elapsed_seconds % 3600) / 60;
89 sec = elapsed_seconds % 60;
92 bridge = ast_channel_get_bridge(c);
93 ast_channel_unlock(c);
102 "ConnectedLineIDNum= %s\n"
103 "ConnectedLineIDName=%s\n"
113 "RawWriteFormat= %s\n"
114 "RawReadFormat= %s\n"
115 "WriteTranscode= %s %s\n"
116 "ReadTranscode= %s %s\n"
117 "1stFileDescriptor= %d\n"
120 "TimetoHangup= %ld\n"
121 "ElapsedTime= %dh%dm%ds\n"
132 ast_channel_tech(c)->type,
133 ast_channel_uniqueid(c),
134 ast_channel_linkedid(c),
135 S_COR(ast_channel_caller(c)->id.number.valid, ast_channel_caller(c)->id.number.str, "(N/A)"),
136 S_COR(ast_channel_caller(c)->id.name.valid, ast_channel_caller(c)->id.name.str, "(N/A)"),
137 S_COR(ast_channel_connected(c)->id.number.valid, ast_channel_connected(c)->id.number.str, "(N/A)"),
138 S_COR(ast_channel_connected(c)->id.name.valid, ast_channel_connected(c)->id.name.str, "(N/A)"),
139 S_OR(ast_channel_dialed(c)->number.str, "(N/A)"),
140 S_COR(ast_channel_redirecting(c)->from.number.valid, ast_channel_redirecting(c)->from.number.str, "(N/A)"),
141 ast_channel_parkinglot(c),
142 ast_channel_language(c),
143 ast_state2str(ast_channel_state(c)),
144 ast_channel_state(c),
145 ast_channel_rings(c),
146 ast_format_cap_get_names(ast_channel_nativeformats(c), &format_buf),
147 ast_format_get_name(ast_channel_writeformat(c)),
148 ast_format_get_name(ast_channel_readformat(c)),
149 ast_format_get_name(ast_channel_rawwriteformat(c)),
150 ast_format_get_name(ast_channel_rawreadformat(c)),
151 ast_channel_writetrans(c) ? "Yes" : "No",
152 ast_translate_path_to_str(ast_channel_writetrans(c), &write_transpath),
153 ast_channel_readtrans(c) ? "Yes" : "No",
154 ast_translate_path_to_str(ast_channel_readtrans(c), &read_transpath),
155 ast_channel_fd(c, 0),
156 ast_channel_fin(c) & ~DEBUGCHAN_FLAG, (ast_channel_fin(c) & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
157 ast_channel_fout(c) & ~DEBUGCHAN_FLAG, (ast_channel_fout(c) & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
158 (long)ast_channel_whentohangup(c)->tv_sec,
162 bridge ? bridge->uniqueid : "(Not bridged)",
163 ast_channel_context(c),
164 ast_channel_exten(c),
165 ast_channel_priority(c),
166 ast_print_group(cgrp, sizeof(cgrp), ast_channel_callgroup(c)),
167 ast_print_group(pgrp, sizeof(pgrp), ast_channel_pickupgroup(c)),
168 ast_channel_appl(c) ? ast_channel_appl(c) : "(N/A)",
169 ast_channel_data(c) ? S_OR(ast_channel_data(c), "(Empty)") : "(None)",
170 (ast_test_flag(ast_channel_flags(c), AST_FLAG_BLOCKING) ? ast_channel_blockproc(c) : "(Not Blocking)"));
176 static int dumpchan_exec(struct ast_channel *chan, const char *data)
178 struct ast_str *vars = ast_str_thread_get(&ast_str_thread_global_buf, 16);
181 static char *line = "================================================================================";
183 if (!ast_strlen_zero(data))
186 if (VERBOSITY_ATLEAST(level)) {
187 serialize_showchan(chan, info, sizeof(info));
188 pbx_builtin_serialize_variables(chan, &vars);
190 "Dumping Info For Channel: %s:\n"
195 "%s%s\n", ast_channel_name(chan), line, info, ast_str_buffer(vars), line);
201 static int unload_module(void)
203 return ast_unregister_application(app);
206 static int load_module(void)
208 return ast_register_application_xml(app, dumpchan_exec);
211 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dump Info About The Calling Channel");