X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=urlmatch.c;h=a8f887b7dfa26d0b7911e766ddc8b8eb2d33d11b;hp=05ec84ac161fec4627a5ec919f155bcba951661e;hb=3b3309056593ee248f7f7ff9320041082355fc66;hpb=0ecd3de12dd83bbe337886f8ad22f88485f3cb37 diff --git a/urlmatch.c b/urlmatch.c index 05ec84ac..a8f887b7 100644 --- a/urlmatch.c +++ b/urlmatch.c @@ -1,4 +1,4 @@ -const char urlmatch_rcs[] = "$Id: urlmatch.c,v 1.56 2009/06/03 16:43:50 fabiankeil Exp $"; +const char urlmatch_rcs[] = "$Id: urlmatch.c,v 1.58 2009/06/03 16:44:41 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/urlmatch.c,v $ @@ -58,7 +58,13 @@ const char urlmatch_rcs[] = "$Id: urlmatch.c,v 1.56 2009/06/03 16:43:50 fabianke const char urlmatch_h_rcs[] = URLMATCH_H_VERSION; -enum regex_anchoring {NO_ANCHORING, LEFT_ANCHORED, RIGHT_ANCHORED}; +enum regex_anchoring +{ + NO_ANCHORING, + LEFT_ANCHORED, + RIGHT_ANCHORED, + RIGHT_ANCHORED_HOST +}; static jb_err compile_host_pattern(struct url_spec *url, const char *host_pattern); /********************************************************************* @@ -546,9 +552,10 @@ jb_err parse_http_request(const char *req, struct http_request *http) * * Parameters : * 1 : pattern = The pattern to compile. - * 2 : anchoring = How the regex should be anchored. - * Can be either one of NO_ANCHORING, - * LEFT_ANCHORED or RIGHT_ANCHORED. + * 2 : anchoring = How the regex should be modified + * before compilation. Can be either + * one of NO_ANCHORING, LEFT_ANCHORED, + * RIGHT_ANCHORED or RIGHT_ANCHORED_HOST. * 3 : url = In case of failures, the spec member is * logged and the structure freed. * 4 : regex = Where the compiled regex should be stored. @@ -582,6 +589,9 @@ static jb_err compile_pattern(const char *pattern, enum regex_anchoring anchorin case RIGHT_ANCHORED: fmt = "%s$"; break; + case RIGHT_ANCHORED_HOST: + fmt = "%s\\.?$"; + break; case LEFT_ANCHORED: fmt = "^%s"; break; @@ -731,7 +741,7 @@ static jb_err compile_url_pattern(struct url_spec *url, char *buf) *********************************************************************/ static jb_err compile_host_pattern(struct url_spec *url, const char *host_pattern) { - return compile_pattern(host_pattern, RIGHT_ANCHORED, url, &url->host_regex); + return compile_pattern(host_pattern, RIGHT_ANCHORED_HOST, url, &url->host_regex); } #else @@ -1217,6 +1227,26 @@ static int host_matches(const struct http_request *http, } +/********************************************************************* + * + * Function : path_matches + * + * Description : Compares a path against a path pattern. + * + * Parameters : + * 1 : path = The path to match + * 2 : pattern = The URL pattern + * + * Returns : TRUE for yes, FALSE otherwise. + * + *********************************************************************/ +static int path_matches(const char *path, const struct url_spec *pattern) +{ + return ((NULL == pattern->preg) + || (0 == regexec(pattern->preg, path, 0, NULL, 0))); +} + + /********************************************************************* * * Function : url_match @@ -1233,9 +1263,6 @@ static int host_matches(const struct http_request *http, int url_match(const struct url_spec *pattern, const struct http_request *http) { - /* XXX: these should probably be functions. */ -#define PATH_MATCHES ((NULL == pattern->preg) || (0 == regexec(pattern->preg, http->path, 0, NULL, 0))) - if (pattern->tag_regex != NULL) { /* It's a tag pattern and shouldn't be matched against URLs */ @@ -1243,7 +1270,7 @@ int url_match(const struct url_spec *pattern, } return (port_matches(http->port, pattern->port_list) - && host_matches(http, pattern) && PATH_MATCHES); + && host_matches(http, pattern) && path_matches(http->path, pattern)); }