PKIFLdapCrlNode.cpp
Go to the documentation of this file.00001
00010 #include "PKIFLdapCrlNode.h"
00011 #include "CRL.h"
00012 #include "Name.h"
00013 #include "PKIFLDAPRepository.h"
00014 #include "LDAP_URL_Header.h"
00015 #include "ToolkitUtils.h"
00016 #include "GottaMatch.h"
00017
00018 #include <iterator>
00019
00020 using namespace std;
00021
00023 struct CPKIFLdapCrlNodeImpl
00024 {
00025 CPKIFNamePtr m_entry;
00026 CPKIFLDAPRepositoryPtr m_ldap;
00027 vector<string> m_attributes;
00028
00029
00030 CPKIFCRLNodeList m_cnl;
00031 };
00033
00040 CPKIFLdapCrlNode::CPKIFLdapCrlNode(
00042 CPKIFLDAPRepositoryPtr& ldap,
00044 CPKIFNamePtr& entry,
00046 std::vector<std::string>& attributes)
00047 : m_impl(new CPKIFLdapCrlNodeImpl)
00048 {
00049 m_impl->m_ldap = ldap;
00050 m_impl->m_entry = entry;
00051 copy(attributes.begin(), attributes.end(), back_inserter(m_impl->m_attributes));
00052 }
00060 CPKIFLdapCrlNode::CPKIFLdapCrlNode()
00061 : m_impl(new CPKIFLdapCrlNodeImpl)
00062 {
00063 }
00071 CPKIFLdapCrlNode::~CPKIFLdapCrlNode()
00072 {
00073 if(m_impl) delete m_impl;
00074 }
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 void CPKIFLdapCrlNode::GetCrls(CPKIFCRLNodeList& crlNodeList)
00138 {
00139 if(!m_impl->m_cnl.empty())
00140 {
00141 copy(m_impl->m_cnl.begin(), m_impl->m_cnl.end(), back_inserter(crlNodeList));
00142 return;
00143 }
00144 else if(PAS_UNAVAILABLE == GetState())
00145 {
00146 return;
00147 }
00148 else
00149 {
00150 if(m_impl->m_entry)
00151 {
00152 m_impl->m_ldap->GetCRLs(m_impl->m_entry, m_impl->m_attributes, m_impl->m_cnl);
00153 if(m_impl->m_cnl.empty())
00154 {
00155 SetState(PAS_UNAVAILABLE);
00156 return;
00157 }
00158 else
00159 {
00160 copy(m_impl->m_cnl.begin(), m_impl->m_cnl.end(), back_inserter(crlNodeList));
00161 SetState(PAS_AVAILABLE);
00162 return;
00163 }
00164 }
00165 else
00166 {
00167 bool atLeastOneWorked = false;
00168 vector<string> sources;
00169 GetSources(sources);
00170 vector<string>::iterator pos;
00171 vector<string>::iterator end = sources.end();
00172 for(pos = sources.begin(); pos != end; ++pos)
00173 {
00174 if(0 == (*pos).find("ldap"))
00175 {
00176 CPKIFCRLList crlList;
00177 GetCRLfromLDAPURL((*pos).c_str(), crlList);
00178 if(!crlList.empty())
00179 {
00180 atLeastOneWorked = true;
00181 CPKIFCRLList::iterator listPos;
00182 CPKIFCRLList::iterator listEnd = crlList.end();
00183 for(listPos = crlList.begin(); listPos != listEnd; ++listPos)
00184 {
00185 CPKIFCRLNodeEntryPtr newNode(new CPKIFCRLNodeEntry);
00186 newNode->SetCRL(*listPos);
00187 newNode->AddSource(*pos);
00188 newNode->SetState(PAS_AVAILABLE);
00189 GottaMatch<CPKIFCRLNodeEntryPtr> gm;
00190 gm.SetRHS(newNode);
00191 if(m_impl->m_cnl.end() == find_if(m_impl->m_cnl.begin(), m_impl->m_cnl.end(), gm))
00192 m_impl->m_cnl.push_back(newNode);
00193 }
00194
00195 if(!m_impl->m_cnl.empty())
00196 {
00197 copy(m_impl->m_cnl.begin(), m_impl->m_cnl.end(), back_inserter(crlNodeList));
00198 SetState(PAS_AVAILABLE);
00199 }
00200 }
00201 }
00202 }
00203
00204 if(!atLeastOneWorked)
00205 {
00206 SetState(PAS_UNAVAILABLE);
00207 }
00208
00209 return;
00210 }
00211 }
00212 }