From a74fd99b1e5a8df88eb58e575f54a08a04ecfd7e Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Fri, 18 Feb 2022 04:35:08 +0000 Subject: [PATCH] Set token at start FossilOrigin-Name: 6bddbaf860e0dadf443c554e170ac083ed871dff2b1c3c7950a8daa81dc221a7 --- src/.#status.c | 1 + src/main.c | 28 ++++++++++++++++++++++++++++ src/status.c | 3 +-- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 120000 src/.#status.c diff --git a/src/.#status.c b/src/.#status.c new file mode 120000 index 0000000..88b7086 --- /dev/null +++ b/src/.#status.c @@ -0,0 +1 @@ +nekobit@toomuchram.2139:1645145990 \ No newline at end of file diff --git a/src/main.c b/src/main.c index b8ec9ee..0e0c081 100644 --- a/src/main.c +++ b/src/main.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "../config.h" #include "index.h" #include "page_config.h" @@ -26,6 +27,30 @@ #include "account.h" #include "login.h" #include "local_config.h" +#include "cookie.h" + +void load_auth_token(mastodont_t* api) +{ + struct http_cookie_info ck; + char* http_cookie = getenv("HTTP_COOKIE"); + + if (http_cookie) + { + char* cookie = malloc(strlen(http_cookie)); + if (!cookie) + { + perror("malloc"); + exit(1); + } + strcpy(cookie, http_cookie); + char* cookie_read = cookie; + if (cookie_get_val(cookie_read, "access_token", &ck) == 0) + { + mastodont_set_token(api, ck.val); + } + free(cookie); + } +} int main(void) { @@ -40,6 +65,9 @@ int main(void) api.url = config_instance_url; mastodont_init(&api); + // Used if the user is authenticated + load_auth_token(&api); + // Config defaults g_config.theme = "ratfe20"; diff --git a/src/status.c b/src/status.c index d43df3b..8b53dbf 100644 --- a/src/status.c +++ b/src/status.c @@ -33,7 +33,7 @@ static void status_post(struct http_query_info* info, void* arg) struct http_cookie_info ck; struct mstdnt_storage storage; - // Cookie copy + // Cookie copy and read char* http_cookie = getenv("HTTP_COOKIE"); char* cookie = malloc(strlen(http_cookie)); strcpy(cookie, http_cookie); @@ -41,7 +41,6 @@ static void status_post(struct http_query_info* info, void* arg) if (cookie_get_val(cookie_read, "access_token", &ck) == 0) { - api->token = ck.val; struct mstdnt_create_status_args args = { .content_type = "text/plain", .expires_in = 0,