Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 2 | include/common/regex.h |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3 | This file defines everything related to regular expressions. |
| 4 | |
| 5 | Copyright (C) 2000-2006 Willy Tarreau - w@1wt.eu |
| 6 | |
| 7 | This library is free software; you can redistribute it and/or |
| 8 | modify it under the terms of the GNU Lesser General Public |
| 9 | License as published by the Free Software Foundation, version 2.1 |
| 10 | exclusively. |
| 11 | |
| 12 | This library is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | Lesser General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU Lesser General Public |
| 18 | License along with this library; if not, write to the Free Software |
| 19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 22 | #ifndef _COMMON_REGEX_H |
| 23 | #define _COMMON_REGEX_H |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 24 | |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 25 | #include <common/config.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 26 | |
| 27 | #ifdef USE_PCRE |
| 28 | #include <pcre.h> |
| 29 | #include <pcreposix.h> |
| 30 | #else |
| 31 | #include <regex.h> |
| 32 | #endif |
| 33 | |
| 34 | /* what to do when a header matches a regex */ |
| 35 | #define ACT_ALLOW 0 /* allow the request */ |
| 36 | #define ACT_REPLACE 1 /* replace the matching header */ |
| 37 | #define ACT_REMOVE 2 /* remove the matching header */ |
| 38 | #define ACT_DENY 3 /* deny the request */ |
| 39 | #define ACT_PASS 4 /* pass this header without allowing or denying the request */ |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 40 | #define ACT_TARPIT 5 /* tarpit the connection matching this request */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 41 | |
| 42 | struct hdr_exp { |
| 43 | struct hdr_exp *next; |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 44 | const regex_t *preg; /* expression to look for */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 45 | int action; /* ACT_ALLOW, ACT_REPLACE, ACT_REMOVE, ACT_DENY */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 46 | const char *replace; /* expression to set instead */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | extern regmatch_t pmatch[MAX_MATCH]; |
| 50 | |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 51 | int exp_replace(char *dst, char *src, const char *str, const regmatch_t *matches); |
| 52 | const char *check_replace_string(const char *str); |
| 53 | const char *chain_regex(struct hdr_exp **head, const regex_t *preg, |
| 54 | int action, const char *replace); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 55 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 56 | #endif /* _COMMON_REGEX_H */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 57 | |
| 58 | /* |
| 59 | * Local variables: |
| 60 | * c-indent-level: 8 |
| 61 | * c-basic-offset: 8 |
| 62 | * End: |
| 63 | */ |