blob: c3718862d7567a749c30f01681b8125a333c4133 [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
Emeric Brun107ca302010-01-04 16:16:05 +010025#include <sys/socket.h>
26#include <netinet/in.h>
Willy Tarreauecfb8e82012-04-20 12:29:52 +020027#include <types/arg.h>
28#include <types/buffers.h>
Emeric Brun107ca302010-01-04 16:16:05 +010029
30/* pattern in and out types */
31enum {
Willy Tarreauaea940e2010-06-06 11:56:36 +020032 PATTERN_TYPE_IP = 0, /* ipv4 type */
David du Colombier4f92d322011-03-24 11:09:31 +010033 PATTERN_TYPE_IPV6, /* ipv6 type */
Willy Tarreauaea940e2010-06-06 11:56:36 +020034 PATTERN_TYPE_INTEGER, /* unsigned 32bits integer type */
35 PATTERN_TYPE_STRING, /* char string type */
Emeric Brun485479d2010-09-23 18:02:19 +020036 PATTERN_TYPE_DATA, /* buffer type */
37 PATTERN_TYPE_CONSTSTRING, /* constant char string type, data need dup before conversion */
38 PATTERN_TYPE_CONSTDATA, /* constant buffer type, data need dup before conversion */
Willy Tarreauaea940e2010-06-06 11:56:36 +020039 PATTERN_TYPES /* number of types, must always be last */
Emeric Brun107ca302010-01-04 16:16:05 +010040};
41
Emeric Brun485479d2010-09-23 18:02:19 +020042
Emeric Brun107ca302010-01-04 16:16:05 +010043/* pattern fetch direction */
44#define PATTERN_FETCH_REQ 1
45#define PATTERN_FETCH_RTR 2
46
Emeric Brun485479d2010-09-23 18:02:19 +020047
Emeric Brun107ca302010-01-04 16:16:05 +010048/* pattern result data */
49union pattern_data {
Willy Tarreauaea940e2010-06-06 11:56:36 +020050 struct in_addr ip; /* used for ipv4 type */
David du Colombier4f92d322011-03-24 11:09:31 +010051 struct in6_addr ipv6; /* used for ipv6 type */
Willy Tarreaub666bc72011-12-16 16:44:06 +010052 int integer; /* used for unsigned 32bits integer type */
Emeric Brun485479d2010-09-23 18:02:19 +020053 struct chunk str; /* used for char string type or buffers*/
Emeric Brun107ca302010-01-04 16:16:05 +010054};
55
56/* pattern result */
57struct pattern {
58 int type; /* current type of data */
59 union pattern_data data; /* data */
60};
61
62/* pattern conversion */
63struct pattern_conv {
64 const char *kw; /* configuration keyword */
Willy Tarreauecfb8e82012-04-20 12:29:52 +020065 int (*process)(const struct arg *arg_p,
Willy Tarreauf9954102012-04-20 14:03:29 +020066 union pattern_data *data); /* process function */
Willy Tarreau9fcb9842012-04-20 14:45:49 +020067 unsigned int arg_mask; /* arguments (ARG*()) */
Emeric Brun485479d2010-09-23 18:02:19 +020068 unsigned int in_type; /* input needed pattern type */
69 unsigned int out_type; /* output pattern type */
Emeric Brun107ca302010-01-04 16:16:05 +010070};
71
72/* pattern conversion expression */
73struct pattern_conv_expr {
74 struct list list; /* member of a pattern expression */
75 struct pattern_conv *conv; /* pattern conversion */
Willy Tarreauecfb8e82012-04-20 12:29:52 +020076 struct arg *arg_p; /* pointer on args */
Emeric Brun107ca302010-01-04 16:16:05 +010077};
78
79/* pattern fetch */
80struct pattern_fetch {
81 const char *kw; /* configuration keyword */
82 int (*process)(struct proxy *px,
83 struct session *l4,
84 void *l7,
Willy Tarreauecfb8e82012-04-20 12:29:52 +020085 int dir, const struct arg *arg_p,
Emeric Brun107ca302010-01-04 16:16:05 +010086 union pattern_data *data); /* fetch processing function */
Willy Tarreau9fcb9842012-04-20 14:45:49 +020087 unsigned int arg_mask; /* arguments (ARG*()) */
Emeric Brun107ca302010-01-04 16:16:05 +010088 unsigned long out_type; /* output pattern type */
89 int dir; /* usable directions */
90};
91
92/* pattern expression */
93struct pattern_expr {
94 struct list list; /* member of list of pattern, currently not used */
95 struct pattern_fetch *fetch; /* pattern fetch */
Willy Tarreauecfb8e82012-04-20 12:29:52 +020096 struct arg *arg_p; /* pointer on args */
Emeric Brun107ca302010-01-04 16:16:05 +010097 struct list conv_exprs; /* list of conversion expression to apply */
98};
99
100/* pattern fetch keywords list */
101struct pattern_fetch_kw_list {
102 struct list list; /* head of pattern fetch keyword list */
103 struct pattern_fetch kw[VAR_ARRAY]; /* array of pattern fetches */
104};
105
106/* pattern conversion keywords list */
107struct pattern_conv_kw_list {
108 struct list list; /* head of pattern conversion keyword list */
109 struct pattern_conv kw[VAR_ARRAY]; /* array of pattern ions */
110};
111
112#endif /* _TYPES_PATTERN_H */