blob: e948264ba02d468e37fbd9ce887fb4afd195f89a [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 Tarreau1a51b632010-01-26 17:17:56 +010066 int arg_i,
Emeric Brun107ca302010-01-04 16:16:05 +010067 union pattern_data *data); /* process function */
Willy Tarreau9e92d322010-01-26 17:58:06 +010068 int (*parse_args)(const char *arg_str,
Willy Tarreauecfb8e82012-04-20 12:29:52 +020069 struct arg **arg_p,
Willy Tarreau9e92d322010-01-26 17:58:06 +010070 int *arg_i); /* argument parser. Can be NULL. */
Emeric Brun485479d2010-09-23 18:02:19 +020071 unsigned int in_type; /* input needed pattern type */
72 unsigned int out_type; /* output pattern type */
Emeric Brun107ca302010-01-04 16:16:05 +010073};
74
75/* pattern conversion expression */
76struct pattern_conv_expr {
77 struct list list; /* member of a pattern expression */
78 struct pattern_conv *conv; /* pattern conversion */
Willy Tarreauecfb8e82012-04-20 12:29:52 +020079 struct arg *arg_p; /* pointer on args */
Emeric Brun485479d2010-09-23 18:02:19 +020080 int arg_i; /* number of args */
Emeric Brun107ca302010-01-04 16:16:05 +010081};
82
83/* pattern fetch */
84struct pattern_fetch {
85 const char *kw; /* configuration keyword */
86 int (*process)(struct proxy *px,
87 struct session *l4,
88 void *l7,
Willy Tarreauecfb8e82012-04-20 12:29:52 +020089 int dir, const struct arg *arg_p,
Emeric Brun485479d2010-09-23 18:02:19 +020090 int arg_i,
Emeric Brun107ca302010-01-04 16:16:05 +010091 union pattern_data *data); /* fetch processing function */
Emeric Brun485479d2010-09-23 18:02:19 +020092 int (*parse_args)(const char *arg_str,
Willy Tarreauecfb8e82012-04-20 12:29:52 +020093 struct arg **arg_p,
Emeric Brun485479d2010-09-23 18:02:19 +020094 int *arg_i); /* argument parser. Can be NULL. */
Emeric Brun107ca302010-01-04 16:16:05 +010095 unsigned long out_type; /* output pattern type */
96 int dir; /* usable directions */
97};
98
99/* pattern expression */
100struct pattern_expr {
101 struct list list; /* member of list of pattern, currently not used */
102 struct pattern_fetch *fetch; /* pattern fetch */
Willy Tarreauecfb8e82012-04-20 12:29:52 +0200103 struct arg *arg_p; /* pointer on args */
Emeric Brun485479d2010-09-23 18:02:19 +0200104 int arg_i; /* number of args */
Emeric Brun107ca302010-01-04 16:16:05 +0100105 struct list conv_exprs; /* list of conversion expression to apply */
106};
107
108/* pattern fetch keywords list */
109struct pattern_fetch_kw_list {
110 struct list list; /* head of pattern fetch keyword list */
111 struct pattern_fetch kw[VAR_ARRAY]; /* array of pattern fetches */
112};
113
114/* pattern conversion keywords list */
115struct pattern_conv_kw_list {
116 struct list list; /* head of pattern conversion keyword list */
117 struct pattern_conv kw[VAR_ARRAY]; /* array of pattern ions */
118};
119
120#endif /* _TYPES_PATTERN_H */