Mercurial > hg > nnchat
changeset 211:c40329e95445
Trim both left and right side of username+password prompt input. Also allow empty passwords, to be able to use guest accounts.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 20 Nov 2010 23:13:30 +0200 |
parents | 4554f9abc686 |
children | f474ea264a5b |
files | nnchat.c |
diffstat | 1 files changed, 11 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/nnchat.c Sat Nov 20 23:12:04 2010 +0200 +++ b/nnchat.c Sat Nov 20 23:13:30 2010 +0200 @@ -879,19 +879,21 @@ return FALSE; } -char *promptRequester(const char *info) +char *promptRequester(const char *info, BOOL allowEmpty) { - char tmpBuf[512]; - ssize_t bufLen; + char tmpBuf[512], *ptr; + ssize_t pos; fputs(info, stdout); fgets(tmpBuf, sizeof(tmpBuf), stdin); - for (bufLen = strlen(tmpBuf) - 1; bufLen > 0 && (tmpBuf[bufLen] == '\n' || tmpBuf[bufLen] == '\r' || th_isspace(tmpBuf[bufLen])); bufLen--) - tmpBuf[bufLen] = 0; + for (pos = strlen(tmpBuf) - 1; pos > 0 && (tmpBuf[pos] == '\n' || tmpBuf[pos] == '\r' || th_isspace(tmpBuf[pos])); pos--) + tmpBuf[pos] = 0; - if (bufLen > 0) - return th_strdup(tmpBuf); + ptr = trimLeft(tmpBuf); + + if (allowEmpty || strlen(ptr) > 0) + return th_strdup(ptr); else return NULL; } @@ -984,8 +986,8 @@ /* Check if we have username and password */ if (optUserName == NULL || optPassword == NULL) { printf("\nYou can avoid this prompt by issuing '/save' after logging in.\n\n"); - optUserName = promptRequester("NN username: "); - optPassword = promptRequester("NN password: "); + optUserName = promptRequester("NN username: ", FALSE); + optPassword = promptRequester("NN password: ", TRUE); if (optUserName == NULL || optPassword == NULL) { THERR("User/pass not specified, get some --help\n"); return -1;