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 { |
| 31 | PATTERN_TYPE_IP = 0, /* ipv4 type */ |
| 32 | PATTERN_TYPE_INTEGER = 1, /* unsigned 32bits integer type */ |
| 33 | PATTERN_TYPE_STRING = 2, /* char string type */ |
| 34 | PATTERN_TYPES |
| 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 { |
| 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 */ |
| 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 */ |
| 57 | int (*process)(const char *arg, |
| 58 | int arg_len, |
| 59 | union pattern_data *data); /* process function */ |
| 60 | unsigned int in_type; /* input needed pattern type */ |
| 61 | unsigned int out_type; /* output pattern type */ |
| 62 | }; |
| 63 | |
| 64 | /* pattern conversion expression */ |
| 65 | struct pattern_conv_expr { |
| 66 | struct list list; /* member of a pattern expression */ |
| 67 | struct pattern_conv *conv; /* pattern conversion */ |
| 68 | char *arg; /* configured keyword argument */ |
| 69 | int arg_len; /* configured keyword argument length */ |
| 70 | }; |
| 71 | |
| 72 | /* pattern fetch */ |
| 73 | struct pattern_fetch { |
| 74 | const char *kw; /* configuration keyword */ |
| 75 | int (*process)(struct proxy *px, |
| 76 | struct session *l4, |
| 77 | void *l7, |
| 78 | int dir, const char *arg, |
| 79 | int arg_len, |
| 80 | union pattern_data *data); /* fetch processing function */ |
| 81 | unsigned long out_type; /* output pattern type */ |
| 82 | int dir; /* usable directions */ |
| 83 | }; |
| 84 | |
| 85 | /* pattern expression */ |
| 86 | struct pattern_expr { |
| 87 | struct list list; /* member of list of pattern, currently not used */ |
| 88 | struct pattern_fetch *fetch; /* pattern fetch */ |
| 89 | char *arg; /* configured keyword argument */ |
| 90 | int arg_len; /* configured keyword argument length */ |
| 91 | struct list conv_exprs; /* list of conversion expression to apply */ |
| 92 | }; |
| 93 | |
| 94 | /* pattern fetch keywords list */ |
| 95 | struct pattern_fetch_kw_list { |
| 96 | struct list list; /* head of pattern fetch keyword list */ |
| 97 | struct pattern_fetch kw[VAR_ARRAY]; /* array of pattern fetches */ |
| 98 | }; |
| 99 | |
| 100 | /* pattern conversion keywords list */ |
| 101 | struct pattern_conv_kw_list { |
| 102 | struct list list; /* head of pattern conversion keyword list */ |
| 103 | struct pattern_conv kw[VAR_ARRAY]; /* array of pattern ions */ |
| 104 | }; |
| 105 | |
| 106 | #endif /* _TYPES_PATTERN_H */ |