From 2bca43f62a6859ce908174d90153b327341214d7 Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Wed, 6 Sep 2006 18:03:44 +0000 Subject: [PATCH] Allow for use as XMLTooling extension, clean up some header use in tests. --- saml/SAMLConfig.cpp | 32 ++++++++++++++++++---- saml/SAMLConfig.h | 15 +++++++--- saml/internal.h | 4 +-- saml/saml.vcproj | 24 ++++++++++++++++ samltest/SAMLArtifactCreationTest.h | 1 + samltest/SAMLArtifactType0001Test.h | 1 + samltest/SAMLArtifactType0002Test.h | 1 + samltest/SAMLArtifactType0004Test.h | 1 + samltest/internal.h | 2 +- .../metadata/FilesystemMetadataProviderTest.h | 1 + samltest/samltest.h | 1 + samltest/security/AbstractPKIXTrustEngineTest.h | 1 + samltest/security/ExplicitKeyTrustEngineTest.h | 1 + 13 files changed, 72 insertions(+), 13 deletions(-) diff --git a/saml/SAMLConfig.cpp b/saml/SAMLConfig.cpp index 6f4bf76..a842faf 100644 --- a/saml/SAMLConfig.cpp +++ b/saml/SAMLConfig.cpp @@ -49,6 +49,20 @@ using namespace xmltooling; using namespace log4cpp; using namespace std; +// Expose entry points when used as an extension library + +extern "C" int SAML_API xmltooling_extension_init(void*) +{ + if (SAMLConfig::getConfig().init(false)) + return 0; + return -1; +} + +extern "C" void SAML_API xmltooling_extension_term() +{ + SAMLConfig::getConfig().term(false); +} + DECL_EXCEPTION_FACTORY(ArtifactException,opensaml); DECL_EXCEPTION_FACTORY(MetadataFilterException,opensaml::saml2md); @@ -66,7 +80,7 @@ SAMLInternalConfig& SAMLInternalConfig::getInternalConfig() return g_config; } -bool SAMLInternalConfig::init() +bool SAMLInternalConfig::init(bool initXMLTooling) { #ifdef _DEBUG xmltooling::NDC ndc("init"); @@ -74,8 +88,10 @@ bool SAMLInternalConfig::init() Category& log=Category::getInstance(SAML_LOGCAT".SAMLConfig"); log.debug("library initialization started"); - XMLToolingConfig::getConfig().init(); - log.debug("XMLTooling library initialized"); + if (initXMLTooling) { + XMLToolingConfig::getConfig().init(); + log.debug("XMLTooling library initialized"); + } REGISTER_EXCEPTION_FACTORY(ArtifactException,opensaml); REGISTER_EXCEPTION_FACTORY(MetadataFilterException,opensaml::saml2md); @@ -94,11 +110,12 @@ bool SAMLInternalConfig::init() return true; } -void SAMLInternalConfig::term() +void SAMLInternalConfig::term(bool termXMLTooling) { #ifdef _DEBUG xmltooling::NDC ndc("term"); #endif + Category& log=Category::getInstance(SAML_LOGCAT".SAMLConfig"); saml1::AssertionSchemaValidators.destroyValidators(); saml1p::ProtocolSchemaValidators.destroyValidators(); @@ -110,8 +127,11 @@ void SAMLInternalConfig::term() MetadataProviderManager.deregisterFactories(); TrustEngineManager.deregisterFactories(); - XMLToolingConfig::getConfig().term(); - Category::getInstance(SAML_LOGCAT".SAMLConfig").info("library shutdown complete"); + if (termXMLTooling) { + XMLToolingConfig::getConfig().term(); + log.debug("XMLTooling library shut down"); + } + log.info("library shutdown complete"); } void SAMLInternalConfig::generateRandomBytes(void* buf, unsigned int len) diff --git a/saml/SAMLConfig.h b/saml/SAMLConfig.h index b97bda0..0474707 100644 --- a/saml/SAMLConfig.h +++ b/saml/SAMLConfig.h @@ -69,19 +69,26 @@ namespace opensaml { * Initializes library * * Each process using the library MUST call this function exactly once - * before using any library classes. + * before using any library classes. The flag controls whether this is the + * "dominant" library or not and can allow the SAML library to be loaded + * as an extension of XMLTooling rather than subsuming it. * + * @param initXMLTooling true iff this method should initialize the XMLTooling layer * @return true iff initialization was successful */ - virtual bool init()=0; + virtual bool init(bool initXMLTooling=true)=0; /** * Shuts down library * * Each process using the library SHOULD call this function exactly once - * before terminating itself + * before terminating itself. The flag controls whether this is the + * "dominant" library or not and can allow the SAML library to be loaded + * as an extension of XMLTooling rather than subsuming it. + * + * @param termXMLTooling true iff this method should shutdown the XMLTooling layer */ - virtual void term()=0; + virtual void term(bool termXMLTooling=true)=0; /** * Generate random information using the underlying security library diff --git a/saml/internal.h b/saml/internal.h index 9be5928..72beb8e 100644 --- a/saml/internal.h +++ b/saml/internal.h @@ -89,8 +89,8 @@ namespace opensaml { static SAMLInternalConfig& getInternalConfig(); // global per-process setup and shutdown of runtime - bool init(); - void term(); + bool init(bool initXMLTooling=true); + void term(bool termXMLTooling=true); void generateRandomBytes(void* buf, unsigned int len); void generateRandomBytes(std::string& buf, unsigned int len); diff --git a/saml/saml.vcproj b/saml/saml.vcproj index e5aa7c0..27b7e03 100644 --- a/saml/saml.vcproj +++ b/saml/saml.vcproj @@ -240,6 +240,14 @@ > + + + + + + + + + + + + #include #include #include diff --git a/samltest/SAMLArtifactType0001Test.h b/samltest/SAMLArtifactType0001Test.h index 48c8754..78ef996 100644 --- a/samltest/SAMLArtifactType0001Test.h +++ b/samltest/SAMLArtifactType0001Test.h @@ -15,6 +15,7 @@ */ #include "internal.h" +#include #include using namespace opensaml::saml1p; diff --git a/samltest/SAMLArtifactType0002Test.h b/samltest/SAMLArtifactType0002Test.h index 45365d8..545564a 100644 --- a/samltest/SAMLArtifactType0002Test.h +++ b/samltest/SAMLArtifactType0002Test.h @@ -15,6 +15,7 @@ */ #include "internal.h" +#include #include using namespace opensaml::saml1p; diff --git a/samltest/SAMLArtifactType0004Test.h b/samltest/SAMLArtifactType0004Test.h index e2f57d0..52273aa 100644 --- a/samltest/SAMLArtifactType0004Test.h +++ b/samltest/SAMLArtifactType0004Test.h @@ -15,6 +15,7 @@ */ #include "internal.h" +#include #include using namespace opensaml::saml2p; diff --git a/samltest/internal.h b/samltest/internal.h index 4575bc4..b5e1bd5 100644 --- a/samltest/internal.h +++ b/samltest/internal.h @@ -18,12 +18,12 @@ #include #include -#include #include #include #include #include #include +#include using namespace opensaml; using namespace xmltooling; diff --git a/samltest/saml2/metadata/FilesystemMetadataProviderTest.h b/samltest/saml2/metadata/FilesystemMetadataProviderTest.h index a6093b1..5358d3e 100644 --- a/samltest/saml2/metadata/FilesystemMetadataProviderTest.h +++ b/samltest/saml2/metadata/FilesystemMetadataProviderTest.h @@ -15,6 +15,7 @@ */ #include "internal.h" +#include #include #include #include diff --git a/samltest/samltest.h b/samltest/samltest.h index 4033914..92509d8 100644 --- a/samltest/samltest.h +++ b/samltest/samltest.h @@ -15,6 +15,7 @@ */ #include "internal.h" +#include #include #include diff --git a/samltest/security/AbstractPKIXTrustEngineTest.h b/samltest/security/AbstractPKIXTrustEngineTest.h index 3db7df2..346bade 100644 --- a/samltest/security/AbstractPKIXTrustEngineTest.h +++ b/samltest/security/AbstractPKIXTrustEngineTest.h @@ -15,6 +15,7 @@ */ #include "internal.h" +#include #include #include diff --git a/samltest/security/ExplicitKeyTrustEngineTest.h b/samltest/security/ExplicitKeyTrustEngineTest.h index 53416e9..e531e8a 100644 --- a/samltest/security/ExplicitKeyTrustEngineTest.h +++ b/samltest/security/ExplicitKeyTrustEngineTest.h @@ -15,6 +15,7 @@ */ #include "internal.h" +#include #include #include -- 2.1.4