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