Start implementing inbox processing

master
teknomunk 1 year ago
parent e2c7c3990a
commit 808f912b1e

@ -0,0 +1,2 @@
FLAGS="-g -MP -MD -Os"
LDFLAGS = "-lcurl"

@ -3,3 +3,21 @@
Personal ActivityPub server intended for single-user instances.
This software is intended to support exactly one user, and bot accounts owned by that user.
WARNING! This software is early in development and as such is missing most of the
functionality one would expect from an ActivityPub server. Software is unstable.
USE AT YOUR OWN RISK.
# Dependencies
libCURL
# TODO
[ ] Process /inbox
[ ] Fetch signing keys
[ ] Implement follow replies
[ ] Process /outbox
[ ] Implement HTTP Signatures

@ -7,6 +7,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
static void io_copy( FILE* in, FILE* out )
{
@ -71,3 +72,29 @@ bool route_inbox( struct http_request* req )
return true;
}
int read_list_end( const char* filename )
{
FILE* f;
int pos = 0;
f = fopen(filename,"r");
fscanf( f, "%d", &pos );
fclose(f);
return pos;
}
void process_inbox()
{
int tail_pos = read_list_end("data/inbox/TAIL");
for(;;) {
int head_pos = read_list_end("data/inbox/HEAD");
if( head_pos > tail_pos ) {
// We have data to process
printf( "Inbox has %d items pending processing...\n", (head_pos - tail_pos) );
}
sleep(1);
}
}

@ -5,4 +5,5 @@
struct http_request;
bool route_inbox( struct http_request* req );
void process_inbox();

@ -4,12 +4,14 @@
#include <stdbool.h>
#include <unistd.h>
#include <signal.h>
#include <sys/prctl.h>
#include "app_args.h"
#include "http_server/http_server.h"
#include "http_server/http_request.h"
#include "controller/main.h"
#include "controller/inbox.h"
bool terminate = false;
@ -31,22 +33,13 @@ void handle_request( struct http_request* req, void* )
}
}
int main( int argc, char* argv[] )
bool run_webserver( struct app_args* args )
{
signal(SIGINT, handle_ctrl_c);
signal(SIGPIPE, SIG_IGN);
struct app_args* args = app_args_new( argc, argv );
if( !args ) {
printf( "Error processing argument\n" );
return 1;
}
struct http_server* srv = http_server_new( args, handle_request, NULL );
if( !srv ) {
printf( "Error setting up server\n" );
app_args_release(args);
return 1;
return false;
}
http_server_set_debug( srv, true );
@ -57,8 +50,39 @@ int main( int argc, char* argv[] )
}
http_server_release( srv );
return true;
}
void inbox_handler()
{
}
int main( int argc, char* argv[] )
{
signal(SIGINT, handle_ctrl_c);
signal(SIGPIPE, SIG_IGN);
struct app_args* args = app_args_new( argc, argv );
if( !args ) {
printf( "Error processing argument\n" );
return 1;
}
int inbox_handler_pid = -1;
// Process inbox
if( !( inbox_handler_pid = fork() ) ) {
prctl(PR_SET_PDEATHSIG, SIGHUP);
process_inbox();
}
// TODO: Process outbox
int code = 0;
if( !run_webserver(args) ) { code = 1; }
app_args_release(args);
return 0;
return code;
}

@ -1 +1 @@
Subproject commit 5d06e72566f2fd9172209fe78b230af9b8f8e7d1
Subproject commit 8cb6d34eefd03de6fc0addbaef1768b492d9e081
Loading…
Cancel
Save