[master] 5c55d208b Add vre_pcre2.h to contain the backend specifics of VRE

Nils Goroll nils.goroll at uplex.de
Tue Aug 3 12:34:05 UTC 2021


commit 5c55d208bdff57bab7cb6ed047e96ad1247fa627
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Mon Aug 2 16:07:38 2021 +0200

    Add vre_pcre2.h to contain the backend specifics of VRE
    
    For now, this is only VRE_unpack() to get the pcre2_code handle.
    
    If we ever change the regex backend again, we will remove
    vre_pcre2.h and add something else.
    
    Suggested by Dridi, thus authorship attributed to Dridi.

diff --git a/include/Makefile.am b/include/Makefile.am
index 818011d3d..1eeaa3537 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -67,6 +67,7 @@ nobase_pkginclude_HEADERS += \
 	vmod_abi.h \
 	vqueue.h \
 	vre.h \
+	vre_pcre2.h \
 	vdef.h \
 	vrt.h \
 	vrt_obj.h \
diff --git a/include/vre_pcre2.h b/include/vre_pcre2.h
new file mode 100644
index 000000000..f020875f8
--- /dev/null
+++ b/include/vre_pcre2.h
@@ -0,0 +1,45 @@
+/*-
+ * Copyright (c) 2021 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Access to the PCRE2 backend in VRE
+ *
+ */
+
+#ifndef VRE_H_INCLUDED
+#error Include vre.h before vre_pcre2.h
+#endif
+
+#ifndef VRE_PCRE2_H_INCLUDED
+#define VRE_PCRE2_H_INCLUDED
+
+#include <pcre2.h>
+
+pcre2_code *VRE_unpack(const vre_t *code);
+
+#endif /* VRE_PCRE2_H_INCLUDED */
diff --git a/lib/libvarnish/vre.c b/lib/libvarnish/vre.c
index ad0d31a3a..ca3029d3f 100644
--- a/lib/libvarnish/vre.c
+++ b/lib/libvarnish/vre.c
@@ -34,8 +34,6 @@
 #include <string.h>
 #include <unistd.h>
 
-#include <pcre2.h>
-
 #include "vdef.h"
 
 #include "vas.h"	// XXX Flexelint "not used" - but req'ed for assert()
@@ -43,6 +41,7 @@
 #include "miniobj.h"
 
 #include "vre.h"
+#include "vre_pcre2.h"
 
 #if !HAVE_PCRE2_SET_DEPTH_LIMIT
 #  define pcre2_set_depth_limit(r, d) pcre2_set_recursion_limit(r, d)
@@ -132,8 +131,8 @@ VRE_error(struct vsb *vsb, int err)
 	return (0);
 }
 
-static pcre2_code *
-vre_unpack(const vre_t *code)
+pcre2_code *
+VRE_unpack(const vre_t *code)
 {
 
 	CHECK_OBJ_NOTNULL(code, VRE_MAGIC);
@@ -168,7 +167,7 @@ VRE_export(const vre_t *code, size_t *sz)
 	vre_t *exp;
 
 	CHECK_OBJ_NOTNULL(code, VRE_MAGIC);
-	re = vre_unpack(code);
+	re = VRE_unpack(code);
 	AZ(pcre2_pattern_info(re, PCRE2_INFO_SIZE, sz));
 
 	exp = malloc(sizeof(*exp) + *sz);
@@ -190,7 +189,7 @@ vre_match(const vre_t *code, const char *subject, size_t length, size_t offset,
 	pcre2_code *re;
 	int matches;
 
-	re = vre_unpack(code);
+	re = VRE_unpack(code);
 
 	if (datap != NULL && *datap != NULL) {
 		data = *datap;


More information about the varnish-commit mailing list