Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1 | /* |
| 2 | * include/types/pattern.h |
| 3 | * Macros, variables and structures for patterns management. |
| 4 | * |
| 5 | * Copyright (C) 2009-2010 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr> |
| 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 | |
| 22 | #ifndef _TYPES_PATTERN_H |
| 23 | #define _TYPES_PATTERN_H |
| 24 | |
| 25 | #include <types/buffers.h> |
| 26 | #include <sys/socket.h> |
| 27 | #include <netinet/in.h> |
| 28 | |
| 29 | /* pattern in and out types */ |
| 30 | enum { |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 31 | PATTERN_TYPE_IP = 0, /* ipv4 type */ |
| 32 | PATTERN_TYPE_INTEGER, /* unsigned 32bits integer type */ |
| 33 | PATTERN_TYPE_STRING, /* char string type */ |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 34 | PATTERN_TYPE_DATA, /* buffer type */ |
| 35 | PATTERN_TYPE_CONSTSTRING, /* constant char string type, data need dup before conversion */ |
| 36 | PATTERN_TYPE_CONSTDATA, /* constant buffer type, data need dup before conversion */ |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 37 | PATTERN_TYPES /* number of types, must always be last */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 38 | }; |
| 39 | |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 40 | |
| 41 | /* pattern arg types */ |
| 42 | enum { |
| 43 | PATTERN_ARG_TYPE_IP = 0, /* ipv4 type */ |
| 44 | PATTERN_ARG_TYPE_INTEGER, /* unsigned 32bits integer type */ |
| 45 | PATTERN_ARG_TYPE_SINTEGER, /* signed 32bits integer type */ |
| 46 | PATTERN_ARG_TYPE_STRING /* string type */ |
| 47 | }; |
| 48 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 49 | /* pattern fetch direction */ |
| 50 | #define PATTERN_FETCH_REQ 1 |
| 51 | #define PATTERN_FETCH_RTR 2 |
| 52 | |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 53 | |
| 54 | union pattern_arg_data { |
| 55 | struct in_addr ip; /* used for ipv4 type */ |
| 56 | uint32_t integer; /* used for unsigned 32bits integer type */ |
Willy Tarreau | b695a6e | 2010-11-14 14:24:27 +0100 | [diff] [blame] | 57 | int sinteger; /* used for signed 32bits integer type */ |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 58 | struct chunk str; |
| 59 | }; |
| 60 | |
| 61 | struct pattern_arg { |
| 62 | int type; /* type of arg */ |
| 63 | union pattern_arg_data data; /* data */ |
| 64 | }; |
| 65 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 66 | /* pattern result data */ |
| 67 | union pattern_data { |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 68 | struct in_addr ip; /* used for ipv4 type */ |
| 69 | uint32_t integer; /* used for unsigned 32bits integer type */ |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 70 | struct chunk str; /* used for char string type or buffers*/ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | /* pattern result */ |
| 74 | struct pattern { |
| 75 | int type; /* current type of data */ |
| 76 | union pattern_data data; /* data */ |
| 77 | }; |
| 78 | |
| 79 | /* pattern conversion */ |
| 80 | struct pattern_conv { |
| 81 | const char *kw; /* configuration keyword */ |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 82 | int (*process)(const struct pattern_arg *arg_p, |
Willy Tarreau | 1a51b63 | 2010-01-26 17:17:56 +0100 | [diff] [blame] | 83 | int arg_i, |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 84 | union pattern_data *data); /* process function */ |
Willy Tarreau | 9e92d32 | 2010-01-26 17:58:06 +0100 | [diff] [blame] | 85 | int (*parse_args)(const char *arg_str, |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 86 | struct pattern_arg **arg_p, |
Willy Tarreau | 9e92d32 | 2010-01-26 17:58:06 +0100 | [diff] [blame] | 87 | int *arg_i); /* argument parser. Can be NULL. */ |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 88 | unsigned int in_type; /* input needed pattern type */ |
| 89 | unsigned int out_type; /* output pattern type */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | /* pattern conversion expression */ |
| 93 | struct pattern_conv_expr { |
| 94 | struct list list; /* member of a pattern expression */ |
| 95 | struct pattern_conv *conv; /* pattern conversion */ |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 96 | struct pattern_arg *arg_p; /* pointer on args */ |
| 97 | int arg_i; /* number of args */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | /* pattern fetch */ |
| 101 | struct pattern_fetch { |
| 102 | const char *kw; /* configuration keyword */ |
| 103 | int (*process)(struct proxy *px, |
| 104 | struct session *l4, |
| 105 | void *l7, |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 106 | int dir, const struct pattern_arg *arg_p, |
| 107 | int arg_i, |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 108 | union pattern_data *data); /* fetch processing function */ |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 109 | int (*parse_args)(const char *arg_str, |
| 110 | struct pattern_arg **arg_p, |
| 111 | int *arg_i); /* argument parser. Can be NULL. */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 112 | unsigned long out_type; /* output pattern type */ |
| 113 | int dir; /* usable directions */ |
| 114 | }; |
| 115 | |
| 116 | /* pattern expression */ |
| 117 | struct pattern_expr { |
| 118 | struct list list; /* member of list of pattern, currently not used */ |
| 119 | struct pattern_fetch *fetch; /* pattern fetch */ |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 120 | struct pattern_arg *arg_p; /* pointer on args */ |
| 121 | int arg_i; /* number of args */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 122 | struct list conv_exprs; /* list of conversion expression to apply */ |
| 123 | }; |
| 124 | |
| 125 | /* pattern fetch keywords list */ |
| 126 | struct pattern_fetch_kw_list { |
| 127 | struct list list; /* head of pattern fetch keyword list */ |
| 128 | struct pattern_fetch kw[VAR_ARRAY]; /* array of pattern fetches */ |
| 129 | }; |
| 130 | |
| 131 | /* pattern conversion keywords list */ |
| 132 | struct pattern_conv_kw_list { |
| 133 | struct list list; /* head of pattern conversion keyword list */ |
| 134 | struct pattern_conv kw[VAR_ARRAY]; /* array of pattern ions */ |
| 135 | }; |
| 136 | |
| 137 | #endif /* _TYPES_PATTERN_H */ |