master
parent
f2a61e0b71
commit
e93ace5584
@ -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…
Reference in new issue