aboutsummaryrefslogtreecommitdiff
path: root/close_im
diff options
context:
space:
mode:
authorJulien Dessaux2019-08-06 11:12:51 +0200
committerJulien Dessaux2019-08-06 11:12:51 +0200
commit37d9ca6cf6aa11a8408f844aa23813c5060725af (patch)
treead87d99ac8767031a2280b155e30a956f64df525 /close_im
parentGet rid of the useless roundtrip of "Expect: 100-continue" when using a POST (diff)
downloadrocket-cli-client-37d9ca6cf6aa11a8408f844aa23813c5060725af.tar.gz
rocket-cli-client-37d9ca6cf6aa11a8408f844aa23813c5060725af.tar.bz2
rocket-cli-client-37d9ca6cf6aa11a8408f844aa23813c5060725af.zip
Added the option to set login and password in config file
Diffstat (limited to '')
-rw-r--r--close_im/main.c55
1 files changed, 32 insertions, 23 deletions
diff --git a/close_im/main.c b/close_im/main.c
index b770f3d..c54ab25 100644
--- a/close_im/main.c
+++ b/close_im/main.c
@@ -14,31 +14,40 @@ int main(void)
return 1;
}
- char* login = NULL;
- size_t len = 0;
- printf("Login: ");
- ssize_t read = getline(&login, &len, stdin);
- if (read > 1) login[read-1] = 0;
+ 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;
+ }
- struct termios oflags, nflags;
- tcgetattr(fileno(stdin), &oflags);
- nflags = oflags;
- nflags.c_lflag &= ~ECHO;
- nflags.c_lflag |= ECHONL;
+ 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;
- }
+ if (tcsetattr(fileno(stdin), TCSADRAIN, &nflags) != 0) {
+ perror("tcsetattr");
+ return -1;
+ }
- char* password = NULL;
- printf("Password: ");
- read = getline(&password, &len, stdin);
- if (read > 1) password[read-1] = 0;
+ 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;
+ if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) {
+ perror("tcsetattr");
+ return -1;
+ }
+ password = termpassword;
}
if (restapi_login(login, password) == 0) {
@@ -62,8 +71,8 @@ int main(void)
restapi_logout();
config_clean();
- free(login);
- free(password);
+ free(termlogin);
+ free(termpassword);
return 0;
}