aboutsummaryrefslogtreecommitdiff
path: root/src/modconf.c
blob: 152d48871392b62a12702d5704e1677681b029d9 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* This file is part of varnish-mib
   Copyright (C) 2018-2019 Sergey Poznyakoff

   Varnish-mib is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   Varnish-mib is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with varnish-mib.  If not, see <http://www.gnu.org/licenses/>.
*/

#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;
char *pid_file = NULL;
int pid_file_immutable = 0;

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);
}

static void
pidfile_parser(const char *token, char *line)
{
	if (!pid_file_immutable)
		pid_file = strdup(line);
}

static void
pidfile_releaser(void)
{
	/* nothing */
}

struct varnish_mib_config
{
	char *token;
	char *help;
	void (*parser)(const char *token, char *line);
	void (*releaser) (void);
};

static struct varnish_mib_config config[] = {
	{ "banTableTimeout",
	  "SECONDS",
	  ban_table_timeout_parser },
	{ "backendTableTimeout",
	  "SECONDS",
	  backend_table_timeout_parser },
	{ "cliPortTimeout",
	  "SECONDS",
	  vcli_timeout_parser },
	{ "CLISocket",
	  "ADDRESS[:PORT]",
	  vcli_address_parser,
	  vcli_address_releaser },
	{ "CLISecretFile",
	  "FILE",
	  vcli_secret_parser,
	  vcli_secret_releaser },
	{ "pidfile",
	  "FILE",
	  pidfile_parser,
	  pidfile_releaser },
	  
	{ NULL }
};

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

void
varnish_mib_config_help(void)
{
	int i;

	for (i = 0; config[i].token; i++) {
		printf("%s %s\n", config[i].token, config[i].help);
	}
}

Return to:

Send suggestions and report system problems to the System administrator.