blob: a3d5c3673b38cd448606fd9eb827886f88ecc27c [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 */
Emeric Brun485479d2010-09-23 18:02:19 +020034 PATTERN_TYPE_DATA, /* buffer type */
35 PATTERN_TYPE_CONSTSTRING, /* constant char string type, data need dup before conversion */
36 PATTERN_TYPE_CONSTDATA, /* constant buffer type, data need dup before conversion */
Willy Tarreauaea940e2010-06-06 11:56:36 +020037 PATTERN_TYPES /* number of types, must always be last */
Emeric Brun107ca302010-01-04 16:16:05 +010038};
39
Emeric Brun485479d2010-09-23 18:02:19 +020040
41/* pattern arg types */
42enum {
43 PATTERN_ARG_TYPE_IP = 0, /* ipv4 type */
44 PATTERN_ARG_TYPE_INTEGER, /* unsigned 32bits integer type */
45 PATTERN_ARG_TYPE_SINTEGER, /* signed 32bits integer type */
46 PATTERN_ARG_TYPE_STRING /* string type */
47};
48
Emeric Brun107ca302010-01-04 16:16:05 +010049/* pattern fetch direction */
50#define PATTERN_FETCH_REQ 1
51#define PATTERN_FETCH_RTR 2
52
Emeric Brun485479d2010-09-23 18:02:19 +020053
54union pattern_arg_data {
55 struct in_addr ip; /* used for ipv4 type */
56 uint32_t integer; /* used for unsigned 32bits integer type */
Willy Tarreaub695a6e2010-11-14 14:24:27 +010057 int sinteger; /* used for signed 32bits integer type */
Emeric Brun485479d2010-09-23 18:02:19 +020058 struct chunk str;
59};
60
61struct pattern_arg {
62 int type; /* type of arg */
63 union pattern_arg_data data; /* data */
64};
65
Emeric Brun107ca302010-01-04 16:16:05 +010066/* pattern result data */
67union pattern_data {
Willy Tarreauaea940e2010-06-06 11:56:36 +020068 struct in_addr ip; /* used for ipv4 type */
69 uint32_t integer; /* used for unsigned 32bits integer type */
Emeric Brun485479d2010-09-23 18:02:19 +020070 struct chunk str; /* used for char string type or buffers*/
Emeric Brun107ca302010-01-04 16:16:05 +010071};
72
73/* pattern result */
74struct pattern {
75 int type; /* current type of data */
76 union pattern_data data; /* data */
77};
78
79/* pattern conversion */
80struct pattern_conv {
81 const char *kw; /* configuration keyword */
Emeric Brun485479d2010-09-23 18:02:19 +020082 int (*process)(const struct pattern_arg *arg_p,
Willy Tarreau1a51b632010-01-26 17:17:56 +010083 int arg_i,
Emeric Brun107ca302010-01-04 16:16:05 +010084 union pattern_data *data); /* process function */
Willy Tarreau9e92d322010-01-26 17:58:06 +010085 int (*parse_args)(const char *arg_str,
Emeric Brun485479d2010-09-23 18:02:19 +020086 struct pattern_arg **arg_p,
Willy Tarreau9e92d322010-01-26 17:58:06 +010087 int *arg_i); /* argument parser. Can be NULL. */
Emeric Brun485479d2010-09-23 18:02:19 +020088 unsigned int in_type; /* input needed pattern type */
89 unsigned int out_type; /* output pattern type */
Emeric Brun107ca302010-01-04 16:16:05 +010090};
91
92/* pattern conversion expression */
93struct pattern_conv_expr {
94 struct list list; /* member of a pattern expression */
95 struct pattern_conv *conv; /* pattern conversion */
Emeric Brun485479d2010-09-23 18:02:19 +020096 struct pattern_arg *arg_p; /* pointer on args */
97 int arg_i; /* number of args */
Emeric Brun107ca302010-01-04 16:16:05 +010098};
99
100/* pattern fetch */
101struct pattern_fetch {
102 const char *kw; /* configuration keyword */
103 int (*process)(struct proxy *px,
104 struct session *l4,
105 void *l7,
Emeric Brun485479d2010-09-23 18:02:19 +0200106 int dir, const struct pattern_arg *arg_p,
107 int arg_i,
Emeric Brun107ca302010-01-04 16:16:05 +0100108 union pattern_data *data); /* fetch processing function */
Emeric Brun485479d2010-09-23 18:02:19 +0200109 int (*parse_args)(const char *arg_str,
110 struct pattern_arg **arg_p,
111 int *arg_i); /* argument parser. Can be NULL. */
Emeric Brun107ca302010-01-04 16:16:05 +0100112 unsigned long out_type; /* output pattern type */
113 int dir; /* usable directions */
114};
115
116/* pattern expression */
117struct pattern_expr {
118 struct list list; /* member of list of pattern, currently not used */
119 struct pattern_fetch *fetch; /* pattern fetch */
Emeric Brun485479d2010-09-23 18:02:19 +0200120 struct pattern_arg *arg_p; /* pointer on args */
121 int arg_i; /* number of args */
Emeric Brun107ca302010-01-04 16:16:05 +0100122 struct list conv_exprs; /* list of conversion expression to apply */
123};
124
125/* pattern fetch keywords list */
126struct pattern_fetch_kw_list {
127 struct list list; /* head of pattern fetch keyword list */
128 struct pattern_fetch kw[VAR_ARRAY]; /* array of pattern fetches */
129};
130
131/* pattern conversion keywords list */
132struct pattern_conv_kw_list {
133 struct list list; /* head of pattern conversion keyword list */
134 struct pattern_conv kw[VAR_ARRAY]; /* array of pattern ions */
135};
136
137#endif /* _TYPES_PATTERN_H */