Debian Codegraph @

apps/app_dumpchan.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2004 - 2005, Anthony Minessale II.
5 *
6 * Anthony Minessale <[email protected]>
7 *
8 * A license has been granted to Digium (via disclaimer) for the use of
9 * this code.
10 *
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.
16 *
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.
20 */
21
22 /*! \file
23 *
24 * \brief Application to dump channel variables
25 *
26 * \author Anthony Minessale <[email protected]>
27 *
28 * \ingroup applications
29 */
30
31 /*** MODULEINFO
32 <support_level>core</support_level>
33 ***/
34
35 #include "asterisk.h"
36
37 #include "asterisk/pbx.h"
38 #include "asterisk/module.h"
39 #include "asterisk/channel.h"
40 #include "asterisk/app.h"
41 #include "asterisk/translate.h"
42 #include "asterisk/bridge.h"
43
44 /*** DOCUMENTATION
45 <application name="DumpChan" language="en_US">
46 <since>
47 <version>1.2.0</version>
48 </since>
49 <synopsis>
50 Dump Info About The Calling Channel.
51 </synopsis>
52 <syntax>
53 <parameter name="level">
54 <para>Minimum verbose level</para>
55 </parameter>
56 </syntax>
57 <description>
58 <para>Displays information on channel and listing of all channel
59 variables. If <replaceable>level</replaceable> is specified, output is only
60 displayed when the verbose level is currently set to that number
61 or greater.</para>
62 </description>
63 <see-also>
64 <ref type="application">NoOp</ref>
65 <ref type="application">Verbose</ref>
66 </see-also>
67 </application>
68 ***/
69
70 static const char app[] = "DumpChan";
71
72 static int serialize_showchan(struct ast_channel *c, char *buf, size_t size)
73 {
74 long elapsed_seconds = 0;
75 int hour = 0, min = 0, sec = 0;
76 struct ast_str *format_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
77 char cgrp[256];
78 char pgrp[256];
79 struct ast_str *write_transpath = ast_str_alloca(256);
80 struct ast_str *read_transpath = ast_str_alloca(256);
81 struct ast_bridge *bridge;
82
83 memset(buf, 0, size);
84 if (!c)
85 return 0;
86
87 elapsed_seconds = ast_channel_get_duration(c);
88 hour = elapsed_seconds / 3600;
89 min = (elapsed_seconds % 3600) / 60;
90 sec = elapsed_seconds % 60;
91
92 ast_channel_lock(c);
93 bridge = ast_channel_get_bridge(c);
94 snprintf(buf,size,
95 "Name= %s\n"
96 "Type= %s\n"
97 "UniqueID= %s\n"
98 "LinkedID= %s\n"
99 "CallerIDNum= %s\n"
100 "CallerIDName= %s\n"
101 "ConnectedLineIDNum= %s\n"
102 "ConnectedLineIDName=%s\n"
103 "DNIDDigits= %s\n"
104 "RDNIS= %s\n"
105 "Parkinglot= %s\n"
106 "Language= %s\n"
107 "State= %s (%u)\n"
108 "Rings= %d\n"
109 "NativeFormat= %s\n"
110 "WriteFormat= %s\n"
111 "ReadFormat= %s\n"
112 "RawWriteFormat= %s\n"
113 "RawReadFormat= %s\n"
114 "WriteTranscode= %s %s\n"
115 "ReadTranscode= %s %s\n"
116 "1stFileDescriptor= %d\n"
117 "Framesin= %u %s\n"
118 "Framesout= %u %s\n"
119 "TimetoHangup= %ld\n"
120 "ElapsedTime= %dh%dm%ds\n"
121 "BridgeID= %s\n"
122 "Context= %s\n"
123 "Extension= %s\n"
124 "Priority= %d\n"
125 "CallGroup= %s\n"
126 "PickupGroup= %s\n"
127 "Application= %s\n"
128 "Data= %s\n"
129 "Blocking_in= %s\n",
130 ast_channel_name(c),
131 ast_channel_tech(c)->type,
132 ast_channel_uniqueid(c),
133 ast_channel_linkedid(c),
134 S_COR(ast_channel_caller(c)->id.number.valid, ast_channel_caller(c)->id.number.str, "(N/A)"),
135 S_COR(ast_channel_caller(c)->id.name.valid, ast_channel_caller(c)->id.name.str, "(N/A)"),
136 S_COR(ast_channel_connected(c)->id.number.valid, ast_channel_connected(c)->id.number.str, "(N/A)"),
137 S_COR(ast_channel_connected(c)->id.name.valid, ast_channel_connected(c)->id.name.str, "(N/A)"),
138 S_OR(ast_channel_dialed(c)->number.str, "(N/A)"),
139 S_COR(ast_channel_redirecting(c)->from.number.valid, ast_channel_redirecting(c)->from.number.str, "(N/A)"),
140 ast_channel_parkinglot(c),
141 ast_channel_language(c),
142 ast_state2str(ast_channel_state(c)),
143 ast_channel_state(c),
144 ast_channel_rings(c),
145 ast_format_cap_get_names(ast_channel_nativeformats(c), &format_buf),
146 ast_format_get_name(ast_channel_writeformat(c)),
147 ast_format_get_name(ast_channel_readformat(c)),
148 ast_format_get_name(ast_channel_rawwriteformat(c)),
149 ast_format_get_name(ast_channel_rawreadformat(c)),
150 ast_channel_writetrans(c) ? "Yes" : "No",
151 ast_translate_path_to_str(ast_channel_writetrans(c), &write_transpath),
152 ast_channel_readtrans(c) ? "Yes" : "No",
153 ast_translate_path_to_str(ast_channel_readtrans(c), &read_transpath),
154 ast_channel_fd(c, 0),
155 ast_channel_fin(c) & ~DEBUGCHAN_FLAG, (ast_channel_fin(c) & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
156 ast_channel_fout(c) & ~DEBUGCHAN_FLAG, (ast_channel_fout(c) & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
157 (long)ast_channel_whentohangup(c)->tv_sec,
158 hour,
159 min,
160 sec,
161 bridge ? bridge->uniqueid : "(Not bridged)",
162 ast_channel_context(c),
163 ast_channel_exten(c),
164 ast_channel_priority(c),
165 ast_print_group(cgrp, sizeof(cgrp), ast_channel_callgroup(c)),
166 ast_print_group(pgrp, sizeof(pgrp), ast_channel_pickupgroup(c)),
167 ast_channel_appl(c) ? ast_channel_appl(c) : "(N/A)",
168 ast_channel_data(c) ? S_OR(ast_channel_data(c), "(Empty)") : "(None)",
169 (ast_test_flag(ast_channel_flags(c), AST_FLAG_BLOCKING) ? ast_channel_blockproc(c) : "(Not Blocking)"));
170 ast_channel_unlock(c);
171 ao2_cleanup(bridge);
172 return 0;
173 }
174
175 static int dumpchan_exec(struct ast_channel *chan, const char *data)
176 {
177 struct ast_str *vars = ast_str_thread_get(&ast_str_thread_global_buf, 16);
178 char info[2048];
179 int level = 0;
180 static char *line = "================================================================================";
181
182 if (!ast_strlen_zero(data))
183 level = atoi(data);
184
185 if (VERBOSITY_ATLEAST(level)) {
186 serialize_showchan(chan, info, sizeof(info));
187 pbx_builtin_serialize_variables(chan, &vars);
188 ast_verb(level, "\n"
189 "Dumping Info For Channel: %s:\n"
190 "%s\n"
191 "Info:\n"
192 "%s\n"
193 "Variables:\n"
194 "%s%s\n", ast_channel_name(chan), line, info, ast_str_buffer(vars), line);
195 }
196
197 return 0;
198 }
199
200 static int unload_module(void)
201 {
202 return ast_unregister_application(app);
203 }
204
205 static int load_module(void)
206 {
207 return ast_register_application_xml(app, dumpchan_exec);
208 }
209
210 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dump Info About The Calling Channel");