--- a/dav/main.c Sat Oct 03 16:44:50 2015 +0200 +++ b/dav/main.c Sat Oct 03 18:11:07 2015 +0200 @@ -68,6 +68,7 @@ xmlGenericErrorFunc fnc = xmlerrorfnc; initGenericErrorDefaultFunc(&fnc); ctx = dav_context_new(); + ctx->key_input = util_key_input; load_config(ctx); printxmlerror = 0; #ifdef DO_THE_TEST @@ -175,49 +176,6 @@ fprintf(stderr, "\n"); } -char* password_input(char *prompt) { - fprintf(stderr, "%s", prompt); - fflush(stderr); - - // hide terminal input -#ifdef _WIN32 - // TODO -#else - struct termios oflags, nflags; - tcgetattr(fileno(stdin), &oflags); - nflags = oflags; - nflags.c_lflag &= ~ECHO; - nflags.c_lflag |= ECHONL; - if (tcsetattr(fileno(stdin), TCSANOW, &nflags) != 0) { - perror("tcsetattr"); - } -#endif - - // read password input - UcxBuffer *buf = ucx_buffer_new(NULL, 128, UCX_BUFFER_AUTOEXTEND); - int c = 0; - while((c = getchar()) != EOF) { - if(c == '\n') { - break; - } - ucx_buffer_putc(buf, c); - } - ucx_buffer_putc(buf, 0); - - // restore terminal settings -#ifdef _WIN32 - // TODO -#else - if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) { - perror("tcsetattr"); - } -#endif - - char *str = buf->space; - free(buf); // only free the UcxBuffer struct - return str; -} - int request_auth(Repository *repo, DavSession *sn) { static int login = 0; if(login) { @@ -234,7 +192,7 @@ user = fgets(ubuf, 256, stdin); } - char *password = password_input("password: "); + char *password = util_password_input("password: "); size_t ulen = strlen(user); if(user[ulen-1] == '\n') {