gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-anastasis] branch master updated (a6ef5c5 -> 7062901)


From: gnunet
Subject: [taler-anastasis] branch master updated (a6ef5c5 -> 7062901)
Date: Thu, 22 Oct 2020 18:52:05 +0200

This is an automated email from the git hooks/post-receive script.

dennis-neufeld pushed a change to branch master
in repository anastasis.

    from a6ef5c5  fix spelling mistakes
     new 3a30ce3  fix strncpy warnings
     new e5f2460  reduce code reuse
     new 281eb08  fix memory leaks
     new 1ba736f  fix memory leaks
     new 319cbe9  merge
     new 7062901  merge

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/backend/anastasis-httpd_truth.c        |   2 +-
 src/backend/anastasis-httpd_truth_upload.c |   4 -
 src/include/anastasis_database_lib.h       |   2 +
 src/include/anastasis_service.h            |  27 ++---
 src/lib/anastasis.c                        | 116 ++++++++++++------
 src/lib/anastasis_api_keyshare_lookup.c    |  11 +-
 src/lib/anastasis_api_truth_store.c        |  11 +-
 src/lib/testing_api_cmd_keyshare_lookup.c  |   8 --
 src/lib/testing_api_cmd_policy_store.c     |   2 +-
 src/lib/testing_api_cmd_truth_store.c      |  23 ++--
 src/lib/testing_cmd_policy_create.c        |   5 +-
 src/lib/testing_cmd_secret_share.c         |   2 +
 src/lib/testing_cmd_truth_upload.c         |   9 +-
 src/stasis/plugin_anastasis_postgres.c     | 185 +++++++++++++++--------------
 src/stasis/test_anastasis_db.c             |   3 +-
 15 files changed, 227 insertions(+), 183 deletions(-)

