|
|
|
@ -8,6 +8,7 @@
|
|
|
|
|
#include "ffdb/fs_list.h"
|
|
|
|
|
#include "ffdb/hash_index.h"
|
|
|
|
|
#include "ffdb/trie.h"
|
|
|
|
|
#include "format.h"
|
|
|
|
|
|
|
|
|
|
// Model
|
|
|
|
|
#include "model/server.h"
|
|
|
|
@ -163,9 +164,9 @@ struct account* account_from_webfinger( const char* handle )
|
|
|
|
|
bool account_sync_from_acitvity_pub( unsigned int account_id )
|
|
|
|
|
{
|
|
|
|
|
char filename[512];
|
|
|
|
|
snprintf( filename, 512, "data/accounts/%d/ap.json", account_id );
|
|
|
|
|
|
|
|
|
|
struct ap_account* ap = ap_account_from_file( filename );
|
|
|
|
|
struct ap_account* ap = ap_account_from_file(
|
|
|
|
|
format( filename, 512, "data/accounts/%d/ap.json", account_id )
|
|
|
|
|
);
|
|
|
|
|
if( !ap ) {
|
|
|
|
|
printf( "! Failed to sync account %d from %s\n", account_id, filename );
|
|
|
|
|
return false;
|
|
|
|
@ -198,8 +199,7 @@ bool account_sync_from_acitvity_pub( unsigned int account_id )
|
|
|
|
|
char* id = strdup(ap->public_key.id);
|
|
|
|
|
char* key_id = NULL;
|
|
|
|
|
strtok_r( id, "#", &key_id );
|
|
|
|
|
snprintf( filename, sizeof(filename), "data/accounts/%d/%s.pem", a->id, key_id );
|
|
|
|
|
FILE* key_pem = fopen(filename,"w");
|
|
|
|
|
FILE* key_pem = fopen( format(filename,sizeof(filename),"data/accounts/%d/%s.pem", a->id, key_id), "w" );
|
|
|
|
|
fprintf( key_pem, "%s", ap->public_key.pem );
|
|
|
|
|
fclose(key_pem);
|
|
|
|
|
|
|
|
|
@ -213,8 +213,7 @@ bool account_sync_from_acitvity_pub( unsigned int account_id )
|
|
|
|
|
struct crypto_keys* account_get_public_key( struct account* a, const char* key_name )
|
|
|
|
|
{
|
|
|
|
|
char filename[512];
|
|
|
|
|
snprintf( filename, sizeof(filename), "data/accounts/%d/%s.pem", a->id, key_name );
|
|
|
|
|
FILE* f = fopen( filename, "r" );
|
|
|
|
|
FILE* f = fopen( format( filename, sizeof(filename), "data/accounts/%d/%s.pem", a->id, key_name ), "r" );
|
|
|
|
|
if( !f ) {
|
|
|
|
|
printf( "Failed to open file %s\n", filename );
|
|
|
|
|
return NULL;
|
|
|
|
@ -237,16 +236,13 @@ struct crypto_keys* account_get_private_key( struct account* a )
|
|
|
|
|
|
|
|
|
|
static void create_account_skeleton( int account_id )
|
|
|
|
|
{
|
|
|
|
|
char b[512];
|
|
|
|
|
|
|
|
|
|
// Make sure the account directory exists
|
|
|
|
|
char dirname[512];
|
|
|
|
|
snprintf( dirname, 512, "data/accounts/%d", account_id );
|
|
|
|
|
mkdir( dirname, 0755 );
|
|
|
|
|
snprintf( dirname, 512, "data/accounts/%d/timeline", account_id );
|
|
|
|
|
mkdir( dirname, 0755 );
|
|
|
|
|
mkdir( format( b, 512, "data/accounts/%d", account_id ), 0755 );
|
|
|
|
|
mkdir( format( b, 512, "data/accounts/%d/timeline", account_id ), 0755 );
|
|
|
|
|
|
|
|
|
|
char filename[512];
|
|
|
|
|
snprintf( filename, 512, "data/accounts/%d/timeline/HEAD", account_id );
|
|
|
|
|
fs_list_set( filename, 0 );
|
|
|
|
|
fs_list_set( format( b, 512, "data/accounts/%d/timeline/HEAD", account_id ), 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct account* account_fetch_from_uri( const char* uri )
|
|
|
|
@ -266,8 +262,7 @@ struct account* account_fetch_from_uri( const char* uri )
|
|
|
|
|
|
|
|
|
|
// Fetch the ActivityPub actor data if we don't already have it
|
|
|
|
|
char filename[512];
|
|
|
|
|
snprintf( filename, 512, "data/accounts/%d/ap.json", account_id );
|
|
|
|
|
FILE* f = fopen(filename,"r");
|
|
|
|
|
FILE* f = fopen( format( filename, 512, "data/accounts/%d/ap.json", account_id ), "r" );
|
|
|
|
|
if( !f ) {
|
|
|
|
|
char tmp_filename[512];
|
|
|
|
|
snprintf( tmp_filename, 512, "%s.tmp", filename );
|
|
|
|
@ -325,15 +320,22 @@ void account_save( struct account* a )
|
|
|
|
|
json_write_object_layout_to_file( filename, "\t", account_layout, a );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void account_add_follower( struct account* a, struct account* follower )
|
|
|
|
|
{
|
|
|
|
|
char filename[512];
|
|
|
|
|
snprintf( filename, sizeof(filename), "data/accounts/%d/followers", a->id );
|
|
|
|
|
|
|
|
|
|
// Insert an entry for this follower (only does something if not already set)
|
|
|
|
|
char filename[512];
|
|
|
|
|
char key[32];
|
|
|
|
|
snprintf( key, sizeof(key), "%d", follower->id );
|
|
|
|
|
ffdb_trie_set( filename, key, "T" );
|
|
|
|
|
ffdb_trie_set(
|
|
|
|
|
format( filename, sizeof(filename), "data/accounts/%d/followers", a->id ),
|
|
|
|
|
format(key,sizeof(key),"%d", follower->id),
|
|
|
|
|
"T"
|
|
|
|
|
);
|
|
|
|
|
ffdb_trie_set(
|
|
|
|
|
format( filename, sizeof(filename), "data/accounts/%d/following", follower->id ),
|
|
|
|
|
format(key,sizeof(key),"%d", a->id),
|
|
|
|
|
"T"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Update follower count
|
|
|
|
|
a->followers_count = ffdb_trie_count(filename);
|
|
|
|
@ -348,13 +350,17 @@ void account_add_follower( struct account* a, struct account* follower )
|
|
|
|
|
}
|
|
|
|
|
void account_remove_follower( struct account* a, struct account* follower )
|
|
|
|
|
{
|
|
|
|
|
char filename[512];
|
|
|
|
|
snprintf( filename, sizeof(filename), "data/accounts/%d/followers", a->id );
|
|
|
|
|
|
|
|
|
|
// Remove the follow
|
|
|
|
|
char filename[512];
|
|
|
|
|
char key[32];
|
|
|
|
|
snprintf( key, sizeof(key), "%d", follower->id );
|
|
|
|
|
ffdb_trie_remove( filename, key );
|
|
|
|
|
ffdb_trie_remove(
|
|
|
|
|
format( filename, sizeof(filename), "data/accounts/%d/followers", a->id ),
|
|
|
|
|
format( key, sizeof(key), "%d", follower->id )
|
|
|
|
|
);
|
|
|
|
|
ffdb_trie_remove(
|
|
|
|
|
format( filename, sizeof(filename), "data/accounts/%d/following", follower->id ),
|
|
|
|
|
format( key, sizeof(key), "%d", a->id )
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Update follower count
|
|
|
|
|
a->followers_count = ffdb_trie_count(filename);
|
|
|
|
|