Stop ignoring .lastclean
[asterisk-bristuff.git] / apps / app_dumpchan.c
blob426ba4eab28d70ae13b0e16e54d1c7b5336e428b
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2004 - 2005, Anthony Minessale II.
6 * Anthony Minessale <anthmct@yahoo.com>
8 * A license has been granted to Digium (via disclaimer) for the use of
9 * this code.
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.
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.
22 /*! \file
24 * \brief Application to dump channel variables
26 * \author Anthony Minessale <anthmct@yahoo.com>
28 * \ingroup applications
31 #include "asterisk.h"
33 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
35 #include <stdlib.h>
36 #include <stdio.h>
37 #include <string.h>
38 #include <unistd.h>
40 #include "asterisk/file.h"
41 #include "asterisk/logger.h"
42 #include "asterisk/channel.h"
43 #include "asterisk/pbx.h"
44 #include "asterisk/module.h"
45 #include "asterisk/options.h"
46 #include "asterisk/utils.h"
47 #include "asterisk/lock.h"
48 #include "asterisk/utils.h"
50 static char *app = "DumpChan";
51 static char *synopsis = "Dump Info About The Calling Channel";
52 static char *desc =
53 " DumpChan([<min_verbose_level>])\n"
54 "Displays information on channel and listing of all channel\n"
55 "variables. If min_verbose_level is specified, output is only\n"
56 "displayed when the verbose level is currently set to that number\n"
57 "or greater. \n";
60 static int serialize_showchan(struct ast_channel *c, char *buf, size_t size)
62 struct timeval now;
63 long elapsed_seconds = 0;
64 int hour = 0, min = 0, sec = 0;
65 char cgrp[BUFSIZ/2];
66 char pgrp[BUFSIZ/2];
67 char formatbuf[BUFSIZ/2];
69 now = ast_tvnow();
70 memset(buf, 0, size);
71 if (!c)
72 return 0;
74 if (c->cdr) {
75 elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
76 hour = elapsed_seconds / 3600;
77 min = (elapsed_seconds % 3600) / 60;
78 sec = elapsed_seconds % 60;
81 snprintf(buf,size,
82 "Name= %s\n"
83 "Type= %s\n"
84 "UniqueID= %s\n"
85 "CallerID= %s\n"
86 "CallerIDName= %s\n"
87 "DNIDDigits= %s\n"
88 "RDNIS= %s\n"
89 "State= %s (%d)\n"
90 "Rings= %d\n"
91 "NativeFormat= %s\n"
92 "WriteFormat= %s\n"
93 "ReadFormat= %s\n"
94 "1stFileDescriptor= %d\n"
95 "Framesin= %d %s\n"
96 "Framesout= %d %s\n"
97 "TimetoHangup= %ld\n"
98 "ElapsedTime= %dh%dm%ds\n"
99 "Context= %s\n"
100 "Extension= %s\n"
101 "Priority= %d\n"
102 "CallGroup= %s\n"
103 "PickupGroup= %s\n"
104 "Application= %s\n"
105 "Data= %s\n"
106 "Blocking_in= %s\n",
107 c->name,
108 c->tech->type,
109 c->uniqueid,
110 S_OR(c->cid.cid_num, "(N/A)"),
111 S_OR(c->cid.cid_name, "(N/A)"),
112 S_OR(c->cid.cid_dnid, "(N/A)"),
113 S_OR(c->cid.cid_rdnis, "(N/A)"),
114 ast_state2str(c->_state),
115 c->_state,
116 c->rings,
117 ast_getformatname_multiple(formatbuf, sizeof(formatbuf), c->nativeformats),
118 ast_getformatname_multiple(formatbuf, sizeof(formatbuf), c->writeformat),
119 ast_getformatname_multiple(formatbuf, sizeof(formatbuf), c->readformat),
120 c->fds[0], c->fin & ~DEBUGCHAN_FLAG, (c->fin & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
121 c->fout & ~DEBUGCHAN_FLAG, (c->fout & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "", (long)c->whentohangup,
122 hour,
123 min,
124 sec,
125 c->context,
126 c->exten,
127 c->priority,
128 ast_print_group(cgrp, sizeof(cgrp), c->callgroup),
129 ast_print_group(pgrp, sizeof(pgrp), c->pickupgroup),
130 ( c->appl ? c->appl : "(N/A)" ),
131 ( c-> data ? S_OR(c->data, "(Empty)") : "(None)"),
132 (ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)"));
134 return 0;
137 static int dumpchan_exec(struct ast_channel *chan, void *data)
139 struct ast_module_user *u;
140 char vars[BUFSIZ * 4];
141 char info[1024];
142 int level = 0;
143 static char *line = "================================================================================";
145 u = ast_module_user_add(chan);
147 if (!ast_strlen_zero(data))
148 level = atoi(data);
150 pbx_builtin_serialize_variables(chan, vars, sizeof(vars));
151 serialize_showchan(chan, info, sizeof(info));
152 if (option_verbose >= level)
153 ast_verbose("\nDumping Info For Channel: %s:\n%s\nInfo:\n%s\nVariables:\n%s%s\n", chan->name, line, info, vars, line);
155 ast_module_user_remove(u);
157 return 0;
160 static int unload_module(void)
162 int res;
164 res = ast_unregister_application(app);
166 ast_module_user_hangup_all();
168 return res;
171 static int load_module(void)
173 return ast_register_application(app, dumpchan_exec, synopsis, desc);
176 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dump Info About The Calling Channel");