From: Willy Tarreau Date: Wed, 6 Oct 2010 14:59:56 +0000 (+0200) Subject: [MINOR] cookie: add options "maxidle" and "maxlife" X-Git-Tag: v1.5-dev8~449 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3193685865c95c43cfbf1f26b70af8678e9b1bd3;p=thirdparty%2Fhaproxy.git [MINOR] cookie: add options "maxidle" and "maxlife" Add two new arguments to the "cookie" keyword, to be able to fix a max idle and max life on them. Right now only the parameter parsing is implemented. (cherry picked from commit 9ad5dec4c3bb8f29129f292cb22d3fc495fcc98a) --- diff --git a/include/types/proxy.h b/include/types/proxy.h index 46b61a2e3e..246a9bed8e 100644 --- a/include/types/proxy.h +++ b/include/types/proxy.h @@ -200,6 +200,8 @@ struct proxy { char *cookie_domain; /* domain used to insert the cookie */ char *cookie_name; /* name of the cookie to look for */ int cookie_len; /* strlen(cookie_name), computed only once */ + unsigned int cookie_maxidle; /* max idle time for this cookie */ + unsigned int cookie_maxlife; /* max life time for this cookie */ char *rdp_cookie_name; /* name of the RDP cookie to look for */ int rdp_cookie_len; /* strlen(rdp_cookie_name), computed only once */ char *url_param_name; /* name of the URL parameter used for hashing */ diff --git a/src/cfgparse.c b/src/cfgparse.c index 3cf1e4af0d..ef2d9ca10c 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -1179,6 +1179,12 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) if (defproxy.cookie_domain) curproxy->cookie_domain = strdup(defproxy.cookie_domain); + if (defproxy.cookie_maxidle) + curproxy->cookie_maxidle = defproxy.cookie_maxidle; + + if (defproxy.cookie_maxlife) + curproxy->cookie_maxlife = defproxy.cookie_maxlife; + if (defproxy.rdp_cookie_name) curproxy->rdp_cookie_name = strdup(defproxy.rdp_cookie_name); curproxy->rdp_cookie_len = defproxy.rdp_cookie_len; @@ -1719,8 +1725,50 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) } cur_arg++; } + else if (!strcmp(args[cur_arg], "maxidle")) { + unsigned int maxidle; + const char *res; + + if (!*args[cur_arg + 1]) { + Alert("parsing [%s:%d]: '%s' expects in seconds as argument.\n", + file, linenum, args[cur_arg]); + err_code |= ERR_ALERT | ERR_FATAL; + goto out; + } + + res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); + if (res) { + Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", + file, linenum, *res, args[cur_arg]); + err_code |= ERR_ALERT | ERR_FATAL; + goto out; + } + curproxy->cookie_maxidle = maxidle; + cur_arg++; + } + else if (!strcmp(args[cur_arg], "maxlife")) { + unsigned int maxlife; + const char *res; + + if (!*args[cur_arg + 1]) { + Alert("parsing [%s:%d]: '%s' expects in seconds as argument.\n", + file, linenum, args[cur_arg]); + err_code |= ERR_ALERT | ERR_FATAL; + goto out; + } + + res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); + if (res) { + Alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", + file, linenum, *res, args[cur_arg]); + err_code |= ERR_ALERT | ERR_FATAL; + goto out; + } + curproxy->cookie_maxlife = maxlife; + cur_arg++; + } else { - Alert("parsing [%s:%d] : '%s' supports 'rewrite', 'insert', 'prefix', 'indirect', 'nocache' and 'postonly', 'domain' options.\n", + Alert("parsing [%s:%d] : '%s' supports 'rewrite', 'insert', 'prefix', 'indirect', 'nocache', 'postonly', 'domain', 'maxidle, and 'maxlife' options.\n", file, linenum, args[0]); err_code |= ERR_ALERT | ERR_FATAL; goto out;