[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 02/04: mod/fix config api
From: |
gnunet |
Subject: |
[taler-anastasis] 02/04: mod/fix config api |
Date: |
Mon, 28 Sep 2020 15:21:25 +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 212384e6394090c1a5ad0034776ed83f3d4c377f
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Sun Sep 27 18:35:30 2020 +0200
mod/fix config api
---
src/backend/Makefile.am | 2 -
src/backend/anastasis-httpd_config.c | 88 ++++++++++++++++++++---------------
src/cli/anastasis-cli-splitter.c | 57 +++++++++++------------
src/include/anastasis_service.h | 9 +---
src/lib/anastasis_api_config.c | 12 ++++-
src/lib/anastasis_api_curl_defaults.c | 2 +
src/lib/anastasis_api_redux.c | 8 ++--
7 files changed, 96 insertions(+), 82 deletions(-)
diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index 975f2dd..c16b279 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -1,8 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-
-
pkgcfgdir = $(prefix)/share/anastasis/config.d/
pkgcfg_DATA = \
diff --git a/src/backend/anastasis-httpd_config.c
b/src/backend/anastasis-httpd_config.c
index 313e663..dae879a 100644
--- a/src/backend/anastasis-httpd_config.c
+++ b/src/backend/anastasis-httpd_config.c
@@ -21,6 +21,7 @@
* @author Dominik Meister
*/
#include "platform.h"
+#include <jansson.h>
#include "anastasis-httpd_config.h"
#include <taler/taler_json_lib.h>
@@ -42,78 +43,89 @@ AH_handler_config (struct TMH_RequestHandler *rh,
const char *upload_data,
size_t *upload_data_size)
{
- json_t *methods = json_array ();
+ json_t *methods = json_object ();
+ json_t *method_arr = json_array ();
+ if (! method_arr)
+ return MHD_HTTP_BAD_GATEWAY;
if (strstr (AH_supported_methods, "question"))
{
json_t *question = json_object ();
- json_t *question_cost = json_object ();
- json_object_set_new (question_cost,
- "method_cost",
- TALER_JSON_from_amount (&AH_question_cost));
json_object_set_new (question,
- "question",
- question);
- json_array_append_new (methods, question);
+ "method",
+ json_string ("question"));
+ json_object_set_new (question,
+ "cost",
+ TALER_JSON_from_amount (&AH_question_cost));
+ GNUNET_assert (
+ 0 ==
+ json_array_append_new (method_arr, question));
}
if (strstr (AH_supported_methods, "sms"))
{
json_t *sms = json_object ();
- json_t *sms_cost = json_object ();
- json_object_set_new (sms_cost,
- "method_cost",
- TALER_JSON_from_amount (&AH_sms_cost));
json_object_set_new (sms,
- "sms",
- sms);
- json_array_append_new (methods, sms);
+ "method",
+ json_string ("sms"));
+ json_object_set_new (sms,
+ "cost",
+ TALER_JSON_from_amount (&AH_sms_cost));
+ GNUNET_assert (
+ 0 ==
+ json_array_append_new (method_arr, sms));
}
if (strstr (AH_supported_methods, "email"))
{
json_t *email = json_object ();
- json_t *email_cost = json_object ();
- json_object_set_new (email_cost,
- "method_cost",
- TALER_JSON_from_amount (&AH_email_cost));
json_object_set_new (email,
- "email",
- email);
- json_array_append_new (methods, email);
+ "method",
+ json_string ("email"));
+ json_object_set_new (email,
+ "cost",
+ TALER_JSON_from_amount (&AH_email_cost));
+ GNUNET_assert (
+ 0 ==
+ json_array_append_new (method_arr, email));
}
if (strstr (AH_supported_methods, "video"))
{
json_t *video = json_object ();
- json_t *video_cost = json_object ();
- json_object_set_new (video_cost,
- "method_cost",
- TALER_JSON_from_amount (&AH_video_cost));
json_object_set_new (video,
- "video",
- video);
- json_array_append_new (methods, video);
+ "method",
+ json_string ("video"));
+ json_object_set_new (video,
+ "cost",
+ TALER_JSON_from_amount (&AH_video_cost));
+ GNUNET_assert (
+ 0 ==
+ json_array_append_new (method_arr, video));
}
if (strstr (AH_supported_methods, "post"))
{
json_t *post = json_object ();
- json_t *post_cost = json_object ();
- json_object_set_new (post_cost,
- "method_cost",
- TALER_JSON_from_amount (&AH_post_cost));
+
json_object_set_new (post,
- "post",
- post);
- json_array_append_new (methods, post);
+ "method",
+ json_string ("post"));
+ json_object_set_new (post,
+ "cost",
+ TALER_JSON_from_amount (&AH_post_cost));
+ GNUNET_assert (
+ 0 ==
+ json_array_append_new (method_arr, post));
}
+ json_object_set_new (methods, "methods", method_arr);
return TALER_MHD_reply_json_pack (connection,
MHD_HTTP_OK,
- "{s:s, s:o, s:I, s:s, s:o, s:s}",
+ "{s:s, s:s, s:I, s:s, s:o, s:s}",
"name", "anastasis",
- "methods", methods,
+ "methods",
+ json_dumps (methods, JSON_COMPACT),
"storage_limit_in_megabytes",
(json_int_t) AH_upload_limit_mb,
"currency",
diff --git a/src/cli/anastasis-cli-splitter.c b/src/cli/anastasis-cli-splitter.c
index 88e3b67..9a1b80e 100644
--- a/src/cli/anastasis-cli-splitter.c
+++ b/src/cli/anastasis-cli-splitter.c
@@ -753,49 +753,48 @@ read_keyboard_command (void *cls)
{
for (unsigned int i = 0; i < servers_length; i++)
{
- char *methods = "";
+ char *methods_str = "";
size_t index;
json_t *method;
+ json_t *method_arr = json_object_get (
+ servers[i].backend_methods, "methods");
- json_array_foreach (servers[i].backend_methods,
+ json_array_foreach (method_arr,
index,
method)
{
- char *buf;
- if (json_object_get (method, "sms"))
- GNUNET_asprintf (&buf,
- "%s sms ",
- methods);
- if (json_object_get (method, "question"))
- GNUNET_asprintf (&buf,
- "%s question ",
- methods);
- if (json_object_get (method, "email"))
- GNUNET_asprintf (&buf,
- "%s email ",
- methods);
- if (json_object_get (method, "post"))
- GNUNET_asprintf (&buf,
- "%s post ",
- methods);
- if (json_object_get (method, "video"))
- GNUNET_asprintf (&buf,
- "%s video ",
- methods);
- GNUNET_strlcpy (methods,
- buf,
- strlen (buf));
- GNUNET_free (buf);
+ char *buf = GNUNET_malloc (strlen (methods_str) + 1);
+ const char *method_str = json_string_value (
+ json_object_get (method, "method"));;
+ if (method_str)
+ {
+ if (strlen (methods_str) > 0)
+ {
+ GNUNET_strlcpy (buf,
+ methods_str,
+ strlen (methods_str));
+ GNUNET_free (methods_str);
+ GNUNET_asprintf (&methods_str,
+ ", %s, %s",
+ buf,
+ method_str);
+ }
+ else
+ GNUNET_asprintf (&methods_str,
+ "%s",
+ method_str);
+ GNUNET_free (buf);
+ }
}
if (NULL != servers[i].backend_url)
printf ("server#%u: %s %s, insured up to: %s, cost: %s\n",
i,
servers[i].backend_url,
- methods,
+ methods_str,
"test_insurance_amount", // FIXME
TALER_amount_to_string (servers[i].backend_cost)
);
- GNUNET_free (methods);
+ GNUNET_free (methods_str);
}
}
else
diff --git a/src/include/anastasis_service.h b/src/include/anastasis_service.h
index f4ad2af..d192afc 100644
--- a/src/include/anastasis_service.h
+++ b/src/include/anastasis_service.h
@@ -297,14 +297,7 @@ struct ANASTASIS_ConfigOperation
/**
* Supported methods.
*/
- const json_t *methods;
-
- /**
- * Cost of authentication by question
- * FIXME: Implement a more elegant way to
- * list costs of authentication methods
- */
- struct TALER_Amount question_cost;
+ json_t *methods;
/**
* Currency of the cost;
diff --git a/src/lib/anastasis_api_config.c b/src/lib/anastasis_api_config.c
index f51d6b1..ef69a69 100644
--- a/src/lib/anastasis_api_config.c
+++ b/src/lib/anastasis_api_config.c
@@ -47,6 +47,7 @@ handle_config_finished (void *cls,
{
struct ANASTASIS_ConfigOperation *co = cls;
const json_t *json = response;
+ json_error_t err;
co->job = NULL;
switch (response_code)
@@ -59,7 +60,6 @@ handle_config_finished (void *cls,
case MHD_HTTP_OK:
{
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_string ("methods", &co->methods),
GNUNET_JSON_spec_string ("currency", &co->currency),
TALER_JSON_spec_amount ("annual_fee", &co->cost),
// FIXME add configs
@@ -74,6 +74,9 @@ handle_config_finished (void *cls,
GNUNET_break (0);
return;
}
+ co->methods = json_loads (json_string_value (
+ json_object_get (json, "methods")),
+ JSON_DECODE_ANY, &err);
co->cb (co->cb_cls,
response_code,
@@ -81,6 +84,7 @@ handle_config_finished (void *cls,
co->currency,
&co->cost
);
+ GNUNET_JSON_parse_free (spec);
ANASTASIS_config_cancel (co);
return;
}
@@ -139,6 +143,12 @@ ANASTASIS_get_config (struct GNUNET_CURL_Context *ctx,
GNUNET_NO,
&handle_config_finished,
co);
+ if (NULL == co->job)
+ {
+ GNUNET_free (co->url);
+ GNUNET_free (co);
+ return NULL;
+ }
return co;
}
diff --git a/src/lib/anastasis_api_curl_defaults.c
b/src/lib/anastasis_api_curl_defaults.c
index f70e906..5e9b200 100644
--- a/src/lib/anastasis_api_curl_defaults.c
+++ b/src/lib/anastasis_api_curl_defaults.c
@@ -34,6 +34,8 @@ ANASTASIS_curl_easy_get_ (const char *url)
CURL *eh;
eh = curl_easy_init ();
+ if (NULL == eh)
+ return NULL;
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_URL,
diff --git a/src/lib/anastasis_api_redux.c b/src/lib/anastasis_api_redux.c
index 3793772..3859729 100644
--- a/src/lib/anastasis_api_redux.c
+++ b/src/lib/anastasis_api_redux.c
@@ -245,7 +245,7 @@ select_country (const json_t *state,
redux_id_attr_init (json_string_value (country)))
{
GNUNET_break (0);
- return NULL;
+ return;
}
new_state = json_deep_copy (state);
if (NULL == new_state)
@@ -304,7 +304,7 @@ change_country (const json_t *state,
redux_id_attr_init (json_string_value (country)))
{
GNUNET_break (0);
- return NULL;
+ return;
}
new_state = json_deep_copy (state);
if (NULL == new_state)
@@ -355,7 +355,7 @@ enter_user_attributes (const json_t *state,
if (NULL == path)
{
GNUNET_break (0);
- return GNUNET_SYSERR;
+ return;
}
GNUNET_asprintf (&dn,
"%s/share/anastasis/provider-list.json",
@@ -373,7 +373,7 @@ enter_user_attributes (const json_t *state,
error.column,
error.position);
GNUNET_free (dn);
- return GNUNET_SYSERR;
+ return;
}
if (NULL == state)
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.