gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 02/03: added api for config


From: gnunet
Subject: [taler-anastasis] 02/03: added api for config
Date: Tue, 19 May 2020 14:20:02 +0200

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

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

commit 646d6078db9688d18cb9a63bcb1fd495eca7b2f2
Author: Dennis Neufeld <address@hidden>
AuthorDate: Mon May 18 14:02:30 2020 +0000

    added api for config
---
 src/backend/Makefile.am                            |  1 +
 src/backend/anastasis-httpd.c                      | 25 +++++-
 src/backend/anastasis-httpd.h                      |  5 ++
 ...asis-httpd_terms.c => anastasis-httpd_config.c} | 24 +++---
 ...asis-httpd_terms.h => anastasis-httpd_config.h} | 22 ++---
 src/backend/anastasis-httpd_terms.c                |  3 +-
 src/backend/anastasis-httpd_terms.h                |  2 +-
 src/include/anastasis_service.h                    | 62 ++++++++++++++
 src/lib/Makefile.am                                |  1 +
 ...anastasis_api_salt.c => anastasis_api_config.c} | 97 +++++++++++-----------
 src/lib/anastasis_api_salt.c                       |  2 +-
 src/lib/test_anastasis_api.conf                    |  2 +
 12 files changed, 173 insertions(+), 73 deletions(-)

diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index 28b892a..975f2dd 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -19,6 +19,7 @@ anastasis_httpd_SOURCES = \
   anastasis-httpd_salt.c anastasis-httpd_salt.h \
   anastasis-httpd_truth.c anastasis-httpd_truth.h \
   anastasis-httpd_terms.c anastasis-httpd_terms.h \
+  anastasis-httpd_config.c anastasis-httpd_config.h \
   anastasis-httpd_truth_upload.c
 
 anastasis_httpd_LDADD = \
diff --git a/src/backend/anastasis-httpd.c b/src/backend/anastasis-httpd.c
index 52a0201..11d48b5 100644
--- a/src/backend/anastasis-httpd.c
+++ b/src/backend/anastasis-httpd.c
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  (C) 2019 Taler Systems SA
+  (C) 2020 Taler Systems SA
 
   TALER is free software; you can redistribute it and/or modify it under the
   terms of the GNU Affero General Public License as published by the Free 
Software
@@ -17,6 +17,8 @@
  * @file backup/anastasis-httpd.c
  * @brief HTTP serving layer intended to provide basic backup operations
  * @author Christian Grothoff
+ * @author Dennis Neufeld
+ * @author Dominik Meister
  */
 #include "platform.h"
 #include <microhttpd.h>
@@ -30,6 +32,7 @@
 #include "anastasis-httpd_truth.h"
 #include "anastasis-httpd_salt.h"
 #include "anastasis-httpd_terms.h"
+#include "anastasis-httpd_config.h"
 
 
 /**
@@ -42,6 +45,11 @@
  */
 unsigned long long int AH_upload_limit_mb;
 
+/**
+ * Supported methods.
+ */
+char *AH_supported_methods;
+
 /**
  * Annual fee for the backup account.
  */
@@ -225,6 +233,9 @@ url_handler (void *cls,
     { "/terms", MHD_HTTP_METHOD_GET, "text/plain",
       NULL, 0,
       &AH_handler_terms, MHD_HTTP_OK },
+    { "/config", MHD_HTTP_METHOD_GET, "text/plain",
+      NULL, 0,
+      &AH_handler_config, MHD_HTTP_OK },
     {NULL, NULL, NULL, NULL, 0, 0 }
   };
   static struct TMH_RequestHandler h404 = {
@@ -609,6 +620,18 @@ run (void *cls,
     GNUNET_SCHEDULER_shutdown ();
     return;
   }
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_string (config,
+                                             "anastasis",
+                                             "SUPPORTED_METHODS",
+                                             &AH_supported_methods))
+  {
+    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+                               "anastasis",
+                               "SUPPORTED_METHODS");
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
 
   /* setup HTTP client event loop */
   AH_ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
