blob: 0c486838afb2a62a2528bb3f3989e76d02fa5a02 [file] [log] [blame]
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +01001/*
2 * MAP management functions.
3 *
4 * Copyright 2000-2013 Willy Tarreau <w@1wt.eu>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
13#include <limits.h>
14#include <stdio.h>
15
16#include <common/standard.h>
17
William Lallemandad8be612016-11-18 19:26:17 +010018#include <types/applet.h>
19#include <types/cli.h>
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010020#include <types/global.h>
21#include <types/map.h>
Thierry FOURNIER1e00d382014-02-11 11:31:40 +010022#include <types/pattern.h>
William Lallemandad8be612016-11-18 19:26:17 +010023#include <types/stats.h>
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010024
William Lallemandad8be612016-11-18 19:26:17 +010025#include <proto/applet.h>
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010026#include <proto/arg.h>
William Lallemandad8be612016-11-18 19:26:17 +010027#include <proto/cli.h>
Thierry FOURNIERb0c0a0f2013-12-10 15:05:34 +010028#include <proto/map.h>
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010029#include <proto/pattern.h>
William Lallemandad8be612016-11-18 19:26:17 +010030#include <proto/stream_interface.h>
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010031#include <proto/sample.h>
32
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +020033/* Parse an IPv4 or IPv6 address and store it into the sample.
34 * The output type is IPv4 or IPv6.
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010035 */
Thierry FOURNIER503bb092015-08-19 08:35:43 +020036int map_parse_ip(const char *text, struct sample_data *data)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010037{
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +020038 int len = strlen(text);
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010039
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +020040 if (buf2ip(text, len, &data->u.ipv4)) {
41 data->type = SMP_T_IPV4;
42 return 1;
43 }
44 if (buf2ip6(text, len, &data->u.ipv6)) {
45 data->type = SMP_T_IPV6;
46 return 1;
47 }
48 return 0;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010049}
50
51/* Parse a string and store a pointer to it into the sample. The original
52 * string must be left in memory because we return a direct memory reference.
Thierry FOURNIER7654c9f2013-12-17 00:20:33 +010053 * The output type is SMP_T_STR. There is no risk that the data will be
54 * overwritten because sample_conv_map() makes a const sample with this
55 * output.
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010056 */
Thierry FOURNIER503bb092015-08-19 08:35:43 +020057int map_parse_str(const char *text, struct sample_data *data)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010058{
Thierry FOURNIER136f9d32015-08-19 09:07:19 +020059 data->u.str.str = (char *)text;
60 data->u.str.len = strlen(text);
61 data->u.str.size = data->u.str.len + 1;
Thierry FOURNIER503bb092015-08-19 08:35:43 +020062 data->type = SMP_T_STR;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010063 return 1;
64}
65
66/* Parse an integer and convert it to a sample. The output type is SINT if the
67 * number is negative, or UINT if it is positive or null. The function returns
68 * zero (error) if the number is too large.
69 */
Thierry FOURNIER503bb092015-08-19 08:35:43 +020070int map_parse_int(const char *text, struct sample_data *data)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010071{
Thierry FOURNIER503bb092015-08-19 08:35:43 +020072 data->type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +020073 data->u.sint = read_int64(&text, text + strlen(text));
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020074 if (*text != '\0')
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010075 return 0;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010076 return 1;
77}
78
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010079/* This crete and initialize map descriptor.
80 * Return NULL if out of memory error
81 */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +010082static struct map_descriptor *map_create_descriptor(struct sample_conv *conv)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010083{
84 struct map_descriptor *desc;
85
86 desc = calloc(1, sizeof(*desc));
87 if (!desc)
88 return NULL;
89
90 desc->conv = conv;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010091
92 return desc;
93}
94
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010095/* This function load the map file according with data type declared into
96 * the "struct sample_conv".
97 *
98 * This function choose the indexation type (ebtree or list) according with
99 * the type of match needed.
100 */
Thierry FOURNIER3def3932015-04-07 11:27:54 +0200101int sample_load_map(struct arg *arg, struct sample_conv *conv,
102 const char *file, int line, char **err)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100103{
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100104 struct map_descriptor *desc;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100105
106 /* create new map descriptor */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100107 desc = map_create_descriptor(conv);
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100108 if (!desc) {
109 memprintf(err, "out of memory");
110 return 0;
111 }
112
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100113 /* Initialize pattern */
114 pattern_init_head(&desc->pat);
115
116 /* This is original pattern, must free */
117 desc->do_free = 1;
118
119 /* Set the match method. */
Thierry FOURNIER1edc9712014-12-15 16:18:39 +0100120 desc->pat.match = pat_match_fcts[(long)conv->private];
121 desc->pat.parse = pat_parse_fcts[(long)conv->private];
122 desc->pat.index = pat_index_fcts[(long)conv->private];
123 desc->pat.delete = pat_delete_fcts[(long)conv->private];
124 desc->pat.prune = pat_prune_fcts[(long)conv->private];
125 desc->pat.expect_type = pat_match_types[(long)conv->private];
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100126
127 /* Set the output parse method. */
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100128 switch (desc->conv->out_type) {
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100129 case SMP_T_STR: desc->pat.parse_smp = map_parse_str; break;
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +0200130 case SMP_T_SINT: desc->pat.parse_smp = map_parse_int; break;
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +0200131 case SMP_T_ADDR: desc->pat.parse_smp = map_parse_ip; break;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100132 default:
133 memprintf(err, "map: internal haproxy error: no default parse case for the input type <%d>.",
134 conv->out_type);
Andreas Seltenreich78f35952016-03-03 20:32:23 +0100135 free(desc);
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100136 return 0;
137 }
138
Thierry FOURNIER39bef452014-01-29 13:29:45 +0100139 /* Load map. */
Thierry FOURNIERe47e4e22014-04-28 11:18:57 +0200140 if (!pattern_read_from_file(&desc->pat, PAT_REF_MAP, arg[0].data.str.str, PAT_MF_NO_DNS,
Thierry FOURNIER94580c92014-02-11 14:36:45 +0100141 1, err, file, line))
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100142 return 0;
Thierry FOURNIER0ffe78c2013-12-05 14:40:25 +0100143
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +0200144 /* the maps of type IP have a string as defaultvalue. This
145 * string canbe anipv4 or an ipv6, we must convert it.
146 */
147 if (desc->conv->out_type == SMP_T_ADDR) {
148 struct sample_data data;
149 if (!map_parse_ip(arg[1].data.str.str, &data)) {
150 memprintf(err, "map: cannot parse default ip <%s>.", arg[1].data.str.str);
151 return 0;
152 }
153 if (data.type == SMP_T_IPV4) {
154 arg[1].type = ARGT_IPV4;
155 arg[1].data.ipv4 = data.u.ipv4;
156 } else {
157 arg[1].type = ARGT_IPV6;
158 arg[1].data.ipv6 = data.u.ipv6;
159 }
160 }
161
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100162 /* replace the first argument by this definition */
163 arg[0].type = ARGT_MAP;
164 arg[0].data.map = desc;
165
166 return 1;
167}
168
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +0200169static int sample_conv_map(const struct arg *arg_p, struct sample *smp, void *private)
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100170{
171 struct map_descriptor *desc;
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100172 struct pattern *pat;
Thierry Fournier8feaa662016-02-10 22:55:20 +0100173 struct chunk *str;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100174
175 /* get config */
176 desc = arg_p[0].data.map;
177
178 /* Execute the match function. */
Thierry FOURNIER1e00d382014-02-11 11:31:40 +0100179 pat = pattern_exec_match(&desc->pat, smp, 1);
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100180
181 /* Match case. */
182 if (pat) {
Thierry FOURNIER503bb092015-08-19 08:35:43 +0200183 if (pat->data) {
Thierry Fournier8feaa662016-02-10 22:55:20 +0100184 /* In the regm case, merge the sample with the input. */
185 if ((long)private == PAT_MATCH_REGM) {
186 str = get_trash_chunk();
187 str->len = exp_replace(str->str, str->size, smp->data.u.str.str,
188 pat->data->u.str.str,
189 (regmatch_t *)smp->ctx.a[0]);
190 if (str->len == -1)
191 return 0;
192 smp->data.u.str = *str;
193 return 1;
194 }
195 /* Copy sample. */
Thierry FOURNIER5cc18d42015-08-19 09:02:36 +0200196 smp->data = *pat->data;
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100197 smp->flags |= SMP_F_CONST;
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100198 return 1;
199 }
200
201 /* Return just int sample containing 1. */
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +0200202 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +0200203 smp->data.u.sint = 1;
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100204 return 1;
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100205 }
206
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100207 /* If no default value avalaible, the converter fails. */
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100208 if (arg_p[1].type == ARGT_STOP)
Thierry FOURNIER1794fdf2014-01-17 15:25:13 +0100209 return 0;
210
211 /* Return the default value. */
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100212 switch (desc->conv->out_type) {
213
214 case SMP_T_STR:
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +0200215 smp->data.type = SMP_T_STR;
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100216 smp->flags |= SMP_F_CONST;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +0200217 smp->data.u.str = arg_p[1].data.str;
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100218 break;
219
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +0200220 case SMP_T_SINT:
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +0200221 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +0200222 smp->data.u.sint = arg_p[1].data.sint;
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100223 break;
224
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +0200225 case SMP_T_ADDR:
226 if (arg_p[1].type == ARGT_IPV4) {
227 smp->data.type = SMP_T_IPV4;
228 smp->data.u.ipv4 = arg_p[1].data.ipv4;
229 } else {
230 smp->data.type = SMP_T_IPV6;
231 smp->data.u.ipv6 = arg_p[1].data.ipv6;
232 }
Thierry FOURNIER933e5de2015-03-13 00:10:16 +0100233 break;
234 }
235
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100236 return 1;
237}
238
William Lallemandad8be612016-11-18 19:26:17 +0100239/* This function is used with map and acl management. It permits to browse
240 * each reference. The variable <getnext> must contain the current node,
241 * <end> point to the root node and the <flags> permit to filter required
242 * nodes.
243 */
244static inline
245struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end,
246 unsigned int flags)
247{
248 struct pat_ref *ref = getnext;
249
250 while (1) {
251
252 /* Get next list entry. */
253 ref = LIST_NEXT(&ref->list, struct pat_ref *, list);
254
255 /* If the entry is the last of the list, return NULL. */
256 if (&ref->list == end)
257 return NULL;
258
259 /* If the entry match the flag, return it. */
260 if (ref->flags & flags)
261 return ref;
262 }
263}
264
265static inline
266struct pat_ref *pat_ref_lookup_ref(const char *reference)
267{
268 int id;
269 char *error;
270
271 /* If the reference starts by a '#', this is numeric id. */
272 if (reference[0] == '#') {
273 /* Try to convert the numeric id. If the conversion fails, the lookup fails. */
274 id = strtol(reference + 1, &error, 10);
275 if (*error != '\0')
276 return NULL;
277
278 /* Perform the unique id lookup. */
279 return pat_ref_lookupid(id);
280 }
281
282 /* Perform the string lookup. */
283 return pat_ref_lookup(reference);
284}
285
286/* This function is used with map and acl management. It permits to browse
287 * each reference.
288 */
289static inline
290struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end)
291{
292 struct pattern_expr *expr;
293 expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list);
294 if (&expr->list == end)
295 return NULL;
296 return expr;
297}
298
299static int cli_io_handler_pat_list(struct appctx *appctx)
300{
301 struct stream_interface *si = appctx->owner;
Emeric Brun8d85aa42017-06-29 15:40:33 +0200302 struct pat_ref_elt *elt;
303
304 if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) {
305 /* If we're forced to shut down, we might have to remove our
306 * reference to the last ref_elt being dumped.
307 */
308 if (appctx->st2 == STAT_ST_LIST) {
309 if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) {
310 LIST_DEL(&appctx->ctx.sess.bref.users);
311 LIST_INIT(&appctx->ctx.sess.bref.users);
312 }
313 }
314 return 1;
315 }
William Lallemandad8be612016-11-18 19:26:17 +0100316
317 switch (appctx->st2) {
318
319 case STAT_ST_INIT:
Emeric Brun8d85aa42017-06-29 15:40:33 +0200320 /* the function had not been called yet, let's prepare the
321 * buffer for a response. We initialize the current stream
322 * pointer to the first in the global list. When a target
323 * stream is being destroyed, it is responsible for updating
324 * this pointer. We know we have reached the end when this
325 * pointer points back to the head of the streams list.
326 */
327 LIST_INIT(&appctx->ctx.map.bref.users);
328 appctx->ctx.map.bref.ref = appctx->ctx.map.ref->head.n;
William Lallemandad8be612016-11-18 19:26:17 +0100329 appctx->st2 = STAT_ST_LIST;
330 /* fall through */
331
332 case STAT_ST_LIST:
Emeric Brun8d85aa42017-06-29 15:40:33 +0200333 if (!LIST_ISEMPTY(&appctx->ctx.map.bref.users)) {
334 LIST_DEL(&appctx->ctx.map.bref.users);
335 LIST_INIT(&appctx->ctx.map.bref.users);
336 }
337
338 while (appctx->ctx.map.bref.ref != &appctx->ctx.map.ref->head) {
William Lallemandad8be612016-11-18 19:26:17 +0100339 chunk_reset(&trash);
340
Emeric Brun8d85aa42017-06-29 15:40:33 +0200341 elt = LIST_ELEM(appctx->ctx.map.bref.ref, struct pat_ref_elt *, list);
342
William Lallemandad8be612016-11-18 19:26:17 +0100343 /* build messages */
Emeric Brun8d85aa42017-06-29 15:40:33 +0200344 if (elt->sample)
William Lallemandad8be612016-11-18 19:26:17 +0100345 chunk_appendf(&trash, "%p %s %s\n",
Emeric Brun8d85aa42017-06-29 15:40:33 +0200346 elt, elt->pattern,
347 elt->sample);
William Lallemandad8be612016-11-18 19:26:17 +0100348 else
349 chunk_appendf(&trash, "%p %s\n",
Emeric Brun8d85aa42017-06-29 15:40:33 +0200350 elt, elt->pattern);
William Lallemandad8be612016-11-18 19:26:17 +0100351
352 if (bi_putchk(si_ic(si), &trash) == -1) {
353 /* let's try again later from this stream. We add ourselves into
354 * this stream's users so that it can remove us upon termination.
355 */
356 si_applet_cant_put(si);
Emeric Brun8d85aa42017-06-29 15:40:33 +0200357 LIST_ADDQ(&elt->back_refs, &appctx->ctx.map.bref.users);
William Lallemandad8be612016-11-18 19:26:17 +0100358 return 0;
359 }
360
361 /* get next list entry and check the end of the list */
Emeric Brun8d85aa42017-06-29 15:40:33 +0200362 appctx->ctx.map.bref.ref = elt->list.n;
William Lallemandad8be612016-11-18 19:26:17 +0100363 }
364
365 appctx->st2 = STAT_ST_FIN;
366 /* fall through */
367
368 default:
369 appctx->st2 = STAT_ST_FIN;
370 return 1;
371 }
372}
373
374static int cli_io_handler_pats_list(struct appctx *appctx)
375{
376 struct stream_interface *si = appctx->owner;
377
378 switch (appctx->st2) {
379 case STAT_ST_INIT:
380 /* Display the column headers. If the message cannot be sent,
381 * quit the fucntion with returning 0. The function is called
382 * later and restart at the state "STAT_ST_INIT".
383 */
384 chunk_reset(&trash);
385 chunk_appendf(&trash, "# id (file) description\n");
386 if (bi_putchk(si_ic(si), &trash) == -1) {
387 si_applet_cant_put(si);
388 return 0;
389 }
390
391 /* Now, we start the browsing of the references lists.
392 * Note that the following call to LIST_ELEM return bad pointer. The only
393 * available field of this pointer is <list>. It is used with the function
394 * pat_list_get_next() for retruning the first available entry
395 */
396 appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list);
397 appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference,
398 appctx->ctx.map.display_flags);
399 appctx->st2 = STAT_ST_LIST;
400 /* fall through */
401
402 case STAT_ST_LIST:
403 while (appctx->ctx.map.ref) {
404 chunk_reset(&trash);
405
406 /* Build messages. If the reference is used by another category than
407 * the listed categorie, display the information in the massage.
408 */
409 chunk_appendf(&trash, "%d (%s) %s\n", appctx->ctx.map.ref->unique_id,
410 appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "",
411 appctx->ctx.map.ref->display);
412
413 if (bi_putchk(si_ic(si), &trash) == -1) {
414 /* let's try again later from this stream. We add ourselves into
415 * this stream's users so that it can remove us upon termination.
416 */
417 si_applet_cant_put(si);
418 return 0;
419 }
420
421 /* get next list entry and check the end of the list */
422 appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference,
423 appctx->ctx.map.display_flags);
424 }
425
426 appctx->st2 = STAT_ST_FIN;
427 /* fall through */
428
429 default:
430 appctx->st2 = STAT_ST_FIN;
431 return 1;
432 }
433 return 0;
434}
435
436static int cli_io_handler_map_lookup(struct appctx *appctx)
437{
438 struct stream_interface *si = appctx->owner;
439 struct sample sample;
440 struct pattern *pat;
441 int match_method;
442
443 switch (appctx->st2) {
444 case STAT_ST_INIT:
445 /* Init to the first entry. The list cannot be change */
446 appctx->ctx.map.expr = LIST_ELEM(&appctx->ctx.map.ref->pat, struct pattern_expr *, list);
447 appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, &appctx->ctx.map.ref->pat);
448 appctx->st2 = STAT_ST_LIST;
449 /* fall through */
450
451 case STAT_ST_LIST:
452 /* for each lookup type */
453 while (appctx->ctx.map.expr) {
454 /* initialise chunk to build new message */
455 chunk_reset(&trash);
456
457 /* execute pattern matching */
458 sample.data.type = SMP_T_STR;
459 sample.flags = SMP_F_CONST;
460 sample.data.u.str.len = appctx->ctx.map.chunk.len;
461 sample.data.u.str.str = appctx->ctx.map.chunk.str;
462 if (appctx->ctx.map.expr->pat_head->match &&
463 sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type))
464 pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1);
465 else
466 pat = NULL;
467
468 /* build return message: set type of match */
469 for (match_method=0; match_method<PAT_MATCH_NUM; match_method++)
470 if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method])
471 break;
472 if (match_method >= PAT_MATCH_NUM)
473 chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match);
474 else
475 chunk_appendf(&trash, "type=%s", pat_match_names[match_method]);
476
477 /* case sensitive */
478 if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE)
479 chunk_appendf(&trash, ", case=insensitive");
480 else
481 chunk_appendf(&trash, ", case=sensitive");
482
483 /* Display no match, and set default value */
484 if (!pat) {
485 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
486 chunk_appendf(&trash, ", found=no");
487 else
488 chunk_appendf(&trash, ", match=no");
489 }
490
491 /* Display match and match info */
492 else {
493 /* display match */
494 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
495 chunk_appendf(&trash, ", found=yes");
496 else
497 chunk_appendf(&trash, ", match=yes");
498
499 /* display index mode */
500 if (pat->sflags & PAT_SF_TREE)
501 chunk_appendf(&trash, ", idx=tree");
502 else
503 chunk_appendf(&trash, ", idx=list");
504
505 /* display pattern */
506 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
507 if (pat->ref && pat->ref->pattern)
508 chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern);
509 else
510 chunk_appendf(&trash, ", key=unknown");
511 }
512 else {
513 if (pat->ref && pat->ref->pattern)
514 chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern);
515 else
516 chunk_appendf(&trash, ", pattern=unknown");
517 }
518
519 /* display return value */
520 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
521 if (pat->data && pat->ref && pat->ref->sample)
522 chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", pat->ref->sample,
523 smp_to_type[pat->data->type]);
524 else
525 chunk_appendf(&trash, ", value=none");
526 }
527 }
528
529 chunk_appendf(&trash, "\n");
530
531 /* display response */
532 if (bi_putchk(si_ic(si), &trash) == -1) {
533 /* let's try again later from this stream. We add ourselves into
534 * this stream's users so that it can remove us upon termination.
535 */
536 si_applet_cant_put(si);
537 return 0;
538 }
539
540 /* get next entry */
541 appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr,
542 &appctx->ctx.map.ref->pat);
543 }
544
545 appctx->st2 = STAT_ST_FIN;
546 /* fall through */
547
548 default:
549 appctx->st2 = STAT_ST_FIN;
William Lallemandad8be612016-11-18 19:26:17 +0100550 return 1;
551 }
552}
553
554static void cli_release_mlook(struct appctx *appctx)
555{
556 free(appctx->ctx.map.chunk.str);
557 appctx->ctx.map.chunk.str = NULL;
558}
559
560
561static int cli_parse_get_map(char **args, struct appctx *appctx, void *private)
562{
563 if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) {
564 /* Set flags. */
565 if (args[1][0] == 'm')
566 appctx->ctx.map.display_flags = PAT_REF_MAP;
567 else
568 appctx->ctx.map.display_flags = PAT_REF_ACL;
569
570 /* No parameter. */
571 if (!*args[2] || !*args[3]) {
572 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
573 appctx->ctx.cli.msg = "Missing map identifier and/or key.\n";
574 else
575 appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100576 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100577 return 1;
578 }
579
580 /* lookup into the maps */
581 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
582 if (!appctx->ctx.map.ref) {
583 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
584 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
585 else
586 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100587 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100588 return 1;
589 }
590
591 /* copy input string. The string must be allocated because
592 * it may be used over multiple iterations. It's released
593 * at the end and upon abort anyway.
594 */
595 appctx->ctx.map.chunk.len = strlen(args[3]);
596 appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1;
597 appctx->ctx.map.chunk.str = strdup(args[3]);
598 if (!appctx->ctx.map.chunk.str) {
599 appctx->ctx.cli.msg = "Out of memory error.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100600 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100601 return 1;
602 }
603
604 return 0;
605 }
606 return 1;
607}
608
Emeric Brun8d85aa42017-06-29 15:40:33 +0200609static void cli_release_show_map(struct appctx *appctx)
610{
611 if (appctx->st2 == STAT_ST_LIST) {
612 if (!LIST_ISEMPTY(&appctx->ctx.map.bref.users))
613 LIST_DEL(&appctx->ctx.map.bref.users);
614 }
615}
616
William Lallemandad8be612016-11-18 19:26:17 +0100617static int cli_parse_show_map(char **args, struct appctx *appctx, void *private)
618{
619 if (strcmp(args[1], "map") == 0 ||
620 strcmp(args[1], "acl") == 0) {
621
622 /* Set ACL or MAP flags. */
623 if (args[1][0] == 'm')
624 appctx->ctx.map.display_flags = PAT_REF_MAP;
625 else
626 appctx->ctx.map.display_flags = PAT_REF_ACL;
627
628 /* no parameter: display all map available */
629 if (!*args[2]) {
William Lallemandad8be612016-11-18 19:26:17 +0100630 appctx->io_handler = cli_io_handler_pats_list;
631 return 0;
632 }
633
634 /* lookup into the refs and check the map flag */
635 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
636 if (!appctx->ctx.map.ref ||
637 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
638 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
639 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
640 else
641 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100642 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100643 return 1;
644 }
William Lallemandad8be612016-11-18 19:26:17 +0100645 appctx->io_handler = cli_io_handler_pat_list;
Emeric Brun8d85aa42017-06-29 15:40:33 +0200646 appctx->io_release = cli_release_show_map;
William Lallemandad8be612016-11-18 19:26:17 +0100647 return 0;
648 }
649
650 return 0;
651}
652
653static int cli_parse_set_map(char **args, struct appctx *appctx, void *private)
654{
655 if (strcmp(args[1], "map") == 0) {
656 char *err;
657
658 /* Set flags. */
659 appctx->ctx.map.display_flags = PAT_REF_MAP;
660
661 /* Expect three parameters: map name, key and new value. */
662 if (!*args[2] || !*args[3] || !*args[4]) {
663 appctx->ctx.cli.msg = "'set map' expects three parameters: map identifier, key and value.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100664 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100665 return 1;
666 }
667
668 /* Lookup the reference in the maps. */
669 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
670 if (!appctx->ctx.map.ref) {
671 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100672 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100673 return 1;
674 }
675
676 /* If the entry identifier start with a '#', it is considered as
677 * pointer id
678 */
679 if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') {
680 struct pat_ref_elt *ref;
681 long long int conv;
682 char *error;
683
684 /* Convert argument to integer value. */
685 conv = strtoll(&args[3][1], &error, 16);
686 if (*error != '\0') {
687 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100688 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100689 return 1;
690 }
691
692 /* Convert and check integer to pointer. */
693 ref = (struct pat_ref_elt *)(long)conv;
694 if ((long long int)(long)ref != conv) {
695 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100696 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100697 return 1;
698 }
699
700 /* Try to delete the entry. */
701 err = NULL;
702 if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) {
703 if (err)
704 memprintf(&err, "%s.\n", err);
705 appctx->ctx.cli.err = err;
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100706 appctx->st0 = CLI_ST_PRINT_FREE;
William Lallemandad8be612016-11-18 19:26:17 +0100707 return 1;
708 }
709 }
710 else {
711 /* Else, use the entry identifier as pattern
712 * string, and update the value.
713 */
714 err = NULL;
715 if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) {
716 if (err)
717 memprintf(&err, "%s.\n", err);
718 appctx->ctx.cli.err = err;
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100719 appctx->st0 = CLI_ST_PRINT_FREE;
William Lallemandad8be612016-11-18 19:26:17 +0100720 return 1;
721 }
722 }
723
724 /* The set is done, send message. */
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100725 appctx->st0 = CLI_ST_PROMPT;
William Lallemandad8be612016-11-18 19:26:17 +0100726 return 0;
727 }
728 return 1;
729}
730
731static int cli_parse_add_map(char **args, struct appctx *appctx, void *private)
732{
733 if (strcmp(args[1], "map") == 0 ||
734 strcmp(args[1], "acl") == 0) {
735 int ret;
736 char *err;
737
738 /* Set flags. */
739 if (args[1][0] == 'm')
740 appctx->ctx.map.display_flags = PAT_REF_MAP;
741 else
742 appctx->ctx.map.display_flags = PAT_REF_ACL;
743
744 /* If the keywork is "map", we expect three parameters, if it
745 * is "acl", we expect only two parameters
746 */
747 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
748 if (!*args[2] || !*args[3] || !*args[4]) {
749 appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100750 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100751 return 1;
752 }
753 }
754 else {
755 if (!*args[2] || !*args[3]) {
756 appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100757 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100758 return 1;
759 }
760 }
761
762 /* Lookup for the reference. */
763 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
764 if (!appctx->ctx.map.ref) {
765 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
766 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
767 else
768 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100769 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100770 return 1;
771 }
772
773 /* The command "add acl" is prohibited if the reference
774 * use samples.
775 */
776 if ((appctx->ctx.map.display_flags & PAT_REF_ACL) &&
777 (appctx->ctx.map.ref->flags & PAT_REF_SMP)) {
778 appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. "
779 "You must use the command 'add map' to add values.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100780 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100781 return 1;
782 }
783
784 /* Add value. */
785 err = NULL;
786 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
787 ret = pat_ref_add(appctx->ctx.map.ref, args[3], args[4], &err);
788 else
789 ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err);
790 if (!ret) {
791 if (err)
792 memprintf(&err, "%s.\n", err);
793 appctx->ctx.cli.err = err;
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100794 appctx->st0 = CLI_ST_PRINT_FREE;
William Lallemandad8be612016-11-18 19:26:17 +0100795 return 1;
796 }
797
798 /* The add is done, send message. */
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100799 appctx->st0 = CLI_ST_PROMPT;
William Lallemandad8be612016-11-18 19:26:17 +0100800 return 1;
801 }
802
803 return 0;
804}
805
806static int cli_parse_del_map(char **args, struct appctx *appctx, void *private)
807{
808 if (args[1][0] == 'm')
809 appctx->ctx.map.display_flags = PAT_REF_MAP;
810 else
811 appctx->ctx.map.display_flags = PAT_REF_ACL;
812
813 /* Expect two parameters: map name and key. */
814 if (appctx->ctx.map.display_flags == PAT_REF_MAP) {
815 if (!*args[2] || !*args[3]) {
816 appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100817 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100818 return 1;
819 }
820 }
821
822 else {
823 if (!*args[2] || !*args[3]) {
824 appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100825 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100826 return 1;
827 }
828 }
829
830 /* Lookup the reference in the maps. */
831 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
832 if (!appctx->ctx.map.ref ||
833 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
834 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100835 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100836 return 1;
837 }
838
839 /* If the entry identifier start with a '#', it is considered as
840 * pointer id
841 */
842 if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') {
843 struct pat_ref_elt *ref;
844 long long int conv;
845 char *error;
846
847 /* Convert argument to integer value. */
848 conv = strtoll(&args[3][1], &error, 16);
849 if (*error != '\0') {
850 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100851 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100852 return 1;
853 }
854
855 /* Convert and check integer to pointer. */
856 ref = (struct pat_ref_elt *)(long)conv;
857 if ((long long int)(long)ref != conv) {
858 appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100859 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100860 return 1;
861 }
862
863 /* Try to delete the entry. */
864 if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) {
865 /* The entry is not found, send message. */
866 appctx->ctx.cli.msg = "Key not found.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100867 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100868 return 1;
869 }
870 }
871 else {
872 /* Else, use the entry identifier as pattern
873 * string and try to delete the entry.
874 */
875 if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) {
876 /* The entry is not found, send message. */
877 appctx->ctx.cli.msg = "Key not found.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100878 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100879 return 1;
880 }
881 }
882
883 /* The deletion is done, send message. */
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100884 appctx->st0 = CLI_ST_PROMPT;
William Lallemandad8be612016-11-18 19:26:17 +0100885 return 1;
886}
887
888
889static int cli_parse_clear_map(char **args, struct appctx *appctx, void *private)
890{
891 if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) {
892 /* Set ACL or MAP flags. */
893 if (args[1][0] == 'm')
894 appctx->ctx.map.display_flags = PAT_REF_MAP;
895 else
896 appctx->ctx.map.display_flags = PAT_REF_ACL;
897
898 /* no parameter */
899 if (!*args[2]) {
900 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
901 appctx->ctx.cli.msg = "Missing map identifier.\n";
902 else
903 appctx->ctx.cli.msg = "Missing ACL identifier.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100904 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100905 return 1;
906 }
907
908 /* lookup into the refs and check the map flag */
909 appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]);
910 if (!appctx->ctx.map.ref ||
911 !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) {
912 if (appctx->ctx.map.display_flags == PAT_REF_MAP)
913 appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n";
914 else
915 appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n";
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100916 appctx->st0 = CLI_ST_PRINT;
William Lallemandad8be612016-11-18 19:26:17 +0100917 return 1;
918 }
919
920 /* Clear all. */
921 pat_ref_prune(appctx->ctx.map.ref);
922
923 /* return response */
Willy Tarreau3b6e5472016-11-24 15:53:53 +0100924 appctx->st0 = CLI_ST_PROMPT;
William Lallemandad8be612016-11-18 19:26:17 +0100925 return 1;
926 }
927 return 0;
928}
929
930/* register cli keywords */
931
932static struct cli_kw_list cli_kws = {{ },{
933 { { "add", "acl", NULL }, "add acl : add acl entry", cli_parse_add_map, NULL },
934 { { "clear", "acl", NULL }, "clear acl <id> : clear the content of this acl", cli_parse_clear_map, NULL },
935 { { "del", "acl", NULL }, "del acl : delete acl entry", cli_parse_del_map, NULL },
936 { { "get", "acl", NULL }, "get acl : report the patterns matching a sample for an ACL", cli_parse_get_map, cli_io_handler_map_lookup, cli_release_mlook },
937 { { "show", "acl", NULL }, "show acl [id] : report available acls or dump an acl's contents", cli_parse_show_map, NULL },
938 { { "add", "map", NULL }, "add map : add map entry", cli_parse_add_map, NULL },
939 { { "clear", "map", NULL }, "clear map <id> : clear the content of this map", cli_parse_clear_map, NULL },
940 { { "del", "map", NULL }, "del map : delete map entry", cli_parse_del_map, NULL },
Nenad Merdanovic96c15712017-03-12 22:01:36 +0100941 { { "get", "map", NULL }, "get map : report the keys and values matching a sample for a map", cli_parse_get_map, cli_io_handler_map_lookup, cli_release_mlook },
William Lallemandad8be612016-11-18 19:26:17 +0100942 { { "set", "map", NULL }, "set map : modify map entry", cli_parse_set_map, NULL },
943 { { "show", "map", NULL }, "show map [id] : report available maps or dump a map's contents", cli_parse_show_map, NULL },
944 { { NULL }, NULL, NULL, NULL }
945}};
946
947
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100948/* Note: must not be declared <const> as its list will be overwritten
949 *
950 * For the map_*_int keywords, the output is declared as SMP_T_UINT, but the converter function
951 * can provide SMP_T_UINT, SMP_T_SINT or SMP_T_BOOL depending on how the patterns found in the
952 * file can be parsed.
953 *
954 * For the map_*_ip keyword, the output is declared as SMP_T_IPV4, but the converter function
955 * can provide SMP_T_IPV4 or SMP_T_IPV6 depending on the patterns found in the file.
956 *
957 * The map_* keywords only emit strings.
958 *
959 * The output type is only used during the configuration parsing. It is used for detecting
960 * compatibility problems.
961 *
962 * The arguments are: <file>[,<default value>]
963 */
964static struct sample_conv_kw_list sample_conv_kws = {ILH, {
Thierry FOURNIER1edc9712014-12-15 16:18:39 +0100965 { "map", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_STR },
966 { "map_str", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_STR },
967 { "map_beg", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_BEG },
968 { "map_sub", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_SUB },
969 { "map_dir", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_DIR },
970 { "map_dom", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_DOM },
971 { "map_end", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_END },
972 { "map_reg", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_REG },
Thierry Fournier8feaa662016-02-10 22:55:20 +0100973 { "map_regm", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, (void *)PAT_MATCH_REGM},
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +0200974 { "map_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_SINT, SMP_T_STR, (void *)PAT_MATCH_INT },
Thierry FOURNIER1edc9712014-12-15 16:18:39 +0100975 { "map_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_ADDR, SMP_T_STR, (void *)PAT_MATCH_IP },
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100976
Thierry FOURNIERbf65cd42015-07-20 17:45:02 +0200977 { "map_str_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_STR },
978 { "map_beg_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_BEG },
979 { "map_sub_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_SUB },
980 { "map_dir_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_DIR },
981 { "map_dom_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_DOM },
982 { "map_end_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_END },
983 { "map_reg_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_STR, SMP_T_SINT, (void *)PAT_MATCH_REG },
984 { "map_int_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_SINT, SMP_T_SINT, (void *)PAT_MATCH_INT },
985 { "map_ip_int", sample_conv_map, ARG2(1,STR,SINT), sample_load_map, SMP_T_ADDR, SMP_T_SINT, (void *)PAT_MATCH_IP },
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100986
Thierry FOURNIERb2f8f082015-08-04 19:35:46 +0200987 { "map_str_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_STR },
988 { "map_beg_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_BEG },
989 { "map_sub_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_SUB },
990 { "map_dir_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_DIR },
991 { "map_dom_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_DOM },
992 { "map_end_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_END },
993 { "map_reg_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_ADDR, (void *)PAT_MATCH_REG },
994 { "map_int_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_SINT, SMP_T_ADDR, (void *)PAT_MATCH_INT },
995 { "map_ip_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_ADDR, SMP_T_ADDR, (void *)PAT_MATCH_IP },
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +0100996
997 { /* END */ },
998}};
999
1000__attribute__((constructor))
1001static void __map_init(void)
1002{
1003 /* register format conversion keywords */
1004 sample_register_convs(&sample_conv_kws);
William Lallemandad8be612016-11-18 19:26:17 +01001005 cli_register_kw(&cli_kws);
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +01001006}