[master] 92ad90fe9 Simplify the vmod_blob codec interface

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Fri Nov 22 14:17:06 UTC 2019


commit 92ad90fe989669764af74a976a122cf568eeac15
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Fri Nov 22 14:45:24 2019 +0100

    Simplify the vmod_blob codec interface
    
    This is a mechanical change that hides the const and restrict details of
    the codec contract in vmod_blob and makes the function signatures more
    manageable.

diff --git a/lib/libvmod_blob/base64.c b/lib/libvmod_blob/base64.c
index f900cbb76..7162b2da5 100644
--- a/lib/libvmod_blob/base64.c
+++ b/lib/libvmod_blob/base64.c
@@ -55,8 +55,8 @@ base64_decode_l(size_t l)
 }
 
 static inline int
-decode(char *restrict *restrict dest, const char *restrict const buf,
-    const size_t buflen, unsigned u, const int n)
+decode(char *restrict *restrict dest, blob_src_t buf,
+    blob_len_t buflen, unsigned u, const int n)
 {
 	char *d;
 
@@ -79,8 +79,8 @@ decode(char *restrict *restrict dest, const char *restrict const buf,
 
 ssize_t
 base64_encode(const enum encoding enc, const enum case_e kase,
-    char *restrict const buf, const size_t buflen,
-    const char *restrict const inbuf, const size_t inlength)
+    blob_dest_t buf, blob_len_t buflen,
+    blob_src_t inbuf, blob_len_t inlength)
 {
 	const struct b64_alphabet *alpha = &b64_alphabet[enc];
 	char *p = buf;
@@ -130,8 +130,8 @@ base64_encode(const enum encoding enc, const enum case_e kase,
 }
 
 ssize_t
-base64_decode(const enum encoding dec, char *restrict const buf,
-    const size_t buflen, ssize_t inlen, VCL_STRANDS strings)
+base64_decode(const enum encoding dec, blob_dest_t buf,
+    blob_len_t buflen, ssize_t inlen, VCL_STRANDS strings)
 {
 	const struct b64_alphabet *alpha = &b64_alphabet[dec];
 	const char *s;
diff --git a/lib/libvmod_blob/hex.c b/lib/libvmod_blob/hex.c
index 6476308ae..91c6124b6 100644
--- a/lib/libvmod_blob/hex.c
+++ b/lib/libvmod_blob/hex.c
@@ -77,8 +77,8 @@ hex2byte(const unsigned char hi, const unsigned char lo)
 
 ssize_t
 hex_encode(const enum encoding enc, const enum case_e kase,
-    char *restrict const buf, const size_t buflen,
-    const char *restrict const in, const size_t inlen)
+    blob_dest_t buf, blob_len_t buflen,
+    blob_src_t in, blob_len_t inlen)
 {
 	char *p = buf;
 	const char *alphabet = hex_alphabet[0];
@@ -103,8 +103,8 @@ hex_encode(const enum encoding enc, const enum case_e kase,
 }
 
 ssize_t
-hex_decode(const enum encoding dec, char *restrict const buf,
-    const size_t buflen, ssize_t n, VCL_STRANDS strings)
+hex_decode(const enum encoding dec, blob_dest_t buf,
+    blob_len_t buflen, ssize_t n, VCL_STRANDS strings)
 {
 	char *dest = buf;
 	const char *b, *s;
diff --git a/lib/libvmod_blob/id.c b/lib/libvmod_blob/id.c
index cc5efab4b..3bca1b9ab 100644
--- a/lib/libvmod_blob/id.c
+++ b/lib/libvmod_blob/id.c
@@ -50,8 +50,8 @@ id_decode_l(size_t l)
 
 ssize_t
 id_encode(const enum encoding enc, const enum case_e kase,
-    char *restrict const buf, const size_t buflen,
-    const char *restrict const in, const size_t inlen)
+    blob_dest_t buf, blob_len_t buflen,
+    blob_src_t in, blob_len_t inlen)
 {
 	(void) enc;
 	(void) kase;
@@ -67,8 +67,8 @@ id_encode(const enum encoding enc, const enum case_e kase,
 }
 
 ssize_t
-id_decode(const enum encoding enc, char *restrict const buf,
-    const size_t buflen, ssize_t n, VCL_STRANDS strings)
+id_decode(const enum encoding enc, blob_dest_t buf,
+    blob_len_t buflen, ssize_t n, VCL_STRANDS strings)
 {
 	const char *s;
 	char *dest = buf;
diff --git a/lib/libvmod_blob/url.c b/lib/libvmod_blob/url.c
index 0134d3859..65d678879 100644
--- a/lib/libvmod_blob/url.c
+++ b/lib/libvmod_blob/url.c
@@ -80,8 +80,8 @@ isoutofrange(const uint8_t c)
 
 ssize_t
 url_encode(const enum encoding enc, const enum case_e kase,
-    char *restrict const buf, const size_t buflen,
-    const char *restrict const in, const size_t inlen)
+    blob_dest_t buf, blob_len_t buflen,
+    blob_src_t in, blob_len_t inlen)
 {
 	char *p = buf;
 	const char * const end = buf + buflen;
@@ -115,8 +115,8 @@ url_encode(const enum encoding enc, const enum case_e kase,
 }
 
 ssize_t
-url_decode(const enum encoding dec, char *restrict const buf,
-    const size_t buflen, ssize_t n, VCL_STRANDS strings)
+url_decode(const enum encoding dec, blob_dest_t buf,
+    blob_len_t buflen, ssize_t n, VCL_STRANDS strings)
 {
 	char *dest = buf;
 	const char * const end = buf + buflen;
diff --git a/lib/libvmod_blob/vmod_blob.h b/lib/libvmod_blob/vmod_blob.h
index ad9f0c1f7..77ae232dc 100644
--- a/lib/libvmod_blob/vmod_blob.h
+++ b/lib/libvmod_blob/vmod_blob.h
@@ -49,6 +49,11 @@ enum case_e {
 #include "tbl_case.h"
 };
 
+typedef const size_t			blob_len_t;
+typedef const ssize_t			blob_slen_t;
+typedef char *restrict const		blob_dest_t;
+typedef const char *restrict const	blob_src_t;
+
 /*
  * Length estimate interface
  */
@@ -82,8 +87,8 @@ size_t  len_f(size_t);
  */
 typedef
 ssize_t encode_f(const enum encoding enc, const enum case_e kase,
-		 char *restrict const buf, const size_t buflen,
-		 const char *restrict const in, const size_t inlen);
+		 blob_dest_t buf, blob_len_t buflen,
+		 blob_src_t in, blob_len_t inlen);
 
 /*
  * General interface for a decoder: decode the concatenation of strings
@@ -107,8 +112,8 @@ ssize_t encode_f(const enum encoding enc, const enum case_e kase,
  *    a static constant empty BLOB
  * otherwise, the number of bytes written
  */
-typedef ssize_t decode_f(const enum encoding dec, char *restrict const buf,
-    const size_t buflen, const ssize_t inlen, VCL_STRANDS strings);
+typedef ssize_t decode_f(const enum encoding dec, blob_dest_t buf,
+    blob_len_t buflen, blob_slen_t inlen, VCL_STRANDS strings);
 
 /* id.c */
 len_f	 id_encode_l;


More information about the varnish-commit mailing list