Move src/util/* to submodule, implement route for status quotes, fix path for embed tool

master
teknomunk 10 months ago
parent 5c8e403765
commit 1251c38c41

3
.gitmodules vendored

@ -31,3 +31,6 @@
[submodule "src/json-ld"]
path = src/json-ld
url = https://gitea.polaris-1.work/teknomunk/json-ld.git
[submodule "src/util"]
path = src/util
url = https://gitea.polaris-1.work/teknomunk/util.git

@ -4,7 +4,7 @@ set -e
rm debug release 2>/dev/null || true
find src | grep -E "\.template$" | while read FILE; do
ruby src/embed.rb "$FILE"
ruby tools/builder/tools/embed.rb "$FILE"
done
ruby tools/builder/build.rb src/apogee.build.json

@ -14,6 +14,20 @@
bool http_request_route_id( struct http_request* req, int* id );
// Route: /api/v1/pleroma/statuses/%d{s->id}/quotes
void show_status_quotes( struct http_request* req, struct status* s )
{
struct {
struct status** items;
int count;
} quotes;
status_get_quotes( s, &quotes );
printf( "Got %d statuses\n", quotes.count );
show_statuses( req, quotes.items, quotes.count );
}
// Route: /api/v1/pleroma/statuses/reactions/
static bool handle_reactions( struct http_request* req, struct status* s )
{
@ -57,8 +71,13 @@ static bool handle_reactions( struct http_request* req, struct status* s )
// Route: /api/v1/pleroma/statuses
static bool route_status( struct http_request* req, struct status* s )
{
printf( __FILE__ " route_status. Remaining: '%s'\n", http_request_get_remaining_path(req) );
if( http_request_route( req, "reactions/" ) ) {
return handle_reactions( req, s );
} else if( http_request_route_term( req, "quotes" ) ) {
printf( __FILE__ " quotes\n" );
show_status_quotes( req, s );
return true;
}
return false;
@ -88,6 +107,7 @@ bool route_pleroma_api2( struct http_request* req )
// Route: /api/v1/pleroma
bool route_pleroma_api( struct http_request* req )
{
printf( "route: route_pleroma_api\n" );
if( http_request_route( req, "/statuses" ) ) {
printf( "route: statuses\n" );
if( http_request_route( req, "/" ) ) {

@ -1 +1 @@
Subproject commit 2d81ba6575bfade5b2fbd723d2ec0e900fd4042f
Subproject commit 77149308f513caa5be458247b509c3fb7f7e5de3

@ -24,7 +24,7 @@ static size_t handle_header( char* header, size_t size, size_t nitems, void* use
int bytes = size * nitems;
int result = bytes;
printf( "? Header: |%.*s|\n", bytes, header );
//printf( "? Header: |%.*s|\n", bytes, header );
if( 0 != strncmp("onion-location: ",header,sizeof("onion-location: ")-1 ) ) {
return result;

@ -787,6 +787,23 @@ void status_get_context( struct status* s, void* ancestors_ptr, void* replies_pt
array_append( replies, sizeof(reply), &reply );
}
}
void status_get_quotes( struct status* s, void* quotes_ptr )
{
struct array_of_status {
struct status** items;
int count;
};
struct array_of_status* quotes = quotes_ptr;
memset( quotes, 0, sizeof(*quotes) );
for( int i = 0; i < s->quotes.count; ++i ) {
struct status* q = status_from_id( s->quotes.items[i] );
if( q ) {
array_append( quotes, sizeof(q), &q );
}
}
}
void status_add_react( struct status* s, const char* react, struct account* a )
{

@ -113,6 +113,7 @@ void status_flag_for_async_fetch( struct status* s );
void status_add_to_timeline( struct status* s, int timeline_id );
void status_get_context( struct status* s, void* ancestors, void* replies );
void status_get_quotes( struct status* s, void* quotes );
void status_add_mention( struct status* s, int id );
void status_add_tag( struct status* s, const char* tag );

@ -0,0 +1 @@
Subproject commit 24b374ef03befcff66499be372d089ade16e2381

@ -1,47 +0,0 @@
#define _GNU_SOURCE
#include "format.h"
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
const char* format( char* buffer, int size, const char* f, ... )
{
va_list args;
va_start(args,f);
vsnprintf( buffer, size, f, args );
va_end(args);
return buffer;
}
char* aformat( const char* f, ... )
{
va_list args;
va_start(args,f);
char* res = NULL;
vasprintf( &res, f, args );
va_end(args);
return res;
}
char* safe_strdup( const char* str )
{
if( !str ) { return NULL; }
return strdup(str);
}
void mkdir_p( const char* ch, int mode )
{
char buffer[512];
strncpy(buffer,ch,512);
char* rem = NULL;
char next_create[512] = "";
for( char* iter = strtok_r(buffer,"/",&rem); iter; iter = strtok_r(NULL,"/",&rem) ) {
strcat(next_create,iter);
mkdir( next_create, mode );
strcat(next_create,"/");
}
}

@ -1,7 +0,0 @@
#pragma once
const char* format( char* buffer, int size, const char* f, ... );
char* aformat( const char* f, ... );
char* safe_strdup( const char* str );
void mkdir_p( const char* ch, int mode );

@ -1 +1 @@
Subproject commit d94711a32676c69ecf492a50f030e132acd1647a
Subproject commit 41f6f54239a9b2f6638da67554db1305f2d69562
Loading…
Cancel
Save