diff --git a/src/backend/anastasis-httpd.h b/src/backend/anastasis-httpd.h
index 14c6230..1f78555 100644
--- a/src/backend/anastasis-httpd.h
+++ b/src/backend/anastasis-httpd.h
@@ -151,6 +151,11 @@ extern struct TALER_Amount AH_annual_fee;
  */
 extern char *AH_backend_url;
 
+/**
+ * Supported methods.
+ */
+extern char *AH_supported_methods;
+
 /**
  * Our fulfillment URL
  */
diff --git a/src/backend/anastasis-httpd_terms.c 
b/src/backend/anastasis-httpd_config.c
similarity index 75%
copy from src/backend/anastasis-httpd_terms.c
copy to src/backend/anastasis-httpd_config.c
index ede38c6..a33ef56 100644
--- a/src/backend/anastasis-httpd_terms.c
+++ b/src/backend/anastasis-httpd_config.c
@@ -14,18 +14,18 @@
   Anastasis; see the file COPYING.GPL.  If not, see 
<http://www.gnu.org/licenses/>
 */
 /**
- * @file backend/anastasis-httpd_terms.c
+ * @file backend/anastasis-httpd_config.c
  * @brief headers for /terms handler
  * @author Christian Grothoff
  * @author Dennis Neufeld
  * @author Dominik Meister
  */
 #include "platform.h"
-#include "anastasis-httpd_terms.h"
+#include "anastasis-httpd_config.h"
 #include <taler/taler_json_lib.h>
 
 /**
- * Manages a /terms call.
+ * Manages a /config call.
  *
  * @param rh context of the handler
  * @param connection the MHD connection to handle
@@ -35,16 +35,18 @@
  * @param mi merchant backend instance, never NULL
  * @return MHD result code
  */