diff --git a/src/backend/anastasis-httpd_truth.c 
b/src/backend/anastasis-httpd_truth.c
index 3f1b655..b82997f 100644
--- a/src/backend/anastasis-httpd_truth.c
+++ b/src/backend/anastasis-httpd_truth.c
@@ -811,7 +811,7 @@ AH_handler_truth_get (struct MHD_Connection *connection,
     case ANASTASIS_DB_STATUS_NO_RESULTS:
       GNUNET_free (decrypted_truth);
       return MHD_NO;
-    case ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT:
+    case ANASTASIS_DB_STATUS_VALID_CODE_STORED:
       break;
     default:
       GNUNET_free (decrypted_truth);
diff --git a/src/backend/anastasis-httpd_truth_upload.c 
b/src/backend/anastasis-httpd_truth_upload.c
index cfc6793..7a50c70 100644
--- a/src/backend/anastasis-httpd_truth_upload.c
+++ b/src/backend/anastasis-httpd_truth_upload.c
@@ -120,10 +120,6 @@ AH_handler_truth_post (struct MHD_Connection *connection,
     res = TALER_MHD_parse_json_data (connection,
                                      json,
                                      spec);
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Truth json from upload: %s\nResult: %i\n",
-                json_dumps (json, JSON_COMPACT),
-                res);
 
     if (GNUNET_SYSERR == res)
       return MHD_NO; /* hard failure */
diff --git a/src/include/anastasis_database_lib.h 
b/src/include/anastasis_database_lib.h
index a2e0287..cff4635 100644
--- a/src/include/anastasis_database_lib.h
+++ b/src/include/anastasis_database_lib.h
@@ -55,10 +55,12 @@ enum ANASTASIS_DB_QueryStatus
    * Already valid code stored under this public key, please use the valid code
    */
   ANASTASIS_DB_STATUS_VALID_CODE_STORED = -6,
+
   /**
    * Provided Challenge code didn't match the server generated code
    */
   ANASTASIS_DB_STATUS_CHALLENGE_CODE_MISSMATCH = -5,
+
   /**
    * Update failed because the old recovery data hash does not match what we 
previously had in the DB.
    */
diff --git a/src/include/anastasis_service.h b/src/include/anastasis_service.h
index 0be7a8a..55aedab 100644
--- a/src/include/anastasis_service.h
+++ b/src/include/anastasis_service.h
@@ -198,7 +198,6 @@ struct ANASTASIS_UploadDetails
 
   union
   {
-
     /**
      * Hash of the stored recovery data, returned if
      * @e us is #ANASTASIS_US_SUCCESS.
@@ -414,29 +413,29 @@ typedef void
  *
  * @param ctx the CURL context used to connect to the backend
  * @param backend_url backend's base URL, including final "/"
- * @param anastasis_pub public key of the user's account
  * @param anastasis_priv private key of the user's account
  * @param prev_recovery_data_hash hash of the previous policy update, NULL for 
the first upload ever
  * @param recovery_data policy data to be stored
  * @param recovery_data_size number of bytes in @a recovery_data
  * @param payment_requested #GNUNET_YES if the client wants to pay more for 
the account now
- * @param payment_secret payment secret of last payment, or NULL (corresponds 
to the Taler order ID)
+ * @param paid_order_id payment identifier of last payment
  * @param cb callback processing the response from /policy
  * @param cb_cls closure for cb
  * @return handle for the operation
  */
 struct ANASTASIS_PolicyStoreOperation *
-ANASTASIS_policy_store (
-  struct GNUNET_CURL_Context *ctx,
-  const char *backend_url,
-  const struct ANASTASIS_CRYPTO_AccountPrivateKeyP *anastasis_priv,
-  const struct GNUNET_HashCode *prev_recovery_data_hash,
-  const void *recovery_data,
-  size_t recovery_data_size,
-  int payment_requested,
-  const struct ANASTASIS_PaymentSecretP *payment_secret,
-  ANASTASIS_PolicyStoreCallback cb,
-  void *cb_cls);
+ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
+                        const char *backend_url,
+                        const struct
+                        ANASTASIS_CRYPTO_AccountPrivateKeyP *anastasis_priv,
+                        const struct
+                        GNUNET_HashCode *prev_recovery_data_hash,
+                        const void *recovery_data,
+                        size_t recovery_data_size,
+                        int payment_requested,
+                        const struct ANASTASIS_PaymentSecretP *payment_secret,
+                        ANASTASIS_PolicyStoreCallback cb,
+                        void *cb_cls);
 
 
 /**
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index 5a066f9..90789f1 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -530,10 +530,7 @@ policy_lookup_cb (void *cls,
                                   size_plaintext,
                                   JSON_DECODE_ANY,
                                   &json_error);
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Recovery_document after json_loadb  %s\n",
-              json_dumps (recovery_document, JSON_COMPACT));
+  GNUNET_free (plaintext);
 
   struct GNUNET_JSON_Specification spec[] = {
     GNUNET_JSON_spec_json ("policies",
@@ -558,17 +555,12 @@ policy_lookup_cb (void *cls,
     return;
   }
   json_decref (recovery_document);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Decryption Policies after unpack  %s\n",
-              json_dumps (dec_policies, JSON_COMPACT | JSON_SORT_KEYS));
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Escrow Methods after unpack  %s\n",
-              json_dumps (esc_methods, JSON_COMPACT | JSON_SORT_KEYS));
+  GNUNET_JSON_parse_free (spec);
 
   r->ri->cs_len = json_array_size (esc_methods);
   r->ri->dps_len = json_array_size (dec_policies);
-  r->ri->dps = GNUNET_new_array (r->ri->dps_len, struct
-                                 ANASTASIS_DecryptionPolicy);
+  r->ri->dps = GNUNET_new_array (r->ri->dps_len,
+                                 struct ANASTASIS_DecryptionPolicy);
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "At %s:%d encrypted core secret is %s-%llu b\n", __FILE__,
@@ -672,8 +664,11 @@ policy_lookup_cb (void *cls,
 
     for (int a = 0; a < r->ri->dps[j].nonces_length; a++)
     {
-      char buf[52];
-      strncpy (buf,nonces + a * 52,52);
+      char buf[53];
+
+      GNUNET_strlcpy (buf,
+                      nonces + a * 52,
+                      52);
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "At %s:%d buf is %s\n", __FILE__, __LINE__,
                   buf);
@@ -796,7 +791,13 @@ ANASTASIS_recovery_abort (struct ANASTASIS_Recovery *r)
     ANASTASIS_policy_lookup_cancel (r->plo);
     r->plo = NULL;
   }
+  if (NULL != r->encrypted_recovery_document)
+  {
+    GNUNET_free (r->encrypted_recovery_document);
+    r->encrypted_recovery_document = NULL;
+  }
   GNUNET_free (r);
+  r = NULL;
 }
 
 
@@ -1091,6 +1092,8 @@ ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
                      "encrypted_truth", GNUNET_JSON_from_data (
                        encrypted_truth, encrypted_truth_size),
                      "truth_mime", mime_type);
+  GNUNET_free (encrypted_key_share);
+  GNUNET_free (encrypted_truth);
   if (NULL == truth)
   {
     GNUNET_break (0);
@@ -1268,7 +1271,11 @@ ANASTASIS_policy_create (const struct ANASTASIS_Truth 
*truths[],
 void
 ANASTASIS_policy_destroy (struct ANASTASIS_Policy *p)
 {
+  GNUNET_free (p->truths);
+  p->truths = NULL;
+
   GNUNET_free (p);
+  p = NULL;
 }
 
 
@@ -1382,26 +1389,32 @@ struct ANASTASIS_SecretShare
    * Callback which gives back the payment details
    */
   ANASTASIS_SharePaymentCallback spc;
+
   /**
    * Closure for the payment callback
    */
   void *spc_cls;
+
   /**
    * Callback which gives back the result of the POST Request
    */
   ANASTASIS_ShareResultCallback src;
+
   /**
    * Closure for the Result Callback
    */
   void *src_cls;
+
   /**
    * Closure for the Result Callback
    */
   struct GNUNET_CURL_Context *ctx;
+
   /**
    * References for the upload states and operations (size of truths passed)
    */
   struct PolicyStoreState **pss;
+
   /**
    * Closure for the Result Callback
    */
@@ -1409,6 +1422,32 @@ struct ANASTASIS_SecretShare
 };
 
 
