From: Neil Cook Date: Fri, 26 Oct 2018 10:26:51 +0000 (+0000) Subject: New methods to add and remove individual policy tags X-Git-Tag: dnsdist-1.3.3~16^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc11520c8bb2ff2ecbfd0db6e6f24051d693a4cc;p=thirdparty%2Fpdns.git New methods to add and remove individual policy tags --- diff --git a/pdns/rec-protobuf.cc b/pdns/rec-protobuf.cc index f12d793510..c7eec6943d 100644 --- a/pdns/rec-protobuf.cc +++ b/pdns/rec-protobuf.cc @@ -179,6 +179,39 @@ void RecProtoBufMessage::setPolicyTags(const std::vector& policyTag #endif /* HAVE_PROTOBUF */ } +void RecProtoBufMessage::addPolicyTag(const std::string& policyTag) +{ +#ifdef HAVE_PROTOBUF + PBDNSMessage_DNSResponse* response = d_message.mutable_response(); + if (response) { + response->add_tags(policyTag); + } +#endif +} + +void RecProtoBufMessage::removePolicyTag(const std::string& policyTag) +{ +#ifdef HAVE_PROTOBUF + PBDNSMessage_DNSResponse* response = d_message.mutable_response(); + if (response) { + const int count = response->tags_size(); + int keep = 0; + for (int idx = 0; idx < count; ++idx) { + auto tagp = response->mutable_tags(idx); + if (tagp->compare(policyTag) == 0) { + } + else { + if (keep < idx) { + response->mutable_tags()->SwapElements(idx, keep); + } + ++keep; + } + } + response->mutable_tags()->DeleteSubrange(keep, count - keep); + } +#endif +} + std::string RecProtoBufMessage::getAppliedPolicy() const { std::string result; diff --git a/pdns/rec-protobuf.hh b/pdns/rec-protobuf.hh index 34386283d6..e4f76b843c 100644 --- a/pdns/rec-protobuf.hh +++ b/pdns/rec-protobuf.hh @@ -53,6 +53,8 @@ public: void setAppliedPolicy(const std::string& policy); void setAppliedPolicyType(const DNSFilterEngine::PolicyType& policyType); void setPolicyTags(const std::vector& policyTags); + void addPolicyTag(const std::string& policyTag); + void removePolicyTag(const std::string& policyTag); std::string getAppliedPolicy() const; std::vector getPolicyTags() const; };