Skip to content

Commit

Permalink
VMOD blob uses STRANDS instead of STRING_LIST.
Browse files Browse the repository at this point in the history
  • Loading branch information
slimhazard committed Aug 16, 2018
1 parent bbc34e2 commit d9f3188
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 102 deletions.
12 changes: 7 additions & 5 deletions lib/libvmod_blob/base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
#include "config.h"
#include <errno.h>

#include "base64.h"

#include "vdef.h"
#include "vrt.h"
#include "vas.h"

#include "base64.h"

#define base64_l(l) (((l) << 2) / 3)

size_t
Expand Down Expand Up @@ -133,7 +133,7 @@ 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,
const char *const p, va_list ap)
const struct strands *restrict const strings)
{
const struct b64_alphabet *alpha = &b64_alphabet[dec];
char *dest = buf;
Expand All @@ -143,12 +143,14 @@ base64_decode(const enum encoding dec, char *restrict const buf,

AN(buf);
AN(alpha);
AN(strings);

if (inlen >= 0)
len = inlen;

for (const char *s = p; len > 0 && s != vrt_magic_string_end;
s = va_arg(ap, const char *)) {
for (int i = 0; len > 0 && i < strings->n; i++) {
const char *s = strings->p[i];

if (s == NULL)
continue;
if (*s && term) {
Expand Down
19 changes: 10 additions & 9 deletions lib/libvmod_blob/hex.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@
#include <ctype.h>
#include <errno.h>

#include "vmod_blob.h"
#include "hex.h"

#include "vdef.h"
#include "vrt.h"
#include "vas.h"

#include "vmod_blob.h"

const char hex_alphabet[][16] = {
"0123456789abcdef",
"0123456789ABCDEF"
Expand Down Expand Up @@ -103,20 +104,20 @@ 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,
const char *restrict const p, va_list ap)
const struct strands *restrict const strings)
{
char *dest = buf;
const char *b;
unsigned char extranib = 0;
ssize_t len = 0;
va_list ap2;

AN(buf);
AN(strings);
assert(dec == HEX);

va_copy(ap2, ap);
for (const char *s = p; s != vrt_magic_string_end;
s = va_arg(ap2, const char *)) {
for (int i = 0; i < strings->n; i++) {
const char *s = strings->p[i];

if (s == NULL)
continue;
b = s;
Expand All @@ -130,7 +131,6 @@ hex_decode(const enum encoding dec, char *restrict const buf,
break;
len += s - b;
}
va_end(ap2);

if (len == 0)
return 0;
Expand All @@ -150,8 +150,9 @@ hex_decode(const enum encoding dec, char *restrict const buf,
len++;
}

for (const char *s = p; len > 0 && s != vrt_magic_string_end;
s = va_arg(ap, const char *)) {
for (int i = 0; len > 0 && i < strings->n; i++) {
const char *s = strings->p[i];

if (s == NULL || *s == '\0')
continue;
if (extranib) {
Expand Down
11 changes: 6 additions & 5 deletions lib/libvmod_blob/id.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
#include <string.h>
#include <errno.h>

#include "vmod_blob.h"

#include "vdef.h"
#include "vrt.h"
#include "vas.h"

#include "vmod_blob.h"

size_t
id_encode_l(size_t l)
{
Expand Down Expand Up @@ -69,20 +69,21 @@ 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, const char *restrict const p, va_list ap)
ssize_t n, const struct strands *restrict const strings)
{
char *dest = buf;
size_t outlen = 0, c = SIZE_MAX;

(void) enc;
AN(buf);
AN(strings);

if (n >= 0)
c = n;

for (const char *s = p; c > 0 && s != vrt_magic_string_end;
s = va_arg(ap, const char *)) {
for (int i = 0; c > 0 && i < strings->n; i++) {
size_t len;
const char *s = strings->p[i];

if (s == NULL || *s == '\0')
continue;
Expand Down
13 changes: 8 additions & 5 deletions lib/libvmod_blob/url.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@
#include "config.h"
#include <errno.h>

#include "vmod_blob.h"
#include "hex.h"

#include "vdef.h"
#include "vrt.h"
#include "vas.h"

#include "vmod_blob.h"

/* Decoder states */
enum state_e {
NORMAL,
Expand Down Expand Up @@ -115,8 +116,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, const char *restrict const p,
va_list ap)
const size_t buflen, ssize_t n,
const struct strands *restrict const strings)
{
char *dest = buf;
const char * const end = buf + buflen;
Expand All @@ -125,13 +126,15 @@ url_decode(const enum encoding dec, char *restrict const buf,
enum state_e state = NORMAL;

AN(buf);
AN(strings);
assert(dec == URL);

if (n >= 0 && (size_t)n < len)
len = n;

for (const char *s = p; len > 0 && s != vrt_magic_string_end;
s = va_arg(ap, const char *)) {
for (int i = 0; len > 0 && i < strings->n; i++) {
const char *s = strings->p[i];

if (s == NULL || *s == '\0')
continue;
while (*s && len) {
Expand Down
6 changes: 3 additions & 3 deletions lib/libvmod_blob/vmod.vcc
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ affect alphabetic characters that are not percent-encoded.

$Function BLOB decode(ENUM {IDENTITY, BASE64, BASE64URL, BASE64URLNOPAD,
HEX, URL} decoding="IDENTITY", INT length=0,
STRING_LIST encoded)
STRANDS encoded)

Returns the BLOB derived from the string ``encoded`` according to the
scheme specified by ``decoding``.
Expand Down Expand Up @@ -231,7 +231,7 @@ $Function STRING transcode(ENUM {IDENTITY, BASE64, BASE64URL, BASE64URLNOPAD,
ENUM {IDENTITY, BASE64, BASE64URL, BASE64URLNOPAD,
HEX, URL} encoding="IDENTITY",
ENUM {LOWER, UPPER, DEFAULT} case="DEFAULT",
INT length=0, STRING_LIST encoded)
INT length=0, STRANDS encoded)

Translates from one encoding to another, by first decoding the string
``encoded`` according to the scheme ``decoding``, and then returning
Expand Down Expand Up @@ -300,7 +300,7 @@ BLOB.

$Object blob(ENUM {IDENTITY, BASE64, BASE64URL, BASE64URLNOPAD, HEX,
URL} decoding="IDENTITY",
STRING_LIST encoded)
STRANDS encoded)

Creates an object that contains the BLOB derived from the string
``encoded`` according to the scheme ``decoding``.
Expand Down
Loading

0 comments on commit d9f3188

Please sign in to comment.