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     //CPKIFCRLPtr m_crl;
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 CPKIFCRLPtr CPKIFLdapCrlNode::GetCRL()const
00084 {
00085     if(m_impl->m_crl != (CPKIFCRL*)NULL)
00086         return m_impl->m_crl;
00087     else if(PAS_UNAVAILABLE == GetState())
00088     {
00089         CPKIFCRLPtr empty;
00090         return empty;
00091     }
00092     else
00093     {
00094         CPKIFCRLNodeList cnl;
00095         if(m_impl->m_entry)
00096         {
00097             m_impl->m_ldap->GetCRLs(m_impl->m_entry, m_impl->m_attributes, cnl);
00098             if(cnl.empty())
00099             {
00100                 SetState(PAS_UNAVAILABLE);
00101                 CPKIFCRLPtr empty;
00102                 return empty;
00103             }
00104             else
00105             {
00106                 m_impl->m_crl = cnl.front()->GetCRL();
00107                 SetState(PAS_AVAILABLE);
00108                 return m_impl->m_crl;
00109             }
00110         }
00111         else
00112         {
00113             vector<string> sources;
00114             GetSources(sources);
00115             vector<string>::iterator pos;
00116             vector<string>::iterator end = sources.end();
00117             for(pos = sources.begin(); pos != end; ++pos)
00118             {
00119                 if(0 == (*pos).find("ldap"))
00120                 {
00121                     CPKIFCRLList crlList;
00122                     GetCRLfromLDAPURL((*pos).c_str(), crlList);
00123                     if(!crlList.empty())
00124                     {
00125                         m_impl->m_crl = crlList.front();
00126                         SetState(PAS_AVAILABLE);
00127                         return m_impl->m_crl;
00128                     }
00129                 }
00130             }
00131 
00132             return m_impl->m_crl; //no sources, return NULL
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 }

Generated on Mon Nov 15 11:15:54 2010 for PublicKeyInfrastructureFramework(PKIF) by  doxygen 1.5.6