|
|
|
@ -14,6 +14,10 @@
|
|
|
|
|
#include "model/account.h"
|
|
|
|
|
#include "model/activity.h"
|
|
|
|
|
#include "model/outbox_envelope.h"
|
|
|
|
|
#include "model/peer.h"
|
|
|
|
|
|
|
|
|
|
// Submodules
|
|
|
|
|
#include "http/url.h"
|
|
|
|
|
|
|
|
|
|
// Stdlib
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
@ -70,25 +74,42 @@ static bool process_envelope( struct outbox_envelope* env )
|
|
|
|
|
FILE* f = NULL;
|
|
|
|
|
struct ap_object* act = NULL;
|
|
|
|
|
struct account* to_account = NULL;
|
|
|
|
|
struct peer* p = NULL;
|
|
|
|
|
|
|
|
|
|
if( env->sent ) { return false; }
|
|
|
|
|
if( env->retry_after > time(NULL) ) { return false; }
|
|
|
|
|
if( env->account_id == 0 ) { goto discard; }
|
|
|
|
|
|
|
|
|
|
// Get outbox URL
|
|
|
|
|
to_account = account_from_id( env->account_id );
|
|
|
|
|
|
|
|
|
|
// Get inbox url
|
|
|
|
|
const char* inbox = to_account->inbox;
|
|
|
|
|
if( env->shared_inbox ) {
|
|
|
|
|
inbox = env->shared_inbox;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try to get peer information
|
|
|
|
|
char domain[512];
|
|
|
|
|
url_get_domain( inbox, domain,sizeof(domain) );
|
|
|
|
|
p = peer_create_from_domain( domain );
|
|
|
|
|
|
|
|
|
|
printf( "Processing outbox/%d.json\n", env->id );
|
|
|
|
|
printf( "shared_inbox=%s\b", env->shared_inbox );
|
|
|
|
|
printf( "inbox=%s\b", inbox );
|
|
|
|
|
printf( "account_id=%d\n", env->account_id );
|
|
|
|
|
printf( "activity_id=%d\n", env->activity_id );
|
|
|
|
|
|
|
|
|
|
if( p && p->admin_disable_outbox ) {
|
|
|
|
|
printf( "Delivery of activities to %s is administratively disabled\n", inbox );
|
|
|
|
|
goto discard;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check blacklist if at least one attempt to deliver has been made
|
|
|
|
|
if( ( env->retries > 0 ) && blacklisted( env ) ) {
|
|
|
|
|
printf( "Matched host blacklist\n" );
|
|
|
|
|
goto discard;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get outbox URL
|
|
|
|
|
to_account = account_from_id( env->account_id );
|
|
|
|
|
|
|
|
|
|
// Load crypto keys
|
|
|
|
|
keys = crypto_keys_new();
|
|
|
|
|
if( !crypto_keys_load_private( keys, "data/owner/private.pem" ) ) {
|
|
|
|
@ -119,11 +140,6 @@ static bool process_envelope( struct outbox_envelope* env )
|
|
|
|
|
postdata[size] = '\0';
|
|
|
|
|
printf( "post: %s\n", postdata );
|
|
|
|
|
|
|
|
|
|
const char* inbox = to_account->inbox;
|
|
|
|
|
if( env->shared_inbox ) {
|
|
|
|
|
inbox = env->shared_inbox;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct http_signature hs;
|
|
|
|
|
memset( &hs, 0, sizeof(hs) );
|
|
|
|
|
hs.input.url = inbox;
|
|
|
|
@ -178,6 +194,10 @@ static bool process_envelope( struct outbox_envelope* env )
|
|
|
|
|
|
|
|
|
|
if( status_code == 200 || status_code == 202 ) {
|
|
|
|
|
printf( "Submitted successfully\n" );
|
|
|
|
|
if( p ) {
|
|
|
|
|
p->last_successful_delivery = time(NULL);
|
|
|
|
|
peer_save(p);
|
|
|
|
|
}
|
|
|
|
|
goto discard;
|
|
|
|
|
} else {
|
|
|
|
|
printf( "\nServer returned status code %ld\n", status_code );
|
|
|
|
@ -191,6 +211,10 @@ static bool process_envelope( struct outbox_envelope* env )
|
|
|
|
|
}
|
|
|
|
|
env->retry_after = time(NULL) + 60 * ( env->retries + 1 ) * ( env->retries + 1 );
|
|
|
|
|
outbox_envelope_save(env);
|
|
|
|
|
if( p ) {
|
|
|
|
|
p->last_failed_delivery = time(NULL);
|
|
|
|
|
peer_save(p);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goto failed;
|
|
|
|
@ -199,6 +223,7 @@ cleanup:
|
|
|
|
|
ap_object_free(act);
|
|
|
|
|
account_free(to_account);
|
|
|
|
|
free(postdata);
|
|
|
|
|
peer_free(p);
|
|
|
|
|
|
|
|
|
|
crypto_keys_free(keys);
|
|
|
|
|
if( f ) { fclose(f); }
|
|
|
|
|