User: hr Date: 06/06/19 18:43:27 Modified: /dba/connectivity/source/drivers/mozab/ MDriver.cxx
Log: INTEGRATION: CWS warnings01 (1.14.28); FILE MERGED 2006/05/18 12:06:20 fs 1.14.28.6: #i65444# 2006/04/20 14:52:04 sb 1.14.28.5: #i53898# Made code compile and/or warning-free again after resync to SRC680m162. 2006/04/07 20:22:38 sb 1.14.28.4: RESYNC: (1.14-1.15); FILE MERGED 2006/03/29 12:39:24 fs 1.14.28.3: getSdbcSceme not reachable for the driver - need to locate symbol on demand 2005/11/21 10:07:51 fs 1.14.28.2: #i57457# warning-free code on unx* 2005/11/16 12:59:12 fs 1.14.28.1: #i57457# warning free code File Changes: Directory: /dba/connectivity/source/drivers/mozab/ ================================================== File [changed]: MDriver.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/mozab/MDriver.cxx?r1=1.15&r2=1.16 Delta lines: +90 -94 --------------------- --- MDriver.cxx 29 Mar 2006 12:17:51 -0000 1.15 +++ MDriver.cxx 20 Jun 2006 01:43:25 -0000 1.16 @@ -62,8 +62,8 @@ MozabDriver::MozabDriver( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) : ODriver_BASE(m_aMutex), m_xMSFactory( _rxFactory ) - ,s_hModule(NULL) - ,s_pCreationFunc(NULL) + ,m_hModule(NULL) + ,m_pCreationFunc(NULL) { } // ----------------------------------------------------------------------------- @@ -86,11 +86,11 @@ connectivity::OWeakRefArray().swap(m_xConnections); // this really clears ODriver_BASE::disposing(); - if(s_hModule) + if(m_hModule) { - s_pCreationFunc = NULL; - osl_unloadModule(s_hModule); - s_hModule = NULL; + m_pCreationFunc = NULL; + osl_unloadModule(m_hModule); + m_hModule = NULL; } } @@ -139,19 +139,21 @@ // -------------------------------------------------------------------------------- Reference< XConnection > SAL_CALL MozabDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException) { - if ( ! acceptsURL(url) ) + if ( !ensureInit() ) + return NULL; + + if ( ! acceptsURL( url ) ) return NULL; // create a new connection with the given properties and append it to our vector - registerClient(); Reference< XConnection > xCon; - if (s_pCreationFunc) + if (m_pCreationFunc) { ::osl::MutexGuard aGuard(m_aMutex); //We must make sure we create an com.sun.star.mozilla.MozillaBootstrap brfore call any mozilla codes Reference<XInterface> xInstance = m_xMSFactory->createInstance(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.mozilla.MozillaBootstrap")) ); OSL_ENSURE( xInstance.is(), "failed to create instance" ); - OConnection* pCon = reinterpret_cast<OConnection*>((*s_pCreationFunc)(this)); + OConnection* pCon = reinterpret_cast<OConnection*>((*m_pCreationFunc)(this)); xCon = pCon; // important here because otherwise the connection could be deleted inside (refcount goes -> 0) pCon->construct(url,info); // late constructor call which can throw exception and allows a correct dtor call when so m_xConnections.push_back(WeakReferenceHelper(*pCon)); @@ -170,15 +172,21 @@ sal_Bool SAL_CALL MozabDriver::acceptsURL( const ::rtl::OUString& url ) throw(SQLException, RuntimeException) { + if ( !ensureInit() ) + return sal_False; + // here we have to look if we support this url format - return acceptsURL_Stat(url) != Unknown; + return impl_classifyURL(url) != Unknown; } // -------------------------------------------------------------------------------- -Sequence< DriverPropertyInfo > SAL_CALL MozabDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException) +Sequence< DriverPropertyInfo > SAL_CALL MozabDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException) { + if ( !ensureInit() ) + return Sequence< DriverPropertyInfo >(); + if ( acceptsURL(url) ) { - if ( acceptsURL_Stat(url) != LDAP ) + if ( impl_classifyURL(url) != LDAP ) return Sequence< DriverPropertyInfo >(); ::std::vector< DriverPropertyInfo > aDriverInfo; @@ -213,7 +221,7 @@ return 0; // depends on you } // -------------------------------------------------------------------------------- -EDriverType MozabDriver::acceptsURL_Stat( const ::rtl::OUString& url ) +EDriverType MozabDriver::impl_classifyURL( const ::rtl::OUString& url ) { // Skip 'sdbc:mozab: part of URL // @@ -236,75 +244,78 @@ else aAddrbookScheme = aAddrbookURI.copy(0, nLen); - if ( aAddrbookScheme.compareToAscii( MozabDriver::getSDBC_SCHEME_MOZILLA() ) == 0 ) - return Mozilla; - if ( aAddrbookScheme.compareToAscii( MozabDriver::getSDBC_SCHEME_THUNDERBIRD() ) == 0 ) - return ThunderBird; - if ( aAddrbookScheme.compareToAscii( MozabDriver::getSDBC_SCHEME_LDAP() ) == 0 ) - return LDAP; - + struct __scheme_map + { + EDriverType eType; + const sal_Char* pScheme; + } aSchemeMap[] = + { #if defined(WNT) || defined(WIN) - if ( aAddrbookScheme.compareToAscii( MozabDriver::getSDBC_SCHEME_OUTLOOK_MAPI() ) == 0 ) - return Outlook; - if ( aAddrbookScheme.compareToAscii( MozabDriver::getSDBC_SCHEME_OUTLOOK_EXPRESS() ) == 0 ) - return OutlookExpress; - + { Outlook, "outlook" }, + { OutlookExpress, "outlookexp" }, #endif + { Mozilla, "mozilla" }, + { ThunderBird, "thunderbird" }, + { LDAP, "ldap" } + }; + + for ( size_t i=0; i < sizeof( aSchemeMap ) / sizeof( aSchemeMap[0] ); ++i ) + { + if ( aAddrbookScheme.compareToAscii( aSchemeMap[i].pScheme ) == 0 ) + return aSchemeMap[i].eType; + } return Unknown; } -// ----------------------------------------------------------------------------- -const sal_Char* MozabDriver::getSDBC_SCHEME_MOZILLA() -{ - static sal_Char* SDBC_SCHEME_MOZILLA = MOZAB_MOZILLA_SCHEMA; - return SDBC_SCHEME_MOZILLA; -} -// ----------------------------------------------------------------------------- -const sal_Char* MozabDriver::getSDBC_SCHEME_THUNDERBIRD() -{ - static sal_Char* SDBC_SCHEME_THUNDERBIRD = MOZAB_THUNDERBIRD_SCHEMA; - return SDBC_SCHEME_THUNDERBIRD; -} -// ----------------------------------------------------------------------------- -const sal_Char* MozabDriver::getSDBC_SCHEME_LDAP() -{ - static sal_Char* SDBC_SCHEME_LDAP = MOZAB_LDAP_SCHEMA; - return SDBC_SCHEME_LDAP; -} -// ----------------------------------------------------------------------------- -const sal_Char* MozabDriver::getSDBC_SCHEME_OUTLOOK_MAPI() + +// -------------------------------------------------------------------------------- +namespace { - static sal_Char* SDBC_SCHEME_OUTLOOK_MAPI = MOZAB_OUTLOOK_SCHEMA; - return SDBC_SCHEME_OUTLOOK_MAPI; + template< typename FUNCTION > + void lcl_getFunctionFromModuleOrUnload( oslModule& _rModule, const sal_Char* _pAsciiSymbolName, FUNCTION& _rFunction ) + { + _rFunction = NULL; + if ( _rModule ) + { + const ::rtl::OUString sSymbolName = ::rtl::OUString::createFromAscii( _pAsciiSymbolName ); + _rFunction = (FUNCTION)( osl_getFunctionSymbol( _rModule, sSymbolName.pData ) ); + + if ( !_rFunction ) + { // did not find the symbol + OSL_ENSURE( false, ::rtl::OString( "lcl_getFunctionFromModuleOrUnload: could not find the symbol " ) + ::rtl::OString( _pAsciiSymbolName ) ); + osl_unloadModule( _rModule ); + _rModule = NULL; + } + } + } } + // ----------------------------------------------------------------------------- -const sal_Char* MozabDriver::getSDBC_SCHEME_OUTLOOK_EXPRESS() +bool MozabDriver::ensureInit() { - static sal_Char* SDBC_SCHEME_OUTLOOK_EXPRESS = MOZAB_OUTLOOKEXP_SCHEMA; - return SDBC_SCHEME_OUTLOOK_EXPRESS; -}// ----------------------------------------------------------------------------- -void MozabDriver::registerClient() -{ - if (!s_hModule) - { - OSL_ENSURE(NULL == s_pCreationFunc, "MozabDriver::registerClient: inconsistence: already have a factory function!"); + if ( m_hModule ) + return true; + + OSL_ENSURE(NULL == m_pCreationFunc, "MozabDriver::ensureInit: inconsistence: already have a factory function!"); const ::rtl::OUString sModuleName = ::rtl::OUString::createFromAscii(SAL_MODULENAME( "mozabdrv2" )); // load the dbtools library - s_hModule = osl_loadModule(sModuleName.pData, 0); - OSL_ENSURE(NULL != s_hModule, "MozabDriver::registerClient: could not load the dbtools library!"); - if (NULL != s_hModule) - { - // first, we need to announce our service factory to the lib - // see the documentation of setMozabServiceFactory for more details - const ::rtl::OUString sSetFactoryFuncName( RTL_CONSTASCII_USTRINGPARAM( "setMozabServiceFactory" ) ); - // reinterpret_cast< OSetMozabServiceFactory >>> removed GNU C - OSetMozabServiceFactory pSetFactoryFunc = - ( OSetMozabServiceFactory )( osl_getSymbol( s_hModule, sSetFactoryFuncName.pData ) ); + m_hModule = osl_loadModule(sModuleName.pData, 0); + OSL_ENSURE(NULL != m_hModule, "MozabDriver::ensureInit: could not load the dbtools library!"); + if ( !m_hModule ) + return false; - OSL_ENSURE( pSetFactoryFunc, "MozabDriver::registerClient: missing an entry point!" ); - if ( pSetFactoryFunc && m_xMSFactory.is() ) + OSetMozabServiceFactory pSetFactoryFunc( NULL ); + + lcl_getFunctionFromModuleOrUnload( m_hModule, "setMozabServiceFactory", pSetFactoryFunc ); + lcl_getFunctionFromModuleOrUnload( m_hModule, "OMozabConnection_CreateInstance", m_pCreationFunc ); + + if ( !m_hModule ) + // one of the symbols did not exist + return false; + + if ( m_xMSFactory.is() ) { // for purpose of transfer safety, the interface needs to be acuired once // (will be release by the callee) @@ -312,21 +323,6 @@ ( *pSetFactoryFunc )( m_xMSFactory.get() ); } - // get the symbol for the method creating the factory - const ::rtl::OUString sFactoryCreationFunc = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("OMozabConnection_CreateInstance")); - // reinterpret_cast<OMozabConnection_CreateInstanceFunction> removed GNU C - s_pCreationFunc = (OMozabConnection_CreateInstanceFunction)(osl_getSymbol(s_hModule, sFactoryCreationFunc.pData)); - - if (NULL == s_pCreationFunc) - { // did not find the symbol - OSL_ENSURE(sal_False, "MozabDriver::registerClient: could not find the symbol for creating the factory!"); - osl_unloadModule(s_hModule); - s_hModule = NULL; - } - } - } + return true; } // ----------------------------------------------------------------------------- - - - --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
