[master] 22480f2 straighten out the rest of the blob vmod enum handling

Nils Goroll nils.goroll at uplex.de
Sun Dec 10 12:00:08 UTC 2017


commit 22480f2e6013867333def4b1d7732eaa0a7a1767
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Sun Dec 10 12:55:06 2017 +0100

    straighten out the rest of the blob vmod enum handling

diff --git a/lib/libvmod_blob/Makefile.am b/lib/libvmod_blob/Makefile.am
index 9be1c7d..2695913 100644
--- a/lib/libvmod_blob/Makefile.am
+++ b/lib/libvmod_blob/Makefile.am
@@ -11,7 +11,8 @@ libvmod_blob_la_SOURCES = \
 	url.c \
 	wb.h \
 	wb.c \
-	tbl_encodings.h
+	tbl_encodings.h \
+	tbl_case.h
 
 base64.o: base64.c base64.h
 
diff --git a/lib/libvmod_blob/tbl_case.h b/lib/libvmod_blob/tbl_case.h
new file mode 100644
index 0000000..c5b4695
--- /dev/null
+++ b/lib/libvmod_blob/tbl_case.h
@@ -0,0 +1,8 @@
+/*
+ * this order MUST be preserved, since enum case_e LOWER and UPPER are used to
+ * index the array of cached encodings for the blob object.
+ */
+VMODENUM(LOWER)
+VMODENUM(UPPER)
+VMODENUM(DEFAULT)
+#undef VMODENUM
diff --git a/lib/libvmod_blob/vmod_blob.c b/lib/libvmod_blob/vmod_blob.c
index 7819701..6e5a198 100644
--- a/lib/libvmod_blob/vmod_blob.c
+++ b/lib/libvmod_blob/vmod_blob.c
@@ -124,6 +124,15 @@ parse_encoding(VCL_ENUM e)
 	WRONG("illegal encoding enum");
 }
 
+static enum case_e
+parse_case(VCL_ENUM e)
+{
+#define VMODENUM(n) if (e == vmod_enum_ ## n) return(n);
+#include "tbl_case.h"
+	WRONG("illegal case enum");
+}
+
+
 static inline size_t
 decode_l_va(enum encoding dec, const char * const p, va_list ap)
 {
@@ -154,15 +163,6 @@ err_decode(VRT_CTX, const char *enc)
 	}
 }
 
-static inline enum case_e
-parse_case(VCL_ENUM case_s)
-{
-	if (case_s == vmod_enum_DEFAULT)	return(DEFAULT);
-	if (case_s == vmod_enum_LOWER)		return(LOWER);
-	if (case_s == vmod_enum_UPPER)		return(UPPER);
-	WRONG("illegal case enum");
-}
-
 static inline int
 encodes_hex(enum encoding enc)
 {
diff --git a/lib/libvmod_blob/vmod_blob.h b/lib/libvmod_blob/vmod_blob.h
index ba359c1..e47dff8 100644
--- a/lib/libvmod_blob/vmod_blob.h
+++ b/lib/libvmod_blob/vmod_blob.h
@@ -31,25 +31,21 @@
 #include <sys/types.h>
 
 enum encoding {
-	IDENTITY = 1,
-	BASE64,
-	BASE64URL,
-	BASE64URLNOPAD,
-	HEX,
-	URL,
+	_INVALID = 0,
+#define VMODENUM(x) x,
+#include "tbl_encodings.h"
 	__MAX_ENCODING
 };
 
-#define AENC(enc) assert((enc) >= IDENTITY && (enc) < __MAX_ENCODING)
+#define AENC(enc) assert((enc) > _INVALID && (enc) < __MAX_ENCODING)
 
 /*
  * The enums MUST appear in this order, since LOWER and UPPER are used to
  * index the array of cached encodings for the blob object.
  */
 enum case_e {
-	LOWER,
-	UPPER,
-	DEFAULT,
+#define VMODENUM(x) x,
+#include "tbl_case.h"
 };
 
 /*


More information about the varnish-commit mailing list