aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-02-22 14:53:11 +0100
committerChristian Grothoff <christian@grothoff.org>2017-02-22 14:53:11 +0100
commit0244c0d86cd86e4cc90e0c112c6edeafdfb558c2 (patch)
treeb534b32562883064a09d856f700995a2f1b5cc42
parent7184623654f81c1ba557f8fa95a3086342b4af6b (diff)
downloadgnunet-0244c0d86cd86e4cc90e0c112c6edeafdfb558c2.tar.gz
gnunet-0244c0d86cd86e4cc90e0c112c6edeafdfb558c2.zip
strcmp instead of memcmp
-rw-r--r--src/block/plugin_block_template.c10
-rw-r--r--src/block/plugin_block_test.c10
-rw-r--r--src/dht/dht_api.c21
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c32
-rw-r--r--src/dht/plugin_block_dht.c10
-rw-r--r--src/fs/plugin_block_fs.c5
-rw-r--r--src/include/gnunet_strings_lib.h14
-rw-r--r--src/regex/plugin_block_regex.c10
-rw-r--r--src/util/strings.c34
9 files changed, 107 insertions, 39 deletions
diff --git a/src/block/plugin_block_template.c b/src/block/plugin_block_template.c
index f11d5ee76..0825bd095 100644
--- a/src/block/plugin_block_template.c
+++ b/src/block/plugin_block_template.c
@@ -98,13 +98,11 @@ block_plugin_template_create_group (void *cls,
98 const char *guard; 98 const char *guard;
99 99
100 guard = va_arg (va, const char *); 100 guard = va_arg (va, const char *);
101 if (0 == memcmp (guard, 101 if (0 == strcmp (guard,
102 "seen-set-size", 102 "seen-set-size"))
103 strlen ("seen-set-size")))
104 bf_size = compute_bloomfilter_size (va_arg (va, unsigned int)); 103 bf_size = compute_bloomfilter_size (va_arg (va, unsigned int));
105 else if (0 == memcmp (guard, 104 else if (0 == strcmp (guard,
106 "filter-size", 105 "filter-size"))
107 strlen ("filter-size")))
108 bf_size = va_arg (va, unsigned int); 106 bf_size = va_arg (va, unsigned int);
109 else 107 else
110 { 108 {
diff --git a/src/block/plugin_block_test.c b/src/block/plugin_block_test.c
index c5483f26e..31112e5dd 100644
--- a/src/block/plugin_block_test.c
+++ b/src/block/plugin_block_test.c
@@ -96,13 +96,11 @@ block_plugin_test_create_group (void *cls,
96 const char *guard; 96 const char *guard;
97 97
98 guard = va_arg (va, const char *); 98 guard = va_arg (va, const char *);
99 if (0 == memcmp (guard, 99 if (0 == strcmp (guard,
100 "seen-set-size", 100 "seen-set-size"))
101 strlen ("seen-set-size")))
102 bf_size = compute_bloomfilter_size (va_arg (va, unsigned int)); 101 bf_size = compute_bloomfilter_size (va_arg (va, unsigned int));
103 else if (0 == memcmp (guard, 102 else if (0 == strcmp (guard,
104 "filter-size", 103 "filter-size"))
105 strlen ("filter-size")))
106 bf_size = va_arg (va, unsigned int); 104 bf_size = va_arg (va, unsigned int);
107 else 105 else
108 { 106 {
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c
index 070d248ed..ee208b50e 100644
--- a/src/dht/dht_api.c
+++ b/src/dht/dht_api.c
@@ -754,12 +754,25 @@ process_client_result (void *cls,
754 meta_length = 754 meta_length =
755 sizeof (struct GNUNET_PeerIdentity) * (get_path_length + put_path_length); 755 sizeof (struct GNUNET_PeerIdentity) * (get_path_length + put_path_length);
756 data_length = msize - meta_length; 756 data_length = msize - meta_length;
757 LOG (GNUNET_ERROR_TYPE_DEBUG,
758 "Giving %u byte reply for %s to application\n",
759 (unsigned int) data_length,
760 GNUNET_h2s (key));
761 put_path = (const struct GNUNET_PeerIdentity *) &crm[1]; 757 put_path = (const struct GNUNET_PeerIdentity *) &crm[1];
762 get_path = &put_path[put_path_length]; 758 get_path = &put_path[put_path_length];
759 {
760 char *pp;
761 char *gp;
762
763 gp = GNUNET_STRINGS_pp2s (get_path,
764 get_path_length);
765 pp = GNUNET_STRINGS_pp2s (put_path,
766 put_path_length);
767 LOG (GNUNET_ERROR_TYPE_DEBUG,
768 "Giving %u byte reply for %s to application (GP: %s, PP: %s)\n",
769 (unsigned int) data_length,
770 GNUNET_h2s (key),
771 gp,
772 pp);
773 GNUNET_free (gp);
774 GNUNET_free (pp);
775 }
763 data = &get_path[get_path_length]; 776 data = &get_path[get_path_length];
764 /* remember that we've seen this result */ 777 /* remember that we've seen this result */
765 GNUNET_CRYPTO_hash (data, 778 GNUNET_CRYPTO_hash (data,
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index 346925032..bb6285730 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -1665,10 +1665,13 @@ handle_dht_p2p_put (void *cls,
1665 if (GNUNET_YES == log_route_details_stderr) 1665 if (GNUNET_YES == log_route_details_stderr)
1666 { 1666 {
1667 char *tmp; 1667 char *tmp;
1668 char *pp;
1668 1669
1670 pp = GNUNET_STRINGS_pp2s (put_path,
1671 putlen);
1669 tmp = GNUNET_strdup (GNUNET_i2s (&my_identity)); 1672 tmp = GNUNET_strdup (GNUNET_i2s (&my_identity));
1670 LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, 1673 LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG,
1671 "R5N PUT %s: %s->%s (%u, %u=>%u)\n", 1674 "R5N PUT %s: %s->%s (%u, %u=>%u, PP: %s)\n",
1672 GNUNET_h2s (&put->key), 1675 GNUNET_h2s (&put->key),
1673 GNUNET_i2s (peer->id), 1676 GNUNET_i2s (peer->id),
1674 tmp, 1677 tmp,
@@ -1676,8 +1679,9 @@ handle_dht_p2p_put (void *cls,
1676 GNUNET_CRYPTO_hash_matching_bits (&peer->phash, 1679 GNUNET_CRYPTO_hash_matching_bits (&peer->phash,
1677 &put->key), 1680 &put->key),
1678 GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, 1681 GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash,
1679 &put->key) 1682 &put->key),
1680 ); 1683 pp);
1684 GNUNET_free (pp);
1681 GNUNET_free (tmp); 1685 GNUNET_free (tmp);
1682 } 1686 }
1683 switch (GNUNET_BLOCK_get_key 1687 switch (GNUNET_BLOCK_get_key
@@ -1965,6 +1969,15 @@ handle_local_result (void *cls,
1965 const void *data, 1969 const void *data,
1966 size_t data_size) 1970 size_t data_size)
1967{ 1971{
1972 char *pp;
1973
1974 pp = GNUNET_STRINGS_pp2s (put_path,
1975 put_path_length);
1976 LOG (GNUNET_ERROR_TYPE_DEBUG,
1977 "Found local result for %s (PP: %s)\n",
1978 GNUNET_h2s (key),
1979 pp);
1980 GNUNET_free (pp);
1968 // FIXME: we can probably do better here by 1981 // FIXME: we can probably do better here by
1969 // passing the peer that did the query in the closure... 1982 // passing the peer that did the query in the closure...
1970 GDS_ROUTING_process (NULL, 1983 GDS_ROUTING_process (NULL,
@@ -2243,14 +2256,23 @@ handle_dht_p2p_result (void *cls,
2243 if (GNUNET_YES == log_route_details_stderr) 2256 if (GNUNET_YES == log_route_details_stderr)
2244 { 2257 {
2245 char *tmp; 2258 char *tmp;
2259 char *pp;
2260 char *gp;
2246 2261
2262 gp = GNUNET_STRINGS_pp2s (get_path,
2263 get_path_length);
2264 pp = GNUNET_STRINGS_pp2s (put_path,
2265 put_path_length);
2247 tmp = GNUNET_strdup (GNUNET_i2s (&my_identity)); 2266 tmp = GNUNET_strdup (GNUNET_i2s (&my_identity));
2248 LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, 2267 LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG,
2249 "R5N RESULT %s: %s->%s (%u)\n", 2268 "R5N RESULT %s: %s->%s (GP: %s, PP: %s)\n",
2250 GNUNET_h2s (&prm->key), 2269 GNUNET_h2s (&prm->key),
2251 GNUNET_i2s (peer->id), 2270 GNUNET_i2s (peer->id),
2252 tmp, 2271 tmp,
2253 get_path_length + 1); 2272 gp,
2273 pp);
2274 GNUNET_free (gp);
2275 GNUNET_free (pp);
2254 GNUNET_free (tmp); 2276 GNUNET_free (tmp);
2255 } 2277 }
2256 /* if we got a HELLO, consider it for our own routing table */ 2278 /* if we got a HELLO, consider it for our own routing table */
diff --git a/src/dht/plugin_block_dht.c b/src/dht/plugin_block_dht.c
index 72480536c..29c08dd50 100644
--- a/src/dht/plugin_block_dht.c
+++ b/src/dht/plugin_block_dht.c
@@ -95,13 +95,11 @@ block_plugin_dht_create_group (void *cls,
95 const char *guard; 95 const char *guard;
96 96
97 guard = va_arg (va, const char *); 97 guard = va_arg (va, const char *);
98 if (0 == memcmp (guard, 98 if (0 == strcmp (guard,
99 "seen-set-size", 99 "seen-set-size"))
100 strlen ("seen-set-size")))
101 bf_size = compute_bloomfilter_size (va_arg (va, unsigned int)); 100 bf_size = compute_bloomfilter_size (va_arg (va, unsigned int));
102 else if (0 == memcmp (guard, 101 else if (0 == strcmp (guard,
103 "filter-size", 102 "filter-size"))
104 strlen ("filter-size")))
105 bf_size = va_arg (va, unsigned int); 103 bf_size = va_arg (va, unsigned int);
106 else 104 else
107 { 105 {
diff --git a/src/fs/plugin_block_fs.c b/src/fs/plugin_block_fs.c
index bea6b148c..996c06dcb 100644
--- a/src/fs/plugin_block_fs.c
+++ b/src/fs/plugin_block_fs.c
@@ -102,9 +102,8 @@ block_plugin_fs_create_group (void *cls,
102 return NULL; 102 return NULL;
103 case GNUNET_BLOCK_TYPE_FS_UBLOCK: 103 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
104 guard = va_arg (va, const char *); 104 guard = va_arg (va, const char *);
105 if (0 != memcmp (guard, 105 if (0 != strcmp (guard,
106 "seen-set-size", 106 "seen-set-size"))
107 strlen ("seen-set-size")))
108 { 107 {
109 /* va-args invalid! bad bug, complain! */ 108 /* va-args invalid! bad bug, complain! */
110 GNUNET_break (0); 109 GNUNET_break (0);
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h
index 0328882dd..144780c82 100644
--- a/src/include/gnunet_strings_lib.h
+++ b/src/include/gnunet_strings_lib.h
@@ -360,6 +360,18 @@ GNUNET_STRINGS_base64_decode (const char *data,
360 360
361 361
362/** 362/**
363 * Convert a peer path to a human-readable string.
364 *
365 * @param pids array of PIDs to convert to a string
366 * @param num_pids length of the @a pids array
367 * @return string representing the array of @a pids
368 */
369char *
370GNUNET_STRINGS_pp2s (const struct GNUNET_PeerIdentity *pids,
371 unsigned int num_pids);
372
373
374/**
363 * Parse a path that might be an URI. 375 * Parse a path that might be an URI.
364 * 376 *
365 * @param path path to parse. Must be NULL-terminated. 377 * @param path path to parse. Must be NULL-terminated.
@@ -477,7 +489,7 @@ GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr,
477 489
478 490
479/** 491/**
480 * Parse an address given as a string into a 492 * Parse an address given as a string into a
481 * `struct sockaddr`. 493 * `struct sockaddr`.
482 * 494 *
483 * @param addr the address 495 * @param addr the address
diff --git a/src/regex/plugin_block_regex.c b/src/regex/plugin_block_regex.c
index b9814c737..19335e815 100644
--- a/src/regex/plugin_block_regex.c
+++ b/src/regex/plugin_block_regex.c
@@ -100,13 +100,11 @@ block_plugin_regex_create_group (void *cls,
100 const char *guard; 100 const char *guard;
101 101
102 guard = va_arg (va, const char *); 102 guard = va_arg (va, const char *);
103 if (0 == memcmp (guard, 103 if (0 == strcmp (guard,
104 "seen-set-size", 104 "seen-set-size"))
105 strlen ("seen-set-size")))
106 bf_size = compute_bloomfilter_size (va_arg (va, unsigned int)); 105 bf_size = compute_bloomfilter_size (va_arg (va, unsigned int));
107 else if (0 == memcmp (guard, 106 else if (0 == strcmp (guard,
108 "filter-size", 107 "filter-size"))
109 strlen ("filter-size")))
110 bf_size = va_arg (va, unsigned int); 108 bf_size = va_arg (va, unsigned int);
111 else 109 else
112 { 110 {
diff --git a/src/util/strings.c b/src/util/strings.c
index 2b51d3e52..291255344 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2005-2013 GNUnet e.V. 3 Copyright (C) 2005-2017 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -17,7 +17,6 @@
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA. 18 Boston, MA 02110-1301, USA.
19*/ 19*/
20
21/** 20/**
22 * @file util/strings.c 21 * @file util/strings.c
23 * @brief string functions 22 * @brief string functions
@@ -90,6 +89,37 @@ GNUNET_STRINGS_buffer_fill (char *buffer, size_t size, unsigned int count, ...)
90 89
91 90
92/** 91/**
92 * Convert a peer path to a human-readable string.
93 *
94 * @param pids array of PIDs to convert to a string
95 * @param num_pids length of the @a pids array
96 * @return string representing the array of @a pids
97 */
98char *
99GNUNET_STRINGS_pp2s (const struct GNUNET_PeerIdentity *pids,
100 unsigned int num_pids)
101{
102 char *buf;
103 size_t off;
104 size_t plen = num_pids * 5 + 1;
105
106 off = 0;
107 buf = GNUNET_malloc (plen);
108 for (unsigned int i = 0;
109 i < num_pids;
110 i++)
111 {
112 off += GNUNET_snprintf (&buf[off],
113 plen - off,
114 "%s%s",
115 GNUNET_i2s (&pids[i]),
116 (i == num_pids -1) ? "" : "-");
117 }
118 return buf;
119}
120
121
122/**
93 * Given a buffer of a given size, find "count" 123 * Given a buffer of a given size, find "count"
94 * 0-terminated strings in the buffer and assign 124 * 0-terminated strings in the buffer and assign
95 * the count (varargs) of type "const char**" to the 125 * the count (varargs) of type "const char**" to the