Use statement exprs instead of local function
[oweals/gnunet.git] / src / gns / plugin_gnsrecord_gns.c
index 5675599dda2ce4049557b4c102ce09189bdcc199..756034d6e089ccc98b2b90bb08fd4cfbb7a7d650 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     (C) 2013, 2014 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2013, 2014 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
@@ -14,8 +14,8 @@
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 
 /**
@@ -174,7 +174,7 @@ gns_string_to_value (void *cls,
       return GNUNET_SYSERR;
     }
     *data = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
-    memcpy (*data, &pkey, sizeof (pkey));
+    GNUNET_memcpy (*data, &pkey, sizeof (pkey));
     *data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
     return GNUNET_OK;
 
@@ -227,7 +227,7 @@ gns_string_to_value (void *cls,
       GNUNET_free (cpy);
       *data_size = off;
       *data = GNUNET_malloc (off);
-      memcpy (*data, nsbuf, off);
+      GNUNET_memcpy (*data, nsbuf, off);
       return GNUNET_OK;
     }
   case GNUNET_GNSRECORD_TYPE_VPN:
@@ -263,29 +263,32 @@ gns_string_to_value (void *cls,
   case GNUNET_GNSRECORD_TYPE_BOX:
     {
       struct GNUNET_GNSRECORD_BoxRecord *box;
-      size_t slen = strlen (s) + 1;
-      char rest[slen];
+      size_t rest;
       unsigned int protocol;
       unsigned int service;
       unsigned int record_type;
       void *bval;
       size_t bval_size;
 
-      if (4 != SSCANF (s,
-                       "%u %u %u %s",
+      if (3 != SSCANF (s,
+                       "%u %u %u ",
                        &protocol,
                        &service,
-                       &record_type,
-                       rest))
+                       &record_type))
       {
         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                     _("Unable to parse BOX record string `%s'\n"),
                     s);
         return GNUNET_SYSERR;
       }
+      rest = snprintf (NULL, 0,
+                       "%u %u %u ",
+                       protocol,
+                       service,
+                       record_type);
       if (GNUNET_OK !=
           GNUNET_GNSRECORD_string_to_value (record_type,
-                                            rest,
+                                            &s[rest],
                                             &bval,
                                             &bval_size))
         return GNUNET_SYSERR;
@@ -294,7 +297,7 @@ gns_string_to_value (void *cls,
       box->protocol = htons (protocol);
       box->service = htons (service);
       box->record_type = htonl (record_type);
-      memcpy (&box[1],
+      GNUNET_memcpy (&box[1],
               bval,
               bval_size);
       GNUNET_free (bval);
@@ -338,8 +341,9 @@ gns_typename_to_number (void *cls,
   unsigned int i;
 
   i=0;
-  while ( (gns_name_map[i].name != NULL) &&
-         (0 != strcasecmp (gns_typename, gns_name_map[i].name)) )
+  while ( (NULL != gns_name_map[i].name) &&
+         (0 != strcasecmp (gns_typename,
+                            gns_name_map[i].name)) )
     i++;
   return gns_name_map[i].number;
 }
@@ -359,7 +363,7 @@ gns_number_to_typename (void *cls,
   unsigned int i;
 
   i=0;
-  while ( (gns_name_map[i].name != NULL) &&
+  while ( (NULL != gns_name_map[i].name) &&
          (type != gns_name_map[i].number) )
     i++;
   return gns_name_map[i].name;