Mon Mar 19 11:30:20 2012

Asterisk developer's documentation


app_dumpchan.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2004 - 2005, Anthony Minessale II.
00005  *
00006  * Anthony Minessale <anthmct@yahoo.com>
00007  *
00008  * A license has been granted to Digium (via disclaimer) for the use of
00009  * this code.
00010  *
00011  * See http://www.asterisk.org for more information about
00012  * the Asterisk project. Please do not directly contact
00013  * any of the maintainers of this project for assistance;
00014  * the project provides a web site, mailing lists and IRC
00015  * channels for your use.
00016  *
00017  * This program is free software, distributed under the terms of
00018  * the GNU General Public License Version 2. See the LICENSE file
00019  * at the top of the source tree.
00020  */
00021 
00022 /*! \file
00023  *
00024  * \brief Application to dump channel variables
00025  *
00026  * \author Anthony Minessale <anthmct@yahoo.com>
00027  *
00028  * \ingroup applications
00029  */
00030 
00031 /*** MODULEINFO
00032    <support_level>core</support_level>
00033  ***/
00034 
00035 #include "asterisk.h"
00036 
00037 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
00038 
00039 #include "asterisk/pbx.h"
00040 #include "asterisk/module.h"
00041 #include "asterisk/channel.h"
00042 #include "asterisk/app.h"
00043 #include "asterisk/translate.h"
00044 
00045 /*** DOCUMENTATION
00046    <application name="DumpChan" language="en_US">
00047       <synopsis>
00048          Dump Info About The Calling Channel.
00049       </synopsis>
00050       <syntax>
00051          <parameter name="level">
00052             <para>Minimun verbose level</para>
00053          </parameter>
00054       </syntax>
00055       <description>
00056          <para>Displays information on channel and listing of all channel
00057          variables. If <replaceable>level</replaceable> is specified, output is only
00058          displayed when the verbose level is currently set to that number
00059          or greater.</para>
00060       </description>
00061       <see-also>
00062          <ref type="application">NoOp</ref>
00063          <ref type="application">Verbose</ref>
00064       </see-also>
00065    </application>
00066  ***/
00067 
00068 static const char app[] = "DumpChan";
00069 
00070 static int serialize_showchan(struct ast_channel *c, char *buf, size_t size)
00071 {
00072    struct timeval now;
00073    long elapsed_seconds = 0;
00074    int hour = 0, min = 0, sec = 0;
00075    char nf[256];
00076    char wf[256];
00077    char rf[256];
00078    char rwf[256];
00079    char rrf[256];
00080    char cgrp[256];
00081    char pgrp[256];
00082    struct ast_str *write_transpath = ast_str_alloca(256);
00083    struct ast_str *read_transpath = ast_str_alloca(256);
00084 
00085    now = ast_tvnow();
00086    memset(buf, 0, size);
00087    if (!c)
00088       return 0;
00089 
00090    if (c->cdr) {
00091       elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
00092       hour = elapsed_seconds / 3600;
00093       min = (elapsed_seconds % 3600) / 60;
00094       sec = elapsed_seconds % 60;
00095    }
00096 
00097    snprintf(buf,size,
00098       "Name=               %s\n"
00099       "Type=               %s\n"
00100       "UniqueID=           %s\n"
00101       "LinkedID=           %s\n"
00102       "CallerIDNum=        %s\n"
00103       "CallerIDName=       %s\n"
00104       "ConnectedLineIDNum= %s\n"
00105       "ConnectedLineIDName=%s\n"
00106       "DNIDDigits=         %s\n"
00107       "RDNIS=              %s\n"
00108       "Parkinglot=         %s\n"
00109       "Language=           %s\n"
00110       "State=              %s (%d)\n"
00111       "Rings=              %d\n"
00112       "NativeFormat=       %s\n"
00113       "WriteFormat=        %s\n"
00114       "ReadFormat=         %s\n"
00115       "RawWriteFormat=     %s\n"
00116       "RawReadFormat=      %s\n"
00117       "WriteTranscode=     %s %s\n"
00118       "ReadTranscode=      %s %s\n"
00119       "1stFileDescriptor=  %d\n"
00120       "Framesin=           %d %s\n"
00121       "Framesout=          %d %s\n"
00122       "TimetoHangup=       %ld\n"
00123       "ElapsedTime=        %dh%dm%ds\n"
00124       "DirectBridge=       %s\n"
00125       "IndirectBridge=     %s\n"
00126       "Context=            %s\n"
00127       "Extension=          %s\n"
00128       "Priority=           %d\n"
00129       "CallGroup=          %s\n"
00130       "PickupGroup=        %s\n"
00131       "Application=        %s\n"
00132       "Data=               %s\n"
00133       "Blocking_in=        %s\n",
00134       c->name,
00135       c->tech->type,
00136       c->uniqueid,
00137       c->linkedid,
00138       S_COR(c->caller.id.number.valid, c->caller.id.number.str, "(N/A)"),
00139       S_COR(c->caller.id.name.valid, c->caller.id.name.str, "(N/A)"),
00140       S_COR(c->connected.id.number.valid, c->connected.id.number.str, "(N/A)"),
00141       S_COR(c->connected.id.name.valid, c->connected.id.name.str, "(N/A)"),
00142       S_OR(c->dialed.number.str, "(N/A)"),
00143       S_COR(c->redirecting.from.number.valid, c->redirecting.from.number.str, "(N/A)"),
00144       c->parkinglot,
00145       c->language,   
00146       ast_state2str(c->_state),
00147       c->_state,
00148       c->rings, 
00149       ast_getformatname_multiple(nf, sizeof(nf), c->nativeformats),
00150       ast_getformatname_multiple(wf, sizeof(wf), c->writeformat),
00151       ast_getformatname_multiple(rf, sizeof(rf), c->readformat),
00152       ast_getformatname_multiple(rwf, sizeof(rwf), c->rawwriteformat),
00153       ast_getformatname_multiple(rrf, sizeof(rrf), c->rawreadformat),
00154       c->writetrans ? "Yes" : "No",
00155       ast_translate_path_to_str(c->writetrans, &write_transpath),
00156       c->readtrans ? "Yes" : "No",
00157       ast_translate_path_to_str(c->readtrans, &read_transpath),
00158       c->fds[0],
00159       c->fin & ~DEBUGCHAN_FLAG, (c->fin & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
00160       c->fout & ~DEBUGCHAN_FLAG, (c->fout & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
00161       (long)c->whentohangup.tv_sec,
00162       hour,
00163       min,
00164       sec,
00165       c->_bridge ? c->_bridge->name : "<none>",
00166       ast_bridged_channel(c) ? ast_bridged_channel(c)->name : "<none>", 
00167       c->context,
00168       c->exten,
00169       c->priority,
00170       ast_print_group(cgrp, sizeof(cgrp), c->callgroup),
00171       ast_print_group(pgrp, sizeof(pgrp), c->pickupgroup),
00172       c->appl ? c->appl : "(N/A)",
00173       c->data ? S_OR(c->data, "(Empty)") : "(None)",
00174       (ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)"));
00175 
00176    return 0;
00177 }
00178 
00179 static int dumpchan_exec(struct ast_channel *chan, const char *data)
00180 {
00181    struct ast_str *vars = ast_str_thread_get(&ast_str_thread_global_buf, 16);
00182    char info[2048];
00183    int level = 0;
00184    static char *line = "================================================================================";
00185 
00186    if (!ast_strlen_zero(data))
00187       level = atoi(data);
00188 
00189    if (option_verbose >= level) {
00190       serialize_showchan(chan, info, sizeof(info));
00191       pbx_builtin_serialize_variables(chan, &vars);
00192       ast_verbose("\n"
00193          "Dumping Info For Channel: %s:\n"
00194          "%s\n"
00195          "Info:\n"
00196          "%s\n"
00197          "Variables:\n"
00198          "%s%s\n", chan->name, line, info, ast_str_buffer(vars), line);
00199    }
00200 
00201    return 0;
00202 }
00203 
00204 static int unload_module(void)
00205 {
00206    return ast_unregister_application(app);
00207 }
00208 
00209 static int load_module(void)
00210 {
00211    return ast_register_application_xml(app, dumpchan_exec);
00212 }
00213 
00214 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dump Info About The Calling Channel");

Generated on Mon Mar 19 11:30:20 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7