[master] 10571f6 Move base64 implementation to varnishncsa

Tollef Fog Heen tfheen at varnish-cache.org
Mon Jun 6 10:47:49 CEST 2011


commit 10571f624c85cf24495642ee5066034510c353b4
Author: Tollef Fog Heen <tfheen at err.no>
Date:   Mon Jun 6 10:43:39 2011 +0200

    Move base64 implementation to varnishncsa

diff --git a/bin/varnishncsa/Makefile.am b/bin/varnishncsa/Makefile.am
index e4a2880..f7f4d56 100644
--- a/bin/varnishncsa/Makefile.am
+++ b/bin/varnishncsa/Makefile.am
@@ -8,6 +8,7 @@ dist_man_MANS = varnishncsa.1
 
 varnishncsa_SOURCES = \
 	varnishncsa.c \
+	base64.c \
 	$(top_builddir)/lib/libvarnish/flopen.c \
 	$(top_builddir)/lib/libvarnish/vpf.c
 
diff --git a/bin/varnishncsa/base64.c b/bin/varnishncsa/base64.c
new file mode 100644
index 0000000..4ff88ce
--- /dev/null
+++ b/bin/varnishncsa/base64.c
@@ -0,0 +1,87 @@
+/*
+ * Written by Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * This file is in the public domain.
+ */
+
+#include "config.h"
+
+#include <sys/types.h>
+#include "varnishapi.h"
+
+static const char b64[] =
+    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+static char i64[256];
+
+void
+VB64_init(void)
+{
+	int i;
+	const char *p;
+
+	for (i = 0; i < 256; i++)
+		i64[i] = -1;
+	for (p = b64, i = 0; *p; p++, i++)
+		i64[(int)*p] = (char)i;
+	i64['='] = 0;
+}
+
+int
+VB64_decode(char *d, unsigned dlen, const char *s)
+{
+	unsigned u, v, l;
+	int i;
+
+	u = 0;
+	l = 0;
+	while (*s) {
+		for (v = 0; v < 4; v++) {
+			if (!*s)
+				break;
+			i = i64[(int)*s++];
+			if (i < 0)
+				return (-1);
+			u <<= 6;
+			u |= i;
+		}
+		for (v = 0; v < 3; v++) {
+			if (l >= dlen - 1)
+				return (-1);
+			*d = (u >> 16) & 0xff;
+			u <<= 8;
+			l++;
+			d++;
+		}
+	}
+	*d = '\0';
+	return (0);
+}
+
+#ifdef TEST_DRIVER
+#include <stdio.h>
+
+const char *test1 =
+"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz"
+"IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg"
+"dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu"
+"dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo"
+"ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=";
+
+int
+main(int argc, char **argv)
+{
+	int i;
+	char buf[BUFSIZ];
+	unsigned l;
+
+	(void)argc;
+	(void)argv;
+
+	VB64_init();
+	l = sizeof buf;
+	VB64_decode(buf, &l, test1);
+	printf("%s\n", buf);
+	return (0);
+}
+#endif
diff --git a/lib/libvarnishapi/Makefile.am b/lib/libvarnishapi/Makefile.am
index 0dff413..e30c400 100644
--- a/lib/libvarnishapi/Makefile.am
+++ b/lib/libvarnishapi/Makefile.am
@@ -21,7 +21,6 @@ libvarnishapi_la_SOURCES = \
 	../libvarnish/vre.c \
 	../libvarnish/vsb.c \
 	../libvarnish/vsha256.c \
-	base64.c \
 	vsm.c \
 	vsl_arg.c \
 	vsl.c \
diff --git a/lib/libvarnishapi/base64.c b/lib/libvarnishapi/base64.c
deleted file mode 100644
index 4ff88ce..0000000
--- a/lib/libvarnishapi/base64.c
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Written by Poul-Henning Kamp <phk at phk.freebsd.dk>
- *
- * This file is in the public domain.
- */
-
-#include "config.h"
-
-#include <sys/types.h>
-#include "varnishapi.h"
-
-static const char b64[] =
-    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
-static char i64[256];
-
-void
-VB64_init(void)
-{
-	int i;
-	const char *p;
-
-	for (i = 0; i < 256; i++)
-		i64[i] = -1;
-	for (p = b64, i = 0; *p; p++, i++)
-		i64[(int)*p] = (char)i;
-	i64['='] = 0;
-}
-
-int
-VB64_decode(char *d, unsigned dlen, const char *s)
-{
-	unsigned u, v, l;
-	int i;
-
-	u = 0;
-	l = 0;
-	while (*s) {
-		for (v = 0; v < 4; v++) {
-			if (!*s)
-				break;
-			i = i64[(int)*s++];
-			if (i < 0)
-				return (-1);
-			u <<= 6;
-			u |= i;
-		}
-		for (v = 0; v < 3; v++) {
-			if (l >= dlen - 1)
-				return (-1);
-			*d = (u >> 16) & 0xff;
-			u <<= 8;
-			l++;
-			d++;
-		}
-	}
-	*d = '\0';
-	return (0);
-}
-
-#ifdef TEST_DRIVER
-#include <stdio.h>
-
-const char *test1 =
-"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz"
-"IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg"
-"dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu"
-"dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo"
-"ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=";
-
-int
-main(int argc, char **argv)
-{
-	int i;
-	char buf[BUFSIZ];
-	unsigned l;
-
-	(void)argc;
-	(void)argv;
-
-	VB64_init();
-	l = sizeof buf;
-	VB64_decode(buf, &l, test1);
-	printf("%s\n", buf);
-	return (0);
-}
-#endif



More information about the varnish-commit mailing list