summaryrefslogtreecommitdiffabout
path: root/src/modconf.c
Side-by-side diff
Diffstat (limited to 'src/modconf.c') (more/less context) (ignore whitespace changes)
-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
--- a/dev/null
+++ b/src/modconf.c
@@ -0,0 +1,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.