gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r4293 - GNUnet/src/applications/fs/ecrs


From: grothoff
Subject: [GNUnet-SVN] r4293 - GNUnet/src/applications/fs/ecrs
Date: Thu, 11 Jan 2007 23:40:19 -0800 (PST)

Author: grothoff
Date: 2007-01-11 23:40:15 -0800 (Thu, 11 Jan 2007)
New Revision: 4293

Added:
   GNUnet/src/applications/fs/ecrs/bincoder.c
   GNUnet/src/applications/fs/ecrs/bincodertest.c
Modified:
   GNUnet/src/applications/fs/ecrs/Makefile.am
   GNUnet/src/applications/fs/ecrs/uri.c
   GNUnet/src/applications/fs/ecrs/uritest.c
Log:
fix

Modified: GNUnet/src/applications/fs/ecrs/Makefile.am
===================================================================
--- GNUnet/src/applications/fs/ecrs/Makefile.am 2007-01-12 07:09:04 UTC (rev 
4292)
+++ GNUnet/src/applications/fs/ecrs/Makefile.am 2007-01-12 07:40:15 UTC (rev 
4293)
@@ -30,6 +30,7 @@
 
 
 check_PROGRAMS = \
+  bincodertest \
   namespacetest \
   uritest \
   metatest \
@@ -40,6 +41,11 @@
 
 TESTS = $(check_PROGRAMS)
 
+bincodertest_SOURCES = \
+  bincodertest.c 
+bincodertest_LDADD = \
+  $(top_builddir)/src/util/libgnunetutil.la 
+
 uritest_SOURCES = \
   uritest.c 
 uritest_LDADD = \
@@ -86,4 +92,4 @@
   $(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la 
 
 EXTRA_DIST = \
-  check.conf peer.conf
+  check.conf peer.conf bincoder.c

Added: GNUnet/src/applications/fs/ecrs/bincoder.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/bincoder.c  2007-01-12 07:09:04 UTC (rev 
4292)
+++ GNUnet/src/applications/fs/ecrs/bincoder.c  2007-01-12 07:40:15 UTC (rev 
4293)
@@ -0,0 +1,122 @@
+/*
+     This file is part of GNUnet.
+     (C) 2007 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file applications/fs/ecrs/bincoder.c
+ * @brief base64-ish encoder/decoder (this is NOT exactly
+ *        the traditional base64 encoding!)
+ * @author Christian Grothoff
+ */
+
+/**
+ * 64 characters for encoding, 6 bits per character
+ */
+static char * encTable__ = 
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_=";
+
+
+static unsigned int getValue__(unsigned char a) {
+  if ( (a >= '0') && (a <= '9') )
+    return a - '0';
+  if ( (a >= 'A') && (a <= 'Z') )
+    return (a - 'A' + 10);
+  if ( (a >= 'a') && (a <= 'z') )
+    return (a - 'a' + 36);
+  if (a == '_')
+    return 62;
+  if (a == '=')
+    return 63;
+  return -1;
+}
+/**
+ * Convert binary data to a string.
+ *
+ * @return converted data
+ */
+static char * 
+bin2enc(const void * data,
+       size_t size) {
+  size_t len;
+  size_t pos;
+  unsigned int bits;
+  unsigned int hbits;
+  char * ret;
+
+  GE_ASSERT(NULL, strlen(encTable__) == 64);
+  len = size * 8 / 6;
+  if (((size * 8) % 6) != 0)
+    len++;
+  ret = MALLOC(len+1);
+  ret[len] = '\0';
+  len = 0;
+  bits = 0;
+  hbits = 0;
+  for (pos=0;pos<size;pos++) {
+    bits |= ((((const unsigned char*)data)[pos]) << hbits);
+    hbits += 8;
+    while (hbits >= 6) {
+      ret[len++] = encTable__[bits & 63];
+      bits >>= 6;
+      hbits -= 6;
+    }
+  }
+  if (hbits > 0) 
+    ret[len++] = encTable__[bits & 63];
+  return ret;
+}
+
+
+/**
+ * Convert string back to binary data.
+ *
+ * @param input '\0'-terminated string 
+ * @param data where to write binary data
+ * @param size how much data should be converted
+ * @return number of characters processed from input,
+ *        -1 on error
+ */
+static int
+enc2bin(const char * input,
+       void * data,
+       size_t size) {
+  size_t len;
+  size_t pos;
+  unsigned int bits;
+  unsigned int hbits;
+
+  len = size * 8 / 6;
+  if (((size * 8) % 6) != 0)
+    len++;
+  if (strlen(input) < len)
+    return -1; /* error! */
+  bits = 0;
+  hbits = 0;
+  len = 0;
+  pos = 0;
+  for (pos=0;pos<size;pos++) {
+    while (hbits < 8) {
+      bits |= (getValue__(input[len++]) << hbits);
+      hbits += 6;
+    }
+    (((unsigned char*)data)[pos]) = (unsigned char) bits;
+    bits >>= 8;
+    hbits -= 8;
+  }
+  return len;
+}


Property changes on: GNUnet/src/applications/fs/ecrs/bincoder.c
___________________________________________________________________
Name: svn:eol-style
   + native

Added: GNUnet/src/applications/fs/ecrs/bincodertest.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/bincodertest.c      2007-01-12 07:09:04 UTC 
(rev 4292)
+++ GNUnet/src/applications/fs/ecrs/bincodertest.c      2007-01-12 07:40:15 UTC 
(rev 4293)
@@ -0,0 +1,65 @@
+/*
+     This file is part of GNUnet.
+     (C) 2007 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file applications/fs/ecrs/bincodertest.c
+ * @brief Test for bincoder.c
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util.h"
+
+#include "bincoder.c"
+
+static int testBC(int i) {
+  char * orig;
+  char * enc;
+  char dec[256];
+  int ret;
+
+  orig = MALLOC(i);
+  memset(orig, i, i);
+  enc = bin2enc(orig, i);
+  ret = enc2bin(enc,
+               dec,
+               i);
+  if ( (ret != strlen(enc)) ||
+       (0 != memcmp(orig, dec, i)) ) {
+    printf("Failed in iteration %d\n", i);
+    ret = -1;
+  }
+  FREE(enc);
+  FREE(orig);
+  return ret != -1 ? 0 : 1;
+}
+
+int main(int argc, char * argv[]) {
+  int failureCount = 0;
+  int i;
+
+  for (i=0;i<256;i++)
+    failureCount += testBC(i);
+  if (failureCount != 0)
+    return 1;
+  return 0;
+}
+
+/* end of bincodertest.c */


Property changes on: GNUnet/src/applications/fs/ecrs/bincodertest.c
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: GNUnet/src/applications/fs/ecrs/uri.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/uri.c       2007-01-12 07:09:04 UTC (rev 
4292)
+++ GNUnet/src/applications/fs/ecrs/uri.c       2007-01-12 07:40:15 UTC (rev 
4293)
@@ -166,102 +166,9 @@
   return ret;
 }
 
