diff --git a/src/controller/api/status.c b/src/controller/api/status.c index 7a3bd1b..d2ed674 100644 --- a/src/controller/api/status.c +++ b/src/controller/api/status.c @@ -228,6 +228,7 @@ bool handle_post( struct http_request* req, struct account* a ) status_make_quote_of( s, atoi(id) ); } + s->url = aformat( "https://%s/note/%d", g_server->domain, s->id ); // Save status data status_save(s); diff --git a/src/controller/did.c b/src/controller/did.c new file mode 100644 index 0000000..3f45386 --- /dev/null +++ b/src/controller/did.c @@ -0,0 +1,8 @@ +#include "did.h" + +bool route_wellknown_did( struct http_request* req ) +{ + // TODO: implement Decentralized Identifier (DID) handler + return false; +} + diff --git a/src/controller/did.h b/src/controller/did.h new file mode 100644 index 0000000..80d7bc0 --- /dev/null +++ b/src/controller/did.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +struct http_request; + +bool route_wellknown_did( struct http_request* req ); + diff --git a/src/controller/inbox.c b/src/controller/inbox.c index 0ef7f69..b2de883 100644 --- a/src/controller/inbox.c +++ b/src/controller/inbox.c @@ -28,6 +28,7 @@ #include #include #include +#include extern bool terminate; @@ -561,6 +562,22 @@ bool route_activity( struct ap_object* act ) return false; } +int find_next_inbox_id() +{ + int res = 0; + DIR* d = opendir("data/inbox/"); + struct dirent* entry; + char* remain; + while( (entry=readdir(d)) ) { + res = strtol(entry->d_name,&remain,10); + if( 0 != strcmp( remain, ".json" ) ) { continue; } + + break; + } + closedir(d); + return res; +} + static bool process_one() { // Items requiring cleanup @@ -568,6 +585,7 @@ static bool process_one() struct ap_envelope* env = NULL; bool result = false; + /* int tail_pos = fs_list_get("data/inbox/TAIL"); int head_pos = fs_list_get("data/inbox/HEAD"); if( head_pos <= tail_pos ) { return false; } @@ -576,10 +594,13 @@ static bool process_one() printf( "Inbox has %d items pending processing...\n", (head_pos - tail_pos) ); int id = tail_pos + 1; + */ + int id = find_next_inbox_id(); + if( id == 0 ) { return false; } printf( "Next item is #%d\n", id ); env = ap_envelope_from_id(id); - bool step_tail = false; + //bool step_tail = false; if( !env ) { printf( "! Failed to parse envelope+activity for data/inbox/%d.json\n", id ); @@ -647,11 +668,17 @@ static bool process_one() } cleanup: + /* printf( "\nstep_tail=%c\n", step_tail ? 'T' : 'F' ); if( step_tail ) { fs_list_set( "data/inbox/TAIL", id ); result = true; } + */ + + char filename[512]; + snprintf( filename, 512, "data/inbox/%d.json", id ); + remove(filename); ap_object_free(act); ap_envelope_free(env); @@ -663,11 +690,12 @@ failed: result = false; goto cleanup; discard: - step_tail = true; + //step_tail = true; result = true; goto cleanup; } +/* bool cleanup_box( const char* box ) { char tail[512]; @@ -695,6 +723,7 @@ bool cleanup_box( const char* box ) } return false; } +*/ void process_inbox() { @@ -703,7 +732,7 @@ void process_inbox() while( !terminate ) { bool activity = false; activity |= process_one(); - activity |= cleanup_box( "data/inbox" ); + //activity |= cleanup_box( "data/inbox" ); if( !activity ) { fflush(stdout); diff --git a/src/controller/main.c b/src/controller/main.c index 2413a72..eab8478 100644 --- a/src/controller/main.c +++ b/src/controller/main.c @@ -8,16 +8,18 @@ #include "model/server.h" // Controller +#include "controller/activity_pub.h" +#include "controller/admin.h" +#include "controller/api/emoji.h" +#include "controller/did.h" +#include "controller/inbox.h" #include "controller/mastodon_api.h" -#include "controller/pleroma_api.h" -#include "controller/oauth.h" -#include "controller/webfinger.h" #include "controller/nodeinfo.h" +#include "controller/oauth.h" #include "controller/owner.h" -#include "controller/inbox.h" -#include "controller/activity_pub.h" -#include "controller/api/emoji.h" -#include "controller/admin.h" +#include "controller/pleroma_api.h" +#include "controller/urn.h" +#include "controller/webfinger.h" // Standard Library #include @@ -195,6 +197,15 @@ bool route_request( struct http_request* req ) } else if( http_request_route( req, "/.well-known" ) ) { if( http_request_route( req, "/webfinger?" ) ) { return route_wellknown_webfinger( req ); + + // DID handler + } else if( http_request_route( req, "did:" ) ) { + return route_wellknown_did( req ); + + // URN handler + } else if( http_request_route( req, "urn:" ) ) { + return route_wellknown_urn( req ); + } else if( http_request_route( req, "/nodeinfo" ) ) { printf( "Nodeinfo\n" ); return route_wellknown_nodeinfo( req ); diff --git a/src/controller/urn.c b/src/controller/urn.c new file mode 100644 index 0000000..aafb43d --- /dev/null +++ b/src/controller/urn.c @@ -0,0 +1,9 @@ +#include "urn.h" + +bool route_wellknown_urn( struct http_request* req ) +{ + + + return false; +} + diff --git a/src/controller/urn.h b/src/controller/urn.h new file mode 100644 index 0000000..2b122e5 --- /dev/null +++ b/src/controller/urn.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +struct http_request; + +bool route_wellknown_urn( struct http_request* req ); + diff --git a/src/model/activity.c b/src/model/activity.c index fa4fb26..77ef051 100644 --- a/src/model/activity.c +++ b/src/model/activity.c @@ -238,7 +238,7 @@ int activity_like( struct status* s ) struct ap_object* activity_create_Note( struct status* s ) { struct ap_object* act = activity_new_local_activity(); - act->id = aformat( "https://%s/note/%d", g_server->domain, s->id ); + act->id = strdup( s->url ); act->type = ap_Note; act->published = s->published; if( s->source ) { diff --git a/src/model/fetch.c b/src/model/fetch.c index 46d8f8c..3ec8c70 100644 --- a/src/model/fetch.c +++ b/src/model/fetch.c @@ -90,7 +90,7 @@ static bool do_fetch_tor( const char* uri, struct fetch_data* fd, const char* re HTTP_REQ_RESULT_STATUS, &status_code, HTTP_RES_HEADER_CALLBACK, fetch_handle_header, (void*)fd, HTTP_REQ_PROXY, proxy, - HTTP_REQ_TIMEOUT, (void*)10, + HTTP_REQ_TIMEOUT, (void*)5, NULL, }; printf( "GET %s\n", uri ); @@ -213,7 +213,7 @@ static bool do_fetch_signed_clearnet( const char* uri, struct fetch_data* fd, co HTTP_REQ_HEADER, "Accept: application/activity+json", HTTP_REQ_OUTFILE, result, HTTP_REQ_RESULT_STATUS, &status_code, - HTTP_REQ_TIMEOUT, (void*)10, + HTTP_REQ_TIMEOUT, (void*)2, NULL, }; @@ -243,7 +243,7 @@ static bool do_fetch( const char* uri, const char* fh ) bool result = false; - if( do_fetch_tor( uri, &fd, fh ) ) { + if( fd.p && fd.p->last_tor_delivery && do_fetch_tor( uri, &fd, fh ) ) { goto success; } if( do_fetch_clearnet( uri, &fd, fh ) ) { diff --git a/src/model/status.c b/src/model/status.c index e29f03a..3637453 100644 --- a/src/model/status.c +++ b/src/model/status.c @@ -31,6 +31,7 @@ #include #include #include +#include #define STATUSES_BY_URI "data/statuses/by-uri"