Tagging 1.3.1 release.
[shibboleth/xmltooling.git] / xmltooling / XMLToolingConfig.cpp
index d36d746..cadf7bc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2007 Internet2
+ *  Copyright 2001-2009 Internet2
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
 /**
  * XMLToolingConfig.cpp
  *
- * Library configuration
+ * Library configuration.
  */
 
 #include "internal.h"
 #include "XMLToolingConfig.h"
 #include "encryption/Encryption.h"
 #include "encryption/Encrypter.h"
-#include "io/HTTPRequest.h"
-#include "io/HTTPResponse.h"
 #include "impl/UnknownElement.h"
+#include "io/HTTPResponse.h"
 #include "security/TrustEngine.h"
 #include "security/OpenSSLCryptoX509CRL.h"
 #include "security/CredentialResolver.h"
 #include "security/KeyInfoResolver.h"
+#include "signature/KeyInfo.h"
 #include "signature/Signature.h"
 #include "soap/SOAP.h"
-#include "soap/SOAPTransport.h"
 #include "util/NDC.h"
 #include "util/PathResolver.h"
 #include "util/ReplayCache.h"
 #include "util/StorageService.h"
 #include "util/TemplateEngine.h"
+#include "util/Threads.h"
 #include "util/URLEncoder.h"
-#include "util/XMLConstants.h"
 #include "validation/ValidatorSuite.h"
 
 #ifdef HAVE_DLFCN_H
@@ -58,6 +57,7 @@
 # include <log4cpp/OstreamAppender.hh>
 #endif
 #include <xercesc/util/PlatformUtils.hpp>
+#include <xercesc/util/XMLUniDefs.hpp>
 #ifndef XMLTOOLING_NO_XMLSEC
 # include <curl/curl.h>
 # include <openssl/err.h>
@@ -69,6 +69,8 @@ using namespace xmltooling::logging;
 using namespace xmltooling;
 using namespace std;
 
+using xercesc::XMLPlatformUtils;
+
 DECL_XMLTOOLING_EXCEPTION_FACTORY(XMLParserException,xmltooling);
 DECL_XMLTOOLING_EXCEPTION_FACTORY(XMLObjectException,xmltooling);
 DECL_XMLTOOLING_EXCEPTION_FACTORY(MarshallingException,xmltooling);
@@ -107,6 +109,22 @@ namespace xmltooling {
     }
 # endif
 #endif
+
+#ifdef WIN32
+    BOOL LogEvent(
+        LPCSTR  lpUNCServerName,
+        WORD  wType,
+        DWORD  dwEventID,
+        PSID  lpUserSid,
+        LPCSTR  message)
+    {
+        LPCSTR  messages[] = {message, NULL};
+
+        HANDLE hElog = RegisterEventSource(lpUNCServerName, "OpenSAML XMLTooling Library");
+        BOOL res = ReportEvent(hElog, wType, 0, dwEventID, lpUserSid, 1, 0, messages, NULL);
+        return (DeregisterEventSource(hElog) && res);
+    }
+#endif
 }
 
 XMLToolingConfig& XMLToolingConfig::getConfig()
@@ -119,6 +137,20 @@ XMLToolingInternalConfig& XMLToolingInternalConfig::getInternalConfig()
     return g_config;
 }
 
+#ifndef XMLTOOLING_NO_XMLSEC
+XMLToolingConfig::XMLToolingConfig()
+    : m_keyInfoResolver(NULL), m_replayCache(NULL), m_pathResolver(NULL), m_templateEngine(NULL), m_urlEncoder(NULL), clock_skew_secs(180)
+#else
+XMLToolingConfig::XMLToolingConfig()
+    : m_pathResolver(NULL), m_templateEngine(NULL), m_urlEncoder(NULL), clock_skew_secs(180)
+#endif
+{
+}
+
+XMLToolingConfig::~XMLToolingConfig()
+{
+}
+
 bool XMLToolingInternalConfig::log_config(const char* config)
 {
     try {
@@ -174,7 +206,11 @@ bool XMLToolingInternalConfig::log_config(const char* config)
         }
     }
     catch (const ConfigureFailure& e) {
-        Category::getInstance(XMLTOOLING_LOGCAT".Logging").crit("failed to initialize log4cpp: %s", e.what());
+        string msg = string("failed to configure logging: ") + e.what();
+        Category::getInstance(XMLTOOLING_LOGCAT".Logging").crit(msg);
+#ifdef WIN32
+        LogEvent(NULL, EVENTLOG_ERROR_TYPE, 2100, NULL, msg.c_str());
+#endif
         return false;
     }
 
@@ -182,6 +218,22 @@ bool XMLToolingInternalConfig::log_config(const char* config)
 }
 
 #ifndef XMLTOOLING_LITE
+const KeyInfoResolver* XMLToolingConfig::getKeyInfoResolver() const
+{
+    return m_keyInfoResolver;
+}
+
+ReplayCache* XMLToolingConfig::getReplayCache() const
+{
+    return m_replayCache;
+}
+
+void XMLToolingConfig::setKeyInfoResolver(xmltooling::KeyInfoResolver *keyInfoResolver)
+{
+    delete m_keyInfoResolver;
+    m_keyInfoResolver = keyInfoResolver;
+}
+
 void XMLToolingConfig::setReplayCache(ReplayCache* replayCache)
 {
     delete m_replayCache;
@@ -189,6 +241,21 @@ void XMLToolingConfig::setReplayCache(ReplayCache* replayCache)
 }
 #endif
 
+PathResolver* XMLToolingConfig::getPathResolver() const
+{
+    return m_pathResolver;
+}
+
+TemplateEngine* XMLToolingConfig::getTemplateEngine() const
+{
+    return m_templateEngine;
+}
+
+const URLEncoder* XMLToolingConfig::getURLEncoder() const
+{
+    return m_urlEncoder;
+}
+
 void XMLToolingConfig::setPathResolver(PathResolver* pathResolver)
 {
     delete m_pathResolver;
@@ -287,6 +354,9 @@ bool XMLToolingInternalConfig::init()
         m_pathResolver = new PathResolver();
         m_urlEncoder = new URLEncoder();
 
+        HTTPResponse::getAllowedSchemes().push_back("https");
+        HTTPResponse::getAllowedSchemes().push_back("http");
+
         // Register xml:id as an ID attribute.
         static const XMLCh xmlid[] = UNICODE_LITERAL_2(i,d);
         AttributeExtensibleXMLObject::registerIDAttribute(QName(xmlconstants::XML_NS, xmlid));
@@ -527,3 +597,14 @@ void XMLToolingInternalConfig::registerXMLAlgorithms()
     registerXMLAlgorithm(DSIGConstants::s_unicodeStrURIKW_AES256, "AES", 256);
 }
 #endif
+
+#ifdef WIN32
+
+extern "C" __declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID)
+{
+    if (fdwReason == DLL_THREAD_DETACH || fdwReason == DLL_PROCESS_DETACH)
+        ThreadKey::onDetach();
+    return TRUE;
+}
+
+#endif