diff --git a/src/ext/lmhpp b/src/ext/lmhpp index 5c49ae6..d1cbd33 160000 --- a/src/ext/lmhpp +++ b/src/ext/lmhpp @@ -1 +1 @@ -Subproject commit 5c49ae6edc0c2869d4be0158e4e08e7ff992dc34 +Subproject commit d1cbd33c13951116055b5590e0089708ccfd2c6c diff --git a/src/service/httpd/handlers/dispatchers.cpp b/src/service/httpd/handlers/dispatchers.cpp index f1e6ea6..7147801 100644 --- a/src/service/httpd/handlers/dispatchers.cpp +++ b/src/service/httpd/handlers/dispatchers.cpp @@ -15,12 +15,15 @@ namespace sx::webserver::dispatchers { - void controller_add_debug_only(lmh::WebServer &server) { -#ifndef BUILD_RELEASE - static Http_Responder status_ping( + void controller_add_status(lmh::WebServer &server) { + auto* status_ping = new Http_Responder( "POST", "/api/status/ping", +#ifndef BUILD_RELEASE authorized::unprotected( +#else + authorized::token_protected( +#endif []([[maybe_unused]] MHD_Connection *c, [[maybe_unused]] std::string const &meth, [[maybe_unused]] std::string const &req) -> json { time_t uptime = time(nullptr) - SmithProxy::instance().ts_sys_started; return {{"version", SMITH_VERSION}, @@ -29,13 +32,13 @@ namespace sx::webserver::dispatchers { {"uptime_str", uptime_string(uptime)}}; })); - status_ping.Content_Type = "application/json"; - server.addController(&status_ping); -#endif + status_ping->Content_Type = "application/json"; + server.addController(std::shared_ptr(status_ping)); + } void controller_add_commons(lmh::WebServer& server) { - static Http_Responder cacert( + auto* cacert = new Http_Responder( "GET", "/cacert", authorized::unprotected( @@ -50,121 +53,119 @@ namespace sx::webserver::dispatchers { return pem_ca_cert; })); - cacert.Content_Type = "application/x-pem-file"; - server.addController(&cacert); + cacert->Content_Type = "application/x-pem-file"; + server.addController(std::shared_ptr(cacert)); } void controller_add_diag(lmh::WebServer &server) { for(auto const& meth: { "GET", "POST"}) { - static Http_Responder handler(meth, "/api/diag/ssl/cache/stats", + auto* handler = new Http_Responder(meth, "/api/diag/ssl/cache/stats", authorized::token_protected(json_ssl_cache_stats)); - handler.Content_Type = "application/json"; - server.addController(&handler); + handler->Content_Type = "application/json"; + server.addController(std::shared_ptr(handler)); } for(auto const& meth: {"GET", "POST"}) { - static Http_Responder handler( + auto* handler = new Http_Responder( meth, "/api/diag/ssl/cache/print", authorized::token_protected(json_ssl_cache_print) ); - handler.Content_Type = "application/json"; - server.addController(&handler); + handler->Content_Type = "application/json"; + server.addController(std::shared_ptr(handler)); } for(auto const& meth: {"GET", "POST"}) { - static Http_Responder handler( + auto* handler = new Http_Responder( meth, "/api/diag/proxy/session/list", authorized::token_protected(json_proxy_session_list) ); - handler.Content_Type = "application/json"; - server.addController(&handler); + handler->Content_Type = "application/json"; + server.addController(std::shared_ptr(handler)); } for(auto const& meth: {"GET", "POST"}) { - static Http_Responder handler( + auto* handler = new Http_Responder( meth, "/api/diag/proxy/neighbor/list", authorized::token_protected(json_proxy_neighbor_list) ); - handler.Content_Type = "application/json"; - server.addController(&handler); + handler->Content_Type = "application/json"; + server.addController(std::shared_ptr(handler)); } for(auto const& meth: {"POST"}) { - static Http_Responder handler( + auto* handler = new Http_Responder( meth, "/api/diag/proxy/neighbor/update", authorized::token_protected(json_proxy_neighbor_update) ); - handler.Content_Type = "application/json"; - server.addController(&handler); + handler->Content_Type = "application/json"; + server.addController(std::shared_ptr(handler)); } for(auto const& meth: {"GET", "POST"}) { - static Http_Responder handler( + auto* handler = new Http_Responder( meth, "/api/do/ssl/custom/reload", authorized::token_protected(json_do_ssl_custom_reload) ); - handler.Content_Type = "application/json"; - server.addController(&handler); + handler->Content_Type = "application/json"; + server.addController(std::shared_ptr(handler)); } } void controller_add_uni(lmh::WebServer &server) { - static Http_Responder cfg_uni_add( + auto* cfg_uni_add = new Http_Responder( "POST", "/api/config/uni/add", authorized::token_protected(&json_add_section_entry) ); - cfg_uni_add.Content_Type = "application/json"; - server.addController(&cfg_uni_add); + cfg_uni_add->Content_Type = "application/json"; + server.addController(std::shared_ptr(cfg_uni_add)); - static Http_Responder cfg_uni_set( + auto* cfg_uni_set = new Http_Responder( "POST", "/api/config/uni/set", authorized::token_protected(&json_set_section_entry) ); - cfg_uni_set.Content_Type = "application/json"; - server.addController(&cfg_uni_set); + cfg_uni_set->Content_Type = "application/json"; + server.addController(std::shared_ptr(cfg_uni_set)); - static Http_Responder cfg_uni_get( + auto* cfg_uni_get = new Http_Responder( "POST", "/api/config/uni/get", authorized::token_protected(&json_get_section_entry) ); - cfg_uni_get.Content_Type = "application/json"; - server.addController(&cfg_uni_get); + cfg_uni_get->Content_Type = "application/json"; + server.addController(std::shared_ptr(cfg_uni_get)); } void controller_add_wh_register(lmh::WebServer& server) { - static Http_Responder webhook_register( + auto* webhook_register = new Http_Responder( "POST", "/api/webhook/register", authorized::token_protected(wh_register) ); - webhook_register.Content_Type = "application/json"; - server.addController(&webhook_register); + webhook_register->Content_Type = "application/json"; + server.addController(std::shared_ptr(webhook_register)); } void controller_add_wh_unregister(lmh::WebServer& server) { - static Http_Responder webhook_unregister( + auto* webhook_unregister = new Http_Responder( "POST", "/api/webhook/unregister", authorized::token_protected(wh_unregister) ); - webhook_unregister.Content_Type = "application/json"; - server.addController(&webhook_unregister); + webhook_unregister->Content_Type = "application/json"; + server.addController(std::shared_ptr(webhook_unregister)); } - - } diff --git a/src/service/httpd/handlers/dispatchers.hpp b/src/service/httpd/handlers/dispatchers.hpp index 7fa59f0..95165c7 100644 --- a/src/service/httpd/handlers/dispatchers.hpp +++ b/src/service/httpd/handlers/dispatchers.hpp @@ -11,7 +11,7 @@ namespace sx::webserver { namespace dispatchers { - void controller_add_debug_only(lmh::WebServer &server); + void controller_add_status(lmh::WebServer &server); void controller_add_commons(lmh::WebServer &server); void controller_add_diag(lmh::WebServer &server); void controller_add_uni(lmh::WebServer &server); diff --git a/src/service/httpd/handlers/handlers.cpp b/src/service/httpd/handlers/handlers.cpp index aadaf2c..b10cc29 100644 --- a/src/service/httpd/handlers/handlers.cpp +++ b/src/service/httpd/handlers/handlers.cpp @@ -76,7 +76,7 @@ namespace sx::webserver { void controller_add_authorization(lmh::WebServer &server) { - static Http_Responder authorize_get( + auto* authorize_get = new Http_Responder( "GET", "/api/authorize", [](MHD_Connection *conn, std::string const &meth, std::string const &req) -> Http_JsonResponseParams { @@ -101,8 +101,10 @@ namespace sx::webserver { ret.response_code = MHD_HTTP_FORBIDDEN; return ret; }); + authorize_get->Content_Type = "application/json"; + server.addController(std::shared_ptr(authorize_get)); - static Http_Responder authorize( + auto* authorize = new Http_Responder( "POST", "/api/authorize", [](MHD_Connection *conn, std::string const &meth, std::string const &req) -> Http_JsonResponseParams { @@ -141,12 +143,9 @@ namespace sx::webserver { return ret; } ); + authorize->Content_Type = "application/json"; + server.addController(std::shared_ptr(authorize)); - authorize.Content_Type = "application/json"; - authorize_get.Content_Type = "application/json"; - - server.addController(&authorize); - server.addController(&authorize_get); auto split_form_data = [](std::string const& str, unsigned char sep1, unsigned char sep2) { @@ -165,7 +164,7 @@ namespace sx::webserver { return vals; }; - static Http_Responder login( + auto* login = new Http_Responder( "POST", "/api/login", [&split_form_data](MHD_Connection *conn, std::string const &meth, std::string const &req) -> Http_JsonResponseParams { @@ -226,8 +225,8 @@ namespace sx::webserver { } ); - login.Content_Type = "application/json"; - server.addController(&login); + login->Content_Type = "application/json"; + server.addController(std::shared_ptr(login)); } } } \ No newline at end of file diff --git a/src/service/httpd/httpd.cpp b/src/service/httpd/httpd.cpp index 20f4fda..0dccbb4 100644 --- a/src/service/httpd/httpd.cpp +++ b/src/service/httpd/httpd.cpp @@ -28,7 +28,7 @@ std::thread* create_httpd_thread(unsigned short port) { dispatchers::controller_add_authorization(server); - dispatchers::controller_add_debug_only(server); + dispatchers::controller_add_status(server); dispatchers::controller_add_commons(server); dispatchers::controller_add_diag(server); dispatchers::controller_add_uni(server);