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

Rearranged code

This commit is contained in:
Ralf Ramsauer 2015-09-22 21:55:31 +02:00
parent 542f5518a6
commit 7496a0bab2

View File

@ -57,33 +57,34 @@ static void session(tcp::socket &&sock)
Json::Reader reader; Json::Reader reader;
Json::Value root; Json::Value root;
Response response; Response response;
std::string command;
if (reader.parse(request, root, false)) if (reader.parse(request, root, false))
{ {
response.message = "Request is no valid JSON"; response.message = "Request is no valid JSON";
response.code = Response::Code::JsonError; response.code = Response::Code::JsonError;
l(response.message, LogLevel::warning); l(response.message, LogLevel::warning);
} else { goto out;
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); try {
if (command == "lock" || command == "unlock") { command = getJsonOrFail<std::string>(root, "command");
response = logic->parseRequest(root); }
} else { catch (...)
response.code = Response::Code::UnknownCommand; {
response.message = "Received unknown command " + command; response.code = Response::Code::JsonError;
l(response.message, LogLevel::warning); 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: out: