PKIFLdapCertNode.cpp
Go to the documentation of this file.00001
00010 #include "PKIFLdapCertNode.h"
00011
00012 #include "Certificate.h"
00013 #include "GottaMatch.h"
00014 #include "LDAP_URL_Header.h"
00015 #include "Name.h"
00016 #include "PKIFLDAPRepository.h"
00017 #include "ToolkitUtils.h"
00018 #include "GottaMatch.h"
00019
00020 #include <iterator>
00021 using namespace std;
00022
00024 struct CPKIFLdapCertNodeImpl
00025 {
00026 CPKIFNamePtr m_entry;
00027 CPKIFLDAPRepositoryPtr m_ldap;
00028 vector<string> m_attributes;
00029
00030 CPKIFCertificateNodeList m_certNodeList;
00031 };
00033
00041 CPKIFLdapCertNode::CPKIFLdapCertNode(
00043 CPKIFLDAPRepositoryPtr& ldap,
00045 CPKIFNamePtr& entry,
00047 std::vector<std::string>& attributes)
00048 : m_impl(new CPKIFLdapCertNodeImpl)
00049 {
00050 m_impl->m_ldap = ldap;
00051 m_impl->m_entry = entry;
00052 copy(attributes.begin(), attributes.end(), back_inserter(m_impl->m_attributes));
00053 }
00061 CPKIFLdapCertNode::CPKIFLdapCertNode()
00062 : m_impl(new CPKIFLdapCertNodeImpl)
00063 {
00064 }
00072 CPKIFLdapCertNode::~CPKIFLdapCertNode()
00073 {
00074 if(m_impl) delete m_impl;
00075 }
00076
00077 bool CPKIFLdapCertNode::operator==(const CPKIFLdapCertNode& rhs) const
00078 {
00079 if(!m_impl->m_entry || !rhs.m_impl->m_entry ||
00080 !(*m_impl->m_entry == *rhs.m_impl->m_entry))
00081 return false;
00082
00083 if(!m_impl->m_ldap || !rhs.m_impl->m_ldap ||
00084 (0 != stricmp(m_impl->m_ldap->GetHost(), rhs.m_impl->m_ldap->GetHost())) ||
00085 (m_impl->m_ldap->GetPort() != rhs.m_impl->m_ldap->GetPort()))
00086 return false;
00087
00088 return true;
00089 }
00090
00098 void CPKIFLdapCertNode::GetCertificates(
00100 CPKIFCertificateNodeList& certNodeList,
00102 PathBuildingDirection pbd)
00103 {
00104 if(m_impl->m_entry)
00105 {
00106 m_impl->m_ldap->GetCertificates(m_impl->m_entry, m_impl->m_attributes, m_impl->m_certNodeList, pbd);
00107 }
00108 else if(m_impl->m_certNodeList.empty())
00109 {
00110 vector<string> sources;
00111 GetSources(sources);
00112 vector<string>::iterator pos;
00113 vector<string>::iterator end = sources.end();
00114 for(pos = sources.begin(); pos != end; ++pos)
00115 {
00116 if(0 == (*pos).find("ldap"))
00117 {
00118 GetCertfromLDAPURL((*pos).c_str(), m_impl->m_certNodeList, pbd);
00119 }
00120 }
00121 }
00122
00123 if(!m_impl->m_certNodeList.empty())
00124 {
00125 CPKIFCertificateNodeList::iterator pos;
00126 CPKIFCertificateNodeList::iterator end = m_impl->m_certNodeList.end();
00127 for(pos = m_impl->m_certNodeList.begin(); pos != end; ++pos)
00128 {
00129 GottaMatch<CPKIFCertificateNodeEntryPtr> gm;
00130 gm.SetRHS(*pos);
00131 if(certNodeList.end() == find_if(certNodeList.begin(), certNodeList.end(), gm))
00132 {
00133 certNodeList.push_back(*pos);
00134 }
00135 }
00136 }
00137 }