[master] 0b95ce0 Include file and other polishing
Poul-Henning Kamp
phk at FreeBSD.org
Wed Nov 1 11:07:05 UTC 2017
commit 0b95ce01636c7db9702956a87475851ffead0584
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Nov 1 11:06:02 2017 +0000
Include file and other polishing
diff --git a/include/vrt.h b/include/vrt.h
index 391a9e3..2c661a0 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -193,19 +193,6 @@ struct vmod_data {
};
/***********************************************************************
- * Enum for which HTTP header-sets we can access
- */
-
-enum gethdr_e {
- HDR_REQ,
- HDR_REQ_TOP,
- HDR_RESP,
- HDR_OBJ,
- HDR_BEREQ,
- HDR_BERESP
-};
-
-/***********************************************************************
* Enum for events sent to compiled VCL and from there to Vmods
*/
@@ -218,13 +205,6 @@ enum vcl_event_e {
/***********************************************************************/
-struct gethdr_s {
- enum gethdr_e where;
- const char *what;
-};
-
-/***********************************************************************/
-
extern const void * const vrt_magic_string_end;
extern const void * const vrt_magic_string_unset;
@@ -299,11 +279,8 @@ struct vrt_backend_probe {
VRT_BACKEND_PROBE_FIELDS(const)
};
-/***********************************************************************/
-
-/*
- * other stuff.
- * XXX: document when bored
+/***********************************************************************
+ * VRT_count() refers to this structure for coordinates into the VCL source.
*/
struct vrt_ref {
@@ -314,8 +291,11 @@ struct vrt_ref {
const char *token;
};
-/* ACL related */
-#define VRT_ACL_MAXADDR 16 /* max(IPv4, IPv6) */
+void VRT_count(VRT_CTX, unsigned);
+
+/***********************************************************************
+ * Implementation details of ACLs
+ */
typedef int acl_match_f(VRT_CTX, const VCL_IP);
@@ -325,28 +305,53 @@ struct vrt_acl {
acl_match_f *match;
};
-void VRT_acl_log(VRT_CTX, const char *msg);
+void VRT_acl_log(VRT_CTX, const char *);
int VRT_acl_match(VRT_CTX, VCL_ACL, VCL_IP);
-/* req related */
+/***********************************************************************
+ * 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
+ */
+
+enum gethdr_e {
+ HDR_REQ,
+ HDR_REQ_TOP,
+ HDR_RESP,
+ HDR_OBJ,
+ HDR_BEREQ,
+ HDR_BERESP
+};
+
+struct gethdr_s {
+ enum gethdr_e where;
+ const char *what;
+};
+
+struct http *VRT_selecthttp(VRT_CTX, enum gethdr_e);
+const char *VRT_GetHdr(VRT_CTX, const struct gethdr_s *);
+
+/***********************************************************************
+ * req related
+ */
VCL_BYTES VRT_CacheReqBody(VRT_CTX, VCL_BYTES maxsize);
/* Regexp related */
-void VRT_re_init(void **, const char *);
-void VRT_re_fini(void *);
-int VRT_re_match(VRT_CTX, const char *, void *re);
-const char *VRT_regsub(VRT_CTX, int all, const char *, void *, const char *);
+const char *VRT_regsub(VRT_CTX, int all, const char *, void *, const char *);
void VRT_ban_string(VRT_CTX, const char *);
unsigned VRT_purge(VRT_CTX, double ttl, double grace, double keep);
-void VRT_count(VRT_CTX, unsigned);
void VRT_synth(VRT_CTX, unsigned, const char *);
void VRT_hit_for_pass(VRT_CTX, VCL_DURATION);
-struct http *VRT_selecthttp(VRT_CTX, enum gethdr_e);
-const char *VRT_GetHdr(VRT_CTX, const struct gethdr_s *);
void VRT_SetHdr(VRT_CTX, const struct gethdr_s *, const char *, ...);
void VRT_handling(VRT_CTX, unsigned hand);
void VRT_fail(VRT_CTX, const char *fmt, ...) __v_printflike(2,3);
@@ -385,6 +390,8 @@ VCL_VCL VRT_vcl_get(VRT_CTX, const char *);
void VRT_vcl_rel(VRT_CTX, VCL_VCL);
void VRT_vcl_select(VRT_CTX, VCL_VCL);
+typedef int vmod_event_f(VRT_CTX, struct vmod_priv *, enum vcl_event_e);
+
typedef void vmod_priv_free_f(void *);
struct vmod_priv {
void *priv;
@@ -415,12 +422,6 @@ const char *VRT_BACKEND_string(VCL_BACKEND);
const char *VRT_STEVEDORE_string(VCL_STEVEDORE);
const char *VRT_CollectString(VRT_CTX, const char *p, ...);
-typedef int vcl_event_f(VRT_CTX, enum vcl_event_e);
-typedef int vcl_init_f(VRT_CTX);
-typedef void vcl_fini_f(VRT_CTX);
-typedef void vcl_func_f(VRT_CTX);
-typedef int vmod_event_f(VRT_CTX, struct vmod_priv *, enum vcl_event_e);
-
#ifdef va_start // XXX: hackish
void *VRT_VSC_Alloc(const char *, size_t, size_t, const unsigned char *, size_t,
const char *, va_list);
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index fa03724..d1c7dd4 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -1144,6 +1144,12 @@ fo.write("\n" + tbl40("#define VCL_RET_MAX", "%d\n" % n))
fo.write("""
+
+typedef int vcl_event_f(VRT_CTX, enum vcl_event_e);
+typedef int vcl_init_f(VRT_CTX);
+typedef void vcl_fini_f(VRT_CTX);
+typedef void vcl_func_f(VRT_CTX);
+
struct VCL_conf {
unsigned magic;
#define VCL_CONF_MAGIC 0x7406c509 /* from /dev/random */
@@ -1151,7 +1157,7 @@ struct VCL_conf {
struct director **default_director;
const struct vrt_backend_probe *default_probe;
unsigned nref;
- struct vrt_ref *ref;
+ const struct vrt_ref *ref;
unsigned nsrc;
const char **srcname;
@@ -1161,7 +1167,7 @@ struct VCL_conf {
""")
for i in returns:
- fo.write("\tvcl_func_f\t*" + i[0] + "_func;\n")
+ fo.write("\tvcl_func_f\t\t\t*" + i[0] + "_func;\n")
fo.write("\n};\n")
fo.close()
diff --git a/lib/libvcc/vcc_acl.c b/lib/libvcc/vcc_acl.c
index 9dd361e..1c80487 100644
--- a/lib/libvcc/vcc_acl.c
+++ b/lib/libvcc/vcc_acl.c
@@ -39,9 +39,11 @@
#include "vcc_compile.h"
+#define ACL_MAXADDR (sizeof(struct in6_addr) + 1)
+
struct acl_e {
VTAILQ_ENTRY(acl_e) list;
- unsigned char data[VRT_ACL_MAXADDR + 1];
+ unsigned char data[ACL_MAXADDR];
unsigned mask;
unsigned not;
unsigned para;
@@ -121,7 +123,8 @@ vcc_acl_add_entry(struct vcc *tl, const struct acl_e *ae, int l,
aen->data[0] = fam & 0xff;
aen->mask += 8;
- memcpy(aen->data + 1, u, l);
+ assert(l + 1L <= sizeof aen->data);
+ memcpy(aen->data + 1L, u, l);
VTAILQ_FOREACH(ae2, &tl->acl, list) {
i = vcl_acl_cmp(aen, ae2);
@@ -344,7 +347,7 @@ vcc_acl_emit(struct vcc *tl, const char *name, const char *rname, int anon)
{
struct acl_e *ae;
int depth, l, m, i;
- unsigned at[VRT_ACL_MAXADDR + 1];
+ unsigned at[ACL_MAXADDR];
struct token *t;
struct inifin *ifp;
struct vsb *func;
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index 468a4c5..fcf1665 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -219,9 +219,9 @@ EmitCoordinates(const struct vcc *tl, struct vsb *vsb)
VSB_printf(vsb, "/* ---===### Location Counters ###===---*/\n");
- VSB_printf(vsb, "\n#define VGC_NREFS %u\n", tl->cnt + 1);
+ VSB_printf(vsb, "\n#define VGC_NREFS %u\n\n", tl->cnt + 1);
- VSB_printf(vsb, "\nstatic struct vrt_ref VGC_ref[VGC_NREFS] = {\n");
+ VSB_printf(vsb, "static const struct vrt_ref VGC_ref[VGC_NREFS] = {\n");
lin = 1;
pos = 0;
sp = 0;
diff --git a/tools/include_wash.py b/tools/include_wash.py
index 6dd12f6..1284e30 100644
--- a/tools/include_wash.py
+++ b/tools/include_wash.py
@@ -28,7 +28,7 @@ def check(fn):
for i in ("stddef.h", "stdint.h", "cache/cache.h", "cache.h"):
if i in l:
print(fn, i + " included with vrt.h")
-
+
for i in ("cache/cache.h", "cache.h"):
if i in l:
for i in (
More information about the varnish-commit
mailing list