Fix memory leaks, change Activity context writer to support extra schemas, language schema and add lite-pub schema by default, change hyperlink end detection

master
teknomunk 1 year ago
parent 16cb584feb
commit b06c9b4c48

1
.gitignore vendored

@ -9,5 +9,6 @@ data/
assets/soapbox/
backup/
vgcore.*
apogee*
/*.log
/*.json

@ -8,7 +8,7 @@ find src | grep -E "\.template$" | while read FILE; do
done
ruby tools/builder/build.rb --code src
mv src.bin debug
cp debug release
strip release
mv src.bin apogee.debug
cp apogee.debug apogee
strip apogee

@ -186,31 +186,52 @@ static struct account* lookup_actor_account( struct ap_activity* act )
static bool route_like( struct ap_activity* act )
{
struct status* s = NULL;
struct account* liker = NULL;
bool result = false;
int error;
struct status* s = lookup_object_status(act,&error);
struct account* liker = lookup_actor_account(act);
s = lookup_object_status(act,&error);
liker = lookup_actor_account(act);
if( !s ) {
if( error == error_lookup_failed ) {
return true;
}
return false;
if( error == error_lookup_failed ) { goto discard; }
goto failed;
};
status_add_like( s, liker );
return true;
discard:
result = true;
goto cleanup;
cleanup:
account_free(liker);
status_free(s);
return result;
failed:
result = false;
goto cleanup;
}
static bool route_emoji_react( struct ap_activity* act )
{
struct status* s = NULL;
struct account* reactor = NULL;
bool result = false;
int error;
struct status* s = lookup_object_status(act,&error);
struct account* reactor = lookup_actor_account(act);
if( !s || !reactor ) { return false; }
s = lookup_object_status(act,&error);
reactor = lookup_actor_account(act);
if( !s || !reactor ) { goto failed; }
status_add_react( s, act->content.content, reactor );
return true;
discard:
result = true;
goto cleanup;
cleanup:
status_free(s);
account_free(reactor);
return result;
failed:
result = false;
goto cleanup;
}
static bool route_update_Person( struct ap_activity* act )
@ -488,7 +509,7 @@ static bool process_one()
if( !env ) {
printf( "Failed to parse envelope+activity for data/inbox/%d.json\n", id );
return false;
goto failed;
}
// Load activity
@ -509,8 +530,8 @@ static bool process_one()
printf( "Processing %d\n", id );
step_tail = route_activity( act );
finished:
printf( "step_tail=%c\n", step_tail ? 'T' : 'F' );
cleanup:
printf( "\nstep_tail=%c\n", step_tail ? 'T' : 'F' );
if( step_tail ) {
fs_list_set( "data/inbox/TAIL", id );
result = true;
@ -522,11 +543,11 @@ finished:
return result;
failed:
result = false;
goto finished;
goto cleanup;
discard:
step_tail = true;
result = true;
goto finished;
goto cleanup;
}
bool cleanup_box( const char* box )

@ -11,6 +11,7 @@ bool route_announce( struct ap_activity* act )
{
bool result = false;
struct status* s = NULL;
struct status* original_post = NULL;
struct account* owner_account = account_from_id( owner_account_id );
struct account* actor_account = account_from_uri( act->actor );
if( !account_does_follow( owner_account, actor_account->id ) ) {
@ -29,7 +30,7 @@ bool route_announce( struct ap_activity* act )
goto failed;
}
struct status* original_post = status_fetch_from_uri( act->object.ref );
original_post = status_fetch_from_uri( act->object.ref );
if( !original_post ) {
goto discard;
}
@ -50,7 +51,7 @@ bool route_announce( struct ap_activity* act )
status_add_to_timeline( s, public_timeline_id );
status_add_to_timeline( s, actor_account->id );
result = true;
goto discard;
cleanup:
status_free(s);
status_free(original_post);

@ -37,6 +37,7 @@ const char* mime_type_for_filename( const char* filename )
{ ".mp3", "audio/mp3" },
{ ".ogg", "audio/ogg" },
{ ".oga", "audio/ogg" },
{ ".jsonld", "application/ld+json" },
{ NULL, NULL },
};

@ -1 +1 @@
Subproject commit febaf3e449be61fd285dbe8b410b1fbfbdde9e6a
Subproject commit d341958ce5faa9cd2b3b8f0796ff842c32cef2e9

@ -301,6 +301,7 @@ bool account_sync_from_activity_pub( unsigned int account_id )
fprintf( key_pem, "%s", ap->public_key.pem );
fclose(key_pem);
}
free(id);
account_save(a);
account_index_webfinger(a);

@ -55,6 +55,9 @@ struct ap_activity* ap_activity_dup( struct ap_activity* act )
new_tag->type = old_tag->type;
new_tag->href = safe_strdup(old_tag->href);
new_tag->name = safe_strdup(old_tag->name);
new_tag->updated = old_tag->updated;
new_tag->icon.type = old_tag->icon.type;
new_tag->icon.url = safe_strdup( old_tag->icon.url );
array_append( &new_act->tags, sizeof(new_tag), &new_tag );
}
@ -122,6 +125,10 @@ void ap_activity_free_composite( struct ap_activity* act )
free(act->actor);
free(act->context);
for( int i = 0; i < act->ap_context.extra.count; ++i ) {
free( act->ap_context.extra.items[i] );
}
free( act->ap_context.extra.items );
free(act->attributed_to);
free(act->target);
@ -172,7 +179,7 @@ void ap_activity_free_composite( struct ap_activity* act )
break;
case apaot_activity:
ap_activity_free( act->object.ptr );
act->object.ptr = 0;
act->object.ptr = NULL;
break;
};

@ -22,6 +22,7 @@ void ap_attachement_free( struct ap_attachement* a )
free(a->mediaType);
free(a->name);
free(a->url);
free(a->value);
free(a);
}
JSON_FIELD_TYPE_OBJECT_LAYOUT_WITH_DEFAULTS( ap_attachement );

@ -2,6 +2,9 @@
#include "json/layout.h"
#include "json/json.h"
#include "format.h"
#include "model/server.h"
#include "collections/array.h"
#include "collections/item_type/string.h"
@ -11,6 +14,15 @@
#include <stdlib.h>
#include <string.h>
static const char* langs[] = {
"und",
"en",
"de",
"fr",
"pt",
"ja",
};
static bool context_eat( struct json_pull_parser* jpp, int* save )
{
json_pull_parser_read_value(jpp);
@ -31,14 +43,6 @@ static bool context_read_language( struct json_pull_parser* jpp, struct ap_activ
if( !lang ) {
return false;
}
static const char* langs[] = {
"und",
"en",
"de",
"fr",
"pt",
"ja",
};
ctx->language = clang_unknown;
for( int i = 0; i < sizeof(langs)/sizeof(langs[0]); ++i ) {
//printf( "candidate: %s ==? %s\n", langs[i], lang );
@ -114,17 +118,26 @@ static bool context_writer( struct json_writer* jw, const char* field_name, void
struct ap_activity_context* ctx = field_data;
int items = 1;
int items = 2;
if( ctx ) {
ctx->extra.count + (ctx->language ? 1 : 0 );
items += ctx->extra.count + (ctx->language ? 1 : 0 );
}
if( items == 1 ) {
json_write_string( jw->f, "https://www.w3.org/ns/activitystreams" );
} else {
printf( "TODO: context_writer, handle array\n" );
exit(1);
fprintf( jw->f, "[" );
json_write_string( jw->f, "https://www.w3.org/ns/activitystreams" );
fprintf( jw->f, "," );
char buffer[512];
json_write_string( jw->f, format( buffer, 512, "https://%s/schemas/litepub-0.1.jsonld", g_server_name ) );
if( items > 2 ) {
for( int i = 0; i < ctx->extra.count; ++i ) {
fprintf( jw->f, "," );
json_write_string( jw->f, ctx->extra.items[i] );
}
if( ctx->language ) {
fprintf( jw->f, ",{ \"@language\":\"%s\"", langs[ctx->language] );
}
}
fprintf( jw->f, "]" );
return true;
}

@ -48,10 +48,11 @@ void ap_activity_tag_free( struct ap_activity_tag* tag )
{
if( !tag ) { return; }
free(tag->icon.url);
free(tag->href);
free(tag->name);
free(tag->id);
free(tag->icon.url);
free(tag->name);
memset(tag,0,sizeof(*tag));
free(tag);

@ -245,8 +245,12 @@ bool status_sync_from_activity_pub( struct status* s, struct ap_activity* act )
}
}
free(s->source);
s->source = safe_strdup(act->source.content);
free(s->url);
s->url = strdup( act->id );
if( !s->source ) {
printf( "? No source, using content directly\n" );
s->content = safe_strdup(act->content.content);
@ -352,6 +356,8 @@ bool status_sync( struct status* s )
}
struct status* status_from_uri_or_fetch( const char* uri )
{
struct status* s = status_from_uri(uri);
if( s ) { return s; }
return status_fetch_from_uri( uri );
}
struct status* status_fetch_from_uri( const char* uri )
@ -365,6 +371,7 @@ struct status* status_fetch_from_uri( const char* uri )
s->account_id = -1;
s->stub = true;
s->published = time(NULL);
free(s->url);
s->url = strdup(uri);
status_save_new(s);
@ -728,7 +735,8 @@ void status_add_like( struct status* s, struct account* a )
notification_save( note );
notification_free( note );
}
} else {
}
if( a->id == owner_account_id ) {
ap_activity_like( s );
}
}

@ -37,7 +37,7 @@ char* status_render_source( struct status* s )
// Handle URLs
if( 0 == strncmp( i, "https://", 8 ) ) {
char* start = i;
while( *i && !index(" ,",*i) ) ++i;
while( *i && !index(" ,\r\n\t",*i) ) ++i;
char* url = strndup( start, i - start );
fprintf( f, "<a href='%s' rel='ugc'>%s</a>", url, url );

Loading…
Cancel
Save