update doxygen docs to specify authors
[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  * disclaimed to Digium
9  *
10  * See http://www.asterisk.org for more information about
11  * the Asterisk project. Please do not directly contact
12  * any of the maintainers of this project for assistance;
13  * the project provides a web site, mailing lists and IRC
14  * channels for your use.
15  *
16  * This program is free software, distributed under the terms of
17  * the GNU General Public License Version 2. See the LICENSE file
18  * at the top of the source tree.
19  */
20
21 /*! \file
22  *
23  * \brief Application to dump channel variables
24  *
25  * \author Anthony Minessale <anthmct@yahoo.com>
26  *
27  * \ingroup applications
28  */
29
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <unistd.h>
34
35 #include "asterisk.h"
36
37 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
38
39 #include "asterisk/file.h"
40 #include "asterisk/logger.h"
41 #include "asterisk/channel.h"
42 #include "asterisk/pbx.h"
43 #include "asterisk/module.h"
44 #include "asterisk/options.h"
45 #include "asterisk/utils.h"
46 #include "asterisk/lock.h"
47 #include "asterisk/utils.h"
48
49 static char *tdesc = "Dump Info About The Calling Channel";
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";
58
59 STANDARD_LOCAL_USER;
60
61 LOCAL_USER_DECL;
62
63 static int ast_serialize_showchan(struct ast_channel *c, char *buf, size_t size)
64 {
65         struct timeval now;
66         long elapsed_seconds=0;
67         int hour=0, min=0, sec=0;
68         char cgrp[256];
69         char pgrp[256];
70         
71         now = ast_tvnow();
72         memset(buf,0,size);
73         if (!c)
74                 return 0;
75
76         if (c->cdr) {
77                 elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
78                 hour = elapsed_seconds / 3600;
79                 min = (elapsed_seconds % 3600) / 60;
80                 sec = elapsed_seconds % 60;
81         }
82
83         snprintf(buf,size, 
84                          "Name=               %s\n"
85                          "Type=               %s\n"
86                          "UniqueID=           %s\n"
87                          "CallerID=           %s\n"
88                          "CallerIDName=       %s\n"
89                          "DNIDDigits=         %s\n"
90                          "State=              %s (%d)\n"
91                          "Rings=              %d\n"
92                          "NativeFormat=       %d\n"
93                          "WriteFormat=        %d\n"
94                          "ReadFormat=         %d\n"
95                          "1stFileDescriptor=  %d\n"
96                          "Framesin=           %d %s\n"
97                          "Framesout=          %d %s\n"
98                          "TimetoHangup=       %ld\n"
99                          "ElapsedTime=        %dh%dm%ds\n"
100                          "Context=            %s\n"
101                          "Extension=          %s\n"
102                          "Priority=           %d\n"
103                          "CallGroup=          %s\n"
104                          "PickupGroup=        %s\n"
105                          "Application=        %s\n"
106                          "Data=               %s\n"
107                          "Blocking_in=        %s\n",
108                          c->name,
109                          c->type,
110                          c->uniqueid,
111                          (c->cid.cid_num ? c->cid.cid_num : "(N/A)"),
112                          (c->cid.cid_name ? c->cid.cid_name : "(N/A)"),
113                          (c->cid.cid_dnid ? c->cid.cid_dnid : "(N/A)" ),
114                          ast_state2str(c->_state),
115                          c->_state,
116                          c->rings,
117                          c->nativeformats,
118                          c->writeformat,
119                          c->readformat,
120                          c->fds[0], c->fin & 0x7fffffff, (c->fin & 0x80000000) ? " (DEBUGGED)" : "",
121                          c->fout & 0x7fffffff, (c->fout & 0x80000000) ? " (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 ? (!ast_strlen_zero(c->data) ? c->data : "(Empty)") : "(None)"),
132                          (ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)"));
133
134         return 0;
135 }
136
137 static int dumpchan_exec(struct ast_channel *chan, void *data)
138 {
139         int res=0;
140         struct localuser *u;
141         char vars[1024];
142         char info[1024];
143         int level = 0;
144         static char *line = "================================================================================";
145         
146         LOCAL_USER_ADD(u);
147
148         if (!ast_strlen_zero(data)) {
149                 level = atoi(data);
150         }
151
152         pbx_builtin_serialize_variables(chan, vars, sizeof(vars));
153         ast_serialize_showchan(chan, info, sizeof(info));
154         if (option_verbose >= level)
155                 ast_verbose("\nDumping Info For Channel: %s:\n%s\nInfo:\n%s\nVariables:\n%s%s\n",chan->name, line, info, vars, line);
156
157         LOCAL_USER_REMOVE(u);
158         
159         return res;
160 }
161
162 int unload_module(void)
163 {
164         int res;
165
166         res = ast_unregister_application(app);
167
168         STANDARD_HANGUP_LOCALUSERS;
169
170         return res;
171 }
172
173 int load_module(void)
174 {
175         return ast_register_application(app, dumpchan_exec, synopsis, desc);
176 }
177
178 char *description(void)
179 {
180         return tdesc;
181 }
182
183 int usecount(void)
184 {
185         int res;
186         STANDARD_USECOUNT(res);
187         return res;
188 }
189
190 char *key()
191 {
192         return ASTERISK_GPL_KEY;
193 }
194