Config stuff (broken)
FossilOrigin-Name: 3920eeca88b0e914fed7247bc09e07e10836138fd481e9a5271172fef64112fc
This commit is contained in:
parent
2b427f1219
commit
b106d03e73
12 changed files with 102 additions and 67 deletions
|
@ -61,6 +61,14 @@ char* read_cookies_env(struct cookie_values* cookies)
|
|||
{ "jsactions", &(cookies->jsactions), key_int },
|
||||
{ "jsreply", &(cookies->jsreply), key_int },
|
||||
{ "jslive", &(cookies->jslive), key_int },
|
||||
{ "js", &(cookies->js), key_int },
|
||||
{ "statattachments", &(cookies->stat_attachments), key_int },
|
||||
{ "statgreentexts", &(cookies->stat_greentexts), key_int },
|
||||
{ "statdope", &(cookies->stat_dope), key_int },
|
||||
{ "statoneclicksoftware", &(cookies->stat_oneclicksoftware), key_int },
|
||||
{ "statemojilikes", &(cookies->stat_emoji_likes), key_int },
|
||||
{ "instanceshowshoutbox", &(cookies->instance_show_shoutbox), key_int },
|
||||
{ "instancepanel", &(cookies->instance_panel), key_int },
|
||||
};
|
||||
|
||||
do
|
||||
|
|
|
@ -33,6 +33,14 @@ struct cookie_values
|
|||
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 http_cookie_info
|
||||
|
|
|
@ -30,6 +30,15 @@ struct local_config
|
|||
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;
|
||||
};
|
||||
|
||||
#endif // LOCAL_CONFIG_H
|
||||
|
|
|
@ -38,21 +38,13 @@ int set_config_str(char** ssn,
|
|||
|
||||
int set_config_int(int* ssn,
|
||||
char* cookie_name,
|
||||
char* value)
|
||||
int 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;
|
||||
*ssn = value;
|
||||
printf("Set-Cookie: %s=%ld; HttpOnly; Path=/; Max-Age=31536000; SameSite=Strict;\r\n",
|
||||
cookie_name, str_l);
|
||||
cookie_name, value);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -72,40 +64,18 @@ void load_config(struct session* ssn, mastodont_t* api)
|
|||
if (storage)
|
||||
cleanup_media_storages(ssn, storage);
|
||||
}
|
||||
set_config_str(&(ssn->config.theme), "theme", ssn->post.theme);
|
||||
set_config_int(&(ssn->config.themeclr), "themeclr", ssn->post.themeclr);
|
||||
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->post.jsactions);
|
||||
set_config_int(&(ssn->config.jsreply), "jsreply", ssn->post.jsreply);
|
||||
set_config_int(&(ssn->config.jslive), "jslive", ssn->post.jslive);
|
||||
}
|
||||
|
||||
#define SET_COOKIE_CONFIG(post, cookie, config) do{ \
|
||||
if (cookie && !post) \
|
||||
config = cookie; \
|
||||
} while(0);
|
||||
|
||||
void read_config(struct session* ssn)
|
||||
{
|
||||
SET_COOKIE_CONFIG(ssn->post.theme,
|
||||
ssn->cookies.theme,
|
||||
ssn->config.theme);
|
||||
SET_COOKIE_CONFIG(ssn->post.themeclr,
|
||||
ssn->cookies.themeclr,
|
||||
ssn->config.themeclr);
|
||||
SET_COOKIE_CONFIG(ssn->post.jsactions,
|
||||
ssn->cookies.jsactions,
|
||||
ssn->config.jsactions);
|
||||
SET_COOKIE_CONFIG(ssn->post.jsreply,
|
||||
ssn->cookies.jsreply,
|
||||
ssn->config.jsreply);
|
||||
SET_COOKIE_CONFIG(ssn->post.jslive,
|
||||
ssn->cookies.jslive,
|
||||
ssn->config.jslive);
|
||||
SET_COOKIE_CONFIG(0,
|
||||
ssn->cookies.logged_in,
|
||||
ssn->config.logged_in);
|
||||
SET_COOKIE_CONFIG((ssn->post.files.content && ssn->post.files.content[0].content),
|
||||
ssn->cookies.background_url,
|
||||
ssn->config.background_url);
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ int set_config_str(char** ssn,
|
|||
|
||||
int set_config_int(int* ssn,
|
||||
char* cookie_name,
|
||||
char* value);
|
||||
int value);
|
||||
|
||||
void load_config(struct session* ssn, mastodont_t* api);
|
||||
void read_config(struct session* ssn);
|
||||
|
|
16
src/main.c
16
src/main.c
|
@ -47,14 +47,24 @@ int main(void)
|
|||
// API
|
||||
while (FCGI_Accept() >= 0)
|
||||
{
|
||||
// Default config
|
||||
struct session ssn = {
|
||||
.config = {
|
||||
.changed = 0,
|
||||
.theme = "treebird20",
|
||||
.themeclr = 0,
|
||||
.jsactions = 0,
|
||||
.jsreply = 0,
|
||||
.jslive = 0
|
||||
.jsactions = 1,
|
||||
.jsreply = 1,
|
||||
.jslive = 0,
|
||||
.js = 1,
|
||||
.stat_attachments = 1,
|
||||
.stat_greentexts = 1,
|
||||
.stat_dope = 1,
|
||||
.stat_oneclicksoftware = 1,
|
||||
.stat_emoji_likes = 0,
|
||||
.stat_hide_muted = 0,
|
||||
.instance_show_shoutbox = 1,
|
||||
.instance_panel = 1,
|
||||
},
|
||||
.cookies = { 0 },
|
||||
.post = { 0 },
|
||||
|
|
|
@ -102,7 +102,8 @@ char* construct_notification_compact(struct session* ssn,
|
|||
notif->status->replies_count,
|
||||
notif->status->reblogs_count,
|
||||
notif->status->favourites_count);
|
||||
status_format = reformat_status(notif->status->content,
|
||||
status_format = reformat_status(ssn,
|
||||
notif->status->content,
|
||||
notif->status->emojis,
|
||||
notif->status->emojis_len);
|
||||
}
|
||||
|
|
17
src/query.c
17
src/query.c
|
@ -104,10 +104,10 @@ char* read_post_data(struct query_values* post)
|
|||
{ "itype", &(post->itype), key_string },
|
||||
{ "id", &(post->id), key_string },
|
||||
{ "theme", &(post->theme), key_string },
|
||||
{ "themeclr", &(post->themeclr), key_string },
|
||||
{ "jsactions", &(post->jsactions), key_string },
|
||||
{ "jsreply", &(post->jsreply), key_string },
|
||||
{ "jslive", &(post->jslive), key_string },
|
||||
{ "themeclr", &(post->themeclr), key_int },
|
||||
{ "jsactions", &(post->jsactions), key_int },
|
||||
{ "jsreply", &(post->jsreply), key_int },
|
||||
{ "jslive", &(post->jslive), key_int },
|
||||
{ "username", &(post->username), key_string },
|
||||
{ "password", &(post->password), key_string },
|
||||
{ "replyid", &(post->replyid), key_string },
|
||||
|
@ -117,6 +117,15 @@ char* read_post_data(struct query_values* post)
|
|||
{ "instance", &(post->instance), key_string },
|
||||
{ "visibility", &(post->visibility), key_string },
|
||||
{ "emojoindex", &(post->emojoindex), key_int },
|
||||
{ "js", &(post->js), key_int },
|
||||
{ "statattachments", &(post->stat_attachments), key_int },
|
||||
{ "statgreentexts", &(post->stat_greentexts), key_int },
|
||||
{ "statdope", &(post->stat_dope), key_int },
|
||||
{ "statoneclicksoftware", &(post->stat_oneclicksoftware), key_int },
|
||||
{ "statemojolikes", &(post->stat_emoji_likes), key_int },
|
||||
{ "stathidemuted", &(post->stat_hide_muted), key_int },
|
||||
{ "instanceshowshoutbox", &(post->instance_show_shoutbox), key_int },
|
||||
{ "instancepanel", &(post->instance_panel), key_int },
|
||||
{ "file", &(post->files), key_files }
|
||||
};
|
||||
// END Query references
|
||||
|
|
17
src/query.h
17
src/query.h
|
@ -46,10 +46,19 @@ struct query_values
|
|||
{
|
||||
// Config
|
||||
char* theme;
|
||||
char* themeclr;
|
||||
char* jsactions;
|
||||
char* jsreply;
|
||||
char* jslive;
|
||||
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;
|
||||
|
||||
char* content;
|
||||
char* itype;
|
||||
|
|
16
src/status.c
16
src/status.c
|
@ -301,11 +301,18 @@ char* construct_in_reply_to(struct mstdnt_status* status,
|
|||
#define REGEX_GREENTEXT "((?:^|<br/?>|\\s)>.*?)(?:<br/?>|$)"
|
||||
#define REGEX_GREENTEXT_LEN 6
|
||||
|
||||
char* reformat_status(char* content, struct mstdnt_emoji* emos, size_t emos_len)
|
||||
char* reformat_status(struct session* ssn,
|
||||
char* content,
|
||||
struct mstdnt_emoji* emos,
|
||||
size_t emos_len)
|
||||
{
|
||||
char* gt_res;
|
||||
char* gt_res = NULL;
|
||||
char* emo_res;
|
||||
gt_res = greentextify(content);
|
||||
if (ssn->config.stat_greentexts)
|
||||
gt_res = greentextify(content);
|
||||
else
|
||||
gt_res = content;
|
||||
|
||||
if (emos)
|
||||
{
|
||||
emo_res = emojify(gt_res, emos, emos_len);
|
||||
|
@ -449,7 +456,8 @@ char* construct_status(struct session* ssn,
|
|||
status->account.emojis_len);
|
||||
|
||||
// Format status
|
||||
char* parse_content = reformat_status(status->content, status->emojis, status->emojis_len);
|
||||
char* parse_content = reformat_status(ssn, status->content, status->emojis, status->emojis_len);
|
||||
|
||||
// Find and replace
|
||||
if (args && args->highlight_word)
|
||||
{
|
||||
|
|
|
@ -85,7 +85,10 @@ char* construct_status_interaction_profiles(struct mstdnt_account* reblogs,
|
|||
size_t* ret_size);
|
||||
char* construct_status_interaction_profile(struct interact_profile_args* args, size_t index, int* size);
|
||||
char* construct_status_interactions_label(char* header, int val, size_t* size);
|
||||
char* reformat_status(char* content, struct mstdnt_emoji* emos, size_t emos_len);
|
||||
char* reformat_status(struct session* ssn,
|
||||
char* content,
|
||||
struct mstdnt_emoji* emos,
|
||||
size_t emos_len);
|
||||
char* greentextify(char* content);
|
||||
|
||||
// Status frontends
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
<label for="cfgstatdope">Show dopameme numbers - Likes, comments, and boost counts</label>
|
||||
</li>
|
||||
<li>
|
||||
<input type="checkbox" id="cfgstatoneclick" name="statoneclicksoftware" value="1" checked>
|
||||
<input type="checkbox" id="cfgstatoneclicksoftware" name="statoneclicksoftware" value="1" checked>
|
||||
<label for="cfgstatoneclicksoftware">Show Like-Boost button - Show a button in the status which likes and boosts a post</label>
|
||||
</li>
|
||||
<li>
|
||||
|
@ -53,11 +53,11 @@
|
|||
<h3>Instance</h3>
|
||||
<ul>
|
||||
<li>
|
||||
<input type="checkbox" id="cfginstanceshowshoutbox" name="instanceshowshoutbox" value="1">
|
||||
<input type="checkbox" id="cfginstanceshowshoutbox" name="instanceshowshoutbox" value="1" checked>
|
||||
<label for="cfginstanceshowshoutbox">Show instance shoutbox (JS required)</label>
|
||||
</li>
|
||||
<li>
|
||||
<input type="checkbox" id="cfginstancepanel" name="instancepanel" value="1">
|
||||
<input type="checkbox" id="cfginstancepanel" name="instancepanel" value="1" checked>
|
||||
<label for="cfginstancepanel">Show instance panel - <em>Admins should <strong>not</strong> use the instance panel for major announcements</em></label>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
Loading…
Reference in a new issue