+#ifndef DISABLE_PCRE_JIT_COMPILATION
+ /* Try to enable JIT compilation but continue if it's unsupported. */
+ if ((ret = pcre2_jit_compile(*regex, PCRE2_JIT_COMPLETE)) &&
+ (ret != PCRE2_ERROR_JIT_BADOPTION))
+ {
+ log_error(LOG_LEVEL_ERROR,
+ "Unexpected error enabling JIT compilation for %s from %s: %s",
+ pattern, url->spec, rebuf);
+ freez(rebuf);
+
+ return JB_ERR_PARSE;
+ }
+#endif
+
+ freez(rebuf);
+
+ 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);