1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#include "common/util.h"
#include <stdlib.h>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include "common/config.h"
#include "restapi/auth.h"
#include "restapi/im.h"
int main(void)
{
if (config_load(CONFIG_PATH) != 0) {
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;
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;
}
char* password = NULL;
printf("Password: ");
read = getline(&password, &len, stdin);
if (read > 1) password[read-1] = 0;
if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) {
perror("tcsetattr");
return -1;
}
if (restapi_login(login, password) == 0) {
while(1) {
char* buff = NULL;
size_t len2;
printf("IM to close: ");
ssize_t entry = getline(&buff, &len2, stdin);
if (entry > 1) {
buff[entry-1] = 0;
} else {
free(buff);
break;
}
restapi_im_close(buff);
free(buff);
}
} else {
printf("Couldn't init rest api.\n");
}
restapi_logout();
config_clean();
free(login);
free(password);
return 0;
}
|