diff options
Diffstat (limited to 'src/reducer/anastasis_api_redux.h')
-rw-r--r-- | src/reducer/anastasis_api_redux.h | 347 |
1 files changed, 347 insertions, 0 deletions
diff --git a/src/reducer/anastasis_api_redux.h b/src/reducer/anastasis_api_redux.h new file mode 100644 index 0000000..19d9466 --- /dev/null +++ b/src/reducer/anastasis_api_redux.h @@ -0,0 +1,347 @@ +/* + This file is part of Anastasis + Copyright (C) 2020, 2021 Taler Systems SA + + Anastasis is free software; you can redistribute it and/or modify it under the + terms of the GNU Lesser General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + Anastasis; see the file COPYING.GPL. If not, see <http://www.gnu.org/licenses/> +*/ +/** + * @file redux/anastasis_api_redux.h + * @brief anastasis reducer api, internal data structures + * @author Christian Grothoff + * @author Dominik Meister + * @author Dennis Neufeld + */ +#ifndef ANASTASIS_API_REDUX_H +#define ANASTASIS_API_REDUX_H + + +#define ANASTASIS_GENERIC_STATES(REDUX_STATE) \ + REDUX_STATE (ERROR) \ + REDUX_STATE (CONTINENT_SELECTING) \ + REDUX_STATE (COUNTRY_SELECTING) \ + REDUX_STATE (USER_ATTRIBUTES_COLLECTING) + +#define GENERATE_GENERIC_ENUM(ENUM) ANASTASIS_GENERIC_STATE_ ## ENUM, + +enum ANASTASIS_GenericState +{ + ANASTASIS_GENERIC_STATES (GENERATE_GENERIC_ENUM) +}; + +#undef GENERATE_GENERIC_ENUM + +#define ANASTASIS_BACKUP_STATES(REDUX_STATE) \ + ANASTASIS_GENERIC_STATES (REDUX_STATE) \ + REDUX_STATE (AUTHENTICATIONS_EDITING) \ + REDUX_STATE (POLICIES_REVIEWING) \ + REDUX_STATE (SECRET_EDITING) \ + REDUX_STATE (TRUTHS_PAYING) \ + REDUX_STATE (POLICIES_PAYING) \ + REDUX_STATE (BACKUP_FINISHED) + +#define GENERATE_BACKUP_ENUM(ENUM) ANASTASIS_BACKUP_STATE_ ## ENUM, + +enum ANASTASIS_BackupState +{ + ANASTASIS_BACKUP_STATES (GENERATE_BACKUP_ENUM) +}; + +#undef GENERATE_BACKUP_ENUM + +#define ANASTASIS_RECOVERY_STATES(REDUX_STATE) \ + ANASTASIS_GENERIC_STATES (REDUX_STATE) \ + REDUX_STATE (SECRET_SELECTING) \ + REDUX_STATE (CHALLENGE_SELECTING) \ + REDUX_STATE (CHALLENGE_PAYING) \ + REDUX_STATE (CHALLENGE_SOLVING) \ + REDUX_STATE (RECOVERY_FINISHED) + +#define GENERATE_RECOVERY_ENUM(ENUM) ANASTASIS_RECOVERY_STATE_ ## ENUM, + +enum ANASTASIS_RecoveryState +{ + ANASTASIS_RECOVERY_STATES (GENERATE_RECOVERY_ENUM) +}; + +#undef GENERATE_RECOVERY_ENUM + + +/** + * CURL context to be used by all operations. + */ +extern struct GNUNET_CURL_Context *ANASTASIS_REDUX_ctx_; + + +/** + * Initialize reducer subsystem. + * + * @param ctx context to use for CURL requests. + */ +void +ANASTASIS_redux_init (struct GNUNET_CURL_Context *ctx); + + +/** + * Terminate reducer subsystem. + */ +void +ANASTASIS_redux_done (void); + + +/** + * Produce an initial state with an initialized list of + * continents. + */ +json_t * +ANASTASIS_REDUX_load_continents_ (void); + + +/** + * Returns the enum value to a string value of a state. + * + * @param state_string + * @return #ANASTASIS_GENERIC_STATE_ERROR on error + */ +enum ANASTASIS_GenericState +ANASTASIS_generic_state_from_string_ (const char *state_string); + + +/** + * Returns the string value of a state. + * + * @param state_string + * @return NULL on error + */ +const char * +ANASTASIS_generic_state_to_string_ (enum ANASTASIS_GenericState gs); + + +/** + * Returns the enum value to a string value of a state. + * + * @param state_string + * @return #ANASTASIS_BACKUP_STATE_ERROR on error + */ +enum ANASTASIS_BackupState +ANASTASIS_backup_state_from_string_ (const char *state_string); + + +/** + * Returns the string value of a state. + * + * @param state_string + * @return NULL on error + */ +const char * +ANASTASIS_backup_state_to_string_ (enum ANASTASIS_BackupState bs); + + +/** + * Returns the enum value to a string value of a state. + * + * @param state_string + * @return XXX on error + */ +enum ANASTASIS_RecoveryState +ANASTASIS_recovery_state_from_string_ (const char *state_string); + + +/** + * Returns the string value of a state. + * + * @param state_string + * @return NULL on error + */ +const char * +ANASTASIS_recovery_state_to_string_ (enum ANASTASIS_RecoveryState rs); + + +/** + * Function to return a json error response. + * + * @param cb callback to give error to + * @param cb_cls callback closure + * @param ec error code + * @param detail error detail + */ +void +ANASTASIS_redux_fail_ (ANASTASIS_ActionCallback cb, + void *cb_cls, + enum TALER_ErrorCode ec, + const char *detail); + + +/** + * DispatchHandler/Callback function which is called for a + * "add_provider" action. Adds another Anastasis provider + * to the list of available providers for storing information. + * + * @param state state to operate on + * @param arguments arguments with a provider URL to add + * @param cb callback to call during/after operation + * @param cb_cls callback closure + * @return true if @a cb was invoked + */ +bool +ANASTASIS_add_provider_ (json_t *state, + const json_t *arguments, + ANASTASIS_ActionCallback cb, + void *cb_cls); + + +/** + * Adds the server configuration of the Anastasis provider + * at @a url to the json @a state. Checks if we have + * the provider information already available. If so, + * imports it into @a state. If not, queries the provider, + * generating a success or failure outcome asynchronously. + * + * @param cr the config request + * @param[in,out] state the json state to operate on + * @param cb callback to call during/after operation + * @param cb_cls callback closure + * @return handle to cancel asynchronous operation, NULL if + * we completed synchronously + */ +struct ANASTASIS_ReduxAction * +ANASTASIS_REDUX_add_provider_to_state_ (const char *url, + json_t *state, + ANASTASIS_ActionCallback cb, + void *cb_cls); + + +/** + * A generic DispatchHandler/Callback function which is called for a + * "back" action. + * + * @param state state to operate on + * @param arguments arguments to use for operation on state + * @param cb callback to call during/after operation + * @param cb_cls callback closure + * @return NULL (no asynchronous action) + */ +struct ANASTASIS_ReduxAction * +ANASTASIS_back_generic_decrement_ (json_t *state, + const json_t *arguments, + ANASTASIS_ActionCallback cb, + void *cb_cls); + + +/** + * Function to load json containing all countries. + * Returns the countries. + * + * @return json_t * + */ +const json_t * +ANASTASIS_redux_countries_init_ (void); + + +/** + * Operates on a recovery state depending on given #ANASTASIS_RecoveryState + * and #ANASTASIS_RecoveryAction. The new #ANASTASIS_RecoveryState is returned + * by a callback function. + * This function can do network access to talk to anastasis service providers. + * + * @param ctx the CURL context used to connect to the backend + * @param[in,out] state input/output state (to be modified) + * @param action what action to perform + * @param arguments data for the @a action + * @param cb function to call with the result + * @param cb_cls closure for @a cb + */ +struct ANASTASIS_ReduxAction * +ANASTASIS_recovery_action_ (json_t *state, + const char *action, + const json_t *arguments, + ANASTASIS_ActionCallback cb, + void *cb_cls); + + +/** + * DispatchHandler/Callback function which is called for a + * "enter_user_attributes" action after verifying that the + * arguments provided were OK and the state transition was + * initiated. Begins the actual recovery logic. + * + * Returns an #ANASTASIS_ReduxAction. + * + * @param state state to operate on + * @param cb callback to call during/after operation + * @param cb_cls callback closure + * @return NULL + */ +struct ANASTASIS_ReduxAction * +ANASTASIS_REDUX_recovery_challenge_begin_ (json_t *state, + const json_t *arguments, + ANASTASIS_ActionCallback cb, + void *cb_cls); + + +/** + * DispatchHandler/Callback function which is called for a + * "enter_user_attributes" action after verifying that the + * arguments provided were OK and the state transition was + * initiated. Begins the actual backup logic. + * + * Returns an #ANASTASIS_ReduxAction. + * + * @param state state to operate on + * @param cb callback to call during/after operation + * @param cb_cls callback closure + */ +struct ANASTASIS_ReduxAction * +ANASTASIS_REDUX_backup_begin_ (json_t *state, + const json_t *arguments, + ANASTASIS_ActionCallback cb, + void *cb_cls); + + +/** + * Operates on a backup state depending on given #ANASTASIS_BackupState + * and #ANASTASIS_BackupAction. The new #ANASTASIS_BackupState is returned + * by a callback function. + * This function can do network access to talk to anastasis service providers. + * + * @param ctx the CURL context used to connect to the backend + * @param[in,out] state input/output state (to be modified) + * @param action what action to perform + * @param arguments data for the @a action + * @param cb function to call with the result + * @param cb_cls closure for @a cb + */ +struct ANASTASIS_ReduxAction * +ANASTASIS_backup_action_ (json_t *state, + const char *action, + const json_t *arguments, + ANASTASIS_ActionCallback cb, + void *cb_cls); + + +/** + * Generic container for an action with asynchronous activities. + */ +struct ANASTASIS_ReduxAction +{ + /** + * Function to call to clean up. + */ + void (*cleanup)(void *cls); + + /** + * Action-specific state, closure for @e cleanup. + */ + void *cleanup_cls; +}; + + +#endif |