LDAPExpr LDAPExpr::ParseExpr( ParseState& ps ) { ps.skipWhite(); if (!ps.prefix("(")) ps.error(MALFORMED); int op; ps.skipWhite(); Byte c = ps.peek(); if ( c == '&') { op = AND; } else if ( c == '|' ) { op = OR; } else if ( c == '!' ) { op = NOT; } else { return ParseSimple(ps); } ps.skip(1); // Ignore the d->m_operator std::vector<LDAPExpr> v; do { v.push_back(ParseExpr(ps)); ps.skipWhite(); } while (ps.peek() == '('); std::size_t n = v.size(); if (!ps.prefix(")") || n == 0 || (op == NOT && n > 1)) ps.error(MALFORMED); return LDAPExpr(op, v); }
LDAPExpr LDAPExpr::ParseSimple( ParseState &ps ) { std::string attrName = ps.getAttributeName(); if (attrName.empty()) ps.error(MALFORMED); int op = 0; if (ps.prefix("=")) op = EQ; else if (ps.prefix("<=")) op = LE; else if(ps.prefix(">=")) op = GE; else if(ps.prefix("~=")) op = APPROX; else { // System.out.println("undef op='" + ps.peek() + "'"); ps.error(OPERATOR); // Does not return } std::string attrValue = ps.getAttributeValue(); if (!ps.prefix(")")) ps.error(MALFORMED); return LDAPExpr(op, attrName, attrValue); }
void ServiceRegistry::Get_unlocked(const std::string& clazz, const std::string& filter, ModulePrivate* /*module*/, std::list<ServiceReference>& res) const { std::list<ServiceRegistration>::const_iterator s; std::list<ServiceRegistration>::const_iterator send; std::list<ServiceRegistration> v; LDAPExpr ldap; if (clazz.empty()) { if (!filter.empty()) { ldap = LDAPExpr(filter); LDAPExpr::ObjectClassSet matched; if (ldap.GetMatchedObjectClasses(matched)) { v.clear(); for(LDAPExpr::ObjectClassSet::const_iterator className = matched.begin(); className != matched.end(); ++className) { MapClassServices::const_iterator i = classServices.find(*className); if (i != classServices.end()) { std::copy(i->second.begin(), i->second.end(), std::back_inserter(v)); } } if (!v.empty()) { s = v.begin(); send = v.end(); } else { return; } } else { s = serviceRegistrations.begin(); send = serviceRegistrations.end(); } } else { s = serviceRegistrations.begin(); send = serviceRegistrations.end(); } } else { MapClassServices::const_iterator it = classServices.find(clazz); if (it != classServices.end()) { s = it->second.begin(); send = it->second.end(); } else { return; } if (!filter.empty()) { ldap = LDAPExpr(filter); } } for (; s != send; ++s) { ServiceReference sri = s->GetReference(); if (filter.empty() || ldap.Evaluate(s->d->properties, false)) { res.push_back(sri); } } }
bool LDAPExpr::Query( const std::string& filter, const ServicePropertiesImpl& pd) { return LDAPExpr(filter).Evaluate(pd, false); }
void ServiceRegistry::Get_unlocked(const std::string& clazz, const std::string& filter, BundlePrivate* bundle, std::vector<ServiceReferenceBase>& res) const { std::vector<ServiceRegistrationBase>::const_iterator s; std::vector<ServiceRegistrationBase>::const_iterator send; std::vector<ServiceRegistrationBase> v; LDAPExpr ldap; if (clazz.empty()) { if (!filter.empty()) { ldap = LDAPExpr(filter); LDAPExpr::ObjectClassSet matched; if (ldap.GetMatchedObjectClasses(matched)) { v.clear(); for (auto& className : matched) { auto i = classServices.find(className); if (i != classServices.end()) { std::copy( i->second.begin(), i->second.end(), std::back_inserter(v)); } } if (!v.empty()) { s = v.begin(); send = v.end(); } else { return; } } else { s = serviceRegistrations.begin(); send = serviceRegistrations.end(); } } else { s = serviceRegistrations.begin(); send = serviceRegistrations.end(); } } else { MapClassServices::const_iterator it = classServices.find(clazz); if (it != classServices.end()) { s = it->second.begin(); send = it->second.end(); } else { return; } if (!filter.empty()) { ldap = LDAPExpr(filter); } } for (; s != send; ++s) { ServiceReferenceBase sri = s->GetReference(clazz); if (filter.empty() || ldap.Evaluate(PropertiesHandle(s->d->properties, true), false)) { res.push_back(sri); } } if (!res.empty()) { if (bundle != nullptr) { auto ctx = bundle->bundleContext.Load(); core->serviceHooks.FilterServiceReferences(ctx.get(), clazz, filter, res); } else { core->serviceHooks.FilterServiceReferences(nullptr, clazz, filter, res); } } }