X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2FXMLToolingConfig.cpp;h=82dbc8db80c1436e01f583f9c440a8e395691b1a;hb=d03d73dd5f54e29603cb0ec09eb528291e2700a9;hp=476f8f1b6f9e73fb097ba301dd5b93a919837c9f;hpb=c23ff33b42e70884030059568fd70bc92567ee26;p=shibboleth%2Fxmltooling.git diff --git a/xmltooling/XMLToolingConfig.cpp b/xmltooling/XMLToolingConfig.cpp index 476f8f1..82dbc8d 100644 --- a/xmltooling/XMLToolingConfig.cpp +++ b/xmltooling/XMLToolingConfig.cpp @@ -37,6 +37,7 @@ #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" @@ -164,10 +165,13 @@ bool XMLToolingInternalConfig::log_config(const char* config) root.setPriority(Priority::FATAL); level=true; } - if (level) + if (level) { root.setAppender(new OstreamAppender("default",&cerr)); - else - PropertyConfigurator::configure(config); + } + else { + string path(config); + PropertyConfigurator::configure(m_pathResolver ? m_pathResolver->resolve(path, PathResolver::XMLTOOLING_CFG_FILE).c_str() : config); + } } catch (const ConfigureFailure& e) { Category::getInstance(XMLTOOLING_LOGCAT".Logging").crit("failed to initialize log4cpp: %s", e.what()); @@ -185,6 +189,12 @@ void XMLToolingConfig::setReplayCache(ReplayCache* replayCache) } #endif +void XMLToolingConfig::setPathResolver(PathResolver* pathResolver) +{ + delete m_pathResolver; + m_pathResolver = pathResolver; +} + void XMLToolingConfig::setTemplateEngine(TemplateEngine* templateEngine) { delete m_templateEngine; @@ -215,12 +225,12 @@ bool XMLToolingInternalConfig::init() #endif XMLPlatformUtils::Initialize(); - log.debug("Xerces initialization complete"); + log.debug("Xerces %s initialization complete", XERCES_FULLVERSIONDOT); #ifndef XMLTOOLING_NO_XMLSEC XSECPlatformUtils::Initialise(); m_xsecProvider=new XSECProvider(); - log.debug("XMLSec initialization complete"); + log.debug("XML-Security %s initialization complete", XSEC_FULLVERSIONDOT); #endif m_parserPool=new ParserPool(); @@ -274,6 +284,7 @@ bool XMLToolingInternalConfig::init() m_keyInfoResolver = KeyInfoResolverManager.newPlugin(INLINE_KEYINFO_RESOLVER,NULL); #endif + m_pathResolver = new PathResolver(); m_urlEncoder = new URLEncoder(); // Register xml:id as an ID attribute. @@ -298,7 +309,7 @@ bool XMLToolingInternalConfig::init() # endif #endif - log.info("library initialization complete"); + log.info("%s library initialization complete", PACKAGE_STRING); return true; } @@ -331,6 +342,9 @@ void XMLToolingInternalConfig::term() m_replayCache = NULL; #endif + delete m_pathResolver; + m_pathResolver = NULL; + delete m_templateEngine; m_templateEngine = NULL; @@ -375,7 +389,7 @@ void XMLToolingInternalConfig::term() #ifdef _DEBUG xmltooling::NDC ndc("term"); #endif - Category::getInstance(XMLTOOLING_LOGCAT".XMLToolingConfig").info("library shutdown complete"); + Category::getInstance(XMLTOOLING_LOGCAT".XMLToolingConfig").info("%s library shutdown complete", PACKAGE_STRING); } Lockable* XMLToolingInternalConfig::lock() @@ -399,30 +413,27 @@ bool XMLToolingInternalConfig::load_library(const char* path, void* context) Locker locker(this); + string resolved(path); + m_pathResolver->resolve(resolved, PathResolver::XMLTOOLING_LIB_FILE); + #if defined(WIN32) HMODULE handle=NULL; - char* fixed=const_cast(path); - if (strchr(fixed,'/')) { - fixed=strdup(path); - char* p=fixed; - while (p=strchr(p,'/')) - *p='\\'; - } - + for (string::iterator i = resolved.begin(); i != resolved.end(); ++i) + if (*i == '/') + *i = '\\'; + UINT em=SetErrorMode(SEM_FAILCRITICALERRORS); try { - handle=LoadLibraryEx(fixed,NULL,LOAD_WITH_ALTERED_SEARCH_PATH); + handle=LoadLibraryEx(resolved.c_str(),NULL,LOAD_WITH_ALTERED_SEARCH_PATH); if (!handle) - handle=LoadLibraryEx(fixed,NULL,0); + handle=LoadLibraryEx(resolved.c_str(),NULL,0); if (!handle) - throw runtime_error(string("unable to load extension library: ") + fixed); + throw runtime_error(string("unable to load extension library: ") + resolved); FARPROC fn=GetProcAddress(handle,"xmltooling_extension_init"); if (!fn) - throw runtime_error(string("unable to locate xmltooling_extension_init entry point: ") + fixed); + throw runtime_error(string("unable to locate xmltooling_extension_init entry point: ") + resolved); if (reinterpret_cast(fn)(context)!=0) - throw runtime_error(string("detected error in xmltooling_extension_init: ") + fixed); - if (fixed!=path) - free(fixed); + throw runtime_error(string("detected error in xmltooling_extension_init: ") + resolved); SetErrorMode(em); } catch(runtime_error& e) { @@ -430,26 +441,24 @@ bool XMLToolingInternalConfig::load_library(const char* path, void* context) if (handle) FreeLibrary(handle); SetErrorMode(em); - if (fixed!=path) - free(fixed); return false; } #elif defined(HAVE_DLFCN_H) - void* handle=dlopen(path,RTLD_LAZY); + void* handle=dlopen(resolved.c_str(),RTLD_LAZY); if (!handle) - throw runtime_error(string("unable to load extension library '") + path + "': " + dlerror()); + throw runtime_error(string("unable to load extension library '") + resolved + "': " + dlerror()); int (*fn)(void*)=(int (*)(void*))(dlsym(handle,"xmltooling_extension_init")); if (!fn) { dlclose(handle); throw runtime_error( - string("unable to locate xmltooling_extension_init entry point in '") + path + "': " + + string("unable to locate xmltooling_extension_init entry point in '") + resolved + "': " + (dlerror() ? dlerror() : "unknown error") ); } try { if (fn(context)!=0) - throw runtime_error(string("detected error in xmltooling_extension_init in ") + path); + throw runtime_error(string("detected error in xmltooling_extension_init in ") + resolved); } catch(runtime_error& e) { log.error(e.what()); @@ -461,7 +470,7 @@ bool XMLToolingInternalConfig::load_library(const char* path, void* context) # error "Don't know about dynamic loading on this platform!" #endif m_libhandles.push_back(handle); - log.info("loaded extension: %s", path); + log.info("loaded extension: %s", resolved.c_str()); return true; } @@ -475,9 +484,9 @@ void xmltooling::log_openssl() unsigned long code=ERR_get_error_line_data(&file,&line,&data,&flags); while (code) { Category& log=Category::getInstance("OpenSSL"); - log.errorStream() << "error code: " << code << " in " << file << ", line " << line << CategoryStream::ENDLINE; + log.errorStream() << "error code: " << code << " in " << file << ", line " << line << logging::eol; if (data && (flags & ERR_TXT_STRING)) - log.errorStream() << "error data: " << data << CategoryStream::ENDLINE; + log.errorStream() << "error data: " << data << logging::eol; code=ERR_get_error_line_data(&file,&line,&data,&flags); } }