#include <assert.h>
#include <string.h>
-#if !defined(_WIN32) && !defined(__OS2__)
+#if !defined(_WIN32)
#include <unistd.h>
#endif
RIGHT_ANCHORED_HOST
};
static jb_err compile_vanilla_host_pattern(struct pattern_spec *url, const char *host_pattern);
-#ifdef FEATURE_EXTENDED_HOST_PATTERNS
+#ifdef FEATURE_PCRE_HOST_PATTERNS
static jb_err compile_pcre_host_pattern(struct pattern_spec *url, const char *host_pattern);
#endif
else if (strncmpic(url_noproto, "https://", 8) == 0)
{
/*
- * Should only happen when called from cgi_show_url_info().
+ * Should only happen when called from cgi_show_url_info()
+ * or when the request was https-inspected and the request
+ * line got rewritten.
*/
url_noproto += 8;
http->ssl = 1;
url_path
);
*url_path = '\0';
- http->hostport = strdup_or_die(url_noproto);
+ http->hostport = string_tolower(url_noproto);
}
else
{
* or CONNECT requests
*/
http->path = strdup_or_die("/");
- http->hostport = strdup_or_die(url_noproto);
+ http->hostport = string_tolower(url_noproto);
}
freez(buf);
+
+ if (http->hostport == NULL)
+ {
+ return JB_ERR_PARSE;
+ }
}
if (!host_available)
static jb_err compile_url_pattern(struct pattern_spec *url, char *buf)
{
char *p;
-
-#ifdef FEATURE_EXTENDED_HOST_PATTERNS
const size_t prefix_length = 18;
+
+#ifdef FEATURE_PCRE_HOST_PATTERNS
if (strncmpic(buf, "PCRE-HOST-PATTERN:", prefix_length) == 0)
{
- url->pattern.url_spec.host_regex_type = EXTENDED_HOST_PATTERN;
+ url->pattern.url_spec.host_regex_type = PCRE_HOST_PATTERN;
/* Overwrite the "PCRE-HOST-PATTERN:" prefix */
memmove(buf, buf+prefix_length, strlen(buf+prefix_length)+1);
}
{
url->pattern.url_spec.host_regex_type = VANILLA_HOST_PATTERN;
}
+#else
+ if (strncmpic(buf, "PCRE-HOST-PATTERN:", prefix_length) == 0)
+ {
+ log_error(LOG_LEVEL_ERROR,
+ "PCRE-HOST-PATTERN detected while Privoxy has been compiled "
+ "without FEATURE_PCRE_HOST_PATTERNS: %s",
+ buf);
+ /* Overwrite the "PCRE-HOST-PATTERN:" prefix */
+ memmove(buf, buf+prefix_length, strlen(buf+prefix_length)+1);
+ /*
+ * The pattern will probably not work as expected.
+ * We don't simply return JB_ERR_PARSE here so the
+ * regression tests can be loaded with and without
+ * FEATURE_PCRE_HOST_PATTERNS.
+ */
+ }
#endif
p = strchr(buf, '/');
if (buf[0] != '\0')
{
-#ifdef FEATURE_EXTENDED_HOST_PATTERNS
- if (url->pattern.url_spec.host_regex_type == EXTENDED_HOST_PATTERN)
+#ifdef FEATURE_PCRE_HOST_PATTERNS
+ if (url->pattern.url_spec.host_regex_type == PCRE_HOST_PATTERN)
{
return compile_pcre_host_pattern(url, buf);
}
}
-#ifdef FEATURE_EXTENDED_HOST_PATTERNS
+#ifdef FEATURE_PCRE_HOST_PATTERNS
/*********************************************************************
*
* Function : compile_pcre_host_pattern
{
return compile_pattern(host_pattern, RIGHT_ANCHORED_HOST, url, &url->pattern.url_spec.host_regex);
}
-#endif /* def FEATURE_EXTENDED_HOST_PATTERNS */
+#endif /* def FEATURE_PCRE_HOST_PATTERNS */
/*********************************************************************
const unsigned flag;
} tag_pattern[] = {
{ "TAG:", 4, PATTERN_SPEC_TAG_PATTERN},
- #ifdef FEATURE_CLIENT_TAGS
+#ifdef FEATURE_CLIENT_TAGS
{ "CLIENT-TAG:", 11, PATTERN_SPEC_CLIENT_TAG_PATTERN},
- #endif
+#endif
{ "NO-REQUEST-TAG:", 15, PATTERN_SPEC_NO_REQUEST_TAG_PATTERN},
{ "NO-RESPONSE-TAG:", 16, PATTERN_SPEC_NO_RESPONSE_TAG_PATTERN}
};
if (pattern == NULL) return;
freez(pattern->spec);
-#ifdef FEATURE_EXTENDED_HOST_PATTERNS
+
+ if (!(pattern->flags & PATTERN_SPEC_URL_PATTERN))
+ {
+ if (pattern->pattern.tag_regex)
+ {
+ regfree(pattern->pattern.tag_regex);
+ freez(pattern->pattern.tag_regex);
+ }
+ return;
+ }
+
+#ifdef FEATURE_PCRE_HOST_PATTERNS
if (pattern->pattern.url_spec.host_regex)
{
regfree(pattern->pattern.url_spec.host_regex);
freez(pattern->pattern.url_spec.host_regex);
}
-#endif /* def FEATURE_EXTENDED_HOST_PATTERNS */
+#endif /* def FEATURE_PCRE_HOST_PATTERNS */
freez(pattern->pattern.url_spec.dbuffer);
freez(pattern->pattern.url_spec.dvec);
pattern->pattern.url_spec.dcount = 0;
regfree(pattern->pattern.url_spec.preg);
freez(pattern->pattern.url_spec.preg);
}
- if (pattern->pattern.tag_regex)
- {
- regfree(pattern->pattern.tag_regex);
- freez(pattern->pattern.tag_regex);
- }
}
const struct pattern_spec *pattern)
{
assert(http->host != NULL);
-#ifdef FEATURE_EXTENDED_HOST_PATTERNS
- if (pattern->pattern.url_spec.host_regex_type == EXTENDED_HOST_PATTERN) {
+#ifdef FEATURE_PCRE_HOST_PATTERNS
+ if (pattern->pattern.url_spec.host_regex_type == PCRE_HOST_PATTERN)
+ {
return ((NULL == pattern->pattern.url_spec.host_regex)
|| (0 == regexec(pattern->pattern.url_spec.host_regex,
http->host, 0, NULL, 0)));