parent
65756c5795
commit
04e1ef6e32
@ -1 +1 @@
|
||||
Subproject commit 9baefa441da46e353691c0e12ac0b008afd4802d
|
||||
Subproject commit a2b0ead640581ff9c7bfeeb2025bb62ff9ee6a06
|
@ -0,0 +1,41 @@
|
||||
#include "inbox_envelope.h"
|
||||
|
||||
#include "json/json.h"
|
||||
#include "json/layout.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
|
||||
static struct json_object_field envelope_layout[] = {
|
||||
{ "signature", offsetof(struct ap_envelope, signature), true, &json_field_string },
|
||||
{ "date", offsetof(struct ap_envelope, date), true, &json_field_string },
|
||||
{ "when", offsetof(struct ap_envelope, when), true, &json_field_string },
|
||||
{ "body", offsetof(struct ap_envelope, activity), true, &json_field_object_composite, ap_activity_layout },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
struct ap_envelope* ap_envelope_from_id( int id )
|
||||
{
|
||||
char filename[512];
|
||||
snprintf( filename, 512, "data/inbox/%d.json", id );
|
||||
|
||||
struct ap_envelope* env = malloc(sizeof(struct ap_envelope));
|
||||
|
||||
if( !json_read_object_layout_from_file( filename, envelope_layout, env ) ) {
|
||||
ap_envelope_free(env);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return env;
|
||||
}
|
||||
|
||||
void ap_envelope_free( struct ap_envelope* env )
|
||||
{
|
||||
if( !env ) { return; }
|
||||
|
||||
free(env->signature);
|
||||
free(env->date);
|
||||
free(env->when);
|
||||
free(env);
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "activity.h"
|
||||
|
||||
struct ap_envelope
|
||||
{
|
||||
char* signature;
|
||||
char* date;
|
||||
char* when;
|
||||
|
||||
struct ap_activity activity;
|
||||
};
|
||||
|
||||
struct ap_envelope* ap_envelope_from_id( int id );
|
||||
void ap_envelope_free( struct ap_envelope* env );
|
||||
|
Loading…
Reference in new issue