[MEDIUM] modularize the global "stats" keyword configuration parser

The "stats" keyword already relied on an external parser, let's
make use of the new keyword registration mechanism.
This commit is contained in:
Willy Tarreau 2008-07-09 20:12:41 +02:00
parent 5b2c33683b
commit 10522fd113
3 changed files with 16 additions and 10 deletions

View File

@ -3,7 +3,7 @@
This file contains definitions of some primitives to dedicated to
statistics output.
Copyright (C) 2000-2007 Willy Tarreau - w@1wt.eu
Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@ -39,7 +39,6 @@
#define STATS_TYPE_BE 1
#define STATS_TYPE_SV 2
int stats_parse_global(const char **args, char *err, int errlen);
int stats_dump_raw(struct session *s, struct uri_auth *uri);
int stats_dump_http(struct session *s, struct uri_auth *uri);
int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri);

View File

@ -295,13 +295,6 @@ int cfg_parse_global(const char *file, int linenum, char **args, int inv)
else if (!strcmp(args[0], "quiet")) {
global.mode |= MODE_QUIET;
}
else if (!strcmp(args[0], "stats")) {
memcpy(trash, "error near 'stats'", 19);
if (stats_parse_global((const char **)args + 1, trash, sizeof(trash)) < 0) {
Alert("parsing [%s:%d] : %s\n", file, linenum, trash);
return -1;
}
}
else if (!strcmp(args[0], "tune.maxpollevents")) {
if (global.tune.maxpollevents != 0) {
Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);

View File

@ -23,6 +23,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <common/cfgparse.h>
#include <common/compat.h>
#include <common/config.h>
#include <common/debug.h>
@ -55,8 +56,10 @@
* zero included. The trailing '\n' must not be written. The function must be
* called with <args> pointing to the first word after "stats".
*/
int stats_parse_global(const char **args, char *err, int errlen)
static int stats_parse_global(char **args, int section_type, struct proxy *curpx,
struct proxy *defpx, char *err, int errlen)
{
args++;
if (!strcmp(args[0], "socket")) {
struct sockaddr_un su;
int cur_arg;
@ -1067,6 +1070,17 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri)
}
}
static struct cfg_kw_list cfg_kws = {{ },{
{ CFG_GLOBAL, "stats", stats_parse_global },
{ 0, NULL, NULL },
}};
__attribute__((constructor))
static void __dumpstats_module_init(void)
{
cfg_register_keywords(&cfg_kws);
}
/*
* Local variables:
* c-indent-level: 8