Config rewrite

FossilOrigin-Name: df35b1f1ef947cf36dab970ebd120b8029a972030283a011efe4bbd83d6ec336
This commit is contained in:
nekobit 2022-05-19 04:18:14 +00:00
parent b106d03e73
commit ca3c2b097c
24 changed files with 301 additions and 251 deletions

View file

@ -108,7 +108,7 @@ static char* account_statuses_cb(struct session* ssn,
if (statuses)
{
// If not set, set it
start_id = ssn->post.start_id ? ssn->post.start_id : statuses[0].id;
start_id = keystr(ssn->post.start_id) ? keystr(ssn->post.start_id) : statuses[0].id;
navigation_box = construct_navigation_box(start_id,
statuses[0].id,
statuses[statuses_len-1].id,
@ -403,8 +403,8 @@ void content_account_statuses(struct session* ssn, mastodont_t* api, char** data
.exclude_reblogs = 0,
.exclude_replies = 0,
.tagged = NULL,
.max_id = ssn->post.max_id,
.min_id = ssn->post.min_id,
.max_id = keystr(ssn->post.max_id),
.min_id = keystr(ssn->post.min_id),
.since_id = NULL,
.offset = 0,
.limit = 20,
@ -427,8 +427,8 @@ void content_account_pinned(struct session* ssn, mastodont_t* api, char** data)
.exclude_reblogs = 0,
.exclude_replies = 0,
.tagged = NULL,
.max_id = ssn->post.max_id,
.min_id = ssn->post.min_id,
.max_id = keystr(ssn->post.max_id),
.min_id = keystr(ssn->post.min_id),
.since_id = NULL,
.offset = 0,
.limit = 20,
@ -447,8 +447,8 @@ void content_account_media(struct session* ssn, mastodont_t* api, char** data)
.exclude_reblogs = 0,
.exclude_replies = 0,
.tagged = NULL,
.max_id = ssn->post.max_id,
.min_id = ssn->post.min_id,
.max_id = keystr(ssn->post.max_id),
.min_id = keystr(ssn->post.min_id),
.since_id = NULL,
.offset = 0,
.limit = 20,
@ -496,9 +496,9 @@ void content_account_bookmarks(struct session* ssn, mastodont_t* api, char** dat
char* start_id;
struct mstdnt_bookmarks_args args = {
.max_id = ssn->post.max_id,
.max_id = keystr(ssn->post.max_id),
.since_id = NULL,
.min_id = ssn->post.min_id,
.min_id = keystr(ssn->post.min_id),
.limit = 20,
};
@ -517,7 +517,7 @@ void content_account_bookmarks(struct session* ssn, mastodont_t* api, char** dat
if (statuses)
{
// If not set, set it
start_id = ssn->post.start_id ? ssn->post.start_id : statuses[0].id;
start_id = keystr(ssn->post.start_id) ? keystr(ssn->post.start_id) : statuses[0].id;
navigation_box = construct_navigation_box(start_id,
statuses[0].id,
statuses[status_count-1].id,
@ -557,8 +557,8 @@ void content_account_favourites(struct session* ssn, mastodont_t* api, char** da
char* start_id;
struct mstdnt_favourites_args args = {
.max_id = ssn->post.max_id,
.min_id = ssn->post.min_id,
.max_id = keystr(ssn->post.max_id),
.min_id = keystr(ssn->post.min_id),
.limit = 20,
};
@ -577,7 +577,7 @@ void content_account_favourites(struct session* ssn, mastodont_t* api, char** da
if (statuses)
{
// If not set, set it
start_id = ssn->post.start_id ? ssn->post.start_id : statuses[0].id;
start_id = keystr(ssn->post.start_id) ? keystr(ssn->post.start_id) : statuses[0].id;
navigation_box = construct_navigation_box(start_id,
statuses[0].id,
statuses[status_count-1].id,

View file

@ -42,7 +42,7 @@ int try_upload_media(struct mstdnt_storage** storage,
struct mstdnt_attachment** attachments,
char*** media_ids)
{
size_t size = ssn->post.files.array_size;
size_t size = keyfile(ssn->post.files).array_size;
if (!FILES_READY(ssn))
return 1;
@ -54,7 +54,7 @@ int try_upload_media(struct mstdnt_storage** storage,
for (int i = 0; i < size; ++i)
{
struct file_content* content = ssn->post.files.content + i;
struct file_content* content = keyfile(ssn->post.files).content + i;
struct mstdnt_upload_media_args args = {
.file = {
.file = content->content,
@ -104,7 +104,7 @@ int try_upload_media(struct mstdnt_storage** storage,
void cleanup_media_storages(struct session* ssn, struct mstdnt_storage* storage)
{
if (!FILES_READY(ssn)) return;
for (size_t i = 0; i < ssn->post.files.array_size; ++i)
for (size_t i = 0; i < keyfile(ssn->post.files).array_size; ++i)
mastodont_storage_cleanup(storage + i);
free(storage);
}
@ -113,7 +113,7 @@ void cleanup_media_ids(struct session* ssn, char** media_ids)
{
if (!FILES_READY(ssn)) return;
if (!media_ids) return;
for (size_t i = 0; i < ssn->post.files.array_size; ++i)
for (size_t i = 0; i < keyfile(ssn->post.files).array_size; ++i)
free(media_ids[i]);
free(media_ids);
}

View file

@ -21,8 +21,9 @@
#include <mastodont.h>
#include "session.h"
#define FILES_READY(ssn) (ssn->post.files.array_size && \
ssn->post.files.content && ssn->post.files.content[0].content_size)
#define FILES_READY(ssn) (ssn->post.files.type.f.array_size && \
ssn->post.files.type.f.content && \
ssn->post.files.type.f.content[0].content_size)
int try_upload_media(struct mstdnt_storage** storage,
struct session* ssn,

View file

@ -50,8 +50,6 @@ void render_base_page(struct base_page* page, struct session* ssn, mastodont_t*
struct mstdnt_notification* notifs = NULL;
size_t notifs_len = 0;
read_config(ssn);
if (ssn->config.logged_in)
login_string = "";
@ -61,7 +59,7 @@ void render_base_page(struct base_page* page, struct session* ssn, mastodont_t*
}
// If user is logged in
if (ssn->cookies.logged_in && ssn->cookies.access_token)
if (keystr(ssn->cookies.logged_in) && keystr(ssn->cookies.access_token))
{
if (mastodont_verify_credentials(api, &acct, &storage) == 0)
{

View file

@ -20,7 +20,6 @@
#include <string.h>
#include <stdlib.h>
#include "cookie.h"
#include "key.h"
enum cookie_state
{
@ -79,7 +78,10 @@ char* read_cookies_env(struct cookie_values* cookies)
for (int i = 0; i < (sizeof(refs)/sizeof(refs[0])); ++i)
{
if (strcmp(info.key, refs[i].key) == 0)
{
refs[i].func(info.val, NULL, refs[i].val);
refs[i].val->is_set = 1;
}
}
}
while (cookies_read);

View file

@ -19,28 +19,29 @@
#ifndef COOKIE_H
#define COOKIE_H
#include <stddef.h>
#include "key.h"
struct cookie_values
{
char* access_token;
char* logged_in;
char* theme;
char* instance_url;
char* background_url;
char* client_id;
char* client_secret;
int themeclr;
int jsactions;
int jsreply;
int jslive;
int js;
int stat_attachments;
int stat_greentexts;
int stat_dope;
int stat_oneclicksoftware;
int stat_emoji_likes;
int instance_show_shoutbox;
int instance_panel;
struct key access_token;
struct key logged_in;
struct key theme;
struct key instance_url;
struct key background_url;
struct key client_id;
struct key client_secret;
struct key themeclr;
struct key jsactions;
struct key jsreply;
struct key jslive;
struct key js;
struct key stat_attachments;
struct key stat_greentexts;
struct key stat_dope;
struct key stat_oneclicksoftware;
struct key stat_emoji_likes;
struct key instance_show_shoutbox;
struct key instance_panel;
};
struct http_cookie_info

View file

@ -25,7 +25,7 @@
#include "../static/error_404.chtml"
#include "../static/error.chtml"
char* construct_error(char* error, enum error_type type, unsigned pad, size_t* size)
char* construct_error(const char* error, enum error_type type, unsigned pad, size_t* size)
{
char* error_html;
char* class;

View file

@ -29,7 +29,7 @@ enum error_type
E_NOTICE
};
char* construct_error(char* error, enum error_type type, unsigned pad, size_t* size);
char* construct_error(const char* error, enum error_type type, unsigned pad, size_t* size);
void content_not_found(struct session* ssn, mastodont_t* api, char* path);
#endif // ERROR_H

View file

@ -20,16 +20,14 @@
#include <limits.h>
#include "key.h"
void key_string(char* val, struct form_props* props, void* _arg)
void key_string(char* val, struct file_content* props, struct key* arg)
{
char** arg = _arg;
*arg = val;
arg->type.s = val;
}
void key_int(char* val, struct form_props* form, void* _arg)
void key_int(char* val, struct file_content* form, struct key* arg)
{
char* err;
int* arg = _arg;
// Convert
long result = strtol(val, &err, 10);
@ -37,8 +35,31 @@ void key_int(char* val, struct form_props* form, void* _arg)
// Overflow
result == LONG_MIN || result == LONG_MAX)
{
*arg = 0;
arg->type.i = 0;
return;
}
*arg = result;
arg->type.i = result;
}
void key_files(char* val, struct file_content* form, struct key* arg)
{
struct file_array* arr = &(arg->type.f);
char* content_cpy;
arr->content = realloc(arr->content,
sizeof(struct file_content) * ++(arr->array_size));
if (!(arr->content))
return;
// Make a copy so we can remember it later
if (!(content_cpy = malloc(form->content_size+1)))
return;
memcpy(content_cpy, val, form->content_size+1);
// Store
arr->content[arr->array_size-1].content = content_cpy;
arr->content[arr->array_size-1].content_size = form->content_size;
arr->content[arr->array_size-1].filename = form->filename;
arr->content[arr->array_size-1].filetype = form->filetype;
}

View file

@ -18,23 +18,52 @@
#ifndef KEY_H
#define KEY_H
#include <string.h>
#include <stddef.h>
struct form_props
// Macros which make things a bit easier to read
#define keystr(key) key.type.s
#define keyint(key) key.type.i
#define keyfile(key) key.type.f
#define keypstr(key) key->type.s
#define keypint(key) key->type.i
#define keypfile(key) key->type.f
struct file_content
{
char* filename;
char* content;
size_t content_size;
char* filetype;
size_t data_size;
char* filename;
};
struct file_array
{
struct file_content* content;
size_t array_size;
};
/** Type used for each query */
struct key
{
union u_type
{
int i;
char* s;
struct file_array f;
} type;
int is_set;
};
struct key_value_refs
{
char* key;
void* val;
void (*func)(char*, struct form_props*, void*);
struct key* val;
void (*func)(char*, struct file_content*, struct key*);
};
void key_string(char* val, struct form_props* form, void* arg);
void key_int(char* val, struct form_props* form, void* arg);
void key_string(char* val, struct file_content* props, struct key* arg);
void key_int(char* val, struct file_content* form, struct key* arg);
void key_files(char* val, struct file_content* form, struct key* arg);
#endif // KEY_H

View file

@ -22,7 +22,6 @@
struct local_config
{
int changed;
char* logged_in;
char* theme;
char* background_url;

View file

@ -20,62 +20,75 @@
#include <stdlib.h>
#include "local_config_set.h"
int set_config_str(char** ssn,
#define post_bool_intp(post) (post->is_set ? keypint(post) : 0)
int set_config_str(struct session* ssn,
char** v,
char* cookie_name,
char* value)
struct key* post,
struct key* cookie)
{
if (value && ssn)
if (ssn->post.set.is_set && post->is_set)
{
*ssn = value;
printf("Set-Cookie: %s=%s; HttpOnly; Path=/; SameSite=Strict;\r\n",
cookie_name, value);
cookie_name, keypstr(post));
}
// If ssn isn't passed but value is set, then that means
// something has changed
return value != NULL;
if ((ssn->post.set.is_set && post->is_set) || cookie->is_set)
*v = post->is_set ? keypstr(post) : keypstr(cookie);
return 0;
}
int set_config_int(int* ssn,
int set_config_int(struct session* ssn,
int* v,
char* cookie_name,
int value)
struct key* post,
struct key* cookie)
{
if (ssn)
if (ssn->post.set.is_set)
{
*ssn = value;
printf("Set-Cookie: %s=%ld; HttpOnly; Path=/; Max-Age=31536000; SameSite=Strict;\r\n",
cookie_name, value);
}
printf("Set-Cookie: %s=%d; HttpOnly; Path=/; Max-Age=31536000; SameSite=Strict;\r\n",
cookie_name, post_bool_intp(post));
}
// Checks if boolean option
if (ssn->post.set.is_set || cookie->is_set)
*v = ssn->post.set.is_set ? post_bool_intp(post)
: keypint(cookie);
return 1;
return 0;
}
// Shorthand for the arguments passed into functions below
#define LOAD_CFG_SIM(strcookie, varname) ssn, &(ssn->config.varname), (strcookie), &(ssn->post.varname), &(ssn->cookies.varname)
void load_config(struct session* ssn, mastodont_t* api)
{
if (ssn->post.theme)
{
struct mstdnt_attachment* attachments = NULL;
struct mstdnt_storage* storage = NULL;
if (try_upload_media(&storage, ssn, api, &attachments, NULL) == 0)
{
set_config_str(&(ssn->config.background_url), "background_url", attachments[0].url);
}
// TODO update
/* if (ssn->post.theme) */
/* { */
/* struct mstdnt_attachment* attachments = NULL; */
/* struct mstdnt_storage* storage = NULL; */
/* if (try_upload_media(&storage, ssn, api, &attachments, NULL) == 0) */
/* { */
/* set_config_str(&(ssn->config.background_url), "background_url", attachments[0].url); */
/* } */
if (storage)
cleanup_media_storages(ssn, storage);
}
set_config_str(&(ssn->config.theme), "theme", ssn->post.theme, ssn->cookie.theme);
set_config_int(&(ssn->config.themeclr), "themeclr", ssn->post.themeclr, ssn->cookie.themeclr);
set_config_int(&(ssn->config.jsactions), "jsactions", ssn->cookie.theme, ssn->post.jsactions);
set_config_int(&(ssn->config.jsreply), "jsreply", ssn->cookie.theme, ssn->post.jsreply);
set_config_int(&(ssn->config.jslive), "jslive", ssn->cookie.theme, ssn->post.jslive);
set_config_int(&(ssn->config.js), "js", ssn->cookie.theme, ssn->post.js);
set_config_int(&(ssn->config.stat_attachments), "statattachments", ssn->cookie.theme, ssn->post.stat_attachments);
set_config_int(&(ssn->config.stat_greentexts), "statgreentexts", ssn->cookie.theme, ssn->post.stat_greentexts);
set_config_int(&(ssn->config.stat_dope), "statdope", ssn->cookie.theme, ssn->post.stat_dope);
set_config_int(&(ssn->config.stat_oneclicksoftware), "statoneclicksoftware", ssn->cookie.theme, ssn->post.stat_oneclicksoftware);
set_config_int(&(ssn->config.stat_emoji_likes), "statemojilikes", ssn->cookie.theme, ssn->post.stat_emoji_likes);
set_config_int(&(ssn->config.instance_show_shoutbox), "instanceshowshoutbox", ssn->cookie.theme, ssn->post.instance_show_shoutbox);
set_config_int(&(ssn->config.instance_panel), "instancepanel", ssn->cookie.theme, ssn->post.instance_panel);
/* if (storage) */
/* cleanup_media_storages(ssn, storage); */
/* } */
set_config_str(LOAD_CFG_SIM("theme", theme));
set_config_int(LOAD_CFG_SIM("themeclr", themeclr));
set_config_int(LOAD_CFG_SIM("jsactions", jsactions));
set_config_int(LOAD_CFG_SIM("jsreply", jsreply));
set_config_int(LOAD_CFG_SIM("jslive", jslive));
set_config_int(LOAD_CFG_SIM("js", js));
set_config_int(LOAD_CFG_SIM("statattachments", stat_attachments));
set_config_int(LOAD_CFG_SIM("statgreentexts", stat_greentexts));
set_config_int(LOAD_CFG_SIM("statdope", stat_dope));
set_config_int(LOAD_CFG_SIM("statoneclicksoftware", stat_oneclicksoftware));
set_config_int(LOAD_CFG_SIM("statemojilikes", stat_emoji_likes));
set_config_int(LOAD_CFG_SIM("instanceshowshoutbox", instance_show_shoutbox));
set_config_int(LOAD_CFG_SIM("instancepanel", instance_panel));
}

View file

@ -22,16 +22,20 @@
#include "local_config.h"
#include "session.h"
#include "attachments.h"
#include "key.h"
int set_config_str(char** ssn,
int set_config_str(struct session* ssn,
char** v,
char* cookie_name,
char* value);
struct key* post,
struct key* cookie);
int set_config_int(int* ssn,
int set_config_int(struct session* ssn,
int* v,
char* cookie_name,
int value);
struct key* post,
struct key* cookie);
void load_config(struct session* ssn, mastodont_t* api);
void read_config(struct session* ssn);
#endif // LOCAL_CONFIG_SET_H

View file

@ -55,15 +55,15 @@ void content_login_oauth(struct session* ssn, mastodont_t* api, char** data)
config_host_url_insecure ? "" : "s",
config_host_url ? config_host_url : redirect_url );
if (ssn->query.code)
if (keystr(ssn->query.code))
{
struct mstdnt_args args_token = {
.grant_type = "authorization_code",
.client_id = ssn->cookies.client_id,
.client_secret = ssn->cookies.client_secret,
.client_id = keystr(ssn->cookies.client_id),
.client_secret = keystr(ssn->cookies.client_secret),
.redirect_uri = urlify_redirect_url,
.scope = LOGIN_SCOPE,
.code = ssn->query.code,
.code = keystr(ssn->query.code),
};
if (mastodont_obtain_oauth_token(api, &args_token, &oauth_storage,
@ -72,16 +72,16 @@ void content_login_oauth(struct session* ssn, mastodont_t* api, char** data)
apply_access_token(token.access_token);
}
}
else if (ssn->post.instance)
else if (keystr(ssn->post.instance))
{
decode_url = curl_easy_unescape(api->curl, ssn->post.instance, 0, NULL);
decode_url = curl_easy_unescape(api->curl, keystr(ssn->post.instance), 0, NULL);
api->url = decode_url;
struct mstdnt_args args_app = {
.client_name = "Treebird",
.redirect_uris = urlify_redirect_url,
.scopes = "read+write+follow+push",
.website = ssn->post.instance
.website = keystr(ssn->post.instance)
};
if (mastodont_register_app(api, &args_app, &storage, &app) == 0)
@ -121,7 +121,7 @@ void content_login(struct session* ssn, mastodont_t* api, char** data)
char* error = NULL;
char* page;
if (ssn->post.username && ssn->post.password)
if (keystr(ssn->post.username) && keystr(ssn->post.password))
{
// Getting the client id/secret
struct mstdnt_args args_app = {
@ -132,7 +132,7 @@ void content_login(struct session* ssn, mastodont_t* api, char** data)
};
// Check if the username contains an @ symbol
char* address = strstr(ssn->post.username, "%40");
char* address = strstr(keystr(ssn->post.username), "%40");
// If it fails, we need to restore
char* orig_url = api->url;
char* url_link = NULL;
@ -161,8 +161,8 @@ void content_login(struct session* ssn, mastodont_t* api, char** data)
.redirect_uri = NULL,
.scope = LOGIN_SCOPE,
.code = NULL,
.username = ssn->post.username,
.password = ssn->post.password
.username = keystr(ssn->post.username),
.password = keystr(ssn->post.password)
};
if (mastodont_obtain_oauth_token(api, &args_token, &oauth_store,

View file

@ -36,6 +36,7 @@
#include "notifications.h"
#include "test.h"
#include "search.h"
#include "local_config_set.h"
int main(void)
{
@ -50,7 +51,6 @@ int main(void)
// Default config
struct session ssn = {
.config = {
.changed = 0,
.theme = "treebird20",
.themeclr = 0,
.jsactions = 1,
@ -66,23 +66,26 @@ int main(void)
.instance_show_shoutbox = 1,
.instance_panel = 1,
},
.cookies = { 0 },
.post = { 0 },
.query = { 0 }
.cookies = {{}},
.post = {{}},
.query = {{}}
};
// Load cookies
char* cookies_str = read_cookies_env(&(ssn.cookies));
char* post_str = read_post_data(&(ssn.post));
char* get_str = read_query_data(&(ssn.query));
char* get_str = read_get_data(&(ssn.query));
mastodont_t api;
if (ssn.cookies.instance_url)
api.url = ssn.cookies.instance_url;
if (keystr(ssn.cookies.instance_url))
api.url = keystr(ssn.cookies.instance_url);
else
api.url = config_instance_url;
mastodont_init(&api, MSTDNT_FLAG_NO_URI_SANITIZE | config_library_flags);
api.token = ssn.cookies.access_token; // Load token now
api.token = keystr(ssn.cookies.access_token); // Load token now
// Read config options
load_config(&ssn, &api);
/*******************
* Path handling *
@ -129,7 +132,7 @@ int main(void)
if (post_str) free(post_str);
if (get_str) free(get_str);
mastodont_free(&api);
free_files(&(ssn.post.files));
free_files(&(keyfile(ssn.post.files)));
++run_count;
}

View file

@ -183,7 +183,7 @@ void content_notifications(struct session* ssn, mastodont_t* api, char** data)
char* start_id;
char* navigation_box = NULL;
if (ssn->cookies.logged_in)
if (keystr(ssn->cookies.logged_in))
{
struct mstdnt_get_notifications_args args = {
.exclude_types = 0,
@ -191,8 +191,8 @@ void content_notifications(struct session* ssn, mastodont_t* api, char** data)
.exclude_visibilities = 0,
.include_types = 0,
.with_muted = 1,
.max_id = ssn->post.max_id,
.min_id = ssn->post.min_id,
.max_id = keystr(ssn->post.max_id),
.min_id = keystr(ssn->post.min_id),
.since_id = NULL,
.offset = 0,
.limit = 20,
@ -201,13 +201,13 @@ void content_notifications(struct session* ssn, mastodont_t* api, char** data)
if (mastodont_get_notifications(api, &args, &storage, &notifs, &notifs_len) == 0)
{
notif_html = construct_notifications(ssn, api, notifs, notifs_len, NULL);
start_id = ssn->post.start_id ? ssn->post.start_id : notifs[0].id;
start_id = keystr(ssn->post.start_id) ? keystr(ssn->post.start_id) : notifs[0].id;
navigation_box = construct_navigation_box(start_id,
notifs[0].id,
notifs[notifs_len-1].id,
NULL);
mstdnt_cleanup_notifications(notifs, notifs_len);
}
mstdnt_cleanup_notifications(notifs, notifs_len);}
else
notif_html = construct_error(storage.error, E_NOTICE, 1, NULL);

View file

@ -24,7 +24,7 @@
#include "query.h"
#include "mime.h"
char* read_query_data(struct get_values* query)
char* read_get_data(struct get_values* query)
{
struct http_query_info info;
char* query_string = getenv("QUERY_STRING");
@ -57,7 +57,12 @@ char* read_query_data(struct get_values* query)
if (!(info.key && info.val)) break;
for (size_t i = 0; i < (sizeof(refs)/sizeof(refs[0])); ++i)
if (strcmp(info.key, refs[i].key) == 0)
{
refs[i].func(info.val, NULL, refs[i].val);
refs[i].val->is_set = 1;
}
else
refs[i].val->is_set = 0;
}
while (g_query_read);
}
@ -65,41 +70,22 @@ char* read_query_data(struct get_values* query)
return get_query;
}
void key_files(char* val, struct form_props* form, void* arg)
{
struct file_array* arr = arg;
char* ptr;
arr->content = realloc(arr->content,
sizeof(struct file_content) * ++(arr->array_size));
if (!(arr->content))
return;
ptr = malloc(form->data_size+1);
if (!ptr)
return;
memcpy(ptr, val, form->data_size+1);
// Store
arr->content[arr->array_size-1].content = ptr;
arr->content[arr->array_size-1].content_size = form->data_size;
arr->content[arr->array_size-1].filename = form->filename;
arr->content[arr->array_size-1].filetype = form->filetype;
}
char* read_post_data(struct query_values* post)
char* read_post_data(struct post_values* post)
{
ptrdiff_t begin_curr_size;
struct http_query_info query_info;
struct http_form_info form_info;
struct form_props form_props;
struct file_content form_props;
char* request_method = getenv("REQUEST_METHOD");
char* content_length = getenv("CONTENT_LENGTH");
char* post_query = NULL, *p_query_read;
// BEGIN Query references
struct key_value_refs refs[] = {
{ "set", &(post->set), key_int },
{ "content", &(post->content), key_string },
{ "itype", &(post->itype), key_string },
{ "id", &(post->id), key_string },
@ -152,7 +138,6 @@ char* read_post_data(struct query_values* post)
p_query_read = post_query;
do
{
if (mime_mem)
{
// Get size from here to the end
@ -164,21 +149,27 @@ char* read_post_data(struct query_values* post)
len - begin_curr_size);
form_props.filename = form_info.filename;
form_props.filetype = form_info.content_type;
form_props.data_size = form_info.value_size;
form_props.content_size = form_info.value_size;
if (!p_query_read) break;
for (size_t i = 0; i < (sizeof(refs)/sizeof(refs[0])); ++i)
if (strcmp(form_info.name, refs[i].key) == 0)
{
refs[i].func(form_info.value, &form_props, refs[i].val);
refs[i].val->is_set = 1;
}
}
else {
else
{
// Mime value not set
p_query_read = parse_query(p_query_read, &query_info);
if (!(query_info.key && query_info.val)) break;
for (size_t i = 0; i < (sizeof(refs)/sizeof(refs[0])); ++i)
if (strcmp(query_info.key, refs[i].key) == 0)
{
refs[i].func(query_info.val, NULL, refs[i].val);
refs[i].val->is_set = 1;
}
}
}
while (p_query_read);
if (mime_mem) free(mime_mem);

View file

@ -28,67 +28,52 @@ struct http_query_info
char* val;
};
struct file_content
{
char* content;
size_t content_size;
char* filetype;
char* filename;
};
struct file_array
{
struct file_content* content;
size_t array_size;
};
struct query_values
struct post_values
{
// Config
char* theme;
int themeclr;
int jsactions;
int jsreply;
int jslive;
int js;
int stat_attachments;
int stat_greentexts;
int stat_dope;
int stat_oneclicksoftware;
int stat_emoji_likes;
int stat_hide_muted;
int instance_show_shoutbox;
int instance_panel;
struct key theme; // String
struct key themeclr; // Int
struct key jsactions; // Int
struct key jsreply; // Int
struct key jslive; // Int
struct key js; // Int
struct key stat_attachments; // Int
struct key stat_greentexts; // Int
struct key stat_dope; // Int
struct key stat_oneclicksoftware; // Int
struct key stat_emoji_likes; // Int
struct key stat_hide_muted; // Int
struct key instance_show_shoutbox; // Int
struct key instance_panel; // Int
struct key set; // Int
char* content;
char* itype;
char* id;
char* username;
char* password;
char* replyid;
char* visibility;
char* instance;
int emojoindex;
struct key content; // String
struct key itype; // String
struct key id; // String
struct key username; // String
struct key password; // String
struct key replyid; // String
struct key visibility; // String
struct key instance; // String
struct key emojoindex; // Int
// Navigation
char* min_id;
char* max_id;
char* start_id;
struct key min_id; // String
struct key max_id; // String
struct key start_id; // String
struct file_array files;
struct key files; // Files
};
struct get_values
{
char* offset;
char* query;
char* code;
struct key offset; // String
struct key query; // String
struct key code; // String
};
void key_files(char* val, struct form_props* form, void* arg);
char* read_query_data(struct get_values* query);
char* read_post_data(struct query_values* post);
char* read_get_data(struct get_values* query);
char* read_post_data(struct post_values* post);
/* A stupidly quick query parser */
char* parse_query(char* begin, struct http_query_info* info);
char* try_handle_post(void (*call)(struct http_query_info*, void*), void* arg);

View file

@ -36,15 +36,15 @@ void search_page(struct session* ssn, mastodont_t* api, enum search_tab tab, cha
char* out_data;
easprintf(&out_data, data_search_html,
config_url_prefix,
ssn->query.query,
keystr(ssn->query.query),
MAKE_FOCUSED_IF(tab, SEARCH_STATUSES),
"Statuses",
config_url_prefix,
ssn->query.query,
keystr(ssn->query.query),
MAKE_FOCUSED_IF(tab, SEARCH_ACCOUNTS),
"Accounts",
config_url_prefix,
ssn->query.query,
keystr(ssn->query.query),
MAKE_FOCUSED_IF(tab, SEARCH_HASHTAGS),
"Hashtags",
content);
@ -81,13 +81,13 @@ void content_search_statuses(struct session* ssn, mastodont_t* api, char** data)
struct mstdnt_search_results results = { 0 };
if (mastodont_search(api,
ssn->query.query,
keystr(ssn->query.query),
&storage,
&args,
&results) == 0)
{
struct construct_statuses_args statuses_args = {
.highlight_word = ssn->query.query,
.highlight_word = keystr(ssn->query.query),
};
statuses_html = construct_statuses(ssn, api, results.statuses, results.statuses_len, &statuses_args, NULL);
if (!statuses_html)
@ -120,7 +120,7 @@ void content_search_accounts(struct session* ssn, mastodont_t* api, char** data)
struct mstdnt_search_results results = { 0 };
if (mastodont_search(api,
ssn->query.query,
keystr(ssn->query.query),
&storage,
&args,
&results) == 0)
@ -159,7 +159,7 @@ void content_search_hashtags(struct session* ssn, mastodont_t* api, char** data)
struct mstdnt_search_results results = { 0 };
if (mastodont_search(api,
ssn->query.query,
keystr(ssn->query.query),
&storage,
&args,
&results) == 0)

View file

@ -24,7 +24,7 @@
struct session
{
struct query_values post;
struct post_values post;
struct get_values query;
struct cookie_values cookies;
struct local_config config;

View file

@ -56,7 +56,7 @@ struct status_args
int try_post_status(struct session* ssn, mastodont_t* api)
{
if (!(ssn->post.content)) return 1;
if (!(keystr(ssn->post.content))) return 1;
struct mstdnt_storage storage = { 0 }, *att_storage = NULL;
@ -73,17 +73,17 @@ int try_post_status(struct session* ssn, mastodont_t* api)
.content_type = "text/plain",
.expires_in = 0,
.in_reply_to_conversation_id = NULL,
.in_reply_to_id = ssn->post.replyid,
.in_reply_to_id = keystr(ssn->post.replyid),
.language = NULL,
.media_ids = media_ids,
.media_ids_len = media_ids ? ssn->post.files.array_size : 0,
.media_ids_len = media_ids ? keyfile(ssn->post.files).array_size : 0,
.poll = NULL,
.preview = 0,
.scheduled_at = NULL,
.sensitive = 0,
.spoiler_text = NULL,
.status = ssn->post.content,
.visibility = ssn->post.visibility,
.status = keystr(ssn->post.content),
.visibility = keystr(ssn->post.visibility),
};
mastodont_create_status(api, &args, &storage);
@ -130,31 +130,31 @@ void content_status_react(struct session* ssn, mastodont_t* api, char** data)
int try_interact_status(struct session* ssn, mastodont_t* api, char* id)
{
struct mstdnt_storage storage = { 0 };
if (!(ssn->post.itype && id)) return 1;
if (!(keystr(ssn->post.itype) && id)) return 1;
// Pretty up the type
if (strcmp(ssn->post.itype, "like") == 0 ||
strcmp(ssn->post.itype, "likeboost") == 0)
if (strcmp(keystr(ssn->post.itype), "like") == 0 ||
strcmp(keystr(ssn->post.itype), "likeboost") == 0)
mastodont_favourite_status(api, id, &storage, NULL);
// Not else if because possibly a like-boost
if (strcmp(ssn->post.itype, "repeat") == 0 ||
strcmp(ssn->post.itype, "likeboost") == 0)
if (strcmp(keystr(ssn->post.itype), "repeat") == 0 ||
strcmp(keystr(ssn->post.itype), "likeboost") == 0)
mastodont_reblog_status(api, id, &storage, NULL);
else if (strcmp(ssn->post.itype, "bookmark") == 0)
else if (strcmp(keystr(ssn->post.itype), "bookmark") == 0)
mastodont_bookmark_status(api, id, &storage, NULL);
else if (strcmp(ssn->post.itype, "pin") == 0)
else if (strcmp(keystr(ssn->post.itype), "pin") == 0)
mastodont_pin_status(api, id, &storage, NULL);
else if (strcmp(ssn->post.itype, "mute") == 0)
else if (strcmp(keystr(ssn->post.itype), "mute") == 0)
mastodont_mute_conversation(api, id, &storage, NULL);
else if (strcmp(ssn->post.itype, "unlike") == 0)
else if (strcmp(keystr(ssn->post.itype), "unlike") == 0)
mastodont_unfavourite_status(api, id, &storage, NULL);
else if (strcmp(ssn->post.itype, "unrepeat") == 0)
else if (strcmp(keystr(ssn->post.itype), "unrepeat") == 0)
mastodont_unreblog_status(api, id, &storage, NULL);
else if (strcmp(ssn->post.itype, "unbookmark") == 0)
else if (strcmp(keystr(ssn->post.itype), "unbookmark") == 0)
mastodont_unbookmark_status(api, id, &storage, NULL);
else if (strcmp(ssn->post.itype, "unpin") == 0)
else if (strcmp(keystr(ssn->post.itype), "unpin") == 0)
mastodont_unpin_status(api, id, &storage, NULL);
else if (strcmp(ssn->post.itype, "unmute") == 0)
else if (strcmp(keystr(ssn->post.itype), "unmute") == 0)
mastodont_unmute_conversation(api, id, &storage, NULL);
mastodont_storage_cleanup(&storage);
@ -412,7 +412,7 @@ char* construct_status(struct session* ssn,
// Emojo picker
if ((flags & STATUS_EMOJI_PICKER) == STATUS_EMOJI_PICKER)
{
emoji_picker_html = construct_emoji_picker(status->id, ssn->post.emojoindex, NULL);
emoji_picker_html = construct_emoji_picker(status->id, keyint(ssn->post.emojoindex), NULL);
}
// If focused, show status interactions

View file

@ -48,9 +48,9 @@ void tl_home(struct session* ssn, mastodont_t* api, int local)
struct mstdnt_timeline_args args = {
.local = local,
.max_id = ssn->post.max_id,
.max_id = keystr(ssn->post.max_id),
.since_id = NULL,
.min_id = ssn->post.min_id,
.min_id = keystr(ssn->post.min_id),
.limit = 20
};
@ -72,7 +72,7 @@ void tl_home(struct session* ssn, mastodont_t* api, int local)
if (statuses)
{
// If not set, set it
start_id = ssn->post.start_id ? ssn->post.start_id : statuses[0].id;
start_id = keystr(ssn->post.start_id) ? keystr(ssn->post.start_id) : statuses[0].id;
navigation_box = construct_navigation_box(start_id,
statuses[0].id,
statuses[status_count-1].id,
@ -115,9 +115,9 @@ void tl_direct(struct session* ssn, mastodont_t* api)
struct mstdnt_timeline_args args = {
.with_muted = 0,
.max_id = ssn->post.max_id,
.max_id = keystr(ssn->post.max_id),
.since_id = NULL,
.min_id = ssn->post.min_id,
.min_id = keystr(ssn->post.min_id),
.limit = 20,
};
@ -136,7 +136,7 @@ void tl_direct(struct session* ssn, mastodont_t* api)
if (statuses)
{
// If not set, set it
start_id = ssn->post.start_id ? ssn->post.start_id : statuses[0].id;
start_id = keystr(ssn->post.start_id) ? keystr(ssn->post.start_id) : statuses[0].id;
navigation_box = construct_navigation_box(start_id,
statuses[0].id,
statuses[status_count-1].id,
@ -183,9 +183,9 @@ void tl_public(struct session* ssn, mastodont_t* api, int local, enum base_categ
.local = local,
.remote = 0,
.only_media = 0,
.max_id = ssn->post.max_id,
.max_id = keystr(ssn->post.max_id),
.since_id = NULL,
.min_id = ssn->post.min_id,
.min_id = keystr(ssn->post.min_id),
.limit = 20
};
@ -207,7 +207,7 @@ void tl_public(struct session* ssn, mastodont_t* api, int local, enum base_categ
if (statuses)
{
// If not set, set it
start_id = ssn->post.start_id ? ssn->post.start_id : statuses[0].id;
start_id = keystr(ssn->post.start_id) ? keystr(ssn->post.start_id) : statuses[0].id;
navigation_box = construct_navigation_box(start_id,
statuses[0].id,
statuses[status_count-1].id,
@ -246,9 +246,9 @@ void tl_list(struct session* ssn, mastodont_t* api, char* list_id)
char* output = NULL;
struct mstdnt_timeline_args args = {
.max_id = ssn->post.max_id,
.max_id = keystr(ssn->post.max_id),
.since_id = NULL,
.min_id = ssn->post.min_id,
.min_id = keystr(ssn->post.min_id),
.limit = 20,
};
@ -270,7 +270,7 @@ void tl_list(struct session* ssn, mastodont_t* api, char* list_id)
if (statuses)
{
// If not set, set it
start_id = ssn->post.start_id ? ssn->post.start_id : statuses[0].id;
start_id = keystr(ssn->post.start_id) ? keystr(ssn->post.start_id) : statuses[0].id;
navigation_box = construct_navigation_box(start_id,
statuses[0].id,
statuses[status_count-1].id,
@ -310,9 +310,9 @@ void tl_tag(struct session* ssn, mastodont_t* api, char* tag_id)
char* output = NULL;
struct mstdnt_timeline_args args = {
.max_id = ssn->post.max_id,
.max_id = keystr(ssn->post.max_id),
.since_id = NULL,
.min_id = ssn->post.min_id,
.min_id = keystr(ssn->post.min_id),
.limit = 20,
};
@ -329,7 +329,7 @@ void tl_tag(struct session* ssn, mastodont_t* api, char* tag_id)
if (statuses)
{
// If not set, set it
start_id = ssn->post.start_id ? ssn->post.start_id : statuses[0].id;
start_id = keystr(ssn->post.start_id) ? keystr(ssn->post.start_id) : statuses[0].id;
navigation_box = construct_navigation_box(start_id,
statuses[0].id,
statuses[status_count-1].id,
@ -361,7 +361,7 @@ void tl_tag(struct session* ssn, mastodont_t* api, char* tag_id)
void content_tl_home(struct session* ssn, mastodont_t* api, char** data)
{
(void)data;
if (ssn->cookies.logged_in)
if (keystr(ssn->cookies.logged_in))
tl_home(ssn, api, 0);
else
content_tl_federated(ssn, api, data);

View file

@ -1,6 +1,7 @@
<div class="simple-page">
<form action="appearance" method="post" enctype="multipart/form-data">
<!-- Appearance -->
<!-- Lets server know we sent it -->
<input type="hidden" name="set" value="1">
<h1>Appearance</h1>
<h3>Theme variant</h3>
<ul>

View file

@ -1,5 +1,7 @@
<div class="simple-page">
<form action="general" method="post">
<!-- Lets server know we sent it -->
<input type="hidden" name="set" value="1">
<h1>General</h1>
<input type="submit" value="Save">
<h3>JavaScript</h3>