#include "forward.h" #include "http/server/request.h" #include "ap/object.h" #include "model/account.h" #include "model/activity.h" #include "model/inbox_envelope.h" #include "controller/api/client_apps.h" #include #include 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; }