https://bugs.internet2.edu/jira/browse/CPPXT-42
[shibboleth/xmltooling.git] / xmltooling / XMLToolingConfig.cpp
index d36d746..7e99906 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.
@@ -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()
@@ -174,7 +192,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;
     }
 
@@ -187,6 +209,12 @@ void XMLToolingConfig::setReplayCache(ReplayCache* replayCache)
     delete m_replayCache;
     m_replayCache = replayCache;
 }
+
+void XMLToolingConfig::setKeyInfoResolver(xmltooling::KeyInfoResolver *keyInfoResolver)
+{
+    delete m_keyInfoResolver;
+    m_keyInfoResolver = keyInfoResolver;
+}
 #endif
 
 void XMLToolingConfig::setPathResolver(PathResolver* pathResolver)
@@ -527,3 +555,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