Merge "AST-2018-005: Fix tdata leaks when calling pjsip_endpt_send_response(2)"
[asterisk/asterisk.git] / apps / app_verbose.c
index b4c6a63..5b78e18 100644 (file)
  * \ingroup applications
  */
 
-#include "asterisk.h"
+/*** MODULEINFO
+       <support_level>core</support_level>
+ ***/
 
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+#include "asterisk.h"
 
 #include "asterisk/module.h"
 #include "asterisk/app.h"
@@ -57,9 +59,9 @@ static char *app_log = "Log";
                        Send arbitrary text to a selected log level.
                </synopsis>
                <syntax>
-                       <parameter name="level">
+                       <parameter name="level" required="true">
                                <para>Level must be one of <literal>ERROR</literal>, <literal>WARNING</literal>, <literal>NOTICE</literal>,
-                               <literal>DEBUG</literal>, <literal>VERBOSE</literal> or <literal>DTMF</literal>.</para> 
+                               <literal>DEBUG</literal>, <literal>VERBOSE</literal> or <literal>DTMF</literal>.</para>
                        </parameter>
                        <parameter name="message" required="true">
                                <para>Output text message.</para>
@@ -72,9 +74,9 @@ static char *app_log = "Log";
  ***/
 
 
-static int verbose_exec(struct ast_channel *chan, void *data)
+static int verbose_exec(struct ast_channel *chan, const char *data)
 {
-       int vsize;
+       unsigned int vsize;
        char *parse;
        AST_DECLARE_APP_ARGS(args,
                AST_APP_ARG(level);
@@ -92,33 +94,19 @@ static int verbose_exec(struct ast_channel *chan, void *data)
                args.level = "0";
        }
 
-       if (sscanf(args.level, "%d", &vsize) != 1) {
+       if (sscanf(args.level, "%30u", &vsize) != 1) {
                vsize = 0;
                ast_log(LOG_WARNING, "'%s' is not a verboser number\n", args.level);
+       } else if (4 < vsize) {
+               vsize = 4;
        }
-       if (option_verbose >= vsize) {
-               switch (vsize) {
-               case 0:
-                       ast_verbose("%s\n", args.msg);
-                       break;
-               case 1:
-                       ast_verbose(VERBOSE_PREFIX_1 "%s\n", args.msg);
-                       break;
-               case 2:
-                       ast_verbose(VERBOSE_PREFIX_2 "%s\n", args.msg);
-                       break;
-               case 3:
-                       ast_verbose(VERBOSE_PREFIX_3 "%s\n", args.msg);
-                       break;
-               default:
-                       ast_verbose(VERBOSE_PREFIX_4 "%s\n", args.msg);
-               }
-       }
+
+       ast_verb(vsize, "%s\n", args.msg);
 
        return 0;
 }
 
-static int log_exec(struct ast_channel *chan, void *data)
+static int log_exec(struct ast_channel *chan, const char *data)
 {
        char *parse;
        int lnum = -1;
@@ -146,17 +134,15 @@ static int log_exec(struct ast_channel *chan, void *data)
                lnum = __LOG_VERBOSE;
        } else if (!strcasecmp(args.level, "DTMF")) {
                lnum = __LOG_DTMF;
-       } else if (!strcasecmp(args.level, "EVENT")) {
-               lnum = __LOG_EVENT;
        } else {
                ast_log(LOG_ERROR, "Unknown log level: '%s'\n", args.level);
        }
 
        if (lnum > -1) {
-               snprintf(context, sizeof(context), "@ %s", chan->context);
-               snprintf(extension, sizeof(extension), "Ext. %s", chan->exten);
+               snprintf(context, sizeof(context), "@ %s", ast_channel_context(chan));
+               snprintf(extension, sizeof(extension), "Ext. %s", ast_channel_exten(chan));
 
-               ast_log(lnum, extension, chan->priority, context, "%s\n", args.msg);
+               ast_log(lnum, extension, ast_channel_priority(chan), context, "%s\n", args.msg);
        }
 
        return 0;
@@ -169,7 +155,7 @@ static int unload_module(void)
        res = ast_unregister_application(app_verbose);
        res |= ast_unregister_application(app_log);
 
-       return res;     
+       return res;
 }
 
 static int load_module(void)