From 40d68fcce26d17ac7cb8f7d233e53326c9dbd443 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Fri, 11 Nov 2016 10:41:49 +0100 Subject: [PATCH] Fix object sync for objects in a global zone fixes #11541 --- lib/remote/apilistener-configsync.cpp | 2 +- lib/remote/apilistener.cpp | 30 +++++++++++++++++++++++---- lib/remote/zone.cpp | 3 +++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/remote/apilistener-configsync.cpp b/lib/remote/apilistener-configsync.cpp index 0f8ba9c93..72775eaa9 100644 --- a/lib/remote/apilistener-configsync.cpp +++ b/lib/remote/apilistener-configsync.cpp @@ -243,7 +243,7 @@ Value ApiListener::ConfigDeleteObjectAPIHandler(const MessageOrigin::Ptr& origin if (!object) { Log(LogNotice, "ApiListener") - << "Could not delete non-existent object '" << params->Get("name") << "'."; + << "Could not delete non-existent object '" << params->Get("name") << "' with type '" << params->Get("type") << "'."; return Empty; } diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 08a476e4a..e90015fb6 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -689,7 +689,7 @@ void ApiListener::SyncSendMessage(const Endpoint::Ptr& endpoint, const Dictionar if (!endpoint->GetSyncing()) { Log(LogNotice, "ApiListener") - << "Sending message to '" << endpoint->GetName() << "'"; + << "Sending message '" << message->Get("method") << "' to '" << endpoint->GetName() << "'"; double maxTs = 0; @@ -713,9 +713,15 @@ bool ApiListener::RelayMessageOne(const Zone::Ptr& targetZone, const MessageOrig Zone::Ptr myZone = Zone::GetLocalZone(); - /* only relay the message to a) the same zone, b) the parent zone and c) direct child zones */ - if (targetZone != myZone && targetZone != myZone->GetParent() && targetZone->GetParent() != myZone) + /* only relay the message to a) the same zone, b) the parent zone and c) direct child zones. Exception is a global zone. */ + if (!targetZone->GetGlobal() && + targetZone != myZone && + targetZone != myZone->GetParent() && + targetZone->GetParent() != myZone) { + Log(LogCritical, "ApiListener") + << "Not relaying message '" << message->Get("method") << "'. Not in the same/parent/child zone."; return true; + } Endpoint::Ptr myEndpoint = GetLocalEndpoint(); @@ -723,7 +729,23 @@ bool ApiListener::RelayMessageOne(const Zone::Ptr& targetZone, const MessageOrig bool relayed = false, log_needed = false, log_done = false; - for (const Endpoint::Ptr& endpoint : targetZone->GetEndpoints()) { + std::set targetEndpoints; + + if (targetZone->GetGlobal()) { + targetEndpoints = myZone->GetEndpoints(); + + for (const Zone::Ptr& zone : ConfigType::GetObjectsByType()) { + /* Fetch immediate child zone members */ + if (zone->GetParent() == myZone) { + std::set endpoints = zone->GetEndpoints(); + targetEndpoints.insert(endpoints.begin(), endpoints.end()); + } + } + } else { + targetEndpoints = targetZone->GetEndpoints(); + } + + for (const Endpoint::Ptr& endpoint : targetEndpoints) { /* don't relay messages to ourselves */ if (endpoint == GetLocalEndpoint()) continue; diff --git a/lib/remote/zone.cpp b/lib/remote/zone.cpp index a72a7a244..fde67688d 100644 --- a/lib/remote/zone.cpp +++ b/lib/remote/zone.cpp @@ -103,6 +103,9 @@ bool Zone::CanAccessObject(const ConfigObject::Ptr& object) if (!object_zone) object_zone = Zone::GetLocalZone(); + if (object_zone->GetGlobal()) + return true; + return object_zone->IsChildOf(this); } -- 2.40.0