Wed Oct 28 11:45:27 2009

Asterisk developer's documentation


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 #include "asterisk.h"
00028 
00029 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 211551 $")
00030 
00031 #include "asterisk/module.h"
00032 #include "asterisk/app.h"
00033 #include "asterisk/channel.h"
00034 
00035 static char *app_verbose = "Verbose";
00036 static char *verbose_synopsis = "Send arbitrary text to verbose output";
00037 static char *verbose_descrip =
00038 "Verbose([<level>,]<message>)\n"
00039 "  level must be an integer value.  If not specified, defaults to 0.\n";
00040 
00041 static char *app_log = "Log";
00042 static char *log_synopsis = "Send arbitrary text to a selected log level";
00043 static char *log_descrip =
00044 "Log(<level>,<message>)\n"
00045 "  level must be one of ERROR, WARNING, NOTICE, DEBUG, VERBOSE, DTMF\n";
00046 
00047 
00048 static int verbose_exec(struct ast_channel *chan, void *data)
00049 {
00050    int vsize;
00051    char *parse;
00052    AST_DECLARE_APP_ARGS(args,
00053       AST_APP_ARG(level);
00054       AST_APP_ARG(msg);
00055    );
00056 
00057    if (ast_strlen_zero(data)) {
00058       return 0;
00059    }
00060 
00061    parse = ast_strdupa(data);
00062    AST_STANDARD_APP_ARGS(args, parse);
00063    if (args.argc == 1) {
00064       args.msg = args.level;
00065       args.level = "0";
00066    }
00067 
00068    if (sscanf(args.level, "%30d", &vsize) != 1) {
00069       vsize = 0;
00070       ast_log(LOG_WARNING, "'%s' is not a verboser number\n", args.level);
00071    }
00072    if (option_verbose >= vsize) {
00073       switch (vsize) {
00074       case 0:
00075          ast_verbose("%s\n", args.msg);
00076          break;
00077       case 1:
00078          ast_verbose(VERBOSE_PREFIX_1 "%s\n", args.msg);
00079          break;
00080       case 2:
00081          ast_verbose(VERBOSE_PREFIX_2 "%s\n", args.msg);
00082          break;
00083       case 3:
00084          ast_verbose(VERBOSE_PREFIX_3 "%s\n", args.msg);
00085          break;
00086       default:
00087          ast_verbose(VERBOSE_PREFIX_4 "%s\n", args.msg);
00088       }
00089    }
00090 
00091    return 0;
00092 }
00093 
00094 static int log_exec(struct ast_channel *chan, void *data)
00095 {
00096    char *parse;
00097    int lnum = -1;
00098    char extension[AST_MAX_EXTENSION + 5], context[AST_MAX_EXTENSION + 2];
00099    AST_DECLARE_APP_ARGS(args,
00100       AST_APP_ARG(level);
00101       AST_APP_ARG(msg);
00102    );
00103 
00104    if (ast_strlen_zero(data))
00105       return 0;
00106 
00107    parse = ast_strdupa(data);
00108    AST_STANDARD_APP_ARGS(args, parse);
00109 
00110    if (!strcasecmp(args.level, "ERROR")) {
00111       lnum = __LOG_ERROR;
00112    } else if (!strcasecmp(args.level, "WARNING")) {
00113       lnum = __LOG_WARNING;
00114    } else if (!strcasecmp(args.level, "NOTICE")) {
00115       lnum = __LOG_NOTICE;
00116    } else if (!strcasecmp(args.level, "DEBUG")) {
00117       lnum = __LOG_DEBUG;
00118    } else if (!strcasecmp(args.level, "VERBOSE")) {
00119       lnum = __LOG_VERBOSE;
00120    } else if (!strcasecmp(args.level, "DTMF")) {
00121       lnum = __LOG_DTMF;
00122    } else if (!strcasecmp(args.level, "EVENT")) {
00123       lnum = __LOG_EVENT;
00124    } else {
00125       ast_log(LOG_ERROR, "Unknown log level: '%s'\n", args.level);
00126    }
00127 
00128    if (lnum > -1) {
00129       snprintf(context, sizeof(context), "@ %s", chan->context);
00130       snprintf(extension, sizeof(extension), "Ext. %s", chan->exten);
00131 
00132       ast_log(lnum, extension, chan->priority, context, "%s\n", args.msg);
00133    }
00134 
00135    return 0;
00136 }
00137 
00138 static int unload_module(void)
00139 {
00140    int res;
00141 
00142    res = ast_unregister_application(app_verbose);
00143    res |= ast_unregister_application(app_log);
00144 
00145    return res; 
00146 }
00147 
00148 static int load_module(void)
00149 {
00150    int res;
00151 
00152    res = ast_register_application(app_log, log_exec, log_synopsis, log_descrip);
00153    res |= ast_register_application(app_verbose, verbose_exec, verbose_synopsis, verbose_descrip);
00154 
00155    return res;
00156 }
00157 
00158 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send verbose output");

Generated on Wed Oct 28 11:45:27 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6