codec_dahdi: Cannot use struct ast_translator.core_{src,src}_codec.
[asterisk/asterisk.git] / apps / app_dumpchan.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2004 - 2005, Anthony Minessale II.
5  *
6  * Anthony Minessale <anthmct@yahoo.com>
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 <anthmct@yahoo.com>
27  *
28  * \ingroup applications
29  */
30
31 /*** MODULEINFO
32         <support_level>core</support_level>
33  ***/
34
35 #include "asterisk.h"
36
37 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
38
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"
45
46 /*** DOCUMENTATION
47         <application name="DumpChan" language="en_US">
48                 <synopsis>
49                         Dump Info About The Calling Channel.
50                 </synopsis>
51                 <syntax>
52                         <parameter name="level">
53                                 <para>Minimum verbose level</para>
54                         </parameter>
55                 </syntax>
56                 <description>
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
60                         or greater.</para>
61                 </description>
62                 <see-also>
63                         <ref type="application">NoOp</ref>
64                         <ref type="application">Verbose</ref>
65                 </see-also>
66         </application>
67  ***/
68
69 static const char app[] = "DumpChan";
70
71 static int serialize_showchan(struct ast_channel *c, char *buf, size_t size)
72 {
73         long elapsed_seconds = 0;
74         int hour = 0, min = 0, sec = 0;
75         struct ast_str *format_buf = ast_str_alloca(64);
76         char cgrp[256];
77         char pgrp[256];
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;
81
82         memset(buf, 0, size);
83         if (!c)
84                 return 0;
85
86         elapsed_seconds = ast_channel_get_duration(c);
87         hour = elapsed_seconds / 3600;
88         min = (elapsed_seconds % 3600) / 60;
89         sec = elapsed_seconds % 60;
90
91         ast_channel_lock(c);
92         bridge = ast_channel_get_bridge(c);
93         ast_channel_unlock(c);
94
95         snprintf(buf,size,
96                 "Name=               %s\n"
97                 "Type=               %s\n"
98                 "UniqueID=           %s\n"
99                 "LinkedID=           %s\n"
100                 "CallerIDNum=        %s\n"
101                 "CallerIDName=       %s\n"
102                 "ConnectedLineIDNum= %s\n"
103                 "ConnectedLineIDName=%s\n"
104                 "DNIDDigits=         %s\n"
105                 "RDNIS=              %s\n"
106                 "Parkinglot=         %s\n"
107                 "Language=           %s\n"
108                 "State=              %s (%u)\n"
109                 "Rings=              %d\n"
110                 "NativeFormat=       %s\n"
111                 "WriteFormat=        %s\n"
112                 "ReadFormat=         %s\n"
113                 "RawWriteFormat=     %s\n"
114                 "RawReadFormat=      %s\n"
115                 "WriteTranscode=     %s %s\n"
116                 "ReadTranscode=      %s %s\n"
117                 "1stFileDescriptor=  %d\n"
118                 "Framesin=           %u %s\n"
119                 "Framesout=          %u %s\n"
120                 "TimetoHangup=       %ld\n"
121                 "ElapsedTime=        %dh%dm%ds\n"
122                 "BridgeID=           %s\n"
123                 "Context=            %s\n"
124                 "Extension=          %s\n"
125                 "Priority=           %d\n"
126                 "CallGroup=          %s\n"
127                 "PickupGroup=        %s\n"
128                 "Application=        %s\n"
129                 "Data=               %s\n"
130                 "Blocking_in=        %s\n",
131                 ast_channel_name(c),
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,
159                 hour,
160                 min,
161                 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)"));
171
172         ao2_cleanup(bridge);
173         return 0;
174 }
175
176 static int dumpchan_exec(struct ast_channel *chan, const char *data)
177 {
178         struct ast_str *vars = ast_str_thread_get(&ast_str_thread_global_buf, 16);
179         char info[2048];
180         int level = 0;
181         static char *line = "================================================================================";
182
183         if (!ast_strlen_zero(data))
184                 level = atoi(data);
185
186         if (VERBOSITY_ATLEAST(level)) {
187                 serialize_showchan(chan, info, sizeof(info));
188                 pbx_builtin_serialize_variables(chan, &vars);
189                 ast_verb(level, "\n"
190                         "Dumping Info For Channel: %s:\n"
191                         "%s\n"
192                         "Info:\n"
193                         "%s\n"
194                         "Variables:\n"
195                         "%s%s\n", ast_channel_name(chan), line, info, ast_str_buffer(vars), line);
196         }
197
198         return 0;
199 }
200
201 static int unload_module(void)
202 {
203         return ast_unregister_application(app);
204 }
205
206 static int load_module(void)
207 {
208         return ast_register_application_xml(app, dumpchan_exec);
209 }
210
211 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dump Info About The Calling Channel");