-/**
- * 64 characters for encoding, 6 bits per character
- */
-static char * encTable__ = 
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_=";
+#include "bincoder.c"
 
 /**
- * Convert binary data to a string.
- *
- * @return converted data
- */
-static char * 
-bin2enc(const void * data,
-       size_t size) {
-  size_t len;
-  size_t pos;
-  unsigned int bits;
-  unsigned int hbits;
-  char * ret;
-
-  GE_ASSERT(NULL, strlen(encTable__) == 64);
-  len = size * 8 / 6;
-  if (((size * 8) % 6) != 0)
-    len++;
-  ret = MALLOC(len+1);
-  ret[len] = '\0';
-  len = 0;
-  bits = 0;
-  hbits = 0;
-  for (pos=0;pos<size;pos++) {
-    bits |= ((((const unsigned char*)data)[pos]) << hbits);
-    hbits += 8;
-    while (hbits >= 6) {
-      ret[len++] = encTable__[bits & 63];
-      bits >>= 6;
-      hbits -= 6;
-    }
-  }
-  if (hbits > 0) 
-    ret[len++] = encTable__[bits & 63];
-  return ret;
-}
-
-static unsigned int getValue__(unsigned char a) {
-  if ( (a >= '0') && (a <= '9') )
-    return a - '0';
-  if ( (a >= 'A') && (a <= 'Z') )
-    return (a - 'A' + 10);
-  if ( (a >= 'a') && (a <= 'z') )
-    return (a - 'A' + 36);
-  if (a == '_')
-    return 60;
-  if (a == '=')
-    return 61;
-  return -1;
-}
-
-/**
- * Convert string back to binary data.
- *
- * @param input '\0'-terminated string 
- * @param data where to write binary data
- * @param size how much data should be converted
- * @return number of characters processed from input,
- *        -1 on error
- */
-static int
-enc2bin(const char * input,
-       void * data,
-       size_t size) {
-  size_t len;
-  size_t pos;
-  unsigned int bits;
-  unsigned int hbits;
-
-  len = size * 8 / 6;
-  if (((size * 8) % 6) != 0)
-    len++;
-  if (strlen(input) < len)
-    return -1; /* error! */
-  bits = 0;
-  hbits = 0;
-  len = 0;
-  pos = 0;
-  for (pos=0;pos<size;pos++) {
-    while (hbits < 8) {
-      bits |= (getValue__(input[len++]) << hbits);
-      hbits += 6;
-    }
-    (((unsigned char*)data)[pos]) = (unsigned char) bits;
-    bits >>= 8;
-    hbits -= 8;
-  }
-  return len;
-}
-
-/**
  * Create a (string) location URI from a Location.
  */
 static char * 
@@ -597,7 +504,7 @@
   }
   if (ret != 0)
     goto ERROR;
-  dup[npos++] = '\0';
+  dup[npos-1] = '\0';
   if (3 != SSCANF(&dup[pos],
                  "%u.%u.%u",
                  &proto,

Modified: GNUnet/src/applications/fs/ecrs/uritest.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/uritest.c   2007-01-12 07:09:04 UTC (rev 
4292)
+++ GNUnet/src/applications/fs/ecrs/uritest.c   2007-01-12 07:40:15 UTC (rev 
4293)
@@ -80,10 +80,12 @@
                             hk);
   freePrivateKey(hk);
   if (uri == NULL) {
+    GE_BREAK(NULL, 0);
     ECRS_freeUri(baseURI);
     return 1;
   }
   if (! ECRS_isLocationUri(uri)) {
+    GE_BREAK(NULL, 0);
     ECRS_freeUri(uri);
     ECRS_freeUri(baseURI);
     return 1;
@@ -91,6 +93,7 @@
   uri2 = ECRS_getContentUri(uri);
   if (! ECRS_equalsUri(baseURI,
                       uri2)) {
+    GE_BREAK(NULL, 0);
     ECRS_freeUri(uri);
     ECRS_freeUri(uri2);
     ECRS_freeUri(baseURI);
@@ -106,11 +109,13 @@
   uri2 = ECRS_stringToUri(NULL, uric);
   FREE(uric);
   if (uri2 == NULL) {
+    GE_BREAK(NULL, 0);
     ECRS_freeUri(uri);
     return 1;
   }
   if (YES != ECRS_equalsUri(uri,
                            uri2)) {
+    GE_BREAK(NULL, 0);
     ECRS_freeUri(uri);
     ECRS_freeUri(uri2);
     return 1;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]