Mercurial > hg > nnchat
changeset 196:edd5ce3e5399
Add simplistic username/password requester if none given on commandline or config file.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 17 Nov 2010 05:13:12 +0200 |
parents | 829457be9eea |
children | e0ec2280a778 |
files | nnchat.c |
diffstat | 1 files changed, 24 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/nnchat.c Wed Nov 17 04:09:41 2010 +0200 +++ b/nnchat.c Wed Nov 17 05:13:12 2010 +0200 @@ -869,6 +869,22 @@ return FALSE; } +char *promptRequester(const char *info) +{ + char tmpBuf[512]; + ssize_t bufLen; + + 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; + + if (bufLen > 0) + return th_strdup(tmpBuf); + else + return NULL; +} int main(int argc, char *argv[]) { @@ -939,7 +955,7 @@ if ((cfgfile = fopen(setConfigFile, "r")) != NULL) th_cfg_read(cfgfile, setConfigFile, cfg); } - + setBrowser = getenv("BROWSER"); if (setBrowser == NULL) setBrowser = "firefox"; @@ -950,8 +966,13 @@ /* Check if we have username and password */ if (optUserName == NULL || optPassword == NULL) { - THERR("User/pass not specified, get some --help\n"); - return -1; + printf("\nYou can avoid this prompt by issuing '/save' after logging in.\n\n"); + optUserName = promptRequester("NN username: "); + optPassword = promptRequester("NN password: "); + if (optUserName == NULL || optPassword == NULL) { + THERR("User/pass not specified, get some --help\n"); + return -1; + } } if (!argsOK)