Debian Codegraph @

apps/app_verbose.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (c) 2004 - 2005 Tilghman Lesher. All rights reserved.
5 *
6 * Tilghman Lesher <[email protected]>
7 *
8 * This code is released by the author with no restrictions on usage.
9 *
10 * See http://www.asterisk.org for more information about
11 * the Asterisk project. Please do not directly contact
12 * any of the maintainers of this project for assistance;
13 * the project provides a web site, mailing lists and IRC
14 * channels for your use.
15 *
16 */
17
18 /*! \file
19 *
20 * \brief Verbose logging application
21 *
22 * \author Tilghman Lesher <[email protected]>
23 *
24 * \ingroup applications
25 */
26
27 /*** MODULEINFO
28 <support_level>core</support_level>
29 ***/
30
31 #include "asterisk.h"
32
33 #include "asterisk/module.h"
34 #include "asterisk/app.h"
35 #include "asterisk/channel.h"
36 #include "asterisk/logger.h"
37
38 static char *app_verbose = "Verbose";
39 static char *app_log = "Log";
40
41 /*** DOCUMENTATION
42 <application name="Verbose" language="en_US">
43 <since>
44 <version>1.0.0</version>
45 </since>
46 <synopsis>
47 Send arbitrary text to verbose output.
48 </synopsis>
49 <syntax>
50 <parameter name="level">
51 <para>Must be an integer value. If not specified, defaults to 0.</para>
52 </parameter>
53 <parameter name="message" required="true">
54 <para>Output text message.</para>
55 </parameter>
56 </syntax>
57 <description>
58 <para>Sends an arbitrary text message to verbose output.</para>
59 </description>
60 </application>
61 <application name="Log" language="en_US">
62 <since>
63 <version>1.4.0</version>
64 </since>
65 <synopsis>
66 Send arbitrary text to a selected log level.
67 </synopsis>
68 <syntax>
69 <parameter name="level" required="true">
70 <para>Level must be one of <literal>ERROR</literal>, <literal>WARNING</literal>, <literal>NOTICE</literal>,
71 <literal>DEBUG</literal>, <literal>VERBOSE</literal>, <literal>DTMF</literal>, or
72 the name of a custom dynamic logging level.</para>
73 </parameter>
74 <parameter name="message" required="true">
75 <para>Output text message.</para>
76 </parameter>
77 </syntax>
78 <description>
79 <para>Sends an arbitrary text message to a selected log level.</para>
80 </description>
81 </application>
82 ***/
83
84
85 static int verbose_exec(struct ast_channel *chan, const char *data)
86 {
87 unsigned int vsize;
88 char *parse;
89 AST_DECLARE_APP_ARGS(args,
90 AST_APP_ARG(level);
91 AST_APP_ARG(msg);
92 );
93
94 if (ast_strlen_zero(data)) {
95 return 0;
96 }
97
98 parse = ast_strdupa(data);
99 AST_STANDARD_APP_ARGS(args, parse);
100 if (args.argc == 1) {
101 args.msg = args.level;
102 args.level = "0";
103 }
104
105 if (sscanf(args.level, "%30u", &vsize) != 1) {
106 vsize = 0;
107 ast_log(LOG_WARNING, "'%s' is not a verboser number\n", args.level);
108 } else if (4 < vsize) {
109 vsize = 4;
110 }
111
112 ast_verb(vsize, "%s\n", args.msg);
113
114 return 0;
115 }
116
117 static int log_exec(struct ast_channel *chan, const char *data)
118 {
119 char *parse;
120 int lnum = -1;
121 char extension[AST_MAX_EXTENSION + 5], context[AST_MAX_EXTENSION + 2];
122 AST_DECLARE_APP_ARGS(args,
123 AST_APP_ARG(level);
124 AST_APP_ARG(msg);
125 );
126
127 if (ast_strlen_zero(data))
128 return 0;
129
130 parse = ast_strdupa(data);
131 AST_STANDARD_APP_ARGS(args, parse);
132
133 if (!strcasecmp(args.level, "ERROR")) {
134 lnum = __LOG_ERROR;
135 } else if (!strcasecmp(args.level, "WARNING")) {
136 lnum = __LOG_WARNING;
137 } else if (!strcasecmp(args.level, "NOTICE")) {
138 lnum = __LOG_NOTICE;
139 } else if (!strcasecmp(args.level, "DEBUG")) {
140 lnum = __LOG_DEBUG;
141 } else if (!strcasecmp(args.level, "VERBOSE")) {
142 lnum = __LOG_VERBOSE;
143 } else if (!strcasecmp(args.level, "DTMF")) {
144 lnum = __LOG_DTMF;
145 } else {
146 lnum = ast_logger_get_dynamic_level(args.level);
147 }
148
149 if (lnum > -1) {
150 snprintf(context, sizeof(context), "@ %s", ast_channel_context(chan));
151 snprintf(extension, sizeof(extension), "Ext. %s", ast_channel_exten(chan));
152
153 ast_log(lnum, extension, ast_channel_priority(chan), context, "%s\n", args.msg);
154 } else {
155 ast_log(LOG_ERROR, "Unknown log level: '%s'\n", args.level);
156 return 0;
157 }
158
159 return 0;
160 }
161
162 static int unload_module(void)
163 {
164 int res;
165
166 res = ast_unregister_application(app_verbose);
167 res |= ast_unregister_application(app_log);
168
169 return res;
170 }
171
172 static int load_module(void)
173 {
174 int res;
175
176 res = ast_register_application_xml(app_log, log_exec);
177 res |= ast_register_application_xml(app_verbose, verbose_exec);
178
179 return res;
180 }
181
182 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send verbose output");