Wed Jan 8 2020 09:49:39

Asterisk developer's documentation


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 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 413586 $")
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>Minimum 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 wf[256];
77  char rf[256];
78  char rwf[256];
79  char rrf[256];
80  char cgrp[256];
81  char pgrp[256];
82  struct ast_str *write_transpath = ast_str_alloca(256);
83  struct ast_str *read_transpath = ast_str_alloca(256);
84 
85  now = ast_tvnow();
86  memset(buf, 0, size);
87  if (!c)
88  return 0;
89 
90  if (c->cdr) {
91  elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
92  hour = elapsed_seconds / 3600;
93  min = (elapsed_seconds % 3600) / 60;
94  sec = elapsed_seconds % 60;
95  }
96 
97  snprintf(buf,size,
98  "Name= %s\n"
99  "Type= %s\n"
100  "UniqueID= %s\n"
101  "LinkedID= %s\n"
102  "CallerIDNum= %s\n"
103  "CallerIDName= %s\n"
104  "ConnectedLineIDNum= %s\n"
105  "ConnectedLineIDName=%s\n"
106  "DNIDDigits= %s\n"
107  "RDNIS= %s\n"
108  "Parkinglot= %s\n"
109  "Language= %s\n"
110  "State= %s (%u)\n"
111  "Rings= %d\n"
112  "NativeFormat= %s\n"
113  "WriteFormat= %s\n"
114  "ReadFormat= %s\n"
115  "RawWriteFormat= %s\n"
116  "RawReadFormat= %s\n"
117  "WriteTranscode= %s %s\n"
118  "ReadTranscode= %s %s\n"
119  "1stFileDescriptor= %d\n"
120  "Framesin= %u %s\n"
121  "Framesout= %u %s\n"
122  "TimetoHangup= %ld\n"
123  "ElapsedTime= %dh%dm%ds\n"
124  "DirectBridge= %s\n"
125  "IndirectBridge= %s\n"
126  "Context= %s\n"
127  "Extension= %s\n"
128  "Priority= %d\n"
129  "CallGroup= %s\n"
130  "PickupGroup= %s\n"
131  "Application= %s\n"
132  "Data= %s\n"
133  "Blocking_in= %s\n",
134  c->name,
135  c->tech->type,
136  c->uniqueid,
137  c->linkedid,
138  S_COR(c->caller.id.number.valid, c->caller.id.number.str, "(N/A)"),
139  S_COR(c->caller.id.name.valid, c->caller.id.name.str, "(N/A)"),
140  S_COR(c->connected.id.number.valid, c->connected.id.number.str, "(N/A)"),
141  S_COR(c->connected.id.name.valid, c->connected.id.name.str, "(N/A)"),
142  S_OR(c->dialed.number.str, "(N/A)"),
144  c->parkinglot,
145  c->language,
146  ast_state2str(c->_state),
147  c->_state,
148  c->rings,
149  ast_getformatname_multiple(nf, sizeof(nf), c->nativeformats),
150  ast_getformatname_multiple(wf, sizeof(wf), c->writeformat),
151  ast_getformatname_multiple(rf, sizeof(rf), c->readformat),
152  ast_getformatname_multiple(rwf, sizeof(rwf), c->rawwriteformat),
153  ast_getformatname_multiple(rrf, sizeof(rrf), c->rawreadformat),
154  c->writetrans ? "Yes" : "No",
155  ast_translate_path_to_str(c->writetrans, &write_transpath),
156  c->readtrans ? "Yes" : "No",
157  ast_translate_path_to_str(c->readtrans, &read_transpath),
158  c->fds[0],
159  c->fin & ~DEBUGCHAN_FLAG, (c->fin & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
160  c->fout & ~DEBUGCHAN_FLAG, (c->fout & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
161  (long)c->whentohangup.tv_sec,
162  hour,
163  min,
164  sec,
165  c->_bridge ? c->_bridge->name : "<none>",
166  ast_bridged_channel(c) ? ast_bridged_channel(c)->name : "<none>",
167  c->context,
168  c->exten,
169  c->priority,
170  ast_print_group(cgrp, sizeof(cgrp), c->callgroup),
171  ast_print_group(pgrp, sizeof(pgrp), c->pickupgroup),
172  c->appl ? c->appl : "(N/A)",
173  c->data ? S_OR(c->data, "(Empty)") : "(None)",
174  (ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)"));
175 
176  return 0;
177 }
178 
179 static int dumpchan_exec(struct ast_channel *chan, const char *data)
180 {
181  struct ast_str *vars = ast_str_thread_get(&ast_str_thread_global_buf, 16);
182  char info[2048];
183  int level = 0;
184  static char *line = "================================================================================";
185 
186  if (!ast_strlen_zero(data))
187  level = atoi(data);
188 
189  if (option_verbose >= level) {
190  serialize_showchan(chan, info, sizeof(info));
191  pbx_builtin_serialize_variables(chan, &vars);
192  ast_verbose("\n"
193  "Dumping Info For Channel: %s:\n"
194  "%s\n"
195  "Info:\n"
196  "%s\n"
197  "Variables:\n"
198  "%s%s\n", chan->name, line, info, ast_str_buffer(vars), line);
199  }
200 
201  return 0;
202 }
203 
204 static int unload_module(void)
205 {
206  return ast_unregister_application(app);
207 }
208 
209 static int load_module(void)
210 {
212 }
213 
214 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dump Info About The Calling Channel");
Main Channel structure associated with a channel.
Definition: channel.h:742
char * str
Subscriber phone number (Malloced)
Definition: channel.h:241
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
struct ast_party_connected_line connected
Channel Connected Line ID information.
Definition: channel.h:811
const char *const type
Definition: channel.h:508
Asterisk main include file. File version handling, generic pbx functions.
int rings
Definition: channel.h:840
static int load_module(void)
Definition: app_dumpchan.c:209
char * str
Subscriber phone number (Malloced)
Definition: channel.h:336
struct ast_party_caller caller
Channel Caller ID information.
Definition: channel.h:804
int priority
Definition: channel.h:841
const ast_string_field uniqueid
Definition: channel.h:787
#define DEBUGCHAN_FLAG
Definition: channel.h:648
format_t writeformat
Definition: channel.h:854
struct ast_party_id id
Connected party ID.
Definition: channel.h:403
#define ast_test_flag(p, flag)
Definition: utils.h:63
Support for translation of data formats. translate.c.
struct ast_party_name name
Subscriber name.
Definition: channel.h:290
struct ast_party_id from
Who is redirecting the call (Sent to the party the call is redirected toward)
Definition: channel.h:449
char context[AST_MAX_CONTEXT]
Definition: channel.h:868
static int dumpchan_exec(struct ast_channel *chan, const char *data)
Definition: app_dumpchan.c:179
unsigned int fout
Definition: channel.h:847
const char * blockproc
Definition: channel.h:753
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
void ast_verbose(const char *fmt,...)
Definition: logger.c:1568
format_t rawwriteformat
Definition: channel.h:856
static int unload_module(void)
Definition: app_dumpchan.c:204
struct ast_party_redirecting redirecting
Redirecting/Diversion information.
Definition: channel.h:814
int option_verbose
Definition: asterisk.c:181
char * str
Subscriber name (Malloced)
Definition: channel.h:214
static int serialize_showchan(struct ast_channel *c, char *buf, size_t size)
Definition: app_dumpchan.c:70
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:142
struct ast_cdr * cdr
Definition: channel.h:766
format_t nativeformats
Definition: channel.h:852
#define ast_str_alloca(init_len)
Definition: strings.h:608
const char * ast_state2str(enum ast_channel_state)
Gives the string form of a given channel state.
Definition: channel.c:1007
const char * data
Definition: channel.h:755
const ast_string_field linkedid
Definition: channel.h:787
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
format_t rawreadformat
Definition: channel.h:855
ast_group_t pickupgroup
Definition: channel.h:819
const char * appl
Definition: channel.h:754
ast_group_t callgroup
Definition: channel.h:818
char * ast_print_group(char *buf, int buflen, ast_group_t group)
print call- and pickup groups into buffer
Definition: channel.c:8236
struct ast_party_id id
Caller party ID.
Definition: channel.h:370
General Asterisk PBX channel definitions.
struct ast_party_dialed::@155 number
Dialed/Called number.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#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:83
const ast_string_field parkinglot
Definition: channel.h:787
struct ast_channel * _bridge
Definition: channel.h:748
int fds[AST_MAX_FDS]
Definition: channel.h:829
struct ast_party_dialed dialed
Dialed/Called information.
Definition: channel.h:797
struct ast_trans_pvt * writetrans
Definition: channel.h:762
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:364
unsigned int fin
Definition: channel.h:845
enum ast_channel_state _state
Definition: channel.h:839
struct ast_channel * ast_bridged_channel(struct ast_channel *chan)
Find bridged channel.
Definition: channel.c:7160
const ast_string_field name
Definition: channel.h:787
struct timeval start
Definition: cdr.h:100
static const char app[]
Definition: app_dumpchan.c:68
static const char name[]
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:630
format_t readformat
Definition: channel.h:853
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:77
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
char * ast_getformatname_multiple(char *buf, size_t size, format_t format)
Get the names of a set of formats.
Definition: frame.c:591
struct timeval whentohangup
Definition: channel.h:789
struct ast_trans_pvt * readtrans
Definition: channel.h:763
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:669
unsigned char valid
TRUE if the name information is valid/present.
Definition: channel.h:229
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
Asterisk module definitions.
struct ast_channel_tech * tech
Definition: channel.h:743
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:247
const ast_string_field language
Definition: channel.h:787
char exten[AST_MAX_EXTENSION]
Definition: channel.h:869
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180
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.
Definition: pbx.c:10444
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:292