Commit 3d1dfa39 authored by Geoff Simmons's avatar Geoff Simmons

factor out common code in hex.c and url.c

parent 2040b8a9
......@@ -11,6 +11,7 @@ libvmod_blobcode_la_SOURCES = \
id.c \
base64.h \
base64.c \
hex.h \
hex.c \
url.c \
wb.h \
......
/*-
* Copyright 2015-2016 UPLEX - Nils Goroll Systemoptimierung
* Copyright 2016 UPLEX - Nils Goroll Systemoptimierung
* All rights reserved.
*
* Authors: Nils Goroll <nils.goroll@uplex.de>
......@@ -28,26 +28,14 @@
#include <ctype.h>
#include <errno.h>
#include <stdint.h>
#include "vmod_blobcode.h"
#include "hex.h"
#include "vrt.h"
#include "vas.h"
size_t
hex_encode_l(size_t l)
{
return ((l) << 1) + 1;
}
size_t
hex_decode_l(size_t l)
{
return ((l) + 1) >> 1;
}
static const char hex_alphabet[][16] = {
const char hex_alphabet[][16] = {
"0123456789abcdef",
"0123456789ABCDEF"
};
......@@ -57,7 +45,7 @@ static const char hex_alphabet[][16] = {
* hex digits with their binary values. This fits all of the hex digits
* into 55 bytes (cacheline friendly).
*/
static const uint8_t nibble[] = {
const uint8_t nibble[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 10, 11, 12,
13, 14, 15, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
......@@ -66,6 +54,18 @@ static const uint8_t nibble[] = {
11, 12, 13, 14, 15
};
size_t
hex_encode_l(size_t l)
{
return ((l) << 1) + 1;
}
size_t
hex_decode_l(size_t l)
{
return ((l) + 1) >> 1;
}
static inline char
hex2byte(const unsigned char hi, const unsigned char lo)
{
......
/*-
* Copyright 2016 UPLEX - Nils Goroll Systemoptimierung
* All rights reserved.
*
* Authors: Nils Goroll <nils.goroll@uplex.de>
* Geoffrey Simmons <geoffrey.simmons@uplex.de>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <stdint.h>
/* These are defined in hex.c */
extern const char hex_alphabet[][16];
extern const uint8_t nibble[];
......@@ -27,9 +27,9 @@
*/
#include <errno.h>
#include <stdint.h>
#include "vmod_blobcode.h"
#include "hex.h"
#include "vrt.h"
#include "vas.h"
......@@ -63,31 +63,6 @@ static const uint8_t unreserved[] = {
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
};
static const char hex_alphabet[][16] = {
"0123456789abcdef",
"0123456789ABCDEF"
};
/*
* Shift the ASCII table over so that it begins at '0', and replace the
* hex digits with their binary values. This fits all of the hex digits
* into 55 bytes (cacheline friendly).
*/
static const uint8_t nibble[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 10, 11, 12,
13, 14, 15, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 10,
11, 12, 13, 14, 15
};
static inline char
hex2byte(const unsigned char hi, const unsigned char lo)
{
return (nibble[hi - '0'] << 4) | nibble[lo - '0'];
}
static inline int
isunreserved(const uint8_t c)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment