-utf8 tolower/upper
authorMartin Schanzenbach <mschanzenbach@posteo.de>
Mon, 26 Mar 2012 12:32:40 +0000 (12:32 +0000)
committerMartin Schanzenbach <mschanzenbach@posteo.de>
Mon, 26 Mar 2012 12:32:40 +0000 (12:32 +0000)
src/gns/Makefile.am
src/gns/gnunet-service-gns.c
src/gns/gnunet-service-gns_resolver.c
src/include/gnunet_strings_lib.h
src/util/Makefile.am
src/util/crypto_hash.c
src/util/strings.c

index 2d47353ba0d8932997e415e6acdf68db813761a9..2b62cec536a21f1598e63601ebc83695a3286974 100644 (file)
@@ -207,7 +207,6 @@ gnunet_service_gns_LDADD = \
        $(top_builddir)/src/dns/libgnunetdnsparser.la \
        $(top_builddir)/src/dht/libgnunetdht.la \
        $(top_builddir)/src/namestore/libgnunetnamestore.la \
-  -lunistring \
   $(GN_LIBINTL)
 gnunet_service_gns_DEPENDENCIES = \
   $(top_builddir)/src/tun/libgnunettun.la \
index 2bd98fc10786fe88a407679d84d196f8b656b588..733886f3a5a6a13c292bef3b0893be48f6436983 100644 (file)
@@ -31,7 +31,6 @@
 #include "gnunet_dnsparser_lib.h"
 #include "gnunet_dht_service.h"
 #include "gnunet_namestore_service.h"
-#include <unicase.h>
 #include "gnunet_gns_service.h"
 #include "block_gns.h"
 #include "gns.h"
@@ -160,7 +159,7 @@ static struct GNUNET_TIME_Relative default_lookup_timeout;
  *
  * @param old the old name to normalize
  * @param new the buffer to write the new name to
- */
+ *
 static void
 normalize_name(const char* old, char** new)
 {
@@ -174,6 +173,9 @@ normalize_name(const char* old, char** new)
   (*new)[n_len] = '\0';
   free(tmp_name);
 }
+*/
+
+
 /**
  * Continue shutdown
  */
@@ -496,7 +498,7 @@ static void handle_shorten(void *cls,
   csh->client = client;
   csh->unique_id = sh_msg->id;
   
-  normalize_name((char*)&sh_msg[1], &nameptr);
+  GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
 
   if (strlen (name) < strlen(GNUNET_GNS_TLD)) {
     csh->name = NULL;
@@ -608,7 +610,7 @@ static void handle_get_authority(void *cls,
     return;
   }
   
-  normalize_name((char*)&sh_msg[1], &nameptr);
+  GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
 
 
   cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle));
@@ -738,7 +740,7 @@ handle_lookup(void *cls,
     return;
   }
   
-  normalize_name((char*)&sh_msg[1], &nameptr);
+  GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
   namelen = strlen(name)+1;
   clh = GNUNET_malloc(sizeof(struct ClientLookupHandle));
   clh->client = client;
index 08f15d639c94c7949f40c181201b0aaf2b57a77f..991d518e6b3927e96d7c28665973b0726a3ab938 100644 (file)
@@ -26,7 +26,6 @@
  * @author Martin Schanzenbach
  */
 #include "platform.h"
-#include <unicase.h>
 #include "gnunet_util_lib.h"
 #include "gnunet_transport_service.h"
 #include "gnunet_dns_service.h"
@@ -1988,9 +1987,8 @@ gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
   struct ResolverHandle *rh;
   struct RecordLookupHandle* rlh;
   char string_hash[MAX_DNS_LABEL_LENGTH];
-  uint8_t* normalized_zkey;
   char nzkey[MAX_DNS_LABEL_LENGTH];
-  size_t normal_len;
+  char* nzkey_ptr = nzkey;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Starting resolution for %s (type=%d)!\n",
@@ -2059,15 +2057,8 @@ gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "ZKEY is %s!\n", string_hash);
       
-      normalized_zkey = u8_toupper ((uint8_t*)string_hash,
-                                    strlen ((char *) string_hash),
-                                    NULL, UNINORM_NFD, NULL, &normal_len);
+      GNUNET_STRINGS_utf8_toupper(string_hash, &nzkey_ptr);
 
-
-      memcpy(nzkey, normalized_zkey, normal_len);
-      nzkey[normal_len] = '\0';
-      free(normalized_zkey);
-      
       if (GNUNET_OK != GNUNET_CRYPTO_short_hash_from_string(nzkey,
                                                       &rh->authority))
       {
@@ -2429,9 +2420,8 @@ gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone,
   struct NameShortenHandle *nsh;
   char string_hash[MAX_DNS_LABEL_LENGTH];
   struct GNUNET_CRYPTO_ShortHashCode zkey;
-  uint8_t* normalized_zkey;
-  size_t normal_len;
   char nzkey[MAX_DNS_LABEL_LENGTH];
+  char* nzkey_ptr = nzkey;
 
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2475,13 +2465,8 @@ gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone,
 
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "ZKEY is %s!\n", string_hash);
-
-    normalized_zkey = u8_toupper ((uint8_t*)string_hash, strlen ((char *) string_hash),
-                                  NULL, UNINORM_NFD, NULL, &normal_len);
-
-    memcpy(nzkey, normalized_zkey, normal_len);
-    nzkey[normal_len] = '\0';
-    free(normalized_zkey);
+    
+    GNUNET_STRINGS_utf8_toupper(string_hash, &nzkey_ptr);
 
     if (GNUNET_OK != GNUNET_CRYPTO_short_hash_from_string(nzkey,
                                                           &zkey))
