blob: c5b19ada1cd13fc8bb576714afce5522cad14fa1 [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
Willy Tarreau422aa072012-04-20 20:49:27 +020030/* input and output sample types */
Emeric Brun107ca302010-01-04 16:16:05 +010031enum {
Willy Tarreau422aa072012-04-20 20:49:27 +020032 SMP_T_BOOL = 0, /* boolean */
33 SMP_T_UINT, /* unsigned 32bits integer type */
34 SMP_T_SINT, /* signed 32bits integer type */
35 SMP_T_IPV4, /* ipv4 type */
36 SMP_T_IPV6, /* ipv6 type */
37 SMP_T_STR, /* char string type */
38 SMP_T_BIN, /* buffer type */
39 SMP_T_CSTR, /* constant char string type, data need dup before conversion */
40 SMP_T_CBIN, /* constant buffer type, data need dup before conversion */
41 SMP_TYPES /* number of types, must always be last */
Emeric Brun107ca302010-01-04 16:16:05 +010042};
43
Willy Tarreau32a6f2e2012-04-25 10:13:36 +020044/* Sample fetch capabilities are used to declare keywords. Right now only
45 * the supportd fetch directions are specified.
46 */
47enum {
48 SMP_CAP_REQ = 1 << 0, /* fetch supported on request */
49 SMP_CAP_RES = 1 << 1, /* fetch supported on response */
50};
51
52/* Sample fetch options are passed to sample fetch functions to add precision
53 * about what is desired :
54 * - fetch direction (req/resp)
55 * - intermediary / final fetch
56 */
57enum {
58 SMP_OPT_DIR_REQ = 0, /* direction = request */
59 SMP_OPT_DIR_RES = 1, /* direction = response */
60 SMP_OPT_DIR = (SMP_OPT_DIR_REQ|SMP_OPT_DIR_RES), /* mask to get direction */
61 SMP_OPT_FINAL = 2, /* final fetch, contents won't change anymore */
Willy Tarreau7a777ed2012-04-26 11:44:02 +020062 SMP_OPT_ITERATE = 4, /* fetches may be iterated if supported (for ACLs) */
Willy Tarreau32a6f2e2012-04-25 10:13:36 +020063};
64
Willy Tarreau16c31b02012-04-23 14:24:58 +020065/* Flags used to describe fetched samples. MAY_CHANGE indicates that the result
66 * of the fetch might still evolve, for instance because of more data expected,
67 * even if the fetch has failed. VOL_* indicates how long a result may be cached.
68 */
69enum {
70 SMP_F_NOT_LAST = 1 << 0, /* other occurrences might exist for this sample */
71 SMP_F_MAY_CHANGE = 1 << 1, /* sample is unstable and might change (eg: request length) */
72 SMP_F_VOL_TEST = 1 << 2, /* result must not survive longer than the test (eg: time) */
73 SMP_F_VOL_1ST = 1 << 3, /* result sensitive to changes in first line (eg: URI) */
74 SMP_F_VOL_HDR = 1 << 4, /* result sensitive to changes in headers */
75 SMP_F_VOL_TXN = 1 << 5, /* result sensitive to new transaction (eg: HTTP version) */
76 SMP_F_VOL_SESS = 1 << 6, /* result sensitive to new session (eg: src IP) */
77 SMP_F_VOLATILE = (1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6), /* any volatility condition */
Willy Tarreau16c31b02012-04-23 14:24:58 +020078};
Emeric Brun485479d2010-09-23 18:02:19 +020079
Willy Tarreau16c31b02012-04-23 14:24:58 +020080/* a sample context might be used by any sample fetch function in order to
81 * store information needed across multiple calls (eg: restart point for a
82 * next occurrence). By definition it may store up to 8 pointers, or any
83 * scalar (double, int, long long).
84 */
85union smp_ctx {
86 void *p; /* any pointer */
87 int i; /* any integer */
88 long long ll; /* any long long or smaller */
89 double d; /* any float or double */
90 void *a[8]; /* any array of up to 8 pointers */
91};
92
93/* a sample is a typed data extracted from a stream. It has a type, contents,
94 * validity constraints, a context for use in iterative calls.
95 */
96struct sample {
97 unsigned int flags; /* SMP_F_* */
Willy Tarreau422aa072012-04-20 20:49:27 +020098 int type; /* SMP_T_* */
Willy Tarreau342acb42012-04-23 22:03:39 +020099 union {
100 unsigned int uint; /* used for unsigned 32bits integers and booleans */
101 int sint; /* used for signed 32bits integers */
102 struct in_addr ipv4; /* used for ipv4 addresses */
103 struct in6_addr ipv6; /* used for ipv6 addresses */
104 struct chunk str; /* used for char strings or buffers */
105 } data; /* sample data */
Willy Tarreau16c31b02012-04-23 14:24:58 +0200106 union smp_ctx ctx;
107};
108
Emeric Brun107ca302010-01-04 16:16:05 +0100109/* pattern conversion */
110struct pattern_conv {
111 const char *kw; /* configuration keyword */
Willy Tarreauecfb8e82012-04-20 12:29:52 +0200112 int (*process)(const struct arg *arg_p,
Willy Tarreau342acb42012-04-23 22:03:39 +0200113 struct sample *smp); /* process function */
Willy Tarreau9fcb9842012-04-20 14:45:49 +0200114 unsigned int arg_mask; /* arguments (ARG*()) */
Willy Tarreau21d68a62012-04-20 15:52:36 +0200115 int (*val_args)(struct arg *arg_p,
116 char **err_msg); /* argument validation function */
Emeric Brun485479d2010-09-23 18:02:19 +0200117 unsigned int in_type; /* input needed pattern type */
118 unsigned int out_type; /* output pattern type */
Emeric Brun107ca302010-01-04 16:16:05 +0100119};
120
121/* pattern conversion expression */
122struct pattern_conv_expr {
123 struct list list; /* member of a pattern expression */
124 struct pattern_conv *conv; /* pattern conversion */
Willy Tarreauecfb8e82012-04-20 12:29:52 +0200125 struct arg *arg_p; /* pointer on args */
Emeric Brun107ca302010-01-04 16:16:05 +0100126};
127
128/* pattern fetch */
129struct pattern_fetch {
130 const char *kw; /* configuration keyword */
131 int (*process)(struct proxy *px,
132 struct session *l4,
133 void *l7,
Willy Tarreau32a6f2e2012-04-25 10:13:36 +0200134 unsigned int opt, /* fetch options (SMP_OPT_*) */
135 const struct arg *arg_p,
Willy Tarreau342acb42012-04-23 22:03:39 +0200136 struct sample *smp); /* fetch processing function */
Willy Tarreau9fcb9842012-04-20 14:45:49 +0200137 unsigned int arg_mask; /* arguments (ARG*()) */
Willy Tarreau21d68a62012-04-20 15:52:36 +0200138 int (*val_args)(struct arg *arg_p,
139 char **err_msg); /* argument validation function */
Emeric Brun107ca302010-01-04 16:16:05 +0100140 unsigned long out_type; /* output pattern type */
Willy Tarreau32a6f2e2012-04-25 10:13:36 +0200141 unsigned int cap; /* fetch capabilities (SMP_CAP_*) */
Emeric Brun107ca302010-01-04 16:16:05 +0100142};
143
144/* pattern expression */
145struct pattern_expr {
146 struct list list; /* member of list of pattern, currently not used */
147 struct pattern_fetch *fetch; /* pattern fetch */
Willy Tarreauecfb8e82012-04-20 12:29:52 +0200148 struct arg *arg_p; /* pointer on args */
Emeric Brun107ca302010-01-04 16:16:05 +0100149 struct list conv_exprs; /* list of conversion expression to apply */
150};
151
152/* pattern fetch keywords list */
153struct pattern_fetch_kw_list {
154 struct list list; /* head of pattern fetch keyword list */
155 struct pattern_fetch kw[VAR_ARRAY]; /* array of pattern fetches */
156};
157
158/* pattern conversion keywords list */
159struct pattern_conv_kw_list {
160 struct list list; /* head of pattern conversion keyword list */
161 struct pattern_conv kw[VAR_ARRAY]; /* array of pattern ions */
162};
163
164#endif /* _TYPES_PATTERN_H */