blob: d9346d99640e6c6a35cdfa6ad157393e4f64d591 [file] [log] [blame]
Emeric Brun107ca302010-01-04 16:16:05 +01001/*
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 */
30enum {
Willy Tarreauaea940e2010-06-06 11:56:36 +020031 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 Brun107ca302010-01-04 16:16:05 +010035};
36
37/* pattern fetch direction */
38#define PATTERN_FETCH_REQ 1
39#define PATTERN_FETCH_RTR 2
40
41/* pattern result data */
42union pattern_data {
Willy Tarreauaea940e2010-06-06 11:56:36 +020043 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 Brun107ca302010-01-04 16:16:05 +010046};
47
48/* pattern result */
49struct pattern {
50 int type; /* current type of data */
51 union pattern_data data; /* data */
52};
53
54/* pattern conversion */
55struct pattern_conv {
56 const char *kw; /* configuration keyword */
Willy Tarreau1a51b632010-01-26 17:17:56 +010057 int (*process)(const void *arg_p,
58 int arg_i,
Emeric Brun107ca302010-01-04 16:16:05 +010059 union pattern_data *data); /* process function */
60 unsigned int in_type; /* input needed pattern type */
61 unsigned int out_type; /* output pattern type */
Willy Tarreau9e92d322010-01-26 17:58:06 +010062 int (*parse_args)(const char *arg_str,
63 void **arg_p,
64 int *arg_i); /* argument parser. Can be NULL. */
Emeric Brun107ca302010-01-04 16:16:05 +010065};
66
67/* pattern conversion expression */
68struct pattern_conv_expr {
69 struct list list; /* member of a pattern expression */
70 struct pattern_conv *conv; /* pattern conversion */
Willy Tarreau1a51b632010-01-26 17:17:56 +010071 void *arg_p; /* pointer arg, most often a string argument */
72 int arg_i; /* int arg, most often the argument's length */
Emeric Brun107ca302010-01-04 16:16:05 +010073};
74
75/* pattern fetch */
76struct 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 */
89struct 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 */
98struct 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 */
104struct 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 */