Fix crash bugs, add Carbon-Emissions-Scope-2 witth garbage value, change bookmark handling

master
teknomunk 1 year ago
parent bd66e9bdb8
commit 51840b57a8

@ -1 +1 @@
Subproject commit 085331a08384befe0b68f217240a305c05040377
Subproject commit 9386994455054715b00f9747089a2b4d4da0182d

@ -24,6 +24,10 @@ bool route_add( struct ap_object* act )
goto failed;
} // Don't have ActivityPub account data, try again later
apa = account_get_activity_pub_data(a);
if( !apa ) {
printf( "Failed to get activity pub data for account %s\n", act->actor );
goto failed;
}
if( 0 != strcmp( apa->featured, act->target ) ) {
printf( "Not adding to featured...\n" );
printf( "apa->featured = %s\n", apa->featured );

@ -163,6 +163,8 @@ bool route_media( struct http_request* req )
bool route_request( struct http_request* req )
{
http_request_add_header( req, "Carbon-Emissions-Scope-2", "123456.789" );
bool inner( struct http_request* req ) {
if( http_request_route( req, "/oauth" ) ) {
return route_oauth( req );

@ -1,6 +1,7 @@
#include "test.h"
#include "test/crypto.h"
#include "ffdb/test.h"
#include "model/fetch.h"
#include <stdio.h>
@ -8,5 +9,11 @@ void built_in_test()
{
if( !ffdb_test() ) { printf( "[FAIL] ffdb_test\n" ); }
if( !test_crypto() ) { printf( "[FAIL] test_crypto\n" ); }
/*
printf( "\n\nTesting remote fetch\n" );
const char* target = "https://example.com/note/1";
if( !pull_remote_file( "/tmp/test.json", target ) ) { printf( "[FAIL] signed fetch\n" ); }
*/
}

@ -1 +1 @@
Subproject commit bcf56bd05285acca6f8da6be2714893a976ef8c6
Subproject commit a2aaf2399b7a5ba0ba75eb10ef69935155866c39

@ -144,20 +144,22 @@ bool account_sync_from_activity( struct account* a, struct ap_object* obj )
}
}
// Extract out the public key
char filename[512];
char* id = strdup(obj->public_key->id);
char* key_id = NULL;
strtok_r( id, "#", &key_id );
FILE* key_pem = fopen( format(filename,sizeof(filename),"data/accounts/%d/%s.pem", a->id, key_id), "w" );
if( !key_pem ) {
printf( "Unable to save public key to %s\n", filename );
} else {
printf( "Writing public key to %s\n", filename );
fprintf( key_pem, "%s", obj->public_key->public_key );
fclose(key_pem);
// Extract out the public key if present
if( obj->public_key ) {
char filename[512];
char* id = strdup(obj->public_key->id);
char* key_id = NULL;
strtok_r( id, "#", &key_id );
FILE* key_pem = fopen( format(filename,sizeof(filename),"data/accounts/%d/%s.pem", a->id, key_id), "w" );
if( !key_pem ) {
printf( "Unable to save public key to %s\n", filename );
} else {
printf( "Writing public key to %s\n", filename );
fprintf( key_pem, "%s", obj->public_key->public_key );
fclose(key_pem);
}
free(id);
}
free(id);
return true;
}

@ -70,12 +70,14 @@ static bool do_fetch( const char* uri, FILE* result )
char digest_header[512];
snprintf( digest_header, sizeof(digest_header), "Digest: %s", hs.digest );
printf( "digets_header = %s\n", digest_header );
printf( "digest_header = %s\n", digest_header );
char content_length_header[512];
snprintf( content_length_header, sizeof(content_length_header), "Content-Length: %d", hs.content_length );
printf( "content_length_header = %s\n", content_length_header );
fseek( result, 0, SEEK_SET );
const void* request2[] = {
HTTP_REQ_URL, uri,
HTTP_REQ_HEADER, user_agent,

@ -173,6 +173,8 @@ struct status* status_new_repost( struct status* s, struct account* a )
repost->repost_id = s->id;
repost->published = time(NULL);
status_add_repost( s, repost );
status_save_new(repost);
return repost;
}
@ -891,14 +893,16 @@ void status_set_bookmark( struct status* s )
s->bookmarked = true;
mkdir_p( "data/bookmarks", 0755 );
char key[32];
ffdb_trie_set( "data/owner/bookmarks", format(key,32,"%d",s->id), "T" );
ffdb_trie_set( "data/owner/bookmarks", format(key,32,"Z-%012d",s->id), "T" );
ffdb_trie_set( "data/owner/bookmarks", format(key,32,"%d",s->id), NULL ); // Clear older format
status_save(s);
}
void status_clear_bookmark( struct status* s )
{
s->bookmarked = false;
char key[32];
ffdb_trie_set( "data/owner/bookmarks", format(key,32,"%d",s->id), NULL );
ffdb_trie_set( "data/owner/bookmarks", format(key,32,"%d",s->id), NULL ); // Clear older format
ffdb_trie_set( "data/owner/bookmarks", format(key,32,"Z-%012d",s->id), NULL );
status_save(s);
}
@ -916,15 +920,51 @@ void status_get_bookmarks( int offset, int limit, void* results_ptr )
} *results = results_ptr;
results->count = 0;
ffdb_trie_list( "data/owner/bookmarks", offset, limit, &keys, NULL );
const char* index = "data/owner/bookmarks";
enum {
migrate_count = 10,
};
int count;
int clean_limit = count = ffdb_trie_count( index );
if( clean_limit > migrate_count ) {
clean_limit = migrate_count;
}
ffdb_trie_list( index, count - clean_limit, clean_limit, &keys, NULL );
for( int i = 0; i < keys.count; ++i ) {
int id;
if( 1 == sscanf( keys.items[i], "%d", &id ) ) {
struct status* s = status_from_id(id);
if( s ) {
array_append( results_ptr, sizeof(s), &s );
status_set_bookmark(s);
status_free(s);
}
}
free(keys.items[i]);
}
keys.count = 0;
ffdb_trie_list( index, offset, limit, &keys, NULL );
for( int i = 0; i < keys.count; ++i ) {
int id;
bool reset = false;
if( 1 == sscanf( keys.items[i], "Z-%012d", &id ) ) {
} else if( 1 == sscanf( keys.items[i], "%d", &id ) ) {
reset = true;
} else {
goto next_iteration;
}
struct status* s = status_from_id(id);
if( s ) {
array_append( results_ptr, sizeof(s), &s );
if( reset ) {
status_set_bookmark(s);
}
}
next_iteration:
free( keys.items[i] );
}
free( keys.items );

Loading…
Cancel
Save