Only play announce time on first pass
[asterisk/asterisk.git] / apps / app_verbose.c
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
3  *
4  * Verbose application
5  * 
6  * Copyright (c) 2004 Tilghman Lesher.  All rights reserved.
7  *
8  * Tilghman Lesher <app_verbose_v001@the-tilghman.com>
9  *
10  * This code is released by the author with no restrictions on usage.
11  *
12  */
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <unistd.h>
17 #include <string.h>
18 #include <asterisk/options.h>
19 #include <asterisk/logger.h>
20 #include <asterisk/channel.h>
21 #include <asterisk/pbx.h>
22 #include <asterisk/module.h>
23
24
25 static char *tdesc = "Send verbose output";
26
27 static char *app_verbose = "Verbose";
28
29 static char *verbose_synopsis = "Send arbitrary text to verbose output";
30
31 static char *verbose_descrip =
32 "Verbose([<level>|]<message>)\n"
33 "  level must be an integer value.  If not specified, defaults to 0."
34 "  Always returns 0.\n";
35
36 STANDARD_LOCAL_USER;
37
38 LOCAL_USER_DECL;
39
40 static int verbose_exec(struct ast_channel *chan, void *data)
41 {
42         char *vtext;
43         int vsize;
44
45         if (data) {
46                 vtext = ast_strdupa((char *)data);
47                 if (vtext) {
48                         char *tmp = strsep(&vtext, "|,");
49                         if (vtext) {
50                                 if (sscanf(tmp, "%d", &vsize) != 1) {
51                                         vsize = 0;
52                                         ast_log(LOG_WARNING, "'%s' is not a verboser number\n", vtext);
53                                 }
54                         } else {
55                                 vtext = tmp;
56                                 vsize = 0;
57                         }
58                         if (option_verbose >= vsize) {
59                                 switch (vsize) {
60                                 case 1:
61                                         ast_verbose(VERBOSE_PREFIX_1 "%s\n", vtext);
62                                         break;
63                                 case 2:
64                                         ast_verbose(VERBOSE_PREFIX_2 "%s\n", vtext);
65                                         break;
66                                 case 3:
67                                         ast_verbose(VERBOSE_PREFIX_3 "%s\n", vtext);
68                                         break;
69                                 default:
70                                         ast_verbose(VERBOSE_PREFIX_4 "%s\n", vtext);
71                                 }
72                         }
73                 } else {
74                         ast_log(LOG_ERROR, "Out of memory\n");
75                 }
76         }
77
78         return 0;
79 }
80
81 int unload_module(void)
82 {
83         STANDARD_HANGUP_LOCALUSERS;
84         return ast_unregister_application(app_verbose);
85 }
86
87 int load_module(void)
88 {
89         return ast_register_application(app_verbose, verbose_exec, verbose_synopsis, verbose_descrip);
90 }
91
92 char *description(void)
93 {
94         return tdesc;
95 }
96
97 int usecount(void)
98 {
99         int res;
100         STANDARD_USECOUNT(res);
101         return res;
102 }
103
104 char *key()
105 {
106         return ASTERISK_GPL_KEY;
107 }