conf: factor out list of regex into separate header

this allows to include the regexes in another file and apply
transformations and experiments.
This commit is contained in:
rofl0r 2020-10-09 00:22:14 +01:00
parent e20aa221ff
commit f1f3994d09
2 changed files with 94 additions and 92 deletions

View File

@ -40,35 +40,6 @@
#include "basicauth.h"
#include "conf-tokens.h"
/*
* The configuration directives are defined in the structure below. Each
* directive requires a regular expression to match against, and a
* function to call when the regex is matched.
*
* Below are defined certain constant regular expression strings that
* can (and likely should) be used when building the regex for the
* given directive.
*/
#define DIGIT "[0-9]"
#define SPACE "[ \t]"
#define WS SPACE "+"
#define STR "\"([^\"]+)\""
#define BOOL "(yes|on|no|off)"
#define INT "(()" DIGIT "+)"
#define ALNUM "([-a-z0-9._]+)"
#define USERNAME "([^:]*)"
#define PASSWORD "([^@]*)"
#define IP "((([0-9]{1,3})\\.){3}[0-9]{1,3})"
#define IPMASK "(" IP "(/" DIGIT "+)?)"
#define IPV6 "(" \
"(([0-9a-f:]{2,39}))|" \
"(([0-9a-f:]{0,29}:" IP "))" \
")"
#define IPV6MASK "(" IPV6 "(/" DIGIT "+)?)"
#define BEGIN "^" SPACE "*"
#define END SPACE "*$"
/*
* Limit the maximum number of substring matches to a reasonably high
* number. Given the usual structure of the configuration file, sixteen
@ -184,69 +155,7 @@ struct {
CONFFILE_HANDLER handler;
regex_t *cre;
} directives[] = {
/* string arguments */
STDCONF (logfile, STR, handle_logfile),
STDCONF (pidfile, STR, handle_pidfile),
STDCONF (anonymous, STR, handle_anonymous),
STDCONF (viaproxyname, STR, handle_viaproxyname),
STDCONF (defaulterrorfile, STR, handle_defaulterrorfile),
STDCONF (statfile, STR, handle_statfile),
STDCONF (stathost, STR, handle_stathost),
STDCONF (xtinyproxy, BOOL, handle_xtinyproxy),
/* boolean arguments */
STDCONF (syslog, BOOL, handle_syslog),
STDCONF (bindsame, BOOL, handle_bindsame),
STDCONF (disableviaheader, BOOL, handle_disableviaheader),
/* integer arguments */
STDCONF (port, INT, handle_port),
STDCONF (maxclients, INT, handle_maxclients),
STDCONF (maxspareservers, INT, handle_obsolete),
STDCONF (minspareservers, INT, handle_obsolete),
STDCONF (startservers, INT, handle_obsolete),
STDCONF (maxrequestsperchild, INT, handle_obsolete),
STDCONF (timeout, INT, handle_timeout),
STDCONF (connectport, INT, handle_connectport),
/* alphanumeric arguments */
STDCONF (user, ALNUM, handle_user),
STDCONF (group, ALNUM, handle_group),
/* ip arguments */
STDCONF (listen, "(" IP "|" IPV6 ")", handle_listen),
STDCONF (allow, "(" "(" IPMASK "|" IPV6MASK ")" "|" ALNUM ")",
handle_allow),
STDCONF (deny, "(" "(" IPMASK "|" IPV6MASK ")" "|" ALNUM ")",
handle_deny),
STDCONF (bind, "(" IP "|" IPV6 ")", handle_bind),
/* other */
STDCONF (basicauth, ALNUM WS ALNUM, handle_basicauth),
STDCONF (errorfile, INT WS STR, handle_errorfile),
STDCONF (addheader, STR WS STR, handle_addheader),
#ifdef FILTER_ENABLE
/* filtering */
STDCONF (filter, STR, handle_filter),
STDCONF (filterurls, BOOL, handle_filterurls),
STDCONF (filterextended, BOOL, handle_filterextended),
STDCONF (filterdefaultdeny, BOOL, handle_filterdefaultdeny),
STDCONF (filtercasesensitive, BOOL, handle_filtercasesensitive),
#endif
#ifdef REVERSE_SUPPORT
/* Reverse proxy arguments */
STDCONF (reversebaseurl, STR, handle_reversebaseurl),
STDCONF (reverseonly, BOOL, handle_reverseonly),
STDCONF (reversemagic, BOOL, handle_reversemagic),
STDCONF (reversepath, STR "(" WS STR ")?", handle_reversepath),
#endif
#ifdef UPSTREAM_SUPPORT
STDCONF (upstream,
"(" "(none)" WS STR ")|" \
"(" "(http|socks4|socks5)" WS \
"(" USERNAME /*username*/ ":" PASSWORD /*password*/ "@" ")?"
"(" IP "|" ALNUM ")"
":" INT "(" WS STR ")?" ")", handle_upstream),
#endif
/* loglevel */
STDCONF (loglevel, "(critical|error|warning|notice|connect|info)",
handle_loglevel)
#include "conf_regex.h"
};
const unsigned int ndirectives = sizeof (directives) / sizeof (directives[0]);