+/**
+ * Free the state of a "policy store" CMD, and possibly
+ * cancel it if it did not complete.
+ *
+ * @param cls closure.
+ */
+static void
+policy_store_cleanup (void *cls)
+{
+  struct PolicyStoreState *pss = cls;
+
+  if (NULL != pss->pso)
+  {
+    ANASTASIS_policy_store_cancel (pss->pso);
+    pss->pso = NULL;
+  }
+  if (NULL != pss->recovery_data)
+  {
+    GNUNET_free (pss->recovery_data);
+    pss->recovery_data = NULL;
+  }
+  GNUNET_free (pss);
+  pss = NULL;
+}
+
+
 static void
 policy_store_cb (void *cls,
                  enum ANASTASIS_ErrorCode ec,
@@ -1481,6 +1520,8 @@ policy_store_cb (void *cls,
                         ec);
           pss->ss->spc = NULL;
         }
+        ANASTASIS_secret_share_cancel (pss->ss);
+        policy_store_cleanup (pss);
       }
       return;
     case ANASTASIS_US_CONFLICTING_POLICY:
@@ -1507,7 +1548,8 @@ policy_store_cb (void *cls,
                     http_status);
       pss->ss->src = NULL;
     }
-
+    ANASTASIS_secret_share_cancel (pss->ss);
+    policy_store_cleanup (pss);
   }
 }
 
@@ -1705,7 +1747,10 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "nonce is:  %s\n",
                   nonce_str);
-      strncpy (nonces + b * strlen (nonce_str), nonce_str, strlen (nonce_str));
+      GNUNET_strlcpy (nonces + b * strlen (nonce_str),
+                      nonce_str,
+                      strlen (nonce_str));
+      GNUNET_free (nonce_str);
     }
 
     nonces[52 * policies[k]->nonces_length] = '\0';
@@ -1735,11 +1780,6 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
       return NULL;
     }
 
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Dec policies json append before upload %d: %s\n",
-                k,
-                json_dumps (dec_policies, JSON_COMPACT));
-
     // FIXME CHALLENGE
     for (unsigned int l = 0; l < policies[k]->nonces_length; l++)
     {
@@ -1800,13 +1840,8 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
         return NULL;
       }
 
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Esc methods json append before upload %d: %s\n",
-                  l,
-                  json_dumps (esc_methods, JSON_COMPACT));
-
       // prepares policy store operation
-      int contains_url = 0;
+      bool contains_url = false;
       for (unsigned int j = 0; j < ss->pss_length; j++)
       {
         if (NULL != ss->pss[j]->anastasis_url)
@@ -1814,12 +1849,12 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
           if (0 == strcmp (ss->pss[j]->anastasis_url,
                            policies[k]->truths[l]->url))
           {
-            contains_url = 1;
+            contains_url = true;
             break;
           }
         }
       }
