00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "asterisk.h"
00028
00029 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 211528 $")
00030
00031 #include <stdio.h>
00032 #include <stdlib.h>
00033 #include <unistd.h>
00034 #include <string.h>
00035
00036 #include "asterisk/options.h"
00037 #include "asterisk/logger.h"
00038 #include "asterisk/channel.h"
00039 #include "asterisk/pbx.h"
00040 #include "asterisk/module.h"
00041
00042 static char *app_verbose = "Verbose";
00043 static char *verbose_synopsis = "Send arbitrary text to verbose output";
00044 static char *verbose_descrip =
00045 "Verbose([<level>|]<message>)\n"
00046 " level must be an integer value. If not specified, defaults to 0.\n";
00047
00048 static char *app_log = "Log";
00049 static char *log_synopsis = "Send arbitrary text to a selected log level";
00050 static char *log_descrip =
00051 "Log(<level>|<message>)\n"
00052 " level must be one of ERROR, WARNING, NOTICE, DEBUG, VERBOSE, DTMF\n";
00053
00054
00055 static int verbose_exec(struct ast_channel *chan, void *data)
00056 {
00057 char *vtext;
00058 int vsize;
00059 struct ast_module_user *u;
00060
00061 u = ast_module_user_add(chan);
00062
00063 if (data) {
00064 char *tmp;
00065 vtext = ast_strdupa(data);
00066 tmp = strsep(&vtext, "|");
00067 if (vtext) {
00068 if (sscanf(tmp, "%30d", &vsize) != 1) {
00069 vsize = 0;
00070 ast_log(LOG_WARNING, "'%s' is not a verboser number\n", vtext);
00071 }
00072 } else {
00073 vtext = tmp;
00074 vsize = 0;
00075 }
00076 if (option_verbose >= vsize) {
00077 switch (vsize) {
00078 case 0:
00079 ast_verbose("%s\n", vtext);
00080 break;
00081 case 1:
00082 ast_verbose(VERBOSE_PREFIX_1 "%s\n", vtext);
00083 break;
00084 case 2:
00085 ast_verbose(VERBOSE_PREFIX_2 "%s\n", vtext);
00086 break;
00087 case 3:
00088 ast_verbose(VERBOSE_PREFIX_3 "%s\n", vtext);
00089 break;
00090 default:
00091 ast_verbose(VERBOSE_PREFIX_4 "%s\n", vtext);
00092 }
00093 }
00094 }
00095
00096 ast_module_user_remove(u);
00097
00098 return 0;
00099 }
00100
00101 static int log_exec(struct ast_channel *chan, void *data)
00102 {
00103 char *level, *ltext;
00104 struct ast_module_user *u;
00105 int lnum = -1;
00106 char extension[AST_MAX_EXTENSION + 5], context[AST_MAX_EXTENSION + 2];
00107
00108 u = ast_module_user_add(chan);
00109 if (ast_strlen_zero(data)) {
00110 ast_module_user_remove(u);
00111 return 0;
00112 }
00113
00114 ltext = ast_strdupa(data);
00115
00116 level = strsep(<ext, "|");
00117
00118 if (!strcasecmp(level, "ERROR")) {
00119 lnum = __LOG_ERROR;
00120 } else if (!strcasecmp(level, "WARNING")) {
00121 lnum = __LOG_WARNING;
00122 } else if (!strcasecmp(level, "NOTICE")) {
00123 lnum = __LOG_NOTICE;
00124 } else if (!strcasecmp(level, "DEBUG")) {
00125 lnum = __LOG_DEBUG;
00126 } else if (!strcasecmp(level, "VERBOSE")) {
00127 lnum = __LOG_VERBOSE;
00128 } else if (!strcasecmp(level, "DTMF")) {
00129 lnum = __LOG_DTMF;
00130 } else if (!strcasecmp(level, "EVENT")) {
00131 lnum = __LOG_EVENT;
00132 } else {
00133 ast_log(LOG_ERROR, "Unknown log level: '%s'\n", level);
00134 }
00135
00136 if (lnum > -1) {
00137 snprintf(context, sizeof(context), "@ %s", chan->context);
00138 snprintf(extension, sizeof(extension), "Ext. %s", chan->exten);
00139
00140 ast_log(lnum, extension, chan->priority, context, "%s\n", ltext);
00141 }
00142 ast_module_user_remove(u);
00143 return 0;
00144 }
00145
00146 static int unload_module(void)
00147 {
00148 int res;
00149
00150 res = ast_unregister_application(app_verbose);
00151 res |= ast_unregister_application(app_log);
00152
00153 ast_module_user_hangup_all();
00154
00155 return res;
00156 }
00157
00158 static int load_module(void)
00159 {
00160 int res;
00161
00162 res = ast_register_application(app_log, log_exec, log_synopsis, log_descrip);
00163 res |= ast_register_application(app_verbose, verbose_exec, verbose_synopsis, verbose_descrip);
00164
00165 return res;
00166 }
00167
00168 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send verbose output");