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.
90 lines
2.1 KiB
C
90 lines
2.1 KiB
C
1 year ago
|
#include "status.h"
|
||
|
|
||
|
#include "json/json.h"
|
||
|
|
||
|
#include "http_server/http_request.h"
|
||
|
#include "model/status.h"
|
||
|
#include "model/account.h"
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
void show_status( struct http_request* req, struct status* s )
|
||
|
{
|
||
|
http_request_send_headers( req, 200, "application/json", true );
|
||
|
FILE* f = http_request_get_response_body( req );
|
||
|
|
||
|
status_write_as_json(s,f);
|
||
|
}
|
||
|
void show_status_context( struct http_request* req, struct status* s )
|
||
|
{
|
||
|
http_request_send_headers( req, 200, "application/json", true );
|
||
|
FILE* f = http_request_get_response_body( req );
|
||
|
|
||
|
fprintf( f, "{\"ancestors\":[],\"descendants\":[]}" );
|
||
|
}
|
||
|
void show_statuses( struct http_request* req, struct status* ss, int count )
|
||
|
{
|
||
|
http_request_send_headers( req, 200, "application/json", true );
|
||
|
FILE* f = http_request_get_response_body( req );
|
||
|
|
||
|
fprintf( f, "[" );
|
||
|
for( int i = 0; i < count; ++i ) {
|
||
|
if( i > 0 ) {
|
||
|
fprintf( f, "," );
|
||
|
}
|
||
|
status_write_as_json(&ss[i],f);
|
||
|
}
|
||
|
fprintf( f, "]" );
|
||
|
}
|
||
|
|
||
|
bool handle_post( struct http_request* req, struct account* a )
|
||
|
{
|
||
|
printf( "TODO: new post" );
|
||
|
FILE* data = http_request_get_request_data( req );
|
||
|
|
||
|
struct json_pull_parser* jpp = json_pull_parser_new( data );
|
||
|
if( !jpp ) { return false; }
|
||
|
int save;
|
||
|
if( !json_pull_parser_begin_object( jpp, &save ) ) { return false; }
|
||
|
|
||
|
struct status s;
|
||
|
|
||
|
bool sensitive = false;
|
||
|
|
||
|
char* key;
|
||
|
while( key = json_pull_parser_read_object_key(jpp) ) {
|
||
|
if( 0 == strcmp(key,"media_ids") ) {
|
||
|
json_pull_parser_read_value(jpp);
|
||
|
|
||
|
} else if( 0 == strcmp(key,"sensitive") ) {
|
||
|
json_pull_parser_read_bool(jpp,&sensitive);
|
||
|
|
||
|
} else if( 0 == strcmp(key,"status") ) {
|
||
|
json_pull_parser_read_string(jpp);
|
||
|
|
||
|
} else if( 0 == strcmp(key,"visibility") ) {
|
||
|
json_pull_parser_read_string(jpp);
|
||
|
|
||
|
} else if( 0 == strcmp(key,"spoiler_text") ) {
|
||
|
json_pull_parser_read_string(jpp);
|
||
|
}
|
||
|
}
|
||
|
free(key);
|
||
|
|
||
|
if( !json_pull_parser_end_object(jpp, &save ) ) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
// {"media_ids":[],"sensitive":false,"status":"Test","visibility":"public","spoiler_text":""}
|
||
|
|
||
|
char ch;
|
||
|
while( (ch = fgetc(data)) != EOF ) {
|
||
|
printf( "%c", ch );
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|