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