[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 01/08: add insurance to config
From: |
gnunet |
Subject: |
[taler-anastasis] 01/08: add insurance to config |
Date: |
Fri, 06 Nov 2020 18:06:26 +0100 |
This is an automated email from the git hooks/post-receive script.
dennis-neufeld pushed a commit to branch master
in repository anastasis.
commit e412d24ae07610e3ed1fd3c574bae823e623f84b
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Mon Nov 2 15:19:59 2020 +0100
add insurance to config
---
src/backend/anastasis-httpd.c | 17 ++++++++
src/backend/anastasis-httpd.h | 5 +++
src/backend/anastasis-httpd_config.c | 68 ++++++++++++++-----------------
src/backend/anastasis.conf | 3 ++
src/include/anastasis_service.h | 3 +-
src/lib/anastasis_api_backup_redux.c | 79 +++++++++++++++++++++---------------
src/lib/anastasis_api_config.c | 10 ++++-
src/lib/anastasis_api_redux.c | 11 +++--
8 files changed, 120 insertions(+), 76 deletions(-)
diff --git a/src/backend/anastasis-httpd.c b/src/backend/anastasis-httpd.c
index c5d56d5..6f9e529 100644
--- a/src/backend/anastasis-httpd.c
+++ b/src/backend/anastasis-httpd.c
@@ -55,6 +55,11 @@ char *AH_supported_methods;
*/
struct TALER_Amount AH_annual_fee;
+/**
+ * Amount of insurance.
+ */
+struct TALER_Amount AH_insurance;
+
const struct GNUNET_CONFIGURATION_Handle *AH_cfg;
/**
@@ -560,6 +565,18 @@ run (void *cls,
GNUNET_SCHEDULER_shutdown ();
return;
}
+ if (GNUNET_OK !=
+ TALER_config_get_amount (config,
+ "anastasis",
+ "INSURANCE",
+ &AH_insurance))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "anastasis",
+ "INSURANCE");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
if (GNUNET_OK !=
TALER_config_get_amount (config,
"anastasis",
diff --git a/src/backend/anastasis-httpd.h b/src/backend/anastasis-httpd.h
index b0b6fba..b475bf4 100644
--- a/src/backend/anastasis-httpd.h
+++ b/src/backend/anastasis-httpd.h
@@ -144,6 +144,11 @@ extern unsigned long long AH_upload_limit_mb;
*/
extern struct TALER_Amount AH_annual_fee;
+/**
+ * Amount of insurance.
+ */
+extern struct TALER_Amount AH_insurance;
+
/**
* Cost of authentication by question
*/
diff --git a/src/backend/anastasis-httpd_config.c
b/src/backend/anastasis-httpd_config.c
index 97b184c..70b1379 100644
--- a/src/backend/anastasis-httpd_config.c
+++ b/src/backend/anastasis-httpd_config.c
@@ -44,71 +44,60 @@ AH_handler_config (struct TMH_RequestHandler *rh,
if (strstr (AH_supported_methods, "question"))
{
- json_t *question = json_object ();
+ json_t *question = json_pack ("{s:s, s:o}",
+ "method",
+ "question",
+ "cost",
+ TALER_JSON_from_amount (&AH_question_cost));
- json_object_set_new (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 = json_pack ("{s:s, s:o}",
+ "method",
+ "sms",
+ "cost",
+ TALER_JSON_from_amount (&AH_sms_cost));
- json_object_set_new (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 = json_pack ("{s:s, s:o}",
+ "method",
+ "email",
+ "cost",
+ TALER_JSON_from_amount (&AH_email_cost));
- json_object_set_new (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 = json_pack ("{s:s, s:o}",
+ "method",
+ "video",
+ "cost",
+ TALER_JSON_from_amount (&AH_video_cost));
- json_object_set_new (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 = json_pack ("{s:s, s:o}",
+ "method",
+ "post",
+ "cost",
+ TALER_JSON_from_amount (&AH_post_cost));
-
- json_object_set_new (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));
@@ -116,8 +105,9 @@ AH_handler_config (struct TMH_RequestHandler *rh,
json_object_set_new (methods, "methods", method_arr);
return TALER_MHD_reply_json_pack (connection,
MHD_HTTP_OK,
- "{s:s, s:s, s:I, s:s, s:o, s:s}",
- "name", "anastasis",
+ "{s:s, s:s, s:I, s:s, s:o, s:o, s:s}",
+ "name",
+ "anastasis",
"methods",
json_dumps (methods, JSON_COMPACT),
"storage_limit_in_megabytes",
@@ -126,6 +116,8 @@ AH_handler_config (struct TMH_RequestHandler *rh,
(char *) AH_currency,
"annual_fee",
TALER_JSON_from_amount (&AH_annual_fee),
+ "insurance",
+ TALER_JSON_from_amount (&AH_insurance),
"version", "0:0:0");
}
diff --git a/src/backend/anastasis.conf b/src/backend/anastasis.conf
index eef9860..c76e94a 100644
--- a/src/backend/anastasis.conf
+++ b/src/backend/anastasis.conf
@@ -29,6 +29,9 @@ DB = postgres
# Annual fee for an account
ANNUAL_FEE = TESTKUDOS:0.1
+# Insurance
+INSURANCE = TESTKUDOS:1.0
+
# Upload limit per backup, in megabytes
UPLOAD_LIMIT_MB = 16
diff --git a/src/include/anastasis_service.h b/src/include/anastasis_service.h
index 2a3411c..2a13dd6 100644
--- a/src/include/anastasis_service.h
+++ b/src/include/anastasis_service.h
@@ -243,7 +243,8 @@ typedef void
unsigned int http_status,
const json_t *methods,
const char *conf_currency,
- const struct TALER_Amount *annual_fee);
+ const struct TALER_Amount *annual_fee,
+ const struct TALER_Amount *insurance);
/**
diff --git a/src/lib/anastasis_api_backup_redux.c
b/src/lib/anastasis_api_backup_redux.c
index a1b9af5..070f44e 100644
--- a/src/lib/anastasis_api_backup_redux.c
+++ b/src/lib/anastasis_api_backup_redux.c
@@ -461,40 +461,27 @@ del_authentication (json_t *state,
ANASTASIS_ActionCallback cb,
void *cb_cls)
{
- json_t *method;
- size_t arr_index;
GNUNET_assert (NULL != arguments);
- json_t *method_arr = json_deep_copy (json_object_get (state,
-
"authentication_methods"));
- GNUNET_assert (NULL != method_arr);
- json_t *del_method = json_object_get (arguments, "authentication_method");
- GNUNET_assert (NULL != del_method);
+ size_t index = (size_t) json_integer_value (
+ json_object_get (arguments,
+ "auth_method_index"));
+ json_t *auth_method_arr = json_object_get (state,
+ "authentication_methods");
- json_array_foreach (method_arr, arr_index, method)
+ GNUNET_assert (json_is_array (auth_method_arr));
+ if (0 != json_array_remove (auth_method_arr, index))
{
- json_t *method_type = json_object_get (method, "method");
- if (1 == json_equal (method_type, json_object_get (del_method, "method")))
- {
- const char *key;
- json_t *value;
- json_t *method_data = json_object_get (method, "data");
- GNUNET_assert (NULL != method_data);
- json_t *del_method_value = json_object_get (del_method, "value");
- GNUNET_assert (NULL != del_method_value);
-
- json_object_foreach (method_data, key, value)
- {
- if (1 == json_equal (del_method_value, value))
- {
- GNUNET_assert (0 == json_array_remove (method_arr, arr_index));
- break;
- }
- }
- }
+ json_t *error = json_pack ("{s:I, s:s}",
+ "code",
+ (json_int_t) ANASTASIS_EC_INVALID,
+ "hint",
+ "Operation failed");
+ cb (cb_cls,
+ ANASTASIS_EC_INVALID,
+ error);
+ return NULL;
}
- GNUNET_assert (0 == json_object_set_new (state,
- "authentication_methods",
- method_arr));
+
cb (cb_cls,
ANASTASIS_EC_NONE,
state);
@@ -609,7 +596,26 @@ del_policy (json_t *state,
ANASTASIS_ActionCallback cb,
void *cb_cls)
{
- // FIXME: implement
+ GNUNET_assert (NULL != arguments);
+ size_t index = (size_t) json_integer_value (
+ json_object_get (arguments,
+ "policy_index"));
+ json_t *policy_arr = json_object_get (state,
+ "policies");
+
+ GNUNET_assert (json_is_array (policy_arr));
+ if (0 != json_array_remove (policy_arr, index))
+ {
+ json_t *error = json_pack ("{s:I, s:s}",
+ "code",
+ (json_int_t) ANASTASIS_EC_INVALID,
+ "hint",
+ "Operation failed");
+ cb (cb_cls,
+ ANASTASIS_EC_INVALID,
+ error);
+ return NULL;
+ }
cb (cb_cls,
ANASTASIS_EC_NONE,
state);
@@ -639,7 +645,15 @@ enter_secret (json_t *state,
ANASTASIS_ActionCallback cb,
void *cb_cls)
{
- // FIXME: implement
+ GNUNET_assert (NULL != arguments);
+ GNUNET_assert (NULL != json_object_get (arguments,
+ "secret"));
+ GNUNET_assert (NULL != json_object_get (arguments,
+ "type"));
+ GNUNET_assert (0 ==
+ json_object_set_new (state,
+ "core_secret",
+ arguments));
cb (cb_cls,
ANASTASIS_EC_NONE,
state);
@@ -654,6 +668,7 @@ pay_policy (json_t *state,
ANASTASIS_ActionCallback cb,
void *cb_cls)
{
+ GNUNET_assert (NULL != arguments);
// FIXME: implement
cb (cb_cls,
ANASTASIS_EC_NONE,
diff --git a/src/lib/anastasis_api_config.c b/src/lib/anastasis_api_config.c
index a1b5e6a..aa46908 100644
--- a/src/lib/anastasis_api_config.c
+++ b/src/lib/anastasis_api_config.c
@@ -64,6 +64,11 @@ struct ANASTASIS_ConfigOperation
*/
struct TALER_Amount cost;
+ /**
+ * Insurance.
+ */
+ struct TALER_Amount insurance;
+
/**
* Supported methods.
*/
@@ -106,6 +111,7 @@ handle_config_finished (void *cls,
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_string ("currency", &co->currency),
TALER_JSON_spec_amount ("annual_fee", &co->cost),
+ TALER_JSON_spec_amount ("insurance", &co->insurance),
// FIXME add configs
GNUNET_JSON_spec_end ()
};
@@ -126,7 +132,8 @@ handle_config_finished (void *cls,
response_code,
co->methods,
co->currency,
- &co->cost
+ &co->cost,
+ &co->insurance
);
GNUNET_JSON_parse_free (spec);
ANASTASIS_config_cancel (co);
@@ -158,6 +165,7 @@ handle_config_finished (void *cls,
response_code,
NULL,
NULL,
+ NULL,
NULL);
co->cb = NULL;
}
diff --git a/src/lib/anastasis_api_redux.c b/src/lib/anastasis_api_redux.c
index 9a392d1..9029057 100644
--- a/src/lib/anastasis_api_redux.c
+++ b/src/lib/anastasis_api_redux.c
@@ -245,13 +245,14 @@ add_config_to_state (struct ConfigRequest *cr,
method_type,
ma_arr = json_array ()));
}
- prov = json_pack ("{s:o, s:o, s:s, s:s}",
- // FIXME: add insurance here...
+ prov = json_pack ("{s:o, s:o, s:o, s:s, s:s}",
"method_cost",
json_object_get (method,
"cost"),
"annual_cost",
TALER_JSON_from_amount (&cr->backend_cost),
+ "insurance",
+ TALER_JSON_from_amount (&cr->backend_insurance),
"provider_url",
cr->backend_url,
"provider_name",
@@ -317,13 +318,15 @@ config_request_timeout (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 insurance Amount of insurance of this service
*/
static void
config_cb (void *cls,
unsigned int http_status,
const json_t *methods,
const char *conf_currency,
- const struct TALER_Amount *annual_fee)
+ const struct TALER_Amount *annual_fee,
+ const struct TALER_Amount *insurance)
{
struct ConfigRequest *cr = cls;
struct SelectCountryHandle *sch = cr->sch;
@@ -340,7 +343,7 @@ config_cb (void *cls,
cr->backend_methods = json_incref ((json_t *) methods);
cr->backend_cost = *annual_fee;
cr->backend_currency = GNUNET_strdup (conf_currency);
- // FIXME: set cr->backend_insurance?
+ cr->backend_insurance = *insurance;
}
conclude_select_country (sch);
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-anastasis] branch master updated (f7e2529 -> eb4a3aa), gnunet, 2020/11/06
- [taler-anastasis] 02/08: description, gnunet, 2020/11/06
- [taler-anastasis] 04/08: reducer - worked on payment/upload, gnunet, 2020/11/06
- [taler-anastasis] 01/08: add insurance to config,
gnunet <=
- [taler-anastasis] 06/08: work on truth upload, gnunet, 2020/11/06
- [taler-anastasis] 05/08: initialize truths, gnunet, 2020/11/06
- [taler-anastasis] 07/08: Merge branch 'master' of ssh://git.taler.net/anastasis, gnunet, 2020/11/06
- [taler-anastasis] 08/08: fix db, fix reducer, gnunet, 2020/11/06
- [taler-anastasis] 03/08: reducer - better error handling, gnunet, 2020/11/06