Sat Apr 26 2014 22:01:26

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: 405431 $")
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>Minimum 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 cgrp[256];
00077    char pgrp[256];
00078    struct ast_str *write_transpath = ast_str_alloca(256);
00079    struct ast_str *read_transpath = ast_str_alloca(256);
00080 
00081    now = ast_tvnow();
00082    memset(buf, 0, size);
00083    if (!c)
00084       return 0;
00085 
00086    if (ast_channel_cdr(c)) {
00087       elapsed_seconds = now.tv_sec - ast_channel_cdr(c)->start.tv_sec;
00088       hour = elapsed_seconds / 3600;
00089       min = (elapsed_seconds % 3600) / 60;
00090       sec = elapsed_seconds % 60;
00091    }
00092 
00093    snprintf(buf,size,
00094       "Name=               %s\n"
00095       "Type=               %s\n"
00096       "UniqueID=           %s\n"
00097       "LinkedID=           %s\n"
00098       "CallerIDNum=        %s\n"
00099       "CallerIDName=       %s\n"
00100       "ConnectedLineIDNum= %s\n"
00101       "ConnectedLineIDName=%s\n"
00102       "DNIDDigits=         %s\n"
00103       "RDNIS=              %s\n"
00104       "Parkinglot=         %s\n"
00105       "Language=           %s\n"
00106       "State=              %s (%d)\n"
00107       "Rings=              %d\n"
00108       "NativeFormat=       %s\n"
00109       "WriteFormat=        %s\n"
00110       "ReadFormat=         %s\n"
00111       "RawWriteFormat=     %s\n"
00112       "RawReadFormat=      %s\n"
00113       "WriteTranscode=     %s %s\n"
00114       "ReadTranscode=      %s %s\n"
00115       "1stFileDescriptor=  %d\n"
00116       "Framesin=           %d %s\n"
00117       "Framesout=          %d %s\n"
00118       "TimetoHangup=       %ld\n"
00119       "ElapsedTime=        %dh%dm%ds\n"
00120       "DirectBridge=       %s\n"
00121       "IndirectBridge=     %s\n"
00122       "Context=            %s\n"
00123       "Extension=          %s\n"
00124       "Priority=           %d\n"
00125       "CallGroup=          %s\n"
00126       "PickupGroup=        %s\n"
00127       "Application=        %s\n"
00128       "Data=               %s\n"
00129       "Blocking_in=        %s\n",
00130       ast_channel_name(c),
00131       ast_channel_tech(c)->type,
00132       ast_channel_uniqueid(c),
00133       ast_channel_linkedid(c),
00134       S_COR(ast_channel_caller(c)->id.number.valid, ast_channel_caller(c)->id.number.str, "(N/A)"),
00135       S_COR(ast_channel_caller(c)->id.name.valid, ast_channel_caller(c)->id.name.str, "(N/A)"),
00136       S_COR(ast_channel_connected(c)->id.number.valid, ast_channel_connected(c)->id.number.str, "(N/A)"),
00137       S_COR(ast_channel_connected(c)->id.name.valid, ast_channel_connected(c)->id.name.str, "(N/A)"),
00138       S_OR(ast_channel_dialed(c)->number.str, "(N/A)"),
00139       S_COR(ast_channel_redirecting(c)->from.number.valid, ast_channel_redirecting(c)->from.number.str, "(N/A)"),
00140       ast_channel_parkinglot(c),
00141       ast_channel_language(c),
00142       ast_state2str(ast_channel_state(c)),
00143       ast_channel_state(c),
00144       ast_channel_rings(c),
00145       ast_getformatname_multiple(nf, sizeof(nf), ast_channel_nativeformats(c)),
00146       ast_getformatname(ast_channel_writeformat(c)),
00147       ast_getformatname(ast_channel_readformat(c)),
00148       ast_getformatname(ast_channel_rawwriteformat(c)),
00149       ast_getformatname(ast_channel_rawreadformat(c)),
00150       ast_channel_writetrans(c) ? "Yes" : "No",
00151       ast_translate_path_to_str(ast_channel_writetrans(c), &write_transpath),
00152       ast_channel_readtrans(c) ? "Yes" : "No",
00153       ast_translate_path_to_str(ast_channel_readtrans(c), &read_transpath),
00154       ast_channel_fd(c, 0),
00155       ast_channel_fin(c) & ~DEBUGCHAN_FLAG, (ast_channel_fin(c) & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
00156       ast_channel_fout(c) & ~DEBUGCHAN_FLAG, (ast_channel_fout(c) & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
00157       (long)ast_channel_whentohangup(c)->tv_sec,
00158       hour,
00159       min,
00160       sec,
00161       ast_channel_internal_bridged_channel(c) ? ast_channel_name(ast_channel_internal_bridged_channel(c)) : "<none>",
00162       ast_bridged_channel(c) ? ast_channel_name(ast_bridged_channel(c)) : "<none>",
00163       ast_channel_context(c),
00164       ast_channel_exten(c),
00165       ast_channel_priority(c),
00166       ast_print_group(cgrp, sizeof(cgrp), ast_channel_callgroup(c)),
00167       ast_print_group(pgrp, sizeof(pgrp), ast_channel_pickupgroup(c)),
00168       ast_channel_appl(c) ? ast_channel_appl(c) : "(N/A)",
00169       ast_channel_data(c) ? S_OR(ast_channel_data(c), "(Empty)") : "(None)",
00170       (ast_test_flag(ast_channel_flags(c), AST_FLAG_BLOCKING) ? ast_channel_blockproc(c) : "(Not Blocking)"));
00171 
00172    return 0;
00173 }
00174 
00175 static int dumpchan_exec(struct ast_channel *chan, const char *data)
00176 {
00177    struct ast_str *vars = ast_str_thread_get(&ast_str_thread_global_buf, 16);
00178    char info[2048];
00179    int level = 0;
00180    static char *line = "================================================================================";
00181 
00182    if (!ast_strlen_zero(data))
00183       level = atoi(data);
00184 
00185    if (VERBOSITY_ATLEAST(level)) {
00186       serialize_showchan(chan, info, sizeof(info));
00187       pbx_builtin_serialize_variables(chan, &vars);
00188       ast_verb(level, "\n"
00189          "Dumping Info For Channel: %s:\n"
00190          "%s\n"
00191          "Info:\n"
00192          "%s\n"
00193          "Variables:\n"
00194          "%s%s\n", ast_channel_name(chan), line, info, ast_str_buffer(vars), line);
00195    }
00196 
00197    return 0;
00198 }
00199 
00200 static int unload_module(void)
00201 {
00202    return ast_unregister_application(app);
00203 }
00204 
00205 static int load_module(void)
00206 {
00207    return ast_register_application_xml(app, dumpchan_exec);
00208 }
00209 
00210 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dump Info About The Calling Channel");