Commit 017d5e8f authored by Micha Mueller's avatar Micha Mueller
Browse files

Unify log messages in HttpsServer

parent c6804497
......@@ -12,8 +12,12 @@
#include <memory>
#include <functional>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/info_parser.hpp>
#include <boost/algorithm/string/split.hpp>
#define LOGH(sev) LOG(sev) << "HttpsServer: "
HttpsServer::requestHandler::requestHandler(HttpsServer& httpsServer) : _httpsServer(httpsServer) {}
void HttpsServer::requestHandler::operator()(server::request const &request, server::connection_ptr connection) {
......@@ -21,7 +25,7 @@ void HttpsServer::requestHandler::operator()(server::request const &request, ser
server::string_type ip = source(request);
unsigned int port = request.source_port;
LOG(info) << "HttpsServer: " << ip << ":" << port << " connected";
LOGH(info) << ip << ":" << port << " connected";
//set appropriate default value to connection status
connection->set_status(server::connection::internal_server_error);
......@@ -40,12 +44,12 @@ void HttpsServer::requestHandler::operator()(server::request const &request, ser
//first check if request is supported at all
if (method != "GET" && method != "PUT") {
LOG(warning) << "HttpsServer: Unsupported " << method << " request was made";
LOGH(warning) << "Unsupported " << method << " request was made";
connection->set_status(server::connection::not_supported);
goto error;
}
LOG(info) << "HttpsServer: " << method << " request of " << request.destination << " was made";
LOGH(info) << method << " request of " << request.destination << " was made";
//do some string processing
//split path into its hierarchical parts
......@@ -85,7 +89,7 @@ void HttpsServer::requestHandler::operator()(server::request const &request, ser
}
if (pathStrs.size() < 1) {
LOG(warning) << "Received malformed request: No first path part";
LOGH(warning) << "Received malformed request: No first path part";
connection->set_status(server::connection::bad_request);
goto error;
}
......@@ -95,7 +99,7 @@ void HttpsServer::requestHandler::operator()(server::request const &request, ser
//first check permission
if (!_httpsServer.check_authkey(auth_value, permission::GETReq)) {
LOG(warning) << "Provided authentication token has insufficient permissions";
LOGH(warning) << "Provided authentication token has insufficient permissions";
connection->set_status(server::connection::unauthorized);
goto error;
}
......@@ -118,12 +122,20 @@ void HttpsServer::requestHandler::operator()(server::request const &request, ser
"least the query ?authkey=[token] at the end. Multiple queries\n"
"need to be separated by semicolons(';')\n";
} else if (pathStrs[0] == "plugins") {
//TODO make (JSON) list of plugins
/* TODO
boost::property_tree::ptree root, plugins;
boost::property_tree::write_info(data, root);
for(auto& p : _httpsServer._plugins) {
plugins.put(p.id, "");
}
root.add_child("plugins", plugins);
*/
} else {
//do some prior checks
if (pathStrs.size() < 2) {
LOG(warning) << "Received malformed request: No second path part";
LOGH(warning) << "Received malformed request: No second path part";
connection->set_status(server::connection::bad_request);
goto error;
}
......@@ -133,13 +145,13 @@ void HttpsServer::requestHandler::operator()(server::request const &request, ser
} else {
if (pathStrs.size() < 3) {
LOG(warning) << "Received malformed request: No third path part";
LOGH(warning) << "Received malformed request: No third path part";
connection->set_status(server::connection::bad_request);
goto error;
}
if (pathStrs[2] != "avg") {
LOG(warning) << "Unknown action " << pathStrs[2] << " requested";
LOGH(warning) << "Unknown action " << pathStrs[2] << " requested";
connection->set_status(server::connection::not_supported);
goto error;
}
......@@ -191,20 +203,20 @@ void HttpsServer::requestHandler::operator()(server::request const &request, ser
//first check permission
if (!_httpsServer.check_authkey(auth_value, permission::PUTReq)) {
LOG(warning) << "Provided authentication token has insufficient permissions";
LOGH(warning) << "Provided authentication token has insufficient permissions";
connection->set_status(server::connection::unauthorized);
goto error;
}
if (pathStrs.size() < 2) {
LOG(warning) << "Received malformed request: No second path part";
LOGH(warning) << "Received malformed request: No second path part";
connection->set_status(server::connection::bad_request);
goto error;
}
//check if query and action are valid values
if (pathStrs[1] != "start" && pathStrs[1] != "stop") {
LOG(warning) << "Unknown action " << pathStrs[1] << " requested";
LOGH(warning) << "Unknown action " << pathStrs[1] << " requested";
connection->set_status(server::connection::not_supported);
goto error;
}
......@@ -235,7 +247,7 @@ void HttpsServer::requestHandler::operator()(server::request const &request, ser
}
}
LOG(info) << "HttpsServer: Responding: " << response;
LOGH(info) << "Responding: " << response;
data << response << std::endl;
//jump right here if an error was encountered.
......@@ -247,7 +259,7 @@ void HttpsServer::requestHandler::operator()(server::request const &request, ser
}
void HttpsServer::requestHandler::log(const server::string_type& message) {
LOG(error) << message;
LOGH(error) << message;
}
HttpsServer::HttpsServer(restAPISettings_t restAPISettings, pluginVector_t& plugins) :
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment