mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2026-05-05 04:56:10 +02:00
MEDIUM: server: move parsing of keyword "id" to server.c
This is the first keyword to be moved to server.c.
This commit is contained in:
parent
d0d6059630
commit
dff5543618
@ -4028,38 +4028,7 @@ stats_error_parsing:
|
||||
}
|
||||
|
||||
while (*args[cur_arg]) {
|
||||
if (!defsrv && !strcmp(args[cur_arg], "id")) {
|
||||
struct eb32_node *node;
|
||||
|
||||
if (!*args[cur_arg + 1]) {
|
||||
Alert("parsing [%s:%d]: '%s' expects an integer argument.\n",
|
||||
file, linenum, args[cur_arg]);
|
||||
err_code |= ERR_ALERT | ERR_FATAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
newsrv->puid = atol(args[cur_arg + 1]);
|
||||
newsrv->conf.id.key = newsrv->puid;
|
||||
|
||||
if (newsrv->puid <= 0) {
|
||||
Alert("parsing [%s:%d]: custom id has to be > 0.\n",
|
||||
file, linenum);
|
||||
err_code |= ERR_ALERT | ERR_FATAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
node = eb32_lookup(&curproxy->conf.used_server_id, newsrv->puid);
|
||||
if (node) {
|
||||
struct server *target = container_of(node, struct server, conf.id);
|
||||
Alert("parsing [%s:%d]: server %s reuses same custom id as server %s (declared at %s:%d).\n",
|
||||
file, linenum, newsrv->id, target->id, target->conf.file, target->conf.line);
|
||||
err_code |= ERR_ALERT | ERR_FATAL;
|
||||
goto out;
|
||||
}
|
||||
eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id);
|
||||
cur_arg += 2;
|
||||
}
|
||||
else if (!defsrv && !strcmp(args[cur_arg], "cookie")) {
|
||||
if (!defsrv && !strcmp(args[cur_arg], "cookie")) {
|
||||
newsrv->cookie = strdup(args[cur_arg + 1]);
|
||||
newsrv->cklen = strlen(args[cur_arg + 1]);
|
||||
cur_arg += 2;
|
||||
|
||||
50
src/server.c
50
src/server.c
@ -12,6 +12,7 @@
|
||||
*/
|
||||
|
||||
#include <common/config.h>
|
||||
#include <common/errors.h>
|
||||
#include <common/time.h>
|
||||
|
||||
#include <proto/server.h>
|
||||
@ -106,6 +107,55 @@ void srv_dump_kws(char **out)
|
||||
}
|
||||
}
|
||||
|
||||
/* parse the "id" server keyword */
|
||||
static int srv_parse_id(char **args, int *cur_arg, struct proxy *curproxy, struct server *newsrv, char **err)
|
||||
{
|
||||
struct eb32_node *node;
|
||||
|
||||
if (!*args[*cur_arg + 1]) {
|
||||
memprintf(err, "'%s' : expects an integer argument", args[*cur_arg]);
|
||||
return ERR_ALERT | ERR_FATAL;
|
||||
}
|
||||
|
||||
newsrv->puid = atol(args[*cur_arg + 1]);
|
||||
newsrv->conf.id.key = newsrv->puid;
|
||||
|
||||
if (newsrv->puid <= 0) {
|
||||
memprintf(err, "'%s' : custom id has to be > 0", args[*cur_arg]);
|
||||
return ERR_ALERT | ERR_FATAL;
|
||||
}
|
||||
|
||||
node = eb32_lookup(&curproxy->conf.used_server_id, newsrv->puid);
|
||||
if (node) {
|
||||
struct server *target = container_of(node, struct server, conf.id);
|
||||
memprintf(err, "'%s' : custom id %d already used at %s:%d ('server %s')",
|
||||
args[*cur_arg], newsrv->puid, target->conf.file, target->conf.line,
|
||||
target->id);
|
||||
return ERR_ALERT | ERR_FATAL;
|
||||
}
|
||||
|
||||
eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Note: must not be declared <const> as its list will be overwritten.
|
||||
* Please take care of keeping this list alphabetically sorted, doing so helps
|
||||
* all code contributors.
|
||||
* Optional keywords are also declared with a NULL ->parse() function so that
|
||||
* the config parser can report an appropriate error when a known keyword was
|
||||
* not enabled.
|
||||
*/
|
||||
static struct srv_kw_list srv_kws = { "ALL", { }, {
|
||||
{ "id", srv_parse_id, 1, 0 }, /* set id# of server */
|
||||
{ NULL, NULL, 0 },
|
||||
}};
|
||||
|
||||
__attribute__((constructor))
|
||||
static void __listener_init(void)
|
||||
{
|
||||
srv_register_keywords(&srv_kws);
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* c-indent-level: 8
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user