From 1008e2957ca75b7dd5eda838c922a017458826fa Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Thu, 21 Feb 2019 12:00:33 +0100 Subject: [PATCH] serialization: implement matching Change-Id: I2d94b5475939e4ccea92def362fe6cc0b1ec98cf --- src/internal/storage_backend_serialized.cpp | 43 +++++++++++++++++------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/internal/storage_backend_serialized.cpp b/src/internal/storage_backend_serialized.cpp index 3a6b207..96b4532 100644 --- a/src/internal/storage_backend_serialized.cpp +++ b/src/internal/storage_backend_serialized.cpp @@ -20,6 +20,9 @@ using namespace FB; namespace ldp_serialized { +template +struct type_helper; + class StorageBackendSerialized::StorageBackendSerializedImpl { int fd{-1}; uint8_t *mem{nullptr}; @@ -31,8 +34,8 @@ public: void printContent() const; - template - T *getPolicySet(); + template ::policy_set_type> + const M *getPolicySet(); }; void StorageBackendSerialized::StorageBackendSerializedImpl::release() { @@ -79,6 +82,7 @@ void StorageBackendSerialized::StorageBackendSerializedImpl::init(const char *fi close(fd); return; } +// TODO: decide - do we need verification? // for verification: // // if (!VerifyFileBuffer(Verifier(mem, length))) @@ -92,18 +96,16 @@ void StorageBackendSerialized::StorageBackendSerializedImpl::printContent() cons } /*************************************************/ -template -struct type_helper; #define TYPE_HELPER(T, t) \ template <> \ - struct type_helper { \ + struct type_helper { \ typedef FB::T##Set policy_set_type; \ typedef FB::Policy##T policy_type; \ }; \ template <> \ - auto StorageBackendSerialized::StorageBackendSerializedImpl::getPolicySet() \ - -> const typename type_helper::policy_set_type * { \ + auto StorageBackendSerialized::StorageBackendSerializedImpl::getPolicySet() \ + -> const typename type_helper::policy_set_type * { \ assert(file); \ return file->m_##t##_set(); \ } @@ -126,9 +128,13 @@ void StorageBackendSerialized::printContent() const { } template -bool match(const T &t, const I *i) { - // TODO!!!! - return true; +bool match(const T &match, const I *i) { + return match.match(makeMessageType(i->type()), i->interface()->c_str(), i->path()->c_str(), + i->member()->c_str(), i->name()->c_str(), i->is_name_prefix()); +} + +template <> bool match(const ldp_xml_parser::MatchItemAccess &match, const FB::ItemAccess *item) { + return match.match(makeBusAccessType(item->type()), item->uid(), item->gid()); } template ::policy_type> @@ -183,10 +189,10 @@ template <> ldp_xml_parser::DecisionItem getDecisionItem(const ldp_xml_parser::M } template ::policy_type> -ldp_xml_parser::DecisionItem getDecisionItemMaybeNull(const T &item, const P *policy) { - if (nullptr == policy) +ldp_xml_parser::DecisionItem getDecisionItemMaybeNull(const T &item, const P *policyPair) { + if (nullptr == policyPair) return ldp_xml_parser::Decision::ANY; - return getDecisionItem(item, policy); + return getDecisionItem(item, policyPair->policy()); } template @@ -210,23 +216,24 @@ ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemGroup(gid_ } #define T_INSTANTIATION(T) \ - template <> ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemContextMandatory(const ldp_xml_parser::MatchItem##T &item) const; \ - template <> ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemContextDefault(const ldp_xml_parser::MatchItem##T &item) const; + template ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemContextMandatory(const ldp_xml_parser::MatchItem##T &item) const; \ + template ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemContextDefault(const ldp_xml_parser::MatchItem##T &item) const; T_INSTANTIATION(Own) T_INSTANTIATION(Send) T_INSTANTIATION(Receive) T_INSTANTIATION(Access) +#undef T_INSTANTIATION + #define T_INSTANTIATION2(T) \ - template <> ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemUser(uid_t uid, const ldp_xml_parser::MatchItem##T &item) const; \ - template <> ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemGroup(gid_t gid, const ldp_xml_parser::MatchItem##T &item) const; + template ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemUser(uid_t uid, const ldp_xml_parser::MatchItem##T &item) const; \ + template ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemGroup(gid_t gid, const ldp_xml_parser::MatchItem##T &item) const; T_INSTANTIATION2(Own) T_INSTANTIATION2(Send) T_INSTANTIATION2(Receive) -#undef T_INSTANTIATION #undef T_INSTANTIATION2 StorageBackendSerialized::StorageBackendSerialized() -- 2.7.4