-      if (0 == contains_url)
+      if (! contains_url)
       {
         ss->pss[index_pss]->anastasis_url = policies[k]->truths[l]->url;
         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1857,10 +1892,6 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
     "core_secret", GNUNET_JSON_from_data (encrypted_core_secret,
                                           core_secret_size));
   GNUNET_assert (NULL != recovery_document);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "recovery document json before upload: %s\n",
-              json_dumps (recovery_document,
-                          JSON_COMPACT | JSON_SORT_KEYS));
 
   // FIXME COMPRESSION
   recovery_document_str = json_dumps (recovery_document,
@@ -1885,6 +1916,8 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
                                                 recovery_document_size,
                                                 &ss->pss[l]->recovery_data,
                                                 
&ss->pss[l]->recovery_data_size);
+    GNUNET_free (recovery_document_str);
+    recovery_document_str = NULL;
     // hash recovery data
     GNUNET_CRYPTO_hash (ss->pss[l]->recovery_data,
                         ss->pss[l]->recovery_data_size,
@@ -1925,5 +1958,20 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
 void
 ANASTASIS_secret_share_cancel (struct ANASTASIS_SecretShare *ss)
 {
-  // FIXME: implement!
+  if (NULL != ss)
+  {
+    if (NULL != ss->pss)
+    {
+      for (unsigned int i = 0; i< ss->pss_length; i++)
+      {
+        if (NULL != ss->pss[i])
+        {
+          GNUNET_free (ss->pss[i]);
+          ss->pss[i] = NULL;
+        }
+      }
+    }
+    GNUNET_free (ss);
+    ss = NULL;
+  }
 }
diff --git a/src/lib/anastasis_api_keyshare_lookup.c 
b/src/lib/anastasis_api_keyshare_lookup.c
index 2666a06..06111ad 100644
--- a/src/lib/anastasis_api_keyshare_lookup.c
+++ b/src/lib/anastasis_api_keyshare_lookup.c
@@ -282,10 +282,6 @@ ANASTASIS_keyshare_lookup (struct GNUNET_CURL_Context *ctx,
   }
   kslo = GNUNET_new (struct ANASTASIS_KeyShareLookupOperation);
   kslo->ctx = ctx;
-  /** FIXME duplicate? see line 323
-  kslo->cb = cb;
-  kslo->cb_cls = cb_cls;
-  */
   kslo->truth_key = truth_key;
   char *pub_key_str;
 
@@ -294,20 +290,14 @@ ANASTASIS_keyshare_lookup (struct GNUNET_CURL_Context 
*ctx,
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "truth public key in keyshare lookup:  %s\n",
               pub_key_str);
-  /*FIXME */
-
-
-
   GNUNET_asprintf (&path,
                    "truth/%s",
                    pub_key_str);
-
   kslo->url = TALER_url_join (backend_url,
                               path,
                               "response",
                               answer,
                               NULL);
-
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Url get request (keyshare lookup): %s\n",
               kslo->url);
@@ -327,6 +317,7 @@ ANASTASIS_keyshare_lookup (struct GNUNET_CURL_Context *ctx,
                                        &handle_keyshare_lookup_finished,
                                        kslo);
   GNUNET_free (path);
+  GNUNET_free (pub_key_str);
   curl_slist_free_all (job_headers);
   return kslo;
 }
diff --git a/src/lib/anastasis_api_truth_store.c 
b/src/lib/anastasis_api_truth_store.c
index e010315..87134a5 100644
--- a/src/lib/anastasis_api_truth_store.c
+++ b/src/lib/anastasis_api_truth_store.c
@@ -61,6 +61,11 @@ struct ANASTASIS_TruthStoreOperation
    */
   void *cb_cls;
 
+  /**
+   * Reference to data (for cleanup).
+   */
+  char *data;
+
   /**
    * Payment URI we received from the service, or NULL.
    */
@@ -83,6 +88,7 @@ ANASTASIS_truth_store_cancel (struct
   }
   GNUNET_free (tso->pay_uri);
   GNUNET_free (tso->url);
+  GNUNET_free (tso->data);
   GNUNET_free (tso);
 }
 
@@ -271,9 +277,6 @@ ANASTASIS_truth_store (struct GNUNET_CURL_Context *ctx,
   CURL *eh;
   char *json_str;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Truth json before upload 3: %s\n",
-              json_dumps (truth_data, JSON_COMPACT));
   json_str = json_dumps (truth_data,
                          JSON_COMPACT);
 
