[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 01/04: modified config api
From: |
gnunet |
Subject: |
[taler-anastasis] 01/04: modified config api |
Date: |
Mon, 28 Sep 2020 15:21:24 +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 9a3996b927c40ff7f6e857ff22fe2f34babad068
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Sat Sep 26 11:43:45 2020 +0200
modified config api
---
src/backend/anastasis-httpd.c | 22 ++++++++++-
src/backend/anastasis-httpd.h | 22 ++++++++++-
src/backend/anastasis-httpd_config.c | 74 +++++++++++++++++++++++++++++++++---
src/cli/anastasis-cli-assembler.c | 31 ++++++++++-----
src/cli/anastasis-cli-splitter.c | 68 ++++++++++++++++++++++++++-------
src/include/anastasis_service.h | 7 ++--
src/lib/anastasis_api_config.c | 6 +--
7 files changed, 190 insertions(+), 40 deletions(-)
diff --git a/src/backend/anastasis-httpd.c b/src/backend/anastasis-httpd.c
index 30f3eff..6142e7f 100644
--- a/src/backend/anastasis-httpd.c
+++ b/src/backend/anastasis-httpd.c
@@ -59,11 +59,29 @@ const struct GNUNET_CONFIGURATION_Handle *AH_cfg;
/**
* Cost of authentication by question
- * FIXME: Implement a more elegant way to
- * list costs of authentication methods
*/
struct TALER_Amount AH_question_cost;
+/**
+ * Cost of authentication by email
+ */
+struct TALER_Amount AH_email_cost;
+
+/**
+ * Cost of authentication by post
+ */
+struct TALER_Amount AH_post_cost;
+
+/**
+ * Cost of authentication by video
+ */
+struct TALER_Amount AH_video_cost;
+
+/**
+ * Cost of authentication by sms
+ */
+struct TALER_Amount AH_sms_cost;
+
/**
* Our Taler backend to process payments.
*/
diff --git a/src/backend/anastasis-httpd.h b/src/backend/anastasis-httpd.h
index c54003f..188a824 100644
--- a/src/backend/anastasis-httpd.h
+++ b/src/backend/anastasis-httpd.h
@@ -153,11 +153,29 @@ extern struct TALER_Amount AH_annual_fee;
/**
* Cost of authentication by question
- * FIXME: Implement a more elegant way to
- * list costs of authentication methods
*/
extern struct TALER_Amount AH_question_cost;
+/**
+ * Cost of authentication by email
+ */
+extern struct TALER_Amount AH_email_cost;
+
+/**
+ * Cost of authentication by post
+ */
+extern struct TALER_Amount AH_post_cost;
+
+/**
+ * Cost of authentication by video
+ */
+extern struct TALER_Amount AH_video_cost;
+
+/**
+ * Cost of authentication by sms
+ */
+extern struct TALER_Amount AH_sms_cost;
+
/**
* Our Taler backend to process payments.
*/
diff --git a/src/backend/anastasis-httpd_config.c
b/src/backend/anastasis-httpd_config.c
index 3340c8f..313e663 100644
--- a/src/backend/anastasis-httpd_config.c
+++ b/src/backend/anastasis-httpd_config.c
@@ -42,20 +42,84 @@ AH_handler_config (struct TMH_RequestHandler *rh,
const char *upload_data,
size_t *upload_data_size)
{
+ json_t *methods = json_array ();
+
+ 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);
+ }
+ 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);
+ }
+ 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);
+ }
+ 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);
+ }
+ 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);
+ }
return TALER_MHD_reply_json_pack (connection,
MHD_HTTP_OK,
- "{s:s, s:s, s:I, s:s, s:o, s:o, s:s}",
+ "{s:s, s:o, s:I, s:s, s:o, s:s}",
"name", "anastasis",
- "methods",
- (char *) AH_supported_methods,
+ "methods", methods,
"storage_limit_in_megabytes",
(json_int_t) AH_upload_limit_mb,
"currency",
(char *) AH_currency,
"annual_fee",
TALER_JSON_from_amount (&AH_annual_fee),
- "question_cost",
- TALER_JSON_from_amount
(&AH_question_cost), // FIXME: implement a more elegant solution
"version", "0:0:0");
}
diff --git a/src/cli/anastasis-cli-assembler.c
b/src/cli/anastasis-cli-assembler.c
index 565a524..fbd6d4b 100644
--- a/src/cli/anastasis-cli-assembler.c
+++ b/src/cli/anastasis-cli-assembler.c
@@ -48,7 +48,7 @@ static unsigned int import_recovery_version;
static struct GNUNET_SCHEDULER_Task *keyboard_task;
/**
- * Curl context for communication with taler backend
+ * Curl context for communication with anastasis backend
*/
static struct GNUNET_CURL_Context *ctx;
@@ -558,17 +558,17 @@ start_read_keyboard ()
* @param methods supported methods by this provider
* @param conf_currency
* @param annual_fee Annual fee of this service
- * @param question_cost Cost for authentication by question
*/
static void
config_cb (void *cls,
unsigned int http_status,
- const char *methods,
+ const json_t *methods,
const char *conf_currency,
- const struct TALER_Amount *annual_fee,
- const struct TALER_Amount *question_cost)
+ const struct TALER_Amount *annual_fee)
{
struct ConfigState *cs = cls;
+ size_t index;
+ json_t *method;
cs->co = NULL;
if (http_status != cs->http_status)
@@ -581,10 +581,23 @@ config_cb (void *cls,
return;
}
- cs->ci->cost = GNUNET_new (struct TALER_Amount);
- GNUNET_memcpy (cs->ci->cost,
- question_cost,
- sizeof (*question_cost));
+ json_t *method_arr = json_object_get (methods,
+ "methods");
+ json_array_foreach (method_arr, index, method)
+ {
+ if (json_object_get (method, cs->ci->method))
+ {
+ struct TALER_Amount *amount;
+ TALER_string_to_amount (json_string_value (json_object_get (
+ method, "method_cost")),
+ amount);
+ cs->ci->cost = GNUNET_new (struct TALER_Amount);
+ GNUNET_memcpy (cs->ci->cost,
+ amount,
+ sizeof (*amount));
+ break;
+ }
+ }
cs->ci->currency = GNUNET_malloc (strlen (conf_currency) + 1);
GNUNET_strlcpy (cs->ci->currency,
conf_currency,
diff --git a/src/cli/anastasis-cli-splitter.c b/src/cli/anastasis-cli-splitter.c
index eb37db8..88e3b67 100644
--- a/src/cli/anastasis-cli-splitter.c
+++ b/src/cli/anastasis-cli-splitter.c
@@ -132,7 +132,7 @@ struct ServerInfo
/**
* supported methods of the anastasis backend.
*/
- char *backend_methods;
+ json_t *backend_methods;
/**
* server salt of the anastasis backend.
@@ -209,7 +209,7 @@ struct ConfigState
/**
* Supported methods.
*/
- char *methods;
+ json_t *methods;
// FIXME add configs
};
@@ -559,15 +559,13 @@ truth_upload_cb (void *cls,
* @param http_status HTTP status of the request
* @param methods supported methods by this provider
* @param annual_fee Annual fee of this service
- * @param question_cost Cost for authentication by question
*/
static void
config_cb (void *cls,
unsigned int http_status,
- const char *methods,
+ const json_t *methods,
const char *conf_currency,
- const struct TALER_Amount *annual_fee,
- const struct TALER_Amount *question_cost)
+ const struct TALER_Amount *annual_fee)
{
struct ConfigState *cs = cls;
struct ANASTASIS_PaymentDetails *pd = GNUNET_new (struct
@@ -592,10 +590,7 @@ config_cb (void *cls,
}
cs->cost = *annual_fee;
- cs->methods = GNUNET_malloc (strlen (methods) + 1);
- GNUNET_strlcpy (cs->methods,
- methods,
- strlen (methods) + 1);
+ cs->methods = methods;
printf ("Server #%u is available\n",
servers_length);
@@ -758,14 +753,49 @@ read_keyboard_command (void *cls)
{
for (unsigned int i = 0; i < servers_length; i++)
{
+ char *methods = "";
+ size_t index;
+ json_t *method;
+
+ json_array_foreach (servers[i].backend_methods,
+ 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);
+ }
if (NULL != servers[i].backend_url)
printf ("server#%u: %s %s, insured up to: %s, cost: %s\n",
i,
servers[i].backend_url,
- servers[i].backend_methods,
+ methods,
"test_insurance_amount", // FIXME
TALER_amount_to_string (servers[i].backend_cost)
);
+ GNUNET_free (methods);
}
}
else
@@ -922,8 +952,20 @@ read_keyboard_command (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"At %s:%d method is %s\n", __FILE__, __LINE__,
tus->method);
- if (NULL != strstr (servers[server_num].backend_methods,
- tus->method))
+ bool method_supported = false;
+ size_t index;
+ json_t *method;
+ json_t *methods = json_object_get (servers[server_num].backend_methods,
+ "methods");
+ json_array_foreach (methods, index, method)
+ {
+ if (json_object_get (method, tus->method))
+ {
+ method_supported = true;
+ break;
+ }
+ }
+ if (method_supported)
{
if (0 == strcmp ("question", tus->method))
{
diff --git a/src/include/anastasis_service.h b/src/include/anastasis_service.h
index 93df99c..f4ad2af 100644
--- a/src/include/anastasis_service.h
+++ b/src/include/anastasis_service.h
@@ -243,10 +243,9 @@ struct ANASTASIS_UploadDetails
typedef void
(*ANASTASIS_ConfigCallback)(void *cls,
unsigned int http_status,
- const char *methods,
+ const json_t *methods,
const char *conf_currency,
- const struct TALER_Amount *annual_fee,
- const struct TALER_Amount *question_cost);
+ const struct TALER_Amount *annual_fee);
struct ANASTASIS_ConfigOperation *
@@ -298,7 +297,7 @@ struct ANASTASIS_ConfigOperation
/**
* Supported methods.
*/
- const char *methods;
+ const json_t *methods;
/**
* Cost of authentication by question
diff --git a/src/lib/anastasis_api_config.c b/src/lib/anastasis_api_config.c
index 54c3337..f51d6b1 100644
--- a/src/lib/anastasis_api_config.c
+++ b/src/lib/anastasis_api_config.c
@@ -62,7 +62,6 @@ handle_config_finished (void *cls,
GNUNET_JSON_spec_string ("methods", &co->methods),
GNUNET_JSON_spec_string ("currency", &co->currency),
TALER_JSON_spec_amount ("annual_fee", &co->cost),
- TALER_JSON_spec_amount ("question_cost", &co->question_cost),
// FIXME add configs
GNUNET_JSON_spec_end ()
};
@@ -80,9 +79,7 @@ handle_config_finished (void *cls,
response_code,
co->methods,
co->currency,
- &co->cost,
- &co->question_cost
- // FIXME add configs
+ &co->cost
);
ANASTASIS_config_cancel (co);
return;
@@ -113,7 +110,6 @@ handle_config_finished (void *cls,
response_code,
NULL,
NULL,
- NULL,
NULL);
co->cb = NULL;
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.