Link libgnunetblockgroup to libgnunetblock
[oweals/gnunet.git] / src / util / strings.c
index 46eab856f0be6425a3f83c244e1c258cd703cb2b..d3268f4d99fa70d23a56db782a4d53f2c5fb80d4 100644 (file)
@@ -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
@@ -35,9 +34,9 @@
 #include <unistr.h>
 #include <uniconv.h>
 
-#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
+#define LOG(kind,...) GNUNET_log_from (kind, "util-strings", __VA_ARGS__)
 
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall)
+#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-strings", syscall)
 
 
 /**
@@ -89,6 +88,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
@@ -1354,7 +1384,7 @@ GNUNET_STRINGS_to_address_ip (const char *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
@@ -1372,7 +1402,7 @@ GNUNET_STRINGS_parse_socket_addr (const char *addr,
   *af = AF_UNSPEC;
   if ('[' == *addr)
   {
-    /* IPv6 */    
+    /* IPv6 */
     *sa = GNUNET_malloc (sizeof (struct sockaddr_in6));
     if (GNUNET_OK !=
        GNUNET_STRINGS_to_address_ipv6 (cp,