From 6f4b9642127cd75bbf3d706b877003c468b3d5d2 Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Thu, 20 Jan 2022 04:45:33 +0000 Subject: [PATCH] Mastodont load FossilOrigin-Name: 834b0fd5e06c00d0cc94eb520d9efdda483eae6df8da5b7bf253205f95f56035 --- .gitignore | 2 +- Makefile | 8 +++++--- src/index.c | 4 +++- src/index.h | 3 ++- src/main.c | 8 ++++++-- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 07c8463..a5b6029 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ filec **/*.cgi **/*.o **/*.chtml -mastodont-c/ \ No newline at end of file +mastodont-c diff --git a/Makefile b/Makefile index 5e113b6..1d45ada 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ TARGET = ratfe.cgi MASTODONT_URL = https://git.nekobit.net/repos/mastodont-c.git -all: $(MASTODONT_DIR) $(TARGET) +all: $(MASTODONT_DIR) dep_build $(TARGET) $(TARGET): filec $(PAGES_CMP) $(OBJ) $(CC) -o $(DIST)$(TARGET) $(OBJ) $(LDFLAGS) @@ -28,9 +28,11 @@ filec: src/file-to-c/main.o $(PAGES_DIR)/index.chtml: $(PAGES_DIR)/index.html ./filec $< data_index_html > $@ -$(MASTODONT_DIR): - git clone $(MASTODONT_URL) +$(MASTODONT_DIR): + git clone $(MASTODONT_URL) || true @echo -e "\033[38;5;13mRun 'make update' to update mastodont-c\033[0m" + +dep_build: make -C $(MASTODONT_DIR) update: diff --git a/src/index.c b/src/index.c index b854336..b819414 100644 --- a/src/index.c +++ b/src/index.c @@ -23,7 +23,9 @@ // Files #include "../static/index.chtml" -void content_index() +void content_index(mastodont_t* api) { + struct mstdnt_response response; + mastodont_timeline_public(api, NULL, &response); printf(data_index_html, config_canonical_name); } diff --git a/src/index.h b/src/index.h index 7659408..16aef0d 100644 --- a/src/index.h +++ b/src/index.h @@ -18,7 +18,8 @@ #ifndef INDEX_H #define INDEX_H +#include -void content_index(); +void content_index(mastodont_t* api); #endif // INDEX_H diff --git a/src/main.c b/src/main.c index 3cbf4cf..e12fce8 100644 --- a/src/main.c +++ b/src/main.c @@ -29,16 +29,20 @@ int main() // Content type is always HTML fputs("Content-type: text/html\r\n\r\n", stdout); + // Global init + mastodont_global_curl_init(); + mastodont_t api; api.url = config_instance_url; - mastodont_init(&api); // Default index if (path == NULL || (path && strcmp(path, "/"))) { - content_index(); + content_index(&api); } + // Cleanup mastodont_free(&api); + mastodont_global_curl_cleanup(); }