1 /* 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> 27 28 #include <common/chunk.h> 29 #include <common/mini-clist.h> 30 31 #include <types/vars.h> 32 #include <types/protocol_buffers.h> 33 #include <types/stick_table.h> 34 35 /* encoding of each arg type : up to 31 types are supported */ 36 #define ARGT_BITS 5 37 #define ARGT_NBTYPES (1 << ARGT_BITS) 38 #define ARGT_MASK (ARGT_NBTYPES - 1) 39 40 /* encoding of the arg count : up to 12 args are possible. 4 bits are left 41 * unused at the top. 42 */ 43 #define ARGM_MASK ((1 << ARGM_BITS) - 1) 44 #define ARGM_BITS 4 45 #define ARGM_NBARGS (sizeof(uint64_t) * 8 - ARGM_BITS) / ARGT_BITS 46 47 enum { 48 ARGT_STOP = 0, /* end of the arg list */ 49 ARGT_SINT, /* signed 64 bit integer. */ 50 ARGT_STR, /* string */ 51 ARGT_IPV4, /* an IPv4 address */ 52 ARGT_MSK4, /* an IPv4 address mask (integer or dotted), stored as ARGT_IPV4 */ 53 ARGT_IPV6, /* an IPv6 address */ 54 ARGT_MSK6, /* an IPv6 address mask (integer or dotted), stored as ARGT_IPV6 */ 55 ARGT_TIME, /* a delay in ms by default, stored as ARGT_UINT */ 56 ARGT_SIZE, /* a size in bytes by default, stored as ARGT_UINT */ 57 ARGT_FE, /* a pointer to a frontend only */ 58 ARGT_BE, /* a pointer to a backend only */ 59 ARGT_TAB, /* a pointer to a stick table */ 60 ARGT_SRV, /* a pointer to a server */ 61 ARGT_USR, /* a pointer to a user list */ 62 ARGT_MAP, /* a pointer to a map descriptor */ 63 ARGT_REG, /* a pointer to a regex */ 64 ARGT_VAR, /* contains a variable description. */ 65 ARGT_PBUF_FNUM, /* a protocol buffer field number */ 66 /* please update arg_type_names[] in args.c if you add entries here */ 67 }; 68 69 /* context where arguments are used, in order to help error reporting */ 70 enum { 71 ARGC_ACL = 0, /* ACL */ 72 ARGC_STK, /* sticking rule */ 73 ARGC_TRK, /* tracking rule */ 74 ARGC_LOG, /* log-format */ 75 ARGC_LOGSD, /* log-format-sd */ 76 ARGC_HRQ, /* http-request */ 77 ARGC_HRS, /* http-response */ 78 ARGC_UIF, /* unique-id-format */ 79 ARGC_RDR, /* redirect */ 80 ARGC_CAP, /* capture rule */ 81 ARGC_SRV, /* server line */ 82 ARGC_SPOE, /* spoe message args */ 83 ARGC_UBK, /* use_backend message */ 84 }; 85 86 /* flags used when compiling and executing regex */ 87 #define ARGF_REG_ICASE 1 88 #define ARGF_REG_GLOB 2 89 90 /* some types that are externally defined */ 91 struct proxy; 92 struct server; 93 struct userlist; 94 struct my_regex; 95 96 union arg_data { 97 long long int sint; 98 struct buffer str; 99 struct in_addr ipv4; 100 struct in6_addr ipv6; 101 struct proxy *prx; /* used for fe, be, tables */ 102 struct server *srv; 103 struct stktable *t; 104 struct userlist *usr; 105 struct map_descriptor *map; 106 struct my_regex *reg; 107 struct pbuf_fid fid; 108 struct var_desc var; 109 }; 110 111 struct arg { 112 unsigned char type; /* argument type, ARGT_* */ 113 unsigned char unresolved; /* argument contains a string in <str> that must be resolved and freed */ 114 unsigned char type_flags; /* type-specific extra flags (eg: case sensitivity for regex), ARGF_* */ 115 union arg_data data; /* argument data */ 116 }; 117 118 /* arg lists are used to store information about arguments that could not be 119 * resolved when parsing the configuration. The head is an arg_list which 120 * serves as a template to create new entries. Nothing here is allocated, 121 * so plain copies are OK. 122 */ 123 struct arg_list { 124 struct list list; /* chaining with other arg_list, or list head */ 125 struct arg *arg; /* pointer to the arg, NULL on list head */ 126 int arg_pos; /* argument position */ 127 int ctx; /* context where the arg is used (ARGC_*) */ 128 const char *kw; /* keyword making use of these args */ 129 const char *conv; /* conv keyword when in conv, otherwise NULL */ 130 const char *file; /* file name where the args are referenced */ 131 int line; /* line number where the args are referenced */ 132 }; 133 134 #endif /* _TYPES_ARG_H */ 135 136 /* 137 * Local variables: 138 * c-indent-level: 8 139 * c-basic-offset: 8 140 * End: 141 */ 142