-int
-AH_handler_terms (struct TMH_RequestHandler *rh,
-                  struct MHD_Connection *connection,
-                  void **connection_cls,
-                  const char *upload_data,
-                  size_t *upload_data_size)
+MHD_RESULT
+AH_handler_config (struct TMH_RequestHandler *rh,
+                   struct MHD_Connection *connection,
+                   void **connection_cls,
+                   const char *upload_data,
+                   size_t *upload_data_size)
 {
   return TALER_MHD_reply_json_pack (connection,
                                     MHD_HTTP_OK,
-                                    "{s:I, s:o, s:s}",
+                                    "{s:s, s:I, s:o, s:s}",
+                                    "methods",
+                                    AH_supported_methods,
                                     "storage_limit_in_megabytes",
                                     (json_int_t) AH_upload_limit_mb,
                                     "annual_fee",
@@ -53,4 +55,4 @@ AH_handler_terms (struct TMH_RequestHandler *rh,
                                     "0.0");
 }
 
-/* end of anastasis-httpd_terms.c */
\ No newline at end of file
+/* end of anastasis-httpd_config.c */
\ No newline at end of file
diff --git a/src/backend/anastasis-httpd_terms.h 
b/src/backend/anastasis-httpd_config.h
similarity index 74%
copy from src/backend/anastasis-httpd_terms.h
copy to src/backend/anastasis-httpd_config.h
index 7d61cbf..f096369 100644
--- a/src/backend/anastasis-httpd_terms.h
+++ b/src/backend/anastasis-httpd_config.h
@@ -14,19 +14,19 @@
   Anastasis; see the file COPYING.GPL.  If not, see 
<http://www.gnu.org/licenses/>
 */
 /**
- * @file backend/anastasis-httpd_terms.h
+ * @file backend/anastasis-httpd_config.h
  * @brief headers for /terms handler
  * @author Christian Grothoff
  * @author Dennis Neufeld
  * @author Dominik Meister
  */
-#ifndef ANASTASIS_HTTPD_TERMS_H
-#define ANASTASIS_HTTPD_TERMS_H
+#ifndef ANASTASIS_HTTPD_CONFIG_H
+#define ANASTASIS_HTTPD_CONFIG_H
 #include <microhttpd.h>
 #include "anastasis-httpd.h"
 
 /**
- * Manages a /terms call.
+ * Manages a /config call.
  *
  * @param rh context of the handler
  * @param connection the MHD connection to handle
@@ -35,13 +35,13 @@
  * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
  * @return MHD result code
  */
-int
-AH_handler_terms (struct TMH_RequestHandler *rh,
-                  struct MHD_Connection *connection,
-                  void **connection_cls,
-                  const char *upload_data,
-                  size_t *upload_data_size);
+MHD_RESULT
+AH_handler_config (struct TMH_RequestHandler *rh,
+                   struct MHD_Connection *connection,
+                   void **connection_cls,
+                   const char *upload_data,
+                   size_t *upload_data_size);
 
 #endif
 
-/* end of anastasis-httpd_terms.h */
\ No newline at end of file
+/* end of anastasis-httpd_config.h */
\ No newline at end of file
diff --git a/src/backend/anastasis-httpd_terms.c 
b/src/backend/anastasis-httpd_terms.c
index ede38c6..999e68f 100644
--- a/src/backend/anastasis-httpd_terms.c
+++ b/src/backend/anastasis-httpd_terms.c
@@ -35,13 +35,14 @@
  * @param mi merchant backend instance, never NULL
  * @return MHD result code
  */
-int
+MHD_RESULT
 AH_handler_terms (struct TMH_RequestHandler *rh,
                   struct MHD_Connection *connection,
                   void **connection_cls,
                   const char *upload_data,
                   size_t *upload_data_size)
 {
+  // FIXME AGB
   return TALER_MHD_reply_json_pack (connection,
                                     MHD_HTTP_OK,
                                     "{s:I, s:o, s:s}",
diff --git a/src/backend/anastasis-httpd_terms.h 
b/src/backend/anastasis-httpd_terms.h
index 7d61cbf..8d918d9 100644
--- a/src/backend/anastasis-httpd_terms.h
+++ b/src/backend/anastasis-httpd_terms.h
@@ -35,7 +35,7 @@
  * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
  * @return MHD result code
  */
-int
+MHD_RESULT
 AH_handler_terms (struct TMH_RequestHandler *rh,
                   struct MHD_Connection *connection,
                   void **connection_cls,
diff --git a/src/include/anastasis_service.h b/src/include/anastasis_service.h
index ad1a9aa..64ce9f6 100644
--- a/src/include/anastasis_service.h
+++ b/src/include/anastasis_service.h
@@ -249,6 +249,68 @@ struct ANASTASIS_UploadDetails
 };
 
 
+typedef void
+(*ANASTASIS_ConfigCallback)(void *cls,
+                            unsigned int http_status,
+                            const char *methods,
+                            const struct TALER_Amount *cost);
+
+
+struct ANASTASIS_ConfigOperation *
+ANASTASIS_get_config (struct GNUNET_CURL_Context *ctx,
+                      const char *base_url,
+                      ANASTASIS_ConfigCallback cb,
+                      void *cb_cls);
+
+
+void
+ANASTASIS_config_cancel (struct ANASTASIS_ConfigOperation *co);
+
+
+/**
+ * @brief A Contract Operation Handle
+ */
+struct ANASTASIS_ConfigOperation
+{
+  /**
+   * The url for this request.
+   */
+  char *url;
+
+  /**
+   * Handle for the request.
+   */
+  struct GNUNET_CURL_Job *job;
+
+  /**
+   * Reference to the execution context.
+   */
+  struct GNUNET_CURL_Context *ctx;
+
+  /**
+  * The callback to pass the backend response to
+  */
+  ANASTASIS_ConfigCallback cb;
+
+  /**
+   * Closure for @a cb.
+   */
+  void *cb_cls;
+
+  /**
+   * Cost.
+   */
+  struct TALER_Amount cost;
+
+  /**
+   * Supported methods.
+   */
+  const char *methods;
+
+  // FIXME add configs
+};
+
+
 typedef void
 (*ANASTASIS_SaltCallback)(void *cls,
                           unsigned int http_status,
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index de8cf44..2123a29 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -18,6 +18,7 @@ libanastasisrest_la_LDFLAGS = \
   -no-undefined
 libanastasisrest_la_SOURCES = \
   anastasis_api_salt.c \
+  anastasis_api_config.c \
   anastasis_api_policy_store.c \
   anastasis_api_truth_store.c \
   anastasis_api_policy_lookup.c \
diff --git a/src/lib/anastasis_api_salt.c b/src/lib/anastasis_api_config.c
similarity index 60%
copy from src/lib/anastasis_api_salt.c
copy to src/lib/anastasis_api_config.c
index eac5e9e..aefcd45 100644
--- a/src/lib/anastasis_api_salt.c
+++ b/src/lib/anastasis_api_config.c
@@ -14,9 +14,11 @@
   Anastasis; see the file COPYING.GPL.  If not, see 
<http://www.gnu.org/licenses/>
 */
 /**
- * @file lib/anastasis_api_salt.c
- * @brief Implementation of the /salt GET
+ * @file lib/anastasis_api_config.c
+ * @brief Implementation of the /config GET
  * @author Christian Grothoff
+ * @author Dennis Neufeld
+ * @author Dominik Meister
  */
 #include "platform.h"
 #include <curl/curl.h>
@@ -31,32 +33,34 @@
 
 /**
  * Function called when we're done processing the
- * HTTP /salt request.
+ * HTTP /config request.
  *
- * @param cls the `struct ANASTASIS_SaltOperation`
+ * @param cls the `struct ANASTASIS_ConfigOperation`
  * @param response_code HTTP response code, 0 on error
  * @param response parsed JSON result, NULL on error
  */
 static void
-handle_salt_finished (void *cls,
-                      long response_code,
-                      const void *response)
+handle_config_finished (void *cls,
+                        long response_code,
+                        const void *response)
 {
-  struct ANASTASIS_SaltOperation *so = cls;
+  struct ANASTASIS_ConfigOperation *co = cls;
   const json_t *json = response;
 
-  so->job = NULL;
+  co->job = NULL;
   switch (response_code)
   {
   case 0:
     /* Hard error */
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Backend didn't even return from GET /policy\n");
+                "Backend didn't even return from GET /config\n");
     break;
   case MHD_HTTP_OK:
     {
       struct GNUNET_JSON_Specification spec[] = {
-        GNUNET_JSON_spec_fixed_auto ("server_salt", &so->salt),
+        GNUNET_JSON_spec_string ("methods", &co->methods),
+        GNUNET_JSON_spec_fixed_auto ("annual_fee", &co->cost),
+        // FIXME add configs
         GNUNET_JSON_spec_end ()
       };
 
@@ -69,15 +73,13 @@ handle_salt_finished (void *cls,
         return;
       }
 
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "At %s:%d Server Salt from Download is %s-%llu b\n", 
__FILE__,
-                  __LINE__,
-                  TALER_B2S (&so->salt),
-                  (unsigned long long) sizeof (so->salt));
-      so->cb (so->cb_cls,
+      co->cb (co->cb_cls,
               response_code,
-              &so->salt);
-      ANASTASIS_salt_cancel (so);
+              co->methods,
+              &co->cost
+              // FIXME add configs
+              );
+      ANASTASIS_config_cancel (co);
       return;
     }
   case MHD_HTTP_BAD_REQUEST:
@@ -100,53 +102,54 @@ handle_salt_finished (void *cls,
     response_code = 0;
     break;
   }
-  if (NULL != so->cb)
+  if (NULL != co->cb)
   {
-    so->cb (so->cb_cls,
+    co->cb (co->cb_cls,
             response_code,
+            NULL,
             NULL);
-    so->cb = NULL;
+    co->cb = NULL;
   }
-  ANASTASIS_salt_cancel (so);
+  ANASTASIS_config_cancel (co);
 }
 
 
-struct ANASTASIS_SaltOperation *
-ANASTASIS_salt (struct GNUNET_CURL_Context *ctx,
-                const char *base_url,
-                ANASTASIS_SaltCallback cb,
-                void *cb_cls)
+struct ANASTASIS_ConfigOperation *
+ANASTASIS_config (struct GNUNET_CURL_Context *ctx,
+                  const char *base_url,
+                  ANASTASIS_ConfigCallback cb,
+                  void *cb_cls)
 {
-  struct ANASTASIS_SaltOperation *so;
+  struct ANASTASIS_ConfigOperation *co;
   CURL *eh;
 
-  so = GNUNET_new (struct ANASTASIS_SaltOperation);
-  so->url = TALER_url_join (base_url,
-                            "salt",
+  co = GNUNET_new (struct ANASTASIS_ConfigOperation);
+  co->url = TALER_url_join (base_url,
+                            "config",
                             NULL);
-  so->ctx = ctx;
-  so->cb = cb;
-  so->cb_cls = cb_cls;
-  eh = ANASTASIS_curl_easy_get_ (so->url);
-  so->job = GNUNET_CURL_job_add2 (ctx,
+  co->ctx = ctx;
+  co->cb = cb;
+  co->cb_cls = cb_cls;
+  eh = ANASTASIS_curl_easy_get_ (co->url);
+  co->job = GNUNET_CURL_job_add2 (ctx,
                                   eh,
                                   GNUNET_NO,
-                                  &handle_salt_finished,
-                                  so);
-  return so;
+                                  &handle_config_finished,
+                                  co);
+  return co;
 }
 
 
 void
-ANASTASIS_salt_cancel (struct ANASTASIS_SaltOperation *so)
+ANASTASIS_config_cancel (struct ANASTASIS_ConfigOperation *co)
 {
-  if (NULL != so->job)
+  if (NULL != co->job)
   {
-    GNUNET_CURL_job_cancel (so->job);
-    so->job = NULL;
+    GNUNET_CURL_job_cancel (co->job);
+    co->job = NULL;
   }
-  GNUNET_free (so->url);
-  GNUNET_free (so);
+  GNUNET_free (co->url);
+  GNUNET_free (co);
 }
 
-/* end of anastasis_api_salt.c */
+/* end of anastasis_api_config.c */
diff --git a/src/lib/anastasis_api_salt.c b/src/lib/anastasis_api_salt.c
index eac5e9e..834b3bf 100644
--- a/src/lib/anastasis_api_salt.c
+++ b/src/lib/anastasis_api_salt.c
@@ -51,7 +51,7 @@ handle_salt_finished (void *cls,
   case 0:
     /* Hard error */
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Backend didn't even return from GET /policy\n");
+                "Backend didn't even return from GET /salt\n");
     break;
   case MHD_HTTP_OK:
     {
diff --git a/src/lib/test_anastasis_api.conf b/src/lib/test_anastasis_api.conf
index 1838b95..3a9fee2 100644
--- a/src/lib/test_anastasis_api.conf
+++ b/src/lib/test_anastasis_api.conf
@@ -42,6 +42,8 @@ ANNUAL_FEE = EUR:4.99
 # Upload limit
 UPLOAD_LIMIT_MB = 1
 
+SUPPORTED_METHODS = Secure-Question
+
 # This specifies which database the postgres backend uses.
 [anastasisdb-postgres]
 CONFIG = postgres:///anastasischeck

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



reply via email to

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