Lists boilerplate, Fix perl/fcgiapp header conflict warnings

FossilOrigin-Name: a04dd4a4b737e28845a422293b10f72335f55aea72ae5bcd20eb01f8842b0dc3
This commit is contained in:
nekobit 2022-08-05 19:45:35 +00:00
parent 937301e307
commit 3c4a5970e8
21 changed files with 84 additions and 84 deletions

15
perl/lists.pm Normal file
View File

@ -0,0 +1,15 @@
package lists;
use strict;
use warnings;
use Exporter 'import';
our @EXPORTS = qw( );
use template_helpers 'to_template';
sub content_lists
{
my ($ssn, $data, $lists) = @_;
to_template(\%vars, $data->{'content_lists.tt'});
}

View File

@ -27,7 +27,7 @@ sub content_notifications
my %vars = (
prefix => '',
ssn=> $ssn,
notif => $notif
notifs => $notifs
);
to_template(\%vars, \$data->{'content_notifs.tt'});

View File

@ -16,7 +16,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <fcgi_stdio.h>
#include <string.h>
#include <stdlib.h>
#include "helpers.h"
@ -28,6 +27,7 @@
#include "../config.h"
#include "local_config_set.h"
#include "account.h"
#include <fcgi_stdio.h>
#include "global_cache.h"
// Files
@ -80,7 +80,7 @@ void render_base_page(struct base_page* page, FCGX_Request* req, struct session*
PUSHMARK(SP);
if (page->session)
mXPUSHs(newRV_inc(page->session));
mXPUSHs(newRV_inc((SV*)page->session));
else
mXPUSHs(newRV_inc((SV*)perlify_session(ssn)));
XPUSHs(newRV_inc((SV*)template_files));
@ -99,7 +99,7 @@ void render_base_page(struct base_page* page, FCGX_Request* req, struct session*
SPAGAIN;
send_result(req, NULL, "text/html", POPp, 0);
cleanup:
PUTBACK;
FREETMPS;
LEAVE;

View File

@ -18,6 +18,7 @@
#ifndef BASE_PAGE_H
#define BASE_PAGE_H
#include "global_perl.h"
#include "session.h"
#include <fcgi_stdio.h>
#include <fcgiapp.h>

View File

@ -16,11 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "cookie.h"
#include <fcgi_stdio.h>
#include <fcgiapp.h>
#include <string.h>
#include <stdlib.h>
#include "cookie.h"
#include "env.h"
enum cookie_state

View File

@ -21,6 +21,8 @@
#include <stddef.h>
#include "global_perl.h"
#include "key.h"
#include <fcgi_stdio.h>
#include <fcgiapp.h>
struct cookie_values
{

View File

@ -16,11 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "emoji.h"
#include <stdlib.h>
#include <string.h>
#include "base_page.h"
#include "string.h"
#include "emoji.h"
#include "easprintf.h"
#include "string_helpers.h"
@ -171,7 +171,7 @@ HV* perlify_emoji(struct mstdnt_emoji* const emoji)
hvstores_str(emoji_hv, "shortcode", emoji->shortcode);
hvstores_str(emoji_hv, "url", emoji->url);
hvstores_str(emoji_hv, "static_url", emoji->static_url);
hvstores_str(emoji_hv, "visible_in_picker", emoji->visible_in_picker);
hvstores_int(emoji_hv, "visible_in_picker", emoji->visible_in_picker);
hvstores_str(emoji_hv, "category", emoji->category);
return emoji_hv;
}

View File

@ -20,8 +20,9 @@
#define EMOJI_H
#include <stddef.h>
#include <mastodont.h>
#include "emoji_codes.h"
#include "global_perl.h"
#include "emoji_codes.h"
#include "path.h"
#define EMOJI_FACTOR_NUM 32

View File

@ -32,6 +32,7 @@
#include "../templates/account_statuses.ctt"
#include "../templates/account_scrobbles.ctt"
#include "../templates/content_notifs.ctt"
#include "../templates/content_lists.ctt"
HV* template_files;
pthread_mutex_t perl_mutex = PTHREAD_MUTEX_INITIALIZER;
@ -53,6 +54,7 @@ void init_template_files()
hv_stores(template_files, "account_statuses.tt", newSVpv(data_account_statuses_tt, data_account_statuses_tt_size));
hv_stores(template_files, "account_scrobbles.tt", newSVpv(data_account_scrobbles_tt, data_account_scrobbles_tt_size));
hv_stores(template_files, "content_notifs.tt", newSVpv(data_content_notifs_tt, data_content_notifs_tt_size));
hv_stores(template_files, "content_lists.tt", newSVpv(data_content_lists_tt, data_content_lists_tt_size));
}
void cleanup_template_files()

View File

@ -17,6 +17,7 @@
*/
#include <stdlib.h>
#include "global_perl.h"
#include "helpers.h"
#include "base_page.h"
#include "../config.h"
@ -33,50 +34,13 @@
#include "../static/list.ctmpl"
#include "../static/lists.ctmpl"
char* construct_list(struct mstdnt_list* list, size_t* size)
{
char* result;
char* title = list->title;
char* list_name = sanitize_html(title);
struct list_template data = {
.list = list_name,
.prefix = config_url_prefix,
.list_id = list->id
};
result = tmpl_gen_list(&data, size);
if (list_name != title)
free(list_name);
return result;
}
static char* construct_list_voidwrap(void* passed, size_t index, size_t* res)
{
return construct_list((struct mstdnt_list*)passed + index, res);
}
char* construct_lists(struct mstdnt_list* lists, size_t size, size_t* ret_size)
{
return construct_func_strings(construct_list_voidwrap, lists, size, ret_size);
}
char* construct_lists_view(char* lists_string, size_t* size)
{
struct lists_template data = {
.lists = lists_string,
.prefix = config_url_prefix
};
return tmpl_gen_lists(&data, size);
}
void content_lists(PATH_ARGS)
{
struct mstdnt_args m_args;
set_mstdnt_args(&m_args, ssn);
struct mstdnt_list* lists = NULL;
size_t size_list = 0;
size_t list_len = 0;
struct mstdnt_storage storage = { 0 };
char* lists_format = NULL;
char* lists_page = NULL;
if (ssn->post.title.is_set)
{
@ -89,20 +53,36 @@ void content_lists(PATH_ARGS)
mastodont_storage_cleanup(&create_storage);
}
if (mastodont_get_lists(api, &m_args, &storage, &lists, &size_list))
{
lists_page = construct_error(storage.error, E_ERROR, 1, NULL);
}
else {
lists_format = construct_lists(lists, size_list, NULL);
if (!lists_format)
lists_format = construct_error("No lists", E_ERROR, 1, NULL);
lists_page = construct_lists_view(lists_format, NULL);
}
mastodont_get_lists(api, &m_args, &storage, &lists, &list_len);
// Call perl
perl_lock();
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
HV* session_hv = perlify_session(ssn);
XPUSHs(newRV_noinc((SV*)session_hv));
XPUSHs(newRV_noinc((SV*)template_files));
// TODO Perlify lists
// ARGS
PUTBACK;
call_pv("lists::content_lists", G_SCALAR);
SPAGAIN;
// Duplicate so we can free the TMPs
char* dup = savesharedsvpv(POPs);
PUTBACK;
FREETMPS;
LEAVE;
perl_unlock();
struct base_page b = {
.category = BASE_CAT_LISTS,
.content = lists_page,
.content = dup,
.session = session_hv,
.sidebar_left = NULL
};
@ -111,9 +91,8 @@ void content_lists(PATH_ARGS)
// Cleanup
mastodont_storage_cleanup(&storage);
if (lists_format) free(lists_format);
if (lists_page) free(lists_page);
mstdnt_cleanup_lists(lists);
Safefree(dup);
}
void list_edit(PATH_ARGS)

View File

@ -22,10 +22,9 @@
#include <mastodont.h>
#include "session.h"
char* construct_list(struct mstdnt_list* list, size_t* size);
char* construct_lists(struct mstdnt_list* lists, size_t size, size_t* ret_size);
char* construct_lists_view(char* lists_string, size_t* size);
/** Creates the main lists view */
void content_lists(PATH_ARGS);
/** Creates a list and then redirects */
void list_edit(PATH_ARGS);
#endif // LISTS_H

View File

@ -19,12 +19,12 @@
#ifndef LOCAL_CONFIG_SET_H
#define LOCAL_CONFIG_SET_H
#include <mastodont.h>
#include <fcgi_stdio.h>
#include <fcgiapp.h>
#include "local_config.h"
#include "session.h"
#include "attachments.h"
#include "local_config.h"
#include "key.h"
#include <fcgi_stdio.h>
#include <fcgiapp.h>
enum config_page
{

View File

@ -16,18 +16,18 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <curl/curl.h>
#include <fcgi_stdio.h>
#include "login.h"
#include <string.h>
#include <stdlib.h>
#include "helpers.h"
#include "query.h"
#include "base_page.h"
#include "login.h"
#include "error.h"
#include "easprintf.h"
#include "../config.h"
#include "http.h"
#include <curl/curl.h>
#include <fcgi_stdio.h>
// Files
#include "../static/login.ctmpl"

View File

@ -16,12 +16,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <fcgi_stdio.h>
#include <EXTERN.h>
#include <perl.h>
#include <pthread.h>
#include "global_perl.h"
#include <fcgiapp.h>
#include <pthread.h>
#include <string.h>
#include <mastodont.h>
#include <stdlib.h>
@ -47,6 +45,8 @@
#include "local_config_set.h"
#include "global_cache.h"
#include "conversations.h"
#include <fcgi_stdio.h>
#include <fcgiapp.h>
#define THREAD_COUNT 20

View File

@ -16,19 +16,19 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <fcgi_stdio.h>
#include "page_config.h"
#include <stdlib.h>
#include <string.h>
#include "http.h"
#include "base_page.h"
#include "../config.h"
#include "easprintf.h"
#include "page_config.h"
#include "query.h"
#include "cookie.h"
#include "local_config_set.h"
#include "string_helpers.h"
#include "l10n.h"
#include <fcgi_stdio.h>
// Pages
#include "../static/config_general.ctmpl"

View File

@ -20,10 +20,10 @@
#define PAGE_CONFIG_H
#include <stddef.h>
#include <mastodont.h>
#include <fcgi_stdio.h>
#include <fcgiapp.h>
#include "path.h"
#include "session.h"
#include <fcgi_stdio.h>
#include <fcgiapp.h>
void content_config_appearance(PATH_ARGS);
void content_config_general(PATH_ARGS);

View File

@ -18,12 +18,12 @@
#ifndef PATH_H
#define PATH_H
#include <fcgi_stdio.h>
#include <fcgiapp.h>
#include "session.h"
#include <mastodont.h>
#include <stddef.h>
#include "env.h"
#include "session.h"
#include <fcgi_stdio.h>
#include <fcgiapp.h>
#define PATH_ARGS FCGX_Request* req, struct session* ssn, mastodont_t* api, char** data

View File

@ -16,15 +16,15 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <fcgi_stdio.h>
#include <fcgiapp.h>
#include "query.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "query.h"
#include "env.h"
#include "mime.h"
#include <fcgi_stdio.h>
#include <fcgiapp.h>
char* read_get_data(FCGX_Request* req, struct get_values* query)
{

View File

@ -16,6 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "global_perl.h"
#include "timeline.h"
#include <stdlib.h>
#include "helpers.h"
@ -30,7 +31,6 @@
#include "query.h"
#include "error.h"
#include "string_helpers.h"
#include "global_perl.h"
#include "../static/timeline_options.ctmpl"
#include "../static/navigation.ctmpl"

View File

@ -18,13 +18,13 @@
#ifndef TIMELINE_H
#define TIMELINE_H
#include <fcgi_stdio.h>
#include <fcgiapp.h>
#include <stddef.h>
#include <mastodont.h>
#include "path.h"
#include "session.h"
#include "base_page.h"
#include <fcgi_stdio.h>
#include <fcgiapp.h>
/** Wrapper for content_tl_federated */
void tl_home(FCGX_Request* req, struct session* ssn, mastodont_t* api, int local);

View File

@ -0,0 +1 @@
<h1>Lists</h1>