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: 419044 $")
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 #include "asterisk/bridge.h"
00045 
00046 /*** DOCUMENTATION
00047    <application name="DumpChan" language="en_US">
00048       <synopsis>
00049          Dump Info About The Calling Channel.
00050       </synopsis>
00051       <syntax>
00052          <parameter name="level">
00053             <para>Minimum verbose level</para>
00054          </parameter>
00055       </syntax>
00056       <description>
00057          <para>Displays information on channel and listing of all channel
00058          variables. If <replaceable>level</replaceable> is specified, output is only
00059          displayed when the verbose level is currently set to that number
00060          or greater.</para>
00061       </description>
00062       <see-also>
00063          <ref type="application">NoOp</ref>
00064          <ref type="application">Verbose</ref>
00065       </see-also>
00066    </application>
00067  ***/
00068 
00069 static const char app[] = "DumpChan";
00070 
00071 static int serialize_showchan(struct ast_channel *c, char *buf, size_t size)
00072 {
00073    long elapsed_seconds = 0;
00074    int hour = 0, min = 0, sec = 0;
00075    struct ast_str *format_buf = ast_str_alloca(64);
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    struct ast_bridge *bridge;
00081 
00082    memset(buf, 0, size);
00083    if (!c)
00084       return 0;
00085 
00086    elapsed_seconds = ast_channel_get_duration(c);
00087    hour = elapsed_seconds / 3600;
00088    min = (elapsed_seconds % 3600) / 60;
00089    sec = elapsed_seconds % 60;
00090 
00091    ast_channel_lock(c);
00092    bridge = ast_channel_get_bridge(c);
00093    ast_channel_unlock(c);
00094 
00095    snprintf(buf,size,
00096       "Name=               %s\n"
00097       "Type=               %s\n"
00098       "UniqueID=           %s\n"
00099       "LinkedID=           %s\n"
00100       "CallerIDNum=        %s\n"
00101       "CallerIDName=       %s\n"
00102       "ConnectedLineIDNum= %s\n"
00103       "ConnectedLineIDName=%s\n"
00104       "DNIDDigits=         %s\n"
00105       "RDNIS=              %s\n"
00106       "Parkinglot=         %s\n"
00107       "Language=           %s\n"
00108       "State=              %s (%u)\n"
00109       "Rings=              %d\n"
00110       "NativeFormat=       %s\n"
00111       "WriteFormat=        %s\n"
00112       "ReadFormat=         %s\n"
00113       "RawWriteFormat=     %s\n"
00114       "RawReadFormat=      %s\n"
00115       "WriteTranscode=     %s %s\n"
00116       "ReadTranscode=      %s %s\n"
00117       "1stFileDescriptor=  %d\n"
00118       "Framesin=           %u %s\n"
00119       "Framesout=          %u %s\n"
00120       "TimetoHangup=       %ld\n"
00121       "ElapsedTime=        %dh%dm%ds\n"
00122       "BridgeID=           %s\n"
00123       "Context=            %s\n"
00124       "Extension=          %s\n"
00125       "Priority=           %d\n"
00126       "CallGroup=          %s\n"
00127       "PickupGroup=        %s\n"
00128       "Application=        %s\n"
00129       "Data=               %s\n"
00130       "Blocking_in=        %s\n",
00131       ast_channel_name(c),
00132       ast_channel_tech(c)->type,
00133       ast_channel_uniqueid(c),
00134       ast_channel_linkedid(c),
00135       S_COR(ast_channel_caller(c)->id.number.valid, ast_channel_caller(c)->id.number.str, "(N/A)"),
00136       S_COR(ast_channel_caller(c)->id.name.valid, ast_channel_caller(c)->id.name.str, "(N/A)"),
00137       S_COR(ast_channel_connected(c)->id.number.valid, ast_channel_connected(c)->id.number.str, "(N/A)"),
00138       S_COR(ast_channel_connected(c)->id.name.valid, ast_channel_connected(c)->id.name.str, "(N/A)"),
00139       S_OR(ast_channel_dialed(c)->number.str, "(N/A)"),
00140       S_COR(ast_channel_redirecting(c)->from.number.valid, ast_channel_redirecting(c)->from.number.str, "(N/A)"),
00141       ast_channel_parkinglot(c),
00142       ast_channel_language(c),
00143       ast_state2str(ast_channel_state(c)),
00144       ast_channel_state(c),
00145       ast_channel_rings(c),
00146       ast_format_cap_get_names(ast_channel_nativeformats(c), &format_buf),
00147       ast_format_get_name(ast_channel_writeformat(c)),
00148       ast_format_get_name(ast_channel_readformat(c)),
00149       ast_format_get_name(ast_channel_rawwriteformat(c)),
00150       ast_format_get_name(ast_channel_rawreadformat(c)),
00151       ast_channel_writetrans(c) ? "Yes" : "No",
00152       ast_translate_path_to_str(ast_channel_writetrans(c), &write_transpath),
00153       ast_channel_readtrans(c) ? "Yes" : "No",
00154       ast_translate_path_to_str(ast_channel_readtrans(c), &read_transpath),
00155       ast_channel_fd(c, 0),
00156       ast_channel_fin(c) & ~DEBUGCHAN_FLAG, (ast_channel_fin(c) & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
00157       ast_channel_fout(c) & ~DEBUGCHAN_FLAG, (ast_channel_fout(c) & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
00158       (long)ast_channel_whentohangup(c)->tv_sec,
00159       hour,
00160       min,
00161       sec,
00162       bridge ? bridge->uniqueid : "(Not bridged)",
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    ao2_cleanup(bridge);
00173    return 0;
00174 }
00175 
00176 static int dumpchan_exec(struct ast_channel *chan, const char *data)
00177 {
00178    struct ast_str *vars = ast_str_thread_get(&ast_str_thread_global_buf, 16);
00179    char info[2048];
00180    int level = 0;
00181    static char *line = "================================================================================";
00182 
00183    if (!ast_strlen_zero(data))
00184       level = atoi(data);
00185 
00186    if (VERBOSITY_ATLEAST(level)) {
00187       serialize_showchan(chan, info, sizeof(info));
00188       pbx_builtin_serialize_variables(chan, &vars);
00189       ast_verb(level, "\n"
00190          "Dumping Info For Channel: %s:\n"
00191          "%s\n"
00192          "Info:\n"
00193          "%s\n"
00194          "Variables:\n"
00195          "%s%s\n", ast_channel_name(chan), line, info, ast_str_buffer(vars), line);
00196    }
00197 
00198    return 0;
00199 }
00200 
00201 static int unload_module(void)
00202 {
00203    return ast_unregister_application(app);
00204 }
00205 
00206 static int load_module(void)
00207 {
00208    return ast_register_application_xml(app, dumpchan_exec);
00209 }
00210 
00211 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dump Info About The Calling Channel");

Generated on Thu Apr 16 06:27:09 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6