aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gns/Makefile.am1
-rw-r--r--src/gns/gnunet-service-gns.c12
-rw-r--r--src/gns/gnunet-service-gns_resolver.c25
-rw-r--r--src/include/gnunet_strings_lib.h21
-rw-r--r--src/util/Makefile.am2
-rw-r--r--src/util/crypto_hash.c14
-rw-r--r--src/util/strings.c40
7 files changed, 86 insertions, 29 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 2d47353ba..2b62cec53 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -207,7 +207,6 @@ gnunet_service_gns_LDADD = \
207 $(top_builddir)/src/dns/libgnunetdnsparser.la \ 207 $(top_builddir)/src/dns/libgnunetdnsparser.la \
208 $(top_builddir)/src/dht/libgnunetdht.la \ 208 $(top_builddir)/src/dht/libgnunetdht.la \
209 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 209 $(top_builddir)/src/namestore/libgnunetnamestore.la \
210 -lunistring \
211 $(GN_LIBINTL) 210 $(GN_LIBINTL)
212gnunet_service_gns_DEPENDENCIES = \ 211gnunet_service_gns_DEPENDENCIES = \
213 $(top_builddir)/src/tun/libgnunettun.la \ 212 $(top_builddir)/src/tun/libgnunettun.la \
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 2bd98fc10..733886f3a 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -31,7 +31,6 @@
31#include "gnunet_dnsparser_lib.h" 31#include "gnunet_dnsparser_lib.h"
32#include "gnunet_dht_service.h" 32#include "gnunet_dht_service.h"
33#include "gnunet_namestore_service.h" 33#include "gnunet_namestore_service.h"
34#include <unicase.h>
35#include "gnunet_gns_service.h" 34#include "gnunet_gns_service.h"
36#include "block_gns.h" 35#include "block_gns.h"
37#include "gns.h" 36#include "gns.h"
@@ -160,7 +159,7 @@ static struct GNUNET_TIME_Relative default_lookup_timeout;
160 * 159 *
161 * @param old the old name to normalize 160 * @param old the old name to normalize
162 * @param new the buffer to write the new name to 161 * @param new the buffer to write the new name to
163 */ 162 *
164static void 163static void
165normalize_name(const char* old, char** new) 164normalize_name(const char* old, char** new)
166{ 165{
@@ -174,6 +173,9 @@ normalize_name(const char* old, char** new)
174 (*new)[n_len] = '\0'; 173 (*new)[n_len] = '\0';
175 free(tmp_name); 174 free(tmp_name);
176} 175}
176*/
177
178
177/** 179/**
178 * Continue shutdown 180 * Continue shutdown
179 */ 181 */
@@ -496,7 +498,7 @@ static void handle_shorten(void *cls,
496 csh->client = client; 498 csh->client = client;
497 csh->unique_id = sh_msg->id; 499 csh->unique_id = sh_msg->id;
498 500
499 normalize_name((char*)&sh_msg[1], &nameptr); 501 GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
500 502
501 if (strlen (name) < strlen(GNUNET_GNS_TLD)) { 503 if (strlen (name) < strlen(GNUNET_GNS_TLD)) {
502 csh->name = NULL; 504 csh->name = NULL;
@@ -608,7 +610,7 @@ static void handle_get_authority(void *cls,
608 return; 610 return;
609 } 611 }
610 612
611 normalize_name((char*)&sh_msg[1], &nameptr); 613 GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
612 614
613 615
614 cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle)); 616 cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle));
@@ -738,7 +740,7 @@ handle_lookup(void *cls,
738 return; 740 return;
739 } 741 }
740 742
741 normalize_name((char*)&sh_msg[1], &nameptr); 743 GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
742 namelen = strlen(name)+1; 744 namelen = strlen(name)+1;
743 clh = GNUNET_malloc(sizeof(struct ClientLookupHandle)); 745 clh = GNUNET_malloc(sizeof(struct ClientLookupHandle));
744 clh->client = client; 746 clh->client = client;
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 08f15d639..991d518e6 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -26,7 +26,6 @@
26 * @author Martin Schanzenbach 26 * @author Martin Schanzenbach
27 */ 27 */
28#include "platform.h" 28#include "platform.h"
29#include <unicase.h>
30#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
31#include "gnunet_transport_service.h" 30#include "gnunet_transport_service.h"
32#include "gnunet_dns_service.h" 31#include "gnunet_dns_service.h"
@@ -1988,9 +1987,8 @@ gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
1988 struct ResolverHandle *rh; 1987 struct ResolverHandle *rh;
1989 struct RecordLookupHandle* rlh; 1988 struct RecordLookupHandle* rlh;
1990 char string_hash[MAX_DNS_LABEL_LENGTH]; 1989 char string_hash[MAX_DNS_LABEL_LENGTH];
1991 uint8_t* normalized_zkey;
1992 char nzkey[MAX_DNS_LABEL_LENGTH]; 1990 char nzkey[MAX_DNS_LABEL_LENGTH];
1993 size_t normal_len; 1991 char* nzkey_ptr = nzkey;
1994 1992
1995 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1993 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1996 "Starting resolution for %s (type=%d)!\n", 1994 "Starting resolution for %s (type=%d)!\n",
@@ -2059,15 +2057,8 @@ gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
2059 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2057 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2060 "ZKEY is %s!\n", string_hash); 2058 "ZKEY is %s!\n", string_hash);
2061 2059
2062 normalized_zkey = u8_toupper ((uint8_t*)string_hash, 2060 GNUNET_STRINGS_utf8_toupper(string_hash, &nzkey_ptr);
2063 strlen ((char *) string_hash),
2064 NULL, UNINORM_NFD, NULL, &normal_len);
2065 2061
2066
2067 memcpy(nzkey, normalized_zkey, normal_len);
2068 nzkey[normal_len] = '\0';
2069 free(normalized_zkey);
2070
2071 if (GNUNET_OK != GNUNET_CRYPTO_short_hash_from_string(nzkey, 2062 if (GNUNET_OK != GNUNET_CRYPTO_short_hash_from_string(nzkey,
2072 &rh->authority)) 2063 &rh->authority))
2073 { 2064 {
@@ -2429,9 +2420,8 @@ gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone,
2429 struct NameShortenHandle *nsh; 2420 struct NameShortenHandle *nsh;
2430 char string_hash[MAX_DNS_LABEL_LENGTH]; 2421 char string_hash[MAX_DNS_LABEL_LENGTH];
2431 struct GNUNET_CRYPTO_ShortHashCode zkey; 2422 struct GNUNET_CRYPTO_ShortHashCode zkey;
2432 uint8_t* normalized_zkey;
2433 size_t normal_len;
2434 char nzkey[MAX_DNS_LABEL_LENGTH]; 2423 char nzkey[MAX_DNS_LABEL_LENGTH];
2424 char* nzkey_ptr = nzkey;
2435 2425
2436 2426
2437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2475,13 +2465,8 @@ gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone,
2475 2465
2476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2466 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2477 "ZKEY is %s!\n", string_hash); 2467 "ZKEY is %s!\n", string_hash);
2478 2468
2479 normalized_zkey = u8_toupper ((uint8_t*)string_hash, strlen ((char *) string_hash), 2469 GNUNET_STRINGS_utf8_toupper(string_hash, &nzkey_ptr);
2480 NULL, UNINORM_NFD, NULL, &normal_len);
2481
2482 memcpy(nzkey, normalized_zkey, normal_len);
2483 nzkey[normal_len] = '\0';
2484 free(normalized_zkey);
2485 2470
2486 if (GNUNET_OK != GNUNET_CRYPTO_short_hash_from_string(nzkey, 2471 if (GNUNET_OK != GNUNET_CRYPTO_short_hash_from_string(nzkey,
2487 &zkey)) 2472 &zkey))
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h
index 55b96fc2c..2eebfecff 100644
--- a/src/include/gnunet_strings_lib.h
+++ b/src/include/gnunet_strings_lib.h
@@ -121,6 +121,27 @@ GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset);
121char * 121char *
122GNUNET_STRINGS_from_utf8 (const char *input, size_t len, const char *charset); 122GNUNET_STRINGS_from_utf8 (const char *input, size_t len, const char *charset);
123 123
124/**
125 * Convert the utf-8 input string to lowercase
126 * Output needs to be allocated appropriately
127 *
128 * @param input input string
129 * @param output output buffer
130 */
131void
132GNUNET_STRINGS_utf8_tolower(const char* input, char** output);
133
134
135/**
136 * Convert the utf-8 input string to lowercase
137 * Output needs to be allocated appropriately
138 *
139 * @param input input string
140 * @param output output buffer
141 */
142void
143GNUNET_STRINGS_utf8_toupper(const char* input, char** output);
144
124 145
125/** 146/**
126 * Complete filename (a la shell) from abbrevition. 147 * Complete filename (a la shell) from abbrevition.
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index 8176056f2..eb0495998 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -106,7 +106,7 @@ libgnunetutil_la_LIBADD = \
106 $(GCLIBADD) $(WINLIB) \ 106 $(GCLIBADD) $(WINLIB) \
107 $(LIBGCRYPT_LIBS) \ 107 $(LIBGCRYPT_LIBS) \
108 $(LTLIBICONV) \ 108 $(LTLIBICONV) \
109 -lltdl -lz $(XLIB) 109 -lltdl -lz -lunistring $(XLIB)
110 110
111libgnunetutil_la_LDFLAGS = \ 111libgnunetutil_la_LDFLAGS = \
112 $(GN_LIB_LDFLAGS) \ 112 $(GN_LIB_LDFLAGS) \
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index 259f62eb8..4d957c00e 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -298,7 +298,12 @@ int
298GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen, 298GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen,
299 GNUNET_HashCode * result) 299 GNUNET_HashCode * result)
300{ 300{
301 return GNUNET_STRINGS_string_to_data (enc, enclen, 301 char upper_enc[enclen];
302 char* up_ptr = upper_enc;
303
304 GNUNET_STRINGS_utf8_toupper(enc, &up_ptr);
305
306 return GNUNET_STRINGS_string_to_data (upper_enc, enclen,
302 (unsigned char*) result, 307 (unsigned char*) result,
303 sizeof (struct GNUNET_HashCode)); 308 sizeof (struct GNUNET_HashCode));
304} 309}
@@ -642,7 +647,12 @@ int
642GNUNET_CRYPTO_short_hash_from_string2 (const char *enc, size_t enclen, 647GNUNET_CRYPTO_short_hash_from_string2 (const char *enc, size_t enclen,
643 struct GNUNET_CRYPTO_ShortHashCode * result) 648 struct GNUNET_CRYPTO_ShortHashCode * result)
644{ 649{
645 return GNUNET_STRINGS_string_to_data (enc, enclen, 650
651 char upper_enc[enclen];
652 char* up_ptr = upper_enc;
653
654 GNUNET_STRINGS_utf8_toupper(enc, &up_ptr);
655 return GNUNET_STRINGS_string_to_data (upper_enc, enclen,
646 (unsigned char*) result, 656 (unsigned char*) result,
647 sizeof (struct GNUNET_CRYPTO_ShortHashCode)); 657 sizeof (struct GNUNET_CRYPTO_ShortHashCode));
648} 658}
diff --git a/src/util/strings.c b/src/util/strings.c
index d796d8894..54dee15f8 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -31,6 +31,7 @@
31#endif 31#endif
32#include "gnunet_common.h" 32#include "gnunet_common.h"
33#include "gnunet_strings_lib.h" 33#include "gnunet_strings_lib.h"
34#include <unicase.h>
34 35
35#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) 36#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
36 37
@@ -401,6 +402,45 @@ GNUNET_STRINGS_from_utf8 (const char *input, size_t len, const char *charset)
401 return GNUNET_STRINGS_conv (input, len, "UTF-8", charset); 402 return GNUNET_STRINGS_conv (input, len, "UTF-8", charset);
402} 403}
403 404
405/**
406 * Convert the utf-8 input string to lowercase
407 * Output needs to be allocated appropriately
408 *
409 * @param input input string
410 * @param output output buffer
411 */
412void
413GNUNET_STRINGS_utf8_tolower(const char* input, char** output)
414{
415 uint8_t *tmp_in;
416 size_t len;
417
418 tmp_in = u8_tolower ((uint8_t*)input, strlen ((char *) input),
419 NULL, UNINORM_NFD, NULL, &len);
420 memcpy(*output, tmp_in, len);
421 (*output)[len] = '\0';
422 free(tmp_in);
423}
424
425/**
426 * Convert the utf-8 input string to uppercase
427 * Output needs to be allocated appropriately
428 *
429 * @param input input string
430 * @param output output buffer
431 */
432void
433GNUNET_STRINGS_utf8_toupper(const char* input, char** output)
434{
435 uint8_t *tmp_in;
436 size_t len;
437
438 tmp_in = u8_toupper ((uint8_t*)input, strlen ((char *) input),
439 NULL, UNINORM_NFD, NULL, &len);
440 memcpy(*output, tmp_in, len);
441 (*output)[len] = '\0';
442 free(tmp_in);
443}
404 444
405 445
406/** 446/**