X-Git-Url: http://www.privoxy.org/gitweb/templates.html?a=blobdiff_plain;f=urlmatch.c;h=494a69a96fa6e1e3d985b24836790872f13ac0ce;hb=4b3b267db159dc23314de3062859481b7c397e32;hp=84e9d29858edb1b1dcc3ff71d7a8034a73edbf58;hpb=53748ca8ca3c893025be34dd4f104546fcbd0602;p=privoxy.git diff --git a/urlmatch.c b/urlmatch.c index 84e9d298..494a69a9 100644 --- a/urlmatch.c +++ b/urlmatch.c @@ -666,7 +666,7 @@ static jb_err compile_pattern(const char *pattern, enum regex_anchoring anchorin snprintf(rebuf, rebuf_size, fmt, pattern); - *regex = pcre2_compile((const unsigned char *)pattern, + *regex = pcre2_compile((const unsigned char *)rebuf, PCRE2_ZERO_TERMINATED, PCRE2_CASELESS, &errcode, &error_offset, NULL); if (*regex == NULL) @@ -1160,7 +1160,7 @@ static int simplematch(const char *pattern, const char *text) * Returns : TRUE for yes, FALSE otherwise. * *********************************************************************/ -int pcre2_pattern_matches(const pcre2_code *pattern, const char *string) +static int pcre2_pattern_matches(const pcre2_code *pattern, const char *string) { PCRE2_SIZE offset; int ret; @@ -1189,6 +1189,29 @@ int pcre2_pattern_matches(const pcre2_code *pattern, const char *string) #endif +/********************************************************************* + * + * Function : regex_matches + * + * Description : Checks if a compiled regex pattern matches a string + * using either pcre2 or pcre1 code. + * + * Parameters : + * 1 : pattern = The compiled pattern + * 2 : string = The string to check + * + * Returns : TRUE for yes, FALSE otherwise. + * + *********************************************************************/ +int regex_matches(const REGEX_TYPE *pattern, const char *string) +{ +#ifdef HAVE_PCRE2 + return pcre2_pattern_matches(pattern, string); +#else + return (0 == regexec(pattern, string, 0, NULL, 0)); +#endif +} + /********************************************************************* * * Function : simple_domaincmp @@ -1483,13 +1506,7 @@ static int host_matches(const struct http_request *http, if (pattern->pattern.url_spec.host_regex_type == PCRE_HOST_PATTERN) { return ((NULL == pattern->pattern.url_spec.host_regex) -#ifdef HAVE_PCRE2 - || pcre2_pattern_matches(pattern->pattern.url_spec.host_regex, - http->host)); -#else - || (0 == regexec(pattern->pattern.url_spec.host_regex, - http->host, 0, NULL, 0))); -#endif + || regex_matches(pattern->pattern.url_spec.host_regex, http->host)); } #endif return ((NULL == pattern->pattern.url_spec.dbuffer) || (0 == domain_match(pattern, http))); @@ -1512,11 +1529,7 @@ static int host_matches(const struct http_request *http, static int path_matches(const char *path, const struct pattern_spec *pattern) { return ((NULL == pattern->pattern.url_spec.preg) -#ifdef HAVE_PCRE2 - || (pcre2_pattern_matches(pattern->pattern.url_spec.preg, path))); -#else - || (0 == regexec(pattern->pattern.url_spec.preg, path, 0, NULL, 0))); -#endif + || regex_matches(pattern->pattern.url_spec.preg, path)); }