Mon Jun 27 16:50:46 2011

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 #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 /*** DOCUMENTATION
00041    <application name="DumpChan" language="en_US">
00042       <synopsis>
00043          Dump Info About The Calling Channel.
00044       </synopsis>
00045       <syntax>
00046          <parameter name="level">
00047             <para>Minimun verbose level</para>
00048          </parameter>
00049       </syntax>
00050       <description>
00051          <para>Displays information on channel and listing of all channel
00052          variables. If <replaceable>level</replaceable> is specified, output is only
00053          displayed when the verbose level is currently set to that number
00054          or greater.</para>
00055       </description>
00056       <see-also>
00057          <ref type="application">NoOp</ref>
00058          <ref type="application">Verbose</ref>
00059       </see-also>
00060    </application>
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");

Generated on Mon Jun 27 16:50:46 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7