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.

67 lines
1.2 KiB
C

#include "status.h"
#include "model/account.h"
#include "json/json.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
static const char* host()
{
return "apogee.polaris-1.work";
}
struct status* status_from_id( unsigned int id )
{
struct status* s = NULL;
char filename[512];
snprintf( filename, 512, "data/statuses/%d.json", id );
FILE* f = fopen( filename, "r" );
if( !f ) { return NULL; }
struct json_pull_parser* jpp = json_pull_parser_new( f );
if( !jpp ) { return NULL; }
s = malloc(sizeof(struct status));
s->id = id;
s->account_id = -1;
int save;
if( !json_pull_parser_begin_object( jpp, &save ) ) { goto failed; }
char* key;
while( key = json_pull_parser_read_object_key(jpp) ) {
if( 0 == strcmp( key, "account_id" ) ) {
if( !json_pull_parser_read_int( jpp, &s->account_id ) ) { goto failed; }
}
}
if( !json_pull_parser_end_object(jpp, &save ) ) { goto failed; }
cleanup:
json_pull_parser_release(jpp);
fclose(f);
return s;
failed:
//status_free(s);
s = NULL;
goto cleanup;
}
void status_write_as_json( struct status* s, FILE* f )
{
struct account* account = account_from_id( s->account_id );
#define RENDER
#include "src/model/status.json.inc"
#undef RENDER
cleanup:
account_free(account);
}