diff --git a/src/base_page.c b/src/base_page.c index efb00b7..604913f 100644 --- a/src/base_page.c +++ b/src/base_page.c @@ -35,6 +35,12 @@ void render_base_page(struct base_page* page) struct http_cookie_info info = { 0 }; char* login_string = "Login / Register"; + /* + * Since getenv() returns a pointer to the env variables, + * we're going to overwrite that data. It saves us some copying + * time, since this is /very likely/ the last time we will ever + * read HTTP_COOKIE + */ if (!g_config.changed && cookie) while (1) { diff --git a/src/cookie.c b/src/cookie.c index 2888c5c..26ffc43 100644 --- a/src/cookie.c +++ b/src/cookie.c @@ -16,6 +16,7 @@ * along with this program. If not, see . */ +#include #include #include "cookie.h" @@ -76,7 +77,7 @@ char* parse_cookies(char* begin, struct http_cookie_info* info) int cookie_get_val(char* src, char* key, struct http_cookie_info* info) { struct http_cookie_info read_info; - char* src_read; + char* src_read = src; while (1) { diff --git a/src/login.c b/src/login.c index dcb126d..ebe4b19 100644 --- a/src/login.c +++ b/src/login.c @@ -58,7 +58,7 @@ void content_login(mastodont_t* api, char** data, size_t data_size) struct mstdnt_app_register_args args_app = { .client_name = "RatFE", .redirect_uris = "http://localhost/", - .scopes = "read+write", + .scopes = "read+write+follow+push", .website = NULL }; diff --git a/src/status.c b/src/status.c index ae54370..eebfc0e 100644 --- a/src/status.c +++ b/src/status.c @@ -21,6 +21,7 @@ #include "status.h" #include "easprintf.h" #include "query.h" +#include "cookie.h" #include "../static/status.chtml" static void status_post(struct http_query_info* info, void* arg) @@ -29,7 +30,37 @@ static void status_post(struct http_query_info* info, void* arg) if (strcmp(info->key, "content") == 0) { + struct http_cookie_info ck; + struct mstdnt_storage storage; + + // Cookie copy + char* http_cookie = getenv("HTTP_COOKIE"); + char* cookie = malloc(strlen(http_cookie)); + strcpy(cookie, http_cookie); + char* cookie_read = cookie; + 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, + .in_reply_to_conversation_id = NULL, + .in_reply_to_id = NULL, + .language = NULL, + .media_ids = NULL, + .poll = NULL, + .preview = 0, + .scheduled_at = NULL, + .sensitive = 0, + .spoiler_text = NULL, + .status = info->val, + .visibility = "public", + }; + mastodont_create_status(api, &args, &storage); + } +// mastodont_storage_cleanup(&storage); + free(cookie); } }