- remove http
[oweals/gnunet.git] / src / namestore / test_namestore_api_put.c
index 7310946b1932472e6400a9a4be8516b04dd73457..8941b6b6d3aa364e91f678ea1ed7841d83d84628 100644 (file)
@@ -24,6 +24,7 @@
 #include "platform.h"
 #include "gnunet_common.h"
 #include "gnunet_namestore_service.h"
+#include "namestore.h"
 
 #define VERBOSE GNUNET_NO
 
@@ -42,7 +43,7 @@ static struct GNUNET_OS_Process *arm;
 static struct GNUNET_CRYPTO_RsaPrivateKey * privkey;
 static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey;
 
-struct GNUNET_NAMESTORE_RecordData *rd;
+struct GNUNET_NAMESTORE_RecordData *s_rd;
 
 static int res;
 
@@ -91,7 +92,6 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
   if (NULL != arm)
     stop_arm();
-
   res = 1;
 }
 
@@ -113,7 +113,7 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
   nsh = NULL;
 
 if (NULL != arm)
+ if (NULL != arm)
     stop_arm();
 }
 
@@ -146,23 +146,46 @@ create_record (int count)
   rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN);
   memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
   }
-
   return rd;
 }
 
+void
+delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  char *afsdir;
+
+  if (GNUNET_OK ==
+      GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite",
+                                               "FILENAME", &afsdir))
+  {
+    if (GNUNET_OK == GNUNET_DISK_file_test (afsdir))
+      if (GNUNET_OK == GNUNET_DISK_file_test (afsdir))
+        if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir))
+          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir);
+   GNUNET_free (afsdir);
+  }
+}
+
 static void
 run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
+  delete_existing_db(cfg);
   endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL);
 
   /* load privat key */
-  privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey");
+  char *hostkey_file;
+  GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
+      "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
+  privkey = GNUNET_CRYPTO_rsa_key_create_from_file(hostkey_file);
+  GNUNET_free (hostkey_file);
+
   GNUNET_assert (privkey != NULL);
   /* get public key */
   GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
 
-  struct GNUNET_CRYPTO_RsaSignature signature;
+  struct GNUNET_CRYPTO_RsaSignature *signature;
 
   start_arm (cfgfile);
   GNUNET_assert (arm != NULL);
@@ -171,20 +194,24 @@ run (void *cls, char *const *args, const char *cfgfile,
   GNUNET_break (NULL != nsh);
 
   /* create record */
-  char * name = "dummy.dummy.gnunet";
-  rd = create_record (RECORDS);
+  char * s_name = "dummy.dummy.gnunet";
+  s_rd = create_record (RECORDS);
+
+  signature = GNUNET_NAMESTORE_create_signature(privkey, s_rd[0].expiration, s_name, s_rd, RECORDS);
 
-  GNUNET_break (rd != NULL);
-  GNUNET_break (name != NULL);
+  GNUNET_break (s_rd != NULL);
+  GNUNET_break (s_name != NULL);
 
-  GNUNET_NAMESTORE_record_put (nsh, &pubkey, name,
+  GNUNET_NAMESTORE_record_put (nsh, &pubkey, s_name,
                               GNUNET_TIME_absolute_get_forever(),
-                              RECORDS, rd, &signature, put_cont, name);
+                              RECORDS, s_rd, signature, put_cont, s_name);
+
+  GNUNET_free (signature);
 
   int c;
   for (c = 0; c < RECORDS; c++)
-    GNUNET_free_non_null((void *) rd[c].data);
-  GNUNET_free (rd);
+    GNUNET_free_non_null((void *) s_rd[c].data);
+  GNUNET_free (s_rd);
 
 }