+ cur = (*i)->getEntityDescriptor(criteria);
+ if (cur.first) {
+ if (bRole) {
+ // We want a role also. Did we find one?
+ if (cur.second) {
+ // Are we using a first match policy?
+ if (m_firstMatch) {
+ // Save locked provider.
+ m_tlsKey->setData(*i);
+ return cur;
+ }
+
+ // Using last match wins. Did we already have one?
+ if (held) {
+ if (ret.second) {
+ // We had a "complete" match, so log it.
+ if (criteria.entityID_ascii) {
+ m_log.warn("found duplicate EntityDescriptor (%s) with role (%s), using last matching copy",
+ criteria.entityID_ascii, criteria.role->toString().c_str());
+ }
+ else if (criteria.entityID_unicode) {
+ auto_ptr_char temp(criteria.entityID_unicode);
+ m_log.warn("found duplicate EntityDescriptor (%s) with role (%s), using last matching copy",
+ temp.get(), criteria.role->toString().c_str());
+ }
+ else if (criteria.artifact) {
+ m_log.warn("found duplicate EntityDescriptor for artifact source (%s) with role (%s), using last matching copy",
+ criteria.artifact->getSource().c_str(), criteria.role->toString().c_str());
+ }
+ }
+ held->unlock();
+ }
+
+ // Save off the latest match.
+ held = *i;
+ ret = cur;
+ }
+ else {
+ // We didn't find the role, so we're going to keep looking,
+ // but save this one if we didn't have the role yet.
+ if (ret.second) {
+ // We already had a role, so let's stick with that.
+ (*i)->unlock();
+ }
+ else {
+ // This is at least as good, so toss anything we had and keep it.
+ if (held)
+ held->unlock();
+ held = *i;
+ ret = cur;
+ }
+ }
+ }
+ else {
+ // Are we using a first match policy?
+ if (m_firstMatch) {
+ // Save locked provider.
+ m_tlsKey->setData(*i);
+ return cur;
+ }
+
+ // Using last match wins. Did we already have one?
+ if (held) {
+ if (criteria.entityID_ascii) {
+ m_log.warn("found duplicate EntityDescriptor (%s), using last matching copy", criteria.entityID_ascii);
+ }
+ else if (criteria.entityID_unicode) {
+ auto_ptr_char temp(criteria.entityID_unicode);
+ m_log.warn("found duplicate EntityDescriptor (%s), using last matching copy", temp.get());
+ }
+ else if (criteria.artifact) {
+ m_log.warn("found duplicate EntityDescriptor for artifact source (%s), using last matching copy",
+ criteria.artifact->getSource().c_str());
+ }
+ held->unlock();
+ }
+
+ // Save off the latest match.
+ held = *i;
+ ret = cur;
+ }
+ }
+ else {
+ // No match, so just unlock this one and move on.
+ (*i)->unlock();