Start actual outbox processing

master
teknomunk 1 year ago
parent 8321a3fd41
commit e2bfe97745

@ -0,0 +1,4 @@
#!/bin/bash
rm src.a
find ./ -type f | grep -E '\.o$' | xargs -I'{}' rm '{}'

@ -1 +1 @@
Subproject commit eb86ce14d5441bf915db91833efdee7871baad4a
Subproject commit 2ca4ca869a52e3c493fab2f835065fdc1a8eeaca

@ -3,25 +3,108 @@
#include "fs_list.h"
#include "model/crypto/keys.h"
#include "model/account.h"
#include "sha256/sha256.h"
#include "collections/array.h"
#include <stdlib.h>
#include <stdio.h>
static void process_one()
{
int tail = fs_list_get("data/outbox/TAIL");
printf( "To handle: %d\n", tail );
}
void process_outbox()
static bool process_one( int id )
{
bool result = false;
struct crypto_keys* keys = crypto_keys_new();
FILE* f = NULL;
if( !crypto_keys_load_private( keys, "data/owner/private.pem" ) ) {
printf( "Failed to load private key\n" );
return false;
}
char buffer[512];
snprintf( buffer, 512, "data/outbox/%d.json", id );
f = fopen( buffer, "r" );
if( !f ) {
printf( "Unable to open file %s\n", buffer );
goto discard;
}
char* toline = NULL;
size_t n;
if( -1 == getline( &toline, &n, f ) ) {
printf( "no to line" );
free(toline);
goto failed;
}
if( strlen(toline) < 5 ) {
printf( "too short.\n" );
goto failed;
}
ARRAY_OF(char*) inboxes;
memset( &inboxes, 0, sizeof(inboxes) );
char* remainder = NULL;
char* iter = strtok_r( &toline[4],",",&remainder);
do
{
int id;
if( sscanf( iter, "%d", &id ) ) {
int compare( void* a, void* b ) { return strcmp( (char*)a, (char*)b ); }
struct account* to_account = account_from_id( id );
if( to_account ) {
if( to_account->inbox ) {
char* item_to_add = strdup(to_account->inbox);
array_append_unique( &inboxes, sizeof(item_to_add), &item_to_add, compare );
}
account_free(to_account);
}
}
iter = strtok_r( NULL,",",&remainder);
} while( iter );
free(toline);
for( int i = 0; i < inboxes.count; ++i ) {
printf( "item[%d] = %s\n", i, inboxes.items[i] );
}
void release( void* item ) { free( *(char**)item ); }
array_free( &inboxes, sizeof(char*), release );
// NOT FINISHED DEVELOPING
goto failed;
discard:
result = true;
cleanup:
crypto_keys_free(keys);
if( f ) { fclose(f); }
return result;
failed:
result = false;
goto cleanup;
}
void process_outbox()
{
int head = fs_list_get("data/outbox/HEAD");
int tail = fs_list_get("data/outbox/TAIL");
if( tail < head ) {
printf( "Processing outbox/%d.json\n", tail );
if( process_one(tail) ) {
printf( "Done with outbox/%d.json\n", tail );
fs_list_set( "data/outbox/TAIL", tail + 1 );
}
}
/*
char hash[32];
sha256_easy_hash( "Hello, World!", 13, hash );
@ -29,7 +112,7 @@ void process_outbox()
printf( "signature = %s\n", signature );
free(signature);
crypto_keys_free(keys);
*/
exit(0);
}

@ -35,6 +35,8 @@ static struct json_object_field account_layout[] = {
{ "avatar", offsetof( struct account, avatar.url ), true, &json_field_string },
{ "avatar_static", offsetof( struct account, avatar.static_url ), true, &json_field_string },
{ "account_url", offsetof( struct account, account_url ), true, &json_field_string },
{ "inbox", offsetof( struct account, inbox ), false, &json_field_string },
{ NULL },
};
@ -285,6 +287,7 @@ void account_sync_from_acitvity_pub( unsigned int account_id )
a->avatar.static_url = strdup(ap->avatar);
a->bot = ( ap->type != apacct_Person );
a->account_url = strdup(ap->url);
a->inbox = strdup(ap->inbox);
if( 0 == strncmp( ap->id, "https://", 8 ) ) {
char* server_name = strdup(&ap->id[8]);

@ -11,6 +11,7 @@ struct account
char* display_name;
char* account_url;
char* inbox;
struct {
char* url;

@ -203,11 +203,13 @@ struct ap_activity* ap_activity_create_accept( struct ap_activity* act )
array_append( &accept->to, sizeof(char*), &new_act_actor );
accept->object.tag = apaot_activity;
accept->object.ptr = ap_activity_dup(act);
/*
accept->has_signature = 1;
accept->signature.type = apst_rsa_signature_2017;
accept->signature.creator = strdup(actor);
accept->signature.created = strdup("TBD");
accept->signature.value = strdup("TBD");
*/
return accept;
}

Loading…
Cancel
Save