diff options
-rw-r--r-- | include/baresip.h | 2 | ||||
-rw-r--r-- | modules/account/account.c | 32 | ||||
-rw-r--r-- | src/account.c | 37 |
3 files changed, 61 insertions, 10 deletions
diff --git a/include/baresip.h b/include/baresip.h index 62e5966..43ffb8a 100644 --- a/include/baresip.h +++ b/include/baresip.h @@ -47,6 +47,7 @@ struct account; int account_alloc(struct account **accp, const char *sipaddr); int account_debug(struct re_printf *pf, const struct account *acc); +int account_set_auth_pass(struct account *acc, const char *pass); int account_set_display_name(struct account *acc, const char *dname); int account_auth(const struct account *acc, char **username, char **password, const char *realm); @@ -59,6 +60,7 @@ uint32_t account_ptime(const struct account *acc); enum answermode account_answermode(const struct account *acc); const char *account_aor(const struct account *acc); const char *account_auth_user(const struct account *acc); +const char *account_auth_pass(const struct account *acc); const char *account_outbound(const struct account *acc, unsigned ix); const char *account_stun_user(const struct account *acc); const char *account_stun_pass(const struct account *acc); diff --git a/modules/account/account.c b/modules/account/account.c index ea9d819..c972908 100644 --- a/modules/account/account.c +++ b/modules/account/account.c @@ -109,11 +109,41 @@ static int account_write_template(const char *file) static int line_handler(const struct pl *addr, void *arg) { char buf[512]; + struct ua *ua; + struct account *acc; + int err; (void)arg; (void)pl_strcpy(addr, buf, sizeof(buf)); - return ua_alloc(NULL, buf); + err = ua_alloc(&ua, buf); + if (err) + return err; + + acc = ua_account(ua); + if (!acc) { + warning("account: no account for this ua\n"); + return ENOENT; + } + + /* optional password prompt */ + if (!str_isset(account_auth_pass(acc))) { + char *pass = NULL; + + (void)re_printf("Please enter password for %s: ", + account_aor(acc)); + + err = ui_password_prompt(&pass); + if (err) + goto out; + + err = account_set_auth_pass(acc, pass); + + mem_deref(pass); + } + + out: + return err; } diff --git a/src/account.c b/src/account.c index 8f10940..1b2e468 100644 --- a/src/account.c +++ b/src/account.c @@ -386,16 +386,8 @@ int account_alloc(struct account **accp, const char *sipaddr) goto out; /* optional password prompt */ - if (!pl_isset(&acc->laddr.uri.password)) { - (void)re_printf("Please enter password for %r@%r: ", - &acc->luri.user, &acc->luri.host); + if (pl_isset(&acc->laddr.uri.password)) { - /* TODO: move interactive code away from CORE, to a module */ - err = ui_password_prompt(&acc->auth_pass); - if (err) - goto out; - } - else { err = re_sdprintf(&acc->auth_pass, "%H", uri_password_unescape, &acc->laddr.uri.password); @@ -433,6 +425,20 @@ int account_alloc(struct account **accp, const char *sipaddr) } +int account_set_auth_pass(struct account *acc, const char *pass) +{ + if (!acc) + return EINVAL; + + acc->auth_pass = mem_deref(acc->auth_pass); + + if (pass) + return str_dup(&acc->auth_pass, pass); + + return 0; +} + + /** * Sets the displayed name. Pass null in dname to disable display name * @@ -540,6 +546,19 @@ const char *account_auth_user(const struct account *acc) /** + * Get the SIP authentication password of an account + * + * @param acc User-Agent account + * + * @return Authentication password + */ +const char *account_auth_pass(const struct account *acc) +{ + return acc ? acc->auth_pass : NULL; +} + + +/** * Get the outbound SIP server of an account * * @param acc User-Agent account |