], [have_pcre2posix=no], -lpcre2-8)
fi
-if test $have_pcre2 = "no"; then
-
-AC_CHECK_LIB(pcre, pcre_compile, [
- AC_CHECK_HEADER(pcre.h, [
- AC_EGREP_HEADER(pcre_fullinfo, pcre.h, [have_pcre=yes], [AC_MSG_WARN([[pcre old version installed]]); have_pcre=no])
- ], [
- AC_CHECK_HEADER(pcre/pcre.h, [
- AC_EGREP_HEADER(pcre_fullinfo, pcre/pcre.h, [have_pcre=yes]; [AC_DEFINE(PCRE_H_IN_SUBDIR)], [AC_MSG_WARN([[pcre old version installed]]); have_pcre=no])
- ], [have_pcre=no])
- ])
-], [have_pcre=no])
-
-AC_CHECK_LIB(pcreposix, regcomp, [
- AC_CHECK_HEADER(pcreposix.h, [
- AC_EGREP_HEADER(pcreposix_regerror, pcreposix.h, [AC_MSG_WARN([[pcreposix old version installed]]); have_pcreposix=no], [have_pcreposix=yes])
- ], [
- AC_CHECK_HEADER(pcre/pcreposix.h, [
- AC_EGREP_HEADER(pcreposix_regerror, pcre/pcreposix.h, [AC_MSG_WARN([[pcreposix old version installed]]); have_pcreposix=no], [have_pcreposix=yes]; [AC_DEFINE(PCREPOSIX_H_IN_SUBDIR)])
- ], [have_pcreposix=no])
- ])
-], [have_pcreposix=no], -lpcre)
-
-fi
dnl ================================================================
dnl libpcrs is temporarily disabled.
dnl
AC_DEFINE(FEATURE_DYNAMIC_PCRE,1,[Define to dynamically link to pcre.])
fi
else
-
-if test $have_pcre = "yes"; then
- echo "using libpcre"
- STATIC_PCRE_ONLY=#
- LIBS="$LIBS -lpcre -lpcreposix"
- if test "$use_static_pcre" = "yes"; then
- pcre_dyn=no
- AC_DEFINE(PCRE_STATIC,1,[Define to statically link to pcre library on Windows.])
-# see /usr/i686-w64-mingw32/sys-root/mingw/include/pcre.h line 54
-# #if defined(_WIN32) && !defined(PCRE_STATIC)
-# # ifndef PCRE_EXP_DECL
-# # define PCRE_EXP_DECL extern __declspec(dllimport)
-# # endif
-# If you want to statically link a program against a PCRE library in the form of
-# a non-dll .a file, you must define PCRE_STATIC before including pcre.h or
-# pcrecpp.h, otherwise the pcre_malloc() and pcre_free() exported functions will
-# be declared __declspec(dllimport), with unwanted results.
- else
- pcre_dyn=yes
- AC_DEFINE(FEATURE_DYNAMIC_PCRE,1,[Define to dynamically link to pcre.])
- fi
-else
- AC_MSG_ERROR(Detected neither pcre2 nor pcre library.)
-fi
+ AC_MSG_ERROR(Failed to detect pcre2 library.)
fi
AC_DEFINE(FEATURE_CONNECTION_KEEP_ALIVE)
return "(pcrs:) At least one variable was too big and has been truncated before compilation";
default:
-#ifdef HAVE_PCRE2
pcre2_get_error_message(error, (PCRE2_UCHAR8*)buf, sizeof(buf));
-#else
- snprintf(buf, sizeof(buf),
- "Error code %d. For details, check the pcre documentation.",
- error);
-#endif
return buf;
}
}
next = job->next;
if (job->pattern != NULL)
{
-#ifdef HAVE_PCRE2
pcre2_code_free(job->pattern);
-#else
- free(job->pattern);
-#endif
}
-#ifndef HAVE_PCRE2
- if (job->hints != NULL)
- {
-#ifdef PCRE_CONFIG_JIT
- pcre_free_study(job->hints);
-#else
- free(job->hints);
-#endif
- }
-#endif
if (job->substitute != NULL)
{
if (job->substitute->text != NULL) free(job->substitute->text);
pcrs_job *newjob;
unsigned int flags;
int capturecount;
-#ifdef HAVE_PCRE2
int ret;
-#else
- int pcre_study_options = 0;
- const char *error;
-#endif
*errptr = 0;
/*
* Compile the pattern
*/
-#ifdef HAVE_PCRE2
PCRE2_SIZE error_offset;
newjob->pattern = pcre2_compile((const unsigned char *)pattern,
PCRE2_ZERO_TERMINATED, (unsigned)newjob->options, errptr,
&error_offset, NULL);
-#else
- newjob->pattern = pcre_compile(pattern, newjob->options, &error, errptr, NULL);
-#endif
if (newjob->pattern == NULL)
{
pcrs_free_job(newjob);
return NULL;
}
-#if defined(PCRE_STUDY_JIT_COMPILE) || defined(HAVE_PCRE2)
#ifdef DISABLE_PCRE_JIT_COMPILATION
#warning PCRE_STUDY_JIT_COMPILE is supported but Privoxy has been configured not to use it
#else
if (!(flags & PCRS_DYNAMIC))
{
-#ifdef HAVE_PCRE2
/* Try to enable JIT compilation but continue if it's unsupported. */
if ((ret = pcre2_jit_compile(newjob->pattern, PCRE2_JIT_COMPLETE)) &&
(ret != PCRE2_ERROR_JIT_BADOPTION))
pcrs_free_job(newjob);
return NULL;
}
-#else
- pcre_study_options = PCRE_STUDY_JIT_COMPILE;
-#endif
}
#endif
-#endif
-#ifndef HAVE_PCRE2
- /*
- * Generate hints. This has little overhead, since the
- * hints will be NULL for a boring pattern anyway.
- */
- newjob->hints = pcre_study(newjob->pattern, pcre_study_options, &error);
- if (error != NULL)
- {
- *errptr = PCRS_ERR_STUDY;
- pcrs_free_job(newjob);
- return NULL;
- }
-#endif
/*
* Determine the number of capturing subpatterns.
* This is needed for handling $+ in the substitute.
*/
-#ifdef HAVE_PCRE2
if (0 > (*errptr = pcre2_pattern_info(newjob->pattern, PCRE2_INFO_CAPTURECOUNT, &capturecount)))
-#else
- if (0 > (*errptr = pcre_fullinfo(newjob->pattern, newjob->hints, PCRE_INFO_CAPTURECOUNT, &capturecount)))
-#endif
{
pcrs_free_job(newjob);
return NULL;
submatches,
max_matches = PCRS_MAX_MATCH_INIT;
size_t newsize;
-#ifdef HAVE_PCRE2
pcrs_match *matches, *dummy;
pcre2_match_data *pcre2_matches;
size_t *offsets;
-#else
- pcrs_match *matches, *dummy;
- int offsets[3 * PCRS_MAX_SUBMATCHES];
-#endif
char *result_offset;
offset = i = 0;
return(PCRS_ERR_BADJOB);
}
-#ifdef HAVE_PCRE2
if (NULL == (pcre2_matches = pcre2_match_data_create_from_pattern(job->pattern, NULL)))
{
return(PCRS_ERR_NOMEM);
}
offsets = pcre2_get_ovector_pointer(pcre2_matches);
-#endif
+
if (NULL == (matches = (pcrs_match *)malloc((size_t)max_matches * sizeof(pcrs_match))))
{
return(PCRS_ERR_NOMEM);
*/
newsize = subject_length;
-#ifdef HAVE_PCRE2
while ((submatches = pcre2_match(job->pattern, (const unsigned char *)subject,
subject_length, (size_t)offset, 0, pcre2_matches, NULL)) > 0)
-#else
- while ((submatches = pcre_exec(job->pattern, job->hints, subject, (int)subject_length, offset, 0, offsets, 3 * PCRS_MAX_SUBMATCHES)) > 0)
-#endif
{
job->flags |= PCRS_SUCCESS;
matches[i].submatches = submatches;
offset = (int)offsets[1];
}
/* Pass pcre error through if (bad) failure */
-#ifdef HAVE_PCRE2
if (submatches < PCRE2_ERROR_NOMATCH)
-#else
- if (submatches < PCRE_ERROR_NOMATCH)
-#endif
{
free(matches);
-#ifdef HAVE_PCRE2
pcre2_match_data_free(pcre2_matches);
-#endif
+
return submatches;
}
matches_found = i;
* and append terminating null byte.
*/
if ((*result = (char *)malloc(newsize + 1
-#ifdef HAVE_PCRE2
/*
* Work around to prevent invalid reads in the jit code.
*/
+ 16
-#endif
)) == NULL)
{
free(matches);
-#ifdef HAVE_PCRE2
pcre2_match_data_free(pcre2_matches);
-#endif
+
return PCRS_ERR_NOMEM;
}
else
memcpy(result_offset, subject + offset, subject_length - (size_t)offset);
*result_length = newsize;
-#ifdef HAVE_PCRE2
pcre2_match_data_free(pcre2_matches);
-#endif
free(matches);
+
return matches_found;
}
*********************************************************************/
-#ifdef HAVE_PCRE2
#define PCRE2_CODE_UNIT_WIDTH 8
#define PCREn(x) PCRE2_ ## x
#ifndef _PCRE2_H
#include <pcre2.h>
#endif
-#else
-#define PCREn(x) PCRE_ ## x
-#ifndef _PCRE_H
-#include <pcre.h>
-#endif
-#endif
/*
* Constants:
/* A PCRS job */
typedef struct PCRS_JOB {
-#ifdef HAVE_PCRE2
- pcre2_code *pattern;
-#else
- pcre *pattern; /* The compiled pcre pattern */
- pcre_extra *hints; /* The pcre hints for the pattern */
-#endif
+ pcre2_code *pattern;
int options; /* The pcre options (numeric) */
unsigned int flags; /* The pcrs and user flags (see "Flags" above) */
pcrs_substitute *substitute; /* The compiled pcrs substitute */
*/
#ifdef STATIC_PCRE
-#ifdef HAVE_PCRE2
# include "pcre2.h"
# include "pcre2posix.h"
#else
-# include "pcre.h"
-# include "pcreposix.h"
-#endif
-#else
-# ifdef HAVE_PCRE2
-# ifdef PCRE2_H_IN_SUBDIR
-# define PCRE2_CODE_UNIT_WIDTH 8
-# include <pcre2/pcre2.h>
-# else
-# define PCRE2_CODE_UNIT_WIDTH 8
-# include <pcre2.h>
-# endif
-# ifdef PCRE2POSIX_H_IN_SUBDIR
-# include <pcre2/pcre2posix.h>
-# else
-# include <pcre2posix.h>
-# endif
+# ifdef PCRE2_H_IN_SUBDIR
+# define PCRE2_CODE_UNIT_WIDTH 8
+# include <pcre2/pcre2.h>
+# else
+# define PCRE2_CODE_UNIT_WIDTH 8
+# include <pcre2.h>
+# endif
+# ifdef PCRE2POSIX_H_IN_SUBDIR
+# include <pcre2/pcre2posix.h>
# else
-# ifdef PCRE_H_IN_SUBDIR
-# include <pcre/pcre.h>
-# else
-# include <pcre.h>
-# endif
-# ifdef PCREPOSIX_H_IN_SUBDIR
-# include <pcre/pcreposix.h>
-# else
-# include <pcreposix.h>
-# endif
+# include <pcre2posix.h>
# endif
#endif
enum crunch_reason crunch_reason; /**< Why the response was generated in the first place. */
};
-#ifdef HAVE_PCRE2
-#define REGEX_TYPE pcre2_code
-#else
-#define REGEX_TYPE regex_t
-#endif
-
struct url_spec
{
#ifdef FEATURE_PCRE_HOST_PATTERNS
- REGEX_TYPE *host_regex;/**< Regex for host matching */
+ pcre2_code *host_regex;/**< Regex for host matching */
enum host_regex_type { VANILLA_HOST_PATTERN, PCRE_HOST_PATTERN } host_regex_type;
#endif /* defined FEATURE_PCRE_HOST_PATTERNS */
int dcount; /**< How many parts to this domain? (length of dvec) */
char *port_list; /**< List of acceptable ports, or NULL to match all ports */
- REGEX_TYPE *preg; /**< Regex for matching path part */
+ pcre2_code *preg; /**< Regex for matching path part */
};
/**
union
{
struct url_spec url_spec;
- REGEX_TYPE *tag_regex;
+ pcre2_code *tag_regex;
} pattern;
unsigned int flags; /**< Bitmap with various pattern properties. */
}
-#ifdef HAVE_PCRE2
/*********************************************************************
*
* Function : compile_pattern
return JB_ERR_OK;
}
-#else
-/*********************************************************************
- *
- * Function : compile_pattern
- *
- * Description : Compiles a host, domain or TAG pattern.
- *
- * Parameters :
- * 1 : pattern = The pattern to compile.
- * 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.
- *
- * Returns : JB_ERR_OK - Success
- * JB_ERR_PARSE - Cannot parse regex
- *
- *********************************************************************/
-static jb_err compile_pattern(const char *pattern, enum regex_anchoring anchoring,
- struct pattern_spec *url, regex_t **regex)
-{
- int errcode;
- const char *fmt = NULL;
- char *rebuf;
- size_t rebuf_size;
-
- assert(pattern);
-
- if (pattern[0] == '\0')
- {
- *regex = NULL;
- return JB_ERR_OK;
- }
-
- switch (anchoring)
- {
- case NO_ANCHORING:
- fmt = "%s";
- break;
- case RIGHT_ANCHORED:
- fmt = "%s$";
- break;
- case RIGHT_ANCHORED_HOST:
- fmt = "%s\\.?$";
- break;
- case LEFT_ANCHORED:
- fmt = "^%s";
- break;
- default:
- log_error(LOG_LEVEL_FATAL,
- "Invalid anchoring in compile_pattern %d", anchoring);
- }
- rebuf_size = strlen(pattern) + strlen(fmt);
- rebuf = malloc_or_die(rebuf_size);
- *regex = zalloc_or_die(sizeof(**regex));
-
- snprintf(rebuf, rebuf_size, fmt, pattern);
-
- errcode = regcomp(*regex, rebuf, (REG_EXTENDED|REG_NOSUB|REG_ICASE));
-
- if (errcode)
- {
- size_t errlen = regerror(errcode, *regex, rebuf, rebuf_size);
- if (errlen > (rebuf_size - (size_t)1))
- {
- errlen = rebuf_size - (size_t)1;
- }
- rebuf[errlen] = '\0';
- log_error(LOG_LEVEL_ERROR, "error compiling %s from %s: %s",
- pattern, url->spec, rebuf);
- free_pattern_spec(url);
- freez(rebuf);
-
- return JB_ERR_PARSE;
- }
- freez(rebuf);
-
- return JB_ERR_OK;
-
-}
-#endif
/*********************************************************************
}
-#ifdef HAVE_PCRE2
/*********************************************************************
*
* Function : pcre2_pattern_matches
return (ret >= 0);
}
-#endif
/*********************************************************************
*
* Function : regex_matches
*
- * Description : Checks if a compiled regex pattern matches a string
- * using either pcre2 or pcre1 code.
+ * Description : Checks if a compiled regex pattern matches a string.
*
* Parameters :
* 1 : pattern = The compiled pattern
* Returns : TRUE for yes, FALSE otherwise.
*
*********************************************************************/
-int regex_matches(const REGEX_TYPE *pattern, const char *string)
+int regex_matches(const pcre2_code *pattern, const char *string)
{
-#ifdef HAVE_PCRE2
return pcre2_pattern_matches(pattern, string);
-#else
- return (0 == regexec(pattern, string, 0, NULL, 0));
-#endif
}
/*********************************************************************
{
if (pattern->pattern.tag_regex)
{
-#ifdef HAVE_PCRE2
pcre2_code_free(pattern->pattern.tag_regex);
-#else
- regfree(pattern->pattern.tag_regex);
- freez(pattern->pattern.tag_regex);
-#endif
}
return;
}
#ifdef FEATURE_PCRE_HOST_PATTERNS
if (pattern->pattern.url_spec.host_regex)
{
-#ifdef HAVE_PCRE2
pcre2_code_free(pattern->pattern.url_spec.host_regex);
-#else
- regfree(pattern->pattern.url_spec.host_regex);
- freez(pattern->pattern.url_spec.host_regex);
-#endif
}
#endif /* def FEATURE_PCRE_HOST_PATTERNS */
freez(pattern->pattern.url_spec.dbuffer);
freez(pattern->pattern.url_spec.port_list);
if (pattern->pattern.url_spec.preg)
{
-#ifdef HAVE_PCRE2
pcre2_code_free(pattern->pattern.url_spec.preg);
-#else
- regfree(pattern->pattern.url_spec.preg);
- freez(pattern->pattern.url_spec.preg);
-#endif
}
}
extern int url_match(const struct pattern_spec *pattern,
const struct http_request *http);
-int regex_matches(const REGEX_TYPE *pattern, const char *string);
+int regex_matches(const pcre2_code *pattern, const char *string);
extern jb_err create_pattern_spec(struct pattern_spec *url, char *buf);
extern void free_pattern_spec(struct pattern_spec *url);