From ad333fb2c7790dfcc4a5af286dfb15e8f7db0a27 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Tue, 6 Aug 2019 19:22:51 +0200 Subject: Migrated the reading of login and password from cli to the common lib --- close_direct_conversations/main.c | 42 ++++++--------------------------------- 1 file changed, 6 insertions(+), 36 deletions(-) (limited to 'close_direct_conversations/main.c') diff --git a/close_direct_conversations/main.c b/close_direct_conversations/main.c index 0938982..82bf851 100644 --- a/close_direct_conversations/main.c +++ b/close_direct_conversations/main.c @@ -1,9 +1,8 @@ #include #include -#include -#include #include "common/config.h" +#include "common/cli.h" #include "common/util.h" #include "restapi/auth.h" #include "restapi/im.h" @@ -22,40 +21,12 @@ int main(void) } const char* login = config_get_login(); - char* termlogin = NULL; - if (login == NULL) { - size_t len = 0; - printf("Login: "); - ssize_t read = getline(&termlogin, &len, stdin); - if (read > 1) termlogin[read-1] = 0; - login = termlogin; - } + if (login == NULL) + login = common_cli_get_login(); const char* password = config_get_password(); - char* termpassword = NULL; - if (password == NULL) { - struct termios oflags, nflags; - tcgetattr(fileno(stdin), &oflags); - nflags = oflags; - nflags.c_lflag &= ~ECHO; - nflags.c_lflag |= ECHONL; - - if (tcsetattr(fileno(stdin), TCSADRAIN, &nflags) != 0) { - perror("tcsetattr"); - return -1; - } - - size_t len = 0; - printf("Password: "); - size_t read = getline(&termpassword, &len, stdin); - if (read > 1) termpassword[read-1] = 0; - - if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) { - perror("tcsetattr"); - return -1; - } - password = termpassword; - } + if (password == NULL) + password = common_cli_get_password(); if (restapi_login(login, password) == 0) { struct subscription* subscriptions = restapi_subscriptions_get(); @@ -84,8 +55,7 @@ int main(void) restapi_logout(); config_clean(); - free(termlogin); - free(termpassword); + common_cli_free(); return 0; } -- cgit v1.2.3