From ac52b22c05dffa93594a2b10e1be6090d88443e9 Mon Sep 17 00:00:00 2001 From: "tim.carrington" Date: Fri, 17 Jan 2020 12:53:54 +0000 Subject: [PATCH] removal of redundant else statements and change GetListenerId to UpdateListenerId --- .../MWR/C3/Interfaces/Connectors/Covenant.cpp | 43 ++++++++----------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/Src/Common/MWR/C3/Interfaces/Connectors/Covenant.cpp b/Src/Common/MWR/C3/Interfaces/Connectors/Covenant.cpp index 66aea0f..96a986d 100755 --- a/Src/Common/MWR/C3/Interfaces/Connectors/Covenant.cpp +++ b/Src/Common/MWR/C3/Interfaces/Connectors/Covenant.cpp @@ -137,11 +137,11 @@ namespace MWR::C3::Interfaces::Connectors /// Map of all connections. std::unordered_map> m_ConnectionMap; - bool GetListenerId(); + bool UpdateListenerId(); }; } -bool MWR::C3::Interfaces::Connectors::Covenant::GetListenerId() +bool MWR::C3::Interfaces::Connectors::Covenant::UpdateListenerId() { std::string url = this->m_webHost + OBF("/api/listeners"); std::pair data; @@ -163,28 +163,23 @@ bool MWR::C3::Interfaces::Connectors::Covenant::GetListenerId() if (resp.status_code() != web::http::status_codes::OK) throw std::exception((OBF("[Covenant] Error getting Listeners, HTTP resp: ") + std::to_string(resp.status_code())).c_str()); - else - { - //Get the json response - auto respData = resp.extract_string(); - response = json::parse(respData.get()); - - for (auto& listeners : response) - { - if (listeners[OBF("name")] != OBF("C3Bridge")) - continue; - else - { - this->m_ListenerId = listeners[OBF("id")].get(); - this->m_ListeningPostAddress = listeners[OBF("connectAddresses")][0].get(); - this->m_ListeningPostPort = listeners[OBF("connectPort")]; - return true; - } - } - - return false; //we didn't find the listener - } + //Get the json response + auto respData = resp.extract_string(); + response = json::parse(respData.get()); + + for (auto& listeners : response) + { + if (listeners[OBF("name")] != OBF("C3Bridge")) + continue; + + this->m_ListenerId = listeners[OBF("id")].get(); + this->m_ListeningPostAddress = listeners[OBF("connectAddresses")][0].get(); + this->m_ListeningPostPort = listeners[OBF("connectPort")]; + return true; + } + + return false; //we didn't find the listener } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -236,7 +231,7 @@ MWR::C3::Interfaces::Connectors::Covenant::Covenant(ByteView arguments) throw std::exception(OBF("[Covenant] Could not get token, invalid logon")); //If the listener doesn't already exist create it. - if (!GetListenerId()) + if (!UpdateListenerId()) { //extract ip address from url size_t start = 0, end = 0;