You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
3.1 KiB
C
141 lines
3.1 KiB
C
#include "account.h"
|
|
|
|
#include "json/json.h"
|
|
#include "json/layout.h"
|
|
|
|
#include <stddef.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
static struct json_enum ap_account_type_enum[] = {
|
|
{ "Person", apacct_Person },
|
|
{ NULL, 0 },
|
|
};
|
|
|
|
#define OBJ_TYPE struct ap_crypto_key
|
|
static struct json_object_field public_key_layout[] = {
|
|
JSON_FIELD_STRING( id, true ),
|
|
JSON_FIELD_STRING( owner, true ),
|
|
{
|
|
.key = "publicKeyPem",
|
|
.offset = offsetof(struct ap_crypto_key,pem),
|
|
.required = true,
|
|
.type = &json_field_string
|
|
},
|
|
JSON_FIELD_END,
|
|
};
|
|
#undef OBJ_TYPE
|
|
|
|
static struct json_object_field icon_layout[] = {
|
|
{
|
|
.key = "url",
|
|
.offset = offsetof(struct ap_account,avatar),
|
|
.required = true,
|
|
.type = &json_field_string
|
|
},
|
|
JSON_FIELD_END,
|
|
};
|
|
|
|
static struct json_object_field image_layout[] = {
|
|
{
|
|
.key = "url",
|
|
.offset = offsetof(struct ap_account,banner),
|
|
.required = true,
|
|
.type = &json_field_string
|
|
},
|
|
JSON_FIELD_END,
|
|
};
|
|
|
|
#define OBJ_TYPE struct ap_account
|
|
static struct json_object_field endpoints_layout[] = {
|
|
{
|
|
.key = "sharedInbox",
|
|
.offset = offsetof(OBJ_TYPE,shared_inbox),
|
|
.required = false,
|
|
.type = &json_field_string,
|
|
},
|
|
};
|
|
static struct json_object_field ap_account_layout[] = {
|
|
JSON_FIELD_STRING( id, true ),
|
|
JSON_FIELD_ENUM( type, ap_account_type_enum, true ),
|
|
JSON_FIELD_STRING( url, true ),
|
|
JSON_FIELD_STRING( name, false ),
|
|
JSON_FIELD_STRING( preferredUsername, true ),
|
|
JSON_FIELD_STRING( inbox, true ),
|
|
JSON_FIELD_STRING( summary, true ),
|
|
JSON_FIELD_STRING( featured, false ),
|
|
JSON_FIELD_STRING( followers, false ),
|
|
JSON_FIELD_STRING( following, false ),
|
|
{
|
|
.key = "publicKey",
|
|
.offset = offsetof(struct ap_account,public_key),
|
|
.required = false,
|
|
.type = &json_field_object_composite,
|
|
.composite_layout = public_key_layout
|
|
},
|
|
{
|
|
.key = "endpoints",
|
|
.offset = 0,
|
|
.required = false,
|
|
.type = &json_field_object_composite,
|
|
.composite_layout = endpoints_layout,
|
|
},
|
|
JSON_FIELD_BOOL( discoverable, false ),
|
|
{
|
|
.key = "icon",
|
|
.offset = 0,
|
|
.required = false,
|
|
.type = &json_field_object_composite,
|
|
.composite_layout = icon_layout
|
|
},
|
|
{
|
|
.key = "image",
|
|
.offset = 0,
|
|
.required = false,
|
|
.type = &json_field_object_composite,
|
|
.composite_layout = image_layout
|
|
},
|
|
JSON_FIELD_END,
|
|
};
|
|
#undef OBJ_TYPE
|
|
|
|
struct ap_account* ap_account_from_file( const char* filename )
|
|
{
|
|
struct ap_account* acc = malloc(sizeof(struct ap_account));
|
|
memset(acc,0,sizeof(struct ap_account));
|
|
|
|
if( !json_read_object_layout_from_file( filename, ap_account_layout, acc ) ) {
|
|
ap_account_free(acc);
|
|
return NULL;
|
|
}
|
|
|
|
return acc;
|
|
}
|
|
|
|
void ap_account_free( struct ap_account* acc )
|
|
{
|
|
if( !acc ) { return; }
|
|
|
|
free(acc->id);
|
|
free(acc->url);
|
|
free(acc->name);
|
|
free(acc->preferredUsername);
|
|
free(acc->inbox);
|
|
free(acc->outbox);
|
|
free(acc->featured);
|
|
free(acc->followers);
|
|
free(acc->following);
|
|
free(acc->avatar);
|
|
free(acc->banner);
|
|
free(acc->summary);
|
|
|
|
free(acc);
|
|
}
|
|
void ap_account_debug_dump( struct ap_account* acc )
|
|
{
|
|
json_write_object_layout_to_FILE( stdout, "\t", ap_account_layout, acc );
|
|
//FILE* f = stdout;
|
|
//#include "src/model/ap/account.debug_dump.txt.inc"
|
|
}
|
|
|