diff --git a/examples/cli.c b/examples/cli.c index 2733209..4e9a6c0 100644 --- a/examples/cli.c +++ b/examples/cli.c @@ -117,37 +117,27 @@ el_status_t do_suspend(void) return CSstay; } -static int my_rl_check_secret(const char* source) +static int my_rl_check_secret(const char *line) { - const char* pattern = (char *)"^unlock\\s"; + const char *pattern = (char *)"^unlock\\s"; regex_t regex; + int rc = 0; - int reti; - int rez = 0; + if (!line || regcomp(®ex, pattern, 0)) + return 0; - if (!pattern || !source) - return rez; + if (!regexec(®ex, line, 0, NULL, 0)) + rc = 1; - /* Compile regular expression */ - reti = regcomp(®ex, pattern, 0); - if (reti) // If couldn't compile regex - return rez; - - /* Execute regular expression */ - reti = regexec(®ex, source, 0, NULL, 0); - if (!reti) // If regex match - rez = 1; - - /* Free memory allocated to the pattern buffer by regcomp() */ regfree(®ex); - return rez; + return rc; } int main(void) { char *line; - char *prompt = "cli> "; + char *prompt = "cli> "; /* Setup callbacks */ rl_set_complete_func(&my_rl_complete); diff --git a/include/editline.h b/include/editline.h index c47a0bc..7d7e5f4 100644 --- a/include/editline.h +++ b/include/editline.h @@ -77,7 +77,7 @@ extern char *rl_complete(char *token, int *match); extern int rl_list_possib(char *token, char ***av); extern char **rl_completion_matches(const char *token, rl_compentry_func_t *generator); extern char *rl_filename_completion_function(const char *text, int state); -extern int rl_check_secret(char *source); +extern int rl_check_secret(const char *source); /* For compatibility with FSF readline. */ extern int rl_point; diff --git a/src/complete.c b/src/complete.c index 3e67b3f..7809ae2 100644 --- a/src/complete.c +++ b/src/complete.c @@ -398,17 +398,22 @@ char *rl_complete(char *token, int *match) } static rl_check_secret_func_t *el_check_secret_func = NULL; -/* For compatibility with the Heimdal project. */ + +/* Added for the BitShares Core project. */ rl_check_secret_func_t *rl_set_check_secret_func(rl_check_secret_func_t *func) { rl_check_secret_func_t *old = el_check_secret_func; + el_check_secret_func = func; + return old; } -int rl_check_secret(char *source) + +int rl_check_secret(const char *line) { if (el_check_secret_func) - return el_check_secret_func(source); + return el_check_secret_func(line); + return 0; } diff --git a/src/editline.c b/src/editline.c index eb213a6..b968c17 100644 --- a/src/editline.c +++ b/src/editline.c @@ -1138,7 +1138,7 @@ static void hist_add(const char *p) if (s == NULL) return; - // Don't add secret information in history + /* Don't add secret information in history */ if (rl_check_secret(s)) return;