You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.6 KiB
C

#include "forward.h"
#include "http/server/request.h"
#include "ap/object.h"
#include "model/account.h"
#include "model/status.h"
#include "model/activity.h"
#include "model/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; };
act->published = time(NULL);
act->id = strdup( a->account_url );
// Save to disk
activity_allocate_local_id(act);
activity_save(act);
// Debug
printf( "Forwarding activity. act=" );
ap_object_write_to_FILE( act, stdout );
// Try to inject to create a status
if( act->type == ap_Create ) {
struct status* s = status_from_activity( act );
if( s ) {
status_save_new(s);
account_create( a, s );
}
} else if( act->type == ap_Announce ) {
struct status* s = status_from_uri( act->object.ref );
if( s ) {
status_free( account_announce( a, s, NULL, act ) );
}
} else {
// Deliver activity
activity_deliver( act );
}
goto failed;
cleanup:
account_free(a);
free(authentication);
return result;
failed:
result = false;
goto cleanup;
}