Asterisk - The Open Source Telephony Project  18.5.0
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 <[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  <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 
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),
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)"),
147  ast_channel_writetrans(c) ? "Yes" : "No",
149  ast_channel_readtrans(c) ? "Yes" : "No",
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)",
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)",
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 {
200 }
201 
202 static int load_module(void)
203 {
205 }
206 
207 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dump Info About The Calling Channel");
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
static const char type[]
Definition: chan_ooh323.c:109
const char * ast_channel_blockproc(const struct ast_channel *chan)
#define ast_channel_lock(chan)
Definition: channel.h:2945
Main Channel structure associated with a channel.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:567
Asterisk main include file. File version handling, generic pbx functions.
const ast_string_field uniqueid
Definition: bridge.h:409
static int load_module(void)
Definition: app_dumpchan.c:202
#define DEBUGCHAN_FLAG
Definition: channel.h:858
#define ast_test_flag(p, flag)
Definition: utils.h:63
unsigned int ast_channel_fout(const struct ast_channel *chan)
Support for translation of data formats. translate.c.
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int dumpchan_exec(struct ast_channel *chan, const char *data)
Definition: app_dumpchan.c:172
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define AST_FORMAT_CAP_NAMES_LEN
Definition: format_cap.h:326
#define VERBOSITY_ATLEAST(level)
Definition: logger.h:461
static int unload_module(void)
Definition: app_dumpchan.c:197
ast_channel_state
ast_channel states
Definition: channelstate.h:35
static int serialize_showchan(struct ast_channel *c, char *buf, size_t size)
Definition: app_dumpchan.c:69
static struct test_val c
#define ast_str_alloca(init_len)
Definition: strings.h:800
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
const char * ast_state2str(enum ast_channel_state)
Gives the string form of a given channel state.
Definition: channel.c:642
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
int ast_channel_priority(const struct ast_channel *chan)
#define ast_verb(level,...)
Definition: logger.h:463
struct ast_trans_pvt * ast_channel_readtrans(const struct ast_channel *chan)
const char * ast_channel_linkedid(const struct ast_channel *chan)
char * ast_print_group(char *buf, int buflen, ast_group_t group)
Print call and pickup groups into buffer.
Definition: channel.c:8133
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct timeval * ast_channel_whentohangup(struct ast_channel *chan)
struct ast_format * ast_channel_readformat(struct ast_channel *chan)
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:10735
unsigned int ast_channel_fin(const struct ast_channel *chan)
General Asterisk PBX channel definitions.
struct ast_trans_pvt * ast_channel_writetrans(const struct ast_channel *chan)
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
#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:85
const char * ast_channel_exten(const struct ast_channel *chan)
Core PBX routines and definitions.
const char * ast_channel_uniqueid(const struct ast_channel *chan)
Structure that contains information about a bridge.
Definition: bridge.h:357
struct ast_format * ast_channel_rawreadformat(struct ast_channel *chan)
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
def info(msg)
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
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:736
const char * ast_channel_appl(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition: channel.h:2946
static const char app[]
Definition: app_dumpchan.c:67
static const char name[]
Definition: cdr_mysql.c:74
int ast_channel_get_duration(struct ast_channel *chan)
Obtain how long the channel since the channel was created.
Definition: channel.c:2839
struct ast_party_redirecting * ast_channel_redirecting(struct ast_channel *chan)
struct ast_format_cap * ast_channel_nativeformats(const struct ast_channel *chan)
const char * ast_channel_data(const struct ast_channel *chan)
int ast_channel_fd(const struct ast_channel *chan, int which)
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:928
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
const char * ast_channel_name(const struct ast_channel *chan)
const char * ast_channel_language(const struct ast_channel *chan)
ast_group_t ast_channel_pickupgroup(const struct ast_channel *chan)
const char * ast_channel_context(const struct ast_channel *chan)
int ast_channel_rings(const struct ast_channel *chan)
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:861
ast_group_t ast_channel_callgroup(const struct ast_channel *chan)
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Bridging API.
Asterisk module definitions.
struct ast_format * ast_channel_writeformat(struct ast_channel *chan)
#define min(a, b)
Definition: f2c.h:197
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
struct ast_format * ast_channel_rawwriteformat(struct ast_channel *chan)
const struct ast_channel_tech * ast_channel_tech(const struct ast_channel *chan)
const char * ast_channel_parkinglot(const struct ast_channel *chan)
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626
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.