Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc87de3482 | ||
|
|
11a4f6c5cf | ||
|
|
64badd6b37 | ||
|
|
48860bbe26 | ||
|
|
c4231e58bf | ||
|
|
38934921c4 | ||
|
|
4147e917d6 | ||
|
|
adad565c03 | ||
|
|
db5c0e99b4 | ||
|
|
8ebbd50cb2 | ||
|
|
732bdd0f56 | ||
|
|
3bb14e0440 | ||
|
|
2b49ef0e0f | ||
|
|
f7c616d2b9 | ||
|
|
cc0a7eb9a2 |
No files matched your search
+7
-10
@@ -210,19 +210,16 @@ AH_TEMPLATE([HAVE_GPERF],
|
||||
[Whether you have gperf installed for faster config parsing.])
|
||||
|
||||
if test "x$GPERF" != "x" -a "x$GPERF" != "xno" ; then
|
||||
AS_ECHO_N(["checking whether gperf is recent enough... "])
|
||||
if "$GPERF" < src/conf-tokens.gperf >/dev/null 2>&1 ; then
|
||||
AS_ECHO("yes")
|
||||
AC_DEFINE(HAVE_GPERF)
|
||||
else
|
||||
AM_CONDITIONAL(HAVE_GPERF, false)
|
||||
AS_ECHO("no")
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_PATH_PROG(RAGEL, ragel, no)
|
||||
AM_CONDITIONAL(HAVE_RAGEL, test "x$RAGEL" != "x" -a "x$RAGEL" != "xno")
|
||||
AH_TEMPLATE([HAVE_RAGEL],
|
||||
[Whether you have ragel installed for faster config parsing.])
|
||||
|
||||
if test "x$RAGEL" != "x" -a "x$RAGEL" != "xno" ; then
|
||||
AC_DEFINE(HAVE_RAGEL)
|
||||
fi
|
||||
|
||||
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
src/Makefile
|
||||
|
||||
@@ -58,6 +58,8 @@ only on one specific address.
|
||||
|
||||
This allows you to specify which address Tinyproxy will bind
|
||||
to for outgoing connections to web servers or upstream proxies.
|
||||
This parameter may be specified multiple times, then Tinyproxy
|
||||
will try all the specified addresses in order.
|
||||
|
||||
=item B<BindSame>
|
||||
|
||||
|
||||
+1
-12
@@ -60,22 +60,11 @@ EXTRA_tinyproxy_SOURCES = filter.c filter.h \
|
||||
tinyproxy_DEPENDENCIES = @ADDITIONAL_OBJECTS@
|
||||
tinyproxy_LDADD = @ADDITIONAL_OBJECTS@ -lpthread
|
||||
|
||||
CLEANFILES =
|
||||
|
||||
if HAVE_GPERF
|
||||
conf-tokens.c: conf-tokens-gperf.inc
|
||||
conf-tokens-gperf.inc: conf-tokens.gperf
|
||||
$(GPERF) $< > $@
|
||||
endif
|
||||
|
||||
if HAVE_RAGEL
|
||||
conf.c: conf_regex.inc
|
||||
conf_regex.inc: conf_regex.rl
|
||||
$(RAGEL) $(RAGEL_FLAGS) -o $@ $<
|
||||
|
||||
CLEANFILES += conf_regex.inc
|
||||
endif
|
||||
|
||||
|
||||
EXTRA_DIST = conf-tokens.gperf conf_regex.rl
|
||||
EXTRA_DIST = conf-tokens.gperf
|
||||
|
||||
+175
-90
@@ -40,12 +40,41 @@
|
||||
#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
|
||||
* substring matches should be plenty.
|
||||
*/
|
||||
#define RE_MAX_MATCHES 16
|
||||
#define RE_MAX_MATCHES 24
|
||||
|
||||
#define CP_WARN(FMT, ...) \
|
||||
log_message (LOG_WARNING, "line %lu: " FMT, lineno, __VA_ARGS__)
|
||||
@@ -142,14 +171,7 @@ static void config_free_regex (void);
|
||||
* do not follow the pattern above. This macro is for convenience
|
||||
* only.
|
||||
*/
|
||||
#ifdef HAVE_RAGEL
|
||||
#define RE2R_EXPORT static
|
||||
#include "conf_regex.inc"
|
||||
typedef int (*matchfunc)(const char*, const char*, size_t, regmatch_t[]);
|
||||
#define STDCONF(d, re, func) [CD_ ## d] = { func, re2r_match_ ## d }
|
||||
#else
|
||||
#define STDCONF(d, re, func) [CD_ ## d] = { func, BEGIN re END, NULL }
|
||||
#endif
|
||||
#define STDCONF(d, re, func) [CD_ ## d] = { BEGIN "()" WS re END, func, NULL }
|
||||
|
||||
/*
|
||||
* Holds the regular expression used to match the configuration directive,
|
||||
@@ -158,15 +180,73 @@ typedef int (*matchfunc)(const char*, const char*, size_t, regmatch_t[]);
|
||||
* to be compiled one.
|
||||
*/
|
||||
struct {
|
||||
CONFFILE_HANDLER handler;
|
||||
#ifndef HAVE_RAGEL
|
||||
const char *re;
|
||||
CONFFILE_HANDLER handler;
|
||||
regex_t *cre;
|
||||
#else
|
||||
matchfunc mf;
|
||||
#endif
|
||||
} directives[] = {
|
||||
#include "conf_regex.h"
|
||||
/* 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)
|
||||
};
|
||||
|
||||
const unsigned int ndirectives = sizeof (directives) / sizeof (directives[0]);
|
||||
@@ -211,6 +291,7 @@ void free_config (struct config_s *conf)
|
||||
safefree (conf->group);
|
||||
stringlist_free(conf->basicauth_list);
|
||||
stringlist_free(conf->listen_addrs);
|
||||
stringlist_free(conf->bind_addrs);
|
||||
#ifdef FILTER_ENABLE
|
||||
safefree (conf->filter);
|
||||
#endif /* FILTER_ENABLE */
|
||||
@@ -222,7 +303,6 @@ void free_config (struct config_s *conf)
|
||||
free_upstream_list (conf->upstream_list);
|
||||
#endif /* UPSTREAM_SUPPORT */
|
||||
safefree (conf->pidpath);
|
||||
safefree (conf->bind_address);
|
||||
safefree (conf->via_proxy_name);
|
||||
if (conf->errorpages) {
|
||||
it = 0;
|
||||
@@ -259,26 +339,23 @@ config_init (void)
|
||||
{
|
||||
unsigned int i, r;
|
||||
|
||||
(void) r;
|
||||
|
||||
for (i = 0; i != ndirectives; ++i) {
|
||||
assert (!directives[i].cre);
|
||||
|
||||
if (!directives[i].handler) {
|
||||
directives[i].handler = handle_disabled_feature;
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifndef HAVE_RAGEL
|
||||
directives[i].cre = (regex_t *) safemalloc (sizeof (regex_t));
|
||||
if (!directives[i].cre)
|
||||
return -1;
|
||||
|
||||
r = regcomp (directives[i].cre,
|
||||
directives[i].re,
|
||||
REG_EXTENDED | REG_NEWLINE);
|
||||
REG_EXTENDED | REG_ICASE | REG_NEWLINE);
|
||||
if (r)
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
||||
atexit (config_free_regex);
|
||||
@@ -293,7 +370,6 @@ config_init (void)
|
||||
static void
|
||||
config_free_regex (void)
|
||||
{
|
||||
#ifndef HAVE_RAGEL
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < ndirectives; i++) {
|
||||
@@ -303,7 +379,6 @@ config_free_regex (void)
|
||||
directives[i].cre = NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -314,25 +389,18 @@ config_free_regex (void)
|
||||
* Returns 0 if a match was found and successfully processed; otherwise,
|
||||
* a negative number is returned.
|
||||
*/
|
||||
static int check_match (struct config_s *conf,
|
||||
const char *line, const char* lineend,
|
||||
static int check_match (struct config_s *conf, const char *line,
|
||||
unsigned long lineno, enum config_directive cd)
|
||||
{
|
||||
regmatch_t match[RE_MAX_MATCHES];
|
||||
unsigned int i = cd;
|
||||
|
||||
#ifndef HAVE_RAGEL
|
||||
(void) lineend;
|
||||
if (!directives[i].cre)
|
||||
return (*directives[i].handler) (conf, line, lineno, match);
|
||||
|
||||
if (!regexec
|
||||
(directives[i].cre, line, RE_MAX_MATCHES, match, 0))
|
||||
return (*directives[i].handler) (conf, line, lineno, match);
|
||||
#else
|
||||
if (!directives[i].mf(line, lineend, RE_MAX_MATCHES, match))
|
||||
return (*directives[i].handler) (conf, line, lineno, match);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -341,7 +409,7 @@ static int check_match (struct config_s *conf,
|
||||
*/
|
||||
static int config_parse (struct config_s *conf, FILE * f)
|
||||
{
|
||||
char buffer[LINE_MAX], *p, *q;
|
||||
char buffer[LINE_MAX], *p, *q, c;
|
||||
const struct config_directive_entry *e;
|
||||
unsigned long lineno = 1;
|
||||
|
||||
@@ -352,14 +420,11 @@ static int config_parse (struct config_s *conf, FILE * f)
|
||||
if(!*p) continue;
|
||||
q = p;
|
||||
while(!isspace(*q))q++;
|
||||
c = *q;
|
||||
*q = 0;
|
||||
e = config_directive_find(p, strlen(p));
|
||||
++q;
|
||||
while(isspace(*q))++q;
|
||||
p = q;
|
||||
while(*p && *p != '\n') ++p;
|
||||
while(isspace(*p)) *(p--) = 0;
|
||||
if (!e || e->value == CD_NIL || check_match (conf, q, ++p, lineno, e->value)) {
|
||||
*q = c;
|
||||
if (!e || e->value == CD_NIL || check_match (conf, q, lineno, e->value)) {
|
||||
fprintf (stderr, "ERROR: Syntax error on line %lu\n", lineno);
|
||||
return 1;
|
||||
}
|
||||
@@ -560,21 +625,19 @@ set_int_arg (unsigned int *var, const char *line, regmatch_t * match)
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#define MGROUP1 -1
|
||||
|
||||
static HANDLE_FUNC (handle_logfile)
|
||||
{
|
||||
return set_string_arg (&conf->logf_name, line, &match[MGROUP1+2]);
|
||||
return set_string_arg (&conf->logf_name, line, &match[2]);
|
||||
}
|
||||
|
||||
static HANDLE_FUNC (handle_pidfile)
|
||||
{
|
||||
return set_string_arg (&conf->pidpath, line, &match[MGROUP1+2]);
|
||||
return set_string_arg (&conf->pidpath, line, &match[2]);
|
||||
}
|
||||
|
||||
static HANDLE_FUNC (handle_anonymous)
|
||||
{
|
||||
char *arg = get_string_arg (line, &match[MGROUP1+2]);
|
||||
char *arg = get_string_arg (line, &match[2]);
|
||||
|
||||
if (!arg)
|
||||
return -1;
|
||||
@@ -590,7 +653,7 @@ static HANDLE_FUNC (handle_anonymous)
|
||||
|
||||
static HANDLE_FUNC (handle_viaproxyname)
|
||||
{
|
||||
int r = set_string_arg (&conf->via_proxy_name, line, &match[MGROUP1+2]);
|
||||
int r = set_string_arg (&conf->via_proxy_name, line, &match[2]);
|
||||
|
||||
if (r)
|
||||
return r;
|
||||
@@ -602,7 +665,7 @@ static HANDLE_FUNC (handle_viaproxyname)
|
||||
|
||||
static HANDLE_FUNC (handle_disableviaheader)
|
||||
{
|
||||
int r = set_bool_arg (&conf->disable_viaheader, line, &match[MGROUP1+2]);
|
||||
int r = set_bool_arg (&conf->disable_viaheader, line, &match[2]);
|
||||
|
||||
if (r) {
|
||||
return r;
|
||||
@@ -615,17 +678,17 @@ static HANDLE_FUNC (handle_disableviaheader)
|
||||
|
||||
static HANDLE_FUNC (handle_defaulterrorfile)
|
||||
{
|
||||
return set_string_arg (&conf->errorpage_undef, line, &match[MGROUP1+2]);
|
||||
return set_string_arg (&conf->errorpage_undef, line, &match[2]);
|
||||
}
|
||||
|
||||
static HANDLE_FUNC (handle_statfile)
|
||||
{
|
||||
return set_string_arg (&conf->statpage, line, &match[MGROUP1+2]);
|
||||
return set_string_arg (&conf->statpage, line, &match[2]);
|
||||
}
|
||||
|
||||
static HANDLE_FUNC (handle_stathost)
|
||||
{
|
||||
int r = set_string_arg (&conf->stathost, line, &match[MGROUP1+2]);
|
||||
int r = set_string_arg (&conf->stathost, line, &match[2]);
|
||||
|
||||
if (r)
|
||||
return r;
|
||||
@@ -636,7 +699,7 @@ static HANDLE_FUNC (handle_stathost)
|
||||
static HANDLE_FUNC (handle_xtinyproxy)
|
||||
{
|
||||
#ifdef XTINYPROXY_ENABLE
|
||||
return set_bool_arg (&conf->add_xtinyproxy, line, &match[MGROUP1+2]);
|
||||
return set_bool_arg (&conf->add_xtinyproxy, line, &match[2]);
|
||||
#else
|
||||
fprintf (stderr,
|
||||
"XTinyproxy NOT Enabled! Recompile with --enable-xtinyproxy\n");
|
||||
@@ -646,12 +709,12 @@ static HANDLE_FUNC (handle_xtinyproxy)
|
||||
|
||||
static HANDLE_FUNC (handle_syslog)
|
||||
{
|
||||
return set_bool_arg (&conf->syslog, line, &match[MGROUP1+2]);
|
||||
return set_bool_arg (&conf->syslog, line, &match[2]);
|
||||
}
|
||||
|
||||
static HANDLE_FUNC (handle_bindsame)
|
||||
{
|
||||
int r = set_bool_arg (&conf->bindsame, line, &match[MGROUP1+2]);
|
||||
int r = set_bool_arg (&conf->bindsame, line, &match[2]);
|
||||
|
||||
if (r)
|
||||
return r;
|
||||
@@ -661,7 +724,7 @@ static HANDLE_FUNC (handle_bindsame)
|
||||
|
||||
static HANDLE_FUNC (handle_port)
|
||||
{
|
||||
set_int_arg (&conf->port, line, &match[MGROUP1+2]);
|
||||
set_int_arg (&conf->port, line, &match[2]);
|
||||
|
||||
if (conf->port > 65535) {
|
||||
fprintf (stderr, "Bad port number (%d) supplied for Port.\n",
|
||||
@@ -674,7 +737,7 @@ static HANDLE_FUNC (handle_port)
|
||||
|
||||
static HANDLE_FUNC (handle_maxclients)
|
||||
{
|
||||
set_int_arg (&conf->maxclients, line, &match[MGROUP1+2]);
|
||||
set_int_arg (&conf->maxclients, line, &match[2]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -687,24 +750,24 @@ static HANDLE_FUNC (handle_obsolete)
|
||||
|
||||
static HANDLE_FUNC (handle_timeout)
|
||||
{
|
||||
return set_int_arg (&conf->idletimeout, line, &match[MGROUP1+2]);
|
||||
return set_int_arg (&conf->idletimeout, line, &match[2]);
|
||||
}
|
||||
|
||||
static HANDLE_FUNC (handle_connectport)
|
||||
{
|
||||
add_connect_port_allowed (get_long_arg (line, &match[MGROUP1+2]),
|
||||
add_connect_port_allowed (get_long_arg (line, &match[2]),
|
||||
&conf->connect_ports);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HANDLE_FUNC (handle_user)
|
||||
{
|
||||
return set_string_arg (&conf->user, line, &match[MGROUP1+2]);
|
||||
return set_string_arg (&conf->user, line, &match[2]);
|
||||
}
|
||||
|
||||
static HANDLE_FUNC (handle_group)
|
||||
{
|
||||
return set_string_arg (&conf->group, line, &match[MGROUP1+2]);
|
||||
return set_string_arg (&conf->group, line, &match[2]);
|
||||
}
|
||||
|
||||
static void warn_invalid_address(char *arg, unsigned long lineno) {
|
||||
@@ -713,7 +776,7 @@ static void warn_invalid_address(char *arg, unsigned long lineno) {
|
||||
|
||||
static HANDLE_FUNC (handle_allow)
|
||||
{
|
||||
char *arg = get_string_arg (line, &match[MGROUP1+2]);
|
||||
char *arg = get_string_arg (line, &match[2]);
|
||||
|
||||
if(insert_acl (arg, ACL_ALLOW, &conf->access_list) < 0)
|
||||
warn_invalid_address (arg, lineno);
|
||||
@@ -723,7 +786,7 @@ static HANDLE_FUNC (handle_allow)
|
||||
|
||||
static HANDLE_FUNC (handle_deny)
|
||||
{
|
||||
char *arg = get_string_arg (line, &match[MGROUP1+2]);
|
||||
char *arg = get_string_arg (line, &match[2]);
|
||||
|
||||
if(insert_acl (arg, ACL_DENY, &conf->access_list) < 0)
|
||||
warn_invalid_address (arg, lineno);
|
||||
@@ -733,18 +796,33 @@ static HANDLE_FUNC (handle_deny)
|
||||
|
||||
static HANDLE_FUNC (handle_bind)
|
||||
{
|
||||
int r = set_string_arg (&conf->bind_address, line, &match[MGROUP1+2]);
|
||||
char *arg = get_string_arg (line, &match[2]);
|
||||
|
||||
if (arg == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (conf->bind_addrs == NULL) {
|
||||
conf->bind_addrs = sblist_new(sizeof(char*), 16);
|
||||
if (conf->bind_addrs == NULL) {
|
||||
CP_WARN ("Could not create a list "
|
||||
"of bind addresses.", "");
|
||||
safefree(arg);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
sblist_add (conf->bind_addrs, &arg);
|
||||
|
||||
if (r)
|
||||
return r;
|
||||
log_message (LOG_INFO,
|
||||
"Outgoing connections bound to IP %s", conf->bind_address);
|
||||
"Added bind address [%s] for outgoing connections.", arg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HANDLE_FUNC (handle_listen)
|
||||
{
|
||||
char *arg = get_string_arg (line, &match[MGROUP1+2]);
|
||||
char *arg = get_string_arg (line, &match[2]);
|
||||
|
||||
if (arg == NULL) {
|
||||
return -1;
|
||||
@@ -769,8 +847,15 @@ static HANDLE_FUNC (handle_listen)
|
||||
|
||||
static HANDLE_FUNC (handle_errorfile)
|
||||
{
|
||||
unsigned long int err = get_long_arg (line, &match[MGROUP1+2]);
|
||||
char *page = get_string_arg (line, &match[MGROUP1+3]);
|
||||
/*
|
||||
* Because an integer is defined as ((0x)?[[:digit:]]+) _two_
|
||||
* match places are used. match[2] matches the full digit
|
||||
* string, while match[3] matches only the "0x" part if
|
||||
* present. This is why the "string" is located at
|
||||
* match[4] (rather than the more intuitive match[3].
|
||||
*/
|
||||
unsigned long int err = get_long_arg (line, &match[2]);
|
||||
char *page = get_string_arg (line, &match[4]);
|
||||
|
||||
if(add_new_errorpage (conf, page, err) < 0) {
|
||||
CP_WARN ("add_new_errorpage() failed: '%s'", page);
|
||||
@@ -781,8 +866,8 @@ static HANDLE_FUNC (handle_errorfile)
|
||||
|
||||
static HANDLE_FUNC (handle_addheader)
|
||||
{
|
||||
char *name = get_string_arg (line, &match[MGROUP1+2]);
|
||||
char *value = get_string_arg (line, &match[MGROUP1+3]);
|
||||
char *name = get_string_arg (line, &match[2]);
|
||||
char *value = get_string_arg (line, &match[3]);
|
||||
http_header_t header;
|
||||
|
||||
if (!conf->add_headers) {
|
||||
@@ -823,7 +908,7 @@ static HANDLE_FUNC (handle_loglevel)
|
||||
sizeof (log_levels) / sizeof (log_levels[0]);
|
||||
unsigned int i;
|
||||
|
||||
char *arg = get_string_arg (line, &match[MGROUP1+2]);
|
||||
char *arg = get_string_arg (line, &match[2]);
|
||||
|
||||
for (i = 0; i != nlevels; ++i) {
|
||||
if (!strcasecmp (arg, log_levels[i].string)) {
|
||||
@@ -840,10 +925,10 @@ static HANDLE_FUNC (handle_loglevel)
|
||||
static HANDLE_FUNC (handle_basicauth)
|
||||
{
|
||||
char *user, *pass;
|
||||
user = get_string_arg(line, &match[MGROUP1+2]);
|
||||
user = get_string_arg(line, &match[2]);
|
||||
if (!user)
|
||||
return -1;
|
||||
pass = get_string_arg(line, &match[MGROUP1+3]);
|
||||
pass = get_string_arg(line, &match[3]);
|
||||
if (!pass) {
|
||||
safefree (user);
|
||||
return -1;
|
||||
@@ -861,48 +946,48 @@ static HANDLE_FUNC (handle_basicauth)
|
||||
#ifdef FILTER_ENABLE
|
||||
static HANDLE_FUNC (handle_filter)
|
||||
{
|
||||
return set_string_arg (&conf->filter, line, &match[MGROUP1+2]);
|
||||
return set_string_arg (&conf->filter, line, &match[2]);
|
||||
}
|
||||
|
||||
static HANDLE_FUNC (handle_filterurls)
|
||||
{
|
||||
return set_bool_arg (&conf->filter_url, line, &match[MGROUP1+2]);
|
||||
return set_bool_arg (&conf->filter_url, line, &match[2]);
|
||||
}
|
||||
|
||||
static HANDLE_FUNC (handle_filterextended)
|
||||
{
|
||||
return set_bool_arg (&conf->filter_extended, line, &match[MGROUP1+2]);
|
||||
return set_bool_arg (&conf->filter_extended, line, &match[2]);
|
||||
}
|
||||
|
||||
static HANDLE_FUNC (handle_filterdefaultdeny)
|
||||
{
|
||||
assert (match[MGROUP1+2].rm_so != -1);
|
||||
assert (match[2].rm_so != -1);
|
||||
|
||||
if (get_bool_arg (line, &match[MGROUP1+2]))
|
||||
if (get_bool_arg (line, &match[2]))
|
||||
filter_set_default_policy (FILTER_DEFAULT_DENY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HANDLE_FUNC (handle_filtercasesensitive)
|
||||
{
|
||||
return set_bool_arg (&conf->filter_casesensitive, line, &match[MGROUP1+2]);
|
||||
return set_bool_arg (&conf->filter_casesensitive, line, &match[2]);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef REVERSE_SUPPORT
|
||||
static HANDLE_FUNC (handle_reverseonly)
|
||||
{
|
||||
return set_bool_arg (&conf->reverseonly, line, &match[MGROUP1+2]);
|
||||
return set_bool_arg (&conf->reverseonly, line, &match[2]);
|
||||
}
|
||||
|
||||
static HANDLE_FUNC (handle_reversemagic)
|
||||
{
|
||||
return set_bool_arg (&conf->reversemagic, line, &match[MGROUP1+2]);
|
||||
return set_bool_arg (&conf->reversemagic, line, &match[2]);
|
||||
}
|
||||
|
||||
static HANDLE_FUNC (handle_reversebaseurl)
|
||||
{
|
||||
return set_string_arg (&conf->reversebaseurl, line, &match[MGROUP1+2]);
|
||||
return set_string_arg (&conf->reversebaseurl, line, &match[2]);
|
||||
}
|
||||
|
||||
static HANDLE_FUNC (handle_reversepath)
|
||||
@@ -912,12 +997,12 @@ static HANDLE_FUNC (handle_reversepath)
|
||||
*/
|
||||
char *arg1, *arg2;
|
||||
|
||||
arg1 = get_string_arg (line, &match[MGROUP1+2]);
|
||||
arg1 = get_string_arg (line, &match[2]);
|
||||
if (!arg1)
|
||||
return -1;
|
||||
|
||||
if (match[MGROUP1+4].rm_so != -1) {
|
||||
arg2 = get_string_arg (line, &match[MGROUP1+4]);
|
||||
if (match[4].rm_so != -1) {
|
||||
arg2 = get_string_arg (line, &match[4]);
|
||||
if (!arg2) {
|
||||
safefree (arg1);
|
||||
return -1;
|
||||
@@ -958,12 +1043,12 @@ static HANDLE_FUNC (handle_upstream)
|
||||
enum proxy_type pt;
|
||||
enum upstream_build_error ube;
|
||||
|
||||
if (match[MGROUP1+3].rm_so != -1) {
|
||||
tmp = get_string_arg (line, &match[MGROUP1+3]);
|
||||
if (match[3].rm_so != -1) {
|
||||
tmp = get_string_arg (line, &match[3]);
|
||||
if(!strcmp(tmp, "none")) {
|
||||
safefree(tmp);
|
||||
if (match[MGROUP1+4].rm_so == -1) return -1;
|
||||
domain = get_string_arg (line, &match[MGROUP1+4]);
|
||||
if (match[4].rm_so == -1) return -1;
|
||||
domain = get_string_arg (line, &match[4]);
|
||||
if (!domain)
|
||||
return -1;
|
||||
ube = upstream_add (NULL, 0, domain, 0, 0, PT_NONE, &conf->upstream_list);
|
||||
@@ -972,7 +1057,7 @@ static HANDLE_FUNC (handle_upstream)
|
||||
}
|
||||
}
|
||||
|
||||
mi = MGROUP1+6;
|
||||
mi = 6;
|
||||
|
||||
tmp = get_string_arg (line, &match[mi]);
|
||||
pt = pt_from_string(tmp);
|
||||
@@ -990,10 +1075,10 @@ static HANDLE_FUNC (handle_upstream)
|
||||
ip = get_string_arg (line, &match[mi]);
|
||||
if (!ip)
|
||||
return -1;
|
||||
mi += 3;
|
||||
mi += 5;
|
||||
|
||||
port = (int) get_long_arg (line, &match[mi]);
|
||||
mi += 2;
|
||||
mi += 3;
|
||||
|
||||
if (match[mi].rm_so != -1)
|
||||
domain = get_string_arg (line, &match[mi]);
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ struct config_s {
|
||||
#endif /* UPSTREAM_SUPPORT */
|
||||
char *pidpath;
|
||||
unsigned int idletimeout;
|
||||
char *bind_address;
|
||||
sblist *bind_addrs;
|
||||
unsigned int bindsame;
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* 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 "([Yy][Ee][Ss]|[Oo][Nn]|[Nn][Oo]|[Oo][Ff][Ff])"
|
||||
#define INT "(" DIGIT "+)"
|
||||
#define ALNUM "([-A-Za-z0-9._]+)"
|
||||
#define USERNAME "([^:]*)"
|
||||
#define PASSWORD "([^@]*)"
|
||||
#define IP "([0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)"
|
||||
#define IPMASK "(" IP "(/" DIGIT "+)?)"
|
||||
#define IPV6 "(" \
|
||||
"(([0-9a-fA-F:]{2,39}))|" \
|
||||
"(([0-9a-fA-F:]{0,29}:" IP "))" \
|
||||
")"
|
||||
|
||||
#define IPV6MASK "(" IPV6 "(/" DIGIT "+)?)"
|
||||
#define BEGIN "^"
|
||||
#define END "$"
|
||||
|
||||
|
||||
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, "([Cc]ritical|[Ee]rror|[Ww]arning|[Nn]otice|[Cc]onnect|[Ii]nfo)",
|
||||
handle_loglevel)
|
||||
|
||||
@@ -1,512 +0,0 @@
|
||||
/* automatically generated with re2r by rofl0r */
|
||||
%%{
|
||||
machine logfile;
|
||||
action A1 { matches[1].rm_so = p-start; }
|
||||
action E1 { matches[1].rm_eo = p-start; }
|
||||
main := '"'([^"]+) >A1 %E1 '"' ;
|
||||
}%%
|
||||
|
||||
RE2R_EXPORT int re2r_match_logfile(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
size_t i, cs;
|
||||
int par;
|
||||
static const unsigned char parents[] = {[0]=0,[1]=0,};
|
||||
const char *start = p, *eof = pe;
|
||||
%% write data nofinal noerror noentry;
|
||||
for(i=0;i<nmatch;++i) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
%% write init;
|
||||
%% write exec;
|
||||
if(cs < %%{ write first_final; }%% ) return -1;
|
||||
matches[0] = (regmatch_t){.rm_so = 0, .rm_eo = eof-start};
|
||||
for(i=1;i<nmatch;++i) if(matches[i].rm_eo == -1) matches[i].rm_so = -1;
|
||||
else if(matches[i].rm_so == matches[i].rm_eo) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
else { par = i; while((par = parents[par])) if(matches[par].rm_eo == -1) { matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1}; break; }}
|
||||
return 0;
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_pidfile(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_logfile(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_anonymous(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_logfile(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_viaproxyname(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_logfile(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_defaulterrorfile(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_logfile(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_statfile(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_logfile(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_stathost(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_logfile(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
%%{
|
||||
machine xtinyproxy;
|
||||
action A1 { matches[1].rm_so = p-start; }
|
||||
action E1 { matches[1].rm_eo = p-start; }
|
||||
main := ([Yy][Ee][Ss]|[Oo][Nn]|[Nn][Oo]|[Oo][Ff][Ff]) >A1 %E1 ;
|
||||
}%%
|
||||
|
||||
RE2R_EXPORT int re2r_match_xtinyproxy(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
size_t i, cs;
|
||||
int par;
|
||||
static const unsigned char parents[] = {[0]=0,[1]=0,};
|
||||
const char *start = p, *eof = pe;
|
||||
%% write data nofinal noerror noentry;
|
||||
for(i=0;i<nmatch;++i) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
%% write init;
|
||||
%% write exec;
|
||||
if(cs < %%{ write first_final; }%% ) return -1;
|
||||
matches[0] = (regmatch_t){.rm_so = 0, .rm_eo = eof-start};
|
||||
for(i=1;i<nmatch;++i) if(matches[i].rm_eo == -1) matches[i].rm_so = -1;
|
||||
else if(matches[i].rm_so == matches[i].rm_eo) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
else { par = i; while((par = parents[par])) if(matches[par].rm_eo == -1) { matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1}; break; }}
|
||||
return 0;
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_syslog(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_xtinyproxy(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_bindsame(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_xtinyproxy(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_disableviaheader(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_xtinyproxy(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
%%{
|
||||
machine port;
|
||||
action A1 { matches[1].rm_so = p-start; }
|
||||
action E1 { matches[1].rm_eo = p-start; }
|
||||
main := ([0-9]+) >A1 %E1 ;
|
||||
}%%
|
||||
|
||||
RE2R_EXPORT int re2r_match_port(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
size_t i, cs;
|
||||
int par;
|
||||
static const unsigned char parents[] = {[0]=0,[1]=0,};
|
||||
const char *start = p, *eof = pe;
|
||||
%% write data nofinal noerror noentry;
|
||||
for(i=0;i<nmatch;++i) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
%% write init;
|
||||
%% write exec;
|
||||
if(cs < %%{ write first_final; }%% ) return -1;
|
||||
matches[0] = (regmatch_t){.rm_so = 0, .rm_eo = eof-start};
|
||||
for(i=1;i<nmatch;++i) if(matches[i].rm_eo == -1) matches[i].rm_so = -1;
|
||||
else if(matches[i].rm_so == matches[i].rm_eo) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
else { par = i; while((par = parents[par])) if(matches[par].rm_eo == -1) { matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1}; break; }}
|
||||
return 0;
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_maxclients(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_port(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_maxspareservers(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_port(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_minspareservers(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_port(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_startservers(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_port(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_maxrequestsperchild(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_port(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_timeout(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_port(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_connectport(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_port(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
%%{
|
||||
machine user;
|
||||
action A1 { matches[1].rm_so = p-start; }
|
||||
action E1 { matches[1].rm_eo = p-start; }
|
||||
main := (('-'|[A-Za-z0-9._])+) >A1 %E1 ;
|
||||
}%%
|
||||
|
||||
RE2R_EXPORT int re2r_match_user(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
size_t i, cs;
|
||||
int par;
|
||||
static const unsigned char parents[] = {[0]=0,[1]=0,};
|
||||
const char *start = p, *eof = pe;
|
||||
%% write data nofinal noerror noentry;
|
||||
for(i=0;i<nmatch;++i) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
%% write init;
|
||||
%% write exec;
|
||||
if(cs < %%{ write first_final; }%% ) return -1;
|
||||
matches[0] = (regmatch_t){.rm_so = 0, .rm_eo = eof-start};
|
||||
for(i=1;i<nmatch;++i) if(matches[i].rm_eo == -1) matches[i].rm_so = -1;
|
||||
else if(matches[i].rm_so == matches[i].rm_eo) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
else { par = i; while((par = parents[par])) if(matches[par].rm_eo == -1) { matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1}; break; }}
|
||||
return 0;
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_group(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_user(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
%%{
|
||||
machine listen;
|
||||
action A1 { matches[1].rm_so = p-start; }
|
||||
action A2 { matches[2].rm_so = p-start; }
|
||||
action A3 { matches[3].rm_so = p-start; }
|
||||
action A4 { matches[4].rm_so = p-start; }
|
||||
action A5 { matches[5].rm_so = p-start; }
|
||||
action A6 { matches[6].rm_so = p-start; }
|
||||
action A7 { matches[7].rm_so = p-start; }
|
||||
action A8 { matches[8].rm_so = p-start; }
|
||||
action E1 { matches[1].rm_eo = p-start; }
|
||||
action E2 { matches[2].rm_eo = p-start; }
|
||||
action E3 { matches[3].rm_eo = p-start; }
|
||||
action E4 { matches[4].rm_eo = p-start; }
|
||||
action E5 { matches[5].rm_eo = p-start; }
|
||||
action E6 { matches[6].rm_eo = p-start; }
|
||||
action E7 { matches[7].rm_eo = p-start; }
|
||||
action E8 { matches[8].rm_eo = p-start; }
|
||||
main := (([0-9]+[.][0-9]+[.][0-9]+[.][0-9]+) >A2 %E2 |((([0-9a-fA-F:]{2,39}) >A5 %E5 ) >A4 %E4 |(([0-9a-fA-F:]{0,29} ":" ([0-9]+[.][0-9]+[.][0-9]+[.][0-9]+) >A8 %E8 ) >A7 %E7 ) >A6 %E6 ) >A3 %E3 ) >A1 %E1 ;
|
||||
}%%
|
||||
|
||||
RE2R_EXPORT int re2r_match_listen(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
size_t i, cs;
|
||||
int par;
|
||||
static const unsigned char parents[] = {[0]=0,[1]=0,[2]=1,[3]=1,[4]=3,[5]=4,[6]=3,[7]=6,[8]=7,};
|
||||
const char *start = p, *eof = pe;
|
||||
%% write data nofinal noerror noentry;
|
||||
for(i=0;i<nmatch;++i) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
%% write init;
|
||||
%% write exec;
|
||||
if(cs < %%{ write first_final; }%% ) return -1;
|
||||
matches[0] = (regmatch_t){.rm_so = 0, .rm_eo = eof-start};
|
||||
for(i=1;i<nmatch;++i) if(matches[i].rm_eo == -1) matches[i].rm_so = -1;
|
||||
else if(matches[i].rm_so == matches[i].rm_eo) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
else { par = i; while((par = parents[par])) if(matches[par].rm_eo == -1) { matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1}; break; }}
|
||||
return 0;
|
||||
}
|
||||
|
||||
%%{
|
||||
machine allow;
|
||||
action A1 { matches[1].rm_so = p-start; }
|
||||
action A2 { matches[2].rm_so = p-start; }
|
||||
action A3 { matches[3].rm_so = p-start; }
|
||||
action A4 { matches[4].rm_so = p-start; }
|
||||
action A5 { matches[5].rm_so = p-start; }
|
||||
action A6 { matches[6].rm_so = p-start; }
|
||||
action A7 { matches[7].rm_so = p-start; }
|
||||
action A8 { matches[8].rm_so = p-start; }
|
||||
action A9 { matches[9].rm_so = p-start; }
|
||||
action A10 { matches[10].rm_so = p-start; }
|
||||
action A11 { matches[11].rm_so = p-start; }
|
||||
action A12 { matches[12].rm_so = p-start; }
|
||||
action A13 { matches[13].rm_so = p-start; }
|
||||
action A14 { matches[14].rm_so = p-start; }
|
||||
action E1 { matches[1].rm_eo = p-start; }
|
||||
action E2 { matches[2].rm_eo = p-start; }
|
||||
action E3 { matches[3].rm_eo = p-start; }
|
||||
action E4 { matches[4].rm_eo = p-start; }
|
||||
action E5 { matches[5].rm_eo = p-start; }
|
||||
action E6 { matches[6].rm_eo = p-start; }
|
||||
action E7 { matches[7].rm_eo = p-start; }
|
||||
action E8 { matches[8].rm_eo = p-start; }
|
||||
action E9 { matches[9].rm_eo = p-start; }
|
||||
action E10 { matches[10].rm_eo = p-start; }
|
||||
action E11 { matches[11].rm_eo = p-start; }
|
||||
action E12 { matches[12].rm_eo = p-start; }
|
||||
action E13 { matches[13].rm_eo = p-start; }
|
||||
action E14 { matches[14].rm_eo = p-start; }
|
||||
main := (((([0-9]+[.][0-9]+[.][0-9]+[.][0-9]+) >A4 %E4 ( "/" [0-9]+)? >A5 %E5 ) >A3 %E3 |(((([0-9a-fA-F:]{2,39}) >A9 %E9 ) >A8 %E8 |(([0-9a-fA-F:]{0,29} ":" ([0-9]+[.][0-9]+[.][0-9]+[.][0-9]+) >A12 %E12 ) >A11 %E11 ) >A10 %E10 ) >A7 %E7 ( "/" [0-9]+)? >A13 %E13 ) >A6 %E6 ) >A2 %E2 |(('-'|[A-Za-z0-9._])+) >A14 %E14 ) >A1 %E1 ;
|
||||
}%%
|
||||
|
||||
RE2R_EXPORT int re2r_match_allow(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
size_t i, cs;
|
||||
int par;
|
||||
static const unsigned char parents[] = {[0]=0,[1]=0,[2]=1,[3]=2,[4]=3,[5]=3,[6]=2,[7]=6,[8]=7,[9]=8,[10]=7,[11]=10,[12]=11,[13]=6,[14]=1,};
|
||||
const char *start = p, *eof = pe;
|
||||
%% write data nofinal noerror noentry;
|
||||
for(i=0;i<nmatch;++i) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
%% write init;
|
||||
%% write exec;
|
||||
if(cs < %%{ write first_final; }%% ) return -1;
|
||||
matches[0] = (regmatch_t){.rm_so = 0, .rm_eo = eof-start};
|
||||
for(i=1;i<nmatch;++i) if(matches[i].rm_eo == -1) matches[i].rm_so = -1;
|
||||
else if(matches[i].rm_so == matches[i].rm_eo) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
else { par = i; while((par = parents[par])) if(matches[par].rm_eo == -1) { matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1}; break; }}
|
||||
return 0;
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_deny(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_allow(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_bind(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_listen(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
%%{
|
||||
machine basicauth;
|
||||
action A1 { matches[1].rm_so = p-start; }
|
||||
action A2 { matches[2].rm_so = p-start; }
|
||||
action E1 { matches[1].rm_eo = p-start; }
|
||||
action E2 { matches[2].rm_eo = p-start; }
|
||||
main := (('-'|[A-Za-z0-9._])+) >A1 %E1 [ \t]+(('-'|[A-Za-z0-9._])+) >A2 %E2 ;
|
||||
}%%
|
||||
|
||||
RE2R_EXPORT int re2r_match_basicauth(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
size_t i, cs;
|
||||
int par;
|
||||
static const unsigned char parents[] = {[0]=0,[1]=0,[2]=0,};
|
||||
const char *start = p, *eof = pe;
|
||||
%% write data nofinal noerror noentry;
|
||||
for(i=0;i<nmatch;++i) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
%% write init;
|
||||
%% write exec;
|
||||
if(cs < %%{ write first_final; }%% ) return -1;
|
||||
matches[0] = (regmatch_t){.rm_so = 0, .rm_eo = eof-start};
|
||||
for(i=1;i<nmatch;++i) if(matches[i].rm_eo == -1) matches[i].rm_so = -1;
|
||||
else if(matches[i].rm_so == matches[i].rm_eo) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
else { par = i; while((par = parents[par])) if(matches[par].rm_eo == -1) { matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1}; break; }}
|
||||
return 0;
|
||||
}
|
||||
|
||||
%%{
|
||||
machine errorfile;
|
||||
action A1 { matches[1].rm_so = p-start; }
|
||||
action A2 { matches[2].rm_so = p-start; }
|
||||
action E1 { matches[1].rm_eo = p-start; }
|
||||
action E2 { matches[2].rm_eo = p-start; }
|
||||
main := ([0-9]+) >A1 %E1 [ \t]+'"'([^"]+) >A2 %E2 '"' ;
|
||||
}%%
|
||||
|
||||
RE2R_EXPORT int re2r_match_errorfile(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
size_t i, cs;
|
||||
int par;
|
||||
static const unsigned char parents[] = {[0]=0,[1]=0,[2]=0,};
|
||||
const char *start = p, *eof = pe;
|
||||
%% write data nofinal noerror noentry;
|
||||
for(i=0;i<nmatch;++i) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
%% write init;
|
||||
%% write exec;
|
||||
if(cs < %%{ write first_final; }%% ) return -1;
|
||||
matches[0] = (regmatch_t){.rm_so = 0, .rm_eo = eof-start};
|
||||
for(i=1;i<nmatch;++i) if(matches[i].rm_eo == -1) matches[i].rm_so = -1;
|
||||
else if(matches[i].rm_so == matches[i].rm_eo) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
else { par = i; while((par = parents[par])) if(matches[par].rm_eo == -1) { matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1}; break; }}
|
||||
return 0;
|
||||
}
|
||||
|
||||
%%{
|
||||
machine addheader;
|
||||
action A1 { matches[1].rm_so = p-start; }
|
||||
action A2 { matches[2].rm_so = p-start; }
|
||||
action E1 { matches[1].rm_eo = p-start; }
|
||||
action E2 { matches[2].rm_eo = p-start; }
|
||||
main := '"'([^"]+) >A1 %E1 '"'[ \t]+'"'([^"]+) >A2 %E2 '"' ;
|
||||
}%%
|
||||
|
||||
RE2R_EXPORT int re2r_match_addheader(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
size_t i, cs;
|
||||
int par;
|
||||
static const unsigned char parents[] = {[0]=0,[1]=0,[2]=0,};
|
||||
const char *start = p, *eof = pe;
|
||||
%% write data nofinal noerror noentry;
|
||||
for(i=0;i<nmatch;++i) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
%% write init;
|
||||
%% write exec;
|
||||
if(cs < %%{ write first_final; }%% ) return -1;
|
||||
matches[0] = (regmatch_t){.rm_so = 0, .rm_eo = eof-start};
|
||||
for(i=1;i<nmatch;++i) if(matches[i].rm_eo == -1) matches[i].rm_so = -1;
|
||||
else if(matches[i].rm_so == matches[i].rm_eo) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
else { par = i; while((par = parents[par])) if(matches[par].rm_eo == -1) { matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1}; break; }}
|
||||
return 0;
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_filter(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_logfile(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_filterurls(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_xtinyproxy(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_filterextended(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_xtinyproxy(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_filterdefaultdeny(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_xtinyproxy(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_filtercasesensitive(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_xtinyproxy(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_reversebaseurl(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_logfile(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_reverseonly(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_xtinyproxy(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
RE2R_EXPORT int re2r_match_reversemagic(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
return re2r_match_xtinyproxy(p, pe, nmatch, matches);
|
||||
}
|
||||
|
||||
%%{
|
||||
machine reversepath;
|
||||
action A1 { matches[1].rm_so = p-start; }
|
||||
action A2 { matches[2].rm_so = p-start; }
|
||||
action A3 { matches[3].rm_so = p-start; }
|
||||
action E1 { matches[1].rm_eo = p-start; }
|
||||
action E2 { matches[2].rm_eo = p-start; }
|
||||
action E3 { matches[3].rm_eo = p-start; }
|
||||
main := '"'([^"]+) >A1 %E1 '"'([ \t]+'"'([^"]+) >A3 %E3 '"')? >A2 %E2 ;
|
||||
}%%
|
||||
|
||||
RE2R_EXPORT int re2r_match_reversepath(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
size_t i, cs;
|
||||
int par;
|
||||
static const unsigned char parents[] = {[0]=0,[1]=0,[2]=0,[3]=2,};
|
||||
const char *start = p, *eof = pe;
|
||||
%% write data nofinal noerror noentry;
|
||||
for(i=0;i<nmatch;++i) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
%% write init;
|
||||
%% write exec;
|
||||
if(cs < %%{ write first_final; }%% ) return -1;
|
||||
matches[0] = (regmatch_t){.rm_so = 0, .rm_eo = eof-start};
|
||||
for(i=1;i<nmatch;++i) if(matches[i].rm_eo == -1) matches[i].rm_so = -1;
|
||||
else if(matches[i].rm_so == matches[i].rm_eo) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
else { par = i; while((par = parents[par])) if(matches[par].rm_eo == -1) { matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1}; break; }}
|
||||
return 0;
|
||||
}
|
||||
|
||||
%%{
|
||||
machine upstream;
|
||||
action A1 { matches[1].rm_so = p-start; }
|
||||
action A2 { matches[2].rm_so = p-start; }
|
||||
action A3 { matches[3].rm_so = p-start; }
|
||||
action A4 { matches[4].rm_so = p-start; }
|
||||
action A5 { matches[5].rm_so = p-start; }
|
||||
action A6 { matches[6].rm_so = p-start; }
|
||||
action A7 { matches[7].rm_so = p-start; }
|
||||
action A8 { matches[8].rm_so = p-start; }
|
||||
action A9 { matches[9].rm_so = p-start; }
|
||||
action A10 { matches[10].rm_so = p-start; }
|
||||
action A11 { matches[11].rm_so = p-start; }
|
||||
action A12 { matches[12].rm_so = p-start; }
|
||||
action A13 { matches[13].rm_so = p-start; }
|
||||
action A14 { matches[14].rm_so = p-start; }
|
||||
action E1 { matches[1].rm_eo = p-start; }
|
||||
action E2 { matches[2].rm_eo = p-start; }
|
||||
action E3 { matches[3].rm_eo = p-start; }
|
||||
action E4 { matches[4].rm_eo = p-start; }
|
||||
action E5 { matches[5].rm_eo = p-start; }
|
||||
action E6 { matches[6].rm_eo = p-start; }
|
||||
action E7 { matches[7].rm_eo = p-start; }
|
||||
action E8 { matches[8].rm_eo = p-start; }
|
||||
action E9 { matches[9].rm_eo = p-start; }
|
||||
action E10 { matches[10].rm_eo = p-start; }
|
||||
action E11 { matches[11].rm_eo = p-start; }
|
||||
action E12 { matches[12].rm_eo = p-start; }
|
||||
action E13 { matches[13].rm_eo = p-start; }
|
||||
action E14 { matches[14].rm_eo = p-start; }
|
||||
main := (( "none" ) >A2 %E2 [ \t]+'"'([^"]+) >A3 %E3 '"') >A1 %E1 |(( "http" | "socks4" | "socks5" ) >A5 %E5 [ \t]+(([^:]*) >A7 %E7 ":" ([^@]*) >A8 %E8 "@" )? >A6 %E6 (([0-9]+[.][0-9]+[.][0-9]+[.][0-9]+) >A10 %E10 |(('-'|[A-Za-z0-9._])+) >A11 %E11 ) >A9 %E9 ":" ([0-9]+) >A12 %E12 ([ \t]+'"'([^"]+) >A14 %E14 '"')? >A13 %E13 ) >A4 %E4 ;
|
||||
}%%
|
||||
|
||||
RE2R_EXPORT int re2r_match_upstream(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
size_t i, cs;
|
||||
int par;
|
||||
static const unsigned char parents[] = {[0]=0,[1]=0,[2]=1,[3]=1,[4]=0,[5]=4,[6]=4,[7]=6,[8]=6,[9]=4,[10]=9,[11]=9,[12]=4,[13]=4,[14]=13,};
|
||||
const char *start = p, *eof = pe;
|
||||
%% write data nofinal noerror noentry;
|
||||
for(i=0;i<nmatch;++i) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
%% write init;
|
||||
%% write exec;
|
||||
if(cs < %%{ write first_final; }%% ) return -1;
|
||||
matches[0] = (regmatch_t){.rm_so = 0, .rm_eo = eof-start};
|
||||
for(i=1;i<nmatch;++i) if(matches[i].rm_eo == -1) matches[i].rm_so = -1;
|
||||
else if(matches[i].rm_so == matches[i].rm_eo) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
else { par = i; while((par = parents[par])) if(matches[par].rm_eo == -1) { matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1}; break; }}
|
||||
return 0;
|
||||
}
|
||||
|
||||
%%{
|
||||
machine loglevel;
|
||||
action A1 { matches[1].rm_so = p-start; }
|
||||
action E1 { matches[1].rm_eo = p-start; }
|
||||
main := ([Cc] "ritical" |[Ee] "rror" |[Ww] "arning" |[Nn] "otice" |[Cc] "onnect" |[Ii] "nfo" ) >A1 %E1 ;
|
||||
}%%
|
||||
|
||||
RE2R_EXPORT int re2r_match_loglevel(const char *p, const char* pe, size_t nmatch, regmatch_t matches[])
|
||||
{
|
||||
size_t i, cs;
|
||||
int par;
|
||||
static const unsigned char parents[] = {[0]=0,[1]=0,};
|
||||
const char *start = p, *eof = pe;
|
||||
%% write data nofinal noerror noentry;
|
||||
for(i=0;i<nmatch;++i) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
%% write init;
|
||||
%% write exec;
|
||||
if(cs < %%{ write first_final; }%% ) return -1;
|
||||
matches[0] = (regmatch_t){.rm_so = 0, .rm_eo = eof-start};
|
||||
for(i=1;i<nmatch;++i) if(matches[i].rm_eo == -1) matches[i].rm_so = -1;
|
||||
else if(matches[i].rm_so == matches[i].rm_eo) matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1};
|
||||
else { par = i; while((par = parents[par])) if(matches[par].rm_eo == -1) { matches[i] = (regmatch_t){.rm_so = -1, .rm_eo = -1}; break; }}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
/* this is a tool to print regexname regex pairs as input for re2r.
|
||||
compile with gcc -I. src/conf_regex_print.c
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define STDCONF(A, B, C) printf("%s %s\n", #A, B)
|
||||
|
||||
int main() {
|
||||
#include "conf_regex.h"
|
||||
;
|
||||
}
|
||||
+32
-14
@@ -49,6 +49,7 @@ struct htab {
|
||||
size_t mask;
|
||||
size_t used;
|
||||
size_t seed;
|
||||
size_t dead;
|
||||
};
|
||||
|
||||
#define MINSIZE 8
|
||||
@@ -107,14 +108,14 @@ static int resize(struct htab *htab, size_t nel)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct elem *lookup(struct htab *htab, const char *key, size_t hash)
|
||||
static struct elem *lookup(struct htab *htab, const char *key, size_t hash, size_t dead)
|
||||
{
|
||||
size_t i, j;
|
||||
struct elem *e;
|
||||
|
||||
for (i=hash,j=1; ; i+=j++) {
|
||||
e = htab->elems + (i & htab->mask);
|
||||
if (!e->item.key ||
|
||||
if ((!e->item.key && (!e->hash || e->hash == dead)) ||
|
||||
(e->hash==hash && STRCMP(e->item.key, key)==0))
|
||||
break;
|
||||
}
|
||||
@@ -138,50 +139,67 @@ void htab_destroy(struct htab *htab)
|
||||
free(htab);
|
||||
}
|
||||
|
||||
static htab_entry *htab_find_item(struct htab *htab, const char* key)
|
||||
static struct elem *htab_find_elem(struct htab *htab, const char* key)
|
||||
{
|
||||
size_t hash = keyhash(key, htab->seed);
|
||||
struct elem *e = lookup(htab, key, hash);
|
||||
struct elem *e = lookup(htab, key, hash, 0);
|
||||
|
||||
if (e->item.key) {
|
||||
return &e->item;
|
||||
return e;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
htab_value* htab_find(struct htab *htab, const char* key)
|
||||
{
|
||||
htab_entry *i = htab_find_item(htab, key);
|
||||
if(i) return &i->data;
|
||||
return 0;
|
||||
struct elem *e = htab_find_elem(htab, key);
|
||||
if(!e) return 0;
|
||||
return &e->item.data;
|
||||
}
|
||||
|
||||
htab_value* htab_find2(struct htab *htab, const char* key, char **saved_key)
|
||||
{
|
||||
struct elem *e = htab_find_elem(htab, key);
|
||||
if(!e) return 0;
|
||||
*saved_key = e->item.key;
|
||||
return &e->item.data;
|
||||
}
|
||||
|
||||
int htab_delete(struct htab *htab, const char* key)
|
||||
{
|
||||
htab_entry *i = htab_find_item(htab, key);
|
||||
if(!i) return 0;
|
||||
i->key = 0;
|
||||
struct elem *e = htab_find_elem(htab, key);
|
||||
if(!e) return 0;
|
||||
e->item.key = 0;
|
||||
e->hash = 0xdeadc0de;
|
||||
--htab->used;
|
||||
++htab->dead;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int htab_insert(struct htab *htab, char* key, htab_value value)
|
||||
{
|
||||
size_t hash = keyhash(key, htab->seed);
|
||||
struct elem *e = lookup(htab, key, hash);
|
||||
size_t hash = keyhash(key, htab->seed), oh;
|
||||
struct elem *e = lookup(htab, key, hash, 0xdeadc0de);
|
||||
if(e->item.key) {
|
||||
/* it's not allowed to overwrite existing data */
|
||||
return 0;
|
||||
}
|
||||
|
||||
oh = e->hash; /* save old hash in case it's tombstone marker */
|
||||
e->item.key = key;
|
||||
e->item.data = value;
|
||||
e->hash = hash;
|
||||
if (++htab->used > htab->mask - htab->mask/4) {
|
||||
if (++htab->used + htab->dead > htab->mask - htab->mask/4) {
|
||||
if (!resize(htab, 2*htab->used)) {
|
||||
htab->used--;
|
||||
e->item.key = 0;
|
||||
e->hash = oh;
|
||||
return 0;
|
||||
}
|
||||
htab->dead = 0;
|
||||
} else if (oh == 0xdeadc0de) {
|
||||
/* re-used tomb */
|
||||
--htab->dead;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ typedef union htab_value {
|
||||
struct htab * htab_create(size_t);
|
||||
void htab_destroy(struct htab *);
|
||||
htab_value* htab_find(struct htab *, const char* key);
|
||||
/* same as htab_find, but can retrieve the saved key (for freeing) */
|
||||
htab_value* htab_find2(struct htab *htab, const char* key, char **saved_key);
|
||||
int htab_insert(struct htab *, char*, htab_value);
|
||||
int htab_delete(struct htab *htab, const char* key);
|
||||
size_t htab_next(struct htab *, size_t iterator, char** key, htab_value **v);
|
||||
|
||||
+23
-18
@@ -20,10 +20,9 @@
|
||||
* HTML error pages with variable substitution.
|
||||
*/
|
||||
|
||||
#include <regex.h>
|
||||
#include "common.h"
|
||||
#include "main.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "buffer.h"
|
||||
#include "conns.h"
|
||||
#include "heap.h"
|
||||
@@ -32,6 +31,8 @@
|
||||
#include "utils.h"
|
||||
#include "conf.h"
|
||||
|
||||
#include <regex.h>
|
||||
|
||||
/*
|
||||
* Add an error number -> filename mapping to the errorpages list.
|
||||
*/
|
||||
@@ -132,7 +133,9 @@ send_html_file (FILE *infile, struct conn_s *connptr)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int send_http_headers (struct conn_s *connptr, int code, const char *message)
|
||||
int send_http_headers (
|
||||
struct conn_s *connptr, int code,
|
||||
const char *message, const char *extra)
|
||||
{
|
||||
const char headers[] =
|
||||
"HTTP/1.0 %d %s\r\n"
|
||||
@@ -141,21 +144,9 @@ int send_http_headers (struct conn_s *connptr, int code, const char *message)
|
||||
"%s"
|
||||
"Connection: close\r\n" "\r\n";
|
||||
|
||||
const char p_auth_str[] =
|
||||
"Proxy-Authenticate: Basic realm=\""
|
||||
PACKAGE_NAME "\"\r\n";
|
||||
|
||||
const char w_auth_str[] =
|
||||
"WWW-Authenticate: Basic realm=\""
|
||||
PACKAGE_NAME "\"\r\n";
|
||||
|
||||
/* according to rfc7235, the 407 error must be accompanied by
|
||||
a Proxy-Authenticate header field. */
|
||||
const char *add = code == 407 ? p_auth_str : (code == 401 ? w_auth_str : "");
|
||||
|
||||
return (write_message (connptr->client_fd, headers,
|
||||
code, message, PACKAGE, VERSION,
|
||||
add));
|
||||
extra));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -179,8 +170,21 @@ int send_http_error_message (struct conn_s *connptr)
|
||||
"<p><em>Generated by %s version %s.</em></p>\n" "</body>\n"
|
||||
"</html>\n";
|
||||
|
||||
const char p_auth_str[] =
|
||||
"Proxy-Authenticate: Basic realm=\""
|
||||
PACKAGE_NAME "\"\r\n";
|
||||
|
||||
const char w_auth_str[] =
|
||||
"WWW-Authenticate: Basic realm=\""
|
||||
PACKAGE_NAME "\"\r\n";
|
||||
|
||||
/* according to rfc7235, the 407 error must be accompanied by
|
||||
a Proxy-Authenticate header field. */
|
||||
const char *add = connptr->error_number == 407 ? p_auth_str :
|
||||
(connptr->error_number == 401 ? w_auth_str : "");
|
||||
|
||||
send_http_headers (connptr, connptr->error_number,
|
||||
connptr->error_string);
|
||||
connptr->error_string, add);
|
||||
|
||||
error_file = get_html_file (connptr->error_number);
|
||||
if (!(infile = fopen (error_file, "r"))) {
|
||||
@@ -243,6 +247,7 @@ int add_standard_vars (struct conn_s *connptr)
|
||||
char errnobuf[16];
|
||||
char timebuf[30];
|
||||
time_t global_time;
|
||||
struct tm tm_buf;
|
||||
|
||||
snprintf (errnobuf, sizeof errnobuf, "%d", connptr->error_number);
|
||||
ADD_VAR_RET ("errno", errnobuf);
|
||||
@@ -258,7 +263,7 @@ int add_standard_vars (struct conn_s *connptr)
|
||||
|
||||
global_time = time (NULL);
|
||||
strftime (timebuf, sizeof (timebuf), "%a, %d %b %Y %H:%M:%S GMT",
|
||||
gmtime (&global_time));
|
||||
gmtime_r (&global_time, &tm_buf));
|
||||
add_error_variable (connptr, "date", timebuf);
|
||||
|
||||
add_error_variable (connptr, "website",
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ extern int add_error_variable (struct conn_s *connptr, const char *key,
|
||||
const char *val);
|
||||
extern int send_html_file (FILE * infile, struct conn_s *connptr);
|
||||
extern int send_http_headers (struct conn_s *connptr, int code,
|
||||
const char *message);
|
||||
const char *message, const char *extra);
|
||||
extern int add_standard_vars (struct conn_s *connptr);
|
||||
|
||||
#endif /* !TINYPROXY_HTML_ERROR_H */
|
||||
+3
-2
@@ -232,6 +232,7 @@ int http_message_send (http_message_t msg, int fd)
|
||||
char timebuf[30];
|
||||
time_t global_time;
|
||||
unsigned int i;
|
||||
struct tm tm_buf;
|
||||
|
||||
assert (is_http_message_valid (msg));
|
||||
|
||||
@@ -254,11 +255,11 @@ int http_message_send (http_message_t msg, int fd)
|
||||
/* Output the date */
|
||||
global_time = time (NULL);
|
||||
strftime (timebuf, sizeof (timebuf), "%a, %d %b %Y %H:%M:%S GMT",
|
||||
gmtime (&global_time));
|
||||
gmtime_r (&global_time, &tm_buf));
|
||||
write_message (fd, "Date: %s\r\n", timebuf);
|
||||
|
||||
/* Output the content-length */
|
||||
write_message (fd, "Content-length: %u\r\n", msg->body.length);
|
||||
write_message (fd, "Content-length: %lu\r\n", (unsigned long) msg->body.length);
|
||||
|
||||
/* Write the separator between the headers and body */
|
||||
safe_write (fd, "\r\n", 2);
|
||||
|
||||
@@ -109,6 +109,7 @@ void log_message (int level, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
struct timespec nowtime;
|
||||
struct tm tm_buf;
|
||||
|
||||
char time_string[TIME_LENGTH];
|
||||
char str[STRING_LENGTH];
|
||||
@@ -177,11 +178,11 @@ void log_message (int level, const char *fmt, ...)
|
||||
clock_gettime(CLOCK_REALTIME, &nowtime);
|
||||
/* Format is month day hour:minute:second (24 time) */
|
||||
strftime (time_string, TIME_LENGTH, "%b %d %H:%M:%S",
|
||||
localtime (&nowtime.tv_sec));
|
||||
localtime_r (&nowtime.tv_sec, &tm_buf));
|
||||
|
||||
snprintf (str, STRING_LENGTH, "%-9s %s.%03u [%ld]: ",
|
||||
snprintf (str, STRING_LENGTH, "%-9s %s.%03lu [%ld]: ",
|
||||
syslog_level[level], time_string,
|
||||
nowtime.tv_nsec/1000000u,
|
||||
(unsigned long) nowtime.tv_nsec/1000000ul,
|
||||
(long int) getpid ());
|
||||
|
||||
/*
|
||||
|
||||
+7
-2
@@ -81,14 +81,19 @@ char* orderedmap_find(struct orderedmap *o, const char *key) {
|
||||
int orderedmap_remove(struct orderedmap *o, const char *key) {
|
||||
size_t i;
|
||||
char *lk;
|
||||
htab_value *lv, *v = htab_find(o->map, key);
|
||||
char *sk;
|
||||
char **sv;
|
||||
htab_value *lv, *v = htab_find2(o->map, key, &sk);
|
||||
if(!v) return 0;
|
||||
htab_delete(o->map, key);
|
||||
sv = sblist_get(o->values, v->n);
|
||||
free(*sv);
|
||||
sblist_delete(o->values, v->n);
|
||||
i = 0;
|
||||
while((i = htab_next(o->map, i, &lk, &lv))) {
|
||||
if(lv->n > v->n) lv->n--;
|
||||
}
|
||||
htab_delete(o->map, key);
|
||||
free(sk);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1454,8 +1454,8 @@ get_request_entity(struct conn_s *connptr)
|
||||
ret = -1;
|
||||
} else {
|
||||
log_message (LOG_INFO,
|
||||
"Read request entity of %d bytes",
|
||||
nread);
|
||||
"Read request entity of %ld bytes",
|
||||
(long) nread);
|
||||
ret = 0;
|
||||
}
|
||||
} else {
|
||||
|
||||
+12
-2
@@ -34,6 +34,7 @@ void reversepath_add (const char *path, const char *url,
|
||||
struct reversepath **reversepath_list)
|
||||
{
|
||||
struct reversepath *reverse;
|
||||
size_t l;
|
||||
|
||||
if (url == NULL) {
|
||||
log_message (LOG_WARNING,
|
||||
@@ -65,8 +66,17 @@ void reversepath_add (const char *path, const char *url,
|
||||
|
||||
if (!path)
|
||||
reverse->path = safestrdup ("/");
|
||||
else
|
||||
reverse->path = safestrdup (path);
|
||||
else {
|
||||
l = strlen (path);
|
||||
if (l && path[l-1] == '/')
|
||||
reverse->path = safestrdup (path);
|
||||
else {
|
||||
reverse->path = safemalloc (l + 2);
|
||||
memcpy (reverse->path, path, l);
|
||||
reverse->path[l] = '/';
|
||||
reverse->path[l+1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
reverse->url = safestrdup (url);
|
||||
|
||||
|
||||
+25
-4
@@ -34,6 +34,7 @@
|
||||
#include "text.h"
|
||||
#include "conf.h"
|
||||
#include "loop.h"
|
||||
#include "sblist.h"
|
||||
|
||||
/*
|
||||
* Return a human readable error for getaddrinfo() and getnameinfo().
|
||||
@@ -68,7 +69,7 @@ bind_socket (int sockfd, const char *addr, int family)
|
||||
n = getaddrinfo (addr, NULL, &hints, &res);
|
||||
if (n != 0) {
|
||||
log_message (LOG_INFO,
|
||||
"bind_socket: getaddrinfo failed for %s: ", addr, get_gai_error (n));
|
||||
"bind_socket: getaddrinfo failed for %s: %s", addr, get_gai_error (n));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -87,6 +88,26 @@ bind_socket (int sockfd, const char *addr, int family)
|
||||
return sockfd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try binding the given socket to supplied addresses, stopping when one succeeds.
|
||||
*/
|
||||
static int
|
||||
bind_socket_list (int sockfd, sblist *addresses, int family)
|
||||
{
|
||||
size_t nb_addresses = sblist_getsize(addresses);
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < nb_addresses; i++) {
|
||||
const char *address = *(const char **)sblist_get(addresses, i);
|
||||
if (bind_socket(sockfd, address, family) >= 0) {
|
||||
log_message(LOG_INFO, "Bound to %s", address);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Open a connection to a remote host. It's been re-written to use
|
||||
* the getaddrinfo() library function, which allows for a protocol
|
||||
@@ -134,9 +155,9 @@ int opensock (const char *host, int port, const char *bind_to)
|
||||
close (sockfd);
|
||||
continue; /* can't bind, so try again */
|
||||
}
|
||||
} else if (config->bind_address) {
|
||||
if (bind_socket (sockfd, config->bind_address,
|
||||
res->ai_family) < 0) {
|
||||
} else if (config->bind_addrs) {
|
||||
if (bind_socket_list (sockfd, config->bind_addrs,
|
||||
res->ai_family) < 0) {
|
||||
close (sockfd);
|
||||
continue; /* can't bind, so try again */
|
||||
}
|
||||
|
||||
+1
-1
@@ -122,7 +122,7 @@ err_minus_one:
|
||||
add_error_variable (connptr, "deniedconns", denied);
|
||||
add_error_variable (connptr, "refusedconns", refused);
|
||||
add_standard_vars (connptr);
|
||||
send_http_headers (connptr, 200, "Statistic requested");
|
||||
send_http_headers (connptr, 200, "Statistic requested", "");
|
||||
send_html_file (statfile, connptr);
|
||||
fclose (statfile);
|
||||
pthread_mutex_unlock(&stats_file_lock);
|
||||
|
||||
Reference in new issue
Block a user