Thu Jul 9 13:40:18 2009

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: 107961 $")
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          "Language=           %s\n"
00079          "State=              %s (%d)\n"
00080          "Rings=              %d\n"
00081          "NativeFormat=       %s\n"
00082          "WriteFormat=        %s\n"
00083          "ReadFormat=         %s\n"
00084          "RawWriteFormat=     %s\n"
00085          "RawReadFormat=      %s\n"
00086          "1stFileDescriptor=  %d\n"
00087          "Framesin=           %d %s\n"
00088          "Framesout=          %d %s\n"
00089          "TimetoHangup=       %ld\n"
00090          "ElapsedTime=        %dh%dm%ds\n"
00091          "Context=            %s\n"
00092          "Extension=          %s\n"
00093          "Priority=           %d\n"
00094          "CallGroup=          %s\n"
00095          "PickupGroup=        %s\n"
00096          "Application=        %s\n"
00097          "Data=               %s\n"
00098          "Blocking_in=        %s\n",
00099          c->name,
00100          c->tech->type,
00101          c->uniqueid,
00102          S_OR(c->cid.cid_num, "(N/A)"),
00103          S_OR(c->cid.cid_name, "(N/A)"),
00104          S_OR(c->cid.cid_dnid, "(N/A)"),
00105          S_OR(c->cid.cid_rdnis, "(N/A)"),
00106          c->language,
00107          ast_state2str(c->_state),
00108          c->_state,
00109          c->rings,
00110          ast_getformatname_multiple(formatbuf, sizeof(formatbuf), c->nativeformats),
00111          ast_getformatname_multiple(formatbuf, sizeof(formatbuf), c->writeformat),
00112          ast_getformatname_multiple(formatbuf, sizeof(formatbuf), c->readformat),
00113          ast_getformatname_multiple(formatbuf, sizeof(formatbuf), c->rawwriteformat),
00114          ast_getformatname_multiple(formatbuf, sizeof(formatbuf), c->rawreadformat),
00115          c->fds[0], c->fin & ~DEBUGCHAN_FLAG, (c->fin & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
00116          c->fout & ~DEBUGCHAN_FLAG, (c->fout & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "", (long)c->whentohangup,
00117          hour,
00118          min,
00119          sec,
00120          c->context,
00121          c->exten,
00122          c->priority,
00123          ast_print_group(cgrp, sizeof(cgrp), c->callgroup),
00124          ast_print_group(pgrp, sizeof(pgrp), c->pickupgroup),
00125          ( c->appl ? c->appl : "(N/A)" ),
00126          ( c-> data ? S_OR(c->data, "(Empty)") : "(None)"),
00127          (ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)"));
00128 
00129    return 0;
00130 }
00131 
00132 static int dumpchan_exec(struct ast_channel *chan, void *data)
00133 {
00134    struct ast_str *vars = ast_str_alloca(BUFSIZ * 4); /* XXX very large! */
00135    char info[1024];
00136    int level = 0;
00137    static char *line = "================================================================================";
00138 
00139    if (!ast_strlen_zero(data))
00140       level = atoi(data);
00141 
00142    pbx_builtin_serialize_variables(chan, &vars);
00143    serialize_showchan(chan, info, sizeof(info));
00144    if (option_verbose >= level)
00145       ast_verbose("\nDumping Info For Channel: %s:\n%s\nInfo:\n%s\nVariables:\n%s%s\n", chan->name, line, info, vars->str, line);
00146 
00147    return 0;
00148 }
00149 
00150 static int unload_module(void)
00151 {
00152    return ast_unregister_application(app);
00153 }
00154 
00155 static int load_module(void)
00156 {
00157    return ast_register_application(app, dumpchan_exec, synopsis, desc);
00158 }
00159 
00160 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dump Info About The Calling Channel");

Generated on Thu Jul 9 13:40:18 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7