[master] 5391143e1 vrt: Replace void pointers with the regex types
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Fri Jan 15 16:17:07 UTC 2021
commit 5391143e1aa5246ab58a6390a9c68b151a05abc1
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Tue Jan 12 17:06:32 2021 +0100
vrt: Replace void pointers with the regex types
Now that we have a proper type for regular expressions, use it in the
VRT API where it makes sense. The VRT_re_{init,fini}() functions were
moved to VPI since they are here strictly to support libvcc.
Summary: in VRT we use VCL_REGEX but in VPI we use struct vre.
diff --git a/bin/varnishd/cache/cache_vrt_re.c b/bin/varnishd/cache/cache_vrt_re.c
index f38515151..13135655c 100644
--- a/bin/varnishd/cache/cache_vrt_re.c
+++ b/bin/varnishd/cache/cache_vrt_re.c
@@ -36,6 +36,7 @@
#include <ctype.h>
#include "cache_varnishd.h"
+#include "vcc_interface.h"
static void
Tadd(char **b, char *e, const char *p, int l)
@@ -52,7 +53,7 @@ Tadd(char **b, char *e, const char *p, int l)
}
void
-VRT_re_init(void **rep, const char *re)
+VPI_re_init(vre_t **rep, const char *re)
{
vre_t *t;
const char *error;
@@ -65,7 +66,7 @@ VRT_re_init(void **rep, const char *re)
}
void
-VRT_re_fini(void *rep)
+VPI_re_fini(vre_t *rep)
{
vre_t *vv;
@@ -74,18 +75,16 @@ VRT_re_fini(void *rep)
VRE_free(&vv);
}
-int
-VRT_re_match(VRT_CTX, const char *s, void *re)
+VCL_BOOL
+VRT_re_match(VRT_CTX, const char *s, VCL_REGEX re)
{
- vre_t *t;
int i;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (s == NULL)
s = "";
AN(re);
- t = re;
- i = VRE_exec(t, s, strlen(s), 0, 0, NULL, 0, &cache_param->vre_limits);
+ i = VRE_exec(re, s, strlen(s), 0, 0, NULL, 0, &cache_param->vre_limits);
if (i >= 0)
return (1);
if (i < VRE_ERROR_NOMATCH )
@@ -93,12 +92,11 @@ VRT_re_match(VRT_CTX, const char *s, void *re)
return (0);
}
-const char *
-VRT_regsub(VRT_CTX, int all, const char *str, void *re,
- const char *sub)
+VCL_STRING
+VRT_regsub(VRT_CTX, int all, VCL_STRING str, VCL_REGEX re,
+ VCL_STRING sub)
{
int ovector[30];
- vre_t *t;
int i, l;
char *res_b;
char *res_e;
@@ -115,10 +113,9 @@ VRT_regsub(VRT_CTX, int all, const char *str, void *re,
str = "";
if (sub == NULL)
sub = "";
- t = re;
memset(ovector, 0, sizeof(ovector));
len = strlen(str);
- i = VRE_exec(t, str, len, 0, options, ovector, 30,
+ i = VRE_exec(re, str, len, 0, options, ovector, 30,
&cache_param->vre_limits);
/* If it didn't match, we can return the original string */
@@ -158,7 +155,7 @@ VRT_regsub(VRT_CTX, int all, const char *str, void *re,
break;
memset(ovector, 0, sizeof(ovector));
options |= VRE_NOTEMPTY;
- i = VRE_exec(t, str, len, offset, options, ovector, 30,
+ i = VRE_exec(re, str, len, offset, options, ovector, 30,
&cache_param->vre_limits);
if (i < VRE_ERROR_NOMATCH ) {
WS_Release(ctx->ws, 0);
diff --git a/include/vcc_interface.h b/include/vcc_interface.h
index c754af479..7303a0544 100644
--- a/include/vcc_interface.h
+++ b/include/vcc_interface.h
@@ -71,3 +71,8 @@ struct vpi_ii {
const void * p;
const char * const name;
};
+
+/* Compile time regexp */
+
+void VPI_re_init(struct vre **, const char *);
+void VPI_re_fini(struct vre *);
diff --git a/include/vrt.h b/include/vrt.h
index c88d8cb9e..70fb7e36b 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -61,6 +61,10 @@
* VRT_ban_string() signature changed
* VRT_priv_task_get() added
* VRT_priv_top_get() added
+ * VRT_re_init removed
+ * VRT_re_fini removed
+ * VRT_re_match signature changed
+ * VRT_regsub signature changed
* 12.0 (2020-09-15)
* Added VRT_DirectorResolve()
* Added VCL_STRING VRT_BLOB_string(VRT_CTX, VCL_BLOB)
@@ -458,14 +462,6 @@ VCL_BACKEND VRT_DirectorResolve(VRT_CTX, VCL_BACKEND);
void VRT_acl_log(VRT_CTX, const char *);
int VRT_acl_match(VRT_CTX, VCL_ACL, VCL_IP);
-/***********************************************************************
- * Compile time regexp
- */
-
-void VRT_re_init(void **, const char *);
-void VRT_re_fini(void *);
-int VRT_re_match(VRT_CTX, const char *, void *);
-
/***********************************************************************
* Getting hold of the various struct http
*/
@@ -495,7 +491,8 @@ VCL_BYTES VRT_CacheReqBody(VRT_CTX, VCL_BYTES maxsize);
/* Regexp related */
-const char *VRT_regsub(VRT_CTX, int all, const char *, void *, const char *);
+VCL_BOOL VRT_re_match(VRT_CTX, VCL_STRING, VCL_REGEX);
+VCL_STRING VRT_regsub(VRT_CTX, int all, VCL_STRING, VCL_REGEX, VCL_STRING);
VCL_STRING VRT_ban_string(VRT_CTX, VCL_STRING);
VCL_INT VRT_purge(VRT_CTX, VCL_DURATION, VCL_DURATION, VCL_DURATION);
VCL_VOID VRT_synth(VRT_CTX, VCL_INT, VCL_STRING);
diff --git a/lib/libvcc/vcc_utils.c b/lib/libvcc/vcc_utils.c
index 419df3fcb..9cc27c68b 100644
--- a/lib/libvcc/vcc_utils.c
+++ b/lib/libvcc/vcc_utils.c
@@ -71,12 +71,12 @@ vcc_regexp(struct vcc *tl, struct vsb *vgc_name)
if (vgc_name)
VSB_cat(vgc_name, buf);
- Fh(tl, 0, "static void *%s;\n", buf);
+ Fh(tl, 0, "static struct vre *%s;\n", buf);
ifp = New_IniFin(tl);
- VSB_printf(ifp->ini, "\tVRT_re_init(&%s, ",buf);
+ VSB_printf(ifp->ini, "\tVPI_re_init(&%s, ",buf);
EncToken(ifp->ini, tl->t);
VSB_cat(ifp->ini, ");");
- VSB_printf(ifp->fin, "\t\tVRT_re_fini(%s);", buf);
+ VSB_printf(ifp->fin, "\t\tVPI_re_fini(%s);", buf);
}
/*
More information about the varnish-commit
mailing list