diff --git a/Makefile b/Makefile index 8242936..0f0a2fe 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,8 @@ CC ?= cc GIT ?= git MASTODONT_DIR = mastodont-c/ MASTODONT = $(MASTODONT_DIR)libmastodont.a -CFLAGS += -Wall -I $(MASTODONT_DIR)include/ -Wno-unused-variable -Wno-discarded-qualifiers $(shell pkg-config --cflags libcurl libcjson libpcre) -LDFLAGS = -L$(MASTODONT_DIR) -lmastodont $(shell pkg-config --libs libcjson libcurl libpcre) +CFLAGS += -Wall -I $(MASTODONT_DIR)include/ -Wno-unused-variable -Wno-discarded-qualifiers $(shell pkg-config --cflags libcurl libcjson libpcre fcgi) +LDFLAGS = -L$(MASTODONT_DIR) -lmastodont $(shell pkg-config --libs libcjson libcurl libpcre fcgi) SRC = $(wildcard src/*.c) OBJ = $(patsubst %.c,%.o,$(SRC)) PAGES_DIR = static diff --git a/src/main.c b/src/main.c index 396ca7a..6f33c70 100644 --- a/src/main.c +++ b/src/main.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include "../config.h" @@ -41,41 +42,49 @@ int main(void) mastodont_global_curl_init(); // API - mastodont_t api; - api.url = config_instance_url; - mastodont_init(&api, MSTDNT_FLAG_NO_URI_SANITIZE); + while (FCGI_Accept() >= 0) + { + mastodont_t api; + api.url = config_instance_url; + mastodont_init(&api, MSTDNT_FLAG_NO_URI_SANITIZE); - // Load cookies - char* cookies_str = read_cookies_env(); - api.token = cookies.access_token; // Load token now - char* post_str = read_post_data(); + // Load cookies + char* cookies_str = read_cookies_env(); + api.token = cookies.access_token; // Load token now + char* post_str = read_post_data(); - // Config defaults - g_config.theme = "treebird20"; + // Config defaults + g_config.theme = "treebird20"; - /******************* - * Path handling * - ******************/ - struct path_info paths[] = { - { "/config", content_config }, - { "/login", content_login }, - { "/test", content_test }, - { "/@:", content_account }, - { "/status/:/interact", status_interact }, - { "/status/:/reply", status_reply }, - { "/status/:", status_view }, - { "/lists/for/:", content_tl_list }, - { "/lists", content_lists }, - { "/federated", content_tl_federated }, - { "/local", content_tl_local }, - { "/notifications", content_notifications }, - }; + /******************* + * Path handling * + ******************/ + struct path_info paths[] = { + { "/config", content_config }, + { "/login", content_login }, + { "/test", content_test }, + { "/@:", content_account }, + { "/status/:/interact", status_interact }, + { "/status/:/reply", status_reply }, + { "/status/:", status_view }, + { "/lists/for/:", content_tl_list }, + { "/lists", content_lists }, + { "/federated", content_tl_federated }, + { "/local", content_tl_local }, + { "/notifications", content_notifications }, + }; - handle_paths(&api, paths, sizeof(paths)/sizeof(paths[0])); + handle_paths(&api, paths, sizeof(paths)/sizeof(paths[0])); + + // Cleanup + if (cookies_str) free(cookies_str); + if (post_str) free(post_str); + mastodont_free(&api); + + // Obliterate all global values, so the next client + // can't even consider reading them + memset(&cookies, 0, sizeof(cookies)); + } - // Cleanup - if (cookies_str) free(cookies_str); - if (post_str) free(post_str); - mastodont_free(&api); mastodont_global_curl_cleanup(); }