Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 18 | #include <types/global.h> |
| 19 | #include <types/map.h> |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 20 | #include <types/pattern.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 21 | |
| 22 | #include <proto/arg.h> |
Thierry FOURNIER | b0c0a0f | 2013-12-10 15:05:34 +0100 | [diff] [blame] | 23 | #include <proto/map.h> |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 24 | #include <proto/pattern.h> |
| 25 | #include <proto/sample.h> |
| 26 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 27 | /* Parse an IPv4 address and store it into the sample. |
| 28 | * The output type is IPV4. |
| 29 | */ |
Thierry FOURNIER | b0c0a0f | 2013-12-10 15:05:34 +0100 | [diff] [blame] | 30 | int map_parse_ip(const char *text, struct sample_storage *smp) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 31 | { |
| 32 | if (!buf2ip(text, strlen(text), &smp->data.ipv4)) |
| 33 | return 0; |
| 34 | smp->type = SMP_T_IPV4; |
| 35 | return 1; |
| 36 | } |
| 37 | |
| 38 | /* Parse an IPv6 address and store it into the sample. |
| 39 | * The output type is IPV6. |
| 40 | */ |
Thierry FOURNIER | b0c0a0f | 2013-12-10 15:05:34 +0100 | [diff] [blame] | 41 | int map_parse_ip6(const char *text, struct sample_storage *smp) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 42 | { |
| 43 | if (!buf2ip6(text, strlen(text), &smp->data.ipv6)) |
| 44 | return 0; |
| 45 | smp->type = SMP_T_IPV6; |
| 46 | return 1; |
| 47 | } |
| 48 | |
| 49 | /* Parse a string and store a pointer to it into the sample. The original |
| 50 | * string must be left in memory because we return a direct memory reference. |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 51 | * The output type is SMP_T_STR. There is no risk that the data will be |
| 52 | * overwritten because sample_conv_map() makes a const sample with this |
| 53 | * output. |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 54 | */ |
Thierry FOURNIER | b0c0a0f | 2013-12-10 15:05:34 +0100 | [diff] [blame] | 55 | int map_parse_str(const char *text, struct sample_storage *smp) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 56 | { |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 57 | smp->data.str.str = (char *)text; |
| 58 | smp->data.str.len = strlen(text); |
| 59 | smp->data.str.size = smp->data.str.len + 1; |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 60 | smp->type = SMP_T_STR; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 61 | return 1; |
| 62 | } |
| 63 | |
| 64 | /* Parse an integer and convert it to a sample. The output type is SINT if the |
| 65 | * number is negative, or UINT if it is positive or null. The function returns |
| 66 | * zero (error) if the number is too large. |
| 67 | */ |
Thierry FOURNIER | b0c0a0f | 2013-12-10 15:05:34 +0100 | [diff] [blame] | 68 | int map_parse_int(const char *text, struct sample_storage *smp) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 69 | { |
| 70 | long long int value; |
| 71 | char *error; |
| 72 | |
| 73 | /* parse interger and convert it. Return the value in 64 format. */ |
| 74 | value = strtoll(text, &error, 10); |
| 75 | if (*error != '\0') |
| 76 | return 0; |
| 77 | |
| 78 | /* check sign iand limits */ |
| 79 | if (value < 0) { |
| 80 | if (value < INT_MIN) |
| 81 | return 0; |
| 82 | smp->type = SMP_T_SINT; |
| 83 | smp->data.sint = value; |
| 84 | } |
| 85 | else { |
| 86 | if (value > UINT_MAX) |
| 87 | return 0; |
| 88 | smp->type = SMP_T_UINT; |
| 89 | smp->data.uint = value; |
| 90 | } |
| 91 | |
| 92 | return 1; |
| 93 | } |
| 94 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 95 | /* This crete and initialize map descriptor. |
| 96 | * Return NULL if out of memory error |
| 97 | */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 98 | static struct map_descriptor *map_create_descriptor(struct sample_conv *conv) |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 99 | { |
| 100 | struct map_descriptor *desc; |
| 101 | |
| 102 | desc = calloc(1, sizeof(*desc)); |
| 103 | if (!desc) |
| 104 | return NULL; |
| 105 | |
| 106 | desc->conv = conv; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 107 | |
| 108 | return desc; |
| 109 | } |
| 110 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 111 | /* Reads patterns from a file. If <err_msg> is non-NULL, an error message will |
| 112 | * be returned there on errors and the caller will have to free it. |
| 113 | * |
| 114 | * The file contains one key + value per line. Lines which start with '#' are |
| 115 | * ignored, just like empty lines. Leading tabs/spaces are stripped. The key is |
| 116 | * then the first "word" (series of non-space/tabs characters), and the value is |
| 117 | * what follows this series of space/tab till the end of the line excluding |
| 118 | * trailing spaces/tabs. |
| 119 | * |
| 120 | * Example : |
| 121 | * |
| 122 | * # this is a comment and is ignored |
| 123 | * 62.212.114.60 1wt.eu \n |
| 124 | * <-><-----------><---><----><----> |
| 125 | * | | | | `--- trailing spaces ignored |
| 126 | * | | | `-------- value |
| 127 | * | | `--------------- middle spaces ignored |
| 128 | * | `------------------------ key |
| 129 | * `-------------------------------- leading spaces ignored |
| 130 | * |
| 131 | * Return non-zero in case of succes, otherwise 0. |
| 132 | */ |
| 133 | static int map_read_entries_from_file(const char *filename, |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 134 | struct pat_ref *ref, |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 135 | char **err) |
| 136 | { |
| 137 | FILE *file; |
| 138 | char *c; |
| 139 | int ret = 0; |
| 140 | int line = 0; |
| 141 | char *key_beg; |
| 142 | char *key_end; |
| 143 | char *value_beg; |
| 144 | char *value_end; |
| 145 | |
| 146 | file = fopen(filename, "r"); |
| 147 | if (!file) { |
| 148 | memprintf(err, "failed to open pattern file <%s>", filename); |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | /* now parse all patterns. The file may contain only one pattern |
| 153 | * followed by one value per line. The start spaces, separator spaces |
| 154 | * and and spaces are stripped. Each can contain comment started by '#' |
| 155 | */ |
| 156 | while (fgets(trash.str, trash.size, file) != NULL) { |
| 157 | line++; |
| 158 | c = trash.str; |
| 159 | |
| 160 | /* ignore lines beginning with a dash */ |
| 161 | if (*c == '#') |
| 162 | continue; |
| 163 | |
| 164 | /* strip leading spaces and tabs */ |
| 165 | while (*c == ' ' || *c == '\t') |
| 166 | c++; |
| 167 | |
| 168 | /* empty lines are ignored too */ |
Thierry FOURNIER | 338a031 | 2014-02-26 18:30:13 +0100 | [diff] [blame] | 169 | if (*c == '\0' || *c == '\r' || *c == '\n') |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 170 | continue; |
| 171 | |
| 172 | /* look for the end of the key */ |
| 173 | key_beg = c; |
| 174 | while (*c && *c != ' ' && *c != '\t' && *c != '\n' && *c != '\r') |
| 175 | c++; |
| 176 | |
| 177 | key_end = c; |
| 178 | |
| 179 | /* strip middle spaces and tabs */ |
| 180 | while (*c == ' ' || *c == '\t') |
| 181 | c++; |
| 182 | |
| 183 | /* look for the end of the value, it is the end of the line */ |
| 184 | value_beg = c; |
| 185 | while (*c && *c != '\n' && *c != '\r') |
| 186 | c++; |
| 187 | value_end = c; |
| 188 | |
| 189 | /* trim possibly trailing spaces and tabs */ |
| 190 | while (value_end > value_beg && (value_end[-1] == ' ' || value_end[-1] == '\t')) |
| 191 | value_end--; |
| 192 | |
| 193 | /* set final \0 and check entries */ |
| 194 | *key_end = '\0'; |
| 195 | *value_end = '\0'; |
| 196 | |
| 197 | /* insert values */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 198 | if (!pat_ref_append(ref, key_beg, value_beg, line)) { |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 199 | memprintf(err, "out of memory"); |
| 200 | goto out_close; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | /* succes */ |
| 205 | ret = 1; |
| 206 | |
| 207 | out_close: |
| 208 | fclose(file); |
| 209 | return ret; |
| 210 | } |
| 211 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 212 | /* This function load the map file according with data type declared into |
| 213 | * the "struct sample_conv". |
| 214 | * |
| 215 | * This function choose the indexation type (ebtree or list) according with |
| 216 | * the type of match needed. |
| 217 | */ |
| 218 | static int sample_load_map(struct arg *arg, struct sample_conv *conv, char **err) |
| 219 | { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 220 | struct pat_ref *ref; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 221 | struct map_descriptor *desc; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 222 | struct pattern_expr *expr; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 223 | |
| 224 | /* look for existing map reference. The reference is the |
| 225 | * file encountered in the first argument. arg[0] with string |
| 226 | * type is guaranteed by the parser. |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 227 | * |
| 228 | * If the reference dosn't exists, create it and load file. |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 229 | */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 230 | ref = pat_ref_lookup(arg[0].data.str.str); |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 231 | if (!ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 232 | ref = pat_ref_new(arg[0].data.str.str, PAT_REF_MAP); |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 233 | if (!ref) { |
| 234 | memprintf(err, "out of memory"); |
| 235 | return 0; |
| 236 | } |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 237 | if (!map_read_entries_from_file(arg[0].data.str.str, ref, err)) |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | /* create new map descriptor */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 242 | desc = map_create_descriptor(conv); |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 243 | if (!desc) { |
| 244 | memprintf(err, "out of memory"); |
| 245 | return 0; |
| 246 | } |
| 247 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 248 | /* Initialize pattern */ |
| 249 | pattern_init_head(&desc->pat); |
| 250 | |
| 251 | /* This is original pattern, must free */ |
| 252 | desc->do_free = 1; |
| 253 | |
| 254 | /* Set the match method. */ |
| 255 | desc->pat.match = pat_match_fcts[conv->private]; |
| 256 | desc->pat.parse = pat_parse_fcts[conv->private]; |
| 257 | desc->pat.index = pat_index_fcts[conv->private]; |
| 258 | desc->pat.delete = pat_delete_fcts[conv->private]; |
| 259 | desc->pat.prune = pat_prune_fcts[conv->private]; |
| 260 | desc->pat.find_smp = pat_find_smp_fcts[conv->private]; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 261 | desc->pat.expect_type = pat_match_types[conv->private]; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 262 | |
| 263 | /* Set the output parse method. */ |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 264 | switch (desc->conv->out_type) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 265 | case SMP_T_STR: desc->pat.parse_smp = map_parse_str; break; |
| 266 | case SMP_T_UINT: desc->pat.parse_smp = map_parse_int; break; |
| 267 | case SMP_T_IPV4: desc->pat.parse_smp = map_parse_ip; break; |
| 268 | case SMP_T_IPV6: desc->pat.parse_smp = map_parse_ip6; break; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 269 | default: |
| 270 | memprintf(err, "map: internal haproxy error: no default parse case for the input type <%d>.", |
| 271 | conv->out_type); |
| 272 | return 0; |
| 273 | } |
| 274 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 275 | /* Create new pattern expression for this reference. */ |
| 276 | expr = pattern_new_expr(&desc->pat, ref, err); |
| 277 | if (!expr) |
| 278 | return 0; |
Thierry FOURNIER | 0ffe78c | 2013-12-05 14:40:25 +0100 | [diff] [blame] | 279 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 280 | /* Load the reference content in the pattern expression. */ |
| 281 | if (!pat_ref_load(ref, expr, 0, 1, err)) |
| 282 | return 0; |
Thierry FOURNIER | 0ffe78c | 2013-12-05 14:40:25 +0100 | [diff] [blame] | 283 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 284 | /* The second argument is the default value */ |
| 285 | if (arg[1].type == ARGT_STR) { |
| 286 | desc->default_value = strdup(arg[1].data.str.str); |
| 287 | if (!desc->default_value) { |
| 288 | memprintf(err, "out of memory"); |
| 289 | return 0; |
| 290 | } |
| 291 | desc->def = calloc(1, sizeof(*desc->def)); |
| 292 | if (!desc->def) { |
| 293 | memprintf(err, "out of memory"); |
| 294 | return 0; |
| 295 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 296 | if (!desc->pat.parse_smp(desc->default_value, desc->def)) { |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 297 | memprintf(err, "Cannot parse default value"); |
| 298 | return 0; |
| 299 | } |
| 300 | } |
| 301 | else |
| 302 | desc->def = NULL; |
| 303 | |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 304 | /* replace the first argument by this definition */ |
| 305 | arg[0].type = ARGT_MAP; |
| 306 | arg[0].data.map = desc; |
| 307 | |
| 308 | return 1; |
| 309 | } |
| 310 | |
| 311 | static int sample_conv_map(const struct arg *arg_p, struct sample *smp) |
| 312 | { |
| 313 | struct map_descriptor *desc; |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 314 | struct pattern *pat; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 315 | |
| 316 | /* get config */ |
| 317 | desc = arg_p[0].data.map; |
| 318 | |
| 319 | /* Execute the match function. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 320 | pat = pattern_exec_match(&desc->pat, smp, 1); |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 321 | |
| 322 | /* Match case. */ |
| 323 | if (pat) { |
| 324 | /* Copy sample. */ |
| 325 | if (pat->smp) { |
| 326 | smp->type = pat->smp->type; |
| 327 | smp->flags |= SMP_F_CONST; |
| 328 | memcpy(&smp->data, &pat->smp->data, sizeof(smp->data)); |
| 329 | return 1; |
| 330 | } |
| 331 | |
| 332 | /* Return just int sample containing 1. */ |
| 333 | smp->type = SMP_T_UINT; |
| 334 | smp->data.uint= 1; |
| 335 | return 1; |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 336 | } |
| 337 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 338 | /* If no default value avalaible, the converter fails. */ |
| 339 | if (!desc->def) |
| 340 | return 0; |
| 341 | |
| 342 | /* Return the default value. */ |
| 343 | smp->type = desc->def->type; |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 344 | smp->flags |= SMP_F_CONST; |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 345 | memcpy(&smp->data, &desc->def->data, sizeof(smp->data)); |
Thierry FOURNIER | d5f624d | 2013-11-26 11:52:33 +0100 | [diff] [blame] | 346 | return 1; |
| 347 | } |
| 348 | |
| 349 | /* Note: must not be declared <const> as its list will be overwritten |
| 350 | * |
| 351 | * For the map_*_int keywords, the output is declared as SMP_T_UINT, but the converter function |
| 352 | * can provide SMP_T_UINT, SMP_T_SINT or SMP_T_BOOL depending on how the patterns found in the |
| 353 | * file can be parsed. |
| 354 | * |
| 355 | * For the map_*_ip keyword, the output is declared as SMP_T_IPV4, but the converter function |
| 356 | * can provide SMP_T_IPV4 or SMP_T_IPV6 depending on the patterns found in the file. |
| 357 | * |
| 358 | * The map_* keywords only emit strings. |
| 359 | * |
| 360 | * The output type is only used during the configuration parsing. It is used for detecting |
| 361 | * compatibility problems. |
| 362 | * |
| 363 | * The arguments are: <file>[,<default value>] |
| 364 | */ |
| 365 | static struct sample_conv_kw_list sample_conv_kws = {ILH, { |
| 366 | { "map", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, PAT_MATCH_STR }, |
| 367 | { "map_str", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, PAT_MATCH_STR }, |
| 368 | { "map_beg", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, PAT_MATCH_BEG }, |
| 369 | { "map_sub", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, PAT_MATCH_SUB }, |
| 370 | { "map_dir", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, PAT_MATCH_DIR }, |
| 371 | { "map_dom", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, PAT_MATCH_DOM }, |
| 372 | { "map_end", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, PAT_MATCH_END }, |
| 373 | { "map_reg", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_STR, PAT_MATCH_REG }, |
| 374 | { "map_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_UINT, SMP_T_STR, PAT_MATCH_INT }, |
| 375 | { "map_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_ADDR, SMP_T_STR, PAT_MATCH_IP }, |
| 376 | |
| 377 | { "map_str_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_UINT, PAT_MATCH_STR }, |
| 378 | { "map_beg_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_UINT, PAT_MATCH_BEG }, |
| 379 | { "map_sub_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_UINT, PAT_MATCH_SUB }, |
| 380 | { "map_dir_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_UINT, PAT_MATCH_DIR }, |
| 381 | { "map_dom_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_UINT, PAT_MATCH_DOM }, |
| 382 | { "map_end_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_UINT, PAT_MATCH_END }, |
| 383 | { "map_reg_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_UINT, PAT_MATCH_REG }, |
| 384 | { "map_int_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_UINT, SMP_T_UINT, PAT_MATCH_INT }, |
| 385 | { "map_ip_int", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_ADDR, SMP_T_UINT, PAT_MATCH_IP }, |
| 386 | |
| 387 | { "map_str_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_IPV4, PAT_MATCH_STR }, |
| 388 | { "map_beg_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_IPV4, PAT_MATCH_BEG }, |
| 389 | { "map_sub_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_IPV4, PAT_MATCH_SUB }, |
| 390 | { "map_dir_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_IPV4, PAT_MATCH_DIR }, |
| 391 | { "map_dom_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_IPV4, PAT_MATCH_DOM }, |
| 392 | { "map_end_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_IPV4, PAT_MATCH_END }, |
| 393 | { "map_reg_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_STR, SMP_T_IPV4, PAT_MATCH_REG }, |
| 394 | { "map_int_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_UINT, SMP_T_IPV4, PAT_MATCH_INT }, |
| 395 | { "map_ip_ip", sample_conv_map, ARG2(1,STR,STR), sample_load_map, SMP_T_ADDR, SMP_T_IPV4, PAT_MATCH_IP }, |
| 396 | |
| 397 | { /* END */ }, |
| 398 | }}; |
| 399 | |
| 400 | __attribute__((constructor)) |
| 401 | static void __map_init(void) |
| 402 | { |
| 403 | /* register format conversion keywords */ |
| 404 | sample_register_convs(&sample_conv_kws); |
| 405 | } |