@@ -313,6 +316,7 @@ ANASTASIS_truth_store (struct GNUNET_CURL_Context *ctx,
                                    paid_order_id,
                                    NULL);
       GNUNET_free (path);
+      GNUNET_free (pub_key_str);
     }
     else
     {
@@ -325,6 +329,7 @@ ANASTASIS_truth_store (struct GNUNET_CURL_Context *ctx,
               "URL before curl:  %s\n",
               tso->url);
   tso->ctx = ctx;
+  tso->data = json_str;
   tso->cb = cb;
   tso->cb_cls = cb_cls;
   eh = ANASTASIS_curl_easy_get_ (tso->url);
diff --git a/src/lib/testing_api_cmd_keyshare_lookup.c 
b/src/lib/testing_api_cmd_keyshare_lookup.c
index f1bb85f..68fea91 100644
--- a/src/lib/testing_api_cmd_keyshare_lookup.c
+++ b/src/lib/testing_api_cmd_keyshare_lookup.c
@@ -153,14 +153,6 @@ keyshare_lookup_run (void *cls,
     }
   }
 
-  char *pub_key_str;
-  pub_key_str = GNUNET_STRINGS_data_to_string_alloc (ksls->truth_public_key,
-                                                     sizeof (*ksls->
-                                                             
truth_public_key));
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "truth public key in keyshare testing cmd:  %s\n",
-              pub_key_str);
-
   ksls->kslo = ANASTASIS_keyshare_lookup (is->ctx,
                                           ksls->anastasis_url,
                                           ksls->truth_public_key,
diff --git a/src/lib/testing_api_cmd_policy_store.c 
b/src/lib/testing_api_cmd_policy_store.c
index c200151..d573530 100644
--- a/src/lib/testing_api_cmd_policy_store.c
+++ b/src/lib/testing_api_cmd_policy_store.c
@@ -404,7 +404,7 @@ policy_store_run (void *cls,
 
 
 /**
- * Free the state of a "policy sore" CMD, and possibly
+ * Free the state of a "policy store" CMD, and possibly
  * cancel it if it did not complete.
  *
  * @param cls closure.
diff --git a/src/lib/testing_api_cmd_truth_store.c 
b/src/lib/testing_api_cmd_truth_store.c
index 13bd789..46ef43f 100644
--- a/src/lib/testing_api_cmd_truth_store.c
+++ b/src/lib/testing_api_cmd_truth_store.c
@@ -180,7 +180,9 @@ truth_store_cb (void *cls,
         return;
       }
     case ANASTASIS_US_HTTP_ERROR:
-      break;
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (tss->is);
+      return;
     case ANASTASIS_US_CLIENT_ERROR:
       GNUNET_break (0);
       TALER_TESTING_interpreter_fail (tss->is);
@@ -213,9 +215,7 @@ truth_store_run (void *cls,
 {
   struct TruthStoreState *tss = cls;
   tss->is = is;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Truth json before upload 2: %s\n",
-              json_dumps (tss->truth_data, JSON_COMPACT));
+
   if (NULL != tss->prev_upload)
   {
     const struct TALER_TESTING_Command *ref;
@@ -307,9 +307,13 @@ truth_store_cleanup (void *cls,
     ANASTASIS_truth_store_cancel (tss->tso);
     tss->tso = NULL;
   }
-
-  GNUNET_free (tss->payment_order_id);
+  if (NULL != tss->payment_order_id)
+  {
+    GNUNET_free (tss->payment_order_id);
+    tss->payment_order_id = NULL;
+  }
   GNUNET_free (tss);
+  tss = NULL;
 }
 
 
@@ -425,9 +429,6 @@ ANASTASIS_TESTING_make_truth_example (
                           "truth_mime", mime_type
                           );
   GNUNET_assert (NULL != truth_data);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Truth json before upload 0: %s\n",
-              json_dumps (truth_data, JSON_COMPACT));
   GNUNET_free (encrypted_truth);
   return truth_data;
 }
@@ -455,10 +456,6 @@ ANASTASIS_TESTING_cmd_truth_store (const char *label,
 {
   struct TruthStoreState *tss;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Truth json before upload 1: %s\n",
-              json_dumps (truth_data, JSON_COMPACT));
-
   tss = GNUNET_new (struct TruthStoreState);
   tss->truth_data = truth_data;
   tss->http_status = http_status;
diff --git a/src/lib/testing_cmd_policy_create.c 
b/src/lib/testing_cmd_policy_create.c
index 07d3a66..c685ade 100644
--- a/src/lib/testing_cmd_policy_create.c
+++ b/src/lib/testing_cmd_policy_create.c
@@ -55,7 +55,7 @@ struct PolicyCreateState
   /**
    * Policy object
    */
-  const struct ANASTASIS_Policy *policy;
+  struct ANASTASIS_Policy *policy;
 };
 
 
@@ -118,6 +118,7 @@ policy_create_run (void *cls,
 
   pcs->policy = ANASTASIS_policy_create (truths,
                                          pcs->cmd_label_array_length);
+
   if (NULL == pcs->policy)
   {
     GNUNET_break (0);
@@ -142,7 +143,9 @@ policy_create_cleanup (void *cls,
   struct PolicyCreateState *pcs = cls;
 
   GNUNET_free (pcs->cmd_label_array);
+  ANASTASIS_policy_destroy (pcs->policy);
   GNUNET_free (pcs);
+  pcs = NULL;
 }
 
 
diff --git a/src/lib/testing_cmd_secret_share.c 
b/src/lib/testing_cmd_secret_share.c
index cbf87bc..ac8bca1 100644
--- a/src/lib/testing_cmd_secret_share.c
+++ b/src/lib/testing_cmd_secret_share.c
@@ -390,7 +390,9 @@ secret_share_cleanup (void *cls,
   struct SecretShareState *sss = cls;
 
   GNUNET_free (sss->cmd_label_array);
+  sss->cmd_label_array = NULL;
   GNUNET_free (sss);
+  sss = NULL;
 }
 
 
diff --git a/src/lib/testing_cmd_truth_upload.c 
b/src/lib/testing_cmd_truth_upload.c
index fae9492..b73bbc4 100644
--- a/src/lib/testing_cmd_truth_upload.c
+++ b/src/lib/testing_cmd_truth_upload.c
@@ -106,7 +106,7 @@ struct TruthUploadState
   /**
    * Truth object
    */
-  const struct ANASTASIS_Truth *truth;
+  struct ANASTASIS_Truth *truth;
 };
 
 
@@ -243,6 +243,13 @@ truth_upload_cleanup (void *cls,
     ANASTASIS_truth_upload_cancel (tus->tuo);
     tus->tuo = NULL;
   }
+  if (NULL != tus->id_data)
+    json_decref ((json_t *) tus->id_data);
+  if (NULL != tus->truth)
+  {
+    GNUNET_free (tus->truth);
+    tus->truth = NULL;
+  }
   GNUNET_free (tus);
 }
 
diff --git a/src/stasis/plugin_anastasis_postgres.c 
b/src/stasis/plugin_anastasis_postgres.c
index c00667b..770ab17 100644
--- a/src/stasis/plugin_anastasis_postgres.c
+++ b/src/stasis/plugin_anastasis_postgres.c
@@ -267,6 +267,61 @@ postgres_gc (void *cls,
 }
 
 
+/**
+ * Check if there is already a valid code.
+ *
+ * @param pg postgres closure
+ * @param truth_public_key identifier for a challenge
+ * @param code code which will be safed to check later
+ * @param creation_date timestamp
+ * @return transaction status, NULL if codes are different
+ */
+static enum ANASTASIS_DB_QueryStatus
+check_valid_code (struct PostgresClosure *pg,
+                  const struct
+                  ANASTASIS_CRYPTO_TruthPublicKeyP *
+                  truth_public_key,
+                  uint64_t code,
+                  struct GNUNET_TIME_Absolute creation_date)
+{
+  enum ANASTASIS_DB_QueryStatus qs;
+  uint64_t server_code;
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_auto_from_type (truth_public_key),
+    TALER_PQ_query_param_absolute_time (&creation_date),
+    GNUNET_PQ_query_param_end
+  };
+  struct GNUNET_PQ_ResultSpec rs[] = {
+    GNUNET_PQ_result_spec_uint64 ("code",
+                                  &server_code),
+    GNUNET_PQ_result_spec_end
+  };
+  qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                 "challengecode_select",
+                                                 params,
+                                                 rs);
+  switch (qs)
+  {
+  case GNUNET_DB_STATUS_HARD_ERROR:
+    return ANASTASIS_DB_STATUS_HARD_ERROR;
+  case GNUNET_DB_STATUS_SOFT_ERROR:
+    GNUNET_break (0);
+    return ANASTASIS_DB_STATUS_SOFT_ERROR;
+  case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+    return ANASTASIS_DB_STATUS_NO_RESULTS;
+  case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+    if (server_code == code)
+    {
+      return ANASTASIS_DB_STATUS_VALID_CODE_STORED;
+    }
+    return ANASTASIS_DB_STATUS_CHALLENGE_CODE_MISSMATCH;
+  default:
+    GNUNET_break (0);
+    return ANASTASIS_DB_STATUS_HARD_ERROR;
+  }
+}
+
+
 /**
  * Closure for #payment_by_account_cb.
  */
