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 */ |
| 34 | PATTERN_TYPES /* number of types, must always be last */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | /* pattern fetch direction */ |
| 38 | #define PATTERN_FETCH_REQ 1 |
| 39 | #define PATTERN_FETCH_RTR 2 |
| 40 | |
| 41 | /* pattern result data */ |
| 42 | union pattern_data { |
Willy Tarreau | aea940e | 2010-06-06 11:56:36 +0200 | [diff] [blame] | 43 | struct in_addr ip; /* used for ipv4 type */ |
| 44 | uint32_t integer; /* used for unsigned 32bits integer type */ |
| 45 | struct chunk str; /* used for char string type */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | /* pattern result */ |
| 49 | struct pattern { |
| 50 | int type; /* current type of data */ |
| 51 | union pattern_data data; /* data */ |
| 52 | }; |
| 53 | |
| 54 | /* pattern conversion */ |
| 55 | struct pattern_conv { |
| 56 | const char *kw; /* configuration keyword */ |
Willy Tarreau | 1a51b63 | 2010-01-26 17:17:56 +0100 | [diff] [blame] | 57 | int (*process)(const void *arg_p, |
| 58 | int arg_i, |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 59 | union pattern_data *data); /* process function */ |
| 60 | unsigned int in_type; /* input needed pattern type */ |
| 61 | unsigned int out_type; /* output pattern type */ |
Willy Tarreau | 9e92d32 | 2010-01-26 17:58:06 +0100 | [diff] [blame] | 62 | int (*parse_args)(const char *arg_str, |
| 63 | void **arg_p, |
| 64 | int *arg_i); /* argument parser. Can be NULL. */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | /* pattern conversion expression */ |
| 68 | struct pattern_conv_expr { |
| 69 | struct list list; /* member of a pattern expression */ |
| 70 | struct pattern_conv *conv; /* pattern conversion */ |
Willy Tarreau | 1a51b63 | 2010-01-26 17:17:56 +0100 | [diff] [blame] | 71 | void *arg_p; /* pointer arg, most often a string argument */ |
| 72 | int arg_i; /* int arg, most often the argument's length */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | /* pattern fetch */ |
| 76 | struct pattern_fetch { |
| 77 | const char *kw; /* configuration keyword */ |
| 78 | int (*process)(struct proxy *px, |
| 79 | struct session *l4, |
| 80 | void *l7, |
| 81 | int dir, const char *arg, |
| 82 | int arg_len, |
| 83 | union pattern_data *data); /* fetch processing function */ |
| 84 | unsigned long out_type; /* output pattern type */ |
| 85 | int dir; /* usable directions */ |
| 86 | }; |
| 87 | |
| 88 | /* pattern expression */ |
| 89 | struct pattern_expr { |
| 90 | struct list list; /* member of list of pattern, currently not used */ |
| 91 | struct pattern_fetch *fetch; /* pattern fetch */ |
| 92 | char *arg; /* configured keyword argument */ |
| 93 | int arg_len; /* configured keyword argument length */ |
| 94 | struct list conv_exprs; /* list of conversion expression to apply */ |
| 95 | }; |
| 96 | |
| 97 | /* pattern fetch keywords list */ |
| 98 | struct pattern_fetch_kw_list { |
| 99 | struct list list; /* head of pattern fetch keyword list */ |
| 100 | struct pattern_fetch kw[VAR_ARRAY]; /* array of pattern fetches */ |
| 101 | }; |
| 102 | |
| 103 | /* pattern conversion keywords list */ |
| 104 | struct pattern_conv_kw_list { |
| 105 | struct list list; /* head of pattern conversion keyword list */ |
| 106 | struct pattern_conv kw[VAR_ARRAY]; /* array of pattern ions */ |
| 107 | }; |
| 108 | |
| 109 | #endif /* _TYPES_PATTERN_H */ |