Fix memory leaks, implement Emoji federation, fix mention bug, fix other bugs

master
teknomunk 1 year ago
parent cb3d102c38
commit d41ebc7a24

@ -25,6 +25,7 @@ bool route_ap_note( struct http_request* req )
// Route: /note/%d{id}
int id = -1;
if( 1 != sscanf( id_str, "%d", &id ) ) { return false; }
free(id_str);
struct status* s = status_from_id( id );
if( !s ) { return false; }

@ -40,6 +40,8 @@ static bool handle_followers( struct http_request* req )
FILE* f = http_request_get_response_body(req);
#include "src/view/owner/followers.json.inc"
account_free( owner_account );
return true;
}
static bool handle_following( struct http_request* req )
@ -50,6 +52,7 @@ static bool handle_following( struct http_request* req )
FILE* f = http_request_get_response_body(req);
#include "src/view/owner/following.json.inc"
account_free( owner_account );
return true;
}
@ -61,6 +64,7 @@ static bool handle_owner_actor( struct http_request* req )
FILE* f = http_request_get_response_body(req);
#include "src/view/owner/actor.json.inc"
account_free( owner_account );
return true;
}

@ -1 +1 @@
Subproject commit 8d0ece286d44d710365b93b0dcbd569a7a573c52
Subproject commit ee80be2064a0399b9501dbb1ecd22d120c067a66

@ -1 +1 @@
Subproject commit 49765d54359b3537465ea432ba92fa955cf4a385
Subproject commit aa8efbacff4ac3d4b80e3ad7d5033e0450d0d28a

@ -9,6 +9,7 @@
#include "model/server.h"
#include "model/account.h"
#include "model/status.h"
#include "model/emoji.h"
#include "model/media.h"
#include "model/ap/outbox_envelope.h"
#include "model/ap/activity/rsa_signature_2017.h"
@ -360,12 +361,8 @@ int ap_activity_like( struct status* s )
struct ap_activity* ap_activity_create_note( struct status* s )
{
struct ap_activity* act = ap_activity_new();
struct account* a = account_from_id( s->account_id );
act->id = aformat( "https://%s/note/%d", g_server_name, s->id );
act->type = apat_note;
act->actor = strdup( a->account_url );
act->attributed_to = strdup( a->account_url );
act->published = s->published;
act->source.content = strdup(s->source);
act->content.content = strdup(status_render_source(s));
@ -374,6 +371,13 @@ struct ap_activity* ap_activity_create_note( struct status* s )
act->in_reply_to = strdup( s_in_reply_to->url );
status_free(s_in_reply_to);
}
/* set account related parameters */ {
struct account* a = account_from_id( s->account_id );
act->actor = strdup( a->account_url );
act->attributed_to = strdup( a->account_url );
account_free(a);
}
char* str = strdup("https://www.w3.org/ns/activitystreams#Public");
array_append( &act->to, sizeof(str), &str );
@ -393,6 +397,23 @@ struct ap_activity* ap_activity_create_note( struct status* s )
}
}
for( int i = 0; i < s->emoji.count; ++i ) {
struct emoji* e = s->emoji.items[i];
struct ap_activity_tag* tag;
tag = malloc(sizeof(*tag));
memset(tag,0,sizeof(*tag));
tag->type = aptag_emoji;
tag->updated = time(NULL);
tag->icon.url = strdup(e->url);
tag->id = strdup(e->url);
tag->icon.type = apot_image;
tag->name = aformat(":%s:", e->shortcode );
array_append( &act->tags, sizeof(tag), &tag );
}
str = aformat( "https://%s/owner/followers", g_server_name );
array_append( &act->cc, sizeof(str), &str );
@ -409,9 +430,10 @@ struct ap_activity* ap_activity_create_note( struct status* s )
tag->href = strdup(mentioned->account_url);
tag->name = aformat( "%s@%s", mentioned->handle, mentioned->server );
array_append( &act->tags, sizeof(tag), &tag );
account_free(mentioned);
}
account_free(a);
return act;
}

