PKIFHttpCrlNode.cpp
Go to the documentation of this file.00001
00010 #include "PKIFHttpCrlNode.h"
00011 #include "CRL.h"
00012 #include "Name.h"
00013 #include "PKIFLDAPRepository.h"
00014 #include "LDAP_URL_Header.h"
00015 #include "GottaMatch.h"
00016
00017 #include <iterator>
00018 using namespace std;
00019
00021 bool RetrieveCRLGivenHTTPURL(const char* url, CPKIFCRLList& crlList);
00022 struct CPKIFHttpCrlNodeImpl
00023 {
00024
00025 CPKIFCRLNodeList m_cnl;
00026 };
00028
00035 CPKIFHttpCrlNode::CPKIFHttpCrlNode()
00036 : m_impl(new CPKIFHttpCrlNodeImpl)
00037 {
00038 }
00046 CPKIFHttpCrlNode::~CPKIFHttpCrlNode()
00047 {
00048 if(m_impl) delete m_impl;
00049 }
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 void CPKIFHttpCrlNode::GetCrls(CPKIFCRLNodeList& crlNodeList)
00089 {
00090 if(!m_impl->m_cnl.empty())
00091 {
00092 copy(m_impl->m_cnl.begin(), m_impl->m_cnl.end(), back_inserter(crlNodeList));
00093 return;
00094 }
00095 else if(PAS_UNAVAILABLE == GetState())
00096 {
00097 return;
00098 }
00099 else
00100 {
00101 bool atLeastOneWorked = false;
00102 vector<string> sources;
00103 GetSources(sources);
00104 vector<string>::iterator pos;
00105 vector<string>::iterator end = sources.end();
00106 for(pos = sources.begin(); pos != end; ++pos)
00107 {
00108 if(0 == (*pos).find("http"))
00109 {
00110 CPKIFCRLList crlList;
00111 RetrieveCRLGivenHTTPURL((*pos).c_str(), crlList);
00112 if(!crlList.empty())
00113 {
00114 atLeastOneWorked = true;
00115 CPKIFCRLList::iterator listPos;
00116 CPKIFCRLList::iterator listEnd = crlList.end();
00117 for(listPos = crlList.begin(); listPos != listEnd; ++listPos)
00118 {
00119 CPKIFCRLNodeEntryPtr newNode(new CPKIFCRLNodeEntry);
00120 newNode->SetCRL(*listPos);
00121 newNode->AddSource(*pos);
00122 newNode->SetState(PAS_AVAILABLE);
00123 GottaMatch<CPKIFCRLNodeEntryPtr> gm;
00124 gm.SetRHS(newNode);
00125 if(m_impl->m_cnl.end() == find_if(m_impl->m_cnl.begin(), m_impl->m_cnl.end(), gm))
00126 m_impl->m_cnl.push_back(newNode);
00127 }
00128
00129 if(!m_impl->m_cnl.empty())
00130 {
00131 copy(m_impl->m_cnl.begin(), m_impl->m_cnl.end(), back_inserter(crlNodeList));
00132 SetState(PAS_AVAILABLE);
00133 }
00134 }
00135 }
00136 }
00137
00138 if(!atLeastOneWorked)
00139 {
00140 SetState(PAS_UNAVAILABLE);
00141 }
00142
00143 return;
00144 }
00145 }