aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rwxr-xr-xsrc/main.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100755
index 0000000..26090ff
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,83 @@
+#include <ncurses.h>
+#include <openssl/ssl.h>
+#include <stdlib.h>
+
+#include "color.h"
+#include "config.h"
+#include "connect.h"
+#include "net.h"
+#include "request.h"
+#include "response.h"
+#include "status.h"
+#include "url.h"
+#include "util.h"
+
+void exit_cleanup(void) { endwin(); }
+
+void init_ncurses(void) {
+ initscr();
+ cbreak();
+ noecho();
+
+ curs_set(0);
+ keypad(stdscr, TRUE);
+ scrollok(stdscr, TRUE);
+
+ if (!has_colors())
+ die("Terminal does not support colors");
+
+ start_color();
+ set_colors();
+
+ refresh();
+}
+
+int main(void) {
+ struct config conf;
+ init_config(&conf);
+
+ init_ncurses();
+ atexit(exit_cleanup);
+
+ getmaxyx(stdscr, conf.i.height, conf.i.width);
+
+ init_status(&conf);
+ conf.s.url = init_url();
+ conf.s.conn = init_connection();
+
+ prompt_status_url(&conf);
+ update_status(&conf, conf.s.url_string);
+
+ int rc = parse_url(conf.s.url, conf.s.url_string);
+ if (rc < 0) {
+ error_status(&conf, "Invalid URL");
+ conf_cleanup(&conf);
+ return 1;
+ }
+
+ rc = tls_connect(&conf, *conf.s.url);
+ if (rc < 0) {
+ conf_cleanup(&conf);
+ return 1;
+ }
+
+ struct request req;
+ req.kind = GET;
+ req.url = *conf.s.url;
+ send_request(&conf, &req);
+
+ struct response res;
+ rc = read_response(&conf, &res);
+ if (rc < 0) {
+ conf_cleanup(&conf);
+ return rc * -1;
+ }
+ conf.s.res = &res;
+
+ printw("%s\n", conf.s.res->content);
+
+ getch();
+
+ conf_cleanup(&conf);
+ return 0;
+}