@@ -466,7 +521,6 @@ postgres_store_recovery_document (void *cls,
     (*version)++;
     break;
   default:
-    // FIXME: Some Action
     rollback (pg);
     return qs;
   }
@@ -533,7 +587,6 @@ postgres_store_recovery_document (void *cls,
     rollback (pg);
     return qs;
   case ANASTASIS_DB_STATUS_SOFT_ERROR:
-    // FIXME: or: retry internally?
     rollback (pg);
     return qs;
   case ANASTASIS_DB_STATUS_NO_RESULTS:
@@ -547,7 +600,6 @@ postgres_store_recovery_document (void *cls,
                 postcounter);
     break;
   default:
-    // FIXME: Some Action
     rollback (pg);
     return qs;
   }
@@ -588,7 +640,6 @@ postgres_store_recovery_document (void *cls,
   case ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT:
     break;
   default:
-    // FIXME: Some Action
     rollback (pg);
     return qs;
   }
@@ -1251,7 +1302,7 @@ postgres_store_truth (void *cls,
   case ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT:
     break;
   default:
-    // FIXME: Some Action
+    rollback (pg);
     return qs;
   }
 
@@ -1323,6 +1374,7 @@ postgres_get_key_share (void *cls,
                         void **key_share,
                         size_t *key_share_size)
 {
+  enum ANASTASIS_DB_QueryStatus qs;
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_auto_from_type (truth_public_key),
@@ -1336,10 +1388,25 @@ postgres_get_key_share (void *cls,
   };
 
   check_connection (pg);
-  return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                   "key_share_select",
-                                                   params,
-                                                   rs);
+  qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                 "key_share_select",
+                                                 params,
+                                                 rs);
+  switch (qs)
+  {
+  case GNUNET_DB_STATUS_HARD_ERROR:
+    GNUNET_break (0);
+    return ANASTASIS_DB_STATUS_HARD_ERROR;
+  case GNUNET_DB_STATUS_SOFT_ERROR:
+    return ANASTASIS_DB_STATUS_SOFT_ERROR;
+  case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+    return ANASTASIS_DB_STATUS_NO_RESULTS;
+  case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+    return ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT;
+  default:
+    GNUNET_break (0);
+    return ANASTASIS_DB_STATUS_HARD_ERROR;
+  }
 }
 
 
