Commit 5391143e authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

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.
parent 20c820e8
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <ctype.h> #include <ctype.h>
#include "cache_varnishd.h" #include "cache_varnishd.h"
#include "vcc_interface.h"
static void static void
Tadd(char **b, char *e, const char *p, int l) Tadd(char **b, char *e, const char *p, int l)
...@@ -52,7 +53,7 @@ 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 void
VRT_re_init(void **rep, const char *re) VPI_re_init(vre_t **rep, const char *re)
{ {
vre_t *t; vre_t *t;
const char *error; const char *error;
...@@ -65,7 +66,7 @@ VRT_re_init(void **rep, const char *re) ...@@ -65,7 +66,7 @@ VRT_re_init(void **rep, const char *re)
} }
void void
VRT_re_fini(void *rep) VPI_re_fini(vre_t *rep)
{ {
vre_t *vv; vre_t *vv;
...@@ -74,18 +75,16 @@ VRT_re_fini(void *rep) ...@@ -74,18 +75,16 @@ VRT_re_fini(void *rep)
VRE_free(&vv); VRE_free(&vv);
} }
int VCL_BOOL
VRT_re_match(VRT_CTX, const char *s, void *re) VRT_re_match(VRT_CTX, const char *s, VCL_REGEX re)
{ {
vre_t *t;
int i; int i;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (s == NULL) if (s == NULL)
s = ""; s = "";
AN(re); AN(re);
t = re; i = VRE_exec(re, s, strlen(s), 0, 0, NULL, 0, &cache_param->vre_limits);
i = VRE_exec(t, s, strlen(s), 0, 0, NULL, 0, &cache_param->vre_limits);
if (i >= 0) if (i >= 0)
return (1); return (1);
if (i < VRE_ERROR_NOMATCH ) if (i < VRE_ERROR_NOMATCH )
...@@ -93,12 +92,11 @@ VRT_re_match(VRT_CTX, const char *s, void *re) ...@@ -93,12 +92,11 @@ VRT_re_match(VRT_CTX, const char *s, void *re)
return (0); return (0);
} }
const char * VCL_STRING
VRT_regsub(VRT_CTX, int all, const char *str, void *re, VRT_regsub(VRT_CTX, int all, VCL_STRING str, VCL_REGEX re,
const char *sub) VCL_STRING sub)
{ {
int ovector[30]; int ovector[30];
vre_t *t;
int i, l; int i, l;
char *res_b; char *res_b;
char *res_e; char *res_e;
...@@ -115,10 +113,9 @@ VRT_regsub(VRT_CTX, int all, const char *str, void *re, ...@@ -115,10 +113,9 @@ VRT_regsub(VRT_CTX, int all, const char *str, void *re,
str = ""; str = "";
if (sub == NULL) if (sub == NULL)
sub = ""; sub = "";
t = re;
memset(ovector, 0, sizeof(ovector)); memset(ovector, 0, sizeof(ovector));
len = strlen(str); 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); &cache_param->vre_limits);
/* If it didn't match, we can return the original string */ /* 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, ...@@ -158,7 +155,7 @@ VRT_regsub(VRT_CTX, int all, const char *str, void *re,
break; break;
memset(ovector, 0, sizeof(ovector)); memset(ovector, 0, sizeof(ovector));
options |= VRE_NOTEMPTY; 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); &cache_param->vre_limits);
if (i < VRE_ERROR_NOMATCH ) { if (i < VRE_ERROR_NOMATCH ) {
WS_Release(ctx->ws, 0); WS_Release(ctx->ws, 0);
......
...@@ -71,3 +71,8 @@ struct vpi_ii { ...@@ -71,3 +71,8 @@ struct vpi_ii {
const void * p; const void * p;
const char * const name; const char * const name;
}; };
/* Compile time regexp */
void VPI_re_init(struct vre **, const char *);
void VPI_re_fini(struct vre *);
...@@ -61,6 +61,10 @@ ...@@ -61,6 +61,10 @@
* VRT_ban_string() signature changed * VRT_ban_string() signature changed
* VRT_priv_task_get() added * VRT_priv_task_get() added
* VRT_priv_top_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) * 12.0 (2020-09-15)
* Added VRT_DirectorResolve() * Added VRT_DirectorResolve()
* Added VCL_STRING VRT_BLOB_string(VRT_CTX, VCL_BLOB) * Added VCL_STRING VRT_BLOB_string(VRT_CTX, VCL_BLOB)
...@@ -458,14 +462,6 @@ VCL_BACKEND VRT_DirectorResolve(VRT_CTX, VCL_BACKEND); ...@@ -458,14 +462,6 @@ VCL_BACKEND VRT_DirectorResolve(VRT_CTX, VCL_BACKEND);
void VRT_acl_log(VRT_CTX, const char *); void VRT_acl_log(VRT_CTX, const char *);
int VRT_acl_match(VRT_CTX, VCL_ACL, VCL_IP); 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 * Getting hold of the various struct http
*/ */
...@@ -495,7 +491,8 @@ VCL_BYTES VRT_CacheReqBody(VRT_CTX, VCL_BYTES maxsize); ...@@ -495,7 +491,8 @@ VCL_BYTES VRT_CacheReqBody(VRT_CTX, VCL_BYTES maxsize);
/* Regexp related */ /* 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_STRING VRT_ban_string(VRT_CTX, VCL_STRING);
VCL_INT VRT_purge(VRT_CTX, VCL_DURATION, VCL_DURATION, VCL_DURATION); VCL_INT VRT_purge(VRT_CTX, VCL_DURATION, VCL_DURATION, VCL_DURATION);
VCL_VOID VRT_synth(VRT_CTX, VCL_INT, VCL_STRING); VCL_VOID VRT_synth(VRT_CTX, VCL_INT, VCL_STRING);
......
...@@ -71,12 +71,12 @@ vcc_regexp(struct vcc *tl, struct vsb *vgc_name) ...@@ -71,12 +71,12 @@ vcc_regexp(struct vcc *tl, struct vsb *vgc_name)
if (vgc_name) if (vgc_name)
VSB_cat(vgc_name, buf); 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); 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); EncToken(ifp->ini, tl->t);
VSB_cat(ifp->ini, ");"); VSB_cat(ifp->ini, ");");
VSB_printf(ifp->fin, "\t\tVRT_re_fini(%s);", buf); VSB_printf(ifp->fin, "\t\tVPI_re_fini(%s);", buf);
} }
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment