/* This file is part of Anastasis Copyright (C) 2020 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 */ /** * @file include/anastasis_json.h * @brief anastasis de-/serialization api * @author Christian Grothoff * @author Dominik Meister * @author Dennis Neufeld */ #ifndef ANASTASIS_JSON_H #define ANASTASIS_JSON_H #include #include #include "anastasis_error_codes.h" /** * Enumeration of possible backup process status. */ enum ANASTASIS_BackupStatus { ANASTASIS_BS_INITIAL, ANASTASIS_BS_SELECT_CONTINENT, ANASTASIS_BS_SELECT_COUNTRY, ANASTASIS_BS_ENTER_USER_ATTRIBUTES, ANASTASIS_BS_ADD_AUTHENTICATION_METHOD, ANASTASIS_BS_ADD_POLICY, ANASTASIS_BS_PAY }; /** * Enumeration of possible recovery process status. */ enum ANASTASIS_RecoveryStatus { ANASTASIS_RS_INITIAL, ANASTASIS_RS_SELECT_CONTINENT, ANASTASIS_RS_SELECT_COUNTRY, ANASTASIS_RS_ENTER_USER_ATTRIBUTES, ANASTASIS_RS_SOLVE_CHALLENGE }; // A state for the backup process. struct ANASTASIS_BackupState { enum ANASTASIS_BackupStatus status; union { struct { // empty! } select_continent; struct { const char *continent; } select_country; struct { const char *continent; const char *country; const char *currency; // derived or per manual override! json_t *user_attributes; } enter_attributes; struct { const char *continent; const char *country; const char *currency; json_t *user_attributes; struct AuthenticationDetails { enum AuthenticationMethod { SMS, VIDEO, SECQUEST, EMAIL, SNAILMAIL }; char *provider_url; union Truth { struct { char *phone_number; } sms; struct { char *question; char *answer; // FIXME: Reasonable to store answer in clear text here? } secquest; struct { char *mailaddress; } email; struct { char *full_name; char *street; // street name + number char *postal_code; char *city; char *country; } snailmail; struct { char *path_to_picture; } video; } truth; }*ad; // array size_t ad_length; } add_authentication; struct { const char *continent; const char *country; const char *currency; json_t *user_attributes; struct AuthenticationDetails { enum AuthenticationMethod { SMS, VIDEO, SECQUEST, EMAIL, SNAILMAIL }; char *provider_url; union Truth { struct { char *phone_number; } sms; struct { char *question; char *answer; // FIXME: Reasonable to store answer in clear text here? } secquest; struct { char *mailaddress; } email; struct { char *full_name; char *street; // street name + number char *postal_code; char *city; char *country; } snailmail; struct { char *path_to_picture; } video; } truth; }*ad; // array size_t ad_length; struct PolicyDetails { struct AuthenticationDetails *ad; // array }*pd; // array size_t pd_length; } add_policy; // FIXME: add_payment } details; }; // A state for the recovery process. struct ANASTASIS_RecoveryState { enum ANASTASIS_RecoveryStatus status; struct { // empty! } select_continent; struct { const char *continent; } select_country; struct { const char *continent; const char *country; const char *currency; // derived or per manual override! json_t *user_attributes; } enter_attributes; struct { const char *continent; const char *country; const char *currency; json_t *user_attributes; struct ChallengeDetails { enum AuthenticationMethod { SMS, VIDEO, SECQUEST, EMAIL, SNAILMAIL }; char *provider_url; union Challenge { struct { char *phone_number; char *code; } sms; struct { char *question; char *answer; // FIXME: Reasonable to store answer in clear text here? } secquest; struct { char *mailaddress; char *code; } email; struct { char *full_name; char *street; // street name + number char *postal_code; char *city; char *country; char *code; } snailmail; struct { char *path_to_picture; char *code; } video; } truth; }*cd; // array size_t cd_length; } solve_challenge; }; /** * Definition of actions on ANASTASIS_BackupState. */ struct ANASTASIS_BackupAction { enum action { ANASTASIS_BA_GET_SELECT_CONTINENT, ANASTASIS_BA_GET_SELECT_COUNTRY, ANASTASIS_BA_GET_ENTER_USER_ATTRIBUTES, ANASTASIS_BA_GET_ADD_AUTHENTICATION_METHOD, ANASTASIS_BA_GET_ADD_POLICY, ANASTASIS_BA_GET_PAY, ANASTASIS_BA_SET_SELECT_CONTINENT, ANASTASIS_BA_SET_SELECT_COUNTRY, ANASTASIS_BA_SET_ENTER_USER_ATTRIBUTES, ANASTASIS_BA_SET_ADD_AUTHENTICATION_METHOD, ANASTASIS_BA_SET_ADD_POLICY, ANASTASIS_BA_SET_PAY }; }; /** * Definition of actions on ANASTASIS_RecoveryState. */ struct ANASTASIS_RecoveryAction { enum action { ANASTASIS_RS_GET_SELECT_CONTINENT, ANASTASIS_RS_GET_SELECT_COUNTRY, ANASTASIS_RS_GET_ENTER_USER_ATTRIBUTES, ANASTASIS_RS_GET_SOLVE_CHALLENGE, ANASTASIS_RS_SET_SELECT_CONTINENT, ANASTASIS_RS_SET_SELECT_COUNTRY, ANASTASIS_RS_SET_ENTER_USER_ATTRIBUTES, ANASTASIS_RS_SET_SOLVE_CHALLENGE }; }; /** * Signature of the callback bassed to #ANASTASIS_apply_anastasis_backup_action * for asynchronous actions on a #ANASTASIS_BackupState. * * @param cls closure * @param new_bs the new #ANASTASIS_BackupState * @param error error code */ typedef void (*ANASTASIS_BackupApplyActionCallback)( void *cls, const struct ANASTASIS_BackupState *new_bs, enum TALER_ErrorCode error); /** * Signature of the callback bassed to #ANASTASIS_apply_anastasis_recovery_action * for asynchronous actions on a #ANASTASIS_RecoveryState. * * @param cls closure * @param new_bs the new #ANASTASIS_RecoveryState * @param error error code */ typedef void (*ANASTASIS_RecoveryApplyActionCallback)( void *cls, const struct ANASTASIS_RecoveryState *new_rs, enum TALER_ErrorCode error); /** * Returns an initial ANASTASIS_BackupState. * * @return initial ANASTASIS_BackupState */ struct ANASTASIS_BackupState * ANASTASIS_get_initial_backup_state (); /** * Returns an initial ANASTASIS_RecoveryState. * * @return initial ANASTASIS_RecoveryState */ struct ANASTASIS_RecoveryState * ANASTASIS_get_initial_recovery_state (); /** * 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 url context for the event loop * @param bs the previous *ANASTASIS_BackupState * @param ba the action to do on #ANASTASIS_BackupState * @param cb callback function to call with the action */ void ANASTASIS_apply_anastasis_backup_action ( struct GNUNET_CURL_Context *ctx, struct ANASTASIS_BackupState *bs, struct ANASTASIS_BackupAction *ba, ANASTASIS_BackupApplyActionCallback cb); /** * 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 url context for the event loop * @param bs the previous *ANASTASIS_RecoveryState * @param ba the action to do on #ANASTASIS_RecoveryState * @param cb callback function to call with the action */ void ANASTASIS_apply_anastasis_recovery_action ( struct GNUNET_CURL_Context *ctx, struct ANASTASIS_RecoveryState *rs, struct ANASTASIS_RecoveryAction *ra, ANASTASIS_RecoveryApplyActionCallback cb); #endif /* _ANASTASIS_JSON_H */