aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2013-04-13 22:44:48 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2013-04-13 22:44:48 +0000
commit308f001bca494f7d67f6a6db0db9665f64250b90 (patch)
treef8e6b376285c7f2eea9c8fd509de277a04861ec3
parent3565b59ec0859c698c72972e53ce73e2a3dedbd7 (diff)
downloadsrc-308f001bca494f7d67f6a6db0db9665f64250b90.tar.gz
src-308f001bca494f7d67f6a6db0db9665f64250b90.zip
Clean up the ntop / pton code. Part of a patch which has been submitted
upstream but not yet adopted.
Notes
Notes: svn path=/head/; revision=249453
-rw-r--r--contrib/ldns/compat/b32_ntop.c6
-rw-r--r--contrib/ldns/compat/b32_pton.c7
-rw-r--r--contrib/ldns/compat/b64_ntop.c5
-rw-r--r--contrib/ldns/compat/b64_pton.c5
-rw-r--r--contrib/ldns/ldns/config.h24
-rw-r--r--contrib/ldns/ldns/util.h31
6 files changed, 47 insertions, 31 deletions
diff --git a/contrib/ldns/compat/b32_ntop.c b/contrib/ldns/compat/b32_ntop.c
index 038ebdc95806..e91434b17289 100644
--- a/contrib/ldns/compat/b32_ntop.c
+++ b/contrib/ldns/compat/b32_ntop.c
@@ -40,6 +40,7 @@
* IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
#include <ldns/config.h>
+#ifndef HAVE_B32_NTOP
#include <sys/types.h>
#include <sys/param.h>
@@ -61,6 +62,8 @@
#include <assert.h>
+#include <ldns/util.h>
+
static const char Base32[] =
"abcdefghijklmnopqrstuvwxyz234567";
/* "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";*/
@@ -171,7 +174,7 @@ static const char Pad32 = '=';
*/
-int
+static int
ldns_b32_ntop_ar(uint8_t const *src, size_t srclength, char *target, size_t targsize, const char B32_ar[]) {
size_t datalength = 0;
uint8_t input[5];
@@ -331,3 +334,4 @@ b32_ntop_extended_hex(uint8_t const *src, size_t srclength, char *target, size_t
return ldns_b32_ntop_ar(src, srclength, target, targsize, Base32_extended_hex);
}
+#endif /* !HAVE_B32_NTOP */
diff --git a/contrib/ldns/compat/b32_pton.c b/contrib/ldns/compat/b32_pton.c
index 9c261e615b98..28accb8dd16e 100644
--- a/contrib/ldns/compat/b32_pton.c
+++ b/contrib/ldns/compat/b32_pton.c
@@ -40,6 +40,7 @@
* IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
#include <ldns/config.h>
+#ifndef HAVE_B32_PTON
#include <sys/types.h>
#include <sys/param.h>
@@ -59,6 +60,8 @@
#include <stdlib.h>
#include <string.h>
+#include <ldns/util.h>
+
/* "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";*/
static const char Base32[] =
"abcdefghijklmnopqrstuvwxyz234567";
@@ -174,7 +177,7 @@ static const char Pad32 = '=';
it returns the number of data bytes stored at the target, or -1 on error.
*/
-int
+static int
ldns_b32_pton_ar(char const *src, size_t hashed_owner_str_len, uint8_t *target, size_t targsize, const char B32_ar[])
{
int tarindex, state, ch;
@@ -385,3 +388,5 @@ b32_pton_extended_hex(char const *src, size_t hashed_owner_str_len, uint8_t *tar
{
return ldns_b32_pton_ar(src, hashed_owner_str_len, target, targsize, Base32_extended_hex);
}
+
+#endif /* !HAVE_B32_PTON */
diff --git a/contrib/ldns/compat/b64_ntop.c b/contrib/ldns/compat/b64_ntop.c
index d0b52b514bdf..a40bad6d3447 100644
--- a/contrib/ldns/compat/b64_ntop.c
+++ b/contrib/ldns/compat/b64_ntop.c
@@ -40,6 +40,7 @@
* IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
#include <ldns/config.h>
+#ifndef HAVE_B64_NTOP
#include <sys/types.h>
#include <sys/param.h>
@@ -59,6 +60,8 @@
#include <stdlib.h>
#include <string.h>
+#include <ldns/util.h>
+
#define Assert(Cond) if (!(Cond)) abort()
static const char Base64[] =
@@ -200,3 +203,5 @@ ldns_b64_ntop(uint8_t const *src, size_t srclength, char *target, size_t targsiz
target[datalength] = '\0'; /* Returned value doesn't count \0. */
return (int) (datalength);
}
+
+#endif /* !HAVE_B64_NTOP */
diff --git a/contrib/ldns/compat/b64_pton.c b/contrib/ldns/compat/b64_pton.c
index aa637d227549..5b128e9ba29a 100644
--- a/contrib/ldns/compat/b64_pton.c
+++ b/contrib/ldns/compat/b64_pton.c
@@ -40,6 +40,7 @@
* IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
#include <ldns/config.h>
+#ifndef HAVE_B64_PTON
#include <sys/types.h>
#include <sys/param.h>
@@ -59,7 +60,7 @@
#include <stdlib.h>
#include <string.h>
-#define Assert(Cond) if (!(Cond)) abort()
+#include <ldns/util.h>
static const char Base64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -258,3 +259,5 @@ ldns_b64_pton(char const *src, uint8_t *target, size_t targsize)
return (tarindex);
}
+
+#endif /* !HAVE_B64_PTON */
diff --git a/contrib/ldns/ldns/config.h b/contrib/ldns/ldns/config.h
index 6e36ffeab959..aef1ee6c0381 100644
--- a/contrib/ldns/ldns/config.h
+++ b/contrib/ldns/ldns/config.h
@@ -489,30 +489,6 @@
extern "C" {
#endif
-#ifndef B64_PTON
-int ldns_b64_ntop(uint8_t const *src, size_t srclength,
- char *target, size_t targsize);
-/**
- * calculates the size needed to store the result of b64_ntop
- */
-/*@unused@*/
-static inline size_t ldns_b64_ntop_calculate_size(size_t srcsize)
-{
- return ((((srcsize + 2) / 3) * 4) + 1);
-}
-#endif /* !B64_PTON */
-#ifndef B64_NTOP
-int ldns_b64_pton(char const *src, uint8_t *target, size_t targsize);
-/**
- * calculates the size needed to store the result of ldns_b64_pton
- */
-/*@unused@*/
-static inline size_t ldns_b64_pton_calculate_size(size_t srcsize)
-{
- return (((((srcsize + 3) / 4) * 3)) + 1);
-}
-#endif /* !B64_NTOP */
-
#ifndef HAVE_SLEEP
/* use windows sleep, in millisecs, instead */
#define sleep(x) Sleep((x)*1000)
diff --git a/contrib/ldns/ldns/util.h b/contrib/ldns/ldns/util.h
index a6441d07e2ba..bb639b6a85ec 100644
--- a/contrib/ldns/ldns/util.h
+++ b/contrib/ldns/ldns/util.h
@@ -325,7 +325,7 @@ uint16_t ldns_get_random(void);
*/
char *ldns_bubblebabble(uint8_t *data, size_t len);
-#ifndef B32_NTOP
+#ifndef HAVE_B32_NTOP
int ldns_b32_ntop(uint8_t const *src, size_t srclength,
char *target, size_t targsize);
int b32_ntop(uint8_t const *src, size_t srclength,
@@ -343,8 +343,8 @@ INLINE size_t ldns_b32_ntop_calculate_size(size_t srcsize)
size_t result = ((((srcsize / 5) * 8) - 2) + 2);
return result;
}
-#endif /* !B32_NTOP */
-#ifndef B32_PTON
+#endif /* !HAVE_B32_NTOP */
+#ifndef HAVE_B32_PTON
int ldns_b32_pton(char const *src, size_t hashed_owner_str_len, uint8_t *target, size_t targsize);
int b32_pton(char const *src, size_t hashed_owner_str_len, uint8_t *target, size_t targsize);
int ldns_b32_pton_extended_hex(char const *src, size_t hashed_owner_str_len, uint8_t *target, size_t targsize);
@@ -358,7 +358,30 @@ INLINE size_t ldns_b32_pton_calculate_size(size_t srcsize)
size_t result = ((((srcsize) / 8) * 5));
return result;
}
-#endif /* !B32_PTON */
+#endif /* !HAVE_B32_PTON */
+#ifndef HAVE_B64_NTOP
+int ldns_b64_ntop(uint8_t const *src, size_t srclength,
+ char *target, size_t targsize);
+/**
+ * calculates the size needed to store the result of b64_ntop
+ */
+/*@unused@*/
+static inline size_t ldns_b64_ntop_calculate_size(size_t srcsize)
+{
+ return ((((srcsize + 2) / 3) * 4) + 1);
+}
+#endif /* !HAVE_B64_NTOP */
+#ifndef HAVE_B64_PTON
+int ldns_b64_pton(char const *src, uint8_t *target, size_t targsize);
+/**
+ * calculates the size needed to store the result of ldns_b64_pton
+ */
+/*@unused@*/
+static inline size_t ldns_b64_pton_calculate_size(size_t srcsize)
+{
+ return (((((srcsize + 3) / 4) * 3)) + 1);
+}
+#endif /* !HAVE_B64_PTON */
INLINE time_t ldns_time(time_t *t) { return time(t); }