From 7496a0bab2eb25da24f52a49540558c3cd48f5b6 Mon Sep 17 00:00:00 2001 From: Ralf Ramsauer Date: Tue, 22 Sep 2015 21:55:31 +0200 Subject: [PATCH] Rearranged code --- doorlockd/main.cpp | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/doorlockd/main.cpp b/doorlockd/main.cpp index 9917aff..6fee715 100644 --- a/doorlockd/main.cpp +++ b/doorlockd/main.cpp @@ -57,33 +57,34 @@ static void session(tcp::socket &&sock) Json::Reader reader; Json::Value root; Response response; + std::string command; if (reader.parse(request, root, false)) { response.message = "Request is no valid JSON"; response.code = Response::Code::JsonError; l(response.message, LogLevel::warning); - } else { - std::string command; - try { - command = getJsonOrFail(root, "command"); - } - catch (...) - { - response.code = Response::Code::JsonError; - response.message = "Error parsing JSON"; - l(response.message, LogLevel::warning); - goto out; - } + 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); - } + try { + command = getJsonOrFail(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: