gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [gnunet] branch master updated: strcmp instead of memcmp


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated: strcmp instead of memcmp
Date: Wed, 22 Feb 2017 14:52:00 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 0244c0d86 strcmp instead of memcmp
0244c0d86 is described below

commit 0244c0d86cd86e4cc90e0c112c6edeafdfb558c2
Author: Christian Grothoff <address@hidden>
AuthorDate: Wed Feb 22 14:53:11 2017 +0100

    strcmp instead of memcmp
---
 src/block/plugin_block_template.c       | 10 ++++------
 src/block/plugin_block_test.c           | 10 ++++------
 src/dht/dht_api.c                       | 21 ++++++++++++++++----
 src/dht/gnunet-service-dht_neighbours.c | 32 ++++++++++++++++++++++++++-----
 src/dht/plugin_block_dht.c              | 10 ++++------
 src/fs/plugin_block_fs.c                |  5 ++---
 src/include/gnunet_strings_lib.h        | 14 +++++++++++++-
 src/regex/plugin_block_regex.c          | 10 ++++------
 src/util/strings.c                      | 34 +++++++++++++++++++++++++++++++--
 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,
   const char *guard;
 
   guard = va_arg (va, const char *);
-  if (0 == memcmp (guard,
-                   "seen-set-size",
-                   strlen ("seen-set-size")))
+  if (0 == strcmp (guard,
+                   "seen-set-size"))
     bf_size = compute_bloomfilter_size (va_arg (va, unsigned int));
