Skip to content

Commit

Permalink
Refactoring (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
akopachov committed Aug 4, 2023
1 parent a8d5f8b commit 025653a
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 6 deletions.
4 changes: 4 additions & 0 deletions totp/cli/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions totp/cli/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
#include <cli/cli.h>
#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);
2 changes: 1 addition & 1 deletion totp/cli/cli_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
2 changes: 1 addition & 1 deletion totp/cli/commands/add/add.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion totp/cli/commands/update/update.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
55 changes: 55 additions & 0 deletions totp/cli/common_command_arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions totp/ui/canvas_extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
#include <gui/gui.h>
#include <font_info.h>

/**
* @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,
Expand Down
11 changes: 11 additions & 0 deletions totp/ui/common_dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,16 @@
#include <dialogs/dialogs.h>
#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);

0 comments on commit 025653a

Please sign in to comment.