diff --git a/src/http/microhttpd_server.cpp b/src/http/microhttpd_server.cpp index 6e4f3cb..59f38e7 100644 --- a/src/http/microhttpd_server.cpp +++ b/src/http/microhttpd_server.cpp @@ -129,7 +129,6 @@ namespace // Call response, ensure that the request above is proprogated well! std::optional resp = that->handle_request(req); - // TODO URGENT Slow to copy each time... Do alternative here. if (!resp) { // Return a 404 @@ -141,6 +140,7 @@ namespace MHD_destroy_response(response); return ret; } + // TODO URGENT Slow to copy each time... Do alternative here. response = MHD_create_response_from_buffer(resp->data.size(), (void*)(resp->data.data()), MHD_RESPMEM_MUST_COPY); diff --git a/src/protocol/masto-api/apps.cpp b/src/protocol/masto-api/apps.cpp index d3d0116..54316bc 100644 --- a/src/protocol/masto-api/apps.cpp +++ b/src/protocol/masto-api/apps.cpp @@ -7,7 +7,6 @@ #include #include -#include #include "mastoapi.h" #include "instance/instance.h" #include "http/mime.h" @@ -39,23 +38,26 @@ HTTP::Response Route::MastoAPI::create_app(std::any& args, rjson::Document root(rjson::kObjectType); rjson::Document::AllocatorType& a = root.GetAllocator(); + // Required parameters try { - const std::string& name = req.param.at("name").string(); - const std::string& redirect_uri = req.param.at("redirect_uri").string(); + const std::string& client_name = + req.param.at("client_name").string(); + const std::string& redirect_uris = + req.param.at("redirect_uris").string(); - root.AddMember("name", name, a); - root.AddMember("redirect_uri", redirect_uri, a); + root.AddMember("name", client_name, a); + root.AddMember("redirect_uri", redirect_uris, a); } catch (const std::out_of_range& err) { return HTTP::Error::make_json_error_response("Missing required parameters", HTTP::Code::BAD_REQUEST); } + // TODO scopes, bullshit aka for security freaks try { const std::string& website = req.param.at("website").string(); root.AddMember("website", website, a); - } - catch(...) { + } catch(...) { root.AddMember("website", rjson::Value(), a); } // Tokens @@ -77,6 +79,6 @@ void Protocol::MastoAPI::init_masto_apps(HTTP::Server* server) { HTTP::Request::Type::POST, "/api/v1/apps", - HTTP::MIME::Mimetypes::JSON + HTTP::MIME::Mimetypes::ANY }, Route::MastoAPI::create_app}); } diff --git a/src/protocol/masto-api/apps.h b/src/protocol/masto-api/apps.h index 83acebd..f3402aa 100644 --- a/src/protocol/masto-api/apps.h +++ b/src/protocol/masto-api/apps.h @@ -3,25 +3,16 @@ * Licensed under BSD 3-Clause. See LICENSE */ -#pragma once - +#ifndef APPS_H +#define APPS_H #include "http/httpserver.h" #include "http/response.h" -namespace Route -{ - namespace MastoAPI - { - HTTP::Response create_app(std::any& args, - HTTP::Request& req, - const HTTP::RequestArgs_t& arg); - } -} +HTTP::Response +Route::MastoAPI::create_app(std::any& args, + HTTP::Request& req, + const HTTP::RequestArgs_t& arg); +void +Protocol::MastoAPI::init_masto_apps(HTTP::Server* server); -namespace Protocol -{ - namespace MastoAPI - { - void init_masto_apps(HTTP::Server* server); - } -} +#endif // APPS_H diff --git a/src/protocol/masto-api/instance.cpp b/src/protocol/masto-api/instance.cpp new file mode 100644 index 0000000..af86ffb --- /dev/null +++ b/src/protocol/masto-api/instance.cpp @@ -0,0 +1,25 @@ +/* + * Wormhole - Federated social network + * Licensed under BSD 3-Clause. See LICENSE + */ + +#include "instance.h" +#include "route_args.h" + +#include + +HTTP::Response +Route::MastoAPI::get_instance(std::any& args, + HTTP::Request& req, + HTTP::RequestArgs_t const& arg) +{ + (void)args; + (void)req; + (void)arg; +} + +void +Protocol::MastoAPI::init_instance_info(HTTP::Server* server) +{ + +} diff --git a/src/protocol/masto-api/instance.h b/src/protocol/masto-api/instance.h new file mode 100644 index 0000000..f242648 --- /dev/null +++ b/src/protocol/masto-api/instance.h @@ -0,0 +1,17 @@ +/* + * Wormhole - Federated social network + * Licensed under BSD 3-Clause. See LICENSE + */ + +#ifndef INSTANCE_H +#define INSTANCE_H +#include "http/httpserver.h" + +HTTP::Response +Route::MastoAPI::create_instance(std::any& args, + HTTP::Request& req, + HTTP::RequestArgs_t const& arg); +void +Protocol::MastoAPI::init_instance_info(HTTP::Server* server); + +#endif // INSTANCE_H