Skip to content
Permalink
Browse files

Code style OCD

  • Loading branch information...
Dridi committed Jul 3, 2019
1 parent b69cbd0 commit 9c5e11fcde41b83c9983905c0725f051eb929f7c
Showing with 49 additions and 51 deletions.
  1. +4 −5 lib/libvmod_blob/base64.c
  2. +20 −18 lib/libvmod_blob/hex.c
  3. +8 −9 lib/libvmod_blob/id.c
  4. +15 −15 lib/libvmod_blob/url.c
  5. +2 −4 lib/libvmod_blob/vmod_blob.h
@@ -56,7 +56,7 @@ 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)
const size_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)
char *restrict const buf, const size_t buflen,
const char *restrict const inbuf, const size_t inlength)
{
const struct b64_alphabet *alpha = &b64_alphabet[enc];
char *p = buf;
@@ -131,8 +131,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 struct strands *restrict const strings)
const size_t buflen, ssize_t inlen, VCL_STRANDS strings)
{
const struct b64_alphabet *alpha = &b64_alphabet[dec];
char *dest = buf;
@@ -27,16 +27,17 @@
*/

#include "config.h"
#include <ctype.h>

#include "hex.h"
#include <ctype.h>

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

#include "vmod_blob.h"

#include "hex.h"

const char hex_alphabet[][16] = {
"0123456789abcdef",
"0123456789ABCDEF"
@@ -48,12 +49,12 @@ const char hex_alphabet[][16] = {
* into 55 bytes (cacheline friendly).
*/
const uint8_t nibble[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
ILL, ILL, ILL, ILL, ILL, ILL, ILL, 10, 11, 12,
13, 14, 15, ILL, ILL, ILL, ILL, ILL, ILL, ILL,
ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL,
ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, 10,
11, 12, 13, 14, 15
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
ILL, ILL, ILL, ILL, ILL, ILL, ILL, 10, 11, 12,
13, 14, 15, ILL, ILL, ILL, ILL, ILL, ILL, ILL,
ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL,
ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, 10,
11, 12, 13, 14, 15
};

size_t
@@ -76,11 +77,12 @@ 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)
char *restrict const buf, const size_t buflen,
const char *restrict const in, const size_t inlen)
{
char *p = buf;
const char *alphabet = hex_alphabet[0];
int i;

AN(buf);
assert(enc == HEX);
@@ -92,7 +94,7 @@ hex_encode(const enum encoding enc, const enum case_e kase,
if (kase == UPPER)
alphabet = hex_alphabet[1];

for (int i = 0; i < inlen; i++) {
for (i = 0; i < inlen; i++) {
*p++ = alphabet[(in[i] & 0xf0) >> 4];
*p++ = alphabet[in[i] & 0x0f];
}
@@ -102,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 struct strands *restrict const strings)
const size_t buflen, ssize_t n, VCL_STRANDS strings)
{
char *dest = buf;
const char *b;
const char *b, *s;
unsigned char extranib = 0;
size_t len = 0;
int i;

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

for (int i = 0; i < strings->n; i++) {
const char *s = strings->p[i];
for (i = 0; i < strings->n; i++) {
s = strings->p[i];

if (s == NULL)
continue;
@@ -143,8 +145,8 @@ hex_decode(const enum encoding dec, char *restrict const buf,
len++;
}

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

if (s == NULL || *s == '\0')
continue;
@@ -27,6 +27,7 @@
*/

#include "config.h"

#include <string.h>

#include "vdef.h"
@@ -49,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)
char *restrict const buf, const size_t buflen,
const char *restrict const in, const size_t inlen)
{
(void) enc;
(void) kase;
@@ -66,12 +67,12 @@ 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 struct strands *restrict const strings)
id_decode(const enum encoding enc, char *restrict const buf,
const size_t buflen, ssize_t n, VCL_STRANDS strings)
{
const char *s;
char *dest = buf;
size_t outlen = 0, c = SIZE_MAX;
size_t len, outlen = 0, c = SIZE_MAX;

(void) enc;
AN(buf);
@@ -81,9 +82,7 @@ id_decode(const enum encoding enc,
c = n;

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

s = strings->p[i];
if (s == NULL || *s == '\0')
continue;
len = strlen(s);
@@ -28,14 +28,14 @@

#include "config.h"

#include "hex.h"

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

#include "vmod_blob.h"

#include "hex.h"

/* Decoder states */
enum state_e {
NORMAL,
@@ -60,10 +60,10 @@ url_decode_l(size_t l)
* (locale-independent and cacheline friendly)
*/
static const uint8_t unreserved[] = {
0x0, 0x0, 0x0, 0x0, 0x0, 0x60, 0xff, 0x3,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xff, 0x03,
0xfe, 0xff, 0xff, 0x87, 0xfe, 0xff, 0xff, 0x47,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

static inline int
@@ -80,12 +80,13 @@ 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)
char *restrict const buf, const size_t buflen,
const char *restrict const in, const size_t inlen)
{
char *p = buf;
const char * const end = buf + buflen;
const char *alphabet = hex_alphabet[0];
int i;

AN(buf);
assert(enc == URL);
@@ -95,7 +96,7 @@ url_encode(const enum encoding enc, const enum case_e kase,
if (kase == UPPER)
alphabet = hex_alphabet[1];

for (int i = 0; i < inlen; i++) {
for (i = 0; i < inlen; i++) {
if (isunreserved(in[i])) {
if (p == end)
return (-1);
@@ -115,14 +116,15 @@ 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 struct strands *restrict const strings)
const size_t buflen, ssize_t n, VCL_STRANDS strings)
{
char *dest = buf;
const char * const end = buf + buflen;
const char *s;
size_t len = SIZE_MAX;
uint8_t nib = 0;
uint8_t nib = 0, nib2;
enum state_e state = NORMAL;
int i;

AN(buf);
AN(strings);
@@ -131,14 +133,12 @@ url_decode(const enum encoding dec, char *restrict const buf,
if (n >= 0)
len = n;

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

if (s == NULL || *s == '\0')
continue;
while (*s && len) {
uint8_t nib2;

switch (state) {
case NORMAL:
if (*s == '%')
@@ -107,10 +107,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,
const struct strands *restrict const strings);
typedef ssize_t decode_f(const enum encoding dec, char *restrict const buf,
const size_t buflen, const ssize_t inlen, VCL_STRANDS strings);

/* id.c */
len_f id_encode_l;

0 comments on commit 9c5e11f

Please sign in to comment.
You can’t perform that action at this time.