1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-12-22 02:14:26 +01:00

Moved Command handling from logic to main

This commit is contained in:
Ralf Ramsauer 2015-09-22 21:48:52 +02:00
parent 211127f9d3
commit c01eb22f91
2 changed files with 22 additions and 3 deletions

View File

@ -75,7 +75,6 @@ Response Logic::parseRequest(const Json::Value &root)
goto out;
}
_logger(" Command: " + command, LogLevel::notice);
_logger(" User : " + user, LogLevel::notice);
_logger(" IP : " + ip, LogLevel::notice);
_logger(" Token : " + token, LogLevel::notice);

View File

@ -13,6 +13,7 @@
#include "daemon.h"
#include "config.h"
#include "logic.h"
#include "util.h"
namespace po = boost::program_options;
using boost::asio::ip::tcp;
@ -61,12 +62,31 @@ static void session(tcp::socket &&sock)
response.code = Response::Code::JsonError;
l(response.message, LogLevel::warning);
} else {
response = logic->parseRequest(root);
std::string command;
try {
command = getJsonOrFail<std::string>(root, "command");
}
catch (...)
{
response.code = Response::Code::JsonError;
response.message = "Error parsing JSON";
l(response.message, LogLevel::warning);
goto out;
}
l(" Command: " + command, LogLevel::notice);
if (command == "lock" || command == "unlock") {
response = logic->parseRequest(root);
} else {
response.code = Response::Code::UnknownCommand;
response.message = "Received unknown command " + command;
l(response.message, LogLevel::warning);
}
}
out:
sock.write_some(boost::asio::buffer(response.toJson()),
error);
if (error == boost::asio::error::eof)
return;
else if (error)