blob: 618be08bf2edf573d2de51c1b2c547ee65ee363e [file] [log] [blame]
Emeric Brun107ca302010-01-04 16:16:05 +01001/*
Willy Tarreaucd3b0942012-04-27 21:52:18 +02002 * include/types/sample.h
3 * Macros, variables and structures for sample management.
Emeric Brun107ca302010-01-04 16:16:05 +01004 *
5 * Copyright (C) 2009-2010 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr>
Willy Tarreau80aca902013-01-07 15:42:20 +01006 * Copyright (C) 2012-2013 Willy Tarreau <w@1wt.eu>
Emeric Brun107ca302010-01-04 16:16:05 +01007 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation, version 2.1
11 * exclusively.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
Willy Tarreaucd3b0942012-04-27 21:52:18 +020023#ifndef _TYPES_SAMPLE_H
24#define _TYPES_SAMPLE_H
Emeric Brun107ca302010-01-04 16:16:05 +010025
Emeric Brun107ca302010-01-04 16:16:05 +010026#include <sys/socket.h>
27#include <netinet/in.h>
Willy Tarreauc7e42382012-08-24 19:22:53 +020028
Willy Tarreau8dabda72020-05-27 17:22:10 +020029#include <haproxy/buf-t.h>
Willy Tarreau35b51c62018-09-10 15:38:55 +020030#include <common/http.h>
Willy Tarreau853b2972020-05-27 18:01:47 +020031#include <haproxy/list-t.h>
Emeric Brun107ca302010-01-04 16:16:05 +010032
Thierry FOURNIERa9ff9942015-06-09 15:49:44 +020033struct arg;
34
Willy Tarreau422aa072012-04-20 20:49:27 +020035/* input and output sample types */
Emeric Brun107ca302010-01-04 16:16:05 +010036enum {
Thierry FOURNIER9c627e82015-06-03 20:12:35 +020037 SMP_T_ANY = 0, /* any type */
38 SMP_T_BOOL, /* boolean */
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020039 SMP_T_SINT, /* signed 64bits integer type */
Thierry FOURNIERb805f712013-11-26 20:47:54 +010040 SMP_T_ADDR, /* ipv4 or ipv6, only used for input type compatibility */
Willy Tarreau422aa072012-04-20 20:49:27 +020041 SMP_T_IPV4, /* ipv4 type */
42 SMP_T_IPV6, /* ipv6 type */
43 SMP_T_STR, /* char string type */
44 SMP_T_BIN, /* buffer type */
Thierry FOURNIERd4373142013-12-17 01:10:10 +010045 SMP_T_METH, /* contain method */
Willy Tarreau422aa072012-04-20 20:49:27 +020046 SMP_TYPES /* number of types, must always be last */
Emeric Brun107ca302010-01-04 16:16:05 +010047};
48
Willy Tarreau80aca902013-01-07 15:42:20 +010049/* Sample sources are used to establish a relation between fetch keywords and
50 * the location where they're about to be used. They're reserved for internal
51 * use and are not meant to be known outside the sample management code.
Willy Tarreau32a6f2e2012-04-25 10:13:36 +020052 */
53enum {
Willy Tarreau80aca902013-01-07 15:42:20 +010054 SMP_SRC_INTRN, /* internal context-less information */
55 SMP_SRC_LISTN, /* listener which accepted the connection */
56 SMP_SRC_FTEND, /* frontend which accepted the connection */
57 SMP_SRC_L4CLI, /* L4 information about the client */
58 SMP_SRC_L5CLI, /* fetch uses client information from embryonic session */
59 SMP_SRC_TRACK, /* fetch involves track counters */
60 SMP_SRC_L6REQ, /* fetch uses raw information from the request buffer */
61 SMP_SRC_HRQHV, /* fetch uses volatile information about HTTP request headers (eg: value) */
62 SMP_SRC_HRQHP, /* fetch uses persistent information about HTTP request headers (eg: meth) */
63 SMP_SRC_HRQBO, /* fetch uses information about HTTP request body */
64 SMP_SRC_BKEND, /* fetch uses information about the backend */
65 SMP_SRC_SERVR, /* fetch uses information about the selected server */
66 SMP_SRC_L4SRV, /* fetch uses information about the server L4 connection */
67 SMP_SRC_L5SRV, /* fetch uses information about the server L5 connection */
68 SMP_SRC_L6RES, /* fetch uses raw information from the response buffer */
69 SMP_SRC_HRSHV, /* fetch uses volatile information about HTTP response headers (eg: value) */
70 SMP_SRC_HRSHP, /* fetch uses persistent information about HTTP response headers (eg: status) */
71 SMP_SRC_HRSBO, /* fetch uses information about HTTP response body */
72 SMP_SRC_RQFIN, /* final information about request buffer (eg: tot bytes) */
73 SMP_SRC_RSFIN, /* final information about response buffer (eg: tot bytes) */
74 SMP_SRC_TXFIN, /* final information about the transaction (eg: #comp rate) */
Willy Tarreau87b09662015-04-03 00:22:06 +020075 SMP_SRC_SSFIN, /* final information about the stream (eg: #requests, final flags) */
Willy Tarreau80aca902013-01-07 15:42:20 +010076 SMP_SRC_ENTRIES /* nothing after this */
Willy Tarreau32a6f2e2012-04-25 10:13:36 +020077};
78
Willy Tarreaubf8e2512013-03-25 14:52:41 +010079/* Sample checkpoints are a list of places where samples may be used. This is
80 * an internal enum used only to build SMP_VAL_*.
81 */
82enum {
83 SMP_CKP_FE_CON_ACC, /* FE connection accept rules ("tcp request connection") */
Willy Tarreau87b09662015-04-03 00:22:06 +020084 SMP_CKP_FE_SES_ACC, /* FE stream accept rules (to come soon) */
Willy Tarreaubf8e2512013-03-25 14:52:41 +010085 SMP_CKP_FE_REQ_CNT, /* FE request content rules ("tcp request content") */
86 SMP_CKP_FE_HRQ_HDR, /* FE HTTP request headers (rules, headers, monitor, stats, redirect) */
87 SMP_CKP_FE_HRQ_BDY, /* FE HTTP request body */
88 SMP_CKP_FE_SET_BCK, /* FE backend switching rules ("use_backend") */
89 SMP_CKP_BE_REQ_CNT, /* BE request content rules ("tcp request content") */
90 SMP_CKP_BE_HRQ_HDR, /* BE HTTP request headers (rules, headers, monitor, stats, redirect) */
91 SMP_CKP_BE_HRQ_BDY, /* BE HTTP request body */
92 SMP_CKP_BE_SET_SRV, /* BE server switching rules ("use_server", "balance", "force-persist", "stick", ...) */
93 SMP_CKP_BE_SRV_CON, /* BE server connect (eg: "source") */
94 SMP_CKP_BE_RES_CNT, /* BE response content rules ("tcp response content") */
95 SMP_CKP_BE_HRS_HDR, /* BE HTTP response headers (rules, headers) */
96 SMP_CKP_BE_HRS_BDY, /* BE HTTP response body (stick-store rules are there) */
97 SMP_CKP_BE_STO_RUL, /* BE stick-store rules */
98 SMP_CKP_FE_RES_CNT, /* FE response content rules ("tcp response content") */
99 SMP_CKP_FE_HRS_HDR, /* FE HTTP response headers (rules, headers) */
100 SMP_CKP_FE_HRS_BDY, /* FE HTTP response body */
Willy Tarreau87b09662015-04-03 00:22:06 +0200101 SMP_CKP_FE_LOG_END, /* FE log at the end of the txn/stream */
Gaetan Rivet707b52f2020-02-21 18:14:59 +0100102 SMP_CKP_BE_CHK_RUL, /* BE tcp-check rules */
Willy Tarreaubf8e2512013-03-25 14:52:41 +0100103 SMP_CKP_ENTRIES /* nothing after this */
104};
105
Willy Tarreau80aca902013-01-07 15:42:20 +0100106/* SMP_USE_* are flags used to declare fetch keywords. Fetch methods are
107 * associated with bitfields composed of these values, generally only one, to
108 * indicate where the contents may be sampled. Some fetches are ambiguous as
109 * they apply to either the request or the response depending on the context,
110 * so they will have 2 of these bits (eg: hdr(), payload(), ...). These are
111 * stored in smp->use.
112 */
113enum {
114 SMP_USE_INTRN = 1 << SMP_SRC_INTRN, /* internal context-less information */
115 SMP_USE_LISTN = 1 << SMP_SRC_LISTN, /* listener which accepted the connection */
116 SMP_USE_FTEND = 1 << SMP_SRC_FTEND, /* frontend which accepted the connection */
117 SMP_USE_L4CLI = 1 << SMP_SRC_L4CLI, /* L4 information about the client */
118 SMP_USE_L5CLI = 1 << SMP_SRC_L5CLI, /* fetch uses client information from embryonic session */
119 SMP_USE_TRACK = 1 << SMP_SRC_TRACK, /* fetch involves track counters */
120 SMP_USE_L6REQ = 1 << SMP_SRC_L6REQ, /* fetch uses raw information from the request buffer */
121 SMP_USE_HRQHV = 1 << SMP_SRC_HRQHV, /* fetch uses volatile information about HTTP request headers (eg: value) */
122 SMP_USE_HRQHP = 1 << SMP_SRC_HRQHP, /* fetch uses persistent information about HTTP request headers (eg: meth) */
123 SMP_USE_HRQBO = 1 << SMP_SRC_HRQBO, /* fetch uses information about HTTP request body */
124 SMP_USE_BKEND = 1 << SMP_SRC_BKEND, /* fetch uses information about the backend */
125 SMP_USE_SERVR = 1 << SMP_SRC_SERVR, /* fetch uses information about the selected server */
126 SMP_USE_L4SRV = 1 << SMP_SRC_L4SRV, /* fetch uses information about the server L4 connection */
127 SMP_USE_L5SRV = 1 << SMP_SRC_L5SRV, /* fetch uses information about the server L5 connection */
128 SMP_USE_L6RES = 1 << SMP_SRC_L6RES, /* fetch uses raw information from the response buffer */
129 SMP_USE_HRSHV = 1 << SMP_SRC_HRSHV, /* fetch uses volatile information about HTTP response headers (eg: value) */
130 SMP_USE_HRSHP = 1 << SMP_SRC_HRSHP, /* fetch uses persistent information about HTTP response headers (eg: status) */
131 SMP_USE_HRSBO = 1 << SMP_SRC_HRSBO, /* fetch uses information about HTTP response body */
132 SMP_USE_RQFIN = 1 << SMP_SRC_RQFIN, /* final information about request buffer (eg: tot bytes) */
133 SMP_USE_RSFIN = 1 << SMP_SRC_RSFIN, /* final information about response buffer (eg: tot bytes) */
134 SMP_USE_TXFIN = 1 << SMP_SRC_TXFIN, /* final information about the transaction (eg: #comp rate) */
Willy Tarreau87b09662015-04-03 00:22:06 +0200135 SMP_USE_SSFIN = 1 << SMP_SRC_SSFIN, /* final information about the stream (eg: #requests, final flags) */
Willy Tarreau80aca902013-01-07 15:42:20 +0100136
Christopher Faulet711ed6a2019-07-16 14:16:10 +0200137 /* This composite one is useful to detect if an http_txn needs to be allocated */
Willy Tarreau80aca902013-01-07 15:42:20 +0100138 SMP_USE_HTTP_ANY = SMP_USE_HRQHV | SMP_USE_HRQHP | SMP_USE_HRQBO |
139 SMP_USE_HRSHV | SMP_USE_HRSHP | SMP_USE_HRSBO,
140};
141
142/* Sample validity is computed from the fetch sources above when keywords
143 * are registered. Each fetch method may be used at different locations. The
144 * configuration parser will check whether the fetches are compatible with the
145 * location where they're used. These are stored in smp->val.
146 */
147enum {
148 SMP_VAL___________ = 0, /* Just used as a visual marker */
Willy Tarreaubf8e2512013-03-25 14:52:41 +0100149 SMP_VAL_FE_CON_ACC = 1 << SMP_CKP_FE_CON_ACC, /* FE connection accept rules ("tcp request connection") */
Willy Tarreau87b09662015-04-03 00:22:06 +0200150 SMP_VAL_FE_SES_ACC = 1 << SMP_CKP_FE_SES_ACC, /* FE stream accept rules (to come soon) */
Willy Tarreaubf8e2512013-03-25 14:52:41 +0100151 SMP_VAL_FE_REQ_CNT = 1 << SMP_CKP_FE_REQ_CNT, /* FE request content rules ("tcp request content") */
152 SMP_VAL_FE_HRQ_HDR = 1 << SMP_CKP_FE_HRQ_HDR, /* FE HTTP request headers (rules, headers, monitor, stats, redirect) */
153 SMP_VAL_FE_HRQ_BDY = 1 << SMP_CKP_FE_HRQ_BDY, /* FE HTTP request body */
154 SMP_VAL_FE_SET_BCK = 1 << SMP_CKP_FE_SET_BCK, /* FE backend switching rules ("use_backend") */
155 SMP_VAL_BE_REQ_CNT = 1 << SMP_CKP_BE_REQ_CNT, /* BE request content rules ("tcp request content") */
156 SMP_VAL_BE_HRQ_HDR = 1 << SMP_CKP_BE_HRQ_HDR, /* BE HTTP request headers (rules, headers, monitor, stats, redirect) */
157 SMP_VAL_BE_HRQ_BDY = 1 << SMP_CKP_BE_HRQ_BDY, /* BE HTTP request body */
158 SMP_VAL_BE_SET_SRV = 1 << SMP_CKP_BE_SET_SRV, /* BE server switching rules ("use_server", "balance", "force-persist", "stick", ...) */
159 SMP_VAL_BE_SRV_CON = 1 << SMP_CKP_BE_SRV_CON, /* BE server connect (eg: "source") */
160 SMP_VAL_BE_RES_CNT = 1 << SMP_CKP_BE_RES_CNT, /* BE response content rules ("tcp response content") */
161 SMP_VAL_BE_HRS_HDR = 1 << SMP_CKP_BE_HRS_HDR, /* BE HTTP response headers (rules, headers) */
162 SMP_VAL_BE_HRS_BDY = 1 << SMP_CKP_BE_HRS_BDY, /* BE HTTP response body (stick-store rules are there) */
163 SMP_VAL_BE_STO_RUL = 1 << SMP_CKP_BE_STO_RUL, /* BE stick-store rules */
164 SMP_VAL_FE_RES_CNT = 1 << SMP_CKP_FE_RES_CNT, /* FE response content rules ("tcp response content") */
165 SMP_VAL_FE_HRS_HDR = 1 << SMP_CKP_FE_HRS_HDR, /* FE HTTP response headers (rules, headers) */
166 SMP_VAL_FE_HRS_BDY = 1 << SMP_CKP_FE_HRS_BDY, /* FE HTTP response body */
Willy Tarreau87b09662015-04-03 00:22:06 +0200167 SMP_VAL_FE_LOG_END = 1 << SMP_CKP_FE_LOG_END, /* FE log at the end of the txn/stream */
Gaetan Rivet707b52f2020-02-21 18:14:59 +0100168 SMP_VAL_BE_CHK_RUL = 1 << SMP_CKP_BE_CHK_RUL, /* BE tcp-check rule */
Willy Tarreau80aca902013-01-07 15:42:20 +0100169
170 /* a few combinations to decide what direction to try to fetch (useful for logs) */
171 SMP_VAL_REQUEST = SMP_VAL_FE_CON_ACC | SMP_VAL_FE_SES_ACC | SMP_VAL_FE_REQ_CNT |
172 SMP_VAL_FE_HRQ_HDR | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK |
173 SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY |
Gaetan Rivet707b52f2020-02-21 18:14:59 +0100174 SMP_VAL_BE_SET_SRV | SMP_VAL_BE_CHK_RUL,
Willy Tarreau80aca902013-01-07 15:42:20 +0100175
176 SMP_VAL_RESPONSE = SMP_VAL_BE_SRV_CON | SMP_VAL_BE_RES_CNT | SMP_VAL_BE_HRS_HDR |
177 SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | SMP_VAL_FE_RES_CNT |
Gaetan Rivet707b52f2020-02-21 18:14:59 +0100178 SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | SMP_VAL_FE_LOG_END |
179 SMP_VAL_BE_CHK_RUL,
Willy Tarreau80aca902013-01-07 15:42:20 +0100180};
181
182extern const unsigned int fetch_cap[SMP_SRC_ENTRIES];
183
Willy Tarreau32a6f2e2012-04-25 10:13:36 +0200184/* Sample fetch options are passed to sample fetch functions to add precision
185 * about what is desired :
186 * - fetch direction (req/resp)
187 * - intermediary / final fetch
188 */
189enum {
190 SMP_OPT_DIR_REQ = 0, /* direction = request */
191 SMP_OPT_DIR_RES = 1, /* direction = response */
192 SMP_OPT_DIR = (SMP_OPT_DIR_REQ|SMP_OPT_DIR_RES), /* mask to get direction */
193 SMP_OPT_FINAL = 2, /* final fetch, contents won't change anymore */
Willy Tarreau7a777ed2012-04-26 11:44:02 +0200194 SMP_OPT_ITERATE = 4, /* fetches may be iterated if supported (for ACLs) */
Willy Tarreau32a6f2e2012-04-25 10:13:36 +0200195};
196
Willy Tarreau16c31b02012-04-23 14:24:58 +0200197/* Flags used to describe fetched samples. MAY_CHANGE indicates that the result
198 * of the fetch might still evolve, for instance because of more data expected,
199 * even if the fetch has failed. VOL_* indicates how long a result may be cached.
200 */
201enum {
202 SMP_F_NOT_LAST = 1 << 0, /* other occurrences might exist for this sample */
203 SMP_F_MAY_CHANGE = 1 << 1, /* sample is unstable and might change (eg: request length) */
204 SMP_F_VOL_TEST = 1 << 2, /* result must not survive longer than the test (eg: time) */
205 SMP_F_VOL_1ST = 1 << 3, /* result sensitive to changes in first line (eg: URI) */
206 SMP_F_VOL_HDR = 1 << 4, /* result sensitive to changes in headers */
207 SMP_F_VOL_TXN = 1 << 5, /* result sensitive to new transaction (eg: HTTP version) */
208 SMP_F_VOL_SESS = 1 << 6, /* result sensitive to new session (eg: src IP) */
209 SMP_F_VOLATILE = (1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6), /* any volatility condition */
Thierry FOURNIER7654c9f2013-12-17 00:20:33 +0100210 SMP_F_CONST = 1 << 7, /* This sample use constant memory. May diplicate it before changes */
Willy Tarreau16c31b02012-04-23 14:24:58 +0200211};
Emeric Brun485479d2010-09-23 18:02:19 +0200212
Willy Tarreauc7e42382012-08-24 19:22:53 +0200213/* needed below */
Willy Tarreau192252e2015-04-04 01:47:55 +0200214struct session;
Willy Tarreau87b09662015-04-03 00:22:06 +0200215struct stream;
Willy Tarreauc7e42382012-08-24 19:22:53 +0200216
Willy Tarreau16c31b02012-04-23 14:24:58 +0200217/* a sample context might be used by any sample fetch function in order to
218 * store information needed across multiple calls (eg: restart point for a
219 * next occurrence). By definition it may store up to 8 pointers, or any
220 * scalar (double, int, long long).
221 */
222union smp_ctx {
223 void *p; /* any pointer */
224 int i; /* any integer */
225 long long ll; /* any long long or smaller */
226 double d; /* any float or double */
227 void *a[8]; /* any array of up to 8 pointers */
228};
229
Willy Tarreauad635822016-08-08 19:21:09 +0200230/* Note: the strings below make use of chunks. Chunks may carry an allocated
231 * size in addition to the length. The size counts from the beginning (str)
232 * to the end. If the size is unknown, it MUST be zero, in which case the
233 * sample will automatically be duplicated when a change larger than <len> has
234 * to be performed. Thus it is safe to always set size to zero.
235 */
Thierry FOURNIER654398a2015-08-20 13:52:51 +0200236union sample_value {
237 long long int sint; /* used for signed 64bits integers */
238 struct in_addr ipv4; /* used for ipv4 addresses */
239 struct in6_addr ipv6; /* used for ipv6 addresses */
Willy Tarreau83061a82018-07-13 11:56:34 +0200240 struct buffer str; /* used for char strings or buffers */
Willy Tarreau35b51c62018-09-10 15:38:55 +0200241 struct http_meth meth; /* used for http method */
Thierry FOURNIER654398a2015-08-20 13:52:51 +0200242};
243
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +0200244/* Used to store sample constant */
245struct sample_data {
Willy Tarreau422aa072012-04-20 20:49:27 +0200246 int type; /* SMP_T_* */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +0200247 union sample_value u; /* sample data */
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +0200248};
249
250/* a sample is a typed data extracted from a stream. It has a type, contents,
251 * validity constraints, a context for use in iterative calls.
252 */
253struct sample {
254 unsigned int flags; /* SMP_F_* */
255 struct sample_data data;
Willy Tarreau16c31b02012-04-23 14:24:58 +0200256 union smp_ctx ctx;
Thierry FOURNIER6879ad32015-05-11 11:54:58 +0200257
258 /* Some sample analyzer (sample-fetch or converters) needs to
259 * known the attached proxy, session and stream. The sample-fetches
260 * and the converters function pointers cannot be called without
261 * these 3 pointers filled.
262 */
263 struct proxy *px;
264 struct session *sess;
Willy Tarreaube508f12016-03-10 11:47:01 +0100265 struct stream *strm; /* WARNING! MAY BE NULL! (eg: tcp-request connection) */
Thierry FOURNIER1d33b882015-05-11 15:25:29 +0200266 unsigned int opt; /* fetch options (SMP_OPT_*) */
Willy Tarreau16c31b02012-04-23 14:24:58 +0200267};
268
Willy Tarreau12785782012-04-27 21:37:17 +0200269/* Descriptor for a sample conversion */
270struct sample_conv {
Emeric Brun107ca302010-01-04 16:16:05 +0100271 const char *kw; /* configuration keyword */
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +0200272 int (*process)(const struct arg *arg_p,
Thierry FOURNIER68a556e2015-02-23 15:11:11 +0100273 struct sample *smp,
Thierry FOURNIER1edc9712014-12-15 16:18:39 +0100274 void *private); /* process function */
David Carlier15073a32016-03-15 19:00:35 +0000275 uint64_t arg_mask; /* arguments (ARG*()) */
Willy Tarreau21d68a62012-04-20 15:52:36 +0200276 int (*val_args)(struct arg *arg_p,
Thierry FOURNIER9c1d67e2013-11-21 13:37:41 +0100277 struct sample_conv *smp_conv,
Thierry FOURNIEReeaa9512014-02-11 14:00:19 +0100278 const char *file, int line,
Willy Tarreau21d68a62012-04-20 15:52:36 +0200279 char **err_msg); /* argument validation function */
Willy Tarreau12785782012-04-27 21:37:17 +0200280 unsigned int in_type; /* expected input sample type */
281 unsigned int out_type; /* output sample type */
Thierry FOURNIER1edc9712014-12-15 16:18:39 +0100282 void *private; /* private values. only used by maps and Lua */
Emeric Brun107ca302010-01-04 16:16:05 +0100283};
284
Willy Tarreau12785782012-04-27 21:37:17 +0200285/* sample conversion expression */
286struct sample_conv_expr {
287 struct list list; /* member of a sample_expr */
288 struct sample_conv *conv; /* sample conversion used */
289 struct arg *arg_p; /* optional arguments */
Emeric Brun107ca302010-01-04 16:16:05 +0100290};
291
Willy Tarreau12785782012-04-27 21:37:17 +0200292/* Descriptor for a sample fetch method */
293struct sample_fetch {
Emeric Brun107ca302010-01-04 16:16:05 +0100294 const char *kw; /* configuration keyword */
Thierry FOURNIER0786d052015-05-11 15:42:45 +0200295 int (*process)(const struct arg *arg_p,
Willy Tarreauef38c392013-07-22 16:29:32 +0200296 struct sample *smp,
Thierry FOURNIERf41a8092014-12-07 18:37:57 +0100297 const char *kw, /* fetch processing function */
298 void *private); /* private value. */
David Carlier15073a32016-03-15 19:00:35 +0000299 uint64_t arg_mask; /* arguments (ARG*()) */
Willy Tarreau21d68a62012-04-20 15:52:36 +0200300 int (*val_args)(struct arg *arg_p,
301 char **err_msg); /* argument validation function */
Willy Tarreau12785782012-04-27 21:37:17 +0200302 unsigned long out_type; /* output sample type */
Willy Tarreau80aca902013-01-07 15:42:20 +0100303 unsigned int use; /* fetch source (SMP_USE_*) */
304 unsigned int val; /* fetch validity (SMP_VAL_*) */
Thierry FOURNIERf41a8092014-12-07 18:37:57 +0100305 void *private; /* private values. only used by Lua */
Emeric Brun107ca302010-01-04 16:16:05 +0100306};
307
Willy Tarreau12785782012-04-27 21:37:17 +0200308/* sample expression */
309struct sample_expr {
310 struct list list; /* member of list of sample, currently not used */
311 struct sample_fetch *fetch; /* sample fetch method */
312 struct arg *arg_p; /* optional pointer to arguments to fetch function */
Emeric Brun107ca302010-01-04 16:16:05 +0100313 struct list conv_exprs; /* list of conversion expression to apply */
314};
315
Willy Tarreau12785782012-04-27 21:37:17 +0200316/* sample fetch keywords list */
317struct sample_fetch_kw_list {
318 struct list list; /* head of sample fetch keyword list */
319 struct sample_fetch kw[VAR_ARRAY]; /* array of sample fetch descriptors */
Emeric Brun107ca302010-01-04 16:16:05 +0100320};
321
Willy Tarreau12785782012-04-27 21:37:17 +0200322/* sample conversion keywords list */
323struct sample_conv_kw_list {
324 struct list list; /* head of sample conversion keyword list */
325 struct sample_conv kw[VAR_ARRAY]; /* array of sample conversion descriptors */
Emeric Brun107ca302010-01-04 16:16:05 +0100326};
327
Thierry FOURNIER8af6ff12013-11-21 10:53:12 +0100328typedef int (*sample_cast_fct)(struct sample *smp);
329extern sample_cast_fct sample_casts[SMP_TYPES][SMP_TYPES];
330
Willy Tarreaucd3b0942012-04-27 21:52:18 +0200331#endif /* _TYPES_SAMPLE_H */