diff options
author | Alfred E. Heggestad <aeh@db.org> | 2016-01-03 21:01:07 +0100 |
---|---|---|
committer | Alfred E. Heggestad <aeh@db.org> | 2016-01-03 21:01:07 +0100 |
commit | 856d3a5ac00d21d7892d2020a16b33bbd4aa829f (patch) | |
tree | eadf0ec6208cd9dcbda6c7a876f627df829f00c4 | |
parent | 435e7c62382df0adcfcec0bae6fd8e65c7dacbda (diff) |
move password_prompt function to ui.c
-rw-r--r-- | include/baresip.h | 1 | ||||
-rw-r--r-- | src/account.c | 37 | ||||
-rw-r--r-- | src/ui.c | 31 |
3 files changed, 37 insertions, 32 deletions
diff --git a/include/baresip.h b/include/baresip.h index b8d92aa..8574d35 100644 --- a/include/baresip.h +++ b/include/baresip.h @@ -588,6 +588,7 @@ void ui_input_str(const char *str); int ui_input_pl(struct re_printf *pf, const struct pl *pl); void ui_output(const char *fmt, ...); bool ui_isediting(void); +int ui_password_prompt(char **passwordp); /* diff --git a/src/account.c b/src/account.c index 846f6f9..7b32890 100644 --- a/src/account.c +++ b/src/account.c @@ -323,37 +323,6 @@ static int encode_uri_user(struct re_printf *pf, const struct uri *uri) } -/* TODO: move interactive code away from CORE, to a module */ -static int password_prompt(struct account *acc) -{ - char pwd[64]; - char *nl; - int err; - - (void)re_printf("Please enter password for %r@%r: ", - &acc->luri.user, &acc->luri.host); - - /* note: blocking UI call */ - fgets(pwd, sizeof(pwd), stdin); - pwd[sizeof(pwd) - 1] = '\0'; - - nl = strchr(pwd, '\n'); - if (nl == NULL) { - (void)re_printf("Invalid password (0 - 63 characters" - " followed by newline)\n"); - return EINVAL; - } - - *nl = '\0'; - - err = str_dup(&acc->auth_pass, pwd); - if (err) - return err; - - return 0; -} - - int account_alloc(struct account **accp, const char *sipaddr) { struct account *acc; @@ -399,7 +368,11 @@ int account_alloc(struct account **accp, const char *sipaddr) /* optional password prompt */ if (!pl_isset(&acc->laddr.uri.password)) { - err = password_prompt(acc); + (void)re_printf("Please enter password for %r@%r: ", + &acc->luri.user, &acc->luri.host); + + /* TODO: move interactive code away from CORE, to a module */ + err = ui_password_prompt(&acc->auth_pass); if (err) goto out; } @@ -3,6 +3,7 @@ * * Copyright (C) 2010 Creytiv.com */ +#include <string.h> #include <re.h> #include <baresip.h> #include "core.h" @@ -167,3 +168,33 @@ bool ui_isediting(void) { return uictx != NULL; } + + +int ui_password_prompt(char **passwordp) +{ + char pwd[64]; + char *nl; + int err; + + if (!passwordp) + return EINVAL; + + /* note: blocking UI call */ + fgets(pwd, sizeof(pwd), stdin); + pwd[sizeof(pwd) - 1] = '\0'; + + nl = strchr(pwd, '\n'); + if (nl == NULL) { + (void)re_printf("Invalid password (0 - 63 characters" + " followed by newline)\n"); + return EINVAL; + } + + *nl = '\0'; + + err = str_dup(passwordp, pwd); + if (err) + return err; + + return 0; +} |