[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 07/08: enumerate states
From: |
gnunet |
Subject: |
[taler-anastasis] 07/08: enumerate states |
Date: |
Fri, 09 Oct 2020 12:03:48 +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 5afb68f3d73b37cf2ed31c925e3d6e08192702d0
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Thu Oct 8 21:34:06 2020 +0200
enumerate states
---
src/include/anastasis_redux.h | 20 ++++++++++++
src/lib/anastasis_api_backup_redux.c | 19 +++++------
src/lib/anastasis_api_recovery_redux.c | 11 ++++---
src/lib/anastasis_api_redux.c | 59 ++++++++++++++++++++++------------
4 files changed, 74 insertions(+), 35 deletions(-)
diff --git a/src/include/anastasis_redux.h b/src/include/anastasis_redux.h
index 76c8f57..d87e7b6 100644
--- a/src/include/anastasis_redux.h
+++ b/src/include/anastasis_redux.h
@@ -27,6 +27,26 @@
#include <gnunet/gnunet_util_lib.h>
#include "anastasis_error_codes.h"
+#define FOREACH_STATE(REDUX_STATE) \
+ REDUX_STATE (NONE) \
+ REDUX_STATE (ContinentSelectionState) \
+ REDUX_STATE (CountrySelectionState) \
+ REDUX_STATE (UserAttributesCollectionState) \
+ REDUX_STATE (AuthenticationsEditingState) \
+ REDUX_STATE (PoliciesReviewingState) \
+ REDUX_STATE (BackupPayingState) \
+
+#define GENERATE_ENUM(ENUM) ENUM,
+#define GENERATE_STRING(STRING) #STRING,
+
+typedef enum
+{
+ FOREACH_STATE (GENERATE_ENUM)
+} REDUX_STATE;
+
+static const char *STATE_STRING[] = {
+ FOREACH_STATE (GENERATE_STRING)
+};
/**
* JSON containing country specific identity attributes to ask the user for.
diff --git a/src/lib/anastasis_api_backup_redux.c
b/src/lib/anastasis_api_backup_redux.c
index f2f18b8..3909357 100644
--- a/src/lib/anastasis_api_backup_redux.c
+++ b/src/lib/anastasis_api_backup_redux.c
@@ -94,7 +94,8 @@ ANASTASIS_backup_start (const struct
GNUNET_CONFIGURATION_Handle *cfg)
}
initial_state = json_pack ("{s:s, s:o}",
- "backup_state", "ContinentSelectionState",
+ "backup_state",
+ STATE_STRING[ContinentSelectionState],
"continents", continents);
GNUNET_assert (NULL != initial_state);
return initial_state;
@@ -377,7 +378,7 @@ done_authentication (json_t *state,
"policies",
pb.policies);
set_state (state,
- "ReviewPoliciesState");
+ STATE_STRING[PoliciesReviewingState]);
cb (cb_cls,
ANASTASIS_EC_NONE,
state);
@@ -426,29 +427,29 @@ ANASTASIS_backup_action (json_t *state,
{
struct Dispatcher
{
- const char *backup_state;
+ REDUX_STATE backup_state;
const char *backup_action;
DispatchHandler fun;
} dispatchers[] = {
{
- "AuthenticationsEditingState",
+ AuthenticationsEditingState,
"add_authentication",
&add_authentication
},
{
- "AuthenticationsEditingState",
+ AuthenticationsEditingState,
"delete_authentication",
&del_authentication
},
{
- "AuthenticationsEditingState",
+ AuthenticationsEditingState,
"next",
&done_authentication
},
- { NULL, NULL, NULL }
+ { NONE, NULL, NULL }
};
const char *s = json_string_value (json_object_get (state,
- "backup-state"));
+ "backup_state"));
if (NULL == s)
{
GNUNET_break (0);
@@ -458,7 +459,7 @@ ANASTASIS_backup_action (json_t *state,
}
for (unsigned int i = 0; NULL != dispatchers[i].fun; i++)
{
- if ( (0 == strcmp (s, dispatchers[i].backup_state)) &&
+ if ( (0 == strcmp (s, STATE_STRING[dispatchers[i].backup_state])) &&
(0 == strcmp (action, dispatchers[i].backup_action)) )
{
dispatchers[i].fun (state, arguments, cb, cb_cls);
diff --git a/src/lib/anastasis_api_recovery_redux.c
b/src/lib/anastasis_api_recovery_redux.c
index 50cfa28..205b800 100644
--- a/src/lib/anastasis_api_recovery_redux.c
+++ b/src/lib/anastasis_api_recovery_redux.c
@@ -92,7 +92,8 @@ ANASTASIS_recovery_start (const struct
GNUNET_CONFIGURATION_Handle *cfg)
}
initial_state = json_pack ("{s:s, s:o}",
- "recovery_state", "ContinentSelectionState",
+ "recovery_state",
+ STATE_STRING[ContinentSelectionState],
"continents", continents);
return initial_state;
}
@@ -120,14 +121,14 @@ ANASTASIS_recovery_action (json_t *state,
{
struct Dispatcher
{
- const char *recovery_state;
+ REDUX_STATE recovery_state;
const char *recovery_action;
DispatchHandler fun;
} dispatchers[] = {
- { NULL, NULL, NULL }
+ { NONE, NULL, NULL }
};
const char *s = json_string_value (json_object_get (state,
- "recovery-state"));
+ "recovery_state"));
if (NULL == s)
{
GNUNET_break (0);
@@ -137,7 +138,7 @@ ANASTASIS_recovery_action (json_t *state,
}
for (unsigned int i = 0; NULL != dispatchers[i].fun; i++)
{
- if ( (0 == strcmp (s, dispatchers[i].recovery_state)) &&
+ if ( (0 == strcmp (s, STATE_STRING[dispatchers[i].recovery_state])) &&
(0 == strcmp (action, dispatchers[i].recovery_action)) )
{
dispatchers[i].fun (state, arguments, cb, cb_cls);
diff --git a/src/lib/anastasis_api_redux.c b/src/lib/anastasis_api_redux.c
index 6ae7363..ed8bd6d 100644
--- a/src/lib/anastasis_api_redux.c
+++ b/src/lib/anastasis_api_redux.c
@@ -199,7 +199,7 @@ select_continent (json_t *state,
json_object_set_new (state,
s_mode,
- json_string ("CountrySelectionState"));
+ json_string (STATE_STRING[CountrySelectionState]));
json_object_set_new (state,
"selected_continent",
@@ -237,7 +237,8 @@ select_country (json_t *state,
GNUNET_assert (NULL != root);
json_object_set_new (state,
s_mode,
- json_string ("UserAttributesCollectionState"));
+ json_string (
+ STATE_STRING[UserAttributesCollectionState]));
json_object_set_new (state,
"selected_country",
@@ -269,7 +270,8 @@ unselect_country (json_t *state,
GNUNET_assert (0 ==
json_object_set_new (state,
s_mode,
- json_string ("CountrySelectionState")));
+ json_string (
+ STATE_STRING[CountrySelectionState])));
cb (cb_cls,
ANASTASIS_EC_NONE,
state);
@@ -288,7 +290,8 @@ unselect_continent (json_t *state,
GNUNET_assert (0 ==
json_object_set_new (state,
s_mode,
- json_string
("ContinentSelectionState")));
+ json_string (
+
STATE_STRING[ContinentSelectionState])));
cb (cb_cls,
ANASTASIS_EC_NONE,
state);
@@ -341,7 +344,7 @@ enter_user_attributes (json_t *state,
GNUNET_assert (NULL != root);
json_object_set_new (state,
s_mode,
- json_string ("AuthenticationsEditingState"));
+ json_string
(STATE_STRING[AuthenticationsEditingState]));
json_object_set_new (state,
"identity_attributes",
@@ -356,6 +359,19 @@ enter_user_attributes (json_t *state,
}
+static void
+state_back (json_t *state,
+ const json_t *arguments,
+ ANASTASIS_ActionCallback cb,
+ void *cb_cls)
+{
+ GNUNET_assert (NULL != state);
+ const char *s_mode = get_state_mode (state);
+
+ /** FIXME: state backwards logic */
+}
+
+
/**
* Operates on a state depending on given #ANASTASIS_BackupState
* or #ANASTASIS_RecoveryState and #ANASTASIS_BackupAction or
@@ -380,67 +396,68 @@ ANASTASIS_redux_action (const json_t *state,
{
struct Dispatcher
{
- const char *redux_state;
+ REDUX_STATE redux_state;
const char *redux_action;
DispatchHandler fun;
} dispatchers[] = {
{
- "ContinentSelectionState",
+ ContinentSelectionState,
"select_continent",
&select_continent
},
{
- "CountrySelectionState",
+ CountrySelectionState,
"unselect_continent",
&unselect_continent
},
{
- "CountrySelectionState",
+ CountrySelectionState,
"select_continent",
&select_continent
},
{
- "CountrySelectionState",
+ CountrySelectionState,
"select_country",
&select_country
},
{
- "UserAttributesCollectionState",
+ UserAttributesCollectionState,
"unselect_country",
&unselect_country
},
{
- "UserAttributesCollectionState",
+ UserAttributesCollectionState,
"select_country",
&select_country
},
{
- "UserAttributesCollectionState",
+ UserAttributesCollectionState,
"back",
&unselect_country
},
{
- "UserAttributesCollectionState",
+ UserAttributesCollectionState,
"select_continent",
&select_continent
},
{
- "UserAttributesCollectionState",
+ UserAttributesCollectionState,
"unselect_continent",
&unselect_continent
},
{
- "UserAttributesCollectionState",
+ UserAttributesCollectionState,
"enter_user_attributes",
&enter_user_attributes
},
{
- "AuthenticationsEditingState",
+ AuthenticationsEditingState,
"back",
&enter_user_attributes
},
- { NULL, NULL, NULL }
+ { NONE, NULL, NULL }
};
+ GNUNET_assert (NULL != state);
json_t *new_state;
const char *s_mode = "backup_state";
const char *s = json_string_value (json_object_get (state,
@@ -462,7 +479,7 @@ ANASTASIS_redux_action (const json_t *state,
GNUNET_assert (NULL != new_state);
for (unsigned int i = 0; NULL != dispatchers[i].fun; i++)
{
- if ( (0 == strcmp (s, dispatchers[i].redux_state)) &&
+ if ( (0 == strcmp (s, STATE_STRING[dispatchers[i].redux_state])) &&
(0 == strcmp (action, dispatchers[i].redux_action)) )
{
dispatchers[i].fun (new_state, arguments, cb, cb_cls);
@@ -470,13 +487,13 @@ ANASTASIS_redux_action (const json_t *state,
return;
}
}
- if (0 == strcmp (s_mode, "backup-state"))
+ if (0 == strcmp (s_mode, "backup_state"))
ANASTASIS_backup_action (new_state,
action,
arguments,
cb,
NULL);
- if (0 == strcmp (s_mode, "recovery-state"))
+ if (0 == strcmp (s_mode, "recovery_state"))
ANASTASIS_recovery_action (new_state,
action,
arguments,
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-anastasis] branch master updated (f4aa746 -> 1586ccd), gnunet, 2020/10/09
- [taler-anastasis] 04/08: fix, gnunet, 2020/10/09
- [taler-anastasis] 02/08: fixes, gnunet, 2020/10/09
- [taler-anastasis] 03/08: fix, gnunet, 2020/10/09
- [taler-anastasis] 06/08: fix, gnunet, 2020/10/09
- [taler-anastasis] 01/08: fixes, gnunet, 2020/10/09
- [taler-anastasis] 05/08: fix changing continent, gnunet, 2020/10/09
- [taler-anastasis] 07/08: enumerate states,
gnunet <=
- [taler-anastasis] 08/08: rework add_authentication, gnunet, 2020/10/09