Create status

FossilOrigin-Name: d314b7e31e03bda767bf675d61c92f93758064f5bfb66ddf18d1f2774f6318f4
This commit is contained in:
me@ow.nekobit.net 2022-02-16 20:29:48 +00:00
parent 6c85bd83b6
commit d5d3312c93
4 changed files with 40 additions and 2 deletions

View file

@ -35,6 +35,12 @@ void render_base_page(struct base_page* page)
struct http_cookie_info info = { 0 };
char* login_string = "<a href=\"login\" id=\"login-header\">Login / Register</a>";
/*
* 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)
{

View file

@ -16,6 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <stdio.h>
#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)
{

View file

@ -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
};

View file

@ -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);
}
}