Backport libcurl-based Xerces net access.
[shibboleth/xmltooling.git] / xmltooling / security / impl / InlineKeyResolver.cpp
index c198b93..126a6ea 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 #include "internal.h"
+#include "logging.h"
 #include "security/BasicX509Credential.h"
 #include "security/KeyInfoCredentialContext.h"
 #include "security/KeyInfoResolver.h"
@@ -31,7 +32,6 @@
 #include "util/XMLConstants.h"
 #include "validation/ValidatorSuite.h"
 
-#include <log4cpp/Category.hh>
 #include <xercesc/util/XMLUniDefs.hpp>
 #include <xsec/dsig/DSIGKeyInfoX509.hpp>
 #include <xsec/enc/XSECKeyInfoResolverDefault.hpp>
@@ -42,8 +42,8 @@
 #include <xsec/framework/XSECException.hpp>
 
 using namespace xmlsignature;
+using namespace xmltooling::logging;
 using namespace xmltooling;
-using namespace log4cpp;
 using namespace std;
 
 namespace xmltooling {
@@ -67,18 +67,30 @@ namespace xmltooling {
 
         KeyInfo* getKeyInfo(bool compact=false) const {
             KeyInfo* ret = m_credctx->getKeyInfo() ? m_credctx->getKeyInfo()->cloneKeyInfo() : NULL;
-            if (ret && compact) {
-                ret->getKeyValues().clear();
-                ret->getSPKIDatas().clear();
-                ret->getPGPDatas().clear();
-                ret->getUnknownXMLObjects().clear();
-                const vector<X509Data*> x509Datas=const_cast<const KeyInfo*>(ret)->getX509Datas();
-                for (vector<X509Data*>::const_iterator x=x509Datas.begin(); x!=x509Datas.end(); ++x) {
-                    (*x)->getX509Certificates().clear();
-                    (*x)->getX509CRLs().clear();
-                    (*x)->getUnknownXMLObjects().clear();
+            if (ret) {
+                ret->setId(NULL);
+                ret->getRetrievalMethods().clear();
+                if (compact) {
+                    ret->getKeyValues().clear();
+                    ret->getSPKIDatas().clear();
+                    ret->getPGPDatas().clear();
+                    ret->getUnknownXMLObjects().clear();
+                    VectorOf(X509Data) x509Datas=ret->getX509Datas();
+                    for (VectorOf(X509Data)::size_type pos = 0; pos < x509Datas.size();) {
+                        x509Datas[pos]->getX509Certificates().clear();
+                        x509Datas[pos]->getX509CRLs().clear();
+                        x509Datas[pos]->getUnknownXMLObjects().clear();
+                        if (x509Datas[pos]->hasChildren())
+                            ++pos;
+                        else
+                            x509Datas.erase(x509Datas.begin() + pos);
+                    }
                 }
             }
+            if (!ret->hasChildren()) {
+                delete ret;
+                ret = NULL;
+            }
             return ret;
         }
         
@@ -175,7 +187,7 @@ void InlineCredential::resolve(const KeyInfo* keyInfo, int types)
 
 bool InlineCredential::resolveKey(const KeyInfo* keyInfo)
 {
-    Category& log = Category::getInstance(XMLTOOLING_LOGCAT".KeyInfoResolver");
+    Category& log = Category::getInstance(XMLTOOLING_LOGCAT".KeyInfoResolver."INLINE_KEYINFO_RESOLVER);
 
     // Check for ds:KeyValue
     const vector<KeyValue*>& keyValues = keyInfo->getKeyValues();
@@ -258,7 +270,7 @@ bool InlineCredential::resolveKey(const KeyInfo* keyInfo)
 
 bool InlineCredential::resolveCerts(const KeyInfo* keyInfo)
 {
-    Category& log = Category::getInstance(XMLTOOLING_LOGCAT".KeyInfoResolver");
+    Category& log = Category::getInstance(XMLTOOLING_LOGCAT".KeyInfoResolver."INLINE_KEYINFO_RESOLVER);
 
     // Check for ds:X509Data
     const vector<X509Data*>& x509Datas=keyInfo->getX509Datas();
@@ -322,7 +334,7 @@ bool InlineCredential::resolveCerts(const KeyInfo* keyInfo)
 
 bool InlineCredential::resolveCRL(const KeyInfo* keyInfo)
 {
-    Category& log = Category::getInstance(XMLTOOLING_LOGCAT".KeyInfoResolver");
+    Category& log = Category::getInstance(XMLTOOLING_LOGCAT".KeyInfoResolver."INLINE_KEYINFO_RESOLVER);
 
     // Check for ds:X509Data
     const vector<X509Data*>& x509Datas=keyInfo->getX509Datas();
@@ -395,10 +407,10 @@ void InlineCredential::resolve(DSIGKeyInfoList* keyInfo, int types)
         }
         catch(XSECException& e) {
             auto_ptr_char temp(e.getMsg());
-            Category::getInstance(XMLTOOLING_LOGCAT".KeyResolver").error("caught XML-Security exception loading certificate: %s", temp.get());
+            Category::getInstance(XMLTOOLING_LOGCAT".KeyResolver."INLINE_KEYINFO_RESOLVER).error("caught XML-Security exception loading certificate: %s", temp.get());
         }
         catch(XSECCryptoException& e) {
-            Category::getInstance(XMLTOOLING_LOGCAT".KeyResolver").error("caught XML-Security exception loading certificate: %s", e.getMsg());
+            Category::getInstance(XMLTOOLING_LOGCAT".KeyResolver."INLINE_KEYINFO_RESOLVER).error("caught XML-Security exception loading certificate: %s", e.getMsg());
         }
     }
 
@@ -431,10 +443,10 @@ void InlineCredential::resolve(DSIGKeyInfoList* keyInfo, int types)
                     }
                     catch(XSECException& e) {
                         auto_ptr_char temp(e.getMsg());
-                        Category::getInstance(XMLTOOLING_LOGCAT".KeyResolver").error("caught XML-Security exception loading CRL: %s", temp.get());
+                        Category::getInstance(XMLTOOLING_LOGCAT".KeyResolver."INLINE_KEYINFO_RESOLVER).error("caught XML-Security exception loading CRL: %s", temp.get());
                     }
                     catch(XSECCryptoException& e) {
-                        Category::getInstance(XMLTOOLING_LOGCAT".KeyResolver").error("caught XML-Security exception loading CRL: %s", e.getMsg());
+                        Category::getInstance(XMLTOOLING_LOGCAT".KeyResolver."INLINE_KEYINFO_RESOLVER).error("caught XML-Security exception loading CRL: %s", e.getMsg());
                     }
                 }
             }