aboutsummaryrefslogtreecommitdiff
path: root/close_im/main.c
diff options
context:
space:
mode:
authorJulien Dessaux2019-08-04 11:03:38 +0200
committerJulien Dessaux2019-08-05 13:28:51 +0200
commit1bec937076d8d40f94ff4603479f21bca2de6c61 (patch)
treed811f0155c09149e9ade2016e224d58b2fbf6d81 /close_im/main.c
parentAdded configuration file parsing (diff)
downloadrocket-cli-client-1bec937076d8d40f94ff4603479f21bca2de6c61.tar.gz
rocket-cli-client-1bec937076d8d40f94ff4603479f21bca2de6c61.tar.bz2
rocket-cli-client-1bec937076d8d40f94ff4603479f21bca2de6c61.zip
Added http lib and basic restapi with rocket_close_im binary
Diffstat (limited to 'close_im/main.c')
-rw-r--r--close_im/main.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/close_im/main.c b/close_im/main.c
new file mode 100644
index 0000000..b770f3d
--- /dev/null
+++ b/close_im/main.c
@@ -0,0 +1,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;
+}