From: Fabian Keil Date: Sun, 24 Nov 2013 14:22:51 +0000 (+0000) Subject: Turn url_spec into an union and rename it to pattern_spec X-Git-Tag: v_3_0_22~217 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=9b87e59614c7e19ed0b40d9037fbf77ae9871214 Turn url_spec into an union and rename it to pattern_spec ... nowadays it can contain TAG patterns as well. --- diff --git a/actions.c b/actions.c index f0898367..acd3d7cb 100644 --- a/actions.c +++ b/actions.c @@ -1,4 +1,4 @@ -const char actions_rcs[] = "$Id: actions.c,v 1.86 2012/11/11 12:37:10 fabiankeil Exp $"; +const char actions_rcs[] = "$Id: actions.c,v 1.87 2012/11/24 13:59:00 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/actions.c,v $ @@ -811,13 +811,13 @@ int update_action_bits_for_tag(struct client_state *csp, const char *tag) for (b = b->next; NULL != b; b = b->next) { /* skip the URL patterns, */ - if (NULL == b->url->tag_regex) + if (NULL == b->url->pattern.tag_regex) { continue; } /* and check if one of the tag patterns matches the tag, */ - if (0 == regexec(b->url->tag_regex, tag, 0, NULL, 0)) + if (0 == regexec(b->url->pattern.tag_regex, tag, 0, NULL, 0)) { /* if it does, update the action bit map, */ if (merge_current_action(csp->action, b->action)) diff --git a/cgiedit.c b/cgiedit.c index a0e0e6d9..f52f5035 100644 --- a/cgiedit.c +++ b/cgiedit.c @@ -1,4 +1,4 @@ -const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.76 2012/07/23 12:42:53 fabiankeil Exp $"; +const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.77 2013/11/06 16:28:00 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgiedit.c,v $ @@ -1827,7 +1827,7 @@ static jb_err get_url_spec_param(struct client_state *csp, const char *orig_param; char *param; char *s; - struct url_spec compiled[1]; + struct pattern_spec compiled[1]; jb_err err; assert(csp); diff --git a/filters.c b/filters.c index f3ea8686..467b8029 100644 --- a/filters.c +++ b/filters.c @@ -1,4 +1,4 @@ -const char filters_rcs[] = "$Id: filters.c,v 1.176 2012/12/07 12:45:20 fabiankeil Exp $"; +const char filters_rcs[] = "$Id: filters.c,v 1.177 2013/04/23 09:37:28 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/filters.c,v $ @@ -781,8 +781,8 @@ struct http_response *trust_url(struct client_state *csp) struct map * exports; char buf[BUFFER_SIZE]; char *p; - struct url_spec **tl; - struct url_spec *t; + struct pattern_spec **tl; + struct pattern_spec *t; jb_err err; /* @@ -1409,7 +1409,7 @@ int is_untrusted_url(const struct client_state *csp) { struct file_list *fl; struct block_spec *b; - struct url_spec **trusted_url; + struct pattern_spec **trusted_url; struct http_request rhttp[1]; const char * referer; jb_err err; @@ -2211,7 +2211,7 @@ const static struct forward_spec *get_forward_override_settings(struct client_st const struct forward_spec *forward_url(struct client_state *csp, const struct http_request *http) { - static const struct forward_spec fwd_default[1] = { FORWARD_SPEC_INITIALIZER }; + static const struct forward_spec fwd_default[1]; /* Zero'ed due to being static. */ struct forward_spec *fwd = csp->config->forward; if (csp->action->flags & ACTION_FORWARD_OVERRIDE) diff --git a/loaders.c b/loaders.c index 2a42b0dd..292ca7fc 100644 --- a/loaders.c +++ b/loaders.c @@ -1,4 +1,4 @@ -const char loaders_rcs[] = "$Id: loaders.c,v 1.94 2012/12/07 12:43:05 fabiankeil Exp $"; +const char loaders_rcs[] = "$Id: loaders.c,v 1.95 2013/01/13 15:38:14 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/loaders.c,v $ @@ -829,7 +829,7 @@ int load_trustfile(struct client_state *csp) FILE *fp; struct block_spec *b, *bl; - struct url_spec **tl; + struct pattern_spec **tl; char *buf = NULL; int reject, trusted; diff --git a/project.h b/project.h index 3bf0548a..79827dcb 100644 --- a/project.h +++ b/project.h @@ -1,7 +1,7 @@ #ifndef PROJECT_H_INCLUDED #define PROJECT_H_INCLUDED /** Version string. */ -#define PROJECT_H_VERSION "$Id: project.h,v 1.196 2013/03/07 14:08:50 fabiankeil Exp $" +#define PROJECT_H_VERSION "$Id: project.h,v 1.197 2013/11/24 14:21:58 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/project.h,v $ @@ -346,15 +346,8 @@ struct http_response enum crunch_reason crunch_reason; /**< Why the response was generated in the first place. */ }; -/** - * A URL or a tag pattern. - */ struct url_spec { - /** The string which was parsed to produce this url_spec. - Used for debugging or display only. */ - char *spec; - #ifdef FEATURE_EXTENDED_HOST_PATTERNS regex_t *host_regex;/**< Regex for host matching */ #else @@ -367,17 +360,25 @@ struct url_spec char *port_list; /**< List of acceptable ports, or NULL to match all ports */ regex_t *preg; /**< Regex for matching path part */ - regex_t *tag_regex; /**< Regex for matching tags */ }; /** - * If you declare a static url_spec, this is the value to initialize it to zero. + * A URL or a tag pattern. */ -#ifndef FEATURE_EXTENDED_HOST_PATTERNS -#define URL_SPEC_INITIALIZER { NULL, NULL, NULL, 0, 0, NULL, NULL, NULL } -#else -#define URL_SPEC_INITIALIZER { NULL, NULL, NULL, NULL, NULL } -#endif /* def FEATURE_EXTENDED_HOST_PATTERNS */ +struct pattern_spec +{ + /** The string which was parsed to produce this pattern_spec. + Used for debugging or display only. */ + char *spec; + + union + { + struct url_spec url_spec; + regex_t *tag_regex; + } pattern; + + unsigned int flags; /**< Bitmap with various pattern properties. */ +}; /** * Constant for host part matching in URLs. If set, indicates that the start of @@ -627,7 +628,7 @@ struct action_spec */ struct url_actions { - struct url_spec url[1]; /**< The URL or tag pattern. */ + struct pattern_spec url[1]; /**< The URL or tag pattern. */ struct action_spec *action; /**< Action settings that might be shared with the list entry before or after the current @@ -1064,9 +1065,9 @@ struct file_list */ struct block_spec { - struct url_spec url[1]; /**< The URL pattern */ - int reject; /**< FIXME: Please document this! */ - struct block_spec *next; /**< Next entry in linked list */ + struct pattern_spec url[1]; /**< The URL pattern */ + int reject; /**< FIXME: Please document this! */ + struct block_spec *next; /**< Next entry in linked list */ }; /** @@ -1082,7 +1083,7 @@ struct block_spec struct forward_spec { /** URL pattern that this forward_spec is for. */ - struct url_spec url[1]; + struct pattern_spec url[1]; /** Connection type. Must be SOCKS_NONE, SOCKS_4, SOCKS_4A or SOCKS_5. */ enum forwarder_type type; @@ -1104,11 +1105,6 @@ struct forward_spec }; -/** - * Initializer for a static struct forward_spec. - */ -#define FORWARD_SPEC_INITIALIZER { { URL_SPEC_INITIALIZER }, 0, NULL, 0, NULL, 0, NULL } - /* Supported filter types */ enum filter_type { @@ -1310,7 +1306,7 @@ struct configuration_spec struct list trust_info[1]; /** FIXME: DOCME: Document this. */ - struct url_spec *trust_list[MAX_TRUSTED_REFERRERS]; + struct pattern_spec *trust_list[MAX_TRUSTED_REFERRERS]; #endif /* def FEATURE_TRUST */ diff --git a/urlmatch.c b/urlmatch.c index c731ec3b..3e807bbd 100644 --- a/urlmatch.c +++ b/urlmatch.c @@ -1,4 +1,4 @@ -const char urlmatch_rcs[] = "$Id: urlmatch.c,v 1.74 2012/12/07 12:49:20 fabiankeil Exp $"; +const char urlmatch_rcs[] = "$Id: urlmatch.c,v 1.75 2012/12/07 12:49:47 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/urlmatch.c,v $ @@ -65,7 +65,7 @@ enum regex_anchoring RIGHT_ANCHORED, RIGHT_ANCHORED_HOST }; -static jb_err compile_host_pattern(struct url_spec *url, const char *host_pattern); +static jb_err compile_host_pattern(struct pattern_spec *url, const char *host_pattern); /********************************************************************* * @@ -573,7 +573,7 @@ jb_err parse_http_request(const char *req, struct http_request *http) * *********************************************************************/ static jb_err compile_pattern(const char *pattern, enum regex_anchoring anchoring, - struct url_spec *url, regex_t **regex) + struct pattern_spec *url, regex_t **regex) { int errcode; char rebuf[BUFFER_SIZE]; @@ -645,7 +645,7 @@ static jb_err compile_pattern(const char *pattern, enum regex_anchoring anchorin * Description : Compiles the three parts of an URL pattern. * * Parameters : - * 1 : url = Target url_spec to be filled in. + * 1 : url = Target pattern_spec to be filled in. * 2 : buf = The url pattern to compile. Will be messed up. * * Returns : JB_ERR_OK - Success @@ -653,7 +653,7 @@ static jb_err compile_pattern(const char *pattern, enum regex_anchoring anchorin * JB_ERR_PARSE - Cannot parse regex * *********************************************************************/ -static jb_err compile_url_pattern(struct url_spec *url, char *buf) +static jb_err compile_url_pattern(struct pattern_spec *url, char *buf) { char *p; @@ -669,7 +669,7 @@ static jb_err compile_url_pattern(struct url_spec *url, char *buf) /* * XXX: does it make sense to compile the slash at the beginning? */ - jb_err err = compile_pattern(p, LEFT_ANCHORED, url, &url->preg); + jb_err err = compile_pattern(p, LEFT_ANCHORED, url, &url->pattern.url_spec.preg); if (JB_ERR_OK != err) { @@ -709,11 +709,11 @@ static jb_err compile_url_pattern(struct url_spec *url, char *buf) if (NULL != p) { *p++ = '\0'; - url->port_list = strdup_or_die(p); + url->pattern.url_spec.port_list = strdup_or_die(p); } else { - url->port_list = NULL; + url->pattern.url_spec.port_list = NULL; } if (buf[0] != '\0') @@ -734,7 +734,7 @@ static jb_err compile_url_pattern(struct url_spec *url, char *buf) * Description : Parses and compiles a host pattern. * * Parameters : - * 1 : url = Target url_spec to be filled in. + * 1 : url = Target pattern_spec to be filled in. * 2 : host_pattern = Host pattern to compile. * * Returns : JB_ERR_OK - Success @@ -742,9 +742,9 @@ static jb_err compile_url_pattern(struct url_spec *url, char *buf) * JB_ERR_PARSE - Cannot parse regex * *********************************************************************/ -static jb_err compile_host_pattern(struct url_spec *url, const char *host_pattern) +static jb_err compile_host_pattern(struct pattern_spec *url, const char *host_pattern) { - return compile_pattern(host_pattern, RIGHT_ANCHORED_HOST, url, &url->host_regex); + return compile_pattern(host_pattern, RIGHT_ANCHORED_HOST, url, &url->pattern.url_spec.host_regex); } #else @@ -756,14 +756,14 @@ static jb_err compile_host_pattern(struct url_spec *url, const char *host_patter * Description : Parses and "compiles" an old-school host pattern. * * Parameters : - * 1 : url = Target url_spec to be filled in. + * 1 : url = Target pattern_spec to be filled in. * 2 : host_pattern = Host pattern to parse. * * Returns : JB_ERR_OK - Success * JB_ERR_PARSE - Cannot parse regex * *********************************************************************/ -static jb_err compile_host_pattern(struct url_spec *url, const char *host_pattern) +static jb_err compile_host_pattern(struct pattern_spec *url, const char *host_pattern) { char *v[150]; size_t size; @@ -1015,7 +1015,7 @@ static int simple_domaincmp(char **pv, char **fv, int len) * Returns : 0 => domains are equivalent, else no match. * *********************************************************************/ -static int domain_match(const struct url_spec *pattern, const struct http_request *fqdn) +static int domain_match(const struct pattern_spec *pattern, const struct http_request *fqdn) { char **pv, **fv; /* vectors */ int plen, flen; @@ -1104,7 +1104,7 @@ static int domain_match(const struct url_spec *pattern, const struct http_reques * written to system log) * *********************************************************************/ -jb_err create_url_spec(struct url_spec *url, char *buf) +jb_err create_url_spec(struct pattern_spec *url, char *buf) { assert(url); assert(buf); @@ -1119,7 +1119,7 @@ jb_err create_url_spec(struct url_spec *url, char *buf) { /* The pattern starts with the first character after "TAG:" */ const char *tag_pattern = buf + 4; - return compile_pattern(tag_pattern, NO_ANCHORING, url, &url->tag_regex); + return compile_pattern(tag_pattern, NO_ANCHORING, url, &url->pattern.tag_regex); } /* If it isn't a tag pattern it must be an URL pattern. */ @@ -1135,37 +1135,37 @@ jb_err create_url_spec(struct url_spec *url, char *buf) * structure elements. * * Parameters : - * 1 : url = pointer to a url_spec structure. + * 1 : url = pointer to a pattern_spec structure. * * Returns : N/A * *********************************************************************/ -void free_url_spec(struct url_spec *url) +void free_url_spec(struct pattern_spec *url) { if (url == NULL) return; freez(url->spec); #ifdef FEATURE_EXTENDED_HOST_PATTERNS - if (url->host_regex) + if (url->pattern.url_spec.host_regex) { - regfree(url->host_regex); - freez(url->host_regex); + regfree(url->pattern.url_spec.host_regex); + freez(url->pattern.url_spec.host_regex); } #else - freez(url->dbuffer); - freez(url->dvec); - url->dcount = 0; + freez(url->pattern.url_spec.dbuffer); + freez(url->pattern.url_spec.dvec); + url->pattern.url_spec.dcount = 0; #endif /* ndef FEATURE_EXTENDED_HOST_PATTERNS */ - freez(url->port_list); - if (url->preg) + freez(url->pattern.url_spec.port_list); + if (url->pattern.url_spec.preg) { - regfree(url->preg); - freez(url->preg); + regfree(url->pattern.url_spec.preg); + freez(url->pattern.url_spec.preg); } - if (url->tag_regex) + if (url->pattern.tag_regex) { - regfree(url->tag_regex); - freez(url->tag_regex); + regfree(url->pattern.tag_regex); + freez(url->pattern.tag_regex); } } @@ -1203,13 +1203,13 @@ static int port_matches(const int port, const char *port_list) * *********************************************************************/ static int host_matches(const struct http_request *http, - const struct url_spec *pattern) + const struct pattern_spec *pattern) { #ifdef FEATURE_EXTENDED_HOST_PATTERNS - return ((NULL == pattern->host_regex) - || (0 == regexec(pattern->host_regex, http->host, 0, NULL, 0))); + return ((NULL == pattern->pattern.url_spec.host_regex) + || (0 == regexec(pattern->pattern.url_spec.host_regex, http->host, 0, NULL, 0))); #else - return ((NULL == pattern->dbuffer) || (0 == domain_match(pattern, http))); + return ((NULL == pattern->pattern.url_spec.dbuffer) || (0 == domain_match(pattern, http))); #endif } @@ -1227,10 +1227,10 @@ static int host_matches(const struct http_request *http, * Returns : TRUE for yes, FALSE otherwise. * *********************************************************************/ -static int path_matches(const char *path, const struct url_spec *pattern) +static int path_matches(const char *path, const struct pattern_spec *pattern) { - return ((NULL == pattern->preg) - || (0 == regexec(pattern->preg, path, 0, NULL, 0))); + return ((NULL == pattern->pattern.url_spec.preg) + || (0 == regexec(pattern->pattern.url_spec.preg, path, 0, NULL, 0))); } @@ -1247,16 +1247,16 @@ static int path_matches(const char *path, const struct url_spec *pattern) * Returns : Nonzero if the URL matches the pattern, else 0. * *********************************************************************/ -int url_match(const struct url_spec *pattern, +int url_match(const struct pattern_spec *pattern, const struct http_request *http) { - if (pattern->tag_regex != NULL) + if (pattern->pattern.tag_regex != NULL) { /* It's a tag pattern and shouldn't be matched against URLs */ return 0; } - return (port_matches(http->port, pattern->port_list) + return (port_matches(http->port, pattern->pattern.url_spec.port_list) && host_matches(http, pattern) && path_matches(http->path, pattern)); } diff --git a/urlmatch.h b/urlmatch.h index cbf864de..7ba4fd7b 100644 --- a/urlmatch.h +++ b/urlmatch.h @@ -1,6 +1,6 @@ #ifndef URLMATCH_H_INCLUDED #define URLMATCH_H_INCLUDED -#define URLMATCH_H_VERSION "$Id: urlmatch.h,v 1.17 2011/09/04 11:10:56 fabiankeil Exp $" +#define URLMATCH_H_VERSION "$Id: urlmatch.h,v 1.18 2011/11/06 11:41:05 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/urlmatch.h,v $ @@ -54,11 +54,11 @@ extern int url_requires_percent_encoding(const char *url); #define REQUIRE_PROTOCOL 1 -extern int url_match(const struct url_spec *pattern, +extern int url_match(const struct pattern_spec *pattern, const struct http_request *http); -extern jb_err create_url_spec(struct url_spec *url, char *buf); -extern void free_url_spec(struct url_spec *url); +extern jb_err create_url_spec(struct pattern_spec *url, char *buf); +extern void free_url_spec(struct pattern_spec *url); extern int match_portlist(const char *portlist, int port); extern jb_err parse_forwarder_address(char *address, char **hostname, int *port);