Refactor http handler to allow checking query for JSON-LD requests, update public key layout

master
teknomunk 9 months ago
parent e239bec504
commit 70380d7600

@ -8,43 +8,48 @@
// Standard Library
#include <string.h>
bool ap_object_handle_http_request( struct http_request* req, struct ap_object* obj, bool release, bool default_jsonld )
bool ap_object_handle_http_request_should_provide( struct http_request* req )
{
bool result = false;
const char* accept_header = http_request_get_header( req, "Accept" );
const char* user_agent = http_request_get_header( req, "User-Agent" );
if( accept_header ) {
printf( "Accept: %s\n", accept_header );
if( strstr( accept_header, "application/ld+json" ) ) {
goto json_ld;
return true;
}
if( strstr( accept_header, "application/json" ) ) {
goto json_ld;
return true;
}
if( strstr( accept_header, "application/activity+json" ) ) {
goto json_ld;
return true;
}
}
if( user_agent ) {
printf( "User-Agent: %s\n", user_agent );
if( strstr( user_agent, "Pleroma" ) ) {
goto json_ld;
return true;
}
if( strstr( user_agent, "Mastodon" ) ) {
goto json_ld;
return true;
}
if( strstr( user_agent, "Akkoma" ) ) {
goto json_ld;
return true;
}
}
if( default_jsonld ) {
return false;
}
bool ap_object_handle_http_request( struct http_request* req, struct ap_object* obj, bool release, bool default_jsonld )
{
bool result = false;
if( ap_object_handle_http_request_should_provide( req ) ) {
goto json_ld;
} else if( default_jsonld ) {
goto json_ld;
} else {
goto failed;
}
goto failed;
json_ld:
FILE* f = http_request_get_response_body( req );
http_request_add_header( req, "Access-Control-Allow-Origin", "*" );

@ -5,5 +5,6 @@
struct http_request;
struct ap_object;
bool ap_object_handle_http_request_should_provide( struct http_request* req );
bool ap_object_handle_http_request( struct http_request* req, struct ap_object* obj, bool release, bool default_jsonld );

@ -240,8 +240,8 @@ struct ap_object
} capabilities;
//char* avatar;
//char* banner;
bool discoverable;
bool manually_approves_followers;
struct rich_bool discoverable;
struct rich_bool manually_approves_followers;
struct ap_public_key* public_key;
char* context;

@ -93,6 +93,7 @@ extern struct json_field_type total_items_type;
#define OBJ_TYPE struct ap_public_key
static struct json_object_field ap_public_key_layout[] = {
JSON_FIELD_STRING( id, true ),
JSON_FIELD_FIXED_STRING( type, "Key", false ),
JSON_FIELD_STRING( owner, true ),
{
.key = "publicKeyPem",
@ -267,11 +268,15 @@ struct json_object_field ap_object_layout[] = {
.offset = offsetof( OBJ_TYPE, image ),
.type = &ap_object_type,
},
JSON_FIELD_BOOL( discoverable, false ),
{
.key = "discoverable",
.offset = offsetof( OBJ_TYPE, discoverable ),
.type = &json_field_rich_bool,
},
{
.key = "manuallyApprovesFollowers",
.offset = offsetof( OBJ_TYPE, manually_approves_followers ),
.type = &json_field_bool,
.type = &json_field_rich_bool,
},
{
.key = "publicKey",

Loading…
Cancel
Save