gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: fix warnings


From: gnunet
Subject: [taler-anastasis] branch master updated: fix warnings
Date: Thu, 21 Nov 2019 09:12:26 +0100

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

grothoff pushed a commit to branch master
in repository anastasis.

The following commit(s) were added to refs/heads/master by this push:
     new ddae816  fix warnings
ddae816 is described below

commit ddae8169e80f8d99369ae6e5cf956132fbc5ab43
Author: Christian Grothoff <address@hidden>
AuthorDate: Thu Nov 21 09:12:18 2019 +0100

    fix warnings
---
 src/backend/anastasis-httpd_policy.c |  52 ++++----
 src/include/Makefile.in              |   2 +-
 src/lib/anastasis_api_policy.c       | 244 +++++++----------------------------
 3 files changed, 78 insertions(+), 220 deletions(-)

diff --git a/src/backend/anastasis-httpd_policy.c 
b/src/backend/anastasis-httpd_policy.c
index 3f23208..6ed7cc3 100644
--- a/src/backend/anastasis-httpd_policy.c
+++ b/src/backend/anastasis-httpd_policy.c
@@ -39,10 +39,11 @@ AH_handler_policy_GET (struct MHD_Connection *connection,
 {
   struct ANASTASIS_AccountPubP accountPubP;
   void *res_recovery_data;
-  size_t *res_recovery_data_size;
-
+  size_t res_recovery_data_size;
+  uint32_t version;
   const char *version_s;
   int ret;
+  enum ANASTASIS_DB_QueryStatus qs;
 
   GNUNET_assert (0 == strncmp (url,
                                "/policy/",
@@ -64,7 +65,7 @@ AH_handler_policy_GET (struct MHD_Connection *connection,
   version_s = MHD_lookup_connection_value (connection,
                                            MHD_GET_ARGUMENT_KIND,
                                            "version");
-  uint32_t version;
+
 
   if (NULL != version_s)
   {
@@ -77,25 +78,32 @@ AH_handler_policy_GET (struct MHD_Connection *connection,
                                              43 /*FIXME */,
                                              "version");
     }
-    db->get_recovery_document (db->cls,
-                               &accountPubP,
-                               version,
-                               res_recovery_data_size,
-                               res_recovery_data);
-    if (NULL == res_recovery_data_size)
-      return TMH_RESPONSE_reply_internal_error (connection,
-                                                42 /*FIXME*/,
-                                                "recovery data size not 
available");
+    qs = db->get_recovery_document (db->cls,
+                                    &accountPubP,
+                                    version,
+                                    &res_recovery_data_size,
+                                    &res_recovery_data);
   }
   else
   {
-    db->get_latest_recovery_document (db->cls,
-                                      &accountPubP,
-                                      res_recovery_data_size,
-                                      &res_recovery_data,
-                                      &version);
-  }
+    qs = db->get_latest_recovery_document (db->cls,
+                                           &accountPubP,
+                                           &res_recovery_data_size,
+                                           &res_recovery_data,
+                                           &version);
 
+  }
+  switch (qs)
+  {
+  // FIXME: handle DB error cases!
+  case ANASTASIS_DB_STATUS_SUCCESS_NO_RESULTS:
+    return TMH_RESPONSE_reply_not_found (connection,
+                                         42 /*FIXME*/,
+                                         "recovery data not available");
+  case ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT:
+    GNUNET_assert (NULL != res_recovery_data);
+    break;
+  }
 
   // BUILD reply
   // binary reply
@@ -106,7 +114,7 @@ AH_handler_policy_GET (struct MHD_Connection *connection,
     *         - version of returned encrypted recovery document
     *         - Etag if Status 200 OK
     */
-    //FIXME: Find correct create_response
+    // FIXME: Find correct create_response
     response = MHD_create_response_from_buffer (sizeof (res_recovery_data),
                                                 res_recovery_data,
                                                 MHD_RESPMEM_MUST_FREE);
@@ -147,9 +155,9 @@ AH_handler_policy_POST (struct MHD_Connection *connection,
   int ret;
 
   GNUNET_STRINGS_string_to_data (upload_data,
-                                strlen (upload_data),
-                                &recovery_data,
-                                sizeof (recovery_data));
+                                 strlen (upload_data),
+                                 &recovery_data,
+                                 sizeof (recovery_data));
 
   GNUNET_assert (0 == strncmp (url,
                                "/policy/",
diff --git a/src/include/Makefile.in b/src/include/Makefile.in
index e97a65e..5ab40c9 100644
--- a/src/include/Makefile.in
+++ b/src/include/Makefile.in
@@ -348,7 +348,7 @@ anastasisinclude_HEADERS = \
   anastasis_database_plugin.h \
   anastasis_service.h \
   anastasis_error_codes.h \
-  anastasis_database_lib.h
+  anastasis_database_lib.h 
 
 all: all-am
 
diff --git a/src/lib/anastasis_api_policy.c b/src/lib/anastasis_api_policy.c
index 010f26f..1549453 100644
--- a/src/lib/anastasis_api_policy.c
+++ b/src/lib/anastasis_api_policy.c
@@ -183,110 +183,6 @@ handle_policy_lookup_finished (void *cls,
 }
 
 
-/**
- * Make an absolute URL with query parameters.
- *
- * @param base_url absolute base URL to use
- * @param path path of the url
- * @param account_pub anastasis account pub (eddsa)
- * @param ... NULL-terminated key-value pairs (char *) for query parameters,
- *        the value will be url-encoded
- * @returns the URL (must be freed with #GNUNET_free) or
- *          NULL if an error occured.
- */
-char *
-ANASTASIS_url_join (const char *base_url,
-                    const char *path,
-                    const struct ANASTASIS_AccountPubP *anastasis_pub,
-                    ...)
-{
-  unsigned int iparam = 0;
-  va_list args;
-  struct TALER_Buffer buf = { 0 };
-  size_t len = 0;
-
-  GNUNET_assert (NULL != base_url);
-  GNUNET_assert (NULL != path);
-  GNUNET_assert (NULL != anastasis_pub);
-
-  if (strlen (base_url) == 0)
-  {
-    /* base URL can't be empty */
-    GNUNET_break (0);
-    return NULL;
-  }
-
-  if ('/' != base_url[strlen (base_url) - 1])
-  {
-    /* Must be an actual base URL! */
-    GNUNET_break (0);
-    return NULL;
-  }
-
-  if ('/' == path[0])
-  {
-    /* The path must be relative. */
-    GNUNET_break (0);
-    return NULL;
-  }
-
-  // Path should be relative to existing path of base URL
-  GNUNET_break ('/' != path[0]);
-
-  if ('/' == path[0])
-    GNUNET_break (0);
-
-  // Convert account pub to base32 encoded string
-  const char *acc_pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (
-    &anastasis_pub->pub);
-
-  /* 1st pass: compute length */
-  len += strlen (base_url) + strlen (path) + strlen (acc_pub_str);
-
-  va_start (args, anastasis_pub);
-  while (1)
-  {
-    char *key;
-    char *value;
-    key = va_arg (args, char *);
-    if (NULL == key)
-      break;
-    value = va_arg (args, char *);
-    if (NULL == value)
-      continue;
-    len += urlencode_len (value) + strlen (key) + 2;
-  }
-  va_end (args);
-
-  TALER_buffer_prealloc (&buf, len);
-
-  TALER_buffer_write_str (&buf, base_url);
-  TALER_buffer_write_str (&buf, path);
-  TALER_buffer_write_str (&buf, acc_pub_str);
-
-  va_start (args, anastasis_pub);
-  while (1)
-  {
-    char *key;
-    char *value;
-    key = va_arg (args, char *);
-    if (NULL == key)
-      break;
-    value = va_arg (args, char *);
-    if (NULL == value)
-      continue;
-    TALER_buffer_write_str (&buf, (0 == iparam) ? "?" : "&");
-    iparam++;
-    TALER_buffer_write_str (&buf, key);
-    TALER_buffer_write_str (&buf, "=");
-    buffer_write_urlencode (&buf, value);
-  }
-  va_end (args);
-
-  return TALER_buffer_reap_str (&buf);
-}
-
-
 /**
  * Does a GET /policy.
  *
@@ -306,16 +202,22 @@ ANASTASIS_policy_lookup (struct GNUNET_CURL_Context *ctx,
 {
   struct ANASTASIS_PolicyLookupOperation *plo;
   CURL *eh;
+  char *acc_pub_str;
+  char *path;
 
   plo = GNUNET_new (struct ANASTASIS_PolicyLookupOperation);
   plo->ctx = ctx;
   plo->cb = cb;
   plo->cb_cls = cb_cls;
-
+  acc_pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (&anastasis_pub->pub);
+  GNUNET_asprintf (&path,
+                   "policy/%s",
+                   acc_pub_str);
+  GNUNET_free (acc_pub_str);
   plo->url = TALER_url_join (backend_url,
-                             "policy",
-                             anastasis_pub);
-
+                             path,
+                             NULL);
+  GNUNET_free (path);
   eh = curl_easy_init ();
   if (CURLE_OK != curl_easy_setopt (eh,
                                     CURLOPT_URL,
@@ -362,19 +264,24 @@ ANASTASIS_policy_lookup_version (struct 
GNUNET_CURL_Context *ctx,
 {
   struct ANASTASIS_PolicyLookupOperation *plo;
   CURL *eh;
+  char *acc_pub_str;
+  char *path;
 
   plo = GNUNET_new (struct ANASTASIS_PolicyLookupOperation);
   plo->ctx = ctx;
   plo->cb = cb;
   plo->cb_cls = cb_cls;
-
-  // plo->url = TALER_url_join (backend_url, "policy", "order_id", order_id, 
NULL);
+  acc_pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (&anastasis_pub->pub);
+  GNUNET_asprintf (&path,
+                   "policy/%s",
+                   acc_pub_str);
+  GNUNET_free (acc_pub_str);
   plo->url = TALER_url_join (backend_url,
-                             "policy",
-                             anastasis_pub,
+                             path,
                              "version",
-                             version);
-
+                             version,
+                             NULL);
+  GNUNET_free (path);
   eh = curl_easy_init ();
   if (CURLE_OK != curl_easy_setopt (eh,
                                     CURLOPT_URL,
@@ -486,72 +393,6 @@ ANASTASIS_policy_store_cancel (struct
 }
 
 
-/**
- * Add the @a body as POST data to the easy handle in @a ctx.
- *
- * @param ctx[in,out] a request context (updated)
- * @param eh easy handle to use
- * @param body bytestream to add to @e ctx
- * @return #GNUNET_OK on success #GNUNET_SYSERR on failure
- */
-int
-ANASTASIS_curl_easy_post (struct TEAH_PostContext *ctx,
-                          CURL *eh,
-                          const void *body,
-                          size_t body_size)
-{
-    size_t slen;
-
-    if (NULL == body)
-    {
-        GNUNET_break (0);
-        return GNUNET_SYSERR;
-    }
-#if COMPRESS_BODIES
-    {
-        Bytef *cbuf;
-        uLongf cbuf_size;
-        int ret;
-
-        cbuf_size = compressBound (body_size);
-        cbuf = GNUNET_malloc (cbuf_size);
-        ret = compress (cbuf,
-                        &cbuf_size,
-                        (const Bytef *) body,
-                        body_size);
-        if (Z_OK != ret)
-        {
-        /* compression failed!? */
-        GNUNET_break (0);
-        GNUNET_free (cbuf);
-        return GNUNET_SYSERR;
-        }
-        slen = (size_t) cbuf_size;
-        ctx->json_enc = (char *) cbuf;
-    }
-    GNUNET_assert
-        (NULL != (ctx->headers = curl_slist_append
-                                (ctx->headers,
-                                "Content-Encoding: deflate")));
-#endif
-
-    GNUNET_assert
-        (NULL != (ctx->headers = curl_slist_append
-                                (ctx->headers,
-                                "Content-Type: anastasis/encrypted-policy")));
-
-    GNUNET_assert (CURLE_OK ==
-                    curl_easy_setopt (eh,
-                                    CURLOPT_POSTFIELDS,
-                                    body));
-    GNUNET_assert (CURLE_OK ==
-                    curl_easy_setopt (eh,
-                                    CURLOPT_POSTFIELDSIZE,
-                                    slen));
-    return GNUNET_OK;
-}
-
-
 /**
  * Store policies, does a POST /policy/$AccountPub
  *
@@ -569,34 +410,43 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
                         ANASTASIS_AccountPubP *anastasis_pub,
                         const void *policy_data,
                         size_t policy_data_size,
-                        const struct 
+                        const struct
                         ANASTASIS_PaymentSecretP *paymentSecretP,
                         ANASTASIS_PolicyStoreCallback cb,
                         void *cb_cls)
 {
   struct ANASTASIS_PolicyStoreOperation *pso;
   CURL *eh;
+  char *acc_pub_str;
+  char *path;
 
+  GNUNET_assert (NULL != policy_data);
   pso = GNUNET_new (struct ANASTASIS_PolicyStoreOperation);
   pso->ctx = ctx;
   pso->cb = cb;
   pso->cb_cls = cb_cls;
-  pso->url = ANASTASIS_url_join (backend_url, 
-                                 "policy",
-                                 anastasis_pub);
+  acc_pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (&anastasis_pub->pub);
+  GNUNET_asprintf (&path,
+                   "policy/%s",
+                   acc_pub_str);
+  GNUNET_free (acc_pub_str);
+  pso->url = TALER_url_join (backend_url,
+                             "policy",
+                             anastasis_pub);
+  GNUNET_free (path);
   eh = curl_easy_init ();
-  if (CURLE_OK != ANASTASIS_curl_easy_post (&pso->post_ctx,
-                                            eh,
-                                            policy_data,
-                                            policy_data_size))
-  {
-    GNUNET_break (0);
-    GNUNET_free (pso);
-    return NULL;
-  }
-
-  
-
+  GNUNET_assert
+    (NULL != (pso->post_ctx.headers = curl_slist_append
+                                        (pso->post_ctx.headers,
+                                        "Content-Type: 
anastasis/encrypted-policy")));
+  GNUNET_assert (CURLE_OK ==
+                 curl_easy_setopt (eh,
+                                   CURLOPT_POSTFIELDS,
+                                   policy_data));
+  GNUNET_assert (CURLE_OK ==
+                 curl_easy_setopt (eh,
+                                   CURLOPT_POSTFIELDSIZE,
+                                   policy_data_size));
   GNUNET_assert (CURLE_OK == curl_easy_setopt (eh,
                                                CURLOPT_URL,
                                                pso->url));
@@ -608,4 +458,4 @@ ANASTASIS_policy_store (struct GNUNET_CURL_Context *ctx,
                pso);
 
   return pso;
-}
\ No newline at end of file
+}

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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