Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 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> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 27 | |
| 28 | #include <common/chunk.h> |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 29 | #include <common/mini-clist.h> |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 30 | |
| 31 | enum { |
| 32 | ARGT_STOP = 0, /* end of the arg list */ |
| 33 | ARGT_UINT, /* unsigned integer, which is a positive integer without any sign */ |
| 34 | ARGT_SINT, /* signed integer, the sign (+/-) was explicit. Falls back to UINT if no sign. */ |
| 35 | ARGT_STR, /* string */ |
| 36 | ARGT_IPV4, /* an IPv4 address */ |
| 37 | ARGT_MSK4, /* an IPv4 address mask (integer or dotted), stored as ARGT_IPV4 */ |
| 38 | ARGT_IPV6, /* an IPv6 address */ |
| 39 | ARGT_MSK6, /* an IPv6 address mask (integer or dotted), stored as ARGT_IPV4 */ |
| 40 | ARGT_TIME, /* a delay in ms by default, stored as ARGT_UINT */ |
| 41 | ARGT_SIZE, /* a size in bytes by default, stored as ARGT_UINT */ |
| 42 | ARGT_FE, /* a pointer to a frontend only */ |
| 43 | ARGT_BE, /* a pointer to a backend only */ |
| 44 | ARGT_TAB, /* a pointer to a stick table */ |
| 45 | ARGT_SRV, /* a pointer to a server */ |
| 46 | ARGT_USR, /* a pointer to a user list */ |
Thierry FOURNIER | 4b5e422 | 2013-11-22 17:40:18 +0100 | [diff] [blame] | 47 | ARGT_MAP, /* a pointer to a map descriptor */ |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 48 | ARGT_NBTYPES /* no more values past 15 */ |
| 49 | }; |
| 50 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 51 | /* context where arguments are used, in order to help error reporting */ |
| 52 | enum { |
| 53 | ARGC_ACL = 0, /* ACL */ |
| 54 | ARGC_STK, /* sticking rule */ |
| 55 | ARGC_TRK, /* tracking rule */ |
| 56 | ARGC_LOG, /* log-format */ |
Thierry FOURNIER | 1c0054f | 2013-11-20 15:09:52 +0100 | [diff] [blame] | 57 | ARGC_HRQ, /* http-request */ |
| 58 | ARGC_HRS, /* http-response */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 59 | ARGC_UIF, /* unique-id-format */ |
Thierry FOURNIER | d18cd0f | 2013-11-29 12:15:45 +0100 | [diff] [blame] | 60 | ARGC_RDR, /* redirect */ |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 61 | }; |
| 62 | |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 63 | /* some types that are externally defined */ |
| 64 | struct proxy; |
| 65 | struct server; |
| 66 | struct userlist; |
| 67 | |
| 68 | union arg_data { |
| 69 | unsigned int uint; /* used for uint, time, size */ |
| 70 | int sint; |
| 71 | struct chunk str; |
| 72 | struct in_addr ipv4; |
| 73 | struct in6_addr ipv6; |
| 74 | struct proxy *prx; /* used for fe, be, tables */ |
| 75 | struct server *srv; |
| 76 | struct userlist *usr; |
Thierry FOURNIER | 4b5e422 | 2013-11-22 17:40:18 +0100 | [diff] [blame] | 77 | struct map_descriptor *map; |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | struct arg { |
Willy Tarreau | 496aa01 | 2012-06-01 10:38:29 +0200 | [diff] [blame] | 81 | unsigned char type; /* argument type, ARGT_* */ |
| 82 | unsigned char unresolved; /* argument contains a string in <str> that must be resolved and freed */ |
| 83 | union arg_data data; /* argument data */ |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 84 | }; |
| 85 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 86 | /* arg lists are used to store information about arguments that could not be |
| 87 | * resolved when parsing the configuration. The head is an arg_list which |
| 88 | * serves as a template to create new entries. Nothing here is allocated, |
| 89 | * so plain copies are OK. |
| 90 | */ |
| 91 | struct arg_list { |
| 92 | struct list list; /* chaining with other arg_list, or list head */ |
| 93 | struct arg *arg; /* pointer to the arg, NULL on list head */ |
| 94 | int arg_pos; /* argument position */ |
| 95 | int ctx; /* context where the arg is used (ARGC_*) */ |
| 96 | const char *kw; /* keyword making use of these args */ |
| 97 | const char *conv; /* conv keyword when in conv, otherwise NULL */ |
| 98 | const char *file; /* file name where the args are referenced */ |
| 99 | int line; /* line number where the args are referenced */ |
| 100 | }; |
Willy Tarreau | 2ac5718 | 2012-04-19 15:24:50 +0200 | [diff] [blame] | 101 | |
| 102 | #endif /* _TYPES_ARG_H */ |
| 103 | |
| 104 | /* |
| 105 | * Local variables: |
| 106 | * c-indent-level: 8 |
| 107 | * c-basic-offset: 8 |
| 108 | * End: |
| 109 | */ |