Fix for #4553
[oweals/gnunet.git] / src / rps / rps-test_util.c
index a3354b0ace2b680ee7c91683a992f70945df3cb4..882f945c93e6ede3e8ac54772915ac1cdd8df753 100644 (file)
@@ -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.
 */
 
 /**
@@ -82,6 +82,11 @@ to_file_ (char *file_name, char *line)
          "Unable to write to file! (Size: %u, size2: %u)\n",
          size,
          size2);
+
+    if (GNUNET_YES != GNUNET_DISK_file_close (f))
+      LOG (GNUNET_ERROR_TYPE_WARNING,
+           "Unable to close file\n");
+
     return;
   }
 
@@ -123,7 +128,7 @@ auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key)
     *end = '\0';
   }
 
-  size = GNUNET_snprintf (name_buf, name_buf_size, "sampler_el-%s-", buf);
+  size = GNUNET_snprintf (name_buf, name_buf_size, "sampler_el-%s", buf);
   if (0 > size)
     LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to create name_buf\n");
 
@@ -132,6 +137,25 @@ auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key)
   return name_buf;
 }
 
+
+struct GNUNET_CRYPTO_AuthKey
+string_to_auth_key (const char *str)
+{
+  struct GNUNET_CRYPTO_AuthKey auth_key;
+
+  if (GNUNET_OK !=
+      GNUNET_STRINGS_string_to_data (str,
+                                     strlen (str),
+                                     &auth_key.key,
+                                     sizeof (struct GNUNET_CRYPTO_AuthKey)))
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to convert string to data\n");
+  }
+
+  return auth_key;
+}
+
+
 char *
 create_file (const char *name)
 {
@@ -145,20 +169,27 @@ create_file (const char *name)
   name_buf_size = (strlen (prefix) + strlen (name) + 2) * sizeof (char);
   name_buf = GNUNET_malloc (name_buf_size);
 
-  size = GNUNET_snprintf (name_buf, name_buf_size, "%s%s-", prefix, name);
+  size = GNUNET_snprintf (name_buf, name_buf_size, "%s%s", prefix, name);
   if (0 > size)
     LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to create name_buf\n");
 
-  GNUNET_DISK_directory_create (prefix);
-
-  file_name = GNUNET_malloc (strlen (name_buf) + 6);
+  if (GNUNET_YES != GNUNET_DISK_directory_create (prefix))
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+         "Could not create directory %s.\n",
+         prefix);
+  }
 
-  if (NULL == (file_name = GNUNET_DISK_mktemp (name_buf)))
-        LOG (GNUNET_ERROR_TYPE_WARNING, "Could not create file\n");
+  if (NULL == strstr (name, "sampler_el"))
+  {/* only append random string to sampler */
+    if (NULL == (file_name = GNUNET_DISK_mktemp (name_buf)))
+          LOG (GNUNET_ERROR_TYPE_WARNING, "Could not create file\n");
 
   GNUNET_free (name_buf);
-
   return file_name;
+  }
+
+  return name_buf;
 }
 
 #endif /* TO_FILE */