@@ -1385,9 +1452,9 @@ postgres_lookup_account (void *cls,
   switch (qs)
   {
   case GNUNET_DB_STATUS_HARD_ERROR:
+    GNUNET_break (0);
     return ANASTASIS_DB_STATUS_HARD_ERROR;
   case GNUNET_DB_STATUS_SOFT_ERROR:
-    GNUNET_break (0);
     return ANASTASIS_DB_STATUS_SOFT_ERROR;
   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
     break; /* handle interesting case below */
@@ -1585,55 +1652,22 @@ postgres_verify_challenge_code (void *cls,
   struct PostgresClosure *pg = cls;
   enum ANASTASIS_DB_QueryStatus qs;
   struct GNUNET_TIME_Absolute time_now = GNUNET_TIME_absolute_get ();
+
+  check_connection (pg);
   GNUNET_TIME_round_abs (&time_now);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "At %s:%d Public key used to query db is: %s\n",
               __FILE__,
               __LINE__,
               TALER_B2S (truth_pub));
+  /*Check if there is already a valid code */
+  qs = check_valid_code (pg,
+                         truth_pub,
+                         code,
+                         time_now);
+  if (qs != ANASTASIS_DB_STATUS_CHALLENGE_CODE_MISSMATCH)
+    return qs;
 
-  {
-    uint64_t server_code;
-    struct GNUNET_PQ_QueryParam params[] = {
-      GNUNET_PQ_query_param_auto_from_type (truth_pub),
-      TALER_PQ_query_param_absolute_time (&time_now),
-      GNUNET_PQ_query_param_end
-    };
-
-    struct GNUNET_PQ_ResultSpec rs[] = {
-      GNUNET_PQ_result_spec_uint64 ("code",
-                                    &server_code),
-      GNUNET_PQ_result_spec_end
-    };
-
-    check_connection (pg);
-
-    qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                   "challengecode_select",
-                                                   params,
-                                                   rs);
-
-    switch (qs)
-    {
-    case GNUNET_DB_STATUS_HARD_ERROR:
-      return ANASTASIS_DB_STATUS_HARD_ERROR;
-    case GNUNET_DB_STATUS_SOFT_ERROR:
-      GNUNET_break (0);
-      return ANASTASIS_DB_STATUS_SOFT_ERROR;
-    case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
-      return ANASTASIS_DB_STATUS_NO_RESULTS;
-    case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
-
-      if (server_code == code)
-      {
-        return ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT;
-      }
-      break;
-    default:
-      GNUNET_break (0);
-      return ANASTASIS_DB_STATUS_HARD_ERROR;
-    }
-  }
   if (GNUNET_OK != begin_transaction (pg,
                                       "update_challenge_retry"))
   {
@@ -1825,55 +1859,24 @@ postgres_store_challenge_code (void *cls,
   enum ANASTASIS_DB_QueryStatus qs;
   struct GNUNET_TIME_Absolute creation_date = GNUNET_TIME_absolute_get ();
   struct GNUNET_TIME_Absolute expiration_date;
+
+  check_connection (pg);
   GNUNET_TIME_round_abs (&creation_date);
   expiration_date = GNUNET_TIME_absolute_add (creation_date,
                                               expiration_time);
-
   /*Check if there is already a valid code */
-  /*FIXME maybe put this in a function code reusage*/
-  uint64_t server_code;
-  {
-    struct GNUNET_PQ_QueryParam params[] = {
-      GNUNET_PQ_query_param_auto_from_type (truth_public_key),
-      TALER_PQ_query_param_absolute_time (&creation_date),
-      GNUNET_PQ_query_param_end
-    };
-    struct GNUNET_PQ_ResultSpec rs[] = {
-      GNUNET_PQ_result_spec_uint64 ("code",
-                                    &server_code),
-      GNUNET_PQ_result_spec_end
-    };
-
-    check_connection (pg);
-    qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                   "challengecode_select",
-                                                   params,
-                                                   rs);
-    switch (qs)
-    {
-    case GNUNET_DB_STATUS_HARD_ERROR:
-      return ANASTASIS_DB_STATUS_HARD_ERROR;
-    case GNUNET_DB_STATUS_SOFT_ERROR:
-      GNUNET_break (0);
-      return ANASTASIS_DB_STATUS_SOFT_ERROR;
-    case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
-      break;
-    case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
-      return ANASTASIS_DB_STATUS_VALID_CODE_STORED;
-    default:
-      GNUNET_break (0);
-      return ANASTASIS_DB_STATUS_HARD_ERROR;
-    }
-  }
-
-  check_connection (pg);
+  qs = check_valid_code (pg,
+                         truth_public_key,
+                         code,
+                         creation_date);
+  if (qs != ANASTASIS_DB_STATUS_NO_RESULTS)
+    return qs;
   if (GNUNET_OK != begin_transaction (pg,
                                       "store_challenge_code"))
   {
     GNUNET_break (0);
     return ANASTASIS_DB_STATUS_HARD_ERROR;
   }
-
   {
     struct GNUNET_PQ_QueryParam params[] = {
       GNUNET_PQ_query_param_auto_from_type (truth_public_key),
diff --git a/src/stasis/test_anastasis_db.c b/src/stasis/test_anastasis_db.c
index fcb51a7..1b4bd1e 100644
--- a/src/stasis/test_anastasis_db.c
+++ b/src/stasis/test_anastasis_db.c
@@ -273,8 +273,7 @@ run (void *cls)
                                          &truth_public_key,
                                          123));
 
-
-  FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
+  FAILIF (ANASTASIS_DB_STATUS_VALID_CODE_STORED !=
           plugin->verify_challenge_code (plugin->cls,
                                          &truth_public_key,
                                          challenge_code));

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]