app_verbose.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (c) 2004 - 2005 Tilghman Lesher.  All rights reserved.
00005  *
00006  * Tilghman Lesher <app_verbose_v001@the-tilghman.com>
00007  *
00008  * This code is released by the author with no restrictions on usage.
00009  *
00010  * See http://www.asterisk.org for more information about
00011  * the Asterisk project. Please do not directly contact
00012  * any of the maintainers of this project for assistance;
00013  * the project provides a web site, mailing lists and IRC
00014  * channels for your use.
00015  *
00016  */
00017 
00018 /*! \file
00019  *
00020  * \brief Verbose logging application
00021  *
00022  * \author Tilghman Lesher <app_verbose_v001@the-tilghman.com>
00023  *
00024  * \ingroup applications
00025  */
00026 
00027 /*** MODULEINFO
00028    <support_level>core</support_level>
00029  ***/
00030 
00031 #include "asterisk.h"
00032 
00033 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 413589 $")
00034 
00035 #include "asterisk/module.h"
00036 #include "asterisk/app.h"
00037 #include "asterisk/channel.h"
00038 
00039 static char *app_verbose = "Verbose";
00040 static char *app_log = "Log";
00041 
00042 /*** DOCUMENTATION
00043    <application name="Verbose" language="en_US">
00044       <synopsis>
00045          Send arbitrary text to verbose output.
00046       </synopsis>
00047       <syntax>
00048          <parameter name="level">
00049             <para>Must be an integer value.  If not specified, defaults to 0.</para>
00050          </parameter>
00051          <parameter name="message" required="true">
00052             <para>Output text message.</para>
00053          </parameter>
00054       </syntax>
00055       <description>
00056          <para>Sends an arbitrary text message to verbose output.</para>
00057       </description>
00058    </application>
00059    <application name="Log" language="en_US">
00060       <synopsis>
00061          Send arbitrary text to a selected log level.
00062       </synopsis>
00063       <syntax>
00064          <parameter name="level" required="true">
00065             <para>Level must be one of <literal>ERROR</literal>, <literal>WARNING</literal>, <literal>NOTICE</literal>,
00066             <literal>DEBUG</literal>, <literal>VERBOSE</literal> or <literal>DTMF</literal>.</para>
00067          </parameter>
00068          <parameter name="message" required="true">
00069             <para>Output text message.</para>
00070          </parameter>
00071       </syntax>
00072       <description>
00073          <para>Sends an arbitrary text message to a selected log level.</para>
00074       </description>
00075    </application>
00076  ***/
00077 
00078 
00079 static int verbose_exec(struct ast_channel *chan, const char *data)
00080 {
00081    unsigned int vsize;
00082    char *parse;
00083    AST_DECLARE_APP_ARGS(args,
00084       AST_APP_ARG(level);
00085       AST_APP_ARG(msg);
00086    );
00087 
00088    if (ast_strlen_zero(data)) {
00089       return 0;
00090    }
00091 
00092    parse = ast_strdupa(data);
00093    AST_STANDARD_APP_ARGS(args, parse);
00094    if (args.argc == 1) {
00095       args.msg = args.level;
00096       args.level = "0";
00097    }
00098 
00099    if (sscanf(args.level, "%30u", &vsize) != 1) {
00100       vsize = 0;
00101       ast_log(LOG_WARNING, "'%s' is not a verboser number\n", args.level);
00102    } else if (4 < vsize) {
00103       vsize = 4;
00104    }
00105 
00106    ast_verb(vsize, "%s\n", args.msg);
00107 
00108    return 0;
00109 }
00110 
00111 static int log_exec(struct ast_channel *chan, const char *data)
00112 {
00113    char *parse;
00114    int lnum = -1;
00115    char extension[AST_MAX_EXTENSION + 5], context[AST_MAX_EXTENSION + 2];
00116    AST_DECLARE_APP_ARGS(args,
00117       AST_APP_ARG(level);
00118       AST_APP_ARG(msg);
00119    );
00120 
00121    if (ast_strlen_zero(data))
00122       return 0;
00123 
00124    parse = ast_strdupa(data);
00125    AST_STANDARD_APP_ARGS(args, parse);
00126 
00127    if (!strcasecmp(args.level, "ERROR")) {
00128       lnum = __LOG_ERROR;
00129    } else if (!strcasecmp(args.level, "WARNING")) {
00130       lnum = __LOG_WARNING;
00131    } else if (!strcasecmp(args.level, "NOTICE")) {
00132       lnum = __LOG_NOTICE;
00133    } else if (!strcasecmp(args.level, "DEBUG")) {
00134       lnum = __LOG_DEBUG;
00135    } else if (!strcasecmp(args.level, "VERBOSE")) {
00136       lnum = __LOG_VERBOSE;
00137    } else if (!strcasecmp(args.level, "DTMF")) {
00138       lnum = __LOG_DTMF;
00139    } else {
00140       ast_log(LOG_ERROR, "Unknown log level: '%s'\n", args.level);
00141    }
00142 
00143    if (lnum > -1) {
00144       snprintf(context, sizeof(context), "@ %s", ast_channel_context(chan));
00145       snprintf(extension, sizeof(extension), "Ext. %s", ast_channel_exten(chan));
00146 
00147       ast_log(lnum, extension, ast_channel_priority(chan), context, "%s\n", args.msg);
00148    }
00149 
00150    return 0;
00151 }
00152 
00153 static int unload_module(void)
00154 {
00155    int res;
00156 
00157    res = ast_unregister_application(app_verbose);
00158    res |= ast_unregister_application(app_log);
00159 
00160    return res;
00161 }
00162 
00163 static int load_module(void)
00164 {
00165    int res;
00166 
00167    res = ast_register_application_xml(app_log, log_exec);
00168    res |= ast_register_application_xml(app_verbose, verbose_exec);
00169 
00170    return res;
00171 }
00172 
00173 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send verbose output");

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