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.

54 lines
1.6 KiB
C

#include "http_server/http_request.h"
#include "controller/mastodon_api.h"
#include "controller/oauth.h"
#include "controller/webfinger.h"
#include "controller/nodeinfo.h"
#include "controller/owner.h"
bool route_asset( struct http_request* req )
{
static struct allowed_t {
const char* route_path;
const char* fs_path;
const char* mime_type;
} allowed[] = {
{ "style.css", "src/assets/style.css", "text/css" },
{ "jquery.js", "src/assets/jquery.js", "application/javascript" },
{ "jquery.plugins.js", "src/assets/jquery.plugins.js", "application/javascript" },
{ "background_noise.png","src/assets/background_noise.png", "image/png" },
{ "feed-icon-28x28.png", "src/assets/feed-icon-28x28.png", "image/png" },
};
for( int i = 0; i < sizeof(allowed)/sizeof(struct allowed_t); ++i ) {
if( http_request_route_term( req, allowed[i].route_path ) ) {
return http_request_send_file( req, allowed[i].fs_path, allowed[i].mime_type );
}
}
return false;
}
bool route_request( struct http_request* req )
{
if( http_request_route( req, "/api/v1/" ) ) {
return route_mastodon_api( req );
} else if( http_request_route( req, "/oauth" ) ) {
return route_oauth( req );
} else if( http_request_route( req, "/owner" ) ) {
return route_owner( req );
} else if( http_request_route( req, "/.well-known" ) ) {
if( http_request_route( req, "/webfinger?" ) ) {
return route_wellknown_webfinger( req );
} else if( http_request_route( req, "/nodeinfo" ) ) {
return route_wellknown_nodeinfo( req );
}
} else if( http_request_route( req, "/assets/" ) ) {
printf( "handling asset\n" );
return route_asset(req);
}
return false;
}