/*
- include/common/regex.h
- This file defines everything related to regular expressions.
-
- Copyright (C) 2000-2006 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
- License as published by the Free Software Foundation, version 2.1
- exclusively.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ * include/common/regex.h
+ * This file defines everything related to regular expressions.
+ *
+ * Copyright (C) 2000-2010 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
+ * License as published by the Free Software Foundation, version 2.1
+ * exclusively.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
#ifndef _COMMON_REGEX_H
#define _COMMON_REGEX_H
const regex_t *preg; /* expression to look for */
int action; /* ACT_ALLOW, ACT_REPLACE, ACT_REMOVE, ACT_DENY */
const char *replace; /* expression to set instead */
+ void *cond; /* a possible condition or NULL */
};
extern regmatch_t pmatch[MAX_MATCH];
int exp_replace(char *dst, char *src, const char *str, const regmatch_t *matches);
const char *check_replace_string(const char *str);
const char *chain_regex(struct hdr_exp **head, const regex_t *preg,
- int action, const char *replace);
+ int action, const char *replace, void *cond);
#endif /* _COMMON_REGEX_H */
goto out;
}
- err = chain_regex(&curproxy->req_exp, preg, ACT_REPLACE, strdup(args[2]));
+ err = chain_regex(&curproxy->req_exp, preg, ACT_REPLACE, strdup(args[2]), NULL);
if (err) {
Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
file, linenum, *err);
goto out;
}
- chain_regex(&curproxy->req_exp, preg, ACT_REMOVE, NULL);
+ chain_regex(&curproxy->req_exp, preg, ACT_REMOVE, NULL, NULL);
warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]);
}
else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */
goto out;
}
- chain_regex(&curproxy->req_exp, preg, ACT_DENY, NULL);
+ chain_regex(&curproxy->req_exp, preg, ACT_DENY, NULL, NULL);
warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]);
}
else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */
goto out;
}
- chain_regex(&curproxy->req_exp, preg, ACT_PASS, NULL);
+ chain_regex(&curproxy->req_exp, preg, ACT_PASS, NULL, NULL);
warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]);
}
else if (!strcmp(args[0], "reqallow")) { /* allow a request if a header matches this regex */
goto out;
}
- chain_regex(&curproxy->req_exp, preg, ACT_ALLOW, NULL);
+ chain_regex(&curproxy->req_exp, preg, ACT_ALLOW, NULL, NULL);
warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]);
}
else if (!strcmp(args[0], "reqtarpit")) { /* tarpit a request if a header matches this regex */
goto out;
}
- chain_regex(&curproxy->req_exp, preg, ACT_TARPIT, NULL);
+ chain_regex(&curproxy->req_exp, preg, ACT_TARPIT, NULL, NULL);
warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]);
}
else if (!strcmp(args[0], "reqsetbe")) { /* switch the backend from a regex, respecting case */
goto out;
}
- chain_regex(&curproxy->req_exp, preg, ACT_SETBE, strdup(args[2]));
+ chain_regex(&curproxy->req_exp, preg, ACT_SETBE, strdup(args[2]), NULL);
warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]);
}
else if (!strcmp(args[0], "reqisetbe")) { /* switch the backend from a regex, ignoring case */
goto out;
}
- chain_regex(&curproxy->req_exp, preg, ACT_SETBE, strdup(args[2]));
+ chain_regex(&curproxy->req_exp, preg, ACT_SETBE, strdup(args[2]), NULL);
warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]);
}
else if (!strcmp(args[0], "reqirep")) { /* replace request header from a regex, ignoring case */
goto out;
}
- err = chain_regex(&curproxy->req_exp, preg, ACT_REPLACE, strdup(args[2]));
+ err = chain_regex(&curproxy->req_exp, preg, ACT_REPLACE, strdup(args[2]), NULL);
if (err) {
Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
file, linenum, *err);
goto out;
}
- chain_regex(&curproxy->req_exp, preg, ACT_REMOVE, NULL);
+ chain_regex(&curproxy->req_exp, preg, ACT_REMOVE, NULL, NULL);
warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]);
}
else if (!strcmp(args[0], "reqideny")) { /* deny a request if a header matches this regex ignoring case */
goto out;
}
- chain_regex(&curproxy->req_exp, preg, ACT_DENY, NULL);
+ chain_regex(&curproxy->req_exp, preg, ACT_DENY, NULL, NULL);
warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]);
}
else if (!strcmp(args[0], "reqipass")) { /* pass this header without allowing or denying the request */
goto out;
}
- chain_regex(&curproxy->req_exp, preg, ACT_PASS, NULL);
+ chain_regex(&curproxy->req_exp, preg, ACT_PASS, NULL, NULL);
warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]);
}
else if (!strcmp(args[0], "reqiallow")) { /* allow a request if a header matches this regex ignoring case */
goto out;
}
- chain_regex(&curproxy->req_exp, preg, ACT_ALLOW, NULL);
+ chain_regex(&curproxy->req_exp, preg, ACT_ALLOW, NULL, NULL);
warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]);
}
else if (!strcmp(args[0], "reqitarpit")) { /* tarpit a request if a header matches this regex ignoring case */
goto out;
}
- chain_regex(&curproxy->req_exp, preg, ACT_TARPIT, NULL);
+ chain_regex(&curproxy->req_exp, preg, ACT_TARPIT, NULL, NULL);
warnif_misplaced_reqxxx(curproxy, file, linenum, args[0]);
}
else if (!strcmp(args[0], "reqadd")) { /* add request header */
- struct wordlist *wl;
+ struct cond_wordlist *wl;
if (curproxy == &defproxy) {
Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
goto out;
}
- err = chain_regex(&curproxy->rsp_exp, preg, ACT_REPLACE, strdup(args[2]));
+ err = chain_regex(&curproxy->rsp_exp, preg, ACT_REPLACE, strdup(args[2]), NULL);
if (err) {
Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
file, linenum, *err);
goto out;
}
- err = chain_regex(&curproxy->rsp_exp, preg, ACT_REMOVE, strdup(args[2]));
+ err = chain_regex(&curproxy->rsp_exp, preg, ACT_REMOVE, strdup(args[2]), NULL);
if (err) {
Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
file, linenum, *err);
goto out;
}
- err = chain_regex(&curproxy->rsp_exp, preg, ACT_DENY, strdup(args[2]));
+ err = chain_regex(&curproxy->rsp_exp, preg, ACT_DENY, strdup(args[2]), NULL);
if (err) {
Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
file, linenum, *err);
goto out;
}
- err = chain_regex(&curproxy->rsp_exp, preg, ACT_REPLACE, strdup(args[2]));
+ err = chain_regex(&curproxy->rsp_exp, preg, ACT_REPLACE, strdup(args[2]), NULL);
if (err) {
Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
file, linenum, *err);
goto out;
}
- err = chain_regex(&curproxy->rsp_exp, preg, ACT_REMOVE, strdup(args[2]));
+ err = chain_regex(&curproxy->rsp_exp, preg, ACT_REMOVE, strdup(args[2]), NULL);
if (err) {
Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
file, linenum, *err);
goto out;
}
- err = chain_regex(&curproxy->rsp_exp, preg, ACT_DENY, strdup(args[2]));
+ err = chain_regex(&curproxy->rsp_exp, preg, ACT_DENY, strdup(args[2]), NULL);
if (err) {
Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
file, linenum, *err);
}
}
else if (!strcmp(args[0], "rspadd")) { /* add response header */
- struct wordlist *wl;
+ struct cond_wordlist *wl;
if (curproxy == &defproxy) {
Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);