config.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #pragma once
  2. #include <flipper_format/flipper_format.h>
  3. #include "../../types/plugin_state.h"
  4. #include "../../types/token_info.h"
  5. #include "constants.h"
  6. typedef uint8_t TokenLoadingResult;
  7. typedef uint8_t TotpConfigFileOpenResult;
  8. typedef uint8_t TotpConfigFileUpdateResult;
  9. /**
  10. * @brief Token loading results
  11. */
  12. enum TokenLoadingResults {
  13. /**
  14. * @brief All the tokens loaded successfully
  15. */
  16. TokenLoadingResultSuccess,
  17. /**
  18. * @brief All the tokens loaded, but there are some warnings
  19. */
  20. TokenLoadingResultWarning,
  21. /**
  22. * @brief Tokens not loaded because of error(s)
  23. */
  24. TokenLoadingResultError
  25. };
  26. /**
  27. * @brief Config file opening result
  28. */
  29. enum TotpConfigFileOpenResults {
  30. /**
  31. * @brief Config file opened successfully
  32. */
  33. TotpConfigFileOpenSuccess = 0,
  34. /**
  35. * @brief An error has occurred during opening config file
  36. */
  37. TotpConfigFileOpenError = 1
  38. };
  39. /**
  40. * @brief Config file updating result
  41. */
  42. enum TotpConfigFileUpdateResults {
  43. /**
  44. * @brief Config file updated successfully
  45. */
  46. TotpConfigFileUpdateSuccess,
  47. /**
  48. * @brief An error has occurred during updating config file
  49. */
  50. TotpConfigFileUpdateError
  51. };
  52. /**
  53. * @brief Tries to take a config file backup
  54. * @return backup path if backup successfully taken; \c NULL otherwise
  55. */
  56. char* totp_config_file_backup();
  57. /**
  58. * @brief Saves all the settings and tokens to an application config file
  59. * @param plugin_state application state
  60. * @return Config file update result
  61. */
  62. TotpConfigFileUpdateResult totp_full_save_config_file(const PluginState* const plugin_state);
  63. /**
  64. * @brief Loads basic information from an application config file into application state without loading all the tokens
  65. * @param plugin_state application state
  66. * @return Config file open result
  67. */
  68. TotpConfigFileOpenResult totp_config_file_load_base(PluginState* const plugin_state);
  69. /**
  70. * @brief Loads tokens from an application config file into application state
  71. * @param plugin_state application state
  72. * @return Results of the loading
  73. */
  74. TokenLoadingResult totp_config_file_load_tokens(PluginState* const plugin_state);
  75. /**
  76. * @brief Add new token to the end of the application config file
  77. * @param token_info token information to be saved
  78. * @return Config file update result
  79. */
  80. TotpConfigFileUpdateResult totp_config_file_save_new_token(const TokenInfo* token_info);
  81. /**
  82. * @brief Updates timezone offset in an application config file
  83. * @param new_timezone_offset new timezone offset to be set
  84. * @return Config file update result
  85. */
  86. TotpConfigFileUpdateResult totp_config_file_update_timezone_offset(float new_timezone_offset);
  87. /**
  88. * @brief Updates notification method in an application config file
  89. * @param new_notification_method new notification method to be set
  90. * @return Config file update result
  91. */
  92. TotpConfigFileUpdateResult
  93. totp_config_file_update_notification_method(NotificationMethod new_notification_method);
  94. /**
  95. * @brief Updates automation method in an application config file
  96. * @param new_automation_method new automation method to be set
  97. * @return Config file update result
  98. */
  99. TotpConfigFileUpdateResult
  100. totp_config_file_update_automation_method(AutomationMethod new_automation_method);
  101. /**
  102. * @brief Updates application user settings
  103. * @param plugin_state application state
  104. * @return Config file update result
  105. */
  106. TotpConfigFileUpdateResult totp_config_file_update_user_settings(const PluginState* plugin_state);
  107. /**
  108. * @brief Updates crypto signatures information
  109. * @param plugin_state application state
  110. * @return Config file update result
  111. */
  112. TotpConfigFileUpdateResult
  113. totp_config_file_update_crypto_signatures(const PluginState* plugin_state);
  114. /**
  115. * @brief Reset all the settings to default
  116. */
  117. void totp_config_file_reset();