-  else if (0 == memcmp (guard,
-                        "filter-size",
-                        strlen ("filter-size")))
+  else if (0 == strcmp (guard,
+                        "filter-size"))
     bf_size = va_arg (va, unsigned int);
   else
   {
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,
   const char *guard;
 
   guard = va_arg (va, const char *);
-  if (0 == memcmp (guard,
-                   "seen-set-size",
-                   strlen ("seen-set-size")))
+  if (0 == strcmp (guard,
+                   "seen-set-size"))
     bf_size = compute_bloomfilter_size (va_arg (va, unsigned int));
-  else if (0 == memcmp (guard,
-                        "filter-size",
-                        strlen ("filter-size")))
+  else if (0 == strcmp (guard,
+                        "filter-size"))
     bf_size = va_arg (va, unsigned int);
   else
   {
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,
   meta_length =
       sizeof (struct GNUNET_PeerIdentity) * (get_path_length + 
put_path_length);
   data_length = msize - meta_length;
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Giving %u byte reply for %s to application\n",
-       (unsigned int) data_length,
-       GNUNET_h2s (key));
   put_path = (const struct GNUNET_PeerIdentity *) &crm[1];
   get_path = &put_path[put_path_length];
+  {
+    char *pp;
+    char *gp;
+
+    gp = GNUNET_STRINGS_pp2s (get_path,
+                              get_path_length);
+    pp = GNUNET_STRINGS_pp2s (put_path,
+                              put_path_length);
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+         "Giving %u byte reply for %s to application (GP: %s, PP: %s)\n",
+         (unsigned int) data_length,
+         GNUNET_h2s (key),
+         gp,
+         pp);
+    GNUNET_free (gp);
+    GNUNET_free (pp);
+  }
   data = &get_path[get_path_length];
   /* remember that we've seen this result */
   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,
   if (GNUNET_YES == log_route_details_stderr)
   {
     char *tmp;
+    char *pp;
 
+    pp = GNUNET_STRINGS_pp2s (put_path,
+                              putlen);
     tmp = GNUNET_strdup (GNUNET_i2s (&my_identity));
     LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG,
-                 "R5N PUT %s: %s->%s (%u, %u=>%u)\n",
+                 "R5N PUT %s: %s->%s (%u, %u=>%u, PP: %s)\n",
                  GNUNET_h2s (&put->key),
                  GNUNET_i2s (peer->id),
                  tmp,
@@ -1676,8 +1679,9 @@ handle_dht_p2p_put (void *cls,
                  GNUNET_CRYPTO_hash_matching_bits (&peer->phash,
                                                    &put->key),
                  GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash,
-                                                   &put->key)
-                );
+                                                   &put->key),
+                 pp);
+    GNUNET_free (pp);
     GNUNET_free (tmp);
   }
   switch (GNUNET_BLOCK_get_key
@@ -1965,6 +1969,15 @@ handle_local_result (void *cls,
                      const void *data,
                      size_t data_size)
 {
+  char *pp;
+
+  pp = GNUNET_STRINGS_pp2s (put_path,
+                            put_path_length);
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Found local result for %s (PP: %s)\n",
+       GNUNET_h2s (key),
+       pp);
+  GNUNET_free (pp);
   // FIXME: we can probably do better here by
   // passing the peer that did the query in the closure...
   GDS_ROUTING_process (NULL,
@@ -2243,14 +2256,23 @@ handle_dht_p2p_result (void *cls,
   if (GNUNET_YES == log_route_details_stderr)
   {
     char *tmp;
+    char *pp;
+    char *gp;
 
+    gp = GNUNET_STRINGS_pp2s (get_path,
+                              get_path_length);
+    pp = GNUNET_STRINGS_pp2s (put_path,
+                              put_path_length);
     tmp = GNUNET_strdup (GNUNET_i2s (&my_identity));
     LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG,
-                 "R5N RESULT %s: %s->%s (%u)\n",
+                 "R5N RESULT %s: %s->%s (GP: %s, PP: %s)\n",
                  GNUNET_h2s (&prm->key),
                  GNUNET_i2s (peer->id),
                  tmp,
-                 get_path_length + 1);
+                 gp,
+                 pp);
+    GNUNET_free (gp);
+    GNUNET_free (pp);
     GNUNET_free (tmp);
   }
   /* 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,
   const char *guard;
 
   guard = va_arg (va, const char *);
-  if (0 == memcmp (guard,
-                   "seen-set-size",
-                   strlen ("seen-set-size")))
+  if (0 == strcmp (guard,
+                   "seen-set-size"))
     bf_size = compute_bloomfilter_size (va_arg (va, unsigned int));
-  else if (0 == memcmp (guard,
-                        "filter-size",
-                        strlen ("filter-size")))
+  else if (0 == strcmp (guard,
+                        "filter-size"))
     bf_size = va_arg (va, unsigned int);
   else
   {
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,
     return NULL;
   case GNUNET_BLOCK_TYPE_FS_UBLOCK:
     guard = va_arg (va, const char *);
-    if (0 != memcmp (guard,
-                     "seen-set-size",
-                     strlen ("seen-set-size")))
+    if (0 != strcmp (guard,
+                     "seen-set-size"))
     {
       /* va-args invalid! bad bug, complain! */
       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,
 
 
 /**
+ * Convert a peer path to a human-readable string.
+ *
+ * @param pids array of PIDs to convert to a string
+ * @param num_pids length of the @a pids array
+ * @return string representing the array of @a pids
+ */
+char *
+GNUNET_STRINGS_pp2s (const struct GNUNET_PeerIdentity *pids,
+                     unsigned int num_pids);
+
+
+/**
  * Parse a path that might be an URI.
  *
  * @param path path to parse. Must be NULL-terminated.
@@ -477,7 +489,7 @@ GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr,
 
 
 /**
- * Parse an address given as a string into a 
+ * Parse an address given as a string into a
  * `struct sockaddr`.
  *
  * @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,
   const char *guard;
 
   guard = va_arg (va, const char *);
-  if (0 == memcmp (guard,
-                   "seen-set-size",
-                   strlen ("seen-set-size")))
+  if (0 == strcmp (guard,
+                   "seen-set-size"))
     bf_size = compute_bloomfilter_size (va_arg (va, unsigned int));
-  else if (0 == memcmp (guard,
-                        "filter-size",
-                        strlen ("filter-size")))
+  else if (0 == strcmp (guard,
+                        "filter-size"))
     bf_size = va_arg (va, unsigned int);
   else
   {
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 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2005-2013 GNUnet e.V.
+     Copyright (C) 2005-2017 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -17,7 +17,6 @@
      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
      Boston, MA 02110-1301, USA.
 */
-
 /**
  * @file util/strings.c
  * @brief string functions
@@ -90,6 +89,37 @@ GNUNET_STRINGS_buffer_fill (char *buffer, size_t size, 
unsigned int count, ...)
 
 
 /**
+ * Convert a peer path to a human-readable string.
+ *
+ * @param pids array of PIDs to convert to a string
+ * @param num_pids length of the @a pids array
+ * @return string representing the array of @a pids
+ */
+char *
+GNUNET_STRINGS_pp2s (const struct GNUNET_PeerIdentity *pids,
+                     unsigned int num_pids)
+{
+  char *buf;
+  size_t off;
+  size_t plen = num_pids * 5 + 1;
+
+  off = 0;
+  buf = GNUNET_malloc (plen);
+  for (unsigned int i = 0;
+       i < num_pids;
+       i++)
+  {
+    off += GNUNET_snprintf (&buf[off],
+                            plen - off,
+                            "%s%s",
+                            GNUNET_i2s (&pids[i]),
+                            (i == num_pids -1) ? "" : "-");
+  }
+  return buf;
+}
+
+
+/**
  * Given a buffer of a given size, find "count"
  * 0-terminated strings in the buffer and assign
  * the count (varargs) of type "const char**" to the

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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