From 064097c069ff450575a519f0187077b5fc2a44fd Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Fri, 1 Apr 2022 14:56:30 +0000 Subject: [PATCH] Config handling FossilOrigin-Name: 65d5f9e7c528992ed6d5dff66a1f8945d6a4fbc37aed5ee3e4999c469815ce61 --- src/local_config.h | 5 +++ src/local_config_set.c | 69 +++++++++++++++++++++++++++++++++++ src/local_config_set.h | 34 +++++++++++++++++ src/page_config.c | 13 +------ src/query.c | 4 ++ src/query.h | 6 +++ static/config_appearance.html | 6 +-- static/config_general.html | 8 ++-- static/status.html | 8 ++-- 9 files changed, 130 insertions(+), 23 deletions(-) create mode 100644 src/local_config_set.c create mode 100644 src/local_config_set.h diff --git a/src/local_config.h b/src/local_config.h index 61b95b0..2af328d 100644 --- a/src/local_config.h +++ b/src/local_config.h @@ -18,11 +18,16 @@ #ifndef LOCAL_CONFIG_H #define LOCAL_CONFIG_H +#include "query.h" struct local_config { int changed; char* theme; + int themeclr; + int jsactions; + int jsreply; + int jslive; }; #endif // LOCAL_CONFIG_H diff --git a/src/local_config_set.c b/src/local_config_set.c new file mode 100644 index 0000000..254645a --- /dev/null +++ b/src/local_config_set.c @@ -0,0 +1,69 @@ +/* + * Treebird - Lightweight frontend for Pleroma + * Copyright (C) 2022 Nekobit + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include +#include "local_config_set.h" + +int set_config_str(char** ssn, + char* cookie_name, + char* value) +{ + if (value && ssn) + { + *ssn = value; + printf("Set-Cookie: %s=%s; HttpOnly; Path=/; SameSite=Strict;\r\n", + cookie_name, value); + } + + // If ssn isn't passed but value is set, then that means + // something has changed + return value != NULL; +} + +int set_config_int(int* ssn, + char* cookie_name, + char* value) +{ + if (!value) return 0; + char* err = NULL; + long str_l = strtol(value, &err, 0); + + // Not a number + if (err == value) + return 0; + + if (ssn) + { + *ssn = str_l; + printf("Set-Cookie: %s=%ld; HttpOnly; Path=/; SameSite=Strict;\r\n", + cookie_name, str_l); + } + + return 1; +} + +void load_config(struct session* ssn) +{ + set_config_str(&(ssn->config.theme), "theme", ssn->post.theme); + set_config_int(&(ssn->config.themeclr), "themeclr", ssn->post.themeclr); + + set_config_int(&(ssn->config.jsactions), "jsactions", ssn->post.jsactions); + set_config_int(&(ssn->config.jsreply), "jsreply", ssn->post.jsreply); + set_config_int(&(ssn->config.jslive), "jslive", ssn->post.jslive); +} diff --git a/src/local_config_set.h b/src/local_config_set.h new file mode 100644 index 0000000..554446a --- /dev/null +++ b/src/local_config_set.h @@ -0,0 +1,34 @@ +/* + * Treebird - Lightweight frontend for Pleroma + * Copyright (C) 2022 Nekobit + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef LOCAL_CONFIG_SET_H +#define LOCAL_CONFIG_SET_H +#include "local_config.h" +#include "session.h" + +int set_config_str(char** ssn, + char* cookie_name, + char* value); + +int set_config_int(int* ssn, + char* cookie_name, + char* value); + +void load_config(struct session* ssn); + +#endif // LOCAL_CONFIG_SET_H diff --git a/src/page_config.c b/src/page_config.c index 01ae4e3..aa3aff2 100644 --- a/src/page_config.c +++ b/src/page_config.c @@ -26,7 +26,7 @@ #include "page_config.h" #include "query.h" #include "cookie.h" -#include "local_config.h" +#include "local_config_set.h" #include "string_helpers.h" #include "l10n.h" @@ -43,17 +43,6 @@ enum config_category CONFIG_CAT_ACCOUNT }; -static void load_config(struct session* ssn) -{ - if (ssn->post.theme) - { - ssn->config.theme = ssn->post.theme; - printf("Set-Cookie: %s=%s; HttpOnly; SameSite=Strict;", - "theme", ssn->post.theme); - ssn->config.changed = 1; - } -} - static char* construct_config_sidebar(enum config_category cat, size_t* size) { char* sidebar_html; diff --git a/src/query.c b/src/query.c index e2b8182..12a9a17 100644 --- a/src/query.c +++ b/src/query.c @@ -77,6 +77,10 @@ char* read_post_data(struct query_values* post) { "itype", &(post->itype) }, { "id", &(post->id) }, { "theme", &(post->theme) }, + { "themeclr", &(post->themeclr) }, + { "jsactions", &(post->jsactions) }, + { "jsreply", &(post->jsreply) }, + { "jslive", &(post->jslive) }, { "username", &(post->username) }, { "password", &(post->password) }, { "replyid", &(post->replyid) }, diff --git a/src/query.h b/src/query.h index 6cac334..39f8b87 100644 --- a/src/query.h +++ b/src/query.h @@ -29,7 +29,13 @@ struct http_query_info struct query_values { + // Config char* theme; + char* themeclr; + char* jsactions; + char* jsreply; + char* jslive; + char* content; char* itype; char* id; diff --git a/static/config_appearance.html b/static/config_appearance.html index 0508638..97dca06 100644 --- a/static/config_appearance.html +++ b/static/config_appearance.html @@ -1,5 +1,5 @@
-
+

Appearance

Theme variant

@@ -16,11 +16,11 @@

Color Scheme

  • - +
  • - +
diff --git a/static/config_general.html b/static/config_general.html index 52515a3..cfaba7d 100644 --- a/static/config_general.html +++ b/static/config_general.html @@ -1,18 +1,18 @@
- +

General

JavaScript

  • - +
  • - +
  • - +
diff --git a/static/status.html b/static/status.html index 02fc001..5bfb40c 100644 --- a/static/status.html +++ b/static/status.html @@ -35,7 +35,7 @@ @@ -45,7 +45,7 @@ @@ -55,7 +55,7 @@ @@ -63,7 +63,7 @@