|
|
|
@ -155,6 +155,15 @@ bool handle_announcements( struct http_request* req )
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// route: GET /api/v1/directory
|
|
|
|
|
bool handle_directory( struct http_request* req )
|
|
|
|
|
{
|
|
|
|
|
http_request_send_headers( req, 200, "application/json", true );
|
|
|
|
|
FILE* f = http_request_get_response_body( req );
|
|
|
|
|
fprintf( f, "[]" );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// route: GET /api/v1/blocks
|
|
|
|
|
bool handle_blocks( struct http_request* req )
|
|
|
|
|
{
|
|
|
|
@ -167,7 +176,55 @@ bool handle_blocks( struct http_request* req )
|
|
|
|
|
// route: POST /api/v1/markers
|
|
|
|
|
bool handle_update_markers( struct http_request* req )
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
FILE* f = http_request_get_request_data(req);
|
|
|
|
|
struct json_pull_parser* jpp = json_pull_parser_new(f);
|
|
|
|
|
|
|
|
|
|
int save = 0;
|
|
|
|
|
if( !json_pull_parser_begin_object(jpp,&save) ) { return false; }
|
|
|
|
|
|
|
|
|
|
char* key = json_pull_parser_read_object_key(jpp);
|
|
|
|
|
if( !key ) { return false; }
|
|
|
|
|
char* marker_name = key;
|
|
|
|
|
|
|
|
|
|
int save2 = 0;
|
|
|
|
|
if( !json_pull_parser_begin_object(jpp,&save2) ) { return false; }
|
|
|
|
|
|
|
|
|
|
char* last_read_id;
|
|
|
|
|
|
|
|
|
|
while( (key=json_pull_parser_read_object_key(jpp)) ) {
|
|
|
|
|
if( 0 == strcmp(key,"last_read_id") ) {
|
|
|
|
|
last_read_id = json_pull_parser_read_string(jpp);
|
|
|
|
|
} else {
|
|
|
|
|
json_pull_parser_read_value(jpp,NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if( !json_pull_parser_end_object(jpp,&save2) ) { return false; }
|
|
|
|
|
|
|
|
|
|
struct marker* m = marker_from_name(marker_name);
|
|
|
|
|
|
|
|
|
|
if( last_read_id ) {
|
|
|
|
|
free(m->last_read_id);
|
|
|
|
|
m->last_read_id = last_read_id;
|
|
|
|
|
m->version += 1;
|
|
|
|
|
|
|
|
|
|
marker_save(m);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
http_request_send_headers( req, 200, "application/json", true );
|
|
|
|
|
FILE* o = http_request_get_response_body(req);
|
|
|
|
|
fprintf(o,"{");
|
|
|
|
|
fprintf(o,"\"%s\":",key);
|
|
|
|
|
marker_write_to_FILE(m,o);
|
|
|
|
|
fprintf(o,"}");
|
|
|
|
|
|
|
|
|
|
marker_free(m);
|
|
|
|
|
|
|
|
|
|
if( !json_pull_parser_end_object(jpp,&save) ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
json_pull_parser_release(jpp);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// route: GET /api/v1/markers
|
|
|
|
@ -313,6 +370,8 @@ bool route_mastodon_api( struct http_request* req )
|
|
|
|
|
return handle_announcements(req);
|
|
|
|
|
} else if( http_request_route( req, "blocks" ) ) {
|
|
|
|
|
return handle_blocks(req);
|
|
|
|
|
} else if( http_request_route( req, "directory" ) ) {
|
|
|
|
|
return handle_directory(req);
|
|
|
|
|
} else if( http_request_route( req, "markers" ) ) {
|
|
|
|
|
if( http_request_route_method( req, "POST" ) ) {
|
|
|
|
|
return handle_update_markers(req);
|
|
|
|
|