More progress
FossilOrigin-Name: 87d1a1fa92872a66a37bd82ea9cc2e687f4107c45855a115b49193953c9b770e
This commit is contained in:
parent
a90878c1b8
commit
588bfc2126
9 changed files with 97 additions and 99 deletions
|
@ -5,6 +5,7 @@ use Template;
|
|||
use l10n qw( %L10N );
|
||||
use notifications qw( notification_compact );
|
||||
use template_helpers qw( &to_template );
|
||||
use status ();
|
||||
|
||||
# my $template = Template->new(
|
||||
# {
|
||||
|
@ -16,7 +17,10 @@ use template_helpers qw( &to_template );
|
|||
|
||||
sub base_page
|
||||
{
|
||||
my ($ssn, $data, $main, $notifs) = @_;
|
||||
my ($ssn,
|
||||
$data,
|
||||
$main,
|
||||
$notifs) = @_;
|
||||
my $result;
|
||||
|
||||
my %vars = (
|
||||
|
|
|
@ -17,3 +17,10 @@ sub status
|
|||
|
||||
to_template(\%vars, \$data->{'status.tt'});
|
||||
}
|
||||
|
||||
sub content_status
|
||||
{
|
||||
my ($ssn, $data, $statuses) = @_;
|
||||
|
||||
to_template(\%name, \$data->{'content_status.tt'});
|
||||
}
|
||||
|
|
|
@ -73,15 +73,19 @@ void render_base_page(struct base_page* page, FCGX_Request* req, struct session*
|
|||
}
|
||||
|
||||
// Init perl stack
|
||||
perl_lock();
|
||||
dSP;
|
||||
ENTER;
|
||||
SAVETMPS;
|
||||
PUSHMARK(SP);
|
||||
|
||||
HV* session_hv = perlify_session(ssn);
|
||||
XPUSHs(sv_2mortal(newRV_inc((SV*)session_hv)));
|
||||
XPUSHs(sv_2mortal(newRV_inc((SV*)template_files)));
|
||||
if (page->session)
|
||||
mXPUSHs(newRV_inc(page->session));
|
||||
else
|
||||
mXPUSHs(newRV_inc((SV*)perlify_session(ssn)));
|
||||
XPUSHs(newRV_inc((SV*)template_files));
|
||||
XPUSHs(sv_2mortal(newSVpv(page->content, 0)));
|
||||
|
||||
if (notifs && notifs_len)
|
||||
{
|
||||
AV* notifs_av = perlify_notifications(notifs, notifs_len);
|
||||
|
@ -94,13 +98,12 @@ void render_base_page(struct base_page* page, FCGX_Request* req, struct session*
|
|||
call_pv("base_page", G_SCALAR);
|
||||
SPAGAIN;
|
||||
|
||||
char* data = POPp;
|
||||
|
||||
send_result(req, NULL, "text/html", data, 0);
|
||||
send_result(req, NULL, "text/html", POPp, 0);
|
||||
cleanup:
|
||||
PUTBACK;
|
||||
FREETMPS;
|
||||
LEAVE;
|
||||
perl_unlock();
|
||||
|
||||
mstdnt_cleanup_notifications(notifs, notifs_len);
|
||||
mastodont_storage_cleanup(&storage);
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include "l10n.h"
|
||||
#include "local_config.h"
|
||||
#include "path.h"
|
||||
|
||||
enum base_category
|
||||
{
|
||||
BASE_CAT_NONE,
|
||||
|
@ -46,6 +45,7 @@ struct base_page
|
|||
enum base_category category;
|
||||
char* content;
|
||||
char* sidebar_left;
|
||||
HV* session;
|
||||
};
|
||||
|
||||
void render_base_page(struct base_page* page, FCGX_Request* req, struct session* ssn, mastodont_t* api);
|
||||
|
|
|
@ -22,7 +22,8 @@
|
|||
#include "../templates/notif_compact.ctt"
|
||||
#include "../templates/status.ctt"
|
||||
|
||||
const HV* template_files;
|
||||
HV* template_files;
|
||||
pthread_mutex_t perl_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
void init_template_files()
|
||||
{
|
||||
|
@ -31,6 +32,7 @@ void init_template_files()
|
|||
hv_stores(template_files, "main.tt", newSVpv(data_main_tt, data_main_tt_size));
|
||||
hv_stores(template_files, "notif_compact.tt", newSVpv(data_notif_compact_tt, data_notif_compact_tt_size));
|
||||
hv_stores(template_files, "status.tt", newSVpv(data_status_tt, data_status_tt_size));
|
||||
hv_stores(template_files, "content_status.tt", newSVpv(data_status_tt, data_status_tt_size));
|
||||
}
|
||||
|
||||
void cleanup_template_files()
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#define GLOBAL_PERL_H
|
||||
#include <EXTERN.h>
|
||||
#include <perl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
// hv_stores(ssn_hv, "id", newSVpv(acct->id, 0));
|
||||
#define hvstores_str(hv, key, val) hv_stores((hv), key, ((val) ? newSVpv((val), 0) : &PL_sv_undef))
|
||||
|
@ -28,7 +29,11 @@
|
|||
((val) ? newRV_inc((SV* const)(val)) : &PL_sv_undef))
|
||||
|
||||
static PerlInterpreter* perl;
|
||||
extern const HV* template_files;
|
||||
extern HV* template_files;
|
||||
extern pthread_mutex_t perl_mutex;
|
||||
|
||||
#define perl_lock() if(1) { pthread_mutex_lock(&perl_mutex); }
|
||||
#define perl_unlock() if(1) { pthread_mutex_unlock(&perl_mutex); }
|
||||
|
||||
void init_template_files();
|
||||
void cleanup_template_files();
|
||||
|
|
26
src/main.c
26
src/main.c
|
@ -16,10 +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 <fcgi_stdio.h>
|
||||
#include "global_perl.h"
|
||||
#include <fcgiapp.h>
|
||||
#include <string.h>
|
||||
|
@ -55,6 +55,8 @@ static void xs_init (pTHX);
|
|||
|
||||
EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
|
||||
|
||||
static int terminate = 0;
|
||||
|
||||
/*******************
|
||||
* Path handling *
|
||||
******************/
|
||||
|
@ -181,7 +183,7 @@ static void* cgi_start(void* arg)
|
|||
FCGX_Request req;
|
||||
FCGX_InitRequest(&req, 0, 0);
|
||||
|
||||
while (1)
|
||||
while (!terminate)
|
||||
{
|
||||
static pthread_mutex_t accept_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
|
@ -195,6 +197,7 @@ static void* cgi_start(void* arg)
|
|||
FCGX_Finish_r(&req);
|
||||
}
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -204,8 +207,20 @@ EXTERN_C void xs_init(pTHX)
|
|||
newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
|
||||
}
|
||||
|
||||
void term(int signum)
|
||||
{
|
||||
FCGX_ShutdownPending();
|
||||
terminate = 1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv, char **env)
|
||||
{
|
||||
struct sigaction action = {
|
||||
.sa_handler = term
|
||||
};
|
||||
sigaction(SIGTERM, &action, NULL);
|
||||
sigaction(SIGINT, &action, NULL);
|
||||
|
||||
// Global init
|
||||
mastodont_global_curl_init();
|
||||
FCGX_Init();
|
||||
|
@ -243,9 +258,14 @@ int main(int argc, char **argv, char **env)
|
|||
mastodont_global_curl_cleanup();
|
||||
|
||||
cleanup_template_files();
|
||||
|
||||
FCGX_ShutdownPending();
|
||||
|
||||
for (unsigned i = 0; i < THREAD_COUNT; ++i)
|
||||
pthread_join(id[i], NULL);
|
||||
|
||||
perl_destruct(perl);
|
||||
perl_free(perl);
|
||||
PERL_SYS_TERM();
|
||||
return EXIT_SUCCESS;
|
||||
return 4;
|
||||
}
|
||||
|
|
128
src/status.c
128
src/status.c
|
@ -1041,106 +1041,62 @@ void content_status_interactions(FCGX_Request* req,
|
|||
|
||||
void content_status(PATH_ARGS, uint8_t flags)
|
||||
{
|
||||
/* struct mstdnt_args m_args; */
|
||||
/* set_mstdnt_args(&m_args, ssn); */
|
||||
/* char* output; */
|
||||
/* // Status context */
|
||||
/* struct mstdnt_storage storage = {0}, status_storage = {0}; */
|
||||
/* struct mstdnt_status* statuses_before = NULL, */
|
||||
/* *statuses_after = NULL, */
|
||||
/* status = { 0 }; */
|
||||
/* size_t stat_before_len = 0, stat_after_len = 0; */
|
||||
/* char* before_html = NULL, *stat_html = NULL, *after_html = NULL, *stat_reply = NULL, */
|
||||
/* * thread_pagination = NULL; */
|
||||
|
||||
/* int stat_after_limit = 15; */
|
||||
/* int stat_before_limit = 15; */
|
||||
/* #define enough_statuses_before (stat_before_len > stat_before_limit) */
|
||||
/* #define enough_statuses_after (stat_after_len > stat_after_limit) */
|
||||
|
||||
/* try_post_status(ssn, api); */
|
||||
/* mastodont_get_status_context(api, */
|
||||
/* &m_args, */
|
||||
/* data[0], */
|
||||
/* &storage, */
|
||||
/* &statuses_before, &statuses_after, */
|
||||
/* &stat_before_len, &stat_after_len); */
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
struct mstdnt_storage storage = {0}, status_storage = {0};
|
||||
struct mstdnt_status* statuses_before = NULL,
|
||||
*statuses_after = NULL,
|
||||
status = { 0 };
|
||||
size_t stat_before_len = 0, stat_after_len = 0;
|
||||
|
||||
/* // Get information */
|
||||
/* if (mastodont_get_status(api, &m_args, data[0], &status_storage, &status)) */
|
||||
/* { */
|
||||
/* stat_html = construct_error("Status not found", E_ERROR, 1, NULL); */
|
||||
/* } */
|
||||
/* else { */
|
||||
/* before_html = construct_statuses(ssn, api, */
|
||||
/* (enough_statuses_before ? */
|
||||
/* statuses_before + (stat_before_len - stat_before_limit) : statuses_before), */
|
||||
/* (enough_statuses_before ? */
|
||||
/* stat_before_limit : stat_before_len), */
|
||||
/* NULL, 0); */
|
||||
try_post_status(ssn, api);
|
||||
mastodont_get_status(api, &m_args, data[0], &status_storage, &status);
|
||||
mastodont_get_status_context(api,
|
||||
&m_args,
|
||||
data[0],
|
||||
&storage,
|
||||
&statuses_before, &statuses_after,
|
||||
&stat_before_len, &stat_after_len);
|
||||
|
||||
/* // Current status */
|
||||
/* stat_html = construct_status(ssn, api, &status, NULL, NULL, NULL, flags); */
|
||||
/* if ((flags & STATUS_REPLY) == STATUS_REPLY) */
|
||||
/* { */
|
||||
/* stat_reply = reply_status(ssn, */
|
||||
/* data[0], */
|
||||
/* &status); */
|
||||
/* } */
|
||||
/* } */
|
||||
perl_lock();
|
||||
dSP;
|
||||
ENTER;
|
||||
SAVETMPS;
|
||||
PUSHMARK(SP);
|
||||
HV* session_hv = perlify_session(ssn);
|
||||
XPUSHs(newRV_inc((SV*)session_hv));
|
||||
XPUSHs(newRV_inc((SV*)template_files));
|
||||
// ARGS
|
||||
PUTBACK;
|
||||
call_pv("status::content_status", G_SCALAR);
|
||||
SPAGAIN;
|
||||
|
||||
/* // After... */
|
||||
/* // For pagination, we already start at the first, so no math required here */
|
||||
/* after_html = construct_statuses(ssn, api, statuses_after, */
|
||||
/* (enough_statuses_after ? stat_after_limit : stat_after_len), */
|
||||
/* NULL, 0); */
|
||||
malloc(1024);
|
||||
|
||||
/* // Thread pagination buttons */
|
||||
/* if (statuses_before || statuses_after) */
|
||||
/* { */
|
||||
/* struct thread_page_btn_template pagination_tmpl = { */
|
||||
/* .prefix = config_url_prefix, */
|
||||
/* .status_first = (statuses_before ? statuses_before[0].id : "deadbeef"), */
|
||||
/* .status_last = (statuses_after ? statuses_after[stat_after_len-1].id : "deadbeef"), */
|
||||
/* .status_before = (statuses_before && enough_statuses_before ? statuses_before[stat_before_len - stat_before_limit].id : "deadbeef"), */
|
||||
/* .status_after = (statuses_after && enough_statuses_after ? */
|
||||
/* statuses_after[stat_after_limit].id : "deadbeef"), */
|
||||
/* }; */
|
||||
/* thread_pagination = tmpl_gen_thread_page_btn(&pagination_tmpl, NULL); */
|
||||
/* } */
|
||||
|
||||
// Duplicate so we can free the TMPs
|
||||
char* dup = savesharedsvpv(POPs);
|
||||
|
||||
/* easprintf(&output, "%s%s%s%s%s%s", */
|
||||
/* thread_pagination ? thread_pagination : "", */
|
||||
/* before_html ? before_html : "", */
|
||||
/* stat_html ? stat_html : "", */
|
||||
/* stat_reply ? stat_reply : "", */
|
||||
/* after_html ? after_html : "", */
|
||||
/* thread_pagination ? thread_pagination : ""); */
|
||||
|
||||
PUTBACK;
|
||||
FREETMPS;
|
||||
LEAVE;
|
||||
perl_unlock();
|
||||
|
||||
struct base_page b = {
|
||||
.category = BASE_CAT_NONE,
|
||||
.content = "test",
|
||||
.content = dup,
|
||||
.session = session_hv,
|
||||
.sidebar_left = NULL
|
||||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b, req, ssn, api);
|
||||
|
||||
// Cleanup
|
||||
/* free(before_html); */
|
||||
/* free(stat_html); */
|
||||
/* free(after_html); */
|
||||
/* free(output); */
|
||||
/* free(thread_pagination); */
|
||||
/* if ((flags & STATUS_REPLY) == STATUS_REPLY) */
|
||||
/* free(stat_reply); */
|
||||
/* mstdnt_cleanup_statuses(statuses_before, stat_before_len); */
|
||||
/* mstdnt_cleanup_statuses(statuses_after, stat_after_len); */
|
||||
/* mstdnt_cleanup_status(&status); */
|
||||
/* mastodont_storage_cleanup(&storage); */
|
||||
/* mastodont_storage_cleanup(&status_storage); */
|
||||
mstdnt_cleanup_statuses(statuses_before, stat_before_len);
|
||||
mstdnt_cleanup_statuses(statuses_after, stat_after_len);
|
||||
mstdnt_cleanup_status(&status);
|
||||
mastodont_storage_cleanup(&storage);
|
||||
mastodont_storage_cleanup(&status_storage);
|
||||
Safefree(dup);
|
||||
}
|
||||
|
||||
void notice_redirect(PATH_ARGS)
|
||||
|
|
1
templates/content_status.tt
Normal file
1
templates/content_status.tt
Normal file
|
@ -0,0 +1 @@
|
|||
asdasd
|
Loading…
Reference in a new issue