mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-02-20 20:57:00 +00:00
MINOR: cfgparse: Extract some code to be re-used.
Create init_peers_frontend() function to allocate and initialize the frontend of "peers" sections (->peers_fe) so that to reuse it later. May be backported to 1.5 and newer.
This commit is contained in:
parent
6583dca675
commit
1825103fbe
@ -482,6 +482,31 @@ void init_default_instance()
|
||||
defproxy.load_server_state_from_file = PR_SRV_STATE_FILE_UNSPEC;
|
||||
}
|
||||
|
||||
/* Allocate and initialize the frontend of a "peers" section found in
|
||||
* file <file> at line <linenum> with <id> as ID.
|
||||
* Return 0 if succeeded, -1 if not.
|
||||
*/
|
||||
static int init_peers_frontend(const char *file, int linenum,
|
||||
const char *id, struct peers *peers)
|
||||
{
|
||||
struct proxy *p;
|
||||
|
||||
p = calloc(1, sizeof *p);
|
||||
if (!p) {
|
||||
ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
|
||||
return -1;
|
||||
}
|
||||
|
||||
init_new_proxy(p);
|
||||
p->parent = peers;
|
||||
p->id = strdup(id);
|
||||
p->conf.args.file = p->conf.file = strdup(file);
|
||||
p->conf.args.line = p->conf.line = linenum;
|
||||
peers_setup_frontend(p);
|
||||
peers->peers_fe = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse a line in a <listen>, <frontend> or <backend> section.
|
||||
@ -624,19 +649,12 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
|
||||
cfg_peers->local = newpeer;
|
||||
|
||||
if (!curpeers->peers_fe) {
|
||||
if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) {
|
||||
if (init_peers_frontend(file, linenum, args[1], curpeers) != 0) {
|
||||
ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
|
||||
err_code |= ERR_ALERT | ERR_ABORT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
init_new_proxy(curpeers->peers_fe);
|
||||
curpeers->peers_fe->parent = curpeers;
|
||||
curpeers->peers_fe->id = strdup(args[1]);
|
||||
curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file);
|
||||
curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum;
|
||||
peers_setup_frontend(curpeers->peers_fe);
|
||||
|
||||
bind_conf = bind_conf_alloc(curpeers->peers_fe, file, linenum, args[2], xprt_get(XPRT_RAW));
|
||||
|
||||
if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) {
|
||||
|
Loading…
Reference in New Issue
Block a user