-fix uninit and fix leak
[oweals/gnunet.git] / src / gns / gnunet-gns-fcfsd.c
index 5503000aca79e8a98438664a562a620728d8585c..25fde90ec99727e08c9ade5897bf129fa9b662da 100644 (file)
@@ -199,7 +199,7 @@ static struct GNUNET_CRYPTO_ShortHashCode fcfsd_zone;
 /**
  * Private key for the fcfsd zone.
  */
-static struct GNUNET_CRYPTO_RsaPrivateKey *fcfs_zone_pkey;
+static struct GNUNET_CRYPTO_EccPrivateKey *fcfs_zone_pkey;
                        
 
 /**
@@ -229,12 +229,12 @@ run_httpd_now ()
 
 static void
 iterate_cb (void *cls,
-                const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
+                const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
                 struct GNUNET_TIME_Absolute expire,
                 const char *name,
                 unsigned int rd_len,
                 const struct GNUNET_NAMESTORE_RecordData *rd,
-                const struct GNUNET_CRYPTO_RsaSignature *signature)
+                const struct GNUNET_CRYPTO_EccSignature *signature)
 {
   struct ZoneinfoRequest *zr = cls;
   struct MHD_Response *response;
@@ -286,16 +286,18 @@ iterate_cb (void *cls,
                                            rd->data,
                                            rd->data_size);
 
-  if (bytes_free < (strlen (name) + strlen (pkey) + 10))
+  if (bytes_free < (strlen (name) + strlen (pkey) + 40))
   {
     new_buf = GNUNET_malloc (zr->buf_len * 2);
     memcpy (new_buf, zr->zoneinfo, zr->write_offset);
     GNUNET_free (zr->zoneinfo);
     zr->zoneinfo = new_buf;
+    zr->buf_len *= 2;
   }
-
-  sprintf (zr->zoneinfo+zr->write_offset, "<tr><td>%s</td><td>%s</td></tr>", name, pkey);
-
+  sprintf (zr->zoneinfo + zr->write_offset, 
+          "<tr><td>%s</td><td>%s</td></tr>", 
+          name, 
+          pkey);
   zr->write_offset = strlen (zr->zoneinfo);
   GNUNET_NAMESTORE_zone_iterator_next (zr->list_it);
   GNUNET_free (pkey);
@@ -504,12 +506,12 @@ put_continuation (void *cls,
  */
 static void 
 zone_to_name_cb (void *cls,
-                const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
+                const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
                 struct GNUNET_TIME_Absolute expire,                        
                 const char *name,
                 unsigned int rd_count,
                 const struct GNUNET_NAMESTORE_RecordData *rd,
-                const struct GNUNET_CRYPTO_RsaSignature *signature)
+                const struct GNUNET_CRYPTO_EccSignature *signature)
 {
   struct Request *request = cls;
   struct GNUNET_NAMESTORE_RecordData r;
@@ -534,12 +536,13 @@ zone_to_name_cb (void *cls,
   r.expiration_time = UINT64_MAX;
   r.record_type = GNUNET_NAMESTORE_TYPE_PKEY;
   r.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
-  request->qe = GNUNET_NAMESTORE_record_create (ns,
-                                               fcfs_zone_pkey,
-                                               request->domain_name,
-                                               &r,
-                                               &put_continuation,
-                                               request);
+  request->qe = GNUNET_NAMESTORE_record_put_by_authority (ns,
+                                                         fcfs_zone_pkey,
+                                                         request->domain_name,
+                                                         1,
+                                                         &r,
+                                                         &put_continuation,
+                                                         request);
 }
 
 
@@ -563,12 +566,12 @@ zone_to_name_cb (void *cls,
  */
 static void 
 lookup_result_processor (void *cls,
-                        const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
+                        const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
                         struct GNUNET_TIME_Absolute expire,                        
                         const char *name,
                         unsigned int rd_count,
                         const struct GNUNET_NAMESTORE_RecordData *rd,
-                        const struct GNUNET_CRYPTO_RsaSignature *signature)
+                        const struct GNUNET_CRYPTO_EccSignature *signature)
 {
   struct Request *request = cls;
   struct GNUNET_CRYPTO_ShortHashCode pub;
@@ -860,7 +863,7 @@ do_shutdown (void *cls,
   }
   if (NULL != fcfs_zone_pkey)
   {
-    GNUNET_CRYPTO_rsa_key_free (fcfs_zone_pkey);
+    GNUNET_CRYPTO_ecc_key_free (fcfs_zone_pkey);
     fcfs_zone_pkey = NULL;
   }
 }
@@ -880,7 +883,7 @@ run (void *cls, char *const *args, const char *cfgfile,
 {
   char *keyfile;
   unsigned long long port;
-  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
+  struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pub;
 
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_number (cfg,
@@ -902,7 +905,7 @@ run (void *cls, char *const *args, const char *cfgfile,
                               "fcfsd", "ZONEKEY");
     return;
   }
-  fcfs_zone_pkey = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
+  fcfs_zone_pkey = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile);
   GNUNET_free (keyfile);
   if (NULL == fcfs_zone_pkey)
   {
@@ -910,7 +913,7 @@ run (void *cls, char *const *args, const char *cfgfile,
                _("Failed to read or create private zone key\n"));
     return;
   }
-  GNUNET_CRYPTO_rsa_key_get_public (fcfs_zone_pkey,
+  GNUNET_CRYPTO_ecc_key_get_public (fcfs_zone_pkey,
                                    &pub);
   GNUNET_CRYPTO_short_hash (&pub, sizeof (pub), &fcfsd_zone);
   ns = GNUNET_NAMESTORE_connect (cfg);
@@ -970,7 +973,7 @@ main (int argc, char *const *argv)
                            _("GNUnet GNS first come first serve registration service"), 
                           options,
                            &run, NULL)) ? 0 : 1;
-
+  GNUNET_free ((void*) argv);
   return ret;
 }