blob: 42dac41ac0c73b7c78588f63cde5c92aca19fb84 [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*()) */
Willy Tarreau21d68a62012-04-20 15:52:36 +020068 int (*val_args)(struct arg *arg_p,
69 char **err_msg); /* argument validation function */
Emeric Brun485479d2010-09-23 18:02:19 +020070 unsigned int in_type; /* input needed pattern type */
71 unsigned int out_type; /* output pattern type */
Emeric Brun107ca302010-01-04 16:16:05 +010072};
73
74/* pattern conversion expression */
75struct pattern_conv_expr {
76 struct list list; /* member of a pattern expression */
77 struct pattern_conv *conv; /* pattern conversion */
Willy Tarreauecfb8e82012-04-20 12:29:52 +020078 struct arg *arg_p; /* pointer on args */
Emeric Brun107ca302010-01-04 16:16:05 +010079};
80
81/* pattern fetch */
82struct pattern_fetch {
83 const char *kw; /* configuration keyword */
84 int (*process)(struct proxy *px,
85 struct session *l4,
86 void *l7,
Willy Tarreauecfb8e82012-04-20 12:29:52 +020087 int dir, const struct arg *arg_p,
Emeric Brun107ca302010-01-04 16:16:05 +010088 union pattern_data *data); /* fetch processing function */
Willy Tarreau9fcb9842012-04-20 14:45:49 +020089 unsigned int arg_mask; /* arguments (ARG*()) */
Willy Tarreau21d68a62012-04-20 15:52:36 +020090 int (*val_args)(struct arg *arg_p,
91 char **err_msg); /* argument validation function */
Emeric Brun107ca302010-01-04 16:16:05 +010092 unsigned long out_type; /* output pattern type */
93 int dir; /* usable directions */
94};
95
96/* pattern expression */
97struct pattern_expr {
98 struct list list; /* member of list of pattern, currently not used */
99 struct pattern_fetch *fetch; /* pattern fetch */
Willy Tarreauecfb8e82012-04-20 12:29:52 +0200100 struct arg *arg_p; /* pointer on args */
Emeric Brun107ca302010-01-04 16:16:05 +0100101 struct list conv_exprs; /* list of conversion expression to apply */
102};
103
104/* pattern fetch keywords list */
105struct pattern_fetch_kw_list {
106 struct list list; /* head of pattern fetch keyword list */
107 struct pattern_fetch kw[VAR_ARRAY]; /* array of pattern fetches */
108};
109
110/* pattern conversion keywords list */
111struct pattern_conv_kw_list {
112 struct list list; /* head of pattern conversion keyword list */
113 struct pattern_conv kw[VAR_ARRAY]; /* array of pattern ions */
114};
115
116#endif /* _TYPES_PATTERN_H */