parent
b7bbc71eee
commit
076053dbb2
@ -0,0 +1,41 @@
|
||||
#include "owner.h"
|
||||
|
||||
#include "http_server/http_request.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static void write_public_key( FILE* f )
|
||||
{
|
||||
FILE* pubkey = fopen( "data/owner/public.pem", "r" );
|
||||
char ch;
|
||||
while( (ch = fgetc(pubkey)) != EOF ) {
|
||||
if( ch == '\n' ) {
|
||||
fprintf( f, "\\n" );
|
||||
} else {
|
||||
fputc(ch,f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_owner_actor( struct http_request* req )
|
||||
{
|
||||
const char* server = "apogee.polaris-1.work";
|
||||
struct account* owner_account = account_from_id(0);
|
||||
|
||||
http_request_send_headers( req, 200, "application/activity+json", true );
|
||||
FILE* f = http_request_get_response_body(req);
|
||||
#define RENDER
|
||||
#include "src/controller/owner_actor.json.inc"
|
||||
#undef RENDER
|
||||
}
|
||||
|
||||
bool route_owner( struct http_request* req )
|
||||
{
|
||||
if( http_request_route( req, "/actor" ) ) {
|
||||
handle_owner_actor(req);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "model/account.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
struct http_request;
|
||||
|
||||
bool route_owner( struct http_request* req );
|
||||
|
@ -0,0 +1,17 @@
|
||||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1"
|
||||
],
|
||||
|
||||
"id": "https://%s{server}/owner/actor",
|
||||
"type": "Person",
|
||||
"preferredUsername": "%s{owner_account->handle}",
|
||||
"inbox": "https://%s{server}/inbox",
|
||||
|
||||
"publicKey": {
|
||||
"id": "https://%s{server}/owner/actor#main-key",
|
||||
"owner": "https://%s{server}/owner/actor",
|
||||
"publicKeyPem": "%( write_public_key(f); )"
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
#include "webfinger.h"
|
||||
|
||||
#include "http_server/http_request.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
bool route_well_known( struct http_request* req )
|
||||
{
|
||||
// /.well-known/webfinger?resource=acct:teknomunk@apogee.polaris-1.work
|
||||
const char* key;
|
||||
char* resource;
|
||||
|
||||
while( key = http_request_route_query_key( req ) ) {
|
||||
if( 0 == strcmp(key,"resource") ) {
|
||||
resource = strdup(http_request_route_query_value(req) );
|
||||
} else {
|
||||
http_request_route_query_value(req);
|
||||
}
|
||||
}
|
||||
|
||||
char* server;
|
||||
strtok_r( resource, ":", &resource );
|
||||
char* account_name = strtok_r( resource, "@", &server );
|
||||
|
||||
// Verify the server name matches this instance
|
||||
// if( 0 != strcmp( server, this_server_hostname() ) ) { return false; }
|
||||
|
||||
http_request_send_headers( req, 200, "application/json", true );
|
||||
FILE* f = http_request_get_response_body(req);
|
||||
#define RENDER
|
||||
#include "src/controller/webfinger.json.inc"
|
||||
#undef RENDER
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
struct http_request;
|
||||
|
||||
bool route_well_known( struct http_request* );
|
||||
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"subject": "acct:%s{resource}@%s{server}",
|
||||
|
||||
"links": [
|
||||
{
|
||||
"rel": "self",
|
||||
"type": "application/activity+json",
|
||||
"href": "https://%s{server}/owner/actor"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in new issue