aboutsummaryrefslogtreecommitdiff
path: root/close_im
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--close_im/CMakeLists.txt8
-rw-r--r--close_im/main.c69
-rw-r--r--close_im/main.cpp46
3 files changed, 74 insertions, 49 deletions
diff --git a/close_im/CMakeLists.txt b/close_im/CMakeLists.txt
index fd5ce8c..aec4090 100644
--- a/close_im/CMakeLists.txt
+++ b/close_im/CMakeLists.txt
@@ -1,7 +1,9 @@
-file(GLOB_RECURSE SOURCES *.cpp)
+file(GLOB_RECURSE SOURCES *.c)
ADD_EXECUTABLE(rocket_close_im ${SOURCES})
-target_link_libraries(rocket_close_im common rest)
-target_link_libraries(rocket_close_im curl)
+target_link_libraries(rocket_close_im common restapi)
+target_link_libraries(rocket_close_im config curl)
+add_dependencies(rocket_close_im cjson-build)
+target_link_libraries(rocket_close_im ${CMAKE_CURRENT_BINARY_DIR}/../cjson/src/cjson-build/libcjson.a)
install(TARGETS rocket_close_im DESTINATION bin)
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;
+}
diff --git a/close_im/main.cpp b/close_im/main.cpp
deleted file mode 100644
index c412d8b..0000000
--- a/close_im/main.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-#include <cstdlib>
-#include <string>
-#include <unistd.h>
-
-#include "common/config.h"
-#include "rest/rest.hpp"
-#include "common/util.h"
-
-int main(void)
-{
- char* login = NULL;
- size_t len = 0;
- printf("Login: ");
- ssize_t read = getline(&login, &len, stdin);
- if (read > 1) login[read-1] = 0;
-
- char* password = getpass("Password: ");
-
- rest_init(WEB_URL);
-
- if (rest_login(login, password)) {
- 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;
- }
- rest_im_close(buff);
- free(buff);
- }
- } else {
- printf("Couldn't init rest api.\n");
- }
-
- rest_logout();
- rest_clear();
-
- free(login);
-
- return 0;
-}