aboutsummaryrefslogtreecommitdiff
path: root/src/modconf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/modconf.c')
-rw-r--r--src/modconf.c123
1 files changed, 123 insertions, 0 deletions
diff --git a/src/modconf.c b/src/modconf.c
new file mode 100644
index 0000000..85b2582
--- /dev/null
+++ b/src/modconf.c
@@ -0,0 +1,123 @@
1#include "varnish_mib.h"
2#include <ctype.h>
3
4static int
5timeout_parser(const char *token, char *line, unsigned *retval)
6{
7 char *p;
8 unsigned long n = strtoul(line, &p, 10);
9
10 if (*p) {
11 if (isspace(*p)) {
12 while (*p && isspace(*p))
13 ++p;
14 if (*p) {
15 config_perror("too many arguments");
16 return 1;
17 }
18 } else {
19 config_perror("invalid timeout value");
20 return 1;
21 }
22 }
23
24 if (n > UINT_MAX) {
25 config_perror("timeout value out of allowed range");
26 return 1;
27 }
28
29 *retval = n;
30 return 0;
31}
32
33unsigned banTable_timeout = 60;
34unsigned vcli_timeout = 5;
35unsigned backendTable_timeout = 5;
36vcli_sockaddr_t vcli_sockaddr;
37char *vcli_secret;
38
39static void
40ban_table_timeout_parser(const char *token, char *line)
41{
42 timeout_parser(token, line, &banTable_timeout);
43}
44
45static void
46backend_table_timeout_parser(const char *token, char *line)
47{
48 timeout_parser(token, line, &backendTable_timeout);
49}
50
51static void
52vcli_timeout_parser(const char *token, char *line)
53{
54 timeout_parser(token, line, &vcli_timeout);
55}
56
57static void
58vcli_address_parser(const char *token, char *line)
59{
60 vcli_sockaddr = vcli_parse_sockaddr(line);
61}
62
63static void
64vcli_address_releaser(void)
65{
66 free(vcli_sockaddr);
67}
68
69static void
70vcli_secret_parser(const char *token, char *line)
71{
72 vcli_secret = strdup(line);
73}
74
75static void
76vcli_secret_releaser(void)
77{
78 free(vcli_secret);
79}
80
81struct varnish_mib_config
82{
83 char *token;
84 char *help;
85 void (*parser)(const char *token, char *line);
86 void (*releaser) (void);
87};
88
89static struct varnish_mib_config config[] = {
90 { "varnishBanTableTimeout",
91 "varnishBanTableTimeout SECONDS",
92 ban_table_timeout_parser },
93 { "varnishBackendTableTimeout",
94 "varnishBackendTableTimeout SECONDS",
95 backend_table_timeout_parser },
96 { "varnishCLIPortTimeout",
97 "varnishCLIPortTimeout SECONDS",
98 vcli_timeout_parser },
99 { "varnishCLISocket",
100 "varnishCLISocket ADDRESS[:PORT]",
101 vcli_address_parser,
102 vcli_address_releaser },
103 { "varnishCLISecretFile",
104 "varnishCLISecretFile FILE",
105 vcli_secret_parser,
106 vcli_secret_releaser },
107 { NULL }
108};
109
110void
111varnish_mib_config_init(void)
112{
113 struct varnish_mib_config *cp;
114 for (cp = config; cp->token; cp++) {
115 if (!register_config_handler("snmpd",
116 cp->token,
117 cp->parser,
118 cp->releaser,
119 cp->help))
120 snmp_log(LOG_ERR,"can't register %s config handler\n",
121 cp->token);
122 }
123}

Return to:

Send suggestions and report system problems to the System administrator.