Split out activity forward code, modify build script to allow rebuilding while apogee is running

master
teknomunk 1 year ago
parent f2a61e0b71
commit e93ace5584

@ -9,6 +9,7 @@ done
ruby tools/builder/build.rb --code src
mv src.bin apogee.debug
cp apogee.debug apogee
cp apogee.debug{,.tmp}
mv apogee.debug.tmp apogee
strip apogee

@ -13,12 +13,11 @@
#include "model/status.h"
#include "model/account.h"
#include "model/notification.h"
#include "model/activity.h"
#include "model/ap/inbox_envelope.h"
#include "model/crypto/http_sign.h"
#include "controller/inbox/follow.h"
#include "src/controller/api/client_apps.h"
#include "controller/inbox/forward.h"
// Stdlib
#include <stdio.h>
@ -449,50 +448,6 @@ bool route_activity( struct ap_object* act )
return false;
}
bool handle_forward( struct ap_envelope* env, struct ap_object* act )
{
char* authentication = NULL;
struct account* a = NULL;
bool result = false;
for( int i = 0; i < env->headers.count; ++i ) {
char* key = env->headers.items[i].key;
char* value = env->headers.items[i].value;
if( 0 == strcasecmp( "Authentication", key ) ) {
free(authentication);
authentication = strdup(value);
}
}
// Make sure this action is allowed
if( !authentication ) { return false; }
if( !check_bearer_token( authentication ) ) { goto failed; }
a = account_from_uri( act->actor );
if( !a->local ) { goto failed; };
// Save to disk
activity_allocate_local_id(act);
activity_save(act);
// Debug
printf( "Forwarding activity. act=" );
ap_object_write_to_FILE( act, stdout );
// TODO: try to inject to create a status
// Deliver activity
activity_deliver( act );
goto failed;
cleanup:
account_free(a);
free(authentication);
return result;
failed:
result = false;
goto cleanup;
}
static bool process_one()
{
// Items requiring cleanup

@ -0,0 +1,58 @@
#include "forward.h"
#include "http/server/request.h"
#include "model/ap/object.h"
#include "model/account.h"
#include "model/activity.h"
#include "model/ap/inbox_envelope.h"
#include "controller/api/client_apps.h"
#include <stdlib.h>
#include <string.h>
bool handle_forward( struct ap_envelope* env, struct ap_object* act )
{
char* authentication = NULL;
struct account* a = NULL;
bool result = false;
for( int i = 0; i < env->headers.count; ++i ) {
char* key = env->headers.items[i].key;
char* value = env->headers.items[i].value;
if( 0 == strcasecmp( "Authentication", key ) ) {
free(authentication);
authentication = strdup(value);
}
}
// Make sure this action is allowed
if( !authentication ) { return false; }
if( !check_bearer_token( authentication ) ) { goto failed; }
a = account_from_uri( act->actor );
if( !a->local ) { goto failed; };
// Save to disk
activity_allocate_local_id(act);
activity_save(act);
// Debug
printf( "Forwarding activity. act=" );
ap_object_write_to_FILE( act, stdout );
// TODO: try to inject to create a status
// Deliver activity
activity_deliver( act );
goto failed;
cleanup:
account_free(a);
free(authentication);
return result;
failed:
result = false;
goto cleanup;
}

@ -0,0 +1,8 @@
#pragma once
#include <stdbool.h>
struct ap_envelope;
struct ap_object;
bool handle_forward( struct ap_envelope* env, struct ap_object* act );
Loading…
Cancel
Save