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
00030
00031 #include "asterisk.h"
00032
00033 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 115076 $")
00034
00035 #include "asterisk/pbx.h"
00036 #include "asterisk/module.h"
00037 #include "asterisk/channel.h"
00038
00039 static char *app = "DumpChan";
00040 static char *synopsis = "Dump Info About The Calling Channel";
00041 static char *desc =
00042 " DumpChan([<min_verbose_level>])\n"
00043 "Displays information on channel and listing of all channel\n"
00044 "variables. If min_verbose_level is specified, output is only\n"
00045 "displayed when the verbose level is currently set to that number\n"
00046 "or greater. \n";
00047
00048
00049 static int serialize_showchan(struct ast_channel *c, char *buf, size_t size)
00050 {
00051 struct timeval now;
00052 long elapsed_seconds = 0;
00053 int hour = 0, min = 0, sec = 0;
00054 char cgrp[BUFSIZ/2];
00055 char pgrp[BUFSIZ/2];
00056 char formatbuf[BUFSIZ/2];
00057
00058 now = ast_tvnow();
00059 memset(buf, 0, size);
00060 if (!c)
00061 return 0;
00062
00063 if (c->cdr) {
00064 elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
00065 hour = elapsed_seconds / 3600;
00066 min = (elapsed_seconds % 3600) / 60;
00067 sec = elapsed_seconds % 60;
00068 }
00069
00070 snprintf(buf,size,
00071 "Name= %s\n"
00072 "Type= %s\n"
00073 "UniqueID= %s\n"
00074 "CallerIDNum= %s\n"
00075 "CallerIDName= %s\n"
00076 "DNIDDigits= %s\n"
00077 "RDNIS= %s\n"
00078 "Parkinglot= %s\n"
00079 "Language= %s\n"
00080 "State= %s (%d)\n"
00081 "Rings= %d\n"
00082 "NativeFormat= %s\n"
00083 "WriteFormat= %s\n"
00084 "ReadFormat= %s\n"
00085 "RawWriteFormat= %s\n"
00086 "RawReadFormat= %s\n"
00087 "1stFileDescriptor= %d\n"
00088 "Framesin= %d %s\n"
00089 "Framesout= %d %s\n"
00090 "TimetoHangup= %ld\n"
00091 "ElapsedTime= %dh%dm%ds\n"
00092 "Context= %s\n"
00093 "Extension= %s\n"
00094 "Priority= %d\n"
00095 "CallGroup= %s\n"
00096 "PickupGroup= %s\n"
00097 "Application= %s\n"
00098 "Data= %s\n"
00099 "Blocking_in= %s\n",
00100 c->name,
00101 c->tech->type,
00102 c->uniqueid,
00103 S_OR(c->cid.cid_num, "(N/A)"),
00104 S_OR(c->cid.cid_name, "(N/A)"),
00105 S_OR(c->cid.cid_dnid, "(N/A)"),
00106 S_OR(c->cid.cid_rdnis, "(N/A)"),
00107 c->parkinglot,
00108 c->language,
00109 ast_state2str(c->_state),
00110 c->_state,
00111 c->rings,
00112 ast_getformatname_multiple(formatbuf, sizeof(formatbuf), c->nativeformats),
00113 ast_getformatname_multiple(formatbuf, sizeof(formatbuf), c->writeformat),
00114 ast_getformatname_multiple(formatbuf, sizeof(formatbuf), c->readformat),
00115 ast_getformatname_multiple(formatbuf, sizeof(formatbuf), c->rawwriteformat),
00116 ast_getformatname_multiple(formatbuf, sizeof(formatbuf), c->rawreadformat),
00117 c->fds[0], c->fin & ~DEBUGCHAN_FLAG, (c->fin & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
00118 c->fout & ~DEBUGCHAN_FLAG, (c->fout & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "", (long)c->whentohangup.tv_sec,
00119 hour,
00120 min,
00121 sec,
00122 c->context,
00123 c->exten,
00124 c->priority,
00125 ast_print_group(cgrp, sizeof(cgrp), c->callgroup),
00126 ast_print_group(pgrp, sizeof(pgrp), c->pickupgroup),
00127 ( c->appl ? c->appl : "(N/A)" ),
00128 ( c-> data ? S_OR(c->data, "(Empty)") : "(None)"),
00129 (ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)"));
00130
00131 return 0;
00132 }
00133
00134 static int dumpchan_exec(struct ast_channel *chan, void *data)
00135 {
00136 struct ast_str *vars = ast_str_alloca(BUFSIZ * 4);
00137 char info[1024];
00138 int level = 0;
00139 static char *line = "================================================================================";
00140
00141 if (!ast_strlen_zero(data))
00142 level = atoi(data);
00143
00144 pbx_builtin_serialize_variables(chan, &vars);
00145 serialize_showchan(chan, info, sizeof(info));
00146 if (option_verbose >= level)
00147 ast_verbose("\nDumping Info For Channel: %s:\n%s\nInfo:\n%s\nVariables:\n%s%s\n", chan->name, line, info, vars->str, line);
00148
00149 return 0;
00150 }
00151
00152 static int unload_module(void)
00153 {
00154 return ast_unregister_application(app);
00155 }
00156
00157 static int load_module(void)
00158 {
00159 return ast_register_application(app, dumpchan_exec, synopsis, desc);
00160 }
00161
00162 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dump Info About The Calling Channel");