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

Generated on Sat Aug 6 00:39:20 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7