Asterisk - The Open Source Telephony Project  21.4.1
app_dumpchan.c
Go to the documentation of this file.
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  snprintf(buf,size,
92  "Name= %s\n"
93  "Type= %s\n"
94  "UniqueID= %s\n"
95  "LinkedID= %s\n"
96  "CallerIDNum= %s\n"
97  "CallerIDName= %s\n"
98  "ConnectedLineIDNum= %s\n"
99  "ConnectedLineIDName=%s\n"
100  "DNIDDigits= %s\n"
101  "RDNIS= %s\n"
102  "Parkinglot= %s\n"
103  "Language= %s\n"
104  "State= %s (%u)\n"
105  "Rings= %d\n"
106  "NativeFormat= %s\n"
107  "WriteFormat= %s\n"
108  "ReadFormat= %s\n"
109  "RawWriteFormat= %s\n"
110  "RawReadFormat= %s\n"
111  "WriteTranscode= %s %s\n"
112  "ReadTranscode= %s %s\n"
113  "1stFileDescriptor= %d\n"
114  "Framesin= %u %s\n"
115  "Framesout= %u %s\n"
116  "TimetoHangup= %ld\n"
117  "ElapsedTime= %dh%dm%ds\n"
118  "BridgeID= %s\n"
119  "Context= %s\n"
120  "Extension= %s\n"
121  "Priority= %d\n"
122  "CallGroup= %s\n"
123  "PickupGroup= %s\n"
124  "Application= %s\n"
125  "Data= %s\n"
126  "Blocking_in= %s\n",
127  ast_channel_name(c),
128  ast_channel_tech(c)->type,
129  ast_channel_uniqueid(c),
130  ast_channel_linkedid(c),
131  S_COR(ast_channel_caller(c)->id.number.valid, ast_channel_caller(c)->id.number.str, "(N/A)"),
132  S_COR(ast_channel_caller(c)->id.name.valid, ast_channel_caller(c)->id.name.str, "(N/A)"),
133  S_COR(ast_channel_connected(c)->id.number.valid, ast_channel_connected(c)->id.number.str, "(N/A)"),
134  S_COR(ast_channel_connected(c)->id.name.valid, ast_channel_connected(c)->id.name.str, "(N/A)"),
135  S_OR(ast_channel_dialed(c)->number.str, "(N/A)"),
136  S_COR(ast_channel_redirecting(c)->from.number.valid, ast_channel_redirecting(c)->from.number.str, "(N/A)"),
137  ast_channel_parkinglot(c),
138  ast_channel_language(c),
141  ast_channel_rings(c),
142  ast_format_cap_get_names(ast_channel_nativeformats(c), &format_buf),
143  ast_format_get_name(ast_channel_writeformat(c)),
144  ast_format_get_name(ast_channel_readformat(c)),
145  ast_format_get_name(ast_channel_rawwriteformat(c)),
146  ast_format_get_name(ast_channel_rawreadformat(c)),
147  ast_channel_writetrans(c) ? "Yes" : "No",
148  ast_translate_path_to_str(ast_channel_writetrans(c), &write_transpath),
149  ast_channel_readtrans(c) ? "Yes" : "No",
150  ast_translate_path_to_str(ast_channel_readtrans(c), &read_transpath),
151  ast_channel_fd(c, 0),
152  ast_channel_fin(c) & ~DEBUGCHAN_FLAG, (ast_channel_fin(c) & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
153  ast_channel_fout(c) & ~DEBUGCHAN_FLAG, (ast_channel_fout(c) & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
154  (long)ast_channel_whentohangup(c)->tv_sec,
155  hour,
156  min,
157  sec,
158  bridge ? bridge->uniqueid : "(Not bridged)",
159  ast_channel_context(c),
160  ast_channel_exten(c),
161  ast_channel_priority(c),
162  ast_print_group(cgrp, sizeof(cgrp), ast_channel_callgroup(c)),
163  ast_print_group(pgrp, sizeof(pgrp), ast_channel_pickupgroup(c)),
164  ast_channel_appl(c) ? ast_channel_appl(c) : "(N/A)",
165  ast_channel_data(c) ? S_OR(ast_channel_data(c), "(Empty)") : "(None)",
166  (ast_test_flag(ast_channel_flags(c), AST_FLAG_BLOCKING) ? ast_channel_blockproc(c) : "(Not Blocking)"));
167  ast_channel_unlock(c);
168  ao2_cleanup(bridge);
169  return 0;
170 }
171 
172 static int dumpchan_exec(struct ast_channel *chan, const char *data)
173 {
174  struct ast_str *vars = ast_str_thread_get(&ast_str_thread_global_buf, 16);
175  char info[2048];
176  int level = 0;
177  static char *line = "================================================================================";
178 
179  if (!ast_strlen_zero(data))
180  level = atoi(data);
181 
182  if (VERBOSITY_ATLEAST(level)) {
183  serialize_showchan(chan, info, sizeof(info));
184  pbx_builtin_serialize_variables(chan, &vars);
185  ast_verb(level, "\n"
186  "Dumping Info For Channel: %s:\n"
187  "%s\n"
188  "Info:\n"
189  "%s\n"
190  "Variables:\n"
191  "%s%s\n", ast_channel_name(chan), line, info, ast_str_buffer(vars), line);
192  }
193 
194  return 0;
195 }
196 
197 static int unload_module(void)
198 {
199  return ast_unregister_application(app);
200 }
201 
202 static int load_module(void)
203 {
204  return ast_register_application_xml(app, dumpchan_exec);
205 }
206 
207 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dump Info About The Calling Channel");
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
const ast_string_field uniqueid
Definition: bridge.h:401
#define DEBUGCHAN_FLAG
Definition: channel.h:857
Support for translation of data formats. translate.c.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
#define AST_FORMAT_CAP_NAMES_LEN
Definition: format_cap.h:324
const ast_string_field name
Definition: bridge.h:401
ast_channel_state
ast_channel states
Definition: channelstate.h:35
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
char * ast_print_group(char *buf, int buflen, ast_group_t group)
Print call and pickup groups into buffer.
Definition: channel.c:8031
Number structure.
Definition: app_followme.c:154
struct ast_bridge * ast_channel_get_bridge(const struct ast_channel *chan)
Get the bridge associated with a channel.
Definition: channel.c:10534
General Asterisk PBX channel definitions.
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:87
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Definition: channel.h:628
Core PBX routines and definitions.
Structure that contains information about a bridge.
Definition: bridge.h:349
Support for dynamic strings.
Definition: strings.h:623
const char * ast_format_cap_get_names(const struct ast_format_cap *cap, struct ast_str **buf)
Get the names of codecs of a set of formats.
Definition: format_cap.c:734
int ast_channel_get_duration(struct ast_channel *chan)
Obtain how long the channel since the channel was created.
Definition: channel.c:2830
const char * ast_translate_path_to_str(struct ast_trans_pvt *t, struct ast_str **str)
Puts a string representation of the translation path into outbuf.
Definition: translate.c:930
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:80
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition: strings.h:909
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Bridging API.
Asterisk module definitions.
const char * ast_state2str(enum ast_channel_state state)
Gives the string form of a given channel state.
Definition: channel.c:636
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:640
int pbx_builtin_serialize_variables(struct ast_channel *chan, struct ast_str **buf)
Create a human-readable string, specifying all variables and their corresponding values.