00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <stdlib.h>
00029 #include <stdio.h>
00030 #include <string.h>
00031 #include <unistd.h>
00032
00033 #include "asterisk.h"
00034
00035 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $")
00036
00037 #include "asterisk/file.h"
00038 #include "asterisk/logger.h"
00039 #include "asterisk/channel.h"
00040 #include "asterisk/pbx.h"
00041 #include "asterisk/module.h"
00042 #include "asterisk/options.h"
00043 #include "asterisk/utils.h"
00044 #include "asterisk/lock.h"
00045 #include "asterisk/utils.h"
00046
00047 static char *tdesc = "Dump Info About The Calling Channel";
00048 static char *app = "DumpChan";
00049 static char *synopsis = "Dump Info About The Calling Channel";
00050 static char *desc =
00051 " DumpChan([<min_verbose_level>])\n"
00052 "Displays information on channel and listing of all channel\n"
00053 "variables. If min_verbose_level is specified, output is only\n"
00054 "displayed when the verbose level is currently set to that number\n"
00055 "or greater. \n";
00056
00057 STANDARD_LOCAL_USER;
00058
00059 LOCAL_USER_DECL;
00060
00061 static int ast_serialize_showchan(struct ast_channel *c, char *buf, size_t size)
00062 {
00063 struct timeval now;
00064 long elapsed_seconds=0;
00065 int hour=0, min=0, sec=0;
00066 char cgrp[256];
00067 char pgrp[256];
00068
00069 now = ast_tvnow();
00070 memset(buf,0,size);
00071 if (!c)
00072 return 0;
00073
00074 if (c->cdr) {
00075 elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
00076 hour = elapsed_seconds / 3600;
00077 min = (elapsed_seconds % 3600) / 60;
00078 sec = elapsed_seconds % 60;
00079 }
00080
00081 snprintf(buf,size,
00082 "Name= %s\n"
00083 "Type= %s\n"
00084 "UniqueID= %s\n"
00085 "CallerID= %s\n"
00086 "CallerIDName= %s\n"
00087 "DNIDDigits= %s\n"
00088 "State= %s (%d)\n"
00089 "Rings= %d\n"
00090 "NativeFormat= %d\n"
00091 "WriteFormat= %d\n"
00092 "ReadFormat= %d\n"
00093 "1stFileDescriptor= %d\n"
00094 "Framesin= %d %s\n"
00095 "Framesout= %d %s\n"
00096 "TimetoHangup= %ld\n"
00097 "ElapsedTime= %dh%dm%ds\n"
00098 "Context= %s\n"
00099 "Extension= %s\n"
00100 "Priority= %d\n"
00101 "CallGroup= %s\n"
00102 "PickupGroup= %s\n"
00103 "Application= %s\n"
00104 "Data= %s\n"
00105 "Blocking_in= %s\n",
00106 c->name,
00107 c->type,
00108 c->uniqueid,
00109 (c->cid.cid_num ? c->cid.cid_num : "(N/A)"),
00110 (c->cid.cid_name ? c->cid.cid_name : "(N/A)"),
00111 (c->cid.cid_dnid ? c->cid.cid_dnid : "(N/A)" ),
00112 ast_state2str(c->_state),
00113 c->_state,
00114 c->rings,
00115 c->nativeformats,
00116 c->writeformat,
00117 c->readformat,
00118 c->fds[0], c->fin & 0x7fffffff, (c->fin & 0x80000000) ? " (DEBUGGED)" : "",
00119 c->fout & 0x7fffffff, (c->fout & 0x80000000) ? " (DEBUGGED)" : "", (long)c->whentohangup,
00120 hour,
00121 min,
00122 sec,
00123 c->context,
00124 c->exten,
00125 c->priority,
00126 ast_print_group(cgrp, sizeof(cgrp), c->callgroup),
00127 ast_print_group(pgrp, sizeof(pgrp), c->pickupgroup),
00128 ( c->appl ? c->appl : "(N/A)" ),
00129 ( c-> data ? (!ast_strlen_zero(c->data) ? c->data : "(Empty)") : "(None)"),
00130 (ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)"));
00131
00132 return 0;
00133 }
00134
00135 static int dumpchan_exec(struct ast_channel *chan, void *data)
00136 {
00137 int res=0;
00138 struct localuser *u;
00139 char vars[1024];
00140 char info[1024];
00141 int level = 0;
00142 static char *line = "================================================================================";
00143
00144 LOCAL_USER_ADD(u);
00145
00146 if (!ast_strlen_zero(data)) {
00147 level = atoi(data);
00148 }
00149
00150 pbx_builtin_serialize_variables(chan, vars, sizeof(vars));
00151 ast_serialize_showchan(chan, info, sizeof(info));
00152 if (option_verbose >= level)
00153 ast_verbose("\nDumping Info For Channel: %s:\n%s\nInfo:\n%s\nVariables:\n%s%s\n",chan->name, line, info, vars, line);
00154
00155 LOCAL_USER_REMOVE(u);
00156
00157 return res;
00158 }
00159
00160 int unload_module(void)
00161 {
00162 int res;
00163
00164 res = ast_unregister_application(app);
00165
00166 STANDARD_HANGUP_LOCALUSERS;
00167
00168 return res;
00169 }
00170
00171 int load_module(void)
00172 {
00173 return ast_register_application(app, dumpchan_exec, synopsis, desc);
00174 }
00175
00176 char *description(void)
00177 {
00178 return tdesc;
00179 }
00180
00181 int usecount(void)
00182 {
00183 int res;
00184 STANDARD_USECOUNT(res);
00185 return res;
00186 }
00187
00188 char *key()
00189 {
00190 return ASTERISK_GPL_KEY;
00191 }
00192