[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 03/04: work on initial policy
From: |
gnunet |
Subject: |
[taler-anastasis] 03/04: work on initial policy |
Date: |
Mon, 28 Sep 2020 15:21:26 +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 1c29911aafac52fec2a019a579ab1f6351901e8d
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Mon Sep 28 15:19:28 2020 +0200
work on initial policy
---
src/include/anastasis_redux.h | 1 +
src/lib/anastasis_api_backup_redux.c | 62 ++++++++++++++++++++++++++++++++++--
2 files changed, 60 insertions(+), 3 deletions(-)
diff --git a/src/include/anastasis_redux.h b/src/include/anastasis_redux.h
index 8d2cfe9..4adc474 100644
--- a/src/include/anastasis_redux.h
+++ b/src/include/anastasis_redux.h
@@ -27,6 +27,7 @@
#include <gnunet/gnunet_util_lib.h>
#include "anastasis_error_codes.h"
+
/**
* JSON containing all supported countries and additional data.
*/
diff --git a/src/lib/anastasis_api_backup_redux.c
b/src/lib/anastasis_api_backup_redux.c
index 1a32f70..e4a8b0f 100644
--- a/src/lib/anastasis_api_backup_redux.c
+++ b/src/lib/anastasis_api_backup_redux.c
@@ -162,13 +162,69 @@ add_authentication (const json_t *state,
"backup-state",
json_string ("ReduxAuthenticationAddedState"));
- json_object_set_new (new_state,
- "authentication_methods",
- methods);
+ json_object_set (new_state,
+ "authentication_methods",
+ methods);
+
+ {
+ // initialize policy
+ size_t index_m; // index methods array
+ size_t index_up; // index used_providers array
+ json_t *method;
+ json_t *used_providers = json_array ();
+ json_t *policy = json_array ();
+
+ // simply distribute the methods
+ json_array_foreach (methods, index_m, method)
+ {
+ size_t index_p; // index providers array
+ json_t *provider;
+ json_t *used_provider;
+ json_t *policy_element = json_object ();
+ json_t *provider_arr = json_object_get (method, "providers");
+ json_array_foreach (provider_arr, index_p, provider)
+ {
+ json_t *method_cpy = json_deep_copy (method);
+ json_object_del (method_cpy, "providers");
+ json_object_set_new (policy_element, "method", method_cpy);
+
+ bool used = false;
+ json_array_foreach (used_providers, index_up, used_provider)
+ {
+ // first, check if provider already is used for a method
+ if (json_equal (provider, used_provider))
+ {
+ used = true;
+ break;
+ }
+ }
+ if (! used)
+ {
+ // if provider is not used for a method, choose it
+ json_array_append (used_providers, provider);
+ json_object_set_new (policy_element, "provider", provider);
+ break;
+ }
+ // if all providers are used once, begin with the first again
+ if (json_array_size (provider_arr) == index_p - 1)
+ {
+ json_array_clear (used_providers);
+ provider = json_array_get (provider_arr, 0);
+ json_array_append (used_providers, provider);
+ json_object_set_new (policy_element, "provider", provider);
+ }
+ }
+ json_array_append_new (policy, policy_element);
+ }
+ json_object_set_new (new_state,
+ "initial_policy",
+ policy);
+ }
cb (cb_cls,
ANASTASIS_EC_NONE,
new_state);
+ json_decref (methods);
json_decref (new_state);
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.