blob: 96974ba880d1b4129c3ddf121ffae5b150f7cedd [file] [log] [blame]
Willy Tarreau2ac57182012-04-19 15:24:50 +02001/*
2 * include/types/arg.h
3 * This file contains structure declarations for generaic argument parsing.
4 *
5 * Copyright 2012 Willy Tarreau <w@1wt.eu>
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_ARG_H
23#define _TYPES_ARG_H
24
25#include <sys/socket.h>
26#include <netinet/in.h>
Willy Tarreauc7e42382012-08-24 19:22:53 +020027
28#include <common/chunk.h>
Willy Tarreaua4312fa2013-04-02 16:34:32 +020029#include <common/mini-clist.h>
Willy Tarreau2ac57182012-04-19 15:24:50 +020030
Thierry FOURNIER4834bc72015-06-06 19:29:07 +020031#include <types/vars.h>
32
Willy Tarreaudbc79d02015-01-19 18:54:49 +010033/* encoding of each arg type : up to 31 types are supported */
34#define ARGT_BITS 5
Willy Tarreau3d241e72015-01-19 18:44:07 +010035#define ARGT_NBTYPES (1 << ARGT_BITS)
36#define ARGT_MASK (ARGT_NBTYPES - 1)
37
David Carlier15073a32016-03-15 19:00:35 +000038/* encoding of the arg count : up to 12 args are possible. 4 bits are left
Willy Tarreaudbc79d02015-01-19 18:54:49 +010039 * unused at the top.
40 */
Willy Tarreau3d241e72015-01-19 18:44:07 +010041#define ARGM_MASK ((1 << ARGM_BITS) - 1)
David Carlier15073a32016-03-15 19:00:35 +000042#define ARGM_BITS 4
43#define ARGM_NBARGS (sizeof(uint64_t) * 8 - ARGM_BITS) / ARGT_BITS
Willy Tarreau3d241e72015-01-19 18:44:07 +010044
Willy Tarreau2ac57182012-04-19 15:24:50 +020045enum {
46 ARGT_STOP = 0, /* end of the arg list */
Thierry FOURNIERbf65cd42015-07-20 17:45:02 +020047 ARGT_SINT, /* signed 64 bit integer. */
Willy Tarreau2ac57182012-04-19 15:24:50 +020048 ARGT_STR, /* string */
49 ARGT_IPV4, /* an IPv4 address */
50 ARGT_MSK4, /* an IPv4 address mask (integer or dotted), stored as ARGT_IPV4 */
51 ARGT_IPV6, /* an IPv6 address */
Tim Duesterhus92bb0342018-01-25 16:24:47 +010052 ARGT_MSK6, /* an IPv6 address mask (integer or dotted), stored as ARGT_IPV6 */
Willy Tarreau2ac57182012-04-19 15:24:50 +020053 ARGT_TIME, /* a delay in ms by default, stored as ARGT_UINT */
54 ARGT_SIZE, /* a size in bytes by default, stored as ARGT_UINT */
55 ARGT_FE, /* a pointer to a frontend only */
56 ARGT_BE, /* a pointer to a backend only */
57 ARGT_TAB, /* a pointer to a stick table */
58 ARGT_SRV, /* a pointer to a server */
59 ARGT_USR, /* a pointer to a user list */
Thierry FOURNIER4b5e4222013-11-22 17:40:18 +010060 ARGT_MAP, /* a pointer to a map descriptor */
Willy Tarreau46947782015-01-19 19:00:58 +010061 ARGT_REG, /* a pointer to a regex */
Thierry FOURNIER4834bc72015-06-06 19:29:07 +020062 ARGT_VAR, /* contains a variable description. */
Willy Tarreauf7ead612015-09-21 20:57:12 +020063 /* please update arg_type_names[] in args.c if you add entries here */
Willy Tarreau2ac57182012-04-19 15:24:50 +020064};
65
Willy Tarreaua4312fa2013-04-02 16:34:32 +020066/* context where arguments are used, in order to help error reporting */
67enum {
68 ARGC_ACL = 0, /* ACL */
69 ARGC_STK, /* sticking rule */
70 ARGC_TRK, /* tracking rule */
71 ARGC_LOG, /* log-format */
Dragan Dosen0b85ece2015-09-25 19:17:44 +020072 ARGC_LOGSD, /* log-format-sd */
Thierry FOURNIER1c0054f2013-11-20 15:09:52 +010073 ARGC_HRQ, /* http-request */
74 ARGC_HRS, /* http-response */
Willy Tarreaua4312fa2013-04-02 16:34:32 +020075 ARGC_UIF, /* unique-id-format */
Thierry FOURNIERd18cd0f2013-11-29 12:15:45 +010076 ARGC_RDR, /* redirect */
Willy Tarreau3a4ac422014-06-13 16:17:14 +020077 ARGC_CAP, /* capture rule */
Willy Tarreau28d976d2015-07-09 11:39:33 +020078 ARGC_SRV, /* server line */
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +020079 ARGC_SPOE, /* spoe message args */
Thierry FOURNIER / OZON.IO4ed1c952016-11-24 23:57:54 +010080 ARGC_UBK, /* use_backend message */
Willy Tarreaua4312fa2013-04-02 16:34:32 +020081};
82
Willy Tarreau46947782015-01-19 19:00:58 +010083/* flags used when compiling and executing regex */
84#define ARGF_REG_ICASE 1
85#define ARGF_REG_GLOB 2
86
Willy Tarreau2ac57182012-04-19 15:24:50 +020087/* some types that are externally defined */
88struct proxy;
89struct server;
90struct userlist;
Willy Tarreau46947782015-01-19 19:00:58 +010091struct my_regex;
Willy Tarreau2ac57182012-04-19 15:24:50 +020092
93union arg_data {
Thierry FOURNIERbf65cd42015-07-20 17:45:02 +020094 long long int sint;
Willy Tarreau83061a82018-07-13 11:56:34 +020095 struct buffer str;
Willy Tarreau2ac57182012-04-19 15:24:50 +020096 struct in_addr ipv4;
97 struct in6_addr ipv6;
98 struct proxy *prx; /* used for fe, be, tables */
99 struct server *srv;
100 struct userlist *usr;
Thierry FOURNIER4b5e4222013-11-22 17:40:18 +0100101 struct map_descriptor *map;
Willy Tarreau46947782015-01-19 19:00:58 +0100102 struct my_regex *reg;
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200103 struct var_desc var;
Willy Tarreau2ac57182012-04-19 15:24:50 +0200104};
105
106struct arg {
Willy Tarreau496aa012012-06-01 10:38:29 +0200107 unsigned char type; /* argument type, ARGT_* */
108 unsigned char unresolved; /* argument contains a string in <str> that must be resolved and freed */
Willy Tarreau085dafa2015-01-21 15:51:47 +0100109 unsigned char type_flags; /* type-specific extra flags (eg: case sensitivity for regex), ARGF_* */
Willy Tarreau496aa012012-06-01 10:38:29 +0200110 union arg_data data; /* argument data */
Willy Tarreau2ac57182012-04-19 15:24:50 +0200111};
112
Willy Tarreaua4312fa2013-04-02 16:34:32 +0200113/* arg lists are used to store information about arguments that could not be
114 * resolved when parsing the configuration. The head is an arg_list which
115 * serves as a template to create new entries. Nothing here is allocated,
116 * so plain copies are OK.
117 */
118struct arg_list {
119 struct list list; /* chaining with other arg_list, or list head */
120 struct arg *arg; /* pointer to the arg, NULL on list head */
121 int arg_pos; /* argument position */
122 int ctx; /* context where the arg is used (ARGC_*) */
123 const char *kw; /* keyword making use of these args */
124 const char *conv; /* conv keyword when in conv, otherwise NULL */
125 const char *file; /* file name where the args are referenced */
126 int line; /* line number where the args are referenced */
127};
Willy Tarreau2ac57182012-04-19 15:24:50 +0200128
129#endif /* _TYPES_ARG_H */
130
131/*
132 * Local variables:
133 * c-indent-level: 8
134 * c-basic-offset: 8
135 * End:
136 */