@ -80,7 +80,7 @@ struct json_object_field ap_activity_layout[] = {
.type = &ap_activity_context_type
},
JSON_FIELD_STRING(id,true),
JSON_FIELD_STRING(id,false),
JSON_FIELD_STRING(actor,false),
JSON_FIELD_STRING(state,false),

@ -27,8 +27,9 @@ char* filename_for_shortcode( const char* shortcode )
char* filename = NULL;
while( ent = readdir(d) ) {
if( 0 == strncmp( shortcode, ent->d_name, len ) && ent->d_name[len] == '.' ) {
char* res = strdup(ent->d_name);
closedir(d);
return strdup(ent->d_name);
return res;
}
}
closedir(d);
@ -37,8 +38,11 @@ char* filename_for_shortcode( const char* shortcode )
struct emoji* emoji_from_shortcode( const char* shortcode )
{
char* filename = filename_for_shortcode( shortcode );
if( !filename ) { return NULL; }
/* check for existence of emoji */ {
char* filename = filename_for_shortcode( shortcode );
if( !filename ) { return NULL; }
free(filename);
}
struct emoji* e;
e = malloc(sizeof(*e));

@ -85,12 +85,12 @@ void status_free( struct status* s );
void status_flag_for_async_fetch( struct status* s );
void status_add_reply( struct status* s, struct status* child );
void status_make_reply_to( struct status* s, int in_reply_to );
void status_get_context( struct status* s, void* ancestors, void* replies );
void status_add_to_timeline( struct status* s, int timeline_id );
void status_get_context( struct status* s, void* ancestors, void* replies );
void status_add_reply( struct status* s, struct status* child );
void status_add_mention( struct status* s, int id );
void status_make_reply_to( struct status* s, int in_reply_to );
void status_add_react( struct status* s, const char* react, struct account* a );
void status_remove_react( struct status* s, const char* react, struct account* a );
void status_add_like( struct status* s, struct account* a );

@ -1,6 +1,7 @@
#include "model/status.h"
#include "collections/array.h"
#include "format.h"
#include "model/account.h"
#include "model/emoji.h"
@ -21,6 +22,12 @@ char* status_render_source( struct status* s )
goto done;
}
char account_server[50]; {
struct account* status_account = account_from_id(s->account_id);
strncpy( account_server, status_account->server, 50 );
account_free(status_account);
}
char* result = NULL;
size_t size = 0;
FILE* f = open_memstream(&result,&size);
@ -37,11 +44,19 @@ char* status_render_source( struct status* s )
free(url);
} else if( isalpha(i[1]) && *i == '@' ) {
char* start = i;
while( *i && !index(" ,",*i) ) ++i;
while( *i && !index(" ,\r\n",*i) ) ++i;
char* handle = strndup( start, i - start );
struct account* user = account_from_webfinger( &handle[1] );
if( !user ) {
char buffer[512];
format( buffer, 512, "%s@%s", handle, account_server );
user = account_from_webfinger( &handle[1] );
}
if( user ) {
status_add_mention( s, user->id );
fprintf( f,
"<span class='h-card'>"
"<a class='u-url mention' href='%s' rel='ugc'>"
@ -93,6 +108,7 @@ char* status_render_source( struct status* s )
s->content = result;
done:
status_save(s);
return s->content;
}

@ -56,6 +56,7 @@ static bool api_Relationship_to_owner_writer( struct json_writer* jw, const char
struct account* owner_account = account_from_id( owner_account_id );
api_Relationship_write( field_data, owner_account, jw->f, jw->indent );
account_free(owner_account);
return true;
}

@ -48,6 +48,7 @@ static bool write_in_reply_to( struct json_writer* jw, const char* field_name, v
json_write_field_name(jw,"in_reply_to_id");
fprintf( jw->f, "null" );
}
status_free(in_reply_to);
return true;
}

Loading…
Cancel
Save