index 55b96fc2c79156aaef3b2bf1df8861c6d996ab87..2eebfecff48b8a5a539c3bd837c95144df2aa0f0 100644 (file)
@@ -121,6 +121,27 @@ GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset);
 char *
 GNUNET_STRINGS_from_utf8 (const char *input, size_t len, const char *charset);
 
+/**
+ * Convert the utf-8 input string to lowercase
+ * Output needs to be allocated appropriately
+ *
+ * @param input input string
+ * @param output output buffer
+ */
+void
+GNUNET_STRINGS_utf8_tolower(const char* input, char** output);
+
+
+/**
+ * Convert the utf-8 input string to lowercase
+ * Output needs to be allocated appropriately
+ *
+ * @param input input string
+ * @param output output buffer
+ */
+void
+GNUNET_STRINGS_utf8_toupper(const char* input, char** output);
+
 
 /**
  * Complete filename (a la shell) from abbrevition.
index 8176056f243699c0d4b71b688b717dbdb740809a..eb049599841c7d2fbc523a18ac4ab20af9adbe64 100644 (file)
@@ -106,7 +106,7 @@ libgnunetutil_la_LIBADD = \
   $(GCLIBADD) $(WINLIB) \
   $(LIBGCRYPT_LIBS) \
   $(LTLIBICONV) \
-  -lltdl -lz $(XLIB) 
+  -lltdl -lz -lunistring $(XLIB) 
 
 libgnunetutil_la_LDFLAGS = \
   $(GN_LIB_LDFLAGS) \
index 259f62eb810e32a671803867b03a5c9f0fdc0613..4d957c00e7b74ad1cd62ef0e320f21a6abf0aa39 100644 (file)
@@ -298,7 +298,12 @@ int
 GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen,
                                 GNUNET_HashCode * result)
 {
-  return GNUNET_STRINGS_string_to_data (enc, enclen,
+  char upper_enc[enclen];
+  char* up_ptr = upper_enc;
+
+  GNUNET_STRINGS_utf8_toupper(enc, &up_ptr);
+
+  return GNUNET_STRINGS_string_to_data (upper_enc, enclen,
                                        (unsigned char*) result,
                                        sizeof (struct GNUNET_HashCode));
 }
@@ -642,7 +647,12 @@ int
 GNUNET_CRYPTO_short_hash_from_string2 (const char *enc, size_t enclen,
                                       struct GNUNET_CRYPTO_ShortHashCode * result)
 {
-  return GNUNET_STRINGS_string_to_data (enc, enclen,
+
+  char upper_enc[enclen];
+  char* up_ptr = upper_enc;
+
+  GNUNET_STRINGS_utf8_toupper(enc, &up_ptr);
+  return GNUNET_STRINGS_string_to_data (upper_enc, enclen,
                                        (unsigned char*) result,
                                        sizeof (struct GNUNET_CRYPTO_ShortHashCode));
 }
index d796d889461cdff192a359f5e3d7f4208387408f..54dee15f892e11b657b2e5523bf92fad16a88b06 100644 (file)
@@ -31,6 +31,7 @@
 #endif
 #include "gnunet_common.h"
 #include "gnunet_strings_lib.h"
+#include <unicase.h>
 
 #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
 
@@ -401,6 +402,45 @@ GNUNET_STRINGS_from_utf8 (const char *input, size_t len, const char *charset)
   return GNUNET_STRINGS_conv (input, len, "UTF-8", charset);
 }
 
+/**
+ * Convert the utf-8 input string to lowercase
+ * Output needs to be allocated appropriately
+ *
+ * @param input input string
+ * @param output output buffer
+ */
+void
+GNUNET_STRINGS_utf8_tolower(const char* input, char** output)
+{
+  uint8_t *tmp_in;
+  size_t len;
+
+  tmp_in = u8_tolower ((uint8_t*)input, strlen ((char *) input),
+                       NULL, UNINORM_NFD, NULL, &len);
+  memcpy(*output, tmp_in, len);
+  (*output)[len] = '\0';
+  free(tmp_in);
+}
+
+/**
+ * Convert the utf-8 input string to uppercase
+ * Output needs to be allocated appropriately
+ *
+ * @param input input string
+ * @param output output buffer
+ */
+void
+GNUNET_STRINGS_utf8_toupper(const char* input, char** output)
+{
+  uint8_t *tmp_in;
+  size_t len;
+
+  tmp_in = u8_toupper ((uint8_t*)input, strlen ((char *) input),
+                       NULL, UNINORM_NFD, NULL, &len);
+  memcpy(*output, tmp_in, len);
+  (*output)[len] = '\0';
+  free(tmp_in);
+}
 
 
 /**