93
src/conf_regex.h Normal file
View File

@ -0,0 +1,93 @@
/*
* The configuration directives are defined in the structure below. Each
* directive requires a regular expression to match against, and a
* function to call when the regex is matched.
*
* Below are defined certain constant regular expression strings that
* can (and likely should) be used when building the regex for the
* given directive.
*/
#define DIGIT "[0-9]"
#define SPACE "[ \t]"
#define WS SPACE "+"
#define STR "\"([^\"]+)\""
#define BOOL "(yes|on|no|off)"
#define INT "(()" DIGIT "+)"
#define ALNUM "([-a-z0-9._]+)"
#define USERNAME "([^:]*)"
#define PASSWORD "([^@]*)"
#define IP "((([0-9]{1,3})\\.){3}[0-9]{1,3})"
#define IPMASK "(" IP "(/" DIGIT "+)?)"
#define IPV6 "(" \
"(([0-9a-f:]{2,39}))|" \
"(([0-9a-f:]{0,29}:" IP "))" \
")"
#define IPV6MASK "(" IPV6 "(/" DIGIT "+)?)"
#define BEGIN "^" SPACE "*"
#define END SPACE "*$"
STDCONF (logfile, STR, handle_logfile),
STDCONF (pidfile, STR, handle_pidfile),
STDCONF (anonymous, STR, handle_anonymous),
STDCONF (viaproxyname, STR, handle_viaproxyname),
STDCONF (defaulterrorfile, STR, handle_defaulterrorfile),
STDCONF (statfile, STR, handle_statfile),
STDCONF (stathost, STR, handle_stathost),
STDCONF (xtinyproxy, BOOL, handle_xtinyproxy),
/* boolean arguments */
STDCONF (syslog, BOOL, handle_syslog),
STDCONF (bindsame, BOOL, handle_bindsame),
STDCONF (disableviaheader, BOOL, handle_disableviaheader),
/* integer arguments */
STDCONF (port, INT, handle_port),
STDCONF (maxclients, INT, handle_maxclients),
STDCONF (maxspareservers, INT, handle_obsolete),
STDCONF (minspareservers, INT, handle_obsolete),
STDCONF (startservers, INT, handle_obsolete),
STDCONF (maxrequestsperchild, INT, handle_obsolete),
STDCONF (timeout, INT, handle_timeout),
STDCONF (connectport, INT, handle_connectport),
/* alphanumeric arguments */
STDCONF (user, ALNUM, handle_user),
STDCONF (group, ALNUM, handle_group),
/* ip arguments */
STDCONF (listen, "(" IP "|" IPV6 ")", handle_listen),
STDCONF (allow, "(" "(" IPMASK "|" IPV6MASK ")" "|" ALNUM ")",
handle_allow),
STDCONF (deny, "(" "(" IPMASK "|" IPV6MASK ")" "|" ALNUM ")",
handle_deny),
STDCONF (bind, "(" IP "|" IPV6 ")", handle_bind),
/* other */
STDCONF (basicauth, ALNUM WS ALNUM, handle_basicauth),
STDCONF (errorfile, INT WS STR, handle_errorfile),
STDCONF (addheader, STR WS STR, handle_addheader),
#ifdef FILTER_ENABLE
/* filtering */
STDCONF (filter, STR, handle_filter),
STDCONF (filterurls, BOOL, handle_filterurls),
STDCONF (filterextended, BOOL, handle_filterextended),
STDCONF (filterdefaultdeny, BOOL, handle_filterdefaultdeny),
STDCONF (filtercasesensitive, BOOL, handle_filtercasesensitive),
#endif
#ifdef REVERSE_SUPPORT
/* Reverse proxy arguments */
STDCONF (reversebaseurl, STR, handle_reversebaseurl),
STDCONF (reverseonly, BOOL, handle_reverseonly),
STDCONF (reversemagic, BOOL, handle_reversemagic),
STDCONF (reversepath, STR "(" WS STR ")?", handle_reversepath),
#endif
#ifdef UPSTREAM_SUPPORT
STDCONF (upstream,
"(" "(none)" WS STR ")|" \
"(" "(http|socks4|socks5)" WS \
"(" USERNAME /*username*/ ":" PASSWORD /*password*/ "@" ")?"
"(" IP "|" ALNUM ")"
":" INT "(" WS STR ")?" ")", handle_upstream),
#endif
/* loglevel */
STDCONF (loglevel, "(critical|error|warning|notice|connect|info)",
handle_loglevel)