From: Adam Malinowski Date: Mon, 3 Nov 2014 13:57:13 +0000 (+0100) Subject: Handle client and agent disconnection X-Git-Tag: submit/R4/20141115.054144~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ced9c53a12b1f47eb2087b97650c0085fdb65c9e;p=platform%2Fcore%2Fsecurity%2Fcynara.git Handle client and agent disconnection This patch handles situations where client and/or agent connection to cynara service is closed. Change-Id: I410b6da96102b6ae16442e90dbbb1e867490287a --- diff --git a/src/service/logic/Logic.cpp b/src/service/logic/Logic.cpp index 4cf78eb..8f51af5 100644 --- a/src/service/logic/Logic.cpp +++ b/src/service/logic/Logic.cpp @@ -63,6 +63,7 @@ #include "Logic.h" namespace Cynara { + Logic::Logic() { } @@ -307,8 +308,17 @@ void Logic::execute(RequestContextPtr context, SetPoliciesRequestPtr request) { request->sequenceNumber())); } -void Logic::contextClosed(RequestContextPtr context UNUSED) { - //We don't care now, but we will +void Logic::contextClosed(RequestContextPtr context) { + LOGD("context closed"); + + LinkId linkId = context->responseQueue(); + + m_agentManager->cleanupAgent(linkId, [&](const AgentTalkerPtr &talker) -> void { + handleAgentTalkerDisconnection(talker); }); + + m_checkRequestManager.cancelRequests(linkId, + [&](const CheckContextPtr &checkContextPtr) -> void { + handleClientDisconnection(checkContextPtr); }); } void Logic::onPoliciesChanged(void) { @@ -317,4 +327,29 @@ void Logic::onPoliciesChanged(void) { //todo remove all saved contexts (if there will be any saved contexts) } +void Logic::handleAgentTalkerDisconnection(const AgentTalkerPtr &agentTalkerPtr) { + CheckContextPtr checkContextPtr = m_checkRequestManager.getContext(agentTalkerPtr); + if (checkContextPtr == nullptr) { + LOGE("No matching check context for agent talker."); + return; + } + + if (!checkContextPtr->cancelled() && checkContextPtr->m_requestContext->responseQueue()) { + PolicyResult result(PredefinedPolicyType::DENY); + checkContextPtr->m_requestContext->returnResponse(checkContextPtr->m_requestContext, + std::make_shared(result, checkContextPtr->m_checkId)); + } + + m_checkRequestManager.removeRequest(checkContextPtr); +} + +void Logic::handleClientDisconnection(const CheckContextPtr &checkContextPtr) { + LOGD("Handle client disconnection"); + + if (!checkContextPtr->cancelled()) { + checkContextPtr->cancel(); + checkContextPtr->m_agentTalker->cancel(); + } +} + } // namespace Cynara diff --git a/src/service/logic/Logic.h b/src/service/logic/Logic.h index 57a862c..33c5701 100644 --- a/src/service/logic/Logic.h +++ b/src/service/logic/Logic.h @@ -91,6 +91,9 @@ private: const PluginData &agentData, const RequestContextPtr &request, const ServicePluginInterfacePtr &plugin); + void handleAgentTalkerDisconnection(const AgentTalkerPtr &agentTalkerPtr); + void handleClientDisconnection(const CheckContextPtr &checkContextPtr); + void onPoliciesChanged(void); };