More perl shit

FossilOrigin-Name: 3e3d09e82d3730e070a60b59be3c4ad69c1f3c965c3bf027673e9a3811825eb6
This commit is contained in:
nekobit 2022-07-23 05:32:17 +00:00
parent 772db3ce28
commit bba2ad9cda
9 changed files with 160 additions and 45 deletions

View file

@ -1,5 +1,7 @@
package l10n;
use Exporter 'import';
our @EXPORT = qw( %L10N );
our %L10N = (

View file

@ -2,7 +2,7 @@ use strict;
use warnings;
# Modules
use Template;
use l10n;
use l10n qw( %L10N );
my $template = Template->new(
{
@ -17,13 +17,12 @@ sub base_page
my ($ssn, $data) = @_;
my $result;
my $vars = {
# L10N => L10N,
my %vars = (
prefix => '',
lang => sub { $l10n::L10N{'EN_US'}{shift(@_)} },
};
lang => sub { $L10N{'EN_US'}->{shift(@_)} },
);
$template->process(\$data, $vars, \$result) ||
$template->process(\$data, \%vars, \$result) ||
return $template->error();
$result;

View file

@ -164,3 +164,35 @@ int cookie_get_val(char* src, char* key, struct http_cookie_info* info)
return 1;
}
HV* perlify_cookies(struct cookie_values* cookies)
{
HV* ssn_cookies_hv = newHV();
hv_stores(ssn_cookies_hv, "lang", newSViv(keyint(cookies->lang)));
hv_stores(ssn_cookies_hv, "interact_img", newSViv(keyint(cookies->interact_img)));
hv_stores(ssn_cookies_hv, "themeclr", newSViv(keyint(cookies->themeclr)));
hv_stores(ssn_cookies_hv, "jsactions", newSViv(keyint(cookies->jsactions)));
hv_stores(ssn_cookies_hv, "jsreply", newSViv(keyint(cookies->jsreply)));
hv_stores(ssn_cookies_hv, "jslive", newSViv(keyint(cookies->jslive)));
hv_stores(ssn_cookies_hv, "js", newSViv(keyint(cookies->js)));
hv_stores(ssn_cookies_hv, "interact_img", newSViv(keyint(cookies->interact_img)));
hv_stores(ssn_cookies_hv, "statattachments", newSViv(keyint(cookies->stat_attachments)));
hv_stores(ssn_cookies_hv, "statgreentexts", newSViv(keyint(cookies->stat_greentexts)));
hv_stores(ssn_cookies_hv, "statdope", newSViv(keyint(cookies->stat_dope)));
hv_stores(ssn_cookies_hv, "statoneclicksoftware", newSViv(keyint(cookies->stat_oneclicksoftware)));
hv_stores(ssn_cookies_hv, "statemojolikes", newSViv(keyint(cookies->stat_emojo_likes)));
hv_stores(ssn_cookies_hv, "stathidemuted", newSViv(keyint(cookies->stat_hide_muted)));
hv_stores(ssn_cookies_hv, "instanceshowshoutbox", newSViv(keyint(cookies->instance_show_shoutbox)));
hv_stores(ssn_cookies_hv, "instancepanel", newSViv(keyint(cookies->instance_panel)));
hv_stores(ssn_cookies_hv, "notifembed", newSViv(keyint(cookies->notif_embed)));
hv_stores(ssn_cookies_hv, "access_token", newSVpv(keystr(cookies->access_token), 0));
hv_stores(ssn_cookies_hv, "logged_in", newSVpv(keystr(cookies->logged_in), 0));
hv_stores(ssn_cookies_hv, "theme", newSVpv(keystr(cookies->theme), 0));
hv_stores(ssn_cookies_hv, "instance_url", newSVpv(keystr(cookies->instance_url), 0));
hv_stores(ssn_cookies_hv, "background_url", newSVpv(keystr(cookies->background_url), 0));
hv_stores(ssn_cookies_hv, "client_id", newSVpv(keystr(cookies->client_id), 0));
hv_stores(ssn_cookies_hv, "client_secret", newSVpv(keystr(cookies->client_secret), 0));
return ssn_cookies_hv;
}

View file

@ -19,6 +19,7 @@
#ifndef COOKIE_H
#define COOKIE_H
#include <stddef.h>
#include "global_perl.h"
#include "key.h"
struct cookie_values
@ -61,4 +62,6 @@ char* parse_cookies(char* begin, struct http_cookie_info* info);
char* read_cookies_env(FCGX_Request* req, struct cookie_values* cookies);
int cookie_get_val(char* src, char* key, struct http_cookie_info* info);
HV* perlify_cookies(struct cookie_values* cookies);
#endif // COOKIE_H

48
src/local_config.c Normal file
View file

@ -0,0 +1,48 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
#include "global_perl.h"
#include "local_config.h"
HV* perlify_config(struct local_config* config)
{
HV* ssn_config_hv = newHV();
hv_stores(ssn_config_hv, "logged_in", newSVpv(config->logged_in, 0));
hv_stores(ssn_config_hv, "theme", newSVpv(config->theme, 0));
hv_stores(ssn_config_hv, "background_url", newSVpv(config->background_url, 0));
hv_stores(ssn_config_hv, "lang", newSViv(config->lang));
hv_stores(ssn_config_hv, "themeclr", newSViv(config->themeclr));
hv_stores(ssn_config_hv, "jsactions", newSViv(config->jsactions));
hv_stores(ssn_config_hv, "jslive", newSViv(config->jslive));
hv_stores(ssn_config_hv, "js", newSViv(config->js));
hv_stores(ssn_config_hv, "interact_img", newSViv(config->interact_img));
hv_stores(ssn_config_hv, "stat_attachments", newSViv(config->stat_attachments));
hv_stores(ssn_config_hv, "stat_greentexts", newSViv(config->stat_greentexts));
hv_stores(ssn_config_hv, "stat_dope", newSViv(config->stat_dope));
hv_stores(ssn_config_hv, "stat_oneclicksoftware", newSViv(config->stat_oneclicksoftware));
hv_stores(ssn_config_hv, "stat_emojo_likes", newSViv(config->stat_emojo_likes));
hv_stores(ssn_config_hv, "stat_hide_muted", newSViv(config->stat_hide_muted));
hv_stores(ssn_config_hv, "instance_show_shoutbox", newSViv(config->instance_show_shoutbox));
hv_stores(ssn_config_hv, "instance_panel", newSViv(config->instance_panel));
hv_stores(ssn_config_hv, "notif_embed", newSViv(config->notif_embed));
hv_stores(ssn_config_hv, "sidebar_opacity", newSViv(config->sidebar_opacity));
return ssn_config_hv;
}

View file

@ -18,6 +18,7 @@
#ifndef LOCAL_CONFIG_H
#define LOCAL_CONFIG_H
#include "global_perl.h"
#include "query.h"
struct local_config
@ -44,4 +45,6 @@ struct local_config
int sidebar_opacity;
};
HV* perlify_config(struct local_config* config);
#endif // LOCAL_CONFIG_H

View file

@ -262,3 +262,59 @@ void free_files(struct file_array* files)
}
free(content);
}
HV* perlify_post_values(struct post_values* post)
{
HV* ssn_post_hv = newHV();
// This ugly...
hv_stores(ssn_post_hv, "theme", newSVpv(keystr(post->theme), 0));
hv_stores(ssn_post_hv, "themeclr", newSViv(keyint(post->themeclr)));
hv_stores(ssn_post_hv, "lang", newSViv(keyint(post->lang)));
hv_stores(ssn_post_hv, "title", newSViv(keyint(post->title)));
hv_stores(ssn_post_hv, "jsactions", newSViv(keyint(post->jsactions)));
hv_stores(ssn_post_hv, "jsreply", newSViv(keyint(post->jsreply)));
hv_stores(ssn_post_hv, "jslive", newSViv(keyint(post->jslive)));
hv_stores(ssn_post_hv, "js", newSViv(keyint(post->js)));
hv_stores(ssn_post_hv, "interact_img", newSViv(keyint(post->interact_img)));
hv_stores(ssn_post_hv, "stat_attachments", newSViv(keyint(post->stat_attachments)));
hv_stores(ssn_post_hv, "stat_greentexts", newSViv(keyint(post->stat_greentexts)));
hv_stores(ssn_post_hv, "stat_dope", newSViv(keyint(post->stat_dope)));
hv_stores(ssn_post_hv, "stat_oneclicksoftware", newSViv(keyint(post->stat_oneclicksoftware)));
hv_stores(ssn_post_hv, "stat_emojo_likes", newSViv(keyint(post->stat_emojo_likes)));
hv_stores(ssn_post_hv, "stat_hide_muted", newSViv(keyint(post->stat_hide_muted)));
hv_stores(ssn_post_hv, "instance_show_shoutbox", newSViv(keyint(post->instance_show_shoutbox)));
hv_stores(ssn_post_hv, "instance_panel", newSViv(keyint(post->instance_panel)));
hv_stores(ssn_post_hv, "notif_embed", newSViv(keyint(post->notif_embed)));
hv_stores(ssn_post_hv, "set", newSViv(keyint(post->set)));
hv_stores(ssn_post_hv, "only_media", newSViv(keyint(post->only_media)));
hv_stores(ssn_post_hv, "replies_only", newSViv(keyint(post->replies_only)));
hv_stores(ssn_post_hv, "replies_policy", newSViv(keyint(post->replies_policy)));
hv_stores(ssn_post_hv, "emojoindex", newSViv(keyint(post->emojoindex)));
hv_stores(ssn_post_hv, "sidebar_opacity", newSViv(keyint(post->sidebar_opacity)));
hv_stores(ssn_post_hv, "file_ids", newSVpv(keystr(post->file_ids), 0));
hv_stores(ssn_post_hv, "content", newSVpv(keystr(post->content), 0));
hv_stores(ssn_post_hv, "itype", newSVpv(keystr(post->itype), 0));
hv_stores(ssn_post_hv, "id", newSVpv(keystr(post->id), 0));
hv_stores(ssn_post_hv, "username", newSVpv(keystr(post->username), 0));
hv_stores(ssn_post_hv, "password", newSVpv(keystr(post->password), 0));
hv_stores(ssn_post_hv, "replyid", newSVpv(keystr(post->replyid), 0));
hv_stores(ssn_post_hv, "visibility", newSVpv(keystr(post->visibility), 0));
hv_stores(ssn_post_hv, "instance", newSVpv(keystr(post->instance), 0));
hv_stores(ssn_post_hv, "min_id", newSVpv(keystr(post->min_id), 0));
hv_stores(ssn_post_hv, "max_id", newSVpv(keystr(post->max_id), 0));
hv_stores(ssn_post_hv, "start_id", newSVpv(keystr(post->start_id), 0));
return ssn_post_hv;
}
HV* perlify_get_values(struct get_values* get)
{
HV* ssn_query_hv = newHV();
hv_stores(ssn_query_hv, "offset", newSVpv(keystr(get->offset), 0));
hv_stores(ssn_query_hv, "query", newSVpv(keystr(get->query), 0));
hv_stores(ssn_query_hv, "code", newSVpv(keystr(get->code), 0));
return ssn_query_hv;
}

View file

@ -18,6 +18,7 @@
#ifndef QUERY_H
#define QUERY_H
#include "global_perl.h"
#include <fcgi_stdio.h>
#include <stddef.h>
#include "key.h"
@ -89,4 +90,8 @@ char* try_handle_post(FCGX_Request* req, void (*call)(struct http_query_info*, v
void free_files(struct file_array* files);
// Perl stuff
HV* perlify_post_values(struct post_values* post);
HV* perlify_get_values(struct get_values* get);
#endif // QUERY_H

View file

@ -30,52 +30,19 @@ const char* const get_token(struct session* ssn)
return keystr(ssn->cookies.access_token);
}
static HV* perlify_post_values(struct post_values* post)
{
}
static HV* perlify_get_values(struct get_values* get)
{
}
static HV* perlify_config(struct local_config* config)
{
HV* ssn_config_hv = newHV();
hv_stores(ssn_config_hv, "logged_in", newSVpv(config->logged_in, 0));
hv_stores(ssn_config_hv, "theme", newSVpv(config->theme, 0));
hv_stores(ssn_config_hv, "background_url", newSVpv(config->background_url, 0));
hv_stores(ssn_config_hv, "lang", newSViv(config->lang));
hv_stores(ssn_config_hv, "themeclr", newSViv(config->themeclr));
hv_stores(ssn_config_hv, "jsactions", newSViv(config->jsactions));
hv_stores(ssn_config_hv, "jslive", newSViv(config->jslive));
hv_stores(ssn_config_hv, "js", newSViv(config->js));
hv_stores(ssn_config_hv, "interact_img", newSViv(config->interact_img));
hv_stores(ssn_config_hv, "stat_attachments", newSViv(config->stat_attachments));
hv_stores(ssn_config_hv, "stat_greentexts", newSViv(config->stat_greentexts));
hv_stores(ssn_config_hv, "stat_dope", newSViv(config->stat_dope));
hv_stores(ssn_config_hv, "stat_oneclicksoftware", newSViv(config->stat_oneclicksoftware));
hv_stores(ssn_config_hv, "stat_emojo_likes", newSViv(config->stat_emojo_likes));
hv_stores(ssn_config_hv, "stat_hide_muted", newSViv(config->stat_hide_muted));
hv_stores(ssn_config_hv, "instance_show_shoutbox", newSViv(config->instance_show_shoutbox));
hv_stores(ssn_config_hv, "instance_panel", newSViv(config->instance_panel));
hv_stores(ssn_config_hv, "notif_embed", newSViv(config->notif_embed));
hv_stores(ssn_config_hv, "sidebar_opacity", newSViv(config->sidebar_opacity));
return ssn_config_hv;
}
HV* perlify_session(struct session* ssn)
{
HV* ssn_hv = newHV();
hv_stores(ssn_hv, "logged_in", newSVuv(ssn->logged_in));
// HV* ssn_post_values = perlify_post_values(&(ssn->post));
// HV* ssn_get_values = perlify_get_values(&(ssn->query));
// HV* ssn_get_values = perlify_cookie_values(&(ssn->query))
HV* ssn_post_values = perlify_post_values(&(ssn->post));
HV* ssn_get_values = perlify_get_values(&(ssn->query));
HV* ssn_cookie_values = perlify_cookies(&(ssn->cookies));
// Config
HV* ssn_config = perlify_config(&(ssn->config));
hv_stores(ssn_hv, "config", newRV_inc((SV*)ssn_config));
hv_stores(ssn_hv, "cookies", newRV_inc((SV*)ssn_cookie_values));
hv_stores(ssn_hv, "query", newRV_inc((SV*)ssn_get_values));
hv_stores(ssn_hv, "post", newRV_inc((SV*)ssn_post_values));
return ssn_hv;
}