blob: 9b4e3405d97e026d1b802c60ae98a1fbc1683d15 [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 */
David du Colombier4f92d322011-03-24 11:09:31 +010032 PATTERN_TYPE_IPV6, /* ipv6 type */
Willy Tarreauaea940e2010-06-06 11:56:36 +020033 PATTERN_TYPE_INTEGER, /* unsigned 32bits integer type */
34 PATTERN_TYPE_STRING, /* char string type */
Emeric Brun485479d2010-09-23 18:02:19 +020035 PATTERN_TYPE_DATA, /* buffer type */
36 PATTERN_TYPE_CONSTSTRING, /* constant char string type, data need dup before conversion */
37 PATTERN_TYPE_CONSTDATA, /* constant buffer type, data need dup before conversion */
Willy Tarreauaea940e2010-06-06 11:56:36 +020038 PATTERN_TYPES /* number of types, must always be last */
Emeric Brun107ca302010-01-04 16:16:05 +010039};
40
Emeric Brun485479d2010-09-23 18:02:19 +020041
42/* pattern arg types */
43enum {
44 PATTERN_ARG_TYPE_IP = 0, /* ipv4 type */
David du Colombier4f92d322011-03-24 11:09:31 +010045 PATTERN_ARG_TYPE_IPV6, /* ipv6 type */
Emeric Brun485479d2010-09-23 18:02:19 +020046 PATTERN_ARG_TYPE_INTEGER, /* unsigned 32bits integer type */
47 PATTERN_ARG_TYPE_SINTEGER, /* signed 32bits integer type */
48 PATTERN_ARG_TYPE_STRING /* string type */
49};
50
Emeric Brun107ca302010-01-04 16:16:05 +010051/* pattern fetch direction */
52#define PATTERN_FETCH_REQ 1
53#define PATTERN_FETCH_RTR 2
54
Emeric Brun485479d2010-09-23 18:02:19 +020055
56union pattern_arg_data {
57 struct in_addr ip; /* used for ipv4 type */
David du Colombier4f92d322011-03-24 11:09:31 +010058 struct in6_addr ipv6; /* used for ipv6 type */
Emeric Brun485479d2010-09-23 18:02:19 +020059 uint32_t integer; /* used for unsigned 32bits integer type */
Willy Tarreaub695a6e2010-11-14 14:24:27 +010060 int sinteger; /* used for signed 32bits integer type */
Emeric Brun485479d2010-09-23 18:02:19 +020061 struct chunk str;
62};
63
64struct pattern_arg {
65 int type; /* type of arg */
66 union pattern_arg_data data; /* data */
67};
68
Emeric Brun107ca302010-01-04 16:16:05 +010069/* pattern result data */
70union pattern_data {
Willy Tarreauaea940e2010-06-06 11:56:36 +020071 struct in_addr ip; /* used for ipv4 type */
David du Colombier4f92d322011-03-24 11:09:31 +010072 struct in6_addr ipv6; /* used for ipv6 type */
Willy Tarreauaea940e2010-06-06 11:56:36 +020073 uint32_t integer; /* used for unsigned 32bits integer type */
Emeric Brun485479d2010-09-23 18:02:19 +020074 struct chunk str; /* used for char string type or buffers*/
Emeric Brun107ca302010-01-04 16:16:05 +010075};
76
77/* pattern result */
78struct pattern {
79 int type; /* current type of data */
80 union pattern_data data; /* data */
81};
82
83/* pattern conversion */
84struct pattern_conv {
85 const char *kw; /* configuration keyword */
Emeric Brun485479d2010-09-23 18:02:19 +020086 int (*process)(const struct pattern_arg *arg_p,
Willy Tarreau1a51b632010-01-26 17:17:56 +010087 int arg_i,
Emeric Brun107ca302010-01-04 16:16:05 +010088 union pattern_data *data); /* process function */
Willy Tarreau9e92d322010-01-26 17:58:06 +010089 int (*parse_args)(const char *arg_str,
Emeric Brun485479d2010-09-23 18:02:19 +020090 struct pattern_arg **arg_p,
Willy Tarreau9e92d322010-01-26 17:58:06 +010091 int *arg_i); /* argument parser. Can be NULL. */
Emeric Brun485479d2010-09-23 18:02:19 +020092 unsigned int in_type; /* input needed pattern type */
93 unsigned int out_type; /* output pattern type */
Emeric Brun107ca302010-01-04 16:16:05 +010094};
95
96/* pattern conversion expression */
97struct pattern_conv_expr {
98 struct list list; /* member of a pattern expression */
99 struct pattern_conv *conv; /* pattern conversion */
Emeric Brun485479d2010-09-23 18:02:19 +0200100 struct pattern_arg *arg_p; /* pointer on args */
101 int arg_i; /* number of args */
Emeric Brun107ca302010-01-04 16:16:05 +0100102};
103
104/* pattern fetch */
105struct pattern_fetch {
106 const char *kw; /* configuration keyword */
107 int (*process)(struct proxy *px,
108 struct session *l4,
109 void *l7,
Emeric Brun485479d2010-09-23 18:02:19 +0200110 int dir, const struct pattern_arg *arg_p,
111 int arg_i,
Emeric Brun107ca302010-01-04 16:16:05 +0100112 union pattern_data *data); /* fetch processing function */
Emeric Brun485479d2010-09-23 18:02:19 +0200113 int (*parse_args)(const char *arg_str,
114 struct pattern_arg **arg_p,
115 int *arg_i); /* argument parser. Can be NULL. */
Emeric Brun107ca302010-01-04 16:16:05 +0100116 unsigned long out_type; /* output pattern type */
117 int dir; /* usable directions */
118};
119
120/* pattern expression */
121struct pattern_expr {
122 struct list list; /* member of list of pattern, currently not used */
123 struct pattern_fetch *fetch; /* pattern fetch */
Emeric Brun485479d2010-09-23 18:02:19 +0200124 struct pattern_arg *arg_p; /* pointer on args */
125 int arg_i; /* number of args */
Emeric Brun107ca302010-01-04 16:16:05 +0100126 struct list conv_exprs; /* list of conversion expression to apply */
127};
128
129/* pattern fetch keywords list */
130struct pattern_fetch_kw_list {
131 struct list list; /* head of pattern fetch keyword list */
132 struct pattern_fetch kw[VAR_ARRAY]; /* array of pattern fetches */
133};
134
135/* pattern conversion keywords list */
136struct pattern_conv_kw_list {
137 struct list list; /* head of pattern conversion keyword list */
138 struct pattern_conv kw[VAR_ARRAY]; /* array of pattern ions */
139};
140
141#endif /* _TYPES_PATTERN_H */