summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2008-02-12 12:03:58 +0000
committerThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2008-02-12 12:03:58 +0000
commitabbad00edd7f5f3d33ae77a9d5ac338e5bea5fb3 (patch)
tree0d55fb4d8e5ad7a9376d1bccdea31104cbecacfe /lib
parentbd7029a99b0c2974265c6665638ef14a052f42ab (diff)
downloadmonitoring-plugins-abbad00edd7f5f3d33ae77a9d5ac338e5bea5fb3.tar.gz
Import Gnulib floorf and base64 and removed our old base64 library.
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1926 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am4
-rw-r--r--lib/base64.c50
-rw-r--r--lib/base64.h4
-rw-r--r--lib/tests/Makefile.am2
-rw-r--r--lib/tests/test_base64.c10
5 files changed, 9 insertions, 61 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 36ff245c..5d65bed6 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -5,8 +5,8 @@ SUBDIRS = tests
5noinst_LIBRARIES = libnagiosplug.a 5noinst_LIBRARIES = libnagiosplug.a
6 6
7 7
8libnagiosplug_a_SOURCES = utils_base.c utils_disk.c utils_tcp.c utils_cmd.c base64.c 8libnagiosplug_a_SOURCES = utils_base.c utils_disk.c utils_tcp.c utils_cmd.c
9EXTRA_DIST = utils_base.h utils_disk.h utils_tcp.h utils_cmd.h base64.h 9EXTRA_DIST = utils_base.h utils_disk.h utils_tcp.h utils_cmd.h
10 10
11INCLUDES = -I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins 11INCLUDES = -I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins
12 12
diff --git a/lib/base64.c b/lib/base64.c
deleted file mode 100644
index 1f1fcb8c..00000000
--- a/lib/base64.c
+++ /dev/null
@@ -1,50 +0,0 @@
1/****************************************************************************
2* Function to encode in Base64
3*
4* Written by Lauri Alanko
5*
6*****************************************************************************/
7
8#include "common.h"
9#include "base64.h"
10
11char *
12base64 (const char *bin, size_t len)
13{
14
15 char *buf = (char *) malloc ((len + 2) / 3 * 4 + 1);
16 size_t i = 0, j = 0;
17
18 char BASE64_END = '=';
19 char base64_table[64];
20 strncpy (base64_table, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", 64);
21
22 while (j < len - 2) {
23 buf[i++] = base64_table[bin[j] >> 2];
24 buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)];
25 buf[i++] = base64_table[((bin[j + 1] & 15) << 2) | (bin[j + 2] >> 6)];
26 buf[i++] = base64_table[bin[j + 2] & 63];
27 j += 3;
28 }
29
30 switch (len - j) {
31 case 1:
32 buf[i++] = base64_table[bin[j] >> 2];
33 buf[i++] = base64_table[(bin[j] & 3) << 4];
34 buf[i++] = BASE64_END;
35 buf[i++] = BASE64_END;
36 break;
37 case 2:
38 buf[i++] = base64_table[bin[j] >> 2];
39 buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)];
40 buf[i++] = base64_table[(bin[j + 1] & 15) << 2];
41 buf[i++] = BASE64_END;
42 break;
43 case 0:
44 break;
45 }
46
47 buf[i] = '\0';
48 return buf;
49}
50
diff --git a/lib/base64.h b/lib/base64.h
deleted file mode 100644
index 1e0a0b04..00000000
--- a/lib/base64.h
+++ /dev/null
@@ -1,4 +0,0 @@
1/* Header file for base64.c */
2
3char *base64 (const char *bin, size_t len);
4
diff --git a/lib/tests/Makefile.am b/lib/tests/Makefile.am
index 0ddc8abf..bd25ccfe 100644
--- a/lib/tests/Makefile.am
+++ b/lib/tests/Makefile.am
@@ -36,7 +36,7 @@ test_cmd_LDADD = ../utils_cmd.o ../utils_base.o
36test_base64_SOURCES = test_base64.c 36test_base64_SOURCES = test_base64.c
37test_base64_CFLAGS = -g -I.. 37test_base64_CFLAGS = -g -I..
38test_base64_LDFLAGS = -L/usr/local/lib -ltap 38test_base64_LDFLAGS = -L/usr/local/lib -ltap
39test_base64_LDADD = ../base64.o 39test_base64_LDADD = $(top_srcdir)/gl/base64.o
40 40
41test: ${noinst_PROGRAMS} 41test: ${noinst_PROGRAMS}
42 perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map {$$_ .= ".t"} @ARGV)' $(EXTRA_PROGRAMS) 42 perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map {$$_ .= ".t"} @ARGV)' $(EXTRA_PROGRAMS)
diff --git a/lib/tests/test_base64.c b/lib/tests/test_base64.c
index e3ff3e35..650cfa1a 100644
--- a/lib/tests/test_base64.c
+++ b/lib/tests/test_base64.c
@@ -18,13 +18,12 @@
18*****************************************************************************/ 18*****************************************************************************/
19 19
20#include "common.h" 20#include "common.h"
21#include "base64.h" 21#include "gl/base64.h"
22#include "tap.h" 22#include "tap.h"
23 23
24int 24int
25main (int argc, char **argv) 25main (int argc, char **argv)
26{ 26{
27#if 0 /* The current base64 function doesn't work on 8bit data */
28 char random[1024] = { 27 char random[1024] = {
29 0x8b,0xb0,0xc4,0xe2,0xfc,0x22,0x9f,0x0d,0x85,0xe7,0x2c,0xaa,0x39,0xa1,0x46,0x88, 28 0x8b,0xb0,0xc4,0xe2,0xfc,0x22,0x9f,0x0d,0x85,0xe7,0x2c,0xaa,0x39,0xa1,0x46,0x88,
30 0x50,0xe6,0x34,0x37,0x0b,0x45,0x4b,0xb8,0xb2,0x86,0x7a,0x3e,0x7f,0x0c,0x40,0x18, 29 0x50,0xe6,0x34,0x37,0x0b,0x45,0x4b,0xb8,0xb2,0x86,0x7a,0x3e,0x7f,0x0c,0x40,0x18,
@@ -180,8 +179,9 @@ main (int argc, char **argv)
180 0x46,0x62,0x5a,0x61,0x35,0x52,0x6e,0x50,0x59,0x43,0x4f,0x36,0x4f,0x70,0x4d,0x6c, 179 0x46,0x62,0x5a,0x61,0x35,0x52,0x6e,0x50,0x59,0x43,0x4f,0x36,0x4f,0x70,0x4d,0x6c,
181 0x41,0x6e,0x6a,0x4d,0x56,0x41,0x3d,0x3d 180 0x41,0x6e,0x6a,0x4d,0x56,0x41,0x3d,0x3d
182 }; 181 };
183#endif
184 182
183#if 0
184 /* The old base64 function didn't work on 8bit data, below is 7bit */
185 char random[1024] = { 185 char random[1024] = {
186 0x0b,0x30,0x44,0x62,0x7c,0x22,0x1f,0x0d,0x05,0x67,0x2c,0x2a,0x39,0x21,0x46,0x08, 186 0x0b,0x30,0x44,0x62,0x7c,0x22,0x1f,0x0d,0x05,0x67,0x2c,0x2a,0x39,0x21,0x46,0x08,
187 0x50,0x66,0x34,0x37,0x0b,0x45,0x4b,0x38,0x32,0x06,0x7a,0x3e,0x7f,0x0c,0x40,0x18, 187 0x50,0x66,0x34,0x37,0x0b,0x45,0x4b,0x38,0x32,0x06,0x7a,0x3e,0x7f,0x0c,0x40,0x18,
@@ -336,11 +336,13 @@ main (int argc, char **argv)
336 0x46,0x54,0x5a,0x61,0x5a,0x52,0x6c,0x50,0x59,0x43,0x4d,0x36,0x4f,0x68,0x4d,0x6c, 336 0x46,0x54,0x5a,0x61,0x5a,0x52,0x6c,0x50,0x59,0x43,0x4d,0x36,0x4f,0x68,0x4d,0x6c,
337 0x41,0x6e,0x68,0x4d,0x56,0x41,0x3d,0x3d,0x00 337 0x41,0x6e,0x68,0x4d,0x56,0x41,0x3d,0x3d,0x00
338 }; 338 };
339#endif
340
339 char *b64_test; 341 char *b64_test;
340 342
341 plan_tests(1); 343 plan_tests(1);
342 344
343 b64_test = base64 (random, 1024); 345 base64_encode_alloc (random, 1024, &b64_test);
344 346
345 ok(strcmp(b64_known, b64_test) == 0, 347 ok(strcmp(b64_known, b64_test) == 0,
346 "Test matching a base64 encoded 1024 bytes random string"); 348 "Test matching a base64 encoded 1024 bytes random string");