From afe7e561fd7d031bfc04c1097b6b0adad6478ece Mon Sep 17 00:00:00 2001 From: Alexander Kopachov Date: Fri, 4 Aug 2023 13:04:26 +0200 Subject: [PATCH] Refactoring (#184) --- cli/cli.c | 4 +++ cli/cli.h | 14 +++++++-- cli/cli_helpers.h | 2 +- cli/commands/add/add.c | 2 +- cli/commands/update/update.c | 2 +- cli/common_command_arguments.h | 55 ++++++++++++++++++++++++++++++++++ ui/canvas_extensions.h | 9 ++++++ ui/common_dialogs.h | 11 +++++++ 8 files changed, 93 insertions(+), 6 deletions(-) diff --git a/cli/cli.c b/cli/cli.c index 52d2202d6ff..4cb68ce8320 100644 --- a/cli/cli.c +++ b/cli/cli.c @@ -16,6 +16,10 @@ #include "commands/automation/automation.h" #include "commands/details/details.h" +struct TotpCliContext { + PluginState* plugin_state; +}; + static void totp_cli_print_unknown_command(const FuriString* unknown_command) { TOTP_CLI_PRINTF_ERROR( "Command \"%s\" is unknown. Use \"" TOTP_CLI_COMMAND_HELP diff --git a/cli/cli.h b/cli/cli.h index deee81b847d..13afef78ffb 100644 --- a/cli/cli.h +++ b/cli/cli.h @@ -3,9 +3,17 @@ #include #include "../types/plugin_state.h" -typedef struct { - PluginState* plugin_state; -} TotpCliContext; +typedef struct TotpCliContext TotpCliContext; +/** + * @brief Registers TOTP CLI handler + * @param plugin_state application state + * @return TOTP CLI context + */ TotpCliContext* totp_cli_register_command_handler(PluginState* plugin_state); + +/** + * @brief Unregisters TOTP CLI handler + * @param context application state + */ void totp_cli_unregister_command_handler(TotpCliContext* context); \ No newline at end of file diff --git a/cli/cli_helpers.h b/cli/cli_helpers.h index 991dd2e4848..9c40bff13ff 100644 --- a/cli/cli_helpers.h +++ b/cli/cli_helpers.h @@ -111,6 +111,6 @@ void totp_cli_print_error_updating_config_file(); void totp_cli_print_error_loading_token_info(); /** - * @brief Prints message to let user knwo that command is processing now + * @brief Prints message to let user know that command is processing now */ void totp_cli_print_processing(); \ No newline at end of file diff --git a/cli/commands/add/add.c b/cli/commands/add/add.c index 074458f1120..d2bf8b90718 100644 --- a/cli/commands/add/add.c +++ b/cli/commands/add/add.c @@ -54,7 +54,7 @@ static TotpIteratorUpdateTokenResult // Reading token secret furi_string_reset(temp_str); - TOTP_CLI_PRINTF("Enter token secret and confirm with [ENTER]\r\n"); + TOTP_CLI_PRINTF("Enter token secret and confirm with [ENTER]:\r\n"); if(!totp_cli_read_line(context_t->cli, temp_str, mask_user_input)) { totp_cli_delete_last_line(); furi_string_secure_free(temp_str); diff --git a/cli/commands/update/update.c b/cli/commands/update/update.c index 0435eff4876..79ed7567084 100644 --- a/cli/commands/update/update.c +++ b/cli/commands/update/update.c @@ -83,7 +83,7 @@ static TotpIteratorUpdateTokenResult if(update_token_secret) { // Reading token secret furi_string_reset(temp_str); - TOTP_CLI_PRINTF("Enter token secret and confirm with [ENTER]\r\n"); + TOTP_CLI_PRINTF("Enter token secret and confirm with [ENTER]:\r\n"); bool token_secret_read = totp_cli_read_line(context_t->cli, temp_str, mask_user_input); totp_cli_delete_last_line(); if(!token_secret_read) { diff --git a/cli/common_command_arguments.h b/cli/common_command_arguments.h index be1c0bdfe6f..0bf83422595 100644 --- a/cli/common_command_arguments.h +++ b/cli/common_command_arguments.h @@ -18,32 +18,87 @@ #define TOTP_CLI_COMMAND_ARG_SECRET_ENCODING_PREFIX "-e" #define TOTP_CLI_COMMAND_ARG_SECRET_ENCODING "encoding" +/** + * @brief Prints information about unknown argument + * @param arg + */ void totp_cli_printf_unknown_argument(const FuriString* arg); +/** + * @brief Prints information about missed required argument + * @param arg + */ void totp_cli_printf_missed_argument_value(char* arg); +/** + * @brief Tries to read token hashing algo + * @param token_info token info to set parsed algo to if successfully read and parsed + * @param arg argument to parse + * @param args rest of arguments + * @param[out] parsed will be set to \c true if token hashing algo sucecssfully read and parsed; \c false otherwise + * @return \c true if \c arg represents token hashing algo argument; \c false otherwise + */ bool totp_cli_try_read_algo(TokenInfo* token_info, FuriString* arg, FuriString* args, bool* parsed); +/** + * @brief Tries to read token digits count + * @param token_info token info to set parsed digits count to if successfully read and parsed + * @param arg argument to parse + * @param args rest of arguments + * @param[out] parsed will be set to \c true if token digits count sucecssfully read and parsed; \c false otherwise + * @return \c true if \c arg represents token digits count argument; \c false otherwise + */ bool totp_cli_try_read_digits( TokenInfo* token_info, const FuriString* arg, FuriString* args, bool* parsed); +/** + * @brief Tries to read token duration + * @param token_info token info to set parsed duration to if successfully read and parsed + * @param arg argument to parse + * @param args rest of arguments + * @param[out] parsed will be set to \c true if token duration sucecssfully read and parsed; \c false otherwise + * @return \c true if \c arg represents token duration argument; \c false otherwise + */ bool totp_cli_try_read_duration( TokenInfo* token_info, const FuriString* arg, FuriString* args, bool* parsed); +/** + * @brief Tries to read token automation features + * @param token_info token info to set parsed automation features to if successfully read and parsed + * @param arg argument to parse + * @param args rest of arguments + * @param[out] parsed will be set to \c true if token automation features sucecssfully read and parsed; \c false otherwise + * @return \c true if \c arg represents token automation features argument; \c false otherwise + */ bool totp_cli_try_read_automation_features( TokenInfo* token_info, FuriString* arg, FuriString* args, bool* parsed); +/** + * @brief Tries to read unsecure flag + * @param arg argument to parse + * @param[out] parsed will be set to \c true if unsecure flag sucecssfully read and parsed; \c false otherwise + * @param[out] unsecure_flag will be set to parsed unsecure flag state if read and parsed successfully + * @return \c true if \c arg represents unsecure flag argument; \c false otherwise + */ bool totp_cli_try_read_unsecure_flag(const FuriString* arg, bool* parsed, bool* unsecure_flag); +/** + * @brief Tries to read plain token secret encoding + * @param arg argument to parse + * @param args rest of arguments + * @param[out] parsed will be set to \c true if plain token secret encoding sucecssfully read and parsed; \c false otherwise + * @param[out] secret_encoding will be set to parsed plain token secret encoding if read and parsed successfully + * @return \c true if \c arg represents plain token secret encoding argument; \c false otherwise + */ bool totp_cli_try_read_plain_token_secret_encoding( FuriString* arg, FuriString* args, diff --git a/ui/canvas_extensions.h b/ui/canvas_extensions.h index ab55191400c..2e053b488d1 100644 --- a/ui/canvas_extensions.h +++ b/ui/canvas_extensions.h @@ -4,6 +4,15 @@ #include #include +/** + * @brief Draw string using given font + * @param canvas canvas to draw string at + * @param x horizontal position + * @param y vertical position + * @param text string to draw + * @param text_length string length + * @param font font to be used to draw string + */ void canvas_draw_str_ex( Canvas* canvas, uint8_t x, diff --git a/ui/common_dialogs.h b/ui/common_dialogs.h index 187d0e95c96..1ddd80a7588 100644 --- a/ui/common_dialogs.h +++ b/ui/common_dialogs.h @@ -3,5 +3,16 @@ #include #include "../types/plugin_state.h" +/** + * @brief Shows standard dialog about the fact that error occurred when loading config file + * @param plugin_state application state + * @return dialog button which user pressed to close the dialog + */ DialogMessageButton totp_dialogs_config_loading_error(PluginState* plugin_state); + +/** + * @brief Shows standard dialog about the fact that error occurred when updating config file + * @param plugin_state application state + * @return dialog button which user pressed to close the dialog + */ DialogMessageButton totp_dialogs_config_updating_error(PluginState* plugin_state); \ No newline at end of file