2012-04-19 13:24:50 +00:00
|
|
|
/*
|
|
|
|
* include/proto/arg.h
|
|
|
|
* This file contains functions and macros declarations for generic argument parsing.
|
|
|
|
*
|
|
|
|
* Copyright 2012 Willy Tarreau <w@1wt.eu>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation, version 2.1
|
|
|
|
* exclusively.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _PROTO_ARG_H
|
|
|
|
#define _PROTO_ARG_H
|
|
|
|
|
|
|
|
#include <types/arg.h>
|
|
|
|
|
|
|
|
/* Some macros used to build some arg list. We can declare various argument
|
|
|
|
* combinations from 0 to 7 args using a single 32-bit integer. The first
|
|
|
|
* argument of these macros is always the mandatory number of arguments, and
|
|
|
|
* remaining ones are optional args. Note: ARGM() may also be used to return
|
|
|
|
* the number of mandatory arguments in a mask.
|
|
|
|
*/
|
|
|
|
#define ARGM(m) \
|
2015-01-19 17:44:07 +00:00
|
|
|
(m & ARGM_MASK)
|
2012-04-19 13:24:50 +00:00
|
|
|
|
|
|
|
#define ARG1(m, t1) \
|
2015-01-19 17:44:07 +00:00
|
|
|
(ARGM(m) + (ARGT_##t1 << (ARGM_BITS)))
|
2012-04-19 13:24:50 +00:00
|
|
|
|
|
|
|
#define ARG2(m, t1, t2) \
|
2015-01-19 17:44:07 +00:00
|
|
|
(ARG1(m, t1) + (ARGT_##t2 << (ARGM_BITS + ARGT_BITS)))
|
2012-04-19 13:24:50 +00:00
|
|
|
|
|
|
|
#define ARG3(m, t1, t2, t3) \
|
2015-01-19 17:44:07 +00:00
|
|
|
(ARG2(m, t1, t2) + (ARGT_##t3 << (ARGM_BITS + ARGT_BITS * 2)))
|
2012-04-19 13:24:50 +00:00
|
|
|
|
|
|
|
#define ARG4(m, t1, t2, t3, t4) \
|
2015-01-19 17:44:07 +00:00
|
|
|
(ARG3(m, t1, t2, t3) + (ARGT_##t4 << (ARGM_BITS + ARGT_BITS * 3)))
|
2012-04-19 13:24:50 +00:00
|
|
|
|
|
|
|
#define ARG5(m, t1, t2, t3, t4, t5) \
|
2015-01-19 17:44:07 +00:00
|
|
|
(ARG4(m, t1, t2, t3, t4) + (ARGT_##t5 << (ARGM_BITS + ARGT_BITS * 4)))
|
2012-04-19 13:24:50 +00:00
|
|
|
|
2014-12-08 18:50:43 +00:00
|
|
|
/* Mapping between argument number and literal description. */
|
|
|
|
extern const char *arg_type_names[];
|
|
|
|
|
2012-10-19 17:49:09 +00:00
|
|
|
/* This dummy arg list may be used by default when no arg is found, it helps
|
|
|
|
* parsers by removing pointer checks.
|
|
|
|
*/
|
2015-01-19 17:44:07 +00:00
|
|
|
extern struct arg empty_arg_list[ARGM_NBARGS];
|
2012-10-19 17:49:09 +00:00
|
|
|
|
MAJOR: sample: maintain a per-proxy list of the fetch args to resolve
While ACL args were resolved after all the config was parsed, it was not the
case with sample fetch args because they're almost everywhere now.
The issue is that ACLs now solely rely on sample fetches, so their args
resolving doesn't work anymore. And many fetches involving a server, a
proxy or a userlist don't work at all.
The real issue is that at the bottom layers we have no information about
proxies, line numbers, even ACLs in order to report understandable errors,
and that at the top layers we have no visibility over the locations where
fetches are referenced (think log node).
After failing multiple unsatisfying solutions attempts, we now have a new
concept of args list. The principle is that every proxy has a list head
which contains a number of indications such as the config keyword, the
context where it's used, the file and line number, etc... and a list of
arguments. This list head is of the same type as the elements, so it
serves as a template for adding new elements. This way, it is filled from
top to bottom by the callers with the information they have (eg: line
numbers, ACL name, ...) and the lower layers just have to duplicate it and
add an element when they face an argument they cannot resolve yet.
Then at the end of the configuration parsing, a loop passes over each
proxy's list and resolves all the args in sequence. And this way there is
all necessary information to report verbose errors.
The first immediate benefit is that for the first time we got very precise
location of issues (arg number in a keyword in its context, ...). Second,
in order to do this we had to parse log-format and unique-id-format a bit
earlier, so that was a great opportunity for doing so when the directives
are encountered (unless it's a default section). This way, the recorded
line numbers for these args are the ones of the place where the log format
is declared, not the end of the file.
Userlists report slightly more information now. They're the only remaining
ones in the ACL resolving function.
2013-04-02 14:34:32 +00:00
|
|
|
struct arg_list *arg_list_clone(const struct arg_list *orig);
|
|
|
|
struct arg_list *arg_list_add(struct arg_list *orig, struct arg *arg, int pos);
|
2012-04-19 13:24:50 +00:00
|
|
|
int make_arg_list(const char *in, int len, unsigned int mask, struct arg **argp,
|
MAJOR: sample: maintain a per-proxy list of the fetch args to resolve
While ACL args were resolved after all the config was parsed, it was not the
case with sample fetch args because they're almost everywhere now.
The issue is that ACLs now solely rely on sample fetches, so their args
resolving doesn't work anymore. And many fetches involving a server, a
proxy or a userlist don't work at all.
The real issue is that at the bottom layers we have no information about
proxies, line numbers, even ACLs in order to report understandable errors,
and that at the top layers we have no visibility over the locations where
fetches are referenced (think log node).
After failing multiple unsatisfying solutions attempts, we now have a new
concept of args list. The principle is that every proxy has a list head
which contains a number of indications such as the config keyword, the
context where it's used, the file and line number, etc... and a list of
arguments. This list head is of the same type as the elements, so it
serves as a template for adding new elements. This way, it is filled from
top to bottom by the callers with the information they have (eg: line
numbers, ACL name, ...) and the lower layers just have to duplicate it and
add an element when they face an argument they cannot resolve yet.
Then at the end of the configuration parsing, a loop passes over each
proxy's list and resolves all the args in sequence. And this way there is
all necessary information to report verbose errors.
The first immediate benefit is that for the first time we got very precise
location of issues (arg number in a keyword in its context, ...). Second,
in order to do this we had to parse log-format and unique-id-format a bit
earlier, so that was a great opportunity for doing so when the directives
are encountered (unless it's a default section). This way, the recorded
line numbers for these args are the ones of the place where the log format
is declared, not the end of the file.
Userlists report slightly more information now. They're the only remaining
ones in the ACL resolving function.
2013-04-02 14:34:32 +00:00
|
|
|
char **err_msg, const char **err_ptr, int *err_arg,
|
|
|
|
struct arg_list *al);
|
2012-04-19 13:24:50 +00:00
|
|
|
|
|
|
|
#endif /* _PROTO_ARG_H */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* c-indent-level: 8
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* End:
|
|
|
|
*/
|