Skip to content

Commit

Permalink
Vastly simplify the parse_encoding() and parse_case() functions now
Browse files Browse the repository at this point in the history
that VCL_ENUM have canonical pointers.
  • Loading branch information
bsdphk committed Dec 1, 2017
1 parent c91a6ce commit b6ce6d6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 159 deletions.
4 changes: 1 addition & 3 deletions lib/libvmod_blob/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ libvmod_blob_la_SOURCES = \
hex.c \
url.c \
wb.h \
wb.c \
parse_encoding.h \
parse_encoding.c
wb.c

base64.o: base64.c base64.h

Expand Down
112 changes: 0 additions & 112 deletions lib/libvmod_blob/parse_encoding.c

This file was deleted.

22 changes: 0 additions & 22 deletions lib/libvmod_blob/parse_encoding.h

This file was deleted.

37 changes: 17 additions & 20 deletions lib/libvmod_blob/vmod_blob.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@ static const struct vmod_blob_fptr {
len_f *const encode_l;
encode_f *const encode;
} func[__MAX_ENCODING] = {
[_INVALID] = {
/* make implicit null init explicit for clarity */
.decode_l = NULL,
.decode = NULL,
.encode_l = NULL,
.encode = NULL
},
[IDENTITY] = {
.decode_l = id_decode_l,
.decode = id_decode,
Expand Down Expand Up @@ -123,6 +116,19 @@ static const struct vmod_priv null_blob[1] =
}
};

#include <stdio.h>
static enum encoding
parse_encoding(VCL_ENUM e)
{
if (e == vmod_enum_BASE64) return(BASE64);
if (e == vmod_enum_BASE64URL) return(BASE64URL);
if (e == vmod_enum_BASE64URLNOPAD) return(BASE64URLNOPAD);
if (e == vmod_enum_HEX) return(HEX);
if (e == vmod_enum_IDENTITY) return(IDENTITY);
if (e == vmod_enum_URL) return(URL);
WRONG("illegal encoding enum");
}

static inline size_t
decode_l_va(enum encoding dec, const char * const p, va_list ap)
{
Expand Down Expand Up @@ -156,19 +162,10 @@ err_decode(VRT_CTX, const char *enc)
static inline enum case_e
parse_case(VCL_ENUM case_s)
{
switch (*case_s) {
case 'D':
AZ(strcmp(case_s + 1, "EFAULT"));
return DEFAULT;
case 'L':
AZ(strcmp(case_s + 1, "OWER"));
return LOWER;
case 'U':
AZ(strcmp(case_s + 1, "PPER"));
return UPPER;
default:
WRONG("illegal case enum");
}
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
Expand Down
12 changes: 10 additions & 2 deletions lib/libvmod_blob/vmod_blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@
#include <stdarg.h>
#include <sys/types.h>

#include "parse_encoding.h"
enum encoding {
IDENTITY = 1,
BASE64,
BASE64URL,
BASE64URLNOPAD,
HEX,
URL,
__MAX_ENCODING
};

#define AENC(enc) assert((enc) > _INVALID && (enc) < __MAX_ENCODING)
#define AENC(enc) assert((enc) >= IDENTITY && (enc) < __MAX_ENCODING)

/*
* The enums MUST appear in this order, since LOWER and UPPER are used to
Expand Down

0 comments on commit b6ce6d6

Please sign in to comment.