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