summaryrefslogtreecommitdiffabout
path: root/src/modconf.c
blob: 85b258246d998f5c6db0774a55717adadcfc802a (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
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "varnish_mib.h"
#include <ctype.h>

static int
timeout_parser(const char *token, char *line, unsigned *retval)
{
	char *p;
	unsigned long n = strtoul(line, &p, 10);

	if (*p) {
		if (isspace(*p)) {
			while (*p && isspace(*p))
				++p;
			if (*p) {
				config_perror("too many arguments");
				return 1;
			}
		} else {
			config_perror("invalid timeout value");
			return 1;
		}
	}
	
	if (n > UINT_MAX) {
		config_perror("timeout value out of allowed range");
		return 1;
	}
	
	*retval = n;
	return 0;
}

unsigned banTable_timeout = 60;
unsigned vcli_timeout = 5;
unsigned backendTable_timeout = 5;
vcli_sockaddr_t vcli_sockaddr;
char *vcli_secret;

static void
ban_table_timeout_parser(const char *token, char *line)
{
	timeout_parser(token, line, &banTable_timeout);
}

static void
backend_table_timeout_parser(const char *token, char *line)
{
	timeout_parser(token, line, &backendTable_timeout);
}

static void
vcli_timeout_parser(const char *token, char *line)
{
	timeout_parser(token, line, &vcli_timeout);
}

static void
vcli_address_parser(const char *token, char *line)
{
	vcli_sockaddr = vcli_parse_sockaddr(line);
}

static void
vcli_address_releaser(void)
{
	free(vcli_sockaddr);
}

static void
vcli_secret_parser(const char *token, char *line)
{
	vcli_secret = strdup(line);
}

static void
vcli_secret_releaser(void)
{
	free(vcli_secret);
}

struct varnish_mib_config
{
	char *token;
	char *help;
	void (*parser)(const char *token, char *line);
	void (*releaser) (void);
};

static struct varnish_mib_config config[] = {
	{ "varnishBanTableTimeout",
	  "varnishBanTableTimeout SECONDS",
	  ban_table_timeout_parser },
	{ "varnishBackendTableTimeout",
	  "varnishBackendTableTimeout SECONDS",
	  backend_table_timeout_parser },
	{ "varnishCLIPortTimeout",
	  "varnishCLIPortTimeout SECONDS",
	  vcli_timeout_parser },
	{ "varnishCLISocket",
	  "varnishCLISocket ADDRESS[:PORT]",
	  vcli_address_parser,
	  vcli_address_releaser },
	{ "varnishCLISecretFile",
	  "varnishCLISecretFile FILE",
	  vcli_secret_parser,
	  vcli_secret_releaser },
	{ NULL }
};

void
varnish_mib_config_init(void)
{
	struct varnish_mib_config *cp;
	for (cp = config; cp->token; cp++) {
		if (!register_config_handler("snmpd",
					     cp->token,
					     cp->parser,
					     cp->releaser,
					     cp->help))
			snmp_log(LOG_ERR,"can't register %s config handler\n",
				cp->token);
	}
}

Return to:

Send suggestions and report system problems to the System administrator.