PKIFSupportsSynonymousSources.cpp

Go to the documentation of this file.
00001 
00010 #include "PKIFdll.h"
00011 #include "PKIFCertificateNodeEntry.h"
00012 #include "PKIFCRLNodeEntry.h"
00013 #include "IPKIFSupportsSynonymousSources.h"
00014 #include "LDAP_URL_Header.h"
00015 
00016 #include <cctype>
00017 
00018 #include <vector>
00019 #include <string>
00020 #include <map>
00021 using namespace std;
00022 
00030 IPKIFSupportsSynonymousCRLSources::IPKIFSupportsSynonymousCRLSources()
00031 {
00032 }
00033 
00041 IPKIFSupportsSynonymousCRLSources::~IPKIFSupportsSynonymousCRLSources()
00042 {
00043 }
00044 
00052 IPKIFSupportsSynonymousCertSources::IPKIFSupportsSynonymousCertSources()
00053 {
00054 }
00055 
00063 IPKIFSupportsSynonymousCertSources::~IPKIFSupportsSynonymousCertSources()
00064 {
00065 }
00066 
00067 class UriMatch
00068 {
00069 public:
00070     bool operator()(const std::string& t)
00071     {
00072         if(t == m_rhs)
00073             return true;
00074         else
00075         {
00076             std::string copyOfT = t;
00077             std::transform(copyOfT.begin(), copyOfT.end(), copyOfT.begin(), (int(*)(int)) std::toupper);
00078             if(0 == copyOfT.find("LDAP") && 0 == m_rhs.find("LDAP"))
00079             {
00080                 PKIFLDAP::LDAPURLDesc *ldapInfoUri = NULL;
00081                 PKIFLDAP::ldap_url_parse(copyOfT.c_str(), &ldapInfoUri);
00082 
00083                 PKIFLDAP::LDAPURLDesc *ldapInfoRhs = NULL;
00084                 PKIFLDAP::ldap_url_parse(m_rhs.c_str(), &ldapInfoRhs);
00085                 if(!ldapInfoRhs || !ldapInfoUri)
00086                     return false;
00087 
00088                 bool retVal = true; 
00089                 if(ldapInfoUri->lud_port != ldapInfoRhs->lud_port)
00090                     retVal = false;
00091 
00092                 //need to account for URIs that begin ///
00093                 if((ldapInfoUri->lud_host && !ldapInfoRhs->lud_host) || (!ldapInfoUri->lud_host && ldapInfoRhs->lud_host))
00094                     return false;
00095 
00096                 if(0 != stricmp(ldapInfoUri->lud_host, ldapInfoRhs->lud_host))
00097                     retVal = false;
00098 
00099                 if(0 != stricmp(ldapInfoUri->lud_dn, ldapInfoRhs->lud_dn))
00100                     retVal = false;
00101 /*
00102                 bool match = true;
00103 
00104                 for(int ii = 0; NULL != ldapInfoRhs->lud_attrs[ii]; ++ii)
00105                 {
00106                     for(int jj = 0; NULL != ldapInfoUri->lud_attrs[jj]; ++jj)
00107                     {
00108                         if(0 != stricmp(ldapInfoRhs->lud_attrs[ii], ldapInfoUri->lud_attrs[jj]))
00109                             match = false;
00110                         else
00111                         {
00112                             match = true;
00113                             break;
00114                         }
00115                     }
00116                     if(!match)
00117                         break;
00118                 }
00119 
00120                 retVal = match;
00121 */
00122                 PKIFLDAP::ldap_free_urldesc( ldapInfoUri );
00123                 PKIFLDAP::ldap_free_urldesc( ldapInfoRhs );
00124                 return retVal;
00125             }
00126         }
00127 
00128         return false;
00129     }
00130 
00131     void SetRHS(const std::string& rhs) 
00132     {
00133         m_rhs = rhs;
00134         std::transform(m_rhs.begin(), m_rhs.end(), m_rhs.begin(), (int(*)(int)) std::toupper);
00135     }
00136 private:
00137     std::string m_rhs;
00138 };
00139 
00140 bool UriAlreadyInList(CPKIFCrlSourceList& list, std::string& uri)
00141 {
00142     CPKIFCrlSourceList::iterator pos;
00143     CPKIFCrlSourceList::iterator end = list.end();
00144     for(pos = list.begin(); pos != end; ++pos)
00145     {
00146         std::vector<std::string> sources;
00147         (*pos)->GetSources(sources);
00148 
00149         UriMatch uriMatch;
00150         uriMatch.SetRHS(uri);
00151 
00152         if(sources.end() != find_if(sources.begin(), sources.end(), uriMatch))
00153             return true;
00154     }
00155     return false;
00156 }
00157 
00158 bool UriAlreadyInList(CPKIFCertificateSourceList& list, std::string& uri)
00159 {
00160     CPKIFCertificateSourceList::iterator pos;
00161     CPKIFCertificateSourceList::iterator end = list.end();
00162     for(pos = list.begin(); pos != end; ++pos)
00163     {
00164         std::vector<std::string> sources;
00165         (*pos)->GetSources(sources);
00166 
00167         UriMatch uriMatch;
00168         uriMatch.SetRHS(uri);
00169 
00170         if(sources.end() != find_if(sources.begin(), sources.end(), uriMatch))
00171             return true;
00172     }
00173     return false;
00174 }

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