diff --git a/main/xmlhelp/prj/build.lst b/main/xmlhelp/prj/build.lst index 7430bf6..13ca8b3 100644 --- a/main/xmlhelp/prj/build.lst +++ b/main/xmlhelp/prj/build.lst @@ -1,4 +1,4 @@ -xh xmlhelp : comphelper ucbhelper LIBXSLT:libxslt unoil BERKELEYDB:berkeleydb LUCENE:lucene javaunohelper l10ntools NULL +xh xmlhelp : comphelper ucbhelper LIBXSLT:libxslt unoil LUCENE:lucene javaunohelper l10ntools NULL xh xmlhelp usr1 - all xh_mkout NULL xh xmlhelp\inc nmake - all xh_inc NULL xh xmlhelp\source\treeview nmake - all xh_treeview xh_inc NULL diff --git a/main/xmlhelp/source/cxxhelp/provider/databases.cxx b/main/xmlhelp/source/cxxhelp/provider/databases.cxx index 88c1dea..d23701d 100755 --- a/main/xmlhelp/source/cxxhelp/provider/databases.cxx +++ b/main/xmlhelp/source/cxxhelp/provider/databases.cxx @@ -67,7 +67,6 @@ #include "urlparameter.hxx" using namespace chelp; -using namespace berkeleydbproxy; using namespace com::sun::star; using namespace com::sun::star::uno; using namespace com::sun::star::io; @@ -201,8 +200,6 @@ Databases::~Databases() DatabasesTable::iterator it = m_aDatabases.begin(); while( it != m_aDatabases.end() ) { - if( it->second ) - it->second->close( 0 ); delete it->second; ++it; } @@ -608,7 +605,7 @@ rtl::OUString Databases::country( const rtl::OUString& Language ) -Db* Databases::getBerkeley( const rtl::OUString& Database, +helpdatafileproxy::Hdf* Databases::getHelpDataFile( const rtl::OUString& Database, const rtl::OUString& Language, bool helpText, const rtl::OUString* pExtensionPath ) { @@ -633,7 +630,7 @@ Db* Databases::getBerkeley( const rtl::OUString& Database, if( aPair.second && ! it->second ) { - Db* table = new Db(); + helpdatafileproxy::Hdf* pHdf = 0; rtl::OUString fileURL; if( pExtensionPath ) @@ -641,34 +638,18 @@ Db* Databases::getBerkeley( const rtl::OUString& Database, else fileURL = getInstallPathAsURL() + key; - rtl::OUString fileNameDBHelp( fileURL ); + rtl::OUString fileNameHDFHelp( fileURL ); //Extensions always use the new format if( pExtensionPath != NULL ) - fileNameDBHelp += rtl::OUString::createFromAscii( "_" ); + fileNameHDFHelp += rtl::OUString::createFromAscii( "_" ); //SimpleFileAccess takes file URLs as arguments!!! Using filenames works accidentally but //fails for example when using long path names on Windows (starting with \\?\) - if( m_xSFA->exists( fileNameDBHelp ) ) + if( m_xSFA->exists( fileNameHDFHelp ) ) { - DBHelp* pDBHelp = new DBHelp( fileNameDBHelp, m_xSFA ); - table->setDBHelp( pDBHelp ); - -#ifdef TEST_DBHELP - bool bSuccess; - bool bOldDbAccess = false; - bSuccess = pDBHelp->testAgainstDb( fileURL, bOldDbAccess ); - - bOldDbAccess = true; - bSuccess = pDBHelp->testAgainstDb( fileURL, bOldDbAccess ); -#endif - } - else if( table->open( 0,fileURL, DB_BTREE,DB_RDONLY,0644 ) ) - { - table->close( 0 ); - delete table; - table = 0; + pHdf = new helpdatafileproxy::Hdf( fileNameHDFHelp, m_xSFA ); } - it->second = table; + it->second = pHdf; } return it->second; @@ -776,18 +757,18 @@ namespace chelp { KeywordInfo::KeywordElement::KeywordElement( Databases *pDatabases, - Db* pDb, + helpdatafileproxy::Hdf* pHdf, rtl::OUString& ky, rtl::OUString& data ) : key( ky ) { pDatabases->replaceName( key ); - init( pDatabases,pDb,data ); + init( pDatabases,pHdf,data ); } -void KeywordInfo::KeywordElement::init( Databases *pDatabases,Db* pDb,const rtl::OUString& ids ) +void KeywordInfo::KeywordElement::init( Databases *pDatabases,helpdatafileproxy::Hdf* pHdf,const rtl::OUString& ids ) { const sal_Unicode* idstr = ids.getStr(); std::vector< rtl::OUString > id,anchor; @@ -823,28 +804,15 @@ void KeywordInfo::KeywordElement::init( Databases *pDatabases,Db* pDb,const rtl: nSize = 0; pData = pEmpty; - if( pDb ) + if( pHdf ) { rtl::OString idi( id[i].getStr(),id[i].getLength(),RTL_TEXTENCODING_UTF8 ); - DBHelp* pDBHelp = pDb->getDBHelp(); - if( pDBHelp != NULL ) - { - DBData aDBData; - bool bSuccess = pDBHelp->getValueForKey( idi, aDBData ); - if( bSuccess ) - { - nSize = aDBData.getSize(); - pData = aDBData.getData(); - } - } - else + helpdatafileproxy::HDFData aHDFData; + bool bSuccess = pHdf->getValueForKey( idi, aHDFData ); + if( bSuccess ) { - Dbt key_( static_cast< void* >( const_cast< sal_Char* >( idi.getStr() ) ), - idi.getLength() ); - Dbt data; - pDb->get( 0,&key_,&data,0 ); - nSize = data.get_size(); - pData = static_cast( data.get_data() ); + nSize = aHDFData.getSize(); + pData = aHDFData.getData(); } } @@ -943,30 +911,26 @@ KeywordInfo* Databases::getKeyword( const rtl::OUString& Database, bool bExtension = false; while( (fileURL = aDbFileIt.nextDbFile( bExtension )).getLength() > 0 ) { - Db table; - - rtl::OUString fileNameDBHelp( fileURL ); + rtl::OUString fileNameHDFHelp( fileURL ); if( bExtension ) - fileNameDBHelp += rtl::OUString::createFromAscii( "_" ); - if( m_xSFA->exists( fileNameDBHelp ) ) + fileNameHDFHelp += rtl::OUString::createFromAscii( "_" ); + if( m_xSFA->exists( fileNameHDFHelp ) ) { - DBHelp aDBHelp( fileNameDBHelp, m_xSFA ); + helpdatafileproxy::Hdf aHdf( fileNameHDFHelp, m_xSFA ); - DBData aKey; - DBData aValue; - if( aDBHelp.startIteration() ) + helpdatafileproxy::HDFData aKey; + helpdatafileproxy::HDFData aValue; + if( aHdf.startIteration() ) { - Db* idmap = getBerkeley( Database,Language ); - - DBHelp* pDBHelp = idmap->getDBHelp(); - if( pDBHelp != NULL ) + helpdatafileproxy::Hdf* pHdf = getHelpDataFile( Database,Language ); + if( pHdf != NULL ) { bool bOptimizeForPerformance = true; - pDBHelp->releaseHashMap(); - pDBHelp->createHashMap( bOptimizeForPerformance ); + pHdf->releaseHashMap(); + pHdf->createHashMap( bOptimizeForPerformance ); } - while( aDBHelp.getNextKeyAndValue( aKey, aValue ) ) + while( aHdf.getNextKeyAndValue( aKey, aValue ) ) { rtl::OUString keyword( aKey.getData(), aKey.getSize(), RTL_TEXTENCODING_UTF8 ); @@ -981,70 +945,16 @@ KeywordInfo* Databases::getKeyword( const rtl::OUString& Database, continue; aVector.push_back( KeywordInfo::KeywordElement( this, - idmap, + pHdf, keyword, doclist ) ); } - aDBHelp.stopIteration(); - - if( pDBHelp != NULL ) - pDBHelp->releaseHashMap(); - } - -#ifdef TEST_DBHELP - bool bSuccess; - bool bOldDbAccess = false; - bSuccess = aDBHelp.testAgainstDb( fileURL, bOldDbAccess ); + aHdf.stopIteration(); - bOldDbAccess = true; - bSuccess = aDBHelp.testAgainstDb( fileURL, bOldDbAccess ); - - int nDummy = 0; -#endif - } - - else if( 0 == table.open( 0,fileURL,DB_BTREE,DB_RDONLY,0644 ) ) - { - Db* idmap = getBerkeley( Database,Language ); - - bool first = true; - - Dbc* cursor = 0; - table.cursor( 0,&cursor,0 ); - Dbt key_,data; - key_.set_flags( DB_DBT_MALLOC ); // Initially the cursor must allocate the necessary memory - data.set_flags( DB_DBT_MALLOC ); - while( cursor && DB_NOTFOUND != cursor->get( &key_,&data,DB_NEXT ) ) - { - rtl::OUString keyword( static_cast(key_.get_data()), - key_.get_size(), - RTL_TEXTENCODING_UTF8 ); - rtl::OUString doclist( static_cast(data.get_data()), - data.get_size(), - RTL_TEXTENCODING_UTF8 ); - - bool bBelongsToDatabase = true; - if( bExtension ) - bBelongsToDatabase = checkModuleMatchForExtension( Database, doclist ); - - if( !bBelongsToDatabase ) - continue; - - aVector.push_back( KeywordInfo::KeywordElement( this, - idmap, - keyword, - doclist ) ); - if( first ) - { - key_.set_flags( DB_DBT_REALLOC ); - data.set_flags( DB_DBT_REALLOC ); - first = false; - } + if( pHdf != NULL ) + pHdf->releaseHashMap(); } - - if( cursor ) cursor->close(); } - table.close( 0 ); } // sorting @@ -1361,8 +1271,7 @@ void Databases::setActiveText( const rtl::OUString& Module, rtl::OString id( Id.getStr(),Id.getLength(),RTL_TEXTENCODING_UTF8 ); EmptyActiveTextSet::iterator it = m_aEmptyActiveTextSet.find( id ); bool bFoundAsEmpty = ( it != m_aEmptyActiveTextSet.end() ); - Dbt data; - DBData aDBData; + helpdatafileproxy::HDFData aHDFData; int nSize = 0; const sal_Char* pData = NULL; @@ -1370,27 +1279,12 @@ void Databases::setActiveText( const rtl::OUString& Module, bool bSuccess = false; if( !bFoundAsEmpty ) { - Db* db; - Dbt key( static_cast< void* >( const_cast< sal_Char* >( id.getStr() ) ),id.getLength() ); - while( !bSuccess && (db = aDbIt.nextDb()) != NULL ) + helpdatafileproxy::Hdf* pHdf = 0; + while( !bSuccess && (pHdf = aDbIt.nextHdf()) != NULL ) { - DBHelp* pDBHelp = db->getDBHelp(); - if( pDBHelp != NULL ) - { - bSuccess = pDBHelp->getValueForKey( id, aDBData ); - nSize = aDBData.getSize(); - pData = aDBData.getData(); - } - else - { - int err = db->get( 0, &key, &data, 0 ); - if( err == 0 ) - { - bSuccess = true; - nSize = data.get_size(); - pData = static_cast( data.get_data() ); - } - } + bSuccess = pHdf->getValueForKey( id, aHDFData ); + nSize = aHDFData.getSize(); + pData = aHDFData.getData(); } } @@ -1736,16 +1630,16 @@ void ExtensionIteratorBase::implGetLanguageVectorFromPackage( ::std::vector< ::r //=================================================================== // class DataBaseIterator -Db* DataBaseIterator::nextDb( rtl::OUString* o_pExtensionPath, rtl::OUString* o_pExtensionRegistryPath ) +helpdatafileproxy::Hdf* DataBaseIterator::nextHdf( rtl::OUString* o_pExtensionPath, rtl::OUString* o_pExtensionRegistryPath ) { - Db* pRetDb = NULL; + helpdatafileproxy::Hdf* pRetHdf = NULL; - while( !pRetDb && m_eState != END_REACHED ) + while( !pRetHdf && m_eState != END_REACHED ) { switch( m_eState ) { case INITIAL_MODULE: - pRetDb = m_rDatabases.getBerkeley( m_aInitialModule, m_aLanguage, m_bHelpText ); + pRetHdf = m_rDatabases.getHelpDataFile( m_aInitialModule, m_aLanguage, m_bHelpText ); m_eState = USER_EXTENSIONS; // Later: SHARED_MODULE break; @@ -1759,7 +1653,7 @@ Db* DataBaseIterator::nextDb( rtl::OUString* o_pExtensionPath, rtl::OUString* o_ Reference< deployment::XPackage > xHelpPackage = implGetNextUserHelpPackage( xParentPackageBundle ); if( !xHelpPackage.is() ) break; - pRetDb = implGetDbFromPackage( xHelpPackage, o_pExtensionPath, o_pExtensionRegistryPath ); + pRetHdf = implGetHdfFromPackage( xHelpPackage, o_pExtensionPath, o_pExtensionRegistryPath ); break; } @@ -1770,7 +1664,7 @@ Db* DataBaseIterator::nextDb( rtl::OUString* o_pExtensionPath, rtl::OUString* o_ if( !xHelpPackage.is() ) break; - pRetDb = implGetDbFromPackage( xHelpPackage, o_pExtensionPath, o_pExtensionRegistryPath ); + pRetHdf = implGetHdfFromPackage( xHelpPackage, o_pExtensionPath, o_pExtensionRegistryPath ); break; } @@ -1781,7 +1675,7 @@ Db* DataBaseIterator::nextDb( rtl::OUString* o_pExtensionPath, rtl::OUString* o_ if( !xHelpPackage.is() ) break; - pRetDb = implGetDbFromPackage( xHelpPackage, o_pExtensionPath, o_pExtensionRegistryPath ); + pRetHdf = implGetHdfFromPackage( xHelpPackage, o_pExtensionPath, o_pExtensionRegistryPath ); break; } @@ -1791,10 +1685,10 @@ Db* DataBaseIterator::nextDb( rtl::OUString* o_pExtensionPath, rtl::OUString* o_ } } - return pRetDb; + return pRetHdf; } -Db* DataBaseIterator::implGetDbFromPackage( Reference< deployment::XPackage > xPackage, +helpdatafileproxy::Hdf* DataBaseIterator::implGetHdfFromPackage( Reference< deployment::XPackage > xPackage, rtl::OUString* o_pExtensionPath, rtl::OUString* o_pExtensionRegistryPath ) { @@ -1808,18 +1702,18 @@ Db* DataBaseIterator::implGetDbFromPackage( Reference< deployment::XPackage > xP return NULL; } - Db* pRetDb = NULL; + helpdatafileproxy::Hdf* pRetHdf = NULL; if (optRegData.IsPresent && optRegData.Value.getLength() > 0) { rtl::OUString aRegDataUrl(optRegData.Value); aRegDataUrl += aSlash; rtl::OUString aUsedLanguage = m_aLanguage; - pRetDb = m_rDatabases.getBerkeley( + pRetHdf = m_rDatabases.getHelpDataFile( aHelpFilesBaseName, aUsedLanguage, m_bHelpText, &aRegDataUrl); // Language fallback - if( !pRetDb ) + if( !pRetHdf ) { ::std::vector< ::rtl::OUString > av; implGetLanguageVectorFromPackage( av, xPackage ); @@ -1833,7 +1727,7 @@ Db* DataBaseIterator::implGetDbFromPackage( Reference< deployment::XPackage > xP if( pFound != av.end() ) { aUsedLanguage = *pFound; - pRetDb = m_rDatabases.getBerkeley( + pRetHdf = m_rDatabases.getHelpDataFile( aHelpFilesBaseName, aUsedLanguage, m_bHelpText, &aRegDataUrl); } } @@ -1845,7 +1739,7 @@ Db* DataBaseIterator::implGetDbFromPackage( Reference< deployment::XPackage > xP *o_pExtensionRegistryPath = xPackage->getURL() + aSlash + aUsedLanguage; } - return pRetDb; + return pRetHdf; } diff --git a/main/xmlhelp/source/cxxhelp/provider/databases.hxx b/main/xmlhelp/source/cxxhelp/provider/databases.hxx index 3fed315..5b7c3a5 100644 --- a/main/xmlhelp/source/cxxhelp/provider/databases.hxx +++ b/main/xmlhelp/source/cxxhelp/provider/databases.hxx @@ -50,9 +50,9 @@ // Forward declaration -namespace berkeleydbproxy { +namespace helpdatafileproxy { - class Db; + class Hdf; } @@ -116,7 +116,7 @@ namespace chelp { public: KeywordElement( Databases* pDatabases, - berkeleydbproxy::Db* pDb, + helpdatafileproxy::Hdf* pHdf, rtl::OUString& key, rtl::OUString& ids ); @@ -127,7 +127,7 @@ namespace chelp { com::sun::star::uno::Sequence< rtl::OUString > listAnchor; com::sun::star::uno::Sequence< rtl::OUString > listTitle; - void init( Databases *pDatabases,berkeleydbproxy::Db* pDb,const rtl::OUString& ids ); + void init( Databases *pDatabases,helpdatafileproxy::Hdf* pHdf,const rtl::OUString& ids ); }; @@ -205,7 +205,7 @@ namespace chelp { KeywordInfo* getKeyword( const rtl::OUString& Module, const rtl::OUString& Language ); - berkeleydbproxy::Db* getBerkeley( const rtl::OUString& Module, + helpdatafileproxy::Hdf* getHelpDataFile( const rtl::OUString& Module, const rtl::OUString& Language, bool helpText = false, const rtl::OUString* pExtensionPath = NULL ); @@ -328,7 +328,7 @@ namespace chelp { std::vector< rtl::OUString > m_avModules; - typedef std::hash_map< rtl::OUString,berkeleydbproxy::Db*,ha,eq > DatabasesTable; + typedef std::hash_map< rtl::OUString,helpdatafileproxy::Hdf*,ha,eq > DatabasesTable; DatabasesTable m_aDatabases; // Language and module dependent databases typedef std::hash_map< rtl::OUString,rtl::OUString,ha,eq > LangSetTable; @@ -482,11 +482,11 @@ namespace chelp { , m_bHelpText( bHelpText ) {} - berkeleydbproxy::Db* nextDb( rtl::OUString* o_pExtensionPath = NULL, rtl::OUString* o_pExtensionRegistryPath = NULL ); + helpdatafileproxy::Hdf* nextHdf( rtl::OUString* o_pExtensionPath = NULL, rtl::OUString* o_pExtensionRegistryPath = NULL ); private: - berkeleydbproxy::Db* implGetDbFromPackage( + helpdatafileproxy::Hdf* implGetHdfFromPackage( com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage, rtl::OUString* o_pExtensionPath, rtl::OUString* o_pExtensionRegistryPath ); diff --git a/main/xmlhelp/source/cxxhelp/provider/db.cxx b/main/xmlhelp/source/cxxhelp/provider/db.cxx index 6b2c245..5f19f68 100755 --- a/main/xmlhelp/source/cxxhelp/provider/db.cxx +++ b/main/xmlhelp/source/cxxhelp/provider/db.cxx @@ -31,33 +31,13 @@ #include "com/sun/star/io/XSeekable.hpp" -#include "osl/file.hxx" -#include "osl/thread.hxx" -#ifdef TEST_DBHELP -#include -#endif - -using namespace com::sun::star; using namespace com::sun::star::uno; using namespace com::sun::star::io; -namespace berkeleydbproxy { +namespace helpdatafileproxy { //---------------------------------------------------------------------------- -namespace db_internal -{ - // static void raise_error(int dberr, const char * where); - - static inline int check_error(int dberr, const char * where) - { - (void)where; - - // if (dberr) raise_error(dberr,where); - return dberr; - } -} - -void DBData::copyToBuffer( const char* pSrcData, int nSize ) +void HDFData::copyToBuffer( const char* pSrcData, int nSize ) { m_nSize = nSize; delete [] m_pBuffer; @@ -67,9 +47,9 @@ void DBData::copyToBuffer( const char* pSrcData, int nSize ) } -// DBHelp +// Hdf -bool DBHelp::implReadLenAndData( const char* pData, int& riPos, DBData& rValue ) +bool Hdf::implReadLenAndData( const char* pData, int& riPos, HDFData& rValue ) { bool bSuccess = false; @@ -89,209 +69,7 @@ bool DBHelp::implReadLenAndData( const char* pData, int& riPos, DBData& rValue ) return bSuccess; } -#ifdef TEST_DBHELP - -typedef std::pair< rtl::OString, rtl::OString > KeyValPair; -typedef std::vector< KeyValPair > KeyValPairVector; - -void testWriteKeyValue( FILE* pFile, const KeyValPair& rKeyValPair ) -{ - if( pFile == NULL ) - return; - char cLF = 10; - - const rtl::OString& aKeyStr = rKeyValPair.first; - const rtl::OString& aValueStr = rKeyValPair.second; - int nKeyLen = aKeyStr.getLength(); - int nValueLen = aValueStr.getLength(); - fprintf( pFile, "%x ", nKeyLen ); - if( nKeyLen > 0 ) - fwrite( aKeyStr.getStr(), 1, nKeyLen, pFile ); - fprintf( pFile, " %x ", nValueLen ); - if( nValueLen > 0 ) - fwrite( aValueStr.getStr(), 1, nValueLen, pFile ); - fprintf( pFile, "%c", cLF ); -} - -bool DBHelp::testAgainstDb( const rtl::OUString& fileURL, bool bOldDbAccess ) -{ - bool bSuccess = true; - - KeyValPairVector avKeyValPair; - - rtl::OUString aOutFileName = fileURL; - aOutFileName += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_TestOut")); - if( bOldDbAccess ) - aOutFileName += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_Old")); -#ifdef WNT - FILE* pFile = _wfopen( aOutFileName.getStr(), L"wb" ); -#else - rtl::OString sFile = rtl::OUStringToOString(aOutFileName, osl_getThreadTextEncoding()); - FILE* pFile = fopen( sFile.getStr(), "wb" ); -#endif - // Get all values - Db table; - if( 0 == table.open( 0,fileURL,DB_BTREE,DB_RDONLY,0644 ) ) - { - bool first = true; - - Dbc* cursor = 0; - table.cursor( 0,&cursor,0 ); - Dbt key_,data; - key_.set_flags( DB_DBT_MALLOC ); // Initially the cursor must allocate the necessary memory - data.set_flags( DB_DBT_MALLOC ); - - while( cursor && DB_NOTFOUND != cursor->get( &key_,&data,DB_NEXT ) ) - { - rtl::OString keyword( static_cast(key_.get_data()), - key_.get_size() ); - rtl::OString value( static_cast(data.get_data()), - data.get_size() ); - - KeyValPair aPair( keyword, value ); - avKeyValPair.push_back( aPair ); - if( pFile != NULL ) - testWriteKeyValue( pFile, aPair ); - - if( first ) - { - key_.set_flags( DB_DBT_REALLOC ); - data.set_flags( DB_DBT_REALLOC ); - first = false; - } - } - - if( cursor ) cursor->close(); - } - table.close( 0 ); - - // TEST - DBData aDBData; - Db tableTest; - Dbt data; - - int nOkCount = 0; - int nErrCount = 0; - - bool bTestSuccess; - const char* pTestReadData = NULL; - int nTestReadDataSize = 0; - - sal_uInt32 starttime = osl_getGlobalTimer(); - sal_uInt32 afterfirsttime = starttime; - - if( pFile != NULL ) - { - if( bOldDbAccess ) - fprintf( pFile, "\nTesting old access:\n" ); - else - fprintf( pFile, "\nTesting new access:\n" ); - } - - KeyValPairVector::const_iterator it; - bool bFirst = true; - for( it = avKeyValPair.begin() ; it != avKeyValPair.end() ; ++it ) - { - const KeyValPair& rKeyValPair = *it; - - const rtl::OString& aKeyStr = rKeyValPair.first; - const rtl::OString& aValueStr = rKeyValPair.second; - int nKeyLen = aKeyStr.getLength(); - int nValueLen = aValueStr.getLength(); - - const sal_Char* ptr = aValueStr.getStr(); - - bTestSuccess = false; - pTestReadData = NULL; - nTestReadDataSize = 0; - if( bOldDbAccess ) - { - if( bFirst ) - { - if( tableTest.open( 0,fileURL, DB_BTREE,DB_RDONLY,0644 ) ) - { - if( pFile != NULL ) - fprintf( pFile, "Cannot open database\n" ); - - break; - } - } - - Dbt key( static_cast< void* >( const_cast< sal_Char* >( aKeyStr.getStr() ) ), aKeyStr.getLength() ); - int err = tableTest.get( 0, &key, &data, 0 ); - if( err == 0 ) - { - bTestSuccess = true; - pTestReadData = static_cast< sal_Char* >( data.get_data() ); - nTestReadDataSize = data.get_size(); - } - } - else - { - bTestSuccess = getValueForKey( aKeyStr, aDBData ); - if( bTestSuccess ) - { - pTestReadData = aDBData.getData(); - nTestReadDataSize = aDBData.getSize(); - } - } - if( bFirst ) - { - afterfirsttime = osl_getGlobalTimer(); - bFirst = false; - } - int nError = 0; - if( bTestSuccess && pTestReadData != NULL ) - { - int nCmp = memcmp( ptr, pTestReadData, nValueLen ); - if( nCmp == 0 ) - ++nOkCount; - else - nError = 1; - - if( nValueLen != nTestReadDataSize ) - nError = 2; - } - else - nError = 3; - - if( nError != 0 ) - { - bSuccess = false; - ++nErrCount; - - if( pFile != NULL ) - { - fprintf( pFile, "ERROR, not found:\n" ); - testWriteKeyValue( pFile, rKeyValPair ); - fprintf( pFile, "\nError Code: %d\n", nError ); - } - } - } - tableTest.close( 0 ); - - sal_uInt32 endtime = osl_getGlobalTimer(); - double dDiffTime = (endtime-starttime) / 1000.0; - double dDiffFirstTime = (afterfirsttime-starttime) / 1000.0; - if( pFile != NULL ) - { - int nCount = avKeyValPair.size(); - fprintf( pFile, "%d key/values in total, read %d correctly, %d errors\n", - nCount, nOkCount, nErrCount ); - fprintf( pFile, "Time taken: %g s (First access %g s)\n", dDiffTime, dDiffFirstTime ); - fprintf( pFile, "Average time per access: %g s\n", dDiffTime / nCount ); - } - - if( pFile != NULL ) - fclose( pFile ); - - return bSuccess; -} - -#endif - - -void DBHelp::createHashMap( bool bOptimizeForPerformance ) +void Hdf::createHashMap( bool bOptimizeForPerformance ) { releaseHashMap(); if( bOptimizeForPerformance ) @@ -318,7 +96,7 @@ void DBHelp::createHashMap( bool bOptimizeForPerformance ) int iPos = 0; while( iPos < nRead ) { - DBData aDBKey; + HDFData aDBKey; if( !implReadLenAndData( pData, iPos, aDBKey ) ) break; @@ -351,7 +129,7 @@ void DBHelp::createHashMap( bool bOptimizeForPerformance ) } } -void DBHelp::releaseHashMap( void ) +void Hdf::releaseHashMap( void ) { if( m_pStringToDataMap != NULL ) { @@ -366,7 +144,7 @@ void DBHelp::releaseHashMap( void ) } -bool DBHelp::getValueForKey( const rtl::OString& rKey, DBData& rValue ) +bool Hdf::getValueForKey( const rtl::OString& rKey, HDFData& rValue ) { bool bSuccess = false; if( !m_xSFA.is() ) @@ -434,7 +212,7 @@ bool DBHelp::getValueForKey( const rtl::OString& rKey, DBData& rValue ) return bSuccess; } -bool DBHelp::startIteration( void ) +bool Hdf::startIteration( void ) { bool bSuccess = false; @@ -459,7 +237,7 @@ bool DBHelp::startIteration( void ) return bSuccess; } -bool DBHelp::getNextKeyAndValue( DBData& rKey, DBData& rValue ) +bool Hdf::getNextKeyAndValue( HDFData& rKey, HDFData& rValue ) { bool bSuccess = false; @@ -475,205 +253,11 @@ bool DBHelp::getNextKeyAndValue( DBData& rKey, DBData& rValue ) return bSuccess; } -void DBHelp::stopIteration( void ) +void Hdf::stopIteration( void ) { m_aItData = Sequence(); m_pItData = NULL; m_nItRead = -1; m_iItPos = -1; } - - -Db::Db() -{ - db_internal::check_error( db_create(&m_pDBP,0,0),"Db::Db" ); - m_pDBHelp = NULL; -} - - -Db::~Db() -{ - if (m_pDBP) - { - // should not happen - // TODO: add assert - } - - delete m_pDBHelp; -} - - -int Db::close(u_int32_t flags) -{ - int error = m_pDBP->close(m_pDBP,flags); - m_pDBP = 0; - return db_internal::check_error(error,"Db::close"); -} - -int Db::open(DB_TXN *txnid, - const char *file, - const char *database, - DBTYPE type, - u_int32_t flags, - int mode) -{ - int err = m_pDBP->open(m_pDBP,txnid,file,database,type,flags,mode); - return db_internal::check_error( err,"Db::open" ); -} - -int Db::open(DB_TXN *txnid, - ::rtl::OUString const & fileURL, - DBTYPE type, - u_int32_t flags, - int mode) -{ - ::rtl::OUString ouPath; - ::osl::FileBase::getSystemPathFromFileURL(fileURL, ouPath); - const ::rtl::OString sPath = ::rtl::OUStringToOString(ouPath, osl_getThreadTextEncoding()); - return open(txnid, sPath.getStr(), 0, type, flags, mode); -} - - - -int Db::get(DB_TXN *txnid, Dbt *key, Dbt *data, u_int32_t flags) -{ - int err = m_pDBP->get(m_pDBP,txnid,key,data,flags); - - // these are non-exceptional outcomes - if (err != DB_NOTFOUND && err != DB_KEYEMPTY) - db_internal::check_error( err,"Db::get" ); - - return err; -} - -int Db::cursor(DB_TXN *txnid, Dbc **cursorp, u_int32_t flags) -{ - DBC * dbc = 0; - int error = m_pDBP->cursor(m_pDBP,txnid,&dbc,flags); - - if (!db_internal::check_error(error,"Db::cursor")) - *cursorp = new Dbc(dbc); - - return error; -} - -//---------------------------------------------------------------------------- - -Dbc::Dbc(DBC * dbc) -: m_pDBC(dbc) -{ -} - -Dbc::~Dbc() -{ -} - -int Dbc::close() -{ - int err = m_pDBC->c_close(m_pDBC); - delete this; - return db_internal::check_error( err,"Dbcursor::close" ); -} - -int Dbc::get(Dbt *key, Dbt *data, u_int32_t flags) -{ - int err = m_pDBC->c_get(m_pDBC,key,data,flags); - - // these are non-exceptional outcomes - if (err != DB_NOTFOUND && err != DB_KEYEMPTY) - db_internal::check_error( err, "Dbcursor::get" ); - - return err; -} - -//---------------------------------------------------------------------------- - - -Dbt::Dbt() -{ - using namespace std; - DBT * thispod = this; - memset(thispod, 0, sizeof *thispod); -} - - -Dbt::Dbt(void *data_arg, u_int32_t size_arg) -{ - using namespace std; - DBT * thispod = this; - memset(thispod, 0, sizeof *thispod); - this->set_data(data_arg); - this->set_size(size_arg); -} - -/* -Dbt::Dbt(const Dbt & other) -{ - using namespace std; - const DBT *otherpod = &other; - DBT *thispod = this; - memcpy(thispod, otherpod, sizeof *thispod); -} - -Dbt& Dbt::operator = (const Dbt & other) -{ - if (this != &other) - { - using namespace std; - const DBT *otherpod = &other; - DBT *thispod = this; - memcpy(thispod, otherpod, sizeof *thispod); - } - return *this; -} -*/ - -Dbt::~Dbt() -{ -} - -void * Dbt::get_data() const -{ - return this->data; -} - -void Dbt::set_data(void *value) -{ - this->data = value; -} - -u_int32_t Dbt::get_size() const -{ - return this->size; -} - -void Dbt::set_size(u_int32_t value) -{ - this->size = value; -} - -void Dbt::set_flags(u_int32_t value) -{ - this->flags = value; -} - -//---------------------------------------------------------------------------- -/* -void db_internal::raise_error(int dberr, const char * where) -{ - if (!where) where = ""; - - const char * dberrmsg = db_strerror(dberr); - if (!dberrmsg || !*dberrmsg) dberrmsg = ""; - - rtl::OString msg = where; - msg += ": "; - msg += dberrmsg; - - throw DbException(msg); -} -*/ - -//---------------------------------------------------------------------------- -} // namespace ecomp - +} // end of namespace helpdatafileproxy diff --git a/main/xmlhelp/source/cxxhelp/provider/db.hxx b/main/xmlhelp/source/cxxhelp/provider/db.hxx index 75f698d..80f42fc 100755 --- a/main/xmlhelp/source/cxxhelp/provider/db.hxx +++ b/main/xmlhelp/source/cxxhelp/provider/db.hxx @@ -20,33 +20,17 @@ *************************************************************/ -#ifndef BERKELEYDBPROXY_DB_HXX_ -#define BERKELEYDBPROXY_DB_HXX_ - -#ifdef SYSTEM_DB -#include -#else -#include -#endif +#ifndef HELPDATAFILEPROXY_DB_HXX_ +#define HELPDATAFILEPROXY_DB_HXX_ #include "com/sun/star/ucb/XSimpleFileAccess.hpp" #include #include -extern "C" { - typedef void *(*db_malloc_fcn_type)(size_t); - typedef void *(*db_realloc_fcn_type)(void *, size_t); - typedef void (*db_free_fcn_type)(void *); -} - +namespace helpdatafileproxy { -namespace berkeleydbproxy { - - class Dbc; - class Dbt; - - namespace db_internal + namespace hdf_internal { class Noncopyable { @@ -58,37 +42,10 @@ namespace berkeleydbproxy { ~Noncopyable() {} }; } - - class DbException - { - rtl::OString what_; - public: - explicit DbException(rtl::OString const & whatparam) - : what_(whatparam) - {} - - const char *what() const - { return what_.getStr(); } - }; - - struct eq - { - bool operator()( const rtl::OString& rKey1, const rtl::OString& rKey2 ) const - { return rKey1.compareTo( rKey2 ) == 0; } - }; - struct ha + class HDFData { - size_t operator()( const rtl::OString& rName ) const - { return rName.hashCode(); } - }; - - -//#define TEST_DBHELP - - class DBData - { - friend class DBHelp; + friend class Hdf; int m_nSize; char* m_pBuffer; @@ -96,11 +53,11 @@ namespace berkeleydbproxy { void copyToBuffer( const char* pSrcData, int nSize ); public: - DBData( void ) + HDFData( void ) : m_nSize( 0 ) , m_pBuffer( NULL ) {} - ~DBData() + ~HDFData() { delete [] m_pBuffer; } int getSize() const @@ -109,10 +66,22 @@ namespace berkeleydbproxy { { return m_pBuffer; } }; + struct eq + { + bool operator()( const rtl::OString& rKey1, const rtl::OString& rKey2 ) const + { return rKey1.compareTo( rKey2 ) == 0; } + }; + + struct ha + { + size_t operator()( const rtl::OString& rName ) const + { return rName.hashCode(); } + }; + typedef std::hash_map< rtl::OString,std::pair,ha,eq > StringToValPosMap; typedef std::hash_map< rtl::OString,rtl::OString,ha,eq > StringToDataMap; - class DBHelp + class Hdf : hdf_internal::Noncopyable { rtl::OUString m_aFileURL; StringToDataMap* m_pStringToDataMap; @@ -126,13 +95,13 @@ namespace berkeleydbproxy { int m_nItRead; int m_iItPos; - bool implReadLenAndData( const char* pData, int& riPos, DBData& rValue ); + bool implReadLenAndData( const char* pData, int& riPos, HDFData& rValue ); public: - //DBHelp must get a fileURL which can then directly be used by simple file access. + //HDFHelp must get a fileURL which can then directly be used by simple file access. //SimpleFileAccess requires file URLs as arguments. Passing file path may work but fails //for example when using long file paths on Windows, which start with "\\?\" - DBHelp( const rtl::OUString& rFileURL, + Hdf( const rtl::OUString& rFileURL, com::sun::star::uno::Reference< com::sun::star::ucb::XSimpleFileAccess > xSFA ) : m_aFileURL( rFileURL ) , m_pStringToDataMap( NULL ) @@ -144,114 +113,19 @@ namespace berkeleydbproxy { { OSL_ASSERT(!rFileURL.compareTo(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:")), 5)); } - ~DBHelp() + ~Hdf() { releaseHashMap(); } void createHashMap( bool bOptimizeForPerformance = false ); void releaseHashMap( void ); -#ifdef TEST_DBHELP - bool testAgainstDb( const rtl::OUString& fileURL, bool bOldDbAccess ); -#endif - - bool getValueForKey( const rtl::OString& rKey, DBData& rValue ); + bool getValueForKey( const rtl::OString& rKey, HDFData& rValue ); bool startIteration( void ); - bool getNextKeyAndValue( DBData& rKey, DBData& rValue ); + bool getNextKeyAndValue( HDFData& rKey, HDFData& rValue ); void stopIteration( void ); }; - - class Db : db_internal::Noncopyable - { - private: - DB* m_pDBP; - DBHelp* m_pDBHelp; - - public: - Db(); - ~Db(); - - void setDBHelp( DBHelp* pDBHelp ) - { m_pDBHelp = pDBHelp; } - DBHelp* getDBHelp( void ) - { return m_pDBHelp; } - - int close(u_int32_t flags); - - int open(DB_TXN *txnid, - const char *file, - const char *database, - DBTYPE type, - u_int32_t flags, - int mode); - - int open(DB_TXN *txnid, - ::rtl::OUString const & fileURL, - DBTYPE type, - u_int32_t flags, - int mode); - - - int get(DB_TXN* txnid, Dbt *key, Dbt *data, u_int32_t flags); - - int cursor(DB_TXN *txnid, Dbc **cursorp, u_int32_t flags); - }; - - class Dbc : db_internal::Noncopyable - { - friend class Db; - friend class Dbt; - - private: - DBC* m_pDBC; - - explicit Dbc(DBC* pDBC); - ~Dbc(); - - public: - int close(); - - int get(Dbt *key, Dbt *data, u_int32_t flags); - }; - - class Dbt: private DBT - { - friend class Db; - friend class Dbc; - - public: - Dbt(void *data_arg, u_int32_t size_arg); - - Dbt(); - //Dbt(const Dbt & other); - //Dbt & operator=(const Dbt & other); - - ~Dbt(); - - void *get_data() const; - void set_data(void *value); - - u_int32_t get_size() const; - void set_size(u_int32_t value); - - void set_flags(u_int32_t); - }; } #endif - - - - - - - - - - - - - - - diff --git a/main/xmlhelp/source/cxxhelp/provider/makefile.mk b/main/xmlhelp/source/cxxhelp/provider/makefile.mk index e7e5dae..7c3a8fe 100644 --- a/main/xmlhelp/source/cxxhelp/provider/makefile.mk +++ b/main/xmlhelp/source/cxxhelp/provider/makefile.mk @@ -52,10 +52,6 @@ CFLAGSWERRCXX:= CFLAGS += -DHAVE_EXPAT_H -.IF "$(SYSTEM_DB)" == "YES" -CFLAGS+=-DSYSTEM_DB -I$(DB_INCLUDES) -.ENDIF - .IF "$(SYSTEM_LIBXML)" == "YES" CFLAGS+= $(LIBXML_CFLAGS) .ELSE @@ -77,18 +73,18 @@ CFLAGS+=-GR # --- General ----------------------------------------------------- SLOFILES=\ + $(SLO)$/db.obj \ + $(SLO)$/databases.obj \ $(SLO)$/services.obj \ - $(SLO)$/provider.obj \ - $(SLO)$/content.obj \ $(SLO)$/resultset.obj \ $(SLO)$/resultsetbase.obj \ $(SLO)$/resultsetforroot.obj \ $(SLO)$/resultsetforquery.obj \ $(SLO)$/contentcaps.obj \ + $(SLO)$/provider.obj \ + $(SLO)$/content.obj \ $(SLO)$/urlparameter.obj \ $(SLO)$/inputstream.obj \ - $(SLO)$/databases.obj \ - $(SLO)$/db.obj \ $(SLO)$/bufferedinputstream.obj # --- Targets ---------------------------------------------------------- diff --git a/main/xmlhelp/source/cxxhelp/provider/urlparameter.cxx b/main/xmlhelp/source/cxxhelp/provider/urlparameter.cxx index d848981..8f8ee4d 100644 --- a/main/xmlhelp/source/cxxhelp/provider/urlparameter.cxx +++ b/main/xmlhelp/source/cxxhelp/provider/urlparameter.cxx @@ -89,7 +89,6 @@ using namespace com::sun::star::lang; using namespace com::sun::star::ucb; using namespace com::sun::star::beans; using namespace com::sun::star::container; -using namespace berkeleydbproxy; using namespace chelp; @@ -215,7 +214,7 @@ void URLParameter::init( bool bDefaultLanguageIsInitialized ) { (void)bDefaultLanguageIsInitialized; - m_bBerkeleyRead = false; + m_bHelpDataFileRead = false; m_bStart = false; m_bUseDB = true; m_nHitCount = 100; // The default maximum hitcount @@ -225,10 +224,10 @@ void URLParameter::init( bool bDefaultLanguageIsInitialized ) rtl::OUString URLParameter::get_the_tag() { if(m_bUseDB) { - if( ! m_bBerkeleyRead ) - readBerkeley(); + if( ! m_bHelpDataFileRead ) + readHelpDataFile(); - m_bBerkeleyRead = true; + m_bHelpDataFileRead = true; return m_aTag; } @@ -241,9 +240,9 @@ rtl::OUString URLParameter::get_the_tag() rtl::OUString URLParameter::get_the_path() { if(m_bUseDB) { - if( ! m_bBerkeleyRead ) - readBerkeley(); - m_bBerkeleyRead = true; + if( ! m_bHelpDataFileRead ) + readHelpDataFile(); + m_bHelpDataFileRead = true; return m_aPath; } @@ -256,9 +255,9 @@ rtl::OUString URLParameter::get_the_path() rtl::OUString URLParameter::get_the_title() { if(m_bUseDB) { - if( ! m_bBerkeleyRead ) - readBerkeley(); - m_bBerkeleyRead = true; + if( ! m_bHelpDataFileRead ) + readHelpDataFile(); + m_bHelpDataFileRead = true; return m_aTitle; } @@ -270,9 +269,9 @@ rtl::OUString URLParameter::get_the_title() rtl::OUString URLParameter::get_the_jar() { if(m_bUseDB) { - if( ! m_bBerkeleyRead ) - readBerkeley(); - m_bBerkeleyRead = true; + if( ! m_bHelpDataFileRead ) + readHelpDataFile(); + m_bHelpDataFileRead = true; return m_aJar; } @@ -283,7 +282,7 @@ rtl::OUString URLParameter::get_the_jar() -void URLParameter::readBerkeley() +void URLParameter::readHelpDataFile() { static rtl::OUString aQuestionMark( rtl::OUString::createFromAscii( "?" ) ); @@ -299,41 +298,23 @@ void URLParameter::readBerkeley() int nSize = 0; const sal_Char* pData = NULL; - Dbt data; - DBData aDBData; + helpdatafileproxy::HDFData aHDFData; rtl::OUString aExtensionPath; rtl::OUString aExtensionRegistryPath; while( true ) { - Db* db = aDbIt.nextDb( &aExtensionPath, &aExtensionRegistryPath ); - if( !db ) + helpdatafileproxy::Hdf* pHdf = aDbIt.nextHdf( &aExtensionPath, &aExtensionRegistryPath ); + if( !pHdf ) break; rtl::OString keyStr( m_aId.getStr(),m_aId.getLength(),RTL_TEXTENCODING_UTF8 ); - DBHelp* pDBHelp = db->getDBHelp(); - if( pDBHelp != NULL ) + bSuccess = pHdf->getValueForKey( keyStr, aHDFData ); + if( bSuccess ) { - bSuccess = pDBHelp->getValueForKey( keyStr, aDBData ); - if( bSuccess ) - { - nSize = aDBData.getSize(); - pData = aDBData.getData(); - break; - } - } - else - { - Dbt key( static_cast< void* >( const_cast< sal_Char* >( keyStr.getStr() ) ), - keyStr.getLength() ); - int err = db->get( 0,&key,&data,0 ); - if( err == 0 ) - { - bSuccess = true; - nSize = data.get_size(); - pData = static_cast( data.get_data() ); - break; - } + nSize = aHDFData.getSize(); + pData = aHDFData.getData(); + break; } } diff --git a/main/xmlhelp/source/cxxhelp/provider/urlparameter.hxx b/main/xmlhelp/source/cxxhelp/provider/urlparameter.hxx index c86c28b..15fc8ef 100644 --- a/main/xmlhelp/source/cxxhelp/provider/urlparameter.hxx +++ b/main/xmlhelp/source/cxxhelp/provider/urlparameter.hxx @@ -144,7 +144,7 @@ namespace chelp { rtl::OUString get_title(); - rtl::OUString get_jar() { return get_the_jar(); } // BerkeleyDb + rtl::OUString get_jar() { return get_the_jar(); } rtl::OUString get_ExtensionRegistryPath() { return m_aExtensionRegistryPath; } @@ -189,7 +189,7 @@ namespace chelp { Databases* m_pDatabases; - bool m_bBerkeleyRead; + bool m_bHelpDataFileRead; bool m_bStart; bool m_bUseDB; @@ -234,7 +234,7 @@ namespace chelp { rtl::OUString get_the_jar(); - void readBerkeley(); + void readHelpDataFile(); void parse() throw( com::sun::star::ucb::IllegalIdentifierException ); diff --git a/main/xmlhelp/util/makefile.mk b/main/xmlhelp/util/makefile.mk index 464e90d..5ccab30 100644 --- a/main/xmlhelp/util/makefile.mk +++ b/main/xmlhelp/util/makefile.mk @@ -60,7 +60,6 @@ SHL1STDLIBS= \ $(SALLIB) \ $(EXPATASCII3RDLIB) \ $(UCBHELPERLIB) \ - $(BERKELEYLIB) \ $(XSLTLIB) SHL1LIBS = \ diff --git a/main/xmlhelp/util/ucpchelp.xml b/main/xmlhelp/util/ucpchelp.xml index 0eb2d9c..f2a7ff0 100644 --- a/main/xmlhelp/util/ucpchelp.xml +++ b/main/xmlhelp/util/ucpchelp.xml @@ -42,7 +42,6 @@ external XmlSearch ucbhelper - berkeleydb sal3 cppu3