Opaquify char * and char[] in ast_channel
[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
45 /*** DOCUMENTATION
46         <application name="DumpChan" language="en_US">
47                 <synopsis>
48                         Dump Info About The Calling Channel.
49                 </synopsis>
50                 <syntax>
51                         <parameter name="level">
52                                 <para>Minimun verbose level</para>
53                         </parameter>
54                 </syntax>
55                 <description>
56                         <para>Displays information on channel and listing of all channel
57                         variables. If <replaceable>level</replaceable> is specified, output is only
58                         displayed when the verbose level is currently set to that number
59                         or greater.</para>
60                 </description>
61                 <see-also>
62                         <ref type="application">NoOp</ref>
63                         <ref type="application">Verbose</ref>
64                 </see-also>
65         </application>
66  ***/
67
68 static const char app[] = "DumpChan";
69
70 static int serialize_showchan(struct ast_channel *c, char *buf, size_t size)
71 {
72         struct timeval now;
73         long elapsed_seconds = 0;
74         int hour = 0, min = 0, sec = 0;
75         char nf[256];
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
81         now = ast_tvnow();
82         memset(buf, 0, size);
83         if (!c)
84                 return 0;
85
86         if (c->cdr) {
87                 elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
88                 hour = elapsed_seconds / 3600;
89                 min = (elapsed_seconds % 3600) / 60;
90                 sec = elapsed_seconds % 60;
91         }
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 (%d)\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=           %d %s\n"
117                 "Framesout=          %d %s\n"
118                 "TimetoHangup=       %ld\n"
119                 "ElapsedTime=        %dh%dm%ds\n"
120                 "DirectBridge=       %s\n"
121                 "IndirectBridge=     %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                 c->tech->type,
132                 ast_channel_uniqueid(c),
133                 ast_channel_linkedid(c),
134                 S_COR(c->caller.id.number.valid, c->caller.id.number.str, "(N/A)"),
135                 S_COR(c->caller.id.name.valid, c->caller.id.name.str, "(N/A)"),
136                 S_COR(c->connected.id.number.valid, c->connected.id.number.str, "(N/A)"),
137                 S_COR(c->connected.id.name.valid, c->connected.id.name.str, "(N/A)"),
138                 S_OR(c->dialed.number.str, "(N/A)"),
139                 S_COR(c->redirecting.from.number.valid, c->redirecting.from.number.str, "(N/A)"),
140                 ast_channel_parkinglot(c),
141                 ast_channel_language(c),        
142                 ast_state2str(c->_state),
143                 c->_state,
144                 c->rings, 
145                 ast_getformatname_multiple(nf, sizeof(nf), c->nativeformats),
146                 ast_getformatname(&c->writeformat),
147                 ast_getformatname(&c->readformat),
148                 ast_getformatname(&c->rawwriteformat),
149                 ast_getformatname(&c->rawreadformat),
150                 c->writetrans ? "Yes" : "No",
151                 ast_translate_path_to_str(c->writetrans, &write_transpath),
152                 c->readtrans ? "Yes" : "No",
153                 ast_translate_path_to_str(c->readtrans, &read_transpath),
154                 c->fds[0],
155                 c->fin & ~DEBUGCHAN_FLAG, (c->fin & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
156                 c->fout & ~DEBUGCHAN_FLAG, (c->fout & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
157                 (long)c->whentohangup.tv_sec,
158                 hour,
159                 min,
160                 sec,
161                 c->_bridge ? ast_channel_name(c->_bridge) : "<none>",
162                 ast_bridged_channel(c) ? ast_channel_name(ast_bridged_channel(c)) : "<none>", 
163                 ast_channel_context(c),
164                 ast_channel_exten(c),
165                 c->priority,
166                 ast_print_group(cgrp, sizeof(cgrp), c->callgroup),
167                 ast_print_group(pgrp, sizeof(pgrp), c->pickupgroup),
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(c, AST_FLAG_BLOCKING) ? ast_channel_blockproc(c) : "(Not Blocking)"));
171
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 (option_verbose >= level) {
186                 serialize_showchan(chan, info, sizeof(info));
187                 pbx_builtin_serialize_variables(chan, &vars);
188                 ast_verbose("\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");