aboutsummaryrefslogtreecommitdiffstats
path: root/apps/app_verbose.c
blob: ade139038482e0bd6e234d63e01426e83698400f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * Asterisk -- A telephony toolkit for Linux.
 *
 * Verbose application
 * 
 * Copyright (c) 2004 Tilghman Lesher.  All rights reserved.
 *
 * Tilghman Lesher <app_verbose_v001@the-tilghman.com>
 *
 * This code is released by the author with no restrictions on usage.
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <asterisk/options.h>
#include <asterisk/logger.h>
#include <asterisk/channel.h>
#include <asterisk/pbx.h>
#include <asterisk/module.h>


static char *tdesc = "Send verbose output";

static char *app_verbose = "Verbose";

static char *verbose_synopsis = "Send arbitrary text to verbose output";

static char *verbose_descrip =
"Verbose([<level>|]<message>)\n"
"  level must be an integer value.  If not specified, defaults to 0."
"  Always returns 0.\n";

STANDARD_LOCAL_USER;

LOCAL_USER_DECL;

static int verbose_exec(struct ast_channel *chan, void *data)
{
	char *vtext;
	int vsize;

	if (data) {
		vtext = ast_strdupa((char *)data);
		if (vtext) {
			char *tmp = strsep(&vtext, "|,");
			if (vtext) {
				if (sscanf(tmp, "%d", &vsize) != 1) {
					vsize = 0;
					ast_log(LOG_WARNING, "'%s' is not a verboser number\n", vtext);
				}
			} else {
				vtext = tmp;
				vsize = 0;
			}
			if (option_verbose >= vsize) {
				switch (vsize) {
				case 0:
					ast_verbose("%s\n", vtext);
					break;
				case 1:
					ast_verbose(VERBOSE_PREFIX_1 "%s\n", vtext);
					break;
				case 2:
					ast_verbose(VERBOSE_PREFIX_2 "%s\n", vtext);
					break;
				case 3:
					ast_verbose(VERBOSE_PREFIX_3 "%s\n", vtext);
					break;
				default:
					ast_verbose(VERBOSE_PREFIX_4 "%s\n", vtext);
				}
			}
		} else {
			ast_log(LOG_ERROR, "Out of memory\n");
		}
	}

	return 0;
}

int unload_module(void)
{
	STANDARD_HANGUP_LOCALUSERS;
	return ast_unregister_application(app_verbose);
}

int load_module(void)
{
	return ast_register_application(app_verbose, verbose_exec, verbose_synopsis, verbose_descrip);
}

char *description(void)
{
	return tdesc;
}

int usecount(void)
{
	int res;
	STANDARD_USECOUNT(res);
	return res;
}

char *key()
{
	return ASTERISK_GPL_KEY;
}