Rework initialization to allow running only the web server for debugging without needing to recompile, implement status react serdes, update api to return statuses (Soapbox is not showing them...?)
parent
3f0b5dac86
commit
9292f5d15e
@ -1,7 +1,83 @@
|
||||
#include "react.h"
|
||||
|
||||
#include "json/json.h"
|
||||
#include "json/layout.h"
|
||||
#include "collections/array.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static bool reader( struct json_pull_parser* jpp, void* field_data, struct json_object_field* layout_field_data )
|
||||
{
|
||||
int save;
|
||||
if( !json_pull_parser_begin_object( jpp, &save ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct status_react* sr = *(void**)field_data = malloc(sizeof(struct status_react));
|
||||
memset(sr,0,sizeof(*sr));
|
||||
|
||||
char* key = json_pull_parser_read_object_key(jpp);
|
||||
if( !key ) { return false; }
|
||||
sr->code = key;
|
||||
|
||||
int save2;
|
||||
if( !json_pull_parser_begin_array(jpp,&save2)) { return false; }
|
||||
while( !json_pull_parser_end_array(jpp,&save2)) {
|
||||
int account_id;
|
||||
if( !json_pull_parser_read_int( jpp, &account_id ) ) {
|
||||
printf( "! Failed to read int\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
array_append( &sr->accounts, sizeof(int), &account_id );
|
||||
}
|
||||
|
||||
if( !json_pull_parser_end_object( jpp, &save ) ) {
|
||||
printf( "! Failed to end object\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
static bool writer( struct json_writer* jw, const char* field_name, void* field_data, struct json_object_field* layout_field_data )
|
||||
{
|
||||
struct status_react* sr = *(void**)field_data;
|
||||
|
||||
FILE* f = jw->f;
|
||||
fprintf( f, "{" );
|
||||
json_write_string( f, sr->code );
|
||||
fprintf( f, ",[" );
|
||||
for( int i = 0; i < sr->accounts.count; ++i ) {
|
||||
fprintf(f, (i!=0)?",%d":"%d", sr->accounts.items[i] );
|
||||
}
|
||||
fprintf( f, "]}" );
|
||||
|
||||
return true;
|
||||
}
|
||||
static void* alloc()
|
||||
{
|
||||
struct status_react* react;
|
||||
react = malloc(sizeof(*react));
|
||||
memset(react,0,sizeof(*react));
|
||||
|
||||
printf( "status::react::alloc = %p\n", react );
|
||||
|
||||
return react;
|
||||
}
|
||||
|
||||
static void free_react( void* ptr )
|
||||
{
|
||||
struct status_react* react = ptr;
|
||||
free(react->accounts.items);
|
||||
free(react);
|
||||
}
|
||||
|
||||
struct json_field_type status_react_type = {
|
||||
.reader = reader,
|
||||
.writer = writer,
|
||||
.size = sizeof(struct status_react*),
|
||||
.alloc = alloc,
|
||||
.free = free_react,
|
||||
};
|
||||
|
||||
|
Loading…
Reference in new issue