diff options
270 files changed, 10180 insertions, 5985 deletions
diff --git a/avmedia/source/gstreamer/gstframegrabber.cxx b/avmedia/source/gstreamer/gstframegrabber.cxx index bd55e11f8afe..49a6d9695fbc 100644 --- a/avmedia/source/gstreamer/gstframegrabber.cxx +++ b/avmedia/source/gstreamer/gstframegrabber.cxx @@ -31,6 +31,9 @@ #include <vcl/graph.hxx> #include <vcl/bmpacc.hxx> +#include <string> + + using namespace ::com::sun::star; namespace avmedia { namespace gst { diff --git a/avmedia/source/gstreamer/gstplayer.cxx b/avmedia/source/gstreamer/gstplayer.cxx index f082cfc5c513..614ff80ce352 100644 --- a/avmedia/source/gstreamer/gstplayer.cxx +++ b/avmedia/source/gstreamer/gstplayer.cxx @@ -66,6 +66,92 @@ struct GstBusSource : public GSource {} }; + +// ----------------------------------------------------------------------- +extern "C" +{ + +static gpointer +lcl_implThreadFunc( gpointer pData ) +{ + return( pData ? static_cast< Player* >( pData )->run() : NULL ); +} + +static gboolean +lcl_implBusCheck( GSource* pSource ) +{ + GstBusSource* pBusSource = static_cast< GstBusSource* >( pSource ); + + return( pBusSource && + GST_IS_BUS( pBusSource->mpBus ) && + gst_bus_have_pending( GST_BUS_CAST( pBusSource->mpBus ) ) ); +} + + +static gboolean +lcl_implBusPrepare( GSource* pSource, gint* pTimeout ) +{ + if (pTimeout) + { + *pTimeout = 0; + } + + return lcl_implBusCheck(pSource); +} + +static gboolean +lcl_implBusDispatch( GSource* pSource, + GSourceFunc /*aCallback*/, + gpointer pData ) +{ + GstBusSource* pBusSource = static_cast< GstBusSource* >( pSource ); + gboolean bRet = false; + + if( pData && pBusSource && GST_IS_BUS( pBusSource->mpBus ) ) + { + GstMessage* pMsg = gst_bus_pop( pBusSource->mpBus ); + + if( pMsg ) + { + bRet = static_cast< Player* >( pData )->busCallback( + pBusSource->mpBus, pMsg ); + gst_message_unref( pMsg ); + } + } + + return( bRet ); +} + +static void +lcl_implBusFinalize( GSource* pSource ) +{ + GstBusSource* pBusSource = static_cast< GstBusSource* >( pSource ); + + if( pBusSource && pBusSource->mpBus ) + { + gst_object_unref( pBusSource->mpBus ); + pBusSource->mpBus = NULL; + } +} + +static gboolean +lcl_implIdleFunc( gpointer pData ) +{ + return( pData ? static_cast< Player* >( pData )->idle() : true ); +} + +static GstBusSyncReply +lcl_implHandleCreateWindowFunc( GstBus* pBus, GstMessage* pMsg, gpointer pData ) +{ + return (pData) + ? static_cast< Player* >( pData )->handleCreateWindow( pBus, pMsg ) + : GST_BUS_PASS; +} + +} // extern "C" + + + // --------------- // - Player - // --------------- @@ -102,7 +188,7 @@ Player::Player( GString* pURI ) : OSL_TRACE( ">>> --------------------------------" ); OSL_TRACE( ">>> Creating Player object with URL: %s", pURI->str ); - mpThread = g_thread_create( Player::implThreadFunc, this, true, NULL ); + mpThread = g_thread_create( &lcl_implThreadFunc, this, true, NULL ); } } @@ -329,10 +415,14 @@ double SAL_CALL Player::getRate() void SAL_CALL Player::setPlaybackLoop( sal_Bool bSet ) throw( uno::RuntimeException ) { - if( bSet && !isPlaybackLoop() ) - g_atomic_int_inc( &mnLooping ); - else if( !bSet && isPlaybackLoop() ) - g_atomic_int_dec_and_test( &mnLooping ); + if (bSet) + { + g_atomic_int_compare_and_exchange(&mnLooping, 0, 1); + } + else + { + g_atomic_int_compare_and_exchange(&mnLooping, 1, 0); + } } // ------------------------------------------------------------------------------ @@ -573,62 +663,6 @@ bool Player::implInitPlayer() } // ------------------------------------------------------------------------------ -gboolean Player::implBusPrepare( GSource* pSource, - gint* pTimeout ) -{ - if( pTimeout ) - { - *pTimeout = 0; - } - - return( implBusCheck( pSource ) ); -} - -// ------------------------------------------------------------------------------ -gboolean Player::implBusCheck( GSource* pSource ) -{ - GstBusSource* pBusSource = static_cast< GstBusSource* >( pSource ); - - return( pBusSource && - GST_IS_BUS( pBusSource->mpBus ) && - gst_bus_have_pending( GST_BUS_CAST( pBusSource->mpBus ) ) ); -} - -// ------------------------------------------------------------------------------ -gboolean Player::implBusDispatch( GSource* pSource, - GSourceFunc /*aCallback*/, - gpointer pData ) -{ - GstBusSource* pBusSource = static_cast< GstBusSource* >( pSource ); - gboolean bRet = false; - - if( pData && pBusSource && GST_IS_BUS( pBusSource->mpBus ) ) - { - GstMessage* pMsg = gst_bus_pop( pBusSource->mpBus ); - - if( pMsg ) - { - bRet = static_cast< Player* >( pData )->busCallback( pBusSource->mpBus, pMsg ); - gst_message_unref( pMsg ); - } - } - - return( bRet ); -} - -// ------------------------------------------------------------------------------ -void Player::implBusFinalize( GSource* pSource ) -{ - GstBusSource* pBusSource = static_cast< GstBusSource* >( pSource ); - - if( pBusSource && pBusSource->mpBus ) - { - gst_object_unref( pBusSource->mpBus ); - pBusSource->mpBus = NULL; - } -} - -// ------------------------------------------------------------------------------ gboolean Player::busCallback( GstBus* /*pBus*/, GstMessage* pMsg ) { @@ -674,26 +708,6 @@ gboolean Player::busCallback( GstBus* /*pBus*/, } // ------------------------------------------------------------------------------ -gboolean Player::implIdleFunc( gpointer pData ) -{ - return( pData ? static_cast< Player* >( pData )->idle() : true ); -} - -// ------------------------------------------------------------------------------ -gpointer Player::implThreadFunc( gpointer pData ) -{ - return( pData ? static_cast< Player* >( pData )->run() : NULL ); -} - -// ------------------------------------------------------------------------------ -GstBusSyncReply Player::implHandleCreateWindowFunc( GstBus* pBus, - GstMessage* pMsg, - gpointer pData ) -{ - return( pData ? static_cast< Player* >( pData )->handleCreateWindow( pBus, pMsg ) : GST_BUS_PASS ); -} - -// ------------------------------------------------------------------------------ void Player::implHandleNewElementFunc( GstBin* /* pBin */, GstElement* pElement, gpointer pData ) @@ -800,16 +814,12 @@ void Player::implHandleNewPadFunc( GstElement* pElement, // ------------------------------------------------------------------------------ gboolean Player::idle() { - // test if main loop should quit and set flag mnQuit to 1 - bool bQuit = g_atomic_int_compare_and_exchange( &mnQuit, 1, 1 ); + // test if main loop should quit by comparing with 1 + // and set flag mnQuit to 0 so we call g_main_loop_quit exactly once + bool const bQuit = g_atomic_int_compare_and_exchange( &mnQuit, 1, 0 ); if( bQuit ) { - // set mnQuit back to 0 to avoid mutiple g_main_loop_quit calls - // in case Player::idle() is called again later; - // the flag should have been set only once within Ctor called from - // the application thread - g_atomic_int_dec_and_test( &mnQuit ); g_main_loop_quit( mpLoop ); } @@ -824,10 +834,10 @@ gpointer Player::run() { static GSourceFuncs aSourceFuncs = { - Player::implBusPrepare, - Player::implBusCheck, - Player::implBusDispatch, - Player::implBusFinalize, + &lcl_implBusPrepare, + &lcl_implBusCheck, + &lcl_implBusDispatch, + &lcl_implBusFinalize, NULL, NULL }; @@ -842,7 +852,7 @@ gpointer Player::run() // add idle callback GSource* pIdleSource = g_idle_source_new(); - g_source_set_callback( pIdleSource, Player::implIdleFunc, this, NULL ); + g_source_set_callback( pIdleSource, &lcl_implIdleFunc, this, NULL ); g_source_attach( pIdleSource, mpContext ); // add bus callback @@ -853,7 +863,7 @@ gpointer Player::run() // add bus sync handler to intercept video window creation for setting our own window gst_bus_set_sync_handler( static_cast< GstBusSource* >( pBusSource )->mpBus, - Player::implHandleCreateWindowFunc, this ); + &lcl_implHandleCreateWindowFunc, this ); // watch for all elements (and pads) that will be added to the playbin, // in order to retrieve properties like video width and height diff --git a/avmedia/source/gstreamer/gstplayer.hxx b/avmedia/source/gstreamer/gstplayer.hxx index d751e381258d..0793eaf8caf2 100644 --- a/avmedia/source/gstreamer/gstplayer.hxx +++ b/avmedia/source/gstreamer/gstplayer.hxx @@ -149,11 +149,7 @@ public: virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ); - -protected: - - Player( GString* pURI = NULL ); - +// these are public because the C callbacks call them virtual gboolean busCallback( GstBus* pBus, GstMessage* pMsg ); @@ -164,6 +160,10 @@ protected: virtual GstBusSyncReply handleCreateWindow( GstBus* pBus, GstMessage* pMsg ); +protected: + + Player( GString* pURI = NULL ); + void implQuitThread(); bool implInitPlayer(); @@ -180,25 +180,6 @@ private: Player& operator=( const Player& ); - static gboolean implBusPrepare( GSource* pSource, - gint* pTimeout ); - - static gboolean implBusCheck( GSource* pSource ); - - static gboolean implBusDispatch( GSource* pSource, - GSourceFunc aCallback, - gpointer pData ); - - static void implBusFinalize( GSource* pSource ); - - static gboolean implIdleFunc( gpointer pData ); - - static gpointer implThreadFunc( gpointer pData ); - - static GstBusSyncReply implHandleCreateWindowFunc( GstBus* pBus, - GstMessage* pMsg, - gpointer pDData ); - static void implHandleNewElementFunc( GstBin* pBin, GstElement* pElement, gpointer pData ); diff --git a/avmedia/source/gstreamer/makefile.mk b/avmedia/source/gstreamer/makefile.mk index c648fcc77f89..857c5914b094 100644 --- a/avmedia/source/gstreamer/makefile.mk +++ b/avmedia/source/gstreamer/makefile.mk @@ -62,6 +62,8 @@ SHL1STDLIBS+=$(PKGCONFIG_LIBS) SHL1IMPLIB=i$(TARGET) SHL1LIBS=$(SLB)$/$(TARGET).lib SHL1DEF=$(MISC)$/$(SHL1TARGET).def +# on Solaris checkdll does not work: LD_LIBRARY_PATH breaks the 2 libxml2.so.2 +SHL1NOCHECK=t DEF1NAME=$(SHL1TARGET) DEF1EXPORTFILE=exports.dxp diff --git a/basic/inc/basic/sbxdef.hxx b/basic/inc/basic/sbxdef.hxx index 6dc9fe1d8d66..cc669fd03649 100644 --- a/basic/inc/basic/sbxdef.hxx +++ b/basic/inc/basic/sbxdef.hxx @@ -108,6 +108,7 @@ enum SbxDataType { const sal_uInt32 SBX_TYPE_WITH_EVENTS_FLAG = 0x10000; const sal_uInt32 SBX_TYPE_DIM_AS_NEW_FLAG = 0x20000; const sal_uInt32 SBX_FIXED_LEN_STRING_FLAG = 0x10000; // same value as above as no conflict possible +const sal_uInt32 SBX_TYPE_VAR_TO_DIM_FLAG = 0x40000; #endif @@ -320,6 +321,8 @@ enum SbxError { // Ergebnis einer Rechenoperation/Konversion #define SBX_WITH_EVENTS 0x0080 // Same value as unused SBX_HIDDEN #define SBX_DIM_AS_NEW 0x0800 // Same value as SBX_GBLSEARCH, cannot conflict as one // is used for objects, the other for variables only +#define SBX_VAR_TO_DIM 0x2000 // Same value as SBX_NO_BROADCAST, cannot conflict as + // used for variables without broadcaster only // Broadcaster-IDs: #define SBX_HINT_DYING SFX_HINT_DYING diff --git a/basic/inc/basic/vbahelper.hxx b/basic/inc/basic/vbahelper.hxx index 0d99387965fe..f83548f7e02c 100755..100644 --- a/basic/inc/basic/vbahelper.hxx +++ b/basic/inc/basic/vbahelper.hxx @@ -28,7 +28,9 @@ #ifndef BASIC_VBAHELPR_HXX #define BASIC_VBAHELPR_HXX +#include <com/sun/star/container/XEnumeration.hpp> #include <com/sun/star/frame/XModel.hpp> +#include <rtl/ustring.hxx> namespace basic { namespace vba { @@ -39,6 +41,21 @@ namespace vba { // ============================================================================ +/** Creates and returns an enumeration of all open documents of the same type + as the specified document. + + First, the global module manager (com.sun.star.frame.ModuleManager) is + asked for the type of the passed model, and all open documents with the + same type will be stored in an enumeration object. + + @param rxModel + A document model determining the type of the documents. + */ +::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > createDocumentsEnumeration( + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rxModel ); + +// ============================================================================ + /** Locks or unlocks the controllers of all documents that have the same type as the specified document. @@ -80,6 +97,38 @@ void enableContainerWindowsOfAllDocuments( // ============================================================================ +/** Registers the passed path as working directory for the application the + passed document belongs to. + + @param rxModel + A document model determining the type of the application whose working + directory has been changed. + + @param rPath + The new working directory. + */ +void registerCurrentDirectory( + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rxModel, + const ::rtl::OUString& rPath ); + +// ============================================================================ + +/** Returns the working directory of the application the passed document + belongs to. + + @param rxModel + A document model determining the type of the application whose working + directory is querried. + + @return + The working directory of the specified application, or an empty string + on error (e.g. if the passed document reference is empty). + */ +::rtl::OUString getCurrentDirectory( + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rxModel ); + +// ============================================================================ + } // namespace vba } // namespace basic diff --git a/basic/source/basmgr/vbahelper.cxx b/basic/source/basmgr/vbahelper.cxx index a09446f2e40b..0e9338b52c5e 100755..100644 --- a/basic/source/basmgr/vbahelper.cxx +++ b/basic/source/basmgr/vbahelper.cxx @@ -28,13 +28,18 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_basic.hxx" -#include "basic/vbahelper.hxx" +#include <basic/vbahelper.hxx> + +#include <map> +#include <vector> #include <com/sun/star/container/XEnumeration.hpp> #include <com/sun/star/frame/XDesktop.hpp> #include <com/sun/star/frame/XModel2.hpp> #include <com/sun/star/frame/XModuleManager.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <comphelper/processfactory.hxx> +#include <cppuhelper/implbase1.hxx> +#include <rtl/instance.hxx> namespace basic { namespace vba { @@ -45,64 +50,71 @@ using namespace ::com::sun::star; namespace { -/** Creates the global module manager needed to identify the type of documents. +/** Create an instance of a module manager. */ uno::Reference< frame::XModuleManager > lclCreateModuleManager() { uno::Reference< frame::XModuleManager > xModuleManager; try { - uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW ); + uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); xModuleManager.set( xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ) ) ), uno::UNO_QUERY ); } catch( uno::Exception& ) { } - OSL_ENSURE( xModuleManager.is(), "::basic::vba::lclCreateModuleManager - cannot create module manager" ); return xModuleManager; } // ---------------------------------------------------------------------------- -/** Returns the document service name of the specified document. +/** Implementation of an enumeration of all open documents of the same type. */ -::rtl::OUString lclIdentifyDocument( const uno::Reference< frame::XModuleManager >& rxModuleManager, const uno::Reference< frame::XModel >& rxModel ) +class DocumentsEnumeration : public ::cppu::WeakImplHelper1< container::XEnumeration > { - ::rtl::OUString aServiceName; - if( rxModuleManager.is() ) - { - try - { - aServiceName = rxModuleManager->identify( rxModel ); - } - catch( uno::Exception& ) - { - } - OSL_ENSURE( aServiceName.getLength() > 0, "::basic::vba::lclIdentifyDocument - cannot identify document" ); - } - return aServiceName; -} - -// ---------------------------------------------------------------------------- +public: + DocumentsEnumeration( const uno::Reference< frame::XModel >& rxModel ); + virtual sal_Bool SAL_CALL hasMoreElements() throw (uno::RuntimeException); + virtual uno::Any SAL_CALL nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException); +private: + typedef ::std::vector< uno::Reference< frame::XModel > > ModelVector; + ModelVector maModels; + ModelVector::iterator maModelIt; +}; -/** Returns an enumeration of all open documents. - */ -uno::Reference< container::XEnumeration > lclCreateDocumentEnumeration() +DocumentsEnumeration::DocumentsEnumeration( const uno::Reference< frame::XModel >& rxModel ) { - uno::Reference< container::XEnumeration > xEnumeration; try { - uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW ); + uno::Reference< frame::XModuleManager > xModuleManager( lclCreateModuleManager(), uno::UNO_SET_THROW ); + ::rtl::OUString aIdentifier = xModuleManager->identify( rxModel ); + uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); uno::Reference< frame::XDesktop > xDesktop( xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ) ), uno::UNO_QUERY_THROW ); uno::Reference< container::XEnumerationAccess > xComponentsEA( xDesktop->getComponents(), uno::UNO_SET_THROW ); - xEnumeration = xComponentsEA->createEnumeration(); - + uno::Reference< container::XEnumeration > xEnumeration( xComponentsEA->createEnumeration(), uno::UNO_SET_THROW ); + while( xEnumeration->hasMoreElements() ) + { + uno::Reference< frame::XModel > xCurrModel( xEnumeration->nextElement(), uno::UNO_QUERY_THROW ); + if( xModuleManager->identify( xCurrModel ) == aIdentifier ) + maModels.push_back( xCurrModel ); + } } catch( uno::Exception& ) { } - OSL_ENSURE( xEnumeration.is(), "::basic::vba::lclCreateDocumentEnumeration - cannot create enumeration of all documents" ); - return xEnumeration; + maModelIt = maModels.begin(); +} + +sal_Bool SAL_CALL DocumentsEnumeration::hasMoreElements() throw (uno::RuntimeException) +{ + return maModelIt != maModels.end(); +} + +uno::Any SAL_CALL DocumentsEnumeration::nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) +{ + if( maModelIt == maModels.end() ) + throw container::NoSuchElementException(); + return uno::Any( *maModelIt++ ); } // ---------------------------------------------------------------------------- @@ -163,37 +175,39 @@ typedef void (*ModifyDocumentFunc)( const uno::Reference< frame::XModel >&, sal_ */ void lclIterateDocuments( ModifyDocumentFunc pModifyDocumentFunc, const uno::Reference< frame::XModel >& rxModel, sal_Bool bModificator ) { - uno::Reference< frame::XModuleManager > xModuleManager = lclCreateModuleManager(); - uno::Reference< container::XEnumeration > xDocumentsEnum = lclCreateDocumentEnumeration(); - ::rtl::OUString aIdentifier = lclIdentifyDocument( xModuleManager, rxModel ); - if( xModuleManager.is() && xDocumentsEnum.is() && (aIdentifier.getLength() > 0) ) + uno::Reference< container::XEnumeration > xDocumentsEnum( new DocumentsEnumeration( rxModel ) ); + // iterate over all open documents + while( xDocumentsEnum->hasMoreElements() ) try { - // iterate over all open documents - while( xDocumentsEnum->hasMoreElements() ) - { - try - { - uno::Reference< frame::XModel > xCurrModel( xDocumentsEnum->nextElement(), uno::UNO_QUERY_THROW ); - ::rtl::OUString aCurrIdentifier = lclIdentifyDocument( xModuleManager, xCurrModel ); - if( aCurrIdentifier == aIdentifier ) - pModifyDocumentFunc( xCurrModel, bModificator ); - } - catch( uno::Exception& ) - { - } - } + uno::Reference< frame::XModel > xCurrModel( xDocumentsEnum->nextElement(), uno::UNO_QUERY_THROW ); + pModifyDocumentFunc( xCurrModel, bModificator ); } - else + catch( uno::Exception& ) { - // no module manager, no documents enumeration, no identifier -> at least process the passed document - pModifyDocumentFunc( rxModel, bModificator ); } } +// ---------------------------------------------------------------------------- + +struct CurrDirPool +{ + ::osl::Mutex maMutex; + ::std::map< ::rtl::OUString, ::rtl::OUString > maCurrDirs; +}; + +struct StaticCurrDirPool : public ::rtl::Static< CurrDirPool, StaticCurrDirPool > {}; + } // namespace // ============================================================================ +uno::Reference< container::XEnumeration > createDocumentsEnumeration( const uno::Reference< frame::XModel >& rxModel ) +{ + return new DocumentsEnumeration( rxModel ); +} + +// ============================================================================ + void lockControllersOfAllDocuments( const uno::Reference< frame::XModel >& rxModel, sal_Bool bLockControllers ) { lclIterateDocuments( &lclLockControllers, rxModel, bLockControllers ); @@ -208,5 +222,45 @@ void enableContainerWindowsOfAllDocuments( const uno::Reference< frame::XModel > // ============================================================================ +void registerCurrentDirectory( const uno::Reference< frame::XModel >& rxModel, const ::rtl::OUString& rPath ) +{ + if( rPath.getLength() > 0 ) + { + CurrDirPool& rPool = StaticCurrDirPool::get(); + ::osl::MutexGuard aGuard( rPool.maMutex ); + try + { + uno::Reference< frame::XModuleManager > xModuleManager( lclCreateModuleManager(), uno::UNO_SET_THROW ); + ::rtl::OUString aIdentifier = xModuleManager->identify( rxModel ); + if( aIdentifier.getLength() > 0 ) + rPool.maCurrDirs[ aIdentifier ] = rPath; + } + catch( uno::Exception& ) + { + } + } +} + +// ============================================================================ + +::rtl::OUString getCurrentDirectory( const uno::Reference< frame::XModel >& rxModel ) +{ + ::rtl::OUString aPath; + CurrDirPool& rPool = StaticCurrDirPool::get(); + ::osl::MutexGuard aGuard( rPool.maMutex ); + try + { + uno::Reference< frame::XModuleManager > xModuleManager( lclCreateModuleManager(), uno::UNO_SET_THROW ); + ::rtl::OUString aIdentifier = xModuleManager->identify( rxModel ); + aPath = rPool.maCurrDirs[ aIdentifier ]; + } + catch( uno::Exception& ) + { + } + return aPath; +} + +// ============================================================================ + } // namespace vba } // namespace basic diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx index f8ffa46d48a5..bf7b00e2a633 100644 --- a/basic/source/classes/sb.cxx +++ b/basic/source/classes/sb.cxx @@ -42,6 +42,7 @@ #include <tools/shl.hxx> #include <tools/rc.hxx> #include <vcl/svapp.hxx> +#include <comphelper/processfactory.hxx> #include "sbunoobj.hxx" #include "sbjsmeth.hxx" #include "sbjsmod.hxx" @@ -136,6 +137,7 @@ void DocBasicItem::startListening() Any aThisComp; mrDocBasic.GetUNOConstant( "ThisComponent", aThisComp ); Reference< util::XCloseBroadcaster > xCloseBC( aThisComp, UNO_QUERY ); + mbDisposed = !xCloseBC.is(); if( xCloseBC.is() ) try { xCloseBC->addCloseListener( this ); } catch( uno::Exception& ) {} } @@ -437,7 +439,20 @@ SbxObject* SbiFactory::CreateObject( const String& rClass ) return new BasicCollection( aCollectionName ); } else - return NULL; + if( rClass.EqualsIgnoreCaseAscii( "FileSystemObject" ) ) + { + try + { + Reference< XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory(), UNO_SET_THROW ); + ::rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.FileSystemObject" ) ); + Reference< XInterface > xInterface( xFactory->createInstance( aServiceName ), UNO_SET_THROW ); + return new SbUnoObject( aServiceName, uno::makeAny( xInterface ) ); + } + catch( Exception& ) + {} + } + + return NULL; } @@ -934,8 +949,14 @@ void StarBASIC::SetModified( sal_Bool b ) SbxBase::SetModified( b ); } +extern void lcl_closeTraceFile(); + StarBASIC::~StarBASIC() { +#ifdef DBG_TRACE_BASIC + lcl_closeTraceFile(); +#endif + // Needs to be first action as it can trigger events disposeComVariablesForBasic( this ); @@ -2273,7 +2294,22 @@ void BasicCollection::CollRemove( SbxArray* pPar_ ) SbxVariable* p = pPar_->Get( 1 ); sal_Int32 nIndex = implGetIndex( p ); if( nIndex >= 0 && nIndex < (sal_Int32)xItemArray->Count32() ) + { xItemArray->Remove32( nIndex ); + + // Correct for stack if necessary + SbiInstance* pInst = pINST; + SbiRuntime* pRT = pInst ? pInst->pRun : NULL; + if( pRT ) + { + SbiForStack* pStack = pRT->FindForStackItemForCollection( this ); + if( pStack != NULL ) + { + if( pStack->nCurCollectionIndex >= nIndex ) + --pStack->nCurCollectionIndex; + } + } + } else SetError( SbERR_BAD_ARGUMENT ); } diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx index 13ae406cb305..6f20a68a274f 100755 --- a/basic/source/classes/sbunoobj.cxx +++ b/basic/source/classes/sbunoobj.cxx @@ -1722,8 +1722,7 @@ String getBasicObjectTypeName( SbxObject* pObj ) return aName; } -bool checkUnoObjectType( SbUnoObject* pUnoObj, - const String& aClass ) +bool checkUnoObjectType( SbUnoObject* pUnoObj, const ::rtl::OUString& rClass ) { Any aToInspectObj = pUnoObj->getUnoAny(); TypeClass eType = aToInspectObj.getValueType().getTypeClass(); @@ -1740,6 +1739,21 @@ bool checkUnoObjectType( SbUnoObject* pUnoObj, Reference< XTypeProvider > xTypeProvider( x, UNO_QUERY ); if( xTypeProvider.is() ) { + /* Although interfaces in the ooo.vba namespace obey the IDL rules and + have a leading 'X', in Basic we want to be able to do something + like 'Dim wb As Workbooks' or 'Dim lb As MSForms.Label'. Here we + add a leading 'X' to the class name and a leading dot to the entire + type name. This results e.g. in '.XWorkbooks' or '.MSForms.XLabel' + which matches the interface names 'ooo.vba.excel.XWorkbooks' or + 'ooo.vba.msforms.XLabel'. + */ + ::rtl::OUString aClassName( sal_Unicode( '.' ) ); + sal_Int32 nClassNameDot = rClass.lastIndexOf( '.' ); + if( nClassNameDot >= 0 ) + aClassName += rClass.copy( 0, nClassNameDot + 1 ) + ::rtl::OUString( sal_Unicode( 'X' ) ) + rClass.copy( nClassNameDot + 1 ); + else + aClassName += ::rtl::OUString( sal_Unicode( 'X' ) ) + rClass; + Sequence< Type > aTypeSeq = xTypeProvider->getTypes(); const Type* pTypeArray = aTypeSeq.getConstArray(); sal_uInt32 nIfaceCount = aTypeSeq.getLength(); @@ -1753,8 +1767,8 @@ bool checkUnoObjectType( SbUnoObject* pUnoObj, DBG_ERROR("failed to get XIdlClass for type"); break; } - ::rtl::OUString sClassName = xClass->getName(); - if ( sClassName.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.oleautomation.XAutomationObject" ) ) ) ) + ::rtl::OUString aInterfaceName = xClass->getName(); + if ( aInterfaceName.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.oleautomation.XAutomationObject" ) ) ) ) { // there is a hack in the extensions/source/ole/oleobj.cxx to return the typename of the automation object, lets check if it // matches @@ -1767,20 +1781,15 @@ bool checkUnoObjectType( SbUnoObject* pUnoObj, // can't check type, leave it pass result = true; else - result = sTypeName.equals( aClass ); + result = sTypeName.equals( rClass ); } break; // finished checking automation object } - OSL_TRACE("Checking if object implements %s", - OUStringToOString( defaultNameSpace + aClass, - RTL_TEXTENCODING_UTF8 ).getStr() ); - // although interfaces in the ooo.vba.vba namespace - // obey the idl rules and have a leading X, in basic we - // want to be able to do something like - // 'dim wrkbooks as WorkBooks' - // so test assumes the 'X' has been dropped - sal_Int32 indexLastDot = sClassName.lastIndexOf('.'); - if ( indexLastDot > -1 && sClassName.copy( indexLastDot + 1).equalsIgnoreAsciiCase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("X") ) + aClass ) ) + + // match interface name with passed class name + OSL_TRACE("Checking if object implements %s", OUStringToOString( aClassName, RTL_TEXTENCODING_UTF8 ).getStr() ); + if ( (aClassName.getLength() < aInterfaceName.getLength()) && + aInterfaceName.matchIgnoreAsciiCase( aClassName, aInterfaceName.getLength() - aClassName.getLength() ) ) { result = true; break; diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx index c722e680fd8c..24b031e8f4e9 100644 --- a/basic/source/classes/sbxmod.cxx +++ b/basic/source/classes/sbxmod.cxx @@ -61,6 +61,7 @@ #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/script/ModuleType.hpp> #include <com/sun/star/script/vba/XVBACompatibility.hpp> +#include <com/sun/star/script/vba/VBAScriptEventId.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/document/XEventBroadcaster.hpp> #include <com/sun/star/document/XEventListener.hpp> @@ -88,10 +89,8 @@ using namespace com::sun::star; #include <cppuhelper/implbase1.hxx> #include <basic/sbobjmod.hxx> #include <com/sun/star/uno/XAggregation.hpp> -#include <map> #include <com/sun/star/script/XInvocation.hpp> - using namespace ::com::sun::star; using namespace com::sun::star::lang; using namespace com::sun::star::reflection; using namespace com::sun::star::beans; @@ -107,6 +106,7 @@ using namespace com::sun::star::script; #include <cppuhelper/implbase1.hxx> #include <comphelper/anytostring.hxx> #include <com/sun/star/beans/XPropertySet.hpp> +#include <ooo/vba/VbQueryClose.hpp> typedef ::cppu::WeakImplHelper1< XInvocation > DocObjectWrapper_BASE; typedef ::std::map< sal_Int16, Any, ::std::less< sal_Int16 > > OutParamMap; @@ -451,24 +451,36 @@ TYPEINIT1(SbUserFormModule,SbObjModule) typedef std::vector<HighlightPortion> HighlightPortions; -bool getDefaultVBAMode( StarBASIC* pb ) +uno::Reference< frame::XModel > getDocumentModel( StarBASIC* pb ) { - bool bResult = false; - if ( pb && pb->IsDocBasic() ) + uno::Reference< frame::XModel > xModel; + if( pb && pb->IsDocBasic() ) { uno::Any aDoc; - if ( pb->GetUNOConstant( "ThisComponent", aDoc ) ) - { - uno::Reference< beans::XPropertySet > xProp( aDoc, uno::UNO_QUERY ); - if ( xProp.is() ) - { - uno::Reference< script::vba::XVBACompatibility > xVBAMode( xProp->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BasicLibraries") ) ), uno::UNO_QUERY ); - if ( xVBAMode.is() ) - bResult = xVBAMode->getVBACompatibilityMode() == sal_True; - } - } + if( pb->GetUNOConstant( "ThisComponent", aDoc ) ) + xModel.set( aDoc, uno::UNO_QUERY ); } - return bResult; + return xModel; +} + +uno::Reference< vba::XVBACompatibility > getVBACompatibility( const uno::Reference< frame::XModel >& rxModel ) +{ + uno::Reference< vba::XVBACompatibility > xVBACompat; + try + { + uno::Reference< beans::XPropertySet > xModelProps( rxModel, uno::UNO_QUERY_THROW ); + xVBACompat.set( xModelProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicLibraries" ) ) ), uno::UNO_QUERY ); + } + catch( uno::Exception& ) + { + } + return xVBACompat; +} + +bool getDefaultVBAMode( StarBASIC* pb ) +{ + uno::Reference< vba::XVBACompatibility > xVBACompat = getVBACompatibility( getDocumentModel( pb ) ); + return xVBACompat.is() && xVBACompat->getVBACompatibilityMode(); } class AsyncQuitHandler @@ -501,20 +513,6 @@ IMPL_LINK( AsyncQuitHandler, OnAsyncQuit, void*, /*pNull*/ ) return 0L; } -void VBAUnlockDocuments( StarBASIC* pBasic ) -{ - if ( pBasic && pBasic->IsDocBasic() ) - { - SbUnoObject* pGlobs = dynamic_cast< SbUnoObject* >( pBasic->Find( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ThisComponent" ) ), SbxCLASS_DONTCARE ) ); - if ( pGlobs ) - { - uno::Reference< frame::XModel > xModel( pGlobs->getUnoAny(), uno::UNO_QUERY ); - ::basic::vba::lockControllersOfAllDocuments( xModel, sal_False ); - ::basic::vba::enableContainerWindowsOfAllDocuments( xModel, sal_True ); - } - } -} - ///////////////////////////////////////////////////////////////////////////// // Ein BASIC-Modul hat EXTSEARCH gesetzt, damit die im Modul enthaltenen @@ -833,7 +831,7 @@ void SbModule::SetSource( const String& r ) void SbModule::SetSource32( const ::rtl::OUString& r ) { // Default basic mode to library container mode, but.. allow Option VBASupport 0/1 override - SetVBACompat( getDefaultVBAMode( static_cast< StarBASIC*>( GetParent() ) ) ); + SetVBACompat( getDefaultVBAMode( static_cast< StarBASIC*>( GetParent() ) ) ); aOUSource = r; StartDefinitions(); SbiTokenizer aTok( r ); @@ -1031,6 +1029,8 @@ sal_uInt16 SbModule::Run( SbMethod* pMeth ) sal_uInt16 nRes = 0; sal_Bool bDelInst = sal_Bool( pINST == NULL ); StarBASICRef xBasic; + uno::Reference< frame::XModel > xModel; + uno::Reference< script::vba::XVBACompatibility > xVBACompat; if( bDelInst ) { #ifdef DBG_TRACE_BASIC @@ -1041,6 +1041,23 @@ sal_uInt16 SbModule::Run( SbMethod* pMeth ) pINST = new SbiInstance( (StarBASIC*) GetParent() ); + /* If a VBA script in a document is started, get the VBA compatibility + interface from the document Basic library container, and notify all + VBA script listeners about the started script. */ + if( mbVBACompat ) + { + StarBASIC* pBasic = static_cast< StarBASIC* >( GetParent() ); + if( pBasic && pBasic->IsDocBasic() ) try + { + xModel.set( getDocumentModel( pBasic ), uno::UNO_SET_THROW ); + xVBACompat.set( getVBACompatibility( xModel ), uno::UNO_SET_THROW ); + xVBACompat->broadcastVBAScriptEvent( script::vba::VBAScriptEventId::SCRIPT_STARTED, GetName() ); + } + catch( uno::Exception& ) + { + } + } + // Launcher problem // i80726 The Find below will genarate an error in Testtool so we reset it unless there was one before already sal_Bool bWasError = SbxBase::GetError() != 0; @@ -1183,9 +1200,20 @@ sal_uInt16 SbModule::Run( SbMethod* pMeth ) ResetCapturedAssertions(); #endif - // VBA always ensures screenupdating is enabled after completing - if ( mbVBACompat ) - VBAUnlockDocuments( PTR_CAST( StarBASIC, GetParent() ) ); + if( xVBACompat.is() ) + { + // notify all VBA script listeners about the stopped script + try + { + xVBACompat->broadcastVBAScriptEvent( script::vba::VBAScriptEventId::SCRIPT_STOPPED, GetName() ); + } + catch( uno::Exception& ) + { + } + // VBA always ensures screenupdating is enabled after completing + ::basic::vba::lockControllersOfAllDocuments( xModel, sal_False ); + ::basic::vba::enableContainerWindowsOfAllDocuments( xModel, sal_True ); + } #ifdef DBG_TRACE_BASIC dbg_DeInitTrace(); @@ -2276,8 +2304,9 @@ public: uno::Reference< document::XVbaMethodParameter > xVbaMethodParameter( xControl->getPeer(), uno::UNO_QUERY ); if ( xVbaMethodParameter.is() ) { +#endif sal_Int8 nCancel = 0; - sal_Int8 nCloseMode = 0; + sal_Int8 nCloseMode = ::ooo::vba::VbQueryClose::vbFormControlMenu; Sequence< Any > aParams; aParams.realloc(2); @@ -2286,14 +2315,13 @@ public: mpUserForm->triggerMethod( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Userform_QueryClose") ), aParams); +#if IN_THE_FUTURE xVbaMethodParameter->setVbaMethodParameter( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Cancel")), aParams[0]); return; } } } - - mpUserForm->triggerMethod( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Userform_QueryClose") ) ); #endif } //liuchen 2009-7-21 @@ -2403,15 +2431,14 @@ void SbUserFormModule::triggerMethod( const String& aMethodToRun ) Sequence< Any > aArguments; triggerMethod( aMethodToRun, aArguments ); } -void SbUserFormModule::triggerMethod( const String& aMethodToRun, Sequence< Any >& /*aArguments*/) + +void SbUserFormModule::triggerMethod( const String& aMethodToRun, Sequence< Any >& aArguments ) { OSL_TRACE("*** trigger %s ***", rtl::OUStringToOString( aMethodToRun, RTL_TEXTENCODING_UTF8 ).getStr() ); // Search method SbxVariable* pMeth = SbObjModule::Find( aMethodToRun, SbxCLASS_METHOD ); if( pMeth ) { -#if IN_THE_FUTURE - //liuchen 2009-7-21, support Excel VBA UserForm_QueryClose event with parameters if ( aArguments.getLength() > 0 ) // Setup parameters { SbxArrayRef xArray = new SbxArray; @@ -2439,8 +2466,6 @@ void SbUserFormModule::triggerMethod( const String& aMethodToRun, Sequence< Any pMeth->SetParameters( NULL ); } else -//liuchen 2009-7-21 -#endif { SbxValues aVals; pMeth->Get( aVals ); @@ -2532,7 +2557,7 @@ void SbUserFormModule::Unload() OSL_TRACE("** Unload() "); sal_Int8 nCancel = 0; - sal_Int8 nCloseMode = 1; + sal_Int8 nCloseMode = ::ooo::vba::VbQueryClose::vbFormCode; Sequence< Any > aParams; aParams.realloc(2); @@ -2542,7 +2567,7 @@ void SbUserFormModule::Unload() triggerMethod( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Userform_QueryClose") ), aParams); aParams[0] >>= nCancel; - if (nCancel == 1) + if (nCancel != 0) // Basic returns -1 for "True" { return; } @@ -2585,6 +2610,9 @@ void SbUserFormModule::InitObject() SbUnoObject* pGlobs = (SbUnoObject*)GetParent()->Find( aHook, SbxCLASS_DONTCARE ); if ( m_xModel.is() && pGlobs ) { + // broadcast INITIALIZE_USERFORM script event before the dialog is created + Reference< script::vba::XVBACompatibility > xVBACompat( getVBACompatibility( m_xModel ), uno::UNO_SET_THROW ); + xVBACompat->broadcastVBAScriptEvent( script::vba::VBAScriptEventId::INITIALIZE_USERFORM, GetName() ); uno::Reference< lang::XMultiServiceFactory > xVBAFactory( pGlobs->getUnoAny(), uno::UNO_QUERY_THROW ); uno::Reference< lang::XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory(); diff --git a/basic/source/comp/codegen.cxx b/basic/source/comp/codegen.cxx index a8c7e3f5330f..f59edfbb12e9 100644 --- a/basic/source/comp/codegen.cxx +++ b/basic/source/comp/codegen.cxx @@ -303,6 +303,8 @@ void SbiCodeGen::Save() nUserData |= nDefaultId; if( pPar->IsParamArray() ) nUserData |= PARAM_INFO_PARAMARRAY; + if( pPar->IsWithBrackets() ) + nUserData |= PARAM_INFO_WITHBRACKETS; if( nUserData ) { SbxParamInfo* pParam = (SbxParamInfo*)pInfo->GetParam( i ); diff --git a/basic/source/comp/dim.cxx b/basic/source/comp/dim.cxx index 1ba8982404e4..03c4845569a7 100644 --- a/basic/source/comp/dim.cxx +++ b/basic/source/comp/dim.cxx @@ -51,7 +51,11 @@ SbiSymDef* SbiParser::VarDecl( SbiDimList** ppDim, sal_Bool bStatic, sal_Bool bC SbiDimList* pDim = NULL; // Klammern? if( Peek() == LPAREN ) + { pDim = new SbiDimList( this ); + if( !pDim->GetDims() ) + pDef->SetWithBrackets(); + } pDef->SetType( t ); if( bStatic ) pDef->SetStatic(); @@ -382,6 +386,9 @@ void SbiParser::DefVar( SbiOpcode eOp, sal_Bool bStatic ) if( nFixedStringLength >= 0 ) nOpnd2 |= (SBX_FIXED_LEN_STRING_FLAG + (sal_uInt32(nFixedStringLength) << 17)); // len = all bits above 0x10000 + if( pDim != NULL && pDim->GetDims() > 0 ) + nOpnd2 |= SBX_TYPE_VAR_TO_DIM_FLAG; + aGen.Gen( eOp2, pDef->GetId(), nOpnd2 ); } diff --git a/basic/source/comp/makefile.mk b/basic/source/comp/makefile.mk index d65f6a431e43..1e17b35cde61 100644 --- a/basic/source/comp/makefile.mk +++ b/basic/source/comp/makefile.mk @@ -53,7 +53,8 @@ EXCEPTIONSFILES= \ $(SLO)$/codegen.obj \ $(SLO)$/dim.obj \ $(SLO)$/exprtree.obj \ - $(SLO)$/parser.obj + $(SLO)$/parser.obj \ + $(SLO)$/sbcomp.obj # --- Targets -------------------------------------------------------------- diff --git a/basic/source/comp/sbcomp.cxx b/basic/source/comp/sbcomp.cxx index 12e368d1c7eb..1b3395b70526 100755 --- a/basic/source/comp/sbcomp.cxx +++ b/basic/source/comp/sbcomp.cxx @@ -33,7 +33,7 @@ #include "image.hxx" #include "sbtrace.hxx" #include <basic/sbobjmod.hxx> - +#include <stdio.h> //========================================================================== // Tracing, for debugging only @@ -44,12 +44,13 @@ #include <hash_map> // Trace ini file (set NULL to ignore) -static char GpTraceIniFile[] = "d:\\zBasic.Asm\\BasicTrace.ini"; +// can be overridden with the environment variable OOO_BASICTRACEINI +static char GpTraceIniFile[] = "~/BasicTrace.ini"; //static char* GpTraceIniFile = NULL; // Trace Settings, used if no ini file / not found in ini file -static char GpTraceFileNameDefault[] = "d:\\zBasic.Asm\\BasicTrace.txt"; +static char GpTraceFileNameDefault[] = "~/BasicTrace.txt"; static char* GpTraceFileName = GpTraceFileNameDefault; // GbTraceOn: @@ -63,6 +64,12 @@ static bool GbTraceOn = true; // with TraceCommand( "PCodeOn" / "PCodeOff" ), see below static bool GbIncludePCodes = false; +// GbInitOnlyAtOfficeStart: +// true = Tracing is only intialized onces after Office start when +// Basic runs the first time. Further calls to Basic, e.g. via events +// use the same output file. The trace ini file is not read again. +static bool GbInitOnlyAtOfficeStart = false; + static int GnIndentPerCallLevel = 4; static int GnIndentForPCode = 2; @@ -84,6 +91,37 @@ static int GnIndentForPCode = 2; long as it can be converted to string */ +#ifdef DBG_TRACE_PROFILING + +#include <algorithm> +#include <stack> +#include "canvas/elapsedtime.hxx" + +//*** Profiling *** +// GbTimerOn: +// true = including time stamps +static bool GbTimerOn = true; + +// GbTimeStampForEachStep: +// true = prints time stamp after each command / pcode (very slow) +static bool GbTimeStampForEachStep = false; + +// GbBlockAllAfterFirstFunctionUsage: +// true = everything (commands, pcodes, functions) is only printed +// for the first usage (improves performance when tracing / pro- +// filing large macros) +static bool GbBlockAllAfterFirstFunctionUsage = false; + +// GbBlockStepsAfterFirstFunctionUsage: +// true = commands / pcodes are only printed for the first time +// a function is executed. Afterwards only the entering/leaving +// messages are logged (improves performance when tracing / pro- +// filing large macros) +static bool GbBlockStepsAfterFirstFunctionUsage = false; + +#endif + + static void lcl_skipWhites( char*& rpc ) { while( *rpc == ' ' || *rpc == '\t' ) @@ -174,11 +212,28 @@ static void lcl_ReadIniFile( const char* pIniFileName ) if( strcmp( VarNameBuffer, "GbIncludePCodes") == 0 ) GbIncludePCodes = (strcmp( ValBuffer, "true" ) == 0); else + if( strcmp( VarNameBuffer, "GbInitOnlyAtOfficeStart") == 0 ) + GbInitOnlyAtOfficeStart = (strcmp( ValBuffer, "true" ) == 0); + else if( strcmp( VarNameBuffer, "GnIndentPerCallLevel") == 0 ) GnIndentPerCallLevel = strtol( ValBuffer, NULL, 10 ); else if( strcmp( VarNameBuffer, "GnIndentForPCode") == 0 ) GnIndentForPCode = strtol( ValBuffer, NULL, 10 ); +#ifdef DBG_TRACE_PROFILING + else + if( strcmp( VarNameBuffer, "GbTimerOn") == 0 ) + GbTimerOn = (strcmp( ValBuffer, "true" ) == 0); + else + if( strcmp( VarNameBuffer, "GbTimeStampForEachStep") == 0 ) + GbTimeStampForEachStep = (strcmp( ValBuffer, "true" ) == 0); + else + if( strcmp( VarNameBuffer, "GbBlockAllAfterFirstFunctionUsage") == 0 ) + GbBlockAllAfterFirstFunctionUsage = (strcmp( ValBuffer, "true" ) == 0); + else + if( strcmp( VarNameBuffer, "GbBlockStepsAfterFirstFunctionUsage") == 0 ) + GbBlockStepsAfterFirstFunctionUsage = (strcmp( ValBuffer, "true" ) == 0); +#endif } fclose( pFile ); } @@ -209,14 +264,14 @@ static void lcl_PrepareTraceForModule( SbModule* pModule ) pModule->Disassemble( aDisassemblyStr ); } -static void lcl_lineOut( const char* pFileName, const char* pStr, const char* pPreStr = NULL ) +static FILE* GpGlobalFile = NULL; + +static void lcl_lineOut( const char* pStr, const char* pPreStr = NULL, const char* pPostStr = NULL ) { - const char* pPrintFirst = (pPreStr != NULL) ? pPreStr : ""; - FILE* pFile = fopen( pFileName, "a+" ); - if( pFile != NULL ) + if( GpGlobalFile != NULL ) { - fprintf( pFile, "%s%s\n", pPrintFirst, pStr ); - fclose( pFile ); + fprintf( GpGlobalFile, "%s%s%s\n", pPreStr ? pPreStr : "", pStr, pPostStr ? pPostStr : "" ); + fflush( GpGlobalFile ); } } @@ -304,32 +359,198 @@ String lcl_dumpMethodParameters( SbMethod* pMethod ) // Public functions - static bool GbSavTraceOn = false; + +#ifdef DBG_TRACE_PROFILING +static canvas::tools::ElapsedTime* GpTimer = NULL; +static double GdStartTime = 0.0; +static double GdLastTime = 0.0; +static bool GbBlockSteps = false; +static bool GbBlockAll = false; + +struct FunctionItem +{ + String m_aCompleteFunctionName; + double m_dTotalTime; + double m_dNetTime; + int m_nCallCount; + bool m_bBlockAll; + bool m_bBlockSteps; + + FunctionItem( void ) + : m_dTotalTime( 0.0 ) + , m_dNetTime( 0.0 ) + , m_nCallCount( 0 ) + , m_bBlockAll( false ) + , m_bBlockSteps( false ) + {} +}; +typedef std::hash_map< ::rtl::OUString, FunctionItem*, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > FunctionItemMap; + +static std::stack< double > GaCallEnterTimeStack; +static std::stack< FunctionItem* > GaFunctionItemStack; +static FunctionItemMap GaFunctionItemMap; + +bool compareFunctionNetTime( FunctionItem* p1, FunctionItem* p2 ) +{ + return (p1->m_dNetTime > p2->m_dNetTime); +} + +void lcl_printTimeOutput( void ) +{ + // Overall time output + lcl_lineOut( "" ); + lcl_lineOut( "***** Time Output *****" ); + char TimeBuffer[500]; + double dTotalTime = GpTimer->getElapsedTime() - GdStartTime; + sprintf( TimeBuffer, "Total execution time = %f ms", dTotalTime*1000.0 ); + lcl_lineOut( TimeBuffer ); + lcl_lineOut( "" ); + + if( GbTimerOn ) + { + lcl_lineOut( "Functions:" ); + + std::vector<FunctionItem*> avFunctionItems; + + FunctionItemMap::iterator it; + for( it = GaFunctionItemMap.begin() ; it != GaFunctionItemMap.end() ; ++it ) + { + FunctionItem* pFunctionItem = it->second; + if( pFunctionItem != NULL ) + avFunctionItems.push_back( pFunctionItem ); + } + + std::sort( avFunctionItems.begin(), avFunctionItems.end(), compareFunctionNetTime ); + + std::vector<FunctionItem*>::iterator itv; + for( itv = avFunctionItems.begin() ; itv != avFunctionItems.end() ; ++itv ) + { + FunctionItem* pFunctionItem = *itv; + if( pFunctionItem != NULL ) + { + rtl::OUString aCompleteFunctionName = pFunctionItem->m_aCompleteFunctionName; + const char* pName = OUStringToOString( aCompleteFunctionName, RTL_TEXTENCODING_ASCII_US ).getStr(); + int nNameLen = aCompleteFunctionName.getLength(); + + double dFctTotalTime = pFunctionItem->m_dTotalTime; + double dFctNetTime = pFunctionItem->m_dNetTime; + double dFctTotalTimePercent = 100.0 * dFctTotalTime / dTotalTime; + double dFctNetTimePercent = 100.0 * dFctNetTime / dTotalTime; + int nSpaceCount = 30 - nNameLen; + if( nSpaceCount < 0 ) + nSpaceCount = 2; + sprintf( TimeBuffer, "%s:%sCalled %d times\t%f ms (%f%%) / net %f (%f%%) ms", + pName, lcl_getSpaces( nSpaceCount ), pFunctionItem->m_nCallCount, + dFctTotalTime*1000.0, dFctTotalTimePercent, dFctNetTime*1000.0, dFctNetTimePercent ); + lcl_lineOut( TimeBuffer ); + } + } + } +} +#endif + + +static bool GbInitTraceAlreadyCalled = false; + void dbg_InitTrace( void ) { - if( GpTraceIniFile != NULL ) + if( GbInitOnlyAtOfficeStart && GbInitTraceAlreadyCalled ) + { +#ifdef DBG_TRACE_PROFILING + if( GbTimerOn ) + GpTimer->continueTimer(); +#endif + GpGlobalFile = fopen( GpTraceFileName, "a+" ); + return; + } + GbInitTraceAlreadyCalled = true; + + if( const sal_Char* pcIniFileName = ::getenv( "OOO_BASICTRACEINI" ) ) + lcl_ReadIniFile( pcIniFileName ); + else if( GpTraceIniFile != NULL ) lcl_ReadIniFile( GpTraceIniFile ); - FILE* pFile = fopen( GpTraceFileName, "w" ); - if( pFile != NULL ) - fclose( pFile ); + GpGlobalFile = fopen( GpTraceFileName, "w" ); GbSavTraceOn = GbTraceOn; if( !GbTraceOn ) - lcl_lineOut( GpTraceFileName, "### Program started with trace off ###" ); + lcl_lineOut( "### Program started with trace off ###" ); + +#ifdef DBG_TRACE_PROFILING + GpTimer = new canvas::tools::ElapsedTime(); + GdStartTime = GpTimer->getElapsedTime(); + GdLastTime = GdStartTime; + GbBlockSteps = false; + GbBlockAll = false; +#endif } void dbg_DeInitTrace( void ) { GbTraceOn = GbSavTraceOn; + +#ifdef DBG_TRACE_PROFILING + while( !GaCallEnterTimeStack.empty() ) + GaCallEnterTimeStack.pop(); + while( !GaFunctionItemStack.empty() ) + GaFunctionItemStack.pop(); + + lcl_printTimeOutput(); + + for( FunctionItemMap::iterator it = GaFunctionItemMap.begin() ; it != GaFunctionItemMap.end() ; ++it ) + delete it->second; + GaFunctionItemMap.clear(); + + if( GpGlobalFile ) + { + fclose( GpGlobalFile ); + GpGlobalFile = NULL; + } + + if( GbInitOnlyAtOfficeStart ) + { + if( GbTimerOn ) + GpTimer->pauseTimer(); + } + else + { + delete GpTimer; + } +#endif } static sal_Int32 GnLastCallLvl = 0; +void dbg_tracePrint( const String& aStr, sal_Int32 nCallLvl, bool bCallLvlRelativeToCurrent ) +{ + if( bCallLvlRelativeToCurrent ) + nCallLvl += GnLastCallLvl; + + int nIndent = nCallLvl * GnIndentPerCallLevel; + lcl_lineOut( OUStringToOString( rtl::OUString( aStr ), RTL_TEXTENCODING_ASCII_US ).getStr(), lcl_getSpaces( nIndent ) ); +} + void dbg_traceStep( SbModule* pModule, sal_uInt32 nPC, sal_Int32 nCallLvl ) { if( !GbTraceOn ) return; + +#ifdef DBG_TRACE_PROFILING + if( GbBlockSteps || GbBlockAll ) + return; + + double dCurTime = 0.0; + bool bPrintTimeStamp = false; + if( GbTimerOn ) + { + GpTimer->pauseTimer(); + dCurTime = GpTimer->getElapsedTime(); + bPrintTimeStamp = GbTimeStampForEachStep; + } +#else + bool bPrintTimeStamp = false; +#endif + GnLastCallLvl = nCallLvl; SbModule* pTraceMod = pModule; @@ -346,14 +567,14 @@ void dbg_traceStep( SbModule* pModule, sal_uInt32 nPC, sal_Int32 nCallLvl ) const char* pModuleNameStr = OUStringToOString( rtl::OUString( aModuleName ), RTL_TEXTENCODING_ASCII_US ).getStr(); char Buffer[200]; sprintf( Buffer, "TRACE ERROR: Unknown module \"%s\"", pModuleNameStr ); - lcl_lineOut( GpTraceFileName, Buffer ); + lcl_lineOut( Buffer ); return; } PCToTextDataMap* pInnerMap = it->second; if( pInnerMap == NULL ) { - lcl_lineOut( GpTraceFileName, "TRACE INTERNAL ERROR: No inner map" ); + lcl_lineOut( "TRACE INTERNAL ERROR: No inner map" ); return; } @@ -363,7 +584,7 @@ void dbg_traceStep( SbModule* pModule, sal_uInt32 nPC, sal_Int32 nCallLvl ) const char* pModuleNameStr = OUStringToOString( rtl::OUString( aModuleName ), RTL_TEXTENCODING_ASCII_US ).getStr(); char Buffer[200]; sprintf( Buffer, "TRACE ERROR: No info for PC = %d in module \"%s\"", (int)nPC, pModuleNameStr ); - lcl_lineOut( GpTraceFileName, Buffer ); + lcl_lineOut( Buffer ); return; } @@ -371,24 +592,67 @@ void dbg_traceStep( SbModule* pModule, sal_uInt32 nPC, sal_Int32 nCallLvl ) const TraceTextData& rTraceTextData = itInner->second; const rtl::OString& rStr_STMNT = rTraceTextData.m_aTraceStr_STMNT; + bool bSTMT = false; if( rStr_STMNT.getLength() ) - lcl_lineOut( GpTraceFileName, rStr_STMNT.getStr(), lcl_getSpaces( nIndent ) ); + bSTMT = true; + + char TimeBuffer[200]; +#ifdef DBG_TRACE_PROFILING + if( bPrintTimeStamp ) + { + double dDiffTime = dCurTime - GdLastTime; + GdLastTime = dCurTime; + sprintf( TimeBuffer, "\t\t// Time = %f ms / += %f ms", dCurTime*1000.0, dDiffTime*1000.0 ); + } +#endif + + if( bSTMT ) + { + lcl_lineOut( rStr_STMNT.getStr(), lcl_getSpaces( nIndent ), + (bPrintTimeStamp && !GbIncludePCodes) ? TimeBuffer : NULL ); + } if( !GbIncludePCodes ) + { +#ifdef DBG_TRACE_PROFILING + if( GbTimerOn ) + GpTimer->continueTimer(); +#endif return; + } nIndent += GnIndentForPCode; const rtl::OString& rStr_PCode = rTraceTextData.m_aTraceStr_PCode; if( rStr_PCode.getLength() ) - lcl_lineOut( GpTraceFileName, rStr_PCode.getStr(), lcl_getSpaces( nIndent ) ); + { + lcl_lineOut( rStr_PCode.getStr(), lcl_getSpaces( nIndent ), + bPrintTimeStamp ? TimeBuffer : NULL ); + } + +#ifdef DBG_TRACE_PROFILING + if( GbTimerOn ) + GpTimer->continueTimer(); +#endif } + void dbg_traceNotifyCall( SbModule* pModule, SbMethod* pMethod, sal_Int32 nCallLvl, bool bLeave ) { static const char* pSeparator = "' ================================================================================"; if( !GbTraceOn ) return; + +#ifdef DBG_TRACE_PROFILING + double dCurTime = 0.0; + double dExecutionTime = 0.0; + if( GbTimerOn ) + { + dCurTime = GpTimer->getElapsedTime(); + GpTimer->pauseTimer(); + } +#endif + GnLastCallLvl = nCallLvl; SbModule* pTraceMod = pModule; @@ -399,39 +663,116 @@ void dbg_traceNotifyCall( SbModule* pModule, SbMethod* pMethod, sal_Int32 nCallL pTraceMod = pClassModuleObj->getClassModule(); } + String aCompleteFunctionName = pTraceMod->GetName(); + if( pMethod != NULL ) + { + aCompleteFunctionName.AppendAscii( "::" ); + String aMethodName = pMethod->GetName(); + aCompleteFunctionName += aMethodName; + } + else + { + aCompleteFunctionName.AppendAscii( "/RunInit" ); + } + + bool bOwnBlockSteps = false; +#ifdef DBG_TRACE_PROFILING + bool bOwnBlockAll = false; + FunctionItem* pFunctionItem = NULL; + if( GbTimerOn ) + { + FunctionItemMap::iterator itFunctionItem = GaFunctionItemMap.find( aCompleteFunctionName ); + if( itFunctionItem != GaFunctionItemMap.end() ) + pFunctionItem = itFunctionItem->second; + + if( pFunctionItem == NULL ) + { + DBG_ASSERT( !bLeave, "No FunctionItem in leave!" ); + + pFunctionItem = new FunctionItem(); + pFunctionItem->m_aCompleteFunctionName = aCompleteFunctionName; + GaFunctionItemMap[ aCompleteFunctionName ] = pFunctionItem; + } + else if( GbBlockAllAfterFirstFunctionUsage && !bLeave ) + { + pFunctionItem->m_bBlockAll = true; + } + else if( GbBlockStepsAfterFirstFunctionUsage && !bLeave ) + { + pFunctionItem->m_bBlockSteps = true; + } + + if( bLeave ) + { + bOwnBlockAll = GbBlockAll; + bOwnBlockSteps = GbBlockSteps; + GbBlockAll = false; + GbBlockSteps = false; + + dExecutionTime = dCurTime - GaCallEnterTimeStack.top(); + GaCallEnterTimeStack.pop(); + + pFunctionItem->m_dTotalTime += dExecutionTime; + pFunctionItem->m_dNetTime += dExecutionTime; + pFunctionItem->m_nCallCount++; + + GaFunctionItemStack.pop(); + if( !GaFunctionItemStack.empty() ) + { + FunctionItem* pParentItem = GaFunctionItemStack.top(); + if( pParentItem != NULL ) + { + pParentItem->m_dNetTime -= dExecutionTime; + + GbBlockSteps = pParentItem->m_bBlockSteps; + GbBlockAll = pParentItem->m_bBlockAll; + } + } + } + else + { + GbBlockSteps = bOwnBlockSteps = pFunctionItem->m_bBlockSteps; + GbBlockAll = bOwnBlockAll = pFunctionItem->m_bBlockAll; + + GaCallEnterTimeStack.push( dCurTime ); + GaFunctionItemStack.push( pFunctionItem ); + } + } + + if( bOwnBlockAll ) + { + if( GbTimerOn ) + GpTimer->continueTimer(); + return; + } +#endif + if( nCallLvl > 0 ) nCallLvl--; int nIndent = nCallLvl * GnIndentPerCallLevel; - if( !bLeave ) + if( !bLeave && !bOwnBlockSteps ) { - lcl_lineOut( GpTraceFileName, "" ); - lcl_lineOut( GpTraceFileName, pSeparator, lcl_getSpaces( nIndent ) ); + lcl_lineOut( "" ); + lcl_lineOut( pSeparator, lcl_getSpaces( nIndent ) ); } String aStr; if( bLeave ) { - lcl_lineOut( GpTraceFileName, "}", lcl_getSpaces( nIndent ) ); - aStr.AppendAscii( "' Leaving " ); + if( !bOwnBlockSteps ) + { + lcl_lineOut( "}", lcl_getSpaces( nIndent ) ); + aStr.AppendAscii( "' Leaving " ); + } } else { aStr.AppendAscii( "Entering " ); } - String aModuleName = pTraceMod->GetName(); - aStr += aModuleName; - if( pMethod != NULL ) - { - aStr.AppendAscii( "::" ); - String aMethodName = pMethod->GetName(); - aStr += aMethodName; - } - else - { - aStr.AppendAscii( "/RunInit" ); - } + if( !bLeave || !bOwnBlockSteps ) + aStr += aCompleteFunctionName; - if( pClassModuleObj != NULL ) + if( !bOwnBlockSteps && pClassModuleObj != NULL ) { aStr.AppendAscii( "[this=" ); aStr += pClassModuleObj->GetName(); @@ -440,18 +781,37 @@ void dbg_traceNotifyCall( SbModule* pModule, SbMethod* pMethod, sal_Int32 nCallL if( !bLeave ) aStr += lcl_dumpMethodParameters( pMethod ); - lcl_lineOut( GpTraceFileName, OUStringToOString( rtl::OUString( aStr ), RTL_TEXTENCODING_ASCII_US ).getStr(), lcl_getSpaces( nIndent ) ); + const char* pPostStr = NULL; +#ifdef DBG_TRACE_PROFILING + char TimeBuffer[200]; + if( GbTimerOn && bLeave ) + { + sprintf( TimeBuffer, " // Execution Time = %f ms", dExecutionTime*1000.0 ); + pPostStr = TimeBuffer; + } +#endif + lcl_lineOut( (!bLeave || !bOwnBlockSteps) ? OUStringToOString( rtl::OUString( aStr ), RTL_TEXTENCODING_ASCII_US ).getStr() : "}", + lcl_getSpaces( nIndent ), pPostStr ); if( !bLeave ) - lcl_lineOut( GpTraceFileName, "{", lcl_getSpaces( nIndent ) ); + lcl_lineOut( "{", lcl_getSpaces( nIndent ) ); - if( bLeave ) - lcl_lineOut( GpTraceFileName, "" ); + if( bLeave && !bOwnBlockSteps ) + lcl_lineOut( "" ); + +#ifdef DBG_TRACE_PROFILING + if( GbTimerOn ) + GpTimer->continueTimer(); +#endif } void dbg_traceNotifyError( SbError nTraceErr, const String& aTraceErrMsg, bool bTraceErrHandled, sal_Int32 nCallLvl ) { if( !GbTraceOn ) return; +#ifdef DBG_TRACE_PROFILING + if( GbBlockSteps || GbBlockAll ) + return; +#endif GnLastCallLvl = nCallLvl; rtl::OString aOTraceErrMsg = OUStringToOString( rtl::OUString( aTraceErrMsg ), RTL_TEXTENCODING_ASCII_US ); @@ -460,7 +820,7 @@ void dbg_traceNotifyError( SbError nTraceErr, const String& aTraceErrMsg, bool b const char* pHandledStr = bTraceErrHandled ? " / HANDLED" : ""; sprintf( Buffer, "*** ERROR%s, Id = %d, Msg = \"%s\" ***", pHandledStr, (int)nTraceErr, aOTraceErrMsg.getStr() ); int nIndent = nCallLvl * GnIndentPerCallLevel; - lcl_lineOut( GpTraceFileName, Buffer, lcl_getSpaces( nIndent ) ); + lcl_lineOut( Buffer, lcl_getSpaces( nIndent ) ); } void dbg_RegisterTraceTextForPC( SbModule* pModule, sal_uInt32 nPC, @@ -540,7 +900,7 @@ void RTL_Impl_TraceCommand( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite ) sprintf( Buffer, "### TRACE_PRINT: %s ###", pValStr ); int nIndent = GnLastCallLvl * GnIndentPerCallLevel; - lcl_lineOut( GpTraceFileName, Buffer, lcl_getSpaces( nIndent ) ); + lcl_lineOut( Buffer, lcl_getSpaces( nIndent ) ); if( eOld != SbxERR_OK ) SbxBase::SetError( eOld ); diff --git a/basic/source/comp/symtbl.cxx b/basic/source/comp/symtbl.cxx index 2688b5be28cf..cc6dc04fde65 100644 --- a/basic/source/comp/symtbl.cxx +++ b/basic/source/comp/symtbl.cxx @@ -302,6 +302,7 @@ SbiSymDef::SbiSymDef( const String& rName ) : aName( rName ) bOpt = bParamArray = bWithEvents = + bWithBrackets = bByVal = bChained = bGlobal = sal_False; diff --git a/basic/source/comp/token.cxx b/basic/source/comp/token.cxx index 8700ae4129ba..28c90ff0bd87 100644 --- a/basic/source/comp/token.cxx +++ b/basic/source/comp/token.cxx @@ -561,7 +561,8 @@ SbiToken SbiTokenizer::Next() } special: // #i92642 - if( eCurTok != NIL && eCurTok != REM && eCurTok != EOLN && (tp->t == NAME || tp->t == LINE) ) + bool bStartOfLine = (eCurTok == NIL || eCurTok == REM || eCurTok == EOLN); + if( !bStartOfLine && (tp->t == NAME || tp->t == LINE) ) return eCurTok = SYMBOL; else if( tp->t == TEXT ) return eCurTok = SYMBOL; @@ -628,6 +629,9 @@ special: // #129904 Suppress system if( eTok == STOP && aSym.CompareIgnoreCaseToAscii( "system" ) == COMPARE_EQUAL ) eCurTok = SYMBOL; + + if( eTok == GET && bStartOfLine ) + eCurTok = SYMBOL; } else { diff --git a/basic/source/inc/codegen.hxx b/basic/source/inc/codegen.hxx index a496322bb6d7..9ba99e7ceae8 100644 --- a/basic/source/inc/codegen.hxx +++ b/basic/source/inc/codegen.hxx @@ -87,6 +87,7 @@ public: // #111897 PARAM_INFO flags start at 0x00010000 to not // conflict with DefaultId in SbxParamInfo::nUserData -#define PARAM_INFO_PARAMARRAY 0x0010000 +#define PARAM_INFO_PARAMARRAY 0x0010000 +#define PARAM_INFO_WITHBRACKETS 0x0020000 #endif diff --git a/basic/source/inc/namecont.hxx b/basic/source/inc/namecont.hxx index 7fd6eb06f607..c0e8191be307 100644 --- a/basic/source/inc/namecont.hxx +++ b/basic/source/inc/namecont.hxx @@ -29,6 +29,7 @@ #define BASIC_NAMECONTAINER_HXX #include <hash_map> + #include <com/sun/star/lang/XSingleServiceFactory.hpp> #include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/lang/XInitialization.hpp> @@ -46,71 +47,41 @@ #include <com/sun/star/document/XStorageBasedDocument.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/deployment/XPackage.hpp> +#include <com/sun/star/script/vba/XVBACompatibility.hpp> +#include <com/sun/star/script/vba/XVBAScriptListener.hpp> +#include <com/sun/star/util/XChangesNotifier.hpp> + #include <osl/mutex.hxx> #include <unotools/eventlisteneradapter.hxx> +#include <cppuhelper/implbase3.hxx> +#include <cppuhelper/compbase8.hxx> +#include <cppuhelper/interfacecontainer.hxx> #include <cppuhelper/weakref.hxx> #include <cppuhelper/component.hxx> #include <cppuhelper/typeprovider.hxx> #include <cppuhelper/interfacecontainer.hxx> #include <cppuhelper/basemutex.hxx> #include <sot/storage.hxx> +#include <comphelper/listenernotification.hxx> #include <xmlscript/xmllib_imexp.hxx> -#include <com/sun/star/deployment/XPackage.hpp> - -#include <cppuhelper/implbase2.hxx> -#include <cppuhelper/compbase8.hxx> -#include <cppuhelper/interfacecontainer.hxx> -#include <com/sun/star/script/vba/XVBACompatibility.hpp> class BasicManager; namespace basic { -typedef ::cppu::WeakComponentImplHelper8< - ::com::sun::star::lang::XInitialization, - ::com::sun::star::script::XStorageBasedLibraryContainer, - ::com::sun::star::script::XLibraryContainerPassword, - ::com::sun::star::script::XLibraryContainerExport, - ::com::sun::star::script::XLibraryContainer3, - ::com::sun::star::container::XContainer, - ::com::sun::star::script::vba::XVBACompatibility, - ::com::sun::star::lang::XServiceInfo > LibraryContainerHelper; - -typedef ::cppu::WeakImplHelper2< ::com::sun::star::container::XNameContainer, - ::com::sun::star::container::XContainer > NameContainerHelper; - +//============================================================================ -struct hashName_Impl -{ - size_t operator()(const ::rtl::OUString Str) const - { - return (size_t)Str.hashCode(); - } -}; +typedef ::cppu::WeakImplHelper3< + ::com::sun::star::container::XNameContainer, + ::com::sun::star::container::XContainer, + ::com::sun::star::util::XChangesNotifier > NameContainer_BASE; -struct eqName_Impl +class NameContainer : public ::cppu::BaseMutex, public NameContainer_BASE { - sal_Bool operator()(const ::rtl::OUString Str1, const ::rtl::OUString Str2) const - { - return ( Str1 == Str2 ); - } -}; - -typedef std::hash_map -< - ::rtl::OUString, - sal_Int32, - hashName_Impl, - eqName_Impl -> -NameContainerNameMap; - - -//============================================================================ + typedef std::hash_map< ::rtl::OUString, sal_Int32, ::rtl::OUStringHash > NameContainerNameMap; -class NameContainer : public ::cppu::BaseMutex, public NameContainerHelper -{ NameContainerNameMap mHashMap; ::com::sun::star::uno::Sequence< ::rtl::OUString > mNames; ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > mValues; @@ -119,14 +90,16 @@ class NameContainer : public ::cppu::BaseMutex, public NameContainerHelper ::com::sun::star::uno::Type mType; ::com::sun::star::uno::XInterface* mpxEventSource; - ::cppu::OInterfaceContainerHelper maListenerContainer; + ::cppu::OInterfaceContainerHelper maContainerListeners; + ::cppu::OInterfaceContainerHelper maChangesListeners; public: NameContainer( const ::com::sun::star::uno::Type& rType ) : mnElementCount( 0 ) , mType( rType ) , mpxEventSource( NULL ) - , maListenerContainer( m_aMutex ) + , maContainerListeners( m_aMutex ) + , maChangesListeners( m_aMutex ) {} void setEventSource( ::com::sun::star::uno::XInterface* pxEventSource ) @@ -173,21 +146,18 @@ public: virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + + // Methods XChangesNotifier + virtual void SAL_CALL addChangesListener( const ::com::sun::star::uno::Reference< + ::com::sun::star::util::XChangesListener >& xListener ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeChangesListener( const ::com::sun::star::uno::Reference< + ::com::sun::star::util::XChangesListener >& xListener ) + throw (::com::sun::star::uno::RuntimeException); }; //============================================================================ -class SfxLibrary; - -enum InitMode -{ - DEFAULT, - CONTAINER_INIT_FILE, - LIBRARY_INIT_FILE, - OFFICE_DOCUMENT, - OLD_BASIC_STORAGE -}; - class ModifiableHelper { private: @@ -217,9 +187,42 @@ public: } }; -class SfxLibraryContainer :public LibraryContainerHelper - ,public ::utl::OEventListenerAdapter +//============================================================================ + +typedef ::comphelper::OListenerContainerBase< + ::com::sun::star::script::vba::XVBAScriptListener, + ::com::sun::star::script::vba::VBAScriptEvent > VBAScriptListenerContainer_BASE; + +class VBAScriptListenerContainer : public VBAScriptListenerContainer_BASE +{ +public: + explicit VBAScriptListenerContainer( ::osl::Mutex& rMutex ); + +private: + virtual bool implTypedNotify( + const ::com::sun::star::uno::Reference< ::com::sun::star::script::vba::XVBAScriptListener >& rxListener, + const ::com::sun::star::script::vba::VBAScriptEvent& rEvent ) + throw (::com::sun::star::uno::Exception); +}; + +//============================================================================ + +class SfxLibrary; + +typedef ::cppu::WeakComponentImplHelper8< + ::com::sun::star::lang::XInitialization, + ::com::sun::star::script::XStorageBasedLibraryContainer, + ::com::sun::star::script::XLibraryContainerPassword, + ::com::sun::star::script::XLibraryContainerExport, + ::com::sun::star::script::XLibraryContainer3, + ::com::sun::star::container::XContainer, + ::com::sun::star::script::vba::XVBACompatibility, + ::com::sun::star::lang::XServiceInfo > SfxLibraryContainer_BASE; + +class SfxLibraryContainer : public SfxLibraryContainer_BASE, public ::utl::OEventListenerAdapter { + VBAScriptListenerContainer maVBAScriptListeners; + sal_Int32 mnRunningVBAScripts; sal_Bool mbVBACompat; protected: ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF; @@ -246,7 +249,14 @@ protected: BasicManager* mpBasMgr; sal_Bool mbOwnBasMgr; - InitMode meInitMode; + enum InitMode + { + DEFAULT, + CONTAINER_INIT_FILE, + LIBRARY_INIT_FILE, + OFFICE_DOCUMENT, + OLD_BASIC_STORAGE + } meInitMode; void implStoreLibrary( SfxLibrary* pLib, const ::rtl::OUString& aName, @@ -508,10 +518,24 @@ public: virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException) = 0; // Methods XVBACompatibility - virtual ::sal_Bool SAL_CALL getVBACompatibilityMode() throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setVBACompatibilityMode( ::sal_Bool _vbacompatmodeon ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getVBACompatibilityMode() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setVBACompatibilityMode( ::sal_Bool _vbacompatmodeon ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getRunningVBAScripts() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addVBAScriptListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::script::vba::XVBAScriptListener >& Listener ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeVBAScriptListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::script::vba::XVBAScriptListener >& Listener ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL broadcastVBAScriptEvent( sal_Int32 nIdentifier, const ::rtl::OUString& rModuleName ) + throw (::com::sun::star::uno::RuntimeException); }; +//============================================================================ + class LibraryContainerMethodGuard { private: @@ -529,12 +553,12 @@ public: } }; - //============================================================================ class SfxLibrary : public ::com::sun::star::container::XNameContainer , public ::com::sun::star::container::XContainer + , public ::com::sun::star::util::XChangesNotifier , public ::cppu::BaseMutex , public ::cppu::OComponentHelper { @@ -670,6 +694,14 @@ public: ::com::sun::star::container::XContainerListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + // Methods XChangesNotifier + virtual void SAL_CALL addChangesListener( const ::com::sun::star::uno::Reference< + ::com::sun::star::util::XChangesListener >& xListener ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeChangesListener( const ::com::sun::star::uno::Reference< + ::com::sun::star::util::XChangesListener >& xListener ) + throw (::com::sun::star::uno::RuntimeException); + public: struct LibraryContainerAccess { friend class SfxLibraryContainer; private: LibraryContainerAccess() { } }; void removeElementWithoutChecks( const ::rtl::OUString& _rElementName, LibraryContainerAccess ) @@ -681,18 +713,19 @@ protected: virtual bool SAL_CALL isLibraryElementValid( ::com::sun::star::uno::Any aElement ) const = 0; }; -//=================================================================== +//============================================================================ + class ScriptSubPackageIterator { - com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > m_xMainPackage; + com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > m_xMainPackage; - bool m_bIsValid; - bool m_bIsBundle; + bool m_bIsValid; + bool m_bIsBundle; com::sun::star::uno::Sequence< com::sun::star::uno::Reference - < com::sun::star::deployment::XPackage > > m_aSubPkgSeq; - sal_Int32 m_nSubPkgCount; - sal_Int32 m_iNextSubPkg; + < com::sun::star::deployment::XPackage > > m_aSubPkgSeq; + sal_Int32 m_nSubPkgCount; + sal_Int32 m_iNextSubPkg; com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implDetectScriptPackage( const com::sun::star::uno::Reference @@ -704,13 +737,7 @@ public: com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > getNextScriptSubPackage( bool& rbPureDialogLib ); }; -enum IteratorState -{ - USER_EXTENSIONS, - SHARED_EXTENSIONS, - BUNDLED_EXTENSIONS, - END_REACHED -}; +//============================================================================ class ScriptExtensionIterator { @@ -731,34 +758,37 @@ protected: com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implGetNextBundledScriptPackage( bool& rbPureDialogLib ); - com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext; + com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext; - IteratorState m_eState; + enum IteratorState + { + USER_EXTENSIONS, + SHARED_EXTENSIONS, + BUNDLED_EXTENSIONS, + END_REACHED + } m_eState; com::sun::star::uno::Sequence< com::sun::star::uno::Reference - < com::sun::star::deployment::XPackage > > m_aUserPackagesSeq; - bool m_bUserPackagesLoaded; + < com::sun::star::deployment::XPackage > > m_aUserPackagesSeq; + bool m_bUserPackagesLoaded; com::sun::star::uno::Sequence< com::sun::star::uno::Reference - < com::sun::star::deployment::XPackage > > m_aSharedPackagesSeq; - bool m_bSharedPackagesLoaded; + < com::sun::star::deployment::XPackage > > m_aSharedPackagesSeq; + bool m_bSharedPackagesLoaded; com::sun::star::uno::Sequence< com::sun::star::uno::Reference - < com::sun::star::deployment::XPackage > > m_aBundledPackagesSeq; - bool m_bBundledPackagesLoaded; + < com::sun::star::deployment::XPackage > > m_aBundledPackagesSeq; + bool m_bBundledPackagesLoaded; + int m_iUserPackage; + int m_iSharedPackage; + int m_iBundledPackage; - int m_iUserPackage; - int m_iSharedPackage; - int m_iBundledPackage; - - - - ScriptSubPackageIterator* m_pScriptSubPackageIterator; + ScriptSubPackageIterator* m_pScriptSubPackageIterator; }; // end class ScriptExtensionIterator - +//============================================================================ } // namespace basic diff --git a/basic/source/inc/runtime.hxx b/basic/source/inc/runtime.hxx index 46cd9d16521f..406bd487034c 100644 --- a/basic/source/inc/runtime.hxx +++ b/basic/source/inc/runtime.hxx @@ -465,6 +465,8 @@ public: SbxArray* GetLocals(); SbxArray* GetParams(); + SbiForStack* FindForStackItemForCollection( class BasicCollection* pCollection ); + SbxBase* FindElementExtern( const String& rName ); static bool isVBAEnabled(); diff --git a/basic/source/inc/sbtrace.hxx b/basic/source/inc/sbtrace.hxx index d91c7bdf16e8..6ab27050d263 100755 --- a/basic/source/inc/sbtrace.hxx +++ b/basic/source/inc/sbtrace.hxx @@ -30,6 +30,19 @@ //#define DBG_TRACE_BASIC +// ############################################################################### +// ### +// ### ATTENTION: +// ### +// ### - DBG_TRACE_PROFILING can only be activated together with DBG_TRACE_BASIC +// ### +// ### - If you activate DBG_TRACE_PROFILING you also need to uncomment line +// ### # SHL1STDLIBS+=$(CANVASTOOLSLIB) in basic/util/makefile.mk (search +// ### for DBG_TRACE_PROFILING there) +// ### +// ############################################################################### +//#define DBG_TRACE_PROFILING + #ifdef DBG_TRACE_BASIC void dbg_InitTrace( void ); void dbg_DeInitTrace( void ); diff --git a/basic/source/inc/scriptcont.hxx b/basic/source/inc/scriptcont.hxx index d788a73da0fc..9ef4c41c6ce3 100644 --- a/basic/source/inc/scriptcont.hxx +++ b/basic/source/inc/scriptcont.hxx @@ -35,11 +35,11 @@ class BasicManager; -//============================================================================ - namespace basic { +//============================================================================ + class SfxScriptLibraryContainer : public SfxLibraryContainer, public OldBasicPassword { ::rtl::OUString maScriptLanguage; @@ -140,16 +140,15 @@ public: }; //============================================================================ -typedef std::hash_map< ::rtl::OUString, ::com::sun::star::script::ModuleInfo, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > ModuleInfoMap; -typedef ::cppu::ImplHelper1 < ::com::sun::star::script::vba::XVBAModuleInfo - > SfxScriptLibrary_BASE; +typedef ::cppu::ImplHelper1< ::com::sun::star::script::vba::XVBAModuleInfo > SfxScriptLibrary_BASE; -class SfxScriptLibrary : public SfxLibrary - , public SfxScriptLibrary_BASE +class SfxScriptLibrary : public SfxLibrary, public SfxScriptLibrary_BASE { friend class SfxScriptLibraryContainer; + typedef std::hash_map< ::rtl::OUString, ::com::sun::star::script::ModuleInfo, ::rtl::OUStringHash > ModuleInfoMap; + sal_Bool mbLoadedSource; sal_Bool mbLoadedBinary; ModuleInfoMap mModuleInfos; @@ -194,7 +193,9 @@ protected: virtual bool SAL_CALL isLibraryElementValid( ::com::sun::star::uno::Any aElement ) const; }; -} // namespace base +//============================================================================ + +} // namespace basic #endif diff --git a/basic/source/inc/symtbl.hxx b/basic/source/inc/symtbl.hxx index c30445d87634..576639dc5a45 100644 --- a/basic/source/inc/symtbl.hxx +++ b/basic/source/inc/symtbl.hxx @@ -133,6 +133,7 @@ protected: sal_Bool bGlobal : 1; // sal_True: Global-Variable sal_Bool bParamArray : 1; // sal_True: ParamArray parameter sal_Bool bWithEvents : 1; // sal_True: Declared WithEvents + sal_Bool bWithBrackets : 1; // sal_True: Followed by () sal_uInt16 nDefaultId; // Symbol number of default value short nFixedStringLength; // String length in: Dim foo As String*Length public: @@ -159,6 +160,7 @@ public: void SetOptional() { bOpt = sal_True; } void SetParamArray() { bParamArray = sal_True; } void SetWithEvents() { bWithEvents = sal_True; } + void SetWithBrackets(){ bWithBrackets = sal_True; } void SetByVal( sal_Bool bByVal_ = sal_True ) { bByVal = bByVal_; } void SetStatic( sal_Bool bAsStatic = sal_True ) { bStatic = bAsStatic; } @@ -170,6 +172,7 @@ public: sal_Bool IsOptional() const{ return bOpt; } sal_Bool IsParamArray() const{ return bParamArray; } sal_Bool IsWithEvents() const{ return bWithEvents; } + sal_Bool IsWithBrackets() const{ return bWithBrackets; } sal_Bool IsByVal() const { return bByVal; } sal_Bool IsStatic() const { return bStatic; } sal_Bool IsNew() const { return bNew; } diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index 1d1f1c641547..640dd7e8bcbe 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -82,6 +82,7 @@ using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::ucb; using namespace com::sun::star::io; +using namespace com::sun::star::frame; #endif /* _USE_UNO */ @@ -96,6 +97,7 @@ using namespace com::sun::star::io; #include "iosys.hxx" #include "ddectrl.hxx" #include <sbintern.hxx> +#include <basic/vbahelper.hxx> #include <list> #include <math.h> @@ -118,6 +120,9 @@ using namespace com::sun::star::io; #include <basic/sbobjmod.hxx> +// from source/classes/sbxmod.cxx +Reference< XModel > getDocumentModel( StarBASIC* ); + static void FilterWhiteSpace( String& rStr ) { rStr.EraseAllChars( ' ' ); @@ -382,22 +387,48 @@ RTLFUNC(Asc) } } -RTLFUNC(Chr) +void implChr( SbxArray& rPar, bool bChrW ) { - (void)pBasic; - (void)bWrite; - if ( rPar.Count() < 2 ) StarBASIC::Error( SbERR_BAD_ARGUMENT ); else { SbxVariableRef pArg = rPar.Get( 1 ); - sal_Unicode aCh = (sal_Unicode)pArg->GetUShort(); - String aStr( aCh ); + + String aStr; + if( !bChrW && SbiRuntime::isVBAEnabled() ) + { + sal_Char c = (sal_Char)pArg->GetByte(); + ByteString s( c ); + aStr = String( s, gsl_getSystemTextEncoding() ); + } + else + { + sal_Unicode aCh = (sal_Unicode)pArg->GetUShort(); + aStr = String( aCh ); + } rPar.Get(0)->PutString( aStr ); } } +RTLFUNC(Chr) +{ + (void)pBasic; + (void)bWrite; + + bool bChrW = false; + implChr( rPar, bChrW ); +} + +RTLFUNC(ChrW) +{ + (void)pBasic; + (void)bWrite; + + bool bChrW = true; + implChr( rPar, bChrW ); +} + #ifdef UNX #define _MAX_PATH 260 @@ -481,7 +512,6 @@ RTLFUNC(CurDir) RTLFUNC(ChDir) // JSM { - (void)pBasic; (void)bWrite; rPar.Get(0)->PutEmpty(); @@ -504,6 +534,9 @@ RTLFUNC(ChDir) // JSM if( bError ) StarBASIC::Error( SbERR_PATH_NOT_FOUND ); #endif + // VBA: track current directory per document type (separately for Writer, Calc, Impress, etc.) + if( SbiRuntime::isVBAEnabled() ) + ::basic::vba::registerCurrentDirectory( getDocumentModel( pBasic ), rPar.Get(1)->GetString() ); } else StarBASIC::Error( SbERR_BAD_ARGUMENT ); diff --git a/basic/source/runtime/methods1.cxx b/basic/source/runtime/methods1.cxx index 2f6d18685803..20eca1f985ff 100755..100644 --- a/basic/source/runtime/methods1.cxx +++ b/basic/source/runtime/methods1.cxx @@ -1075,6 +1075,10 @@ sal_Bool lcl_ReadSbxVariable( SbxVariable& rVar, SvStream* pStrm, { sal_uInt8 aByte; *pStrm >> aByte; + + if( bBinary && SbiRuntime::isVBAEnabled() && aByte == 1 && pStrm->IsEof() ) + aByte = 0; + rVar.PutByte( aByte ); } break; @@ -1185,7 +1189,8 @@ void PutGet( SbxArray& rPar, sal_Bool bPut ) } sal_Int16 nFileNo = rPar.Get(1)->GetInteger(); SbxVariable* pVar2 = rPar.Get(2); - sal_Bool bHasRecordNo = (sal_Bool)(pVar2->GetType() != SbxEMPTY); + SbxDataType eType2 = pVar2->GetType(); + sal_Bool bHasRecordNo = (sal_Bool)(eType2 != SbxEMPTY && eType2 != SbxERROR); long nRecordNo = pVar2->GetLong(); if ( nFileNo < 1 || ( bHasRecordNo && nRecordNo < 1 ) ) { diff --git a/basic/source/runtime/rtlproto.hxx b/basic/source/runtime/rtlproto.hxx index bba1867d3591..8594382bd733 100644 --- a/basic/source/runtime/rtlproto.hxx +++ b/basic/source/runtime/rtlproto.hxx @@ -157,6 +157,7 @@ extern RTLFUNC(Abs); extern RTLFUNC(Asc); extern RTLFUNC(Atn); extern RTLFUNC(Chr); +extern RTLFUNC(ChrW); extern RTLFUNC(Cos); extern RTLFUNC(CurDir); extern RTLFUNC(ChDir); // JSM diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx index 10d25cc2292b..1a83a323931d 100644 --- a/basic/source/runtime/runtime.cxx +++ b/basic/source/runtime/runtime.cxx @@ -648,6 +648,7 @@ void SbiRuntime::SetParameters( SbxArray* pParams ) // Methoden sind immer byval! sal_Bool bByVal = v->IsA( TYPE(SbxMethod) ); SbxDataType t = v->GetType(); + bool bTargetTypeIsArray = false; if( p ) { bByVal |= sal_Bool( ( p->eType & SbxBYREF ) == 0 ); @@ -656,9 +657,13 @@ void SbiRuntime::SetParameters( SbxArray* pParams ) if( !bByVal && t != SbxVARIANT && (!v->IsFixed() || (SbxDataType)(v->GetType() & 0x0FFF ) != t) ) bByVal = sal_True; + + bTargetTypeIsArray = (p->nUserData & PARAM_INFO_WITHBRACKETS) != 0; } if( bByVal ) { + if( bTargetTypeIsArray ) + t = SbxOBJECT; SbxVariable* v2 = new SbxVariable( t ); v2->SetFlag( SBX_READWRITE ); *v2 = *v; @@ -1237,6 +1242,26 @@ void SbiRuntime::ClearForStack() PopFor(); } +SbiForStack* SbiRuntime::FindForStackItemForCollection( class BasicCollection* pCollection ) +{ + SbiForStack* pRet = NULL; + + SbiForStack* p = pForStk; + while( p ) + { + SbxVariable* pVar = p->refEnd.Is() ? (SbxVariable*)p->refEnd : NULL; + if( p->eForType == FOR_EACH_COLLECTION && pVar != NULL && + (pCollection = PTR_CAST(BasicCollection,pVar)) == pCollection ) + { + pRet = p; + break; + } + } + + return pRet; +} + + ////////////////////////////////////////////////////////////////////////// // // DLL-Aufrufe diff --git a/basic/source/runtime/stdobj.cxx b/basic/source/runtime/stdobj.cxx index 92d8152e60f4..4004b40e882c 100644 --- a/basic/source/runtime/stdobj.cxx +++ b/basic/source/runtime/stdobj.cxx @@ -128,7 +128,7 @@ static Methods aMethods[] = { { "Chr", SbxSTRING, 1 | _FUNCTION, RTLNAME(Chr),0 }, { "string", SbxINTEGER, 0,NULL,0 }, -{ "ChrW", SbxSTRING, 1 | _FUNCTION | _COMPTMASK, RTLNAME(Chr),0}, +{ "ChrW", SbxSTRING, 1 | _FUNCTION | _COMPTMASK, RTLNAME(ChrW),0}, { "string", SbxINTEGER, 0,NULL,0 }, { "CInt", SbxINTEGER, 1 | _FUNCTION, RTLNAME(CInt),0 }, diff --git a/basic/source/runtime/step0.cxx b/basic/source/runtime/step0.cxx index 43c930e975d2..462726a4c55f 100644 --- a/basic/source/runtime/step0.cxx +++ b/basic/source/runtime/step0.cxx @@ -797,6 +797,8 @@ void SbiRuntime::DimImpl( SbxVariableRef refVar ) // AB 2.4.1996, auch Arrays ohne Dimensionsangaben zulassen (VB-komp.) if( pDims ) { + refVar->ResetFlag( SBX_VAR_TO_DIM ); + for( sal_uInt16 i = 1; i < pDims->Count(); ) { sal_Int32 lb = pDims->Get( i++ )->GetLong(); diff --git a/basic/source/runtime/step1.cxx b/basic/source/runtime/step1.cxx index 0a9572906cc8..4fd91b692a4b 100644 --- a/basic/source/runtime/step1.cxx +++ b/basic/source/runtime/step1.cxx @@ -38,8 +38,7 @@ #include "sbunoobj.hxx" #include "errobject.hxx" -bool checkUnoObjectType( SbUnoObject* refVal, - const String& aClass ); +bool checkUnoObjectType( SbUnoObject* refVal, const ::rtl::OUString& aClass ); // Laden einer numerischen Konstanten (+ID) diff --git a/basic/source/runtime/step2.cxx b/basic/source/runtime/step2.cxx index bbb3668b5b69..dc8ff0a5fd50 100755 --- a/basic/source/runtime/step2.cxx +++ b/basic/source/runtime/step2.cxx @@ -624,7 +624,7 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem ) else if( bVBAEnabled ) // !pObj { SbxArray* pParam = pElem->GetParameters(); - if( pParam != NULL ) + if( pParam != NULL && !pElem->IsSet( SBX_VAR_TO_DIM ) ) Error( SbERR_NO_OBJECT ); } } @@ -1141,6 +1141,10 @@ void SbiRuntime::implHandleSbxFlags( SbxVariable* pVar, SbxDataType t, sal_uInt3 aStr.Fill( nCount, 0 ); pVar->PutString( aStr ); } + + bool bVarToDim = ((nOp2 & SBX_TYPE_VAR_TO_DIM_FLAG) != 0); + if( bVarToDim ) + pVar->SetFlag( SBX_VAR_TO_DIM ); } // Einrichten einer lokalen Variablen (+StringID+Typ) diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx index fbf1429f9753..ae110f4bcf6e 100644 --- a/basic/source/uno/namecont.cxx +++ b/basic/source/uno/namecont.cxx @@ -34,17 +34,13 @@ #include <com/sun/star/lang/XServiceInfo.hpp> #include <vcl/svapp.hxx> #include <vos/mutex.hxx> -#ifndef __RSC //autogen #include <tools/errinf.hxx> -#endif #include <osl/mutex.hxx> #include <vos/diagnose.hxx> #include <rtl/uri.hxx> #include <rtl/strbuf.hxx> #include <comphelper/processfactory.hxx> -#ifndef INCLUDED_COMPHELPER_ANYTOSTRING_HXX #include <comphelper/anytostring.hxx> -#endif #include "namecont.hxx" #include <basic/basicmanagerrepository.hxx> @@ -65,11 +61,9 @@ #include <com/sun/star/uno/DeploymentException.hpp> #include <com/sun/star/lang/DisposedException.hpp> #include <com/sun/star/script/LibraryNotLoadedException.hpp> -#include "com/sun/star/deployment/ExtensionManager.hpp" +#include <com/sun/star/script/vba/VBAScriptEventId.hpp> +#include <com/sun/star/deployment/ExtensionManager.hpp> #include <comphelper/storagehelper.hxx> -#ifndef _RTL_USTRING_HXX_ -#include <comphelper/anytostring.hxx> -#endif #include <cppuhelper/exc_hlp.hxx> #include <basic/sbmod.hxx> @@ -165,25 +159,29 @@ void NameContainer::replaceByName( const OUString& aName, const Any& aElement ) // Fire event - ContainerEvent aEvent; - aEvent.Source = mpxEventSource; - aEvent.Accessor <<= aName; - aEvent.Element = aElement; - aEvent.ReplacedElement = aOldElement; + if( maContainerListeners.getLength() > 0 ) + { + ContainerEvent aEvent; + aEvent.Source = mpxEventSource; + aEvent.Accessor <<= aName; + aEvent.Element = aElement; + aEvent.ReplacedElement = aOldElement; + maContainerListeners.notifyEach( &XContainerListener::elementReplaced, aEvent ); + } - OInterfaceIteratorHelper aIterator( maListenerContainer ); - while( aIterator.hasMoreElements() ) + /* After the container event has been fired (one listener will update the + core Basic manager), fire change event. Listeners can rely that the + Basic source code of the core Basic manager is up-to-date. */ + if( maChangesListeners.getLength() > 0 ) { - Reference< XInterface > xIface = aIterator.next(); - Reference< XContainerListener > xListener( xIface, UNO_QUERY ); - try - { - xListener->elementReplaced( aEvent ); - } - catch(RuntimeException&) - { - aIterator.remove(); - } + ChangesEvent aEvent; + aEvent.Source = mpxEventSource; + aEvent.Base <<= aEvent.Source; + aEvent.Changes.realloc( 1 ); + aEvent.Changes[ 0 ].Accessor <<= aName; + aEvent.Changes[ 0 ].Element <<= aElement; + aEvent.Changes[ 0 ].ReplacedElement = aOldElement; + maChangesListeners.notifyEach( &XChangesListener::changesOccurred, aEvent ); } } @@ -211,33 +209,35 @@ void NameContainer::insertByName( const OUString& aName, const Any& aElement ) mHashMap[ aName ] = nCount; mnElementCount++; - // Fire event - ContainerEvent aEvent; - aEvent.Source = mpxEventSource; - aEvent.Accessor <<= aName; - aEvent.Element = aElement; + if( maContainerListeners.getLength() > 0 ) + { + ContainerEvent aEvent; + aEvent.Source = mpxEventSource; + aEvent.Accessor <<= aName; + aEvent.Element = aElement; + maContainerListeners.notifyEach( &XContainerListener::elementInserted, aEvent ); + } - OInterfaceIteratorHelper aIterator( maListenerContainer ); - while( aIterator.hasMoreElements() ) + /* After the container event has been fired (one listener will update the + core Basic manager), fire change event. Listeners can rely that the + Basic source code of the core Basic manager is up-to-date. */ + if( maChangesListeners.getLength() > 0 ) { - Reference< XInterface > xIface = aIterator.next(); - Reference< XContainerListener > xListener( xIface, UNO_QUERY ); - try - { - xListener->elementInserted( aEvent ); - } - catch(RuntimeException&) - { - aIterator.remove(); - } + ChangesEvent aEvent; + aEvent.Source = mpxEventSource; + aEvent.Base <<= aEvent.Source; + aEvent.Changes.realloc( 1 ); + aEvent.Changes[ 0 ].Accessor <<= aName; + aEvent.Changes[ 0 ].Element <<= aElement; + maChangesListeners.notifyEach( &XChangesListener::changesOccurred, aEvent ); } } -void NameContainer::removeByName( const OUString& Name ) +void NameContainer::removeByName( const OUString& aName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException) { - NameContainerNameMap::iterator aIt = mHashMap.find( Name ); + NameContainerNameMap::iterator aIt = mHashMap.find( aName ); if( aIt == mHashMap.end() ) { throw NoSuchElementException(); @@ -259,26 +259,29 @@ void NameContainer::removeByName( const OUString& Name ) mValues.realloc( iLast ); mnElementCount--; - // Fire event - ContainerEvent aEvent; - aEvent.Source = mpxEventSource; - aEvent.Accessor <<= Name; - aEvent.Element = aOldElement; + if( maContainerListeners.getLength() > 0 ) + { + ContainerEvent aEvent; + aEvent.Source = mpxEventSource; + aEvent.Accessor <<= aName; + aEvent.Element = aOldElement; + maContainerListeners.notifyEach( &XContainerListener::elementRemoved, aEvent ); + } - OInterfaceIteratorHelper aIterator( maListenerContainer ); - while( aIterator.hasMoreElements() ) + /* After the container event has been fired (one listener will update the + core Basic manager), fire change event. Listeners can rely that the + Basic source code of the core Basic manager is up-to-date. */ + if( maChangesListeners.getLength() > 0 ) { - Reference< XInterface > xIface = aIterator.next(); - Reference< XContainerListener > xListener( xIface, UNO_QUERY ); - try - { - xListener->elementRemoved( aEvent ); - } - catch(RuntimeException&) - { - aIterator.remove(); - } + ChangesEvent aEvent; + aEvent.Source = mpxEventSource; + aEvent.Base <<= aEvent.Source; + aEvent.Changes.realloc( 1 ); + aEvent.Changes[ 0 ].Accessor <<= aName; + // aEvent.Changes[ 0 ].Element remains empty (meaning "replaced with nothing") + aEvent.Changes[ 0 ].ReplacedElement = aOldElement; + maChangesListeners.notifyEach( &XChangesListener::changesOccurred, aEvent ); } } @@ -290,7 +293,7 @@ void SAL_CALL NameContainer::addContainerListener( const Reference< XContainerLi if( !xListener.is() ) throw RuntimeException(); Reference< XInterface > xIface( xListener, UNO_QUERY ); - maListenerContainer.addInterface( xIface ); + maContainerListeners.addInterface( xIface ); } void SAL_CALL NameContainer::removeContainerListener( const Reference< XContainerListener >& xListener ) @@ -299,7 +302,26 @@ void SAL_CALL NameContainer::removeContainerListener( const Reference< XContaine if( !xListener.is() ) throw RuntimeException(); Reference< XInterface > xIface( xListener, UNO_QUERY ); - maListenerContainer.removeInterface( xIface ); + maContainerListeners.removeInterface( xIface ); +} + +// Methods XChangesNotifier +void SAL_CALL NameContainer::addChangesListener( const Reference< XChangesListener >& xListener ) + throw (RuntimeException) +{ + if( !xListener.is() ) + throw RuntimeException(); + Reference< XInterface > xIface( xListener, UNO_QUERY ); + maChangesListeners.addInterface( xIface ); +} + +void SAL_CALL NameContainer::removeChangesListener( const Reference< XChangesListener >& xListener ) + throw (RuntimeException) +{ + if( !xListener.is() ) + throw RuntimeException(); + Reference< XInterface > xIface( xListener, UNO_QUERY ); + maChangesListeners.removeInterface( xIface ); } //============================================================================ @@ -320,12 +342,28 @@ void ModifiableHelper::setModified( sal_Bool _bModified ) //============================================================================ +VBAScriptListenerContainer::VBAScriptListenerContainer( ::osl::Mutex& rMutex ) : + VBAScriptListenerContainer_BASE( rMutex ) +{ +} + +bool VBAScriptListenerContainer::implTypedNotify( const Reference< vba::XVBAScriptListener >& rxListener, const vba::VBAScriptEvent& rEvent ) throw (Exception) +{ + rxListener->notifyVBAScriptEvent( rEvent ); + return true; // notify all other listeners too +} + +//============================================================================ + // Implementation class SfxLibraryContainer DBG_NAME( SfxLibraryContainer ) // Ctor SfxLibraryContainer::SfxLibraryContainer( void ) - : LibraryContainerHelper( maMutex ) + : SfxLibraryContainer_BASE( maMutex ) + + , maVBAScriptListeners( maMutex ) + , mnRunningVBAScripts( 0 ) , mbVBACompat( sal_False ) , maModifiable( *this, maMutex ) , maNameContainer( getCppuType( (Reference< XNameAccess >*) NULL ) ) @@ -2649,6 +2687,9 @@ void SfxLibraryContainer::_disposing( const EventObject& _rSource ) // OComponentHelper void SAL_CALL SfxLibraryContainer::disposing() { + Reference< XModel > xModel = mxOwnerDocument; + EventObject aEvent( xModel.get() ); + maVBAScriptListeners.disposing( aEvent ); stopAllComponentListening(); mxOwnerDocument = WeakReference< XModel >(); } @@ -2838,7 +2879,7 @@ void SAL_CALL SfxLibraryContainer::setVBACompatibilityMode( ::sal_Bool _vbacompa */ if( mbVBACompat ) try { - Reference< frame::XModel > xModel( mxOwnerDocument ); // weak-ref -> ref + Reference< XModel > xModel( mxOwnerDocument ); // weak-ref -> ref Reference< XMultiServiceFactory > xFactory( xModel, UNO_QUERY_THROW ); xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAGlobals" ) ) ); } @@ -2848,6 +2889,43 @@ void SAL_CALL SfxLibraryContainer::setVBACompatibilityMode( ::sal_Bool _vbacompa } } +sal_Int32 SAL_CALL SfxLibraryContainer::getRunningVBAScripts() throw (RuntimeException) +{ + LibraryContainerMethodGuard aGuard( *this ); + return mnRunningVBAScripts; +} + +void SAL_CALL SfxLibraryContainer::addVBAScriptListener( const Reference< vba::XVBAScriptListener >& rxListener ) throw (RuntimeException) +{ + maVBAScriptListeners.addTypedListener( rxListener ); +} + +void SAL_CALL SfxLibraryContainer::removeVBAScriptListener( const Reference< vba::XVBAScriptListener >& rxListener ) throw (RuntimeException) +{ + maVBAScriptListeners.removeTypedListener( rxListener ); +} + +void SAL_CALL SfxLibraryContainer::broadcastVBAScriptEvent( sal_Int32 nIdentifier, const ::rtl::OUString& rModuleName ) throw (RuntimeException) +{ + // own lock for accessing the number of running scripts + enterMethod(); + switch( nIdentifier ) + { + case vba::VBAScriptEventId::SCRIPT_STARTED: + ++mnRunningVBAScripts; + break; + case vba::VBAScriptEventId::SCRIPT_STOPPED: + --mnRunningVBAScripts; + break; + } + leaveMethod(); + + Reference< XModel > xModel = mxOwnerDocument; // weak-ref -> ref + Reference< XInterface > xSender( xModel, UNO_QUERY_THROW ); + vba::VBAScriptEvent aEvent( xSender, nIdentifier, rModuleName ); + maVBAScriptListeners.notify( aEvent ); +} + // Methods XServiceInfo ::sal_Bool SAL_CALL SfxLibraryContainer::supportsService( const ::rtl::OUString& _rServiceName ) throw (RuntimeException) @@ -2941,7 +3019,9 @@ Any SAL_CALL SfxLibrary::queryInterface( const Type& rType ) aRet = Any( ::cppu::queryInterface( rType, static_cast< XContainer * >( this ), static_cast< XNameContainer * >( this ), - static_cast< XNameAccess * >( this ) ) ); + static_cast< XNameAccess * >( this ), + static_cast< XElementAccess * >( this ), + static_cast< XChangesNotifier * >( this ) ) ); //} if( !aRet.hasValue() ) aRet = OComponentHelper::queryInterface( rType ); @@ -3083,6 +3163,7 @@ Sequence< Type > SfxLibrary::getTypes() static OTypeCollection s_aTypes_NameContainer( ::getCppuType( (const Reference< XNameContainer > *)0 ), ::getCppuType( (const Reference< XContainer > *)0 ), + ::getCppuType( (const Reference< XChangesNotifier > *)0 ), OComponentHelper::getTypes() ); s_pTypes_NameContainer = &s_aTypes_NameContainer; } @@ -3110,9 +3191,6 @@ Sequence< sal_Int8 > SfxLibrary::getImplementationId() } } - -//============================================================================ - // Methods XContainer void SAL_CALL SfxLibrary::addContainerListener( const Reference< XContainerListener >& xListener ) throw (RuntimeException) @@ -3127,6 +3205,19 @@ void SAL_CALL SfxLibrary::removeContainerListener( const Reference< XContainerLi maNameContainer.removeContainerListener( xListener ); } +// Methods XChangesNotifier +void SAL_CALL SfxLibrary::addChangesListener( const Reference< XChangesListener >& xListener ) + throw (RuntimeException) +{ + maNameContainer.setEventSource( static_cast< XInterface* >( (OWeakObject*)this ) ); + maNameContainer.addChangesListener( xListener ); +} + +void SAL_CALL SfxLibrary::removeChangesListener( const Reference< XChangesListener >& xListener ) + throw (RuntimeException) +{ + maNameContainer.removeChangesListener( xListener ); +} //============================================================================ // Implementation class ScriptExtensionIterator diff --git a/basic/util/makefile.mk b/basic/util/makefile.mk index 31a4dcca8f8b..ae4456cbc923 100644 --- a/basic/util/makefile.mk +++ b/basic/util/makefile.mk @@ -66,6 +66,9 @@ SHL1STDLIBS= \ $(VOSLIB) \ $(XMLSCRIPTLIB) +# Uncomment the following line if DBG_TRACE_PROFILING is active in source/inc/sbtrace.hxx +# SHL1STDLIBS+=$(CANVASTOOLSLIB) + .IF "$(SOLAR_JAVA)" != "TRUE" SHL1STDLIBS+=$(SJLIB) .ENDIF diff --git a/comphelper/inc/comphelper/servicedecl.hxx b/comphelper/inc/comphelper/servicedecl.hxx index 5ea7972e29a2..a7d51824f7c0 100644 --- a/comphelper/inc/comphelper/servicedecl.hxx +++ b/comphelper/inc/comphelper/servicedecl.hxx @@ -27,26 +27,17 @@ #if ! defined(COMPHELPER_SERVICEDECL_HXX_INCLUDED) #define COMPHELPER_SERVICEDECL_HXX_INCLUDED -#if ! defined(INCLUDED_COMPHELPERDLLAPI_H) -#include "comphelper/comphelperdllapi.h" -#endif -#if ! defined(_CPPUHELPER_IMPLBASE1_HXX_) -#include "cppuhelper/implbase1.hxx" -#endif -#if ! defined(_COM_SUN_STAR_UNO_XCOMPONENTCONTEXT_HPP_) -#include "com/sun/star/uno/XComponentContext.hpp" -#endif -#if ! defined(_COM_SUN_STAR_LANG_XSERVICEINFO_HPP_) -#include "com/sun/star/lang/XServiceInfo.hpp" -#endif -#if ! defined(_COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_) -#include "com/sun/star/registry/XRegistryKey.hpp" -#endif -#include "boost/utility.hpp" -#include "boost/function.hpp" -#include "boost/preprocessor/cat.hpp" -#include "boost/preprocessor/repetition.hpp" -#include "boost/preprocessor/seq/enum.hpp" +#include <comphelper/comphelperdllapi.h> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/registry/XRegistryKey.hpp> +#include <uno/environment.h> +#include <boost/utility.hpp> +#include <boost/function.hpp> +#include <boost/preprocessor/cat.hpp> +#include <boost/preprocessor/repetition.hpp> +#include <boost/preprocessor/seq/enum.hpp> namespace comphelper { namespace service_decl { diff --git a/comphelper/inc/comphelper/storagehelper.hxx b/comphelper/inc/comphelper/storagehelper.hxx index 9d44b42e9514..92a2411d6441 100644 --- a/comphelper/inc/comphelper/storagehelper.hxx +++ b/comphelper/inc/comphelper/storagehelper.hxx @@ -44,6 +44,7 @@ #define ZIP_STORAGE_FORMAT_STRING ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ZipFormat" ) ) #define OFOPXML_STORAGE_FORMAT_STRING ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OFOPXMLFormat" ) ) +#define PACKAGE_ENCRYPTIONDATA_SHA256UTF8 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA256UTF8EncryptionKey" ) ) #define PACKAGE_ENCRYPTIONDATA_SHA1UTF8 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA1UTF8EncryptionKey" ) ) #define PACKAGE_ENCRYPTIONDATA_SHA1MS1252 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA1MS1252EncryptionKey" ) ) @@ -164,7 +165,10 @@ public: throw ( ::com::sun::star::uno::Exception ); static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > - CreatePackageEncryptionData( const ::rtl::OUString& aPassword ); + CreatePackageEncryptionData( + const ::rtl::OUString& aPassword, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSF + = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ); static sal_Bool IsValidZipEntryFileName( const ::rtl::OUString& aName, sal_Bool bSlashAllowed ); static sal_Bool IsValidZipEntryFileName( const sal_Unicode *pChar, sal_Int32 nLength, sal_Bool bSlashAllowed ); diff --git a/comphelper/source/misc/storagehelper.cxx b/comphelper/source/misc/storagehelper.cxx index 60ffa965fcf1..9b4e7a15cfca 100644 --- a/comphelper/source/misc/storagehelper.cxx +++ b/comphelper/source/misc/storagehelper.cxx @@ -34,6 +34,9 @@ #include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/beans/IllegalTypeException.hpp> +#include <com/sun/star/xml/crypto/XDigestContext.hpp> +#include <com/sun/star/xml/crypto/XDigestContextSupplier.hpp> +#include <com/sun/star/xml/crypto/DigestID.hpp> #include <rtl/digest.h> @@ -422,18 +425,42 @@ uno::Reference< embed::XStorage > OStorageHelper::GetStorageOfFormatFromStream( } // ---------------------------------------------------------------------- -uno::Sequence< beans::NamedValue > OStorageHelper::CreatePackageEncryptionData( const ::rtl::OUString& aPassword ) +uno::Sequence< beans::NamedValue > OStorageHelper::CreatePackageEncryptionData( const ::rtl::OUString& aPassword, const uno::Reference< lang::XMultiServiceFactory >& xSF ) { // TODO/LATER: Should not the method be part of DocPasswordHelper? uno::Sequence< beans::NamedValue > aEncryptionData; + sal_Int32 nSha1Ind = 0; if ( aPassword.getLength() ) { + // generate SHA256 start key + try + { + uno::Reference< lang::XMultiServiceFactory > xFactory = xSF.is() ? xSF : ::comphelper::getProcessServiceFactory(); + if ( !xFactory.is() ) + throw uno::RuntimeException(); + + uno::Reference< xml::crypto::XDigestContextSupplier > xDigestContextSupplier( xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.crypto.NSSInitializer" ) ) ), uno::UNO_QUERY_THROW ); + uno::Reference< xml::crypto::XDigestContext > xDigestContext( xDigestContextSupplier->getDigestContext( xml::crypto::DigestID::SHA256, uno::Sequence< beans::NamedValue >() ), uno::UNO_SET_THROW ); + + ::rtl::OString aUTF8Password( ::rtl::OUStringToOString( aPassword, RTL_TEXTENCODING_UTF8 ) ); + xDigestContext->updateDigest( uno::Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aUTF8Password.getStr() ), aUTF8Password.getLength() ) ); + uno::Sequence< sal_Int8 > aDigest = xDigestContext->finalizeDigestAndDispose(); + + aEncryptionData.realloc( ++nSha1Ind ); + aEncryptionData[0].Name = PACKAGE_ENCRYPTIONDATA_SHA256UTF8; + aEncryptionData[0].Value <<= aDigest; + } + catch ( uno::Exception& ) + { + OSL_ENSURE( false, "Can not create SHA256 digest!" ); + } + // MS_1252 encoding was used for SO60 document format password encoding, // this encoding supports only a minor subset of nonascii characters, // but for compatibility reasons it has to be used for old document formats - aEncryptionData.realloc( 2 ); - aEncryptionData[0].Name = PACKAGE_ENCRYPTIONDATA_SHA1UTF8; - aEncryptionData[1].Name = PACKAGE_ENCRYPTIONDATA_SHA1MS1252; + aEncryptionData.realloc( nSha1Ind + 2 ); + aEncryptionData[nSha1Ind].Name = PACKAGE_ENCRYPTIONDATA_SHA1UTF8; + aEncryptionData[nSha1Ind + 1].Name = PACKAGE_ENCRYPTIONDATA_SHA1MS1252; rtl_TextEncoding pEncoding[2] = { RTL_TEXTENCODING_UTF8, RTL_TEXTENCODING_MS_1252 }; @@ -449,11 +476,11 @@ uno::Sequence< beans::NamedValue > OStorageHelper::CreatePackageEncryptionData( if ( nError != rtl_Digest_E_None ) { - aEncryptionData.realloc( 0 ); + aEncryptionData.realloc( nSha1Ind ); break; } - aEncryptionData[nInd].Value <<= uno::Sequence< sal_Int8 >( (sal_Int8*)pBuffer, RTL_DIGEST_LENGTH_SHA1 ); + aEncryptionData[nSha1Ind+nInd].Value <<= uno::Sequence< sal_Int8 >( (sal_Int8*)pBuffer, RTL_DIGEST_LENGTH_SHA1 ); } } diff --git a/configure.in b/configure.in index 99f2d63cc307..10dcbb3cba17 100644 --- a/configure.in +++ b/configure.in @@ -3042,16 +3042,18 @@ _ACEOF if test "$JDK" != "gcj" -o "$_gij_longver" -ge "40200"; then # check if JAVA_HOME was (maybe incorrectly?) set automatically to /usr if test "$JAVA_HOME" = "/usr" -a "x$with_jdk_home" = "x"; then - - if basename $(readlink $(readlink $JAVACOMPILER)) >/dev/null 2>/dev/null; then + javac_link_f=`readlink -f "$JAVACOMPILER" 2>/dev/null` + if test $? == 0 && test "$JAVACOMPILER" != "$javac_link_f"; then # try to recover first by looking whether we have a alternatives # system as in Debian or newer SuSEs where following /usr/bin/javac # over /etc/alternatives/javac leads to the right bindir where we # just need to strip a bit away to get a valid JAVA_HOME - JAVA_HOME=$(readlink $(readlink $JAVACOMPILER)) + # Solaris 11 is even worse, because target is relative, so use -f + JAVA_HOME="$javac_link_f" elif readlink $JAVACOMPILER >/dev/null 2>/dev/null; then - # maybe only one level of symlink (e.g. on Mac) - JAVA_HOME=$(readlink $JAVACOMPILER) + # Darwin readlink(1) is so primitive it doesn't even support -f + # maybe only one level of symlink (e.g. on Mac) + JAVA_HOME=`readlink $JAVACOMPILER` else # else warn AC_MSG_WARN([JAVA_HOME is set to /usr - this is very likely to be incorrect]) @@ -5475,7 +5477,12 @@ fi dnl We also need to check for --with-gnu-cp if test -z "$with_gnu_cp"; then - AC_PATH_PROGS(GNUCP, gnucp cp) + # check the place where the good stuff is hidden on Solaris... + if test -x /usr/gnu/bin/cp; then + GNUCP=/usr/gnu/bin/cp + else + AC_PATH_PROGS(GNUCP, gnucp cp) + fi if test -z $GNUCP; then AC_MSG_ERROR([Neither gnucp nor cp found. Install GNU cp and/or specify --with-gnu-cp=/path/to/it]) fi @@ -5754,6 +5761,7 @@ if test "$test_gtk" = "yes"; then if test "$ENABLE_GTK" = "TRUE" ; then PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.4 gdk-pixbuf-xlib-2.0 >= 2.2 ,,AC_MSG_ERROR([requirements to build the gtk-plugin not met. Use --disable-gtk or install the missing packages])) + PKG_CHECK_MODULES(GTHREAD, gthread-2.0,,AC_MSG_ERROR([requirements to build the gtk-plugin not met. Use --disable-gtk or install the missing packages])) BUILD_TYPE="$BUILD_TYPE GTK" if test "x$enable_systray" = "xyes"; then @@ -5790,6 +5798,8 @@ AC_SUBST(ENABLE_DBUS) AC_SUBST(ENABLE_SYSTRAY_GTK) AC_SUBST(GTK_CFLAGS) AC_SUBST(GTK_LIBS) +AC_SUBST(GTHREAD_CFLAGS) +AC_SUBST(GTHREAD_LIBS) dnl =================================================================== dnl Check whether the GStreamer libraries are available. @@ -7013,7 +7023,11 @@ if test "$ANT_HOME" != "NO_ANT_HOME"; then if test -f $ANT_HOME/lib/ant/ant.jar; then ANT_LIB="$ANT_HOME/lib/ant" else - AC_MSG_ERROR([Ant libraries not found!]) + if test -f /usr/share/lib/ant/ant.jar; then + ANT_LIB=/usr/share/lib/ant + else + AC_MSG_ERROR([Ant libraries not found!]) + fi fi fi fi @@ -7100,7 +7114,11 @@ if test "$SOLAR_JAVA" != "" && test "$with_junit" != "no"; then if test -e /usr/share/java/junit4.jar; then OOO_JUNIT_JAR=/usr/share/java/junit4.jar else - OOO_JUNIT_JAR=/usr/share/java/junit.jar + if test -e /usr/share/lib/java/junit.jar; then + OOO_JUNIT_JAR=/usr/share/lib/java/junit.jar + else + OOO_JUNIT_JAR=/usr/share/java/junit.jar + fi fi else OOO_JUNIT_JAR=$with_junit diff --git a/desktop/source/deployment/dp_services.cxx b/desktop/source/deployment/dp_services.cxx index f3dc75ae39c5..c302d1d1cc42 100644 --- a/desktop/source/deployment/dp_services.cxx +++ b/desktop/source/deployment/dp_services.cxx @@ -84,8 +84,6 @@ bool singleton_entries( uno::Reference<registry::XRegistryKey> const& ); extern "C" { -struct uno_Environment; - void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName, uno_Environment ** ) { diff --git a/filter/inc/filter/msfilter/msvbahelper.hxx b/filter/inc/filter/msfilter/msvbahelper.hxx index 94ece293ee20..05c9f0b122ed 100644 --- a/filter/inc/filter/msfilter/msvbahelper.hxx +++ b/filter/inc/filter/msfilter/msvbahelper.hxx @@ -50,6 +50,8 @@ struct MSFILTER_DLLPUBLIC MacroResolvedInfo MSFILTER_DLLPUBLIC String makeMacroURL( const String& sMacroName ); MSFILTER_DLLPUBLIC ::rtl::OUString extractMacroName( const ::rtl::OUString& rMacroUrl ); +MSFILTER_DLLPUBLIC ::rtl::OUString getDefaultProjectName( SfxObjectShell* pShell ); +MSFILTER_DLLPUBLIC ::rtl::OUString resolveVBAMacro( SfxObjectShell* pShell, const ::rtl::OUString& rLibName, const ::rtl::OUString& rModuleName, const ::rtl::OUString& rMacroName ); MSFILTER_DLLPUBLIC MacroResolvedInfo resolveVBAMacro( SfxObjectShell* pShell, const ::rtl::OUString& rMacroName, bool bSearchGlobalTemplates = false ); MSFILTER_DLLPUBLIC sal_Bool executeMacro( SfxObjectShell* pShell, const String& sMacroName, com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArgs, com::sun::star::uno::Any& aRet, const com::sun::star::uno::Any& aCaller ); diff --git a/filter/source/msfilter/msvbahelper.cxx b/filter/source/msfilter/msvbahelper.cxx index 02fa3d60e248..415007c46aea 100644 --- a/filter/source/msfilter/msvbahelper.cxx +++ b/filter/source/msfilter/msvbahelper.cxx @@ -37,6 +37,7 @@ #include <com/sun/star/document/XDocumentProperties.hpp> #include <com/sun/star/document/XDocumentInfoSupplier.hpp> #include <com/sun/star/lang/XUnoTunnel.hpp> +#include <com/sun/star/script/ModuleType.hpp> #include <tools/urlobj.hxx> #include <osl/file.hxx> #include <unotools/pathoptions.hxx> @@ -170,6 +171,7 @@ SfxObjectShell* findShellForUrl( const rtl::OUString& sMacroURLOrPath ) // sMod can be empty ( but we really need the library to search in ) // if sMod is empty and a macro is found then sMod is updated +// if sMod is empty, only standard modules will be searched (no class, document, form modules) bool hasMacro( SfxObjectShell* pShell, const String& sLibrary, String& sMod, const String& sMacro ) { bool bFound = false; @@ -209,8 +211,12 @@ bool hasMacro( SfxObjectShell* pShell, const String& sLibrary, String& sMod, con { if( SbModule* pModule = pMethod->GetModule() ) { - sMod = pModule->GetName(); - bFound = true; + // when searching for a macro without module name, do not search in class/document/form modules + if( pModule->GetModuleType() == script::ModuleType::NORMAL ) + { + sMod = pModule->GetName(); + bFound = true; + } } } } @@ -218,6 +224,19 @@ bool hasMacro( SfxObjectShell* pShell, const String& sLibrary, String& sMod, con } return bFound; } + +::rtl::OUString getDefaultProjectName( SfxObjectShell* pShell ) +{ + ::rtl::OUString aPrjName; + if( BasicManager* pBasicMgr = pShell ? pShell->GetBasicManager() : 0 ) + { + aPrjName = pBasicMgr->GetName(); + if( aPrjName.getLength() == 0 ) + aPrjName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) ); + } + return aPrjName; +} + void parseMacro( const rtl::OUString& sMacro, String& sContainer, String& sModule, String& sProcedure ) { sal_Int32 nMacroDot = sMacro.lastIndexOf( '.' ); @@ -239,6 +258,18 @@ void parseMacro( const rtl::OUString& sMacro, String& sContainer, String& sModul sProcedure = sMacro; } +::rtl::OUString resolveVBAMacro( SfxObjectShell* pShell, const ::rtl::OUString& rLibName, const ::rtl::OUString& rModuleName, const ::rtl::OUString& rMacroName ) +{ + if( pShell ) + { + ::rtl::OUString aLibName = (rLibName.getLength() > 0) ? rLibName : getDefaultProjectName( pShell ); + String aModuleName = rModuleName; + if( hasMacro( pShell, aLibName, aModuleName, rMacroName ) ) + return ::rtl::OUStringBuffer( aLibName ).append( sal_Unicode( '.' ) ).append( aModuleName ).append( sal_Unicode( '.' ) ).append( rMacroName ).makeStringAndClear(); + } + return ::rtl::OUString(); +} + MacroResolvedInfo resolveVBAMacro( SfxObjectShell* pShell, const rtl::OUString& MacroName, bool bSearchGlobalTemplates ) { if( !pShell ) @@ -282,18 +313,27 @@ MacroResolvedInfo resolveVBAMacro( SfxObjectShell* pShell, const rtl::OUString& // macro format = Container.Module.Procedure String sContainer, sModule, sProcedure; parseMacro( aMacroName, sContainer, sModule, sProcedure ); - uno::Reference< container::XNameContainer > xPrjNameCache; +#if 0 // As long as service VBAProjectNameProvider isn't supported in the model, disable the createInstance call // (the ServiceNotRegisteredException is wrongly caught in ScModelObj::createInstance) - //uno::Reference< lang::XMultiServiceFactory> xSF( pShell->GetModel(), uno::UNO_QUERY); - //if ( xSF.is() ) - // xPrjNameCache.set( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAProjectNameProvider" ) ) ), uno::UNO_QUERY ); + uno::Reference< container::XNameContainer > xPrjNameCache; + uno::Reference< lang::XMultiServiceFactory> xSF( pShell->GetModel(), uno::UNO_QUERY); + if ( xSF.is() ) try + { + xPrjNameCache.set( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAProjectNameProvider" ) ) ), uno::UNO_QUERY ); + } + catch( uno::Exception& ) // createInstance may throw + { + } +#endif std::vector< rtl::OUString > sSearchList; if ( sContainer.Len() > 0 ) { +// service VBAProjectNameProvider not implemented +#if 0 // get the Project associated with the Container if ( xPrjNameCache.is() ) { @@ -304,22 +344,18 @@ MacroResolvedInfo resolveVBAMacro( SfxObjectShell* pShell, const rtl::OUString& sContainer = sProject; } } +#endif sSearchList.push_back( sContainer ); // First Lib to search } else { // Ok, if we have no Container specified then we need to search them in order, this document, template this document created from, global templates, // get the name of Project/Library for 'this' document - rtl::OUString sThisProject; - BasicManager* pBasicMgr = pShell-> GetBasicManager(); - if ( pBasicMgr ) - { - if ( pBasicMgr->GetName().Len() ) - sThisProject = pBasicMgr->GetName(); - else // cater for the case where VBA is not enabled - sThisProject = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Standard") ); - } + rtl::OUString sThisProject = getDefaultProjectName( pShell ); sSearchList.push_back( sThisProject ); // First Lib to search + +// service VBAProjectNameProvider not implemented +#if 0 if ( xPrjNameCache.is() ) { // is this document created from a template? @@ -376,7 +412,9 @@ MacroResolvedInfo resolveVBAMacro( SfxObjectShell* pShell, const rtl::OUString& } } +#endif } + std::vector< rtl::OUString >::iterator it_end = sSearchList.end(); for ( std::vector< rtl::OUString >::iterator it = sSearchList.begin(); !aRes.mbFound && (it != it_end); ++it ) { diff --git a/framework/Library_fwe.mk b/framework/Library_fwe.mk index 5d30d108cde6..408a514c2f06 100644 --- a/framework/Library_fwe.mk +++ b/framework/Library_fwe.mk @@ -83,8 +83,6 @@ $(eval $(call gb_Library_add_exception_objects,fwe,\ framework/source/fwe/interaction/preventduplicateinteraction \ framework/source/fwe/xml/eventsconfiguration \ framework/source/fwe/xml/eventsdocumenthandler \ - framework/source/fwe/xml/imagesconfiguration \ - framework/source/fwe/xml/imagesdocumenthandler \ framework/source/fwe/xml/menuconfiguration \ framework/source/fwe/xml/menudocumenthandler \ framework/source/fwe/xml/saxnamespacefilter \ diff --git a/framework/Library_fwk.mk b/framework/Library_fwk.mk index a34a1bc59720..3953d129afc2 100644 --- a/framework/Library_fwk.mk +++ b/framework/Library_fwk.mk @@ -183,6 +183,8 @@ $(eval $(call gb_Library_add_exception_objects,fwk,\ framework/source/uifactory/windowcontentfactorymanager \ framework/source/xml/acceleratorconfigurationreader \ framework/source/xml/acceleratorconfigurationwriter \ + framework/source/xml/imagesconfiguration \ + framework/source/xml/imagesdocumenthandler \ )) # vim: set noet sw=4 ts=4: diff --git a/framework/Package_inc.mk b/framework/Package_inc.mk index 6d1c03a5975b..d72dd52128b8 100644 --- a/framework/Package_inc.mk +++ b/framework/Package_inc.mk @@ -39,7 +39,6 @@ $(eval $(call gb_Package_add_file,framework_inc,inc/framework/undomanagerhelper. $(eval $(call gb_Package_add_file,framework_inc,inc/framework/imutex.hxx,framework/imutex.hxx)) $(eval $(call gb_Package_add_file,framework_inc,inc/framework/iguard.hxx,framework/iguard.hxx)) $(eval $(call gb_Package_add_file,framework_inc,inc/framework/imageproducer.hxx,framework/imageproducer.hxx)) -$(eval $(call gb_Package_add_file,framework_inc,inc/framework/imagesconfiguration.hxx,framework/imagesconfiguration.hxx)) $(eval $(call gb_Package_add_file,framework_inc,inc/framework/interaction.hxx,framework/interaction.hxx)) $(eval $(call gb_Package_add_file,framework_inc,inc/framework/menuconfiguration.hxx,framework/menuconfiguration.hxx)) $(eval $(call gb_Package_add_file,framework_inc,inc/framework/menuextensionsupplier.hxx,framework/menuextensionsupplier.hxx)) diff --git a/framework/inc/framework/imagesconfiguration.hxx b/framework/inc/xml/imagesconfiguration.hxx index 0771e2d8f7f1..3174e6d51b22 100644 --- a/framework/inc/framework/imagesconfiguration.hxx +++ b/framework/inc/xml/imagesconfiguration.hxx @@ -25,8 +25,8 @@ * ************************************************************************/ -#ifndef __FRAMEWORK_XML_IMAGESCONFIGURATION_HXX_ -#define __FRAMEWORK_XML_IMAGESCONFIGURATION_HXX_ +#ifndef FRAMEWORK_XML_IMAGESCONFIGURATION_HXX_ +#define FRAMEWORK_XML_IMAGESCONFIGURATION_HXX_ #include <framework/fwedllapi.h> #include <svl/svarray.hxx> @@ -50,7 +50,7 @@ enum ImageMaskMode ImageMaskMode_Bitmap }; -struct FWE_DLLPUBLIC ImageItemDescriptor +struct ImageItemDescriptor { ImageItemDescriptor() : nIndex( -1 ) {} @@ -58,7 +58,7 @@ struct FWE_DLLPUBLIC ImageItemDescriptor long nIndex; // index of the bitmap inside the bitmaplist }; -struct FWE_DLLPUBLIC ExternalImageItemDescriptor +struct ExternalImageItemDescriptor { String aCommandURL; // URL command to dispatch String aURL; // a URL to an external bitmap @@ -70,7 +70,7 @@ SV_DECL_PTRARR_DEL( ImageItemListDescriptor, ImageItemDescriptorPtr, 10, 2) typedef ExternalImageItemDescriptor* ExternalImageItemDescriptorPtr; SV_DECL_PTRARR_DEL( ExternalImageItemListDescriptor, ExternalImageItemDescriptorPtr, 10, 2) -struct FWE_DLLPUBLIC ImageListItemDescriptor +struct ImageListItemDescriptor { ImageListItemDescriptor() : nMaskMode( ImageMaskMode_Color ), pImageItemList( 0 ) {} @@ -89,7 +89,7 @@ struct FWE_DLLPUBLIC ImageListItemDescriptor typedef ImageListItemDescriptor* ImageListItemDescriptorPtr; SV_DECL_PTRARR_DEL( ImageListDescriptor, ImageListItemDescriptorPtr, 10, 2) -struct FWE_DLLPUBLIC ImageListsDescriptor +struct ImageListsDescriptor { ImageListsDescriptor() : pImageList( 0 ), pExternalImageList( 0 ) {} @@ -99,7 +99,7 @@ struct FWE_DLLPUBLIC ImageListsDescriptor ExternalImageItemListDescriptor* pExternalImageList; }; -class FWE_DLLPUBLIC ImagesConfiguration +class ImagesConfiguration { public: // #110897# diff --git a/framework/inc/xml/imagesdocumenthandler.hxx b/framework/inc/xml/imagesdocumenthandler.hxx index 59d1e4abdb3a..dd6201b5b9e3 100644 --- a/framework/inc/xml/imagesdocumenthandler.hxx +++ b/framework/inc/xml/imagesdocumenthandler.hxx @@ -25,8 +25,8 @@ * ************************************************************************/ -#ifndef __FRAMEWORK_XML_IMAGEDOCUMENTHANDLER_HXX_ -#define __FRAMEWORK_XML_IMAGEDOCUMENTHANDLER_HXX_ +#ifndef FRAMEWORK_XML_IMAGEDOCUMENTHANDLER_HXX_ +#define FRAMEWORK_XML_IMAGEDOCUMENTHANDLER_HXX_ #include <framework/fwedllapi.h> @@ -34,14 +34,12 @@ // interface includes //_________________________________________________________________________________________________________________ -#ifndef __COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HPP_ #include <com/sun/star/xml/sax/XDocumentHandler.hpp> -#endif //_________________________________________________________________________________________________________________ // other includes //_________________________________________________________________________________________________________________ -#include <framework/imagesconfiguration.hxx> +#include <xml/imagesconfiguration.hxx> #include <threadhelp/threadhelpbase.hxx> #include <rtl/ustring.hxx> #include <cppuhelper/implbase1.hxx> @@ -59,7 +57,7 @@ namespace framework{ //***************************************************************************************************************** // Hash code function for using in all hash maps of follow implementation. -class FWE_DLLPUBLIC OReadImagesDocumentHandler : private ThreadHelpBase, // Struct for right initalization of lock member! Must be first of baseclasses. +class OReadImagesDocumentHandler : private ThreadHelpBase, // Struct for right initalization of lock member! Must be first of baseclasses. public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XDocumentHandler > { public: @@ -160,7 +158,7 @@ class FWE_DLLPUBLIC OReadImagesDocumentHandler : private ThreadHelpBase, // S ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > m_xLocator; }; -class FWE_DLLPUBLIC OWriteImagesDocumentHandler : private ThreadHelpBase // Struct for right initalization of lock member! Must be first of baseclasses. +class OWriteImagesDocumentHandler : private ThreadHelpBase // Struct for right initalization of lock member! Must be first of baseclasses. { public: OWriteImagesDocumentHandler( diff --git a/framework/source/uiconfiguration/imagemanager.cxx b/framework/source/uiconfiguration/imagemanager.cxx index 2a57e72e1ce4..776af9982de4 100644 --- a/framework/source/uiconfiguration/imagemanager.cxx +++ b/framework/source/uiconfiguration/imagemanager.cxx @@ -27,9 +27,10 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_framework.hxx" + #include <uiconfiguration/imagemanager.hxx> #include <threadhelp/resetableguard.hxx> -#include <framework/imagesconfiguration.hxx> +#include <xml/imagesconfiguration.hxx> #include <uiconfiguration/graphicnameaccess.hxx> #include <services.h> #include "imagemanagerimpl.hxx" diff --git a/framework/source/uiconfiguration/imagemanagerimpl.cxx b/framework/source/uiconfiguration/imagemanagerimpl.cxx index 537fe623d633..d0caee82297e 100755 --- a/framework/source/uiconfiguration/imagemanagerimpl.cxx +++ b/framework/source/uiconfiguration/imagemanagerimpl.cxx @@ -27,9 +27,10 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_framework.hxx" + #include <imagemanagerimpl.hxx> #include <threadhelp/resetableguard.hxx> -#include <framework/imagesconfiguration.hxx> +#include <xml/imagesconfiguration.hxx> #include <uiconfiguration/graphicnameaccess.hxx> #include <services.h> diff --git a/framework/source/uiconfiguration/moduleimagemanager.cxx b/framework/source/uiconfiguration/moduleimagemanager.cxx index fc90dd102912..0e0f828a253f 100644 --- a/framework/source/uiconfiguration/moduleimagemanager.cxx +++ b/framework/source/uiconfiguration/moduleimagemanager.cxx @@ -27,10 +27,11 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_framework.hxx" + #include <rtl/logfile.hxx> #include <uiconfiguration/moduleimagemanager.hxx> #include <threadhelp/resetableguard.hxx> -#include <framework/imagesconfiguration.hxx> +#include <xml/imagesconfiguration.hxx> #include <uiconfiguration/graphicnameaccess.hxx> #include <services.h> #include "imagemanagerimpl.hxx" diff --git a/framework/source/uielement/menubarmanager.cxx b/framework/source/uielement/menubarmanager.cxx index fd8e0d3fbcd7..9df04fa17ab4 100644 --- a/framework/source/uielement/menubarmanager.cxx +++ b/framework/source/uielement/menubarmanager.cxx @@ -134,16 +134,20 @@ static const char ITEM_DESCRIPTOR_LABEL[] = "Label"; static const char ITEM_DESCRIPTOR_TYPE[] = "Type"; static const char ITEM_DESCRIPTOR_MODULEIDENTIFIER[] = "ModuleIdentifier"; static const char ITEM_DESCRIPTOR_DISPATCHPROVIDER[] = "DispatchProvider"; -static const char ITEM_DESCRIPTOR_STYLE[] = "Style"; - -const sal_Int32 LEN_DESCRIPTOR_COMMANDURL = 10; -const sal_Int32 LEN_DESCRIPTOR_HELPURL = 7; -const sal_Int32 LEN_DESCRIPTOR_CONTAINER = 23; -const sal_Int32 LEN_DESCRIPTOR_LABEL = 5; -const sal_Int32 LEN_DESCRIPTOR_TYPE = 4; -const sal_Int32 LEN_DESCRIPTOR_MODULEIDENTIFIER = 16; -const sal_Int32 LEN_DESCRIPTOR_DISPATCHPROVIDER = 16; -static const sal_Int32 ITEM_DESCRIPTOR_STYLE_LEN = 5; +static const char ITEM_DESCRIPTOR_STYLE[] = "Style"; +static const char ITEM_DESCRIPTOR_ISVISIBLE[] = "IsVisible"; +static const char ITEM_DESCRIPTOR_ENABLED[] = "Enabled"; + +static const sal_Int32 LEN_DESCRIPTOR_COMMANDURL = 10; +static const sal_Int32 LEN_DESCRIPTOR_HELPURL = 7; +static const sal_Int32 LEN_DESCRIPTOR_CONTAINER = 23; +static const sal_Int32 LEN_DESCRIPTOR_LABEL = 5; +static const sal_Int32 LEN_DESCRIPTOR_TYPE = 4; +static const sal_Int32 LEN_DESCRIPTOR_MODULEIDENTIFIER = 16; +static const sal_Int32 LEN_DESCRIPTOR_DISPATCHPROVIDER = 16; +static const sal_Int32 LEN_DESCRIPTOR_STYLE = 5; +static const sal_Int32 LEN_DESCRIPTOR_ISVISIBLE = 9; +static const sal_Int32 LEN_DESCRIPTOR_ENABLED = 7; const sal_uInt16 ADDONMENU_MERGE_ITEMID_START = 1500; @@ -1757,6 +1761,8 @@ void MenuBarManager::FillMenu( rtl::OUString aLabel; rtl::OUString aHelpURL; rtl::OUString aModuleIdentifier( rModuleIdentifier ); + sal_Bool bShow(sal_True); + sal_Bool bEnabled(sal_True); sal_uInt16 nType = 0; Reference< XIndexAccess > xIndexContainer; Reference< XDispatchProvider > xDispatchProvider( rDispatchProvider ); @@ -1768,29 +1774,26 @@ void MenuBarManager::FillMenu( for ( int i = 0; i < aProp.getLength(); i++ ) { rtl::OUString aPropName = aProp[i].Name; - if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_COMMANDURL, - LEN_DESCRIPTOR_COMMANDURL )) + if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_COMMANDURL, LEN_DESCRIPTOR_COMMANDURL )) aProp[i].Value >>= aCommandURL; - else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_HELPURL, - LEN_DESCRIPTOR_HELPURL )) + else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_HELPURL, LEN_DESCRIPTOR_HELPURL )) aProp[i].Value >>= aHelpURL; - else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_CONTAINER, - LEN_DESCRIPTOR_CONTAINER )) + else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_CONTAINER, LEN_DESCRIPTOR_CONTAINER )) aProp[i].Value >>= xIndexContainer; - else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_LABEL, - LEN_DESCRIPTOR_LABEL )) + else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_LABEL, LEN_DESCRIPTOR_LABEL )) aProp[i].Value >>= aLabel; - else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_TYPE, - LEN_DESCRIPTOR_TYPE )) + else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_TYPE, LEN_DESCRIPTOR_TYPE )) aProp[i].Value >>= nType; - else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_MODULEIDENTIFIER, - LEN_DESCRIPTOR_MODULEIDENTIFIER )) + else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_MODULEIDENTIFIER, LEN_DESCRIPTOR_MODULEIDENTIFIER )) aProp[i].Value >>= aModuleIdentifier; - else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_DISPATCHPROVIDER, - LEN_DESCRIPTOR_DISPATCHPROVIDER )) + else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_DISPATCHPROVIDER, LEN_DESCRIPTOR_DISPATCHPROVIDER )) aProp[i].Value >>= xDispatchProvider; - else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_STYLE, ITEM_DESCRIPTOR_STYLE_LEN )) + else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_STYLE, LEN_DESCRIPTOR_STYLE )) aProp[i].Value >>= nStyle; + else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_ISVISIBLE, LEN_DESCRIPTOR_ISVISIBLE )) + aProp[i].Value >>= bShow; + else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_ENABLED, LEN_DESCRIPTOR_ENABLED )) + aProp[i].Value >>= bEnabled; } if ( nType == ::com::sun::star::ui::ItemType::DEFAULT ) @@ -1809,6 +1812,13 @@ void MenuBarManager::FillMenu( nBits |= MIB_RADIOCHECK; pMenu->SetItemBits( nId, nBits ); } + + if ( !bShow ) + pMenu->HideItem( nId ); + + if ( !bEnabled) + pMenu->EnableItem( nId, sal_False ); + if ( xIndexContainer.is() ) { PopupMenu* pNewPopupMenu = new PopupMenu; diff --git a/framework/source/fwe/xml/imagesconfiguration.cxx b/framework/source/xml/imagesconfiguration.cxx index d561a76d5995..946b5b9d0f11 100644 --- a/framework/source/fwe/xml/imagesconfiguration.cxx +++ b/framework/source/xml/imagesconfiguration.cxx @@ -27,12 +27,11 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_framework.hxx" -#include <framework/imagesconfiguration.hxx> + +#include <xml/imagesconfiguration.hxx> #include <services.h> -#ifndef __FRAMEWORK_CLASSES_IMAGESDOCUMENTHANDLER_HXX_ #include <xml/imagesdocumenthandler.hxx> -#endif #include <xml/saxnamespacefilter.hxx> //_________________________________________________________________________________________________________________ diff --git a/framework/source/fwe/xml/imagesdocumenthandler.cxx b/framework/source/xml/imagesdocumenthandler.cxx index cdf20958332a..cdf20958332a 100644 --- a/framework/source/fwe/xml/imagesdocumenthandler.cxx +++ b/framework/source/xml/imagesdocumenthandler.cxx diff --git a/gdk-pixbuf/gdk-pixbuf-2.23.0-win32.patch b/gdk-pixbuf/gdk-pixbuf-2.23.0-win32.patch index 2677ef0ca1c7..3c56febbad6b 100644 --- a/gdk-pixbuf/gdk-pixbuf-2.23.0-win32.patch +++ b/gdk-pixbuf/gdk-pixbuf-2.23.0-win32.patch @@ -197,7 +197,7 @@ @@ -1,9 +1,19 @@ -TOP = ..\.. PRJ_TOP = .. -+GLIB_TOP = $(PRJ_TOP)\..\..\..\..\..\glib\wntmsci12.pro\misc\build\glib-2.28.1 ++GLIB_TOP = PACKAGE = gdk_pixbuf PKG_VER = $(GDK_PIXBUF_VER) +GLIB_INC = -I$(OUTDIR)\inc\external\glib-2.0 @@ -212,7 +212,7 @@ +GDIPLUS_LIB = gdiplus.lib -!INCLUDE $(TOP)/glib/build/win32/make.msc -+!INCLUDE $(GLIB_TOP)\build\win32\make.msc ++!INCLUDE $(OUTDIR)\inc\external\glib-2.0\make.msc !IFNDEF PERL PERL = perl @@ -270,11 +270,11 @@ gdk-pixbuf-marshal.h: gdk-pixbuf-marshal.list - ..\..\glib\gobject\glib-genmarshal --prefix=_gdk_pixbuf_marshal gdk-pixbuf-marshal.list --header >gdk-pixbuf-marshal.h -+ $(GLIB_TOP)\glib\gobject\glib-genmarshal --prefix=_gdk_pixbuf_marshal gdk-pixbuf-marshal.list --header >gdk-pixbuf-marshal.h ++ $(OUTDIR)\bin\glib-genmarshal --prefix=_gdk_pixbuf_marshal gdk-pixbuf-marshal.list --header >gdk-pixbuf-marshal.h gdk-pixbuf-marshal.c: gdk-pixbuf-marshal.h gdk-pixbuf-marshal.list - ..\..\glib\gobject\glib-genmarshal --prefix=_gdk_pixbuf_marshal gdk-pixbuf-marshal.list --body >gdk-pixbuf-marshal.c -+ $(GLIB_TOP)\glib\gobject\glib-genmarshal --prefix=_gdk_pixbuf_marshal gdk-pixbuf-marshal.list --body >gdk-pixbuf-marshal.c ++ $(OUTDIR)\bin\glib-genmarshal --prefix=_gdk_pixbuf_marshal gdk-pixbuf-marshal.list --body >gdk-pixbuf-marshal.c -gdk-pixbuf-alias.h: gdk-pixbuf.symbols - perl makegdkpixbufalias.pl < gdk-pixbuf.symbols > gdk-pixbuf-alias.h @@ -333,7 +333,7 @@ # gdk-pixbuf-enum-types.h : $(gdk_pixbuf_headers) makefile.msc - $(PERL) $(GLIB)\gobject\glib-mkenums \ -+ $(PERL) $(PRJ_TOP)\glib-mkenums.pl \ ++ $(PERL) $(OUTDIR)\bin\glib-mkenums \ --fhead "#ifndef __GDK_PIXBUF__ENUM_TYPES_H__\n#define __GDK_PIXBUF_ENUM_TYPES_H__\n" \ --fprod "/* enumerations from \"@filename@\" */\n" \ --vhead "GType @enum_name@_get_type (void);\n#define GDK_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n" \ @@ -343,7 +343,7 @@ gdk-pixbuf-enum-types.c: $(gdk_pixbuf_headers) makefile.msc - $(PERL) $(GLIB)\gobject\glib-mkenums \ - --fhead "#include <gdk-pixbuf/gdk-pixbuf.h>" \ -+ $(PERL) $(PRJ_TOP)\glib-mkenums.pl \ ++ $(PERL) $(OUTDIR)\bin\glib-mkenums \ + --fhead "#include <gdk-pixbuf.h>" \ --fprod "\n/* enumerations from \"@filename@\" */" \ --vhead "GType\n@enum_name@_get_type (void)\n{\n static GType etype = 0;\n if (etype == 0) {\n static const G@Type@Value values[] = {" \ @@ -370,11 +370,11 @@ -PACKAGE = pixops PRJ_TOP = ..\.. +PACKAGE = pixops -+GLIB_TOP = $(PRJ_TOP)\..\..\..\..\..\glib\wntmsci12.pro\misc\build\glib-2.28.1 ++GLIB_TOP = +GLIB_INC = -I$(OUTDIR)\inc\external\glib-2.0 -!INCLUDE $(TOP)/glib/build/win32/make.msc -+!INCLUDE $(GLIB_TOP)\build\win32\make.msc ++!INCLUDE $(OUTDIR)\inc\external\glib-2.0\make.msc -PKG_CFLAGS = -I.. $(GLIB_CFLAGS) +PKG_CFLAGS = -I.. $(SOLARINC) $(GLIB_INC) $(GLIB_CFLAGS) @@ -422,548 +422,6 @@ #include "pixops.h" #include "pixops-internal.h" ---- misc/gdk-pixbuf-2.23.0/glib-mkenums.pl 2011-03-24 04:59:07.281250000 +0100 -+++ misc/build/gdk-pixbuf-2.23.0/glib-mkenums.pl 2011-03-22 01:58:24.343750000 +0100 -@@ -1 +1,538 @@ --dummy -+#! perl.exe -+ -+use warnings; -+use File::Basename; -+use Safe; -+ -+# glib-mkenums.pl -+# Information about the current enumeration -+my $flags; # Is enumeration a bitmask? -+my $option_underscore_name; # Overriden underscore variant of the enum name -+ # for example to fix the cases we don't get the -+ # mixed-case -> underscorized transform right. -+my $option_lowercase_name; # DEPRECATED. A lower case name to use as part -+ # of the *_get_type() function, instead of the -+ # one that we guess. For instance, when an enum -+ # uses abnormal capitalization and we can not -+ # guess where to put the underscores. -+my $seenbitshift; # Have we seen bitshift operators? -+my $enum_prefix; # Prefix for this enumeration -+my $enumname; # Name for this enumeration -+my $enumshort; # $enumname without prefix -+my $enumname_prefix; # prefix of $enumname -+my $enumindex = 0; # Global enum counter -+my $firstenum = 1; # Is this the first enumeration per file? -+my @entries; # [ $name, $val ] for each entry -+my $sandbox = Safe->new; # sandbox for safe evaluation of expressions -+ -+sub parse_trigraph { -+ my $opts = shift; -+ my @opts; -+ -+ for $opt (split /\s*,\s*/, $opts) { -+ $opt =~ s/^\s*//; -+ $opt =~ s/\s*$//; -+ my ($key,$val) = $opt =~ /(\w+)(?:=(.+))?/; -+ defined $val or $val = 1; -+ push @opts, $key, $val; -+ } -+ @opts; -+} -+sub parse_entries { -+ my $file = shift; -+ my $file_name = shift; -+ my $looking_for_name = 0; -+ -+ while (<$file>) { -+ # read lines until we have no open comments -+ while (m@/\*([^*]|\*(?!/))*$@) { -+ my $new; -+ defined ($new = <$file>) || die "Unmatched comment in $ARGV"; -+ $_ .= $new; -+ } -+ # strip comments w/o options -+ s@/\*(?!<) -+ ([^*]+|\*(?!/))* -+ \*/@@gx; -+ -+ # strip newlines -+ s@\n@ @; -+ -+ # skip empty lines -+ next if m@^\s*$@; -+ -+ if ($looking_for_name) { -+ if (/^\s*(\w+)/) { -+ $enumname = $1; -+ return 1; -+ } -+ } -+ -+ # Handle include files -+ if (/^\#include\s*<([^>]*)>/ ) { -+ my $file= "../$1"; -+ open NEWFILE, $file or die "Cannot open include file $file: $!\n"; -+ -+ if (parse_entries (\*NEWFILE, $NEWFILE)) { -+ return 1; -+ } else { -+ next; -+ } -+ } -+ -+ if (/^\s*\}\s*(\w+)/) { -+ $enumname = $1; -+ $enumindex++; -+ return 1; -+ } -+ -+ if (/^\s*\}/) { -+ $enumindex++; -+ $looking_for_name = 1; -+ next; -+ } -+ -+ if (m@^\s* -+ (\w+)\s* # name -+ (?:=( # value -+ \s*\w+\s*\(.*\)\s* # macro with multiple args -+ | # OR -+ (?:[^,/]|/(?!\*))* # anything but a comma or comment -+ ))?,?\s* -+ (?:/\*< # options -+ (([^*]|\*(?!/))*) -+ >\s*\*/)?,? -+ \s*$ -+ @x) { -+ my ($name, $value, $options) = ($1,$2,$3); -+ -+ if (!defined $flags && defined $value && $value =~ /<</) { -+ $seenbitshift = 1; -+ } -+ -+ if (defined $options) { -+ my %options = parse_trigraph($options); -+ if (!defined $options{skip}) { -+ push @entries, [ $name, $value, $options{nick} ]; -+ } -+ } else { -+ push @entries, [ $name, $value ]; -+ } -+ } elsif (m@^\s*\#@) { -+ # ignore preprocessor directives -+ } else { -+ print STDERR "$0: $file_name:$.: Failed to parse `$_'\n"; -+ } -+ } -+ -+ return 0; -+} -+ -+sub version { -+ print "glib-mkenums version glib-@GLIB_VERSION@\n"; -+ print "glib-mkenums comes with ABSOLUTELY NO WARRANTY.\n"; -+ print "You may redistribute copies of glib-mkenums under the terms of\n"; -+ print "the GNU General Public License which can be found in the\n"; -+ print "GLib source package. Sources, examples and contact\n"; -+ print "information are available at http://www.gtk.org\n"; -+ exit 0; -+} -+sub usage { -+ print "Usage:\n"; -+ print " glib-mkenums [OPTION...] [FILES...]\n\n"; -+ print "Help Options:\n"; -+ print " -h, --help Show this help message\n\n"; -+ print "Utility Options:\n"; -+ print " --fhead <text> Output file header\n"; -+ print " --fprod <text> Per input file production\n"; -+ print " --ftail <text> Output file trailer\n"; -+ print " --eprod <text> Per enum text (produced prior to value itarations)\n"; -+ print " --vhead <text> Value header, produced before iterating over enum values\n"; -+ print " --vprod <text> Value text, produced for each enum value\n"; -+ print " --vtail <text> Value tail, produced after iterating over enum values\n"; -+ print " --comments <text> Comment structure\n"; -+ print " --template file Template file\n"; -+ print " -v, --version Print version informations\n\n"; -+ print "Production text substitutions:\n"; -+ print " \@EnumName\@ PrefixTheXEnum\n"; -+ print " \@enum_name\@ prefix_the_xenum\n"; -+ print " \@ENUMNAME\@ PREFIX_THE_XENUM\n"; -+ print " \@ENUMSHORT\@ THE_XENUM\n"; -+ print " \@ENUMPREFIX\@ PREFIX\n"; -+ print " \@VALUENAME\@ PREFIX_THE_XVALUE\n"; -+ print " \@valuenick\@ the-xvalue\n"; -+ print " \@valuenum\@ the integer value (limited support, Since: 2.26)\n"; -+ print " \@type\@ either enum or flags\n"; -+ print " \@Type\@ either Enum or Flags\n"; -+ print " \@TYPE\@ either ENUM or FLAGS\n"; -+ print " \@filename\@ name of current input file\n"; -+ print " \@basename\@ base name of the current input file (Since: 2.22)\n"; -+ exit 0; -+} -+ -+# production variables: -+my $fhead = ""; # output file header -+my $fprod = ""; # per input file production -+my $ftail = ""; # output file trailer -+my $eprod = ""; # per enum text (produced prior to value itarations) -+my $vhead = ""; # value header, produced before iterating over enum values -+my $vprod = ""; # value text, produced for each enum value -+my $vtail = ""; # value tail, produced after iterating over enum values -+my $comment_tmpl = ""; # comment template -+ -+sub read_template_file { -+ my ($file) = @_; -+ my %tmpl = ('file-header', $fhead, -+ 'file-production', $fprod, -+ 'file-tail', $ftail, -+ 'enumeration-production', $eprod, -+ 'value-header', $vhead, -+ 'value-production', $vprod, -+ 'value-tail', $vtail, -+ 'comment', $comment_tmpl); -+ my $in = 'junk'; -+ open (FILE, $file) || die "Can't open $file: $!\n"; -+ while (<FILE>) { -+ if (/^\/\*\*\*\s+(BEGIN|END)\s+([\w-]+)\s+\*\*\*\//) { -+ if (($in eq 'junk') && ($1 eq 'BEGIN') && (exists($tmpl{$2}))) { -+ $in = $2; -+ next; -+ } -+ elsif (($in eq $2) && ($1 eq 'END') && (exists($tmpl{$2}))) { -+ $in = 'junk'; -+ next; -+ } else { -+ die "Malformed template file $file\n"; -+ } -+ } -+ if (!($in eq 'junk')) { -+ $tmpl{$in} .= $_; -+ } -+ } -+ close (FILE); -+ if (!($in eq 'junk')) { -+ die "Malformed template file $file\n"; -+ } -+ $fhead = $tmpl{'file-header'}; -+ $fprod = $tmpl{'file-production'}; -+ $ftail = $tmpl{'file-tail'}; -+ $eprod = $tmpl{'enumeration-production'}; -+ $vhead = $tmpl{'value-header'}; -+ $vprod = $tmpl{'value-production'}; -+ $vtail = $tmpl{'value-tail'}; -+ $comment_tmpl = $tmpl{'comment'}; -+ -+ # default to C-style comments -+ $comment_tmpl = "/* \@comment\@ */" if $comment_tmpl eq ""; -+} -+ -+if (!defined $ARGV[0]) { -+ usage; -+} -+while ($_=$ARGV[0],/^-/) { -+ shift; -+ last if /^--$/; -+ if (/^--template$/) { read_template_file (shift); } -+ elsif (/^--fhead$/) { $fhead = $fhead . shift } -+ elsif (/^--fprod$/) { $fprod = $fprod . shift } -+ elsif (/^--ftail$/) { $ftail = $ftail . shift } -+ elsif (/^--eprod$/) { $eprod = $eprod . shift } -+ elsif (/^--vhead$/) { $vhead = $vhead . shift } -+ elsif (/^--vprod$/) { $vprod = $vprod . shift } -+ elsif (/^--vtail$/) { $vtail = $vtail . shift } -+ elsif (/^--comments$/) { $comment_tmpl = shift } -+ elsif (/^--help$/ || /^-h$/ || /^-\?$/) { usage; } -+ elsif (/^--version$/ || /^-v$/) { version; } -+ else { usage; } -+ last if not defined($ARGV[0]); -+} -+ -+# put auto-generation comment -+{ -+ my $comment = $comment_tmpl; -+ $comment =~ s/\@comment\@/Generated data (by glib-mkenums)/; -+ print "\n" . $comment . "\n\n"; -+} -+ -+if (length($fhead)) { -+ my $prod = $fhead; -+ my $base = basename ($ARGV[0]); -+ -+ $prod =~ s/\@filename\@/$ARGV[0]/g; -+ $prod =~ s/\@basename\@/$base/g; -+ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; -+ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; -+ chomp ($prod); -+ -+ print "$prod\n"; -+} -+ -+while (<>) { -+ if (eof) { -+ close (ARGV); # reset line numbering -+ $firstenum = 1; # Flag to print filename at next enum -+ } -+ -+ # read lines until we have no open comments -+ while (m@/\*([^*]|\*(?!/))*$@) { -+ my $new; -+ defined ($new = <>) || die "Unmatched comment in $ARGV"; -+ $_ .= $new; -+ } -+ # strip comments w/o options -+ s@/\*(?!<) -+ ([^*]+|\*(?!/))* -+ \*/@@gx; -+ -+ if (m@^\s*typedef\s+enum\s* -+ ({)?\s* -+ (?:/\*< -+ (([^*]|\*(?!/))*) -+ >\s*\*/)? -+ \s*({)? -+ @x) { -+ if (defined $2) { -+ my %options = parse_trigraph ($2); -+ next if defined $options{skip}; -+ $enum_prefix = $options{prefix}; -+ $flags = $options{flags}; -+ $option_lowercase_name = $options{lowercase_name}; -+ $option_underscore_name = $options{underscore_name}; -+ } else { -+ $enum_prefix = undef; -+ $flags = undef; -+ $option_lowercase_name = undef; -+ $option_underscore_name = undef; -+ } -+ if (defined $option_lowercase_name) { -+ if (defined $option_underscore_name) { -+ print STDERR "$0: $ARGV:$.: lowercase_name overriden with underscore_name\n"; -+ $option_lowercase_name = undef; -+ } else { -+ print STDERR "$0: $ARGV:$.: lowercase_name is deprecated, use underscore_name\n"; -+ } -+ } -+ # Didn't have trailing '{' look on next lines -+ if (!defined $1 && !defined $4) { -+ while (<>) { -+ if (s/^\s*\{//) { -+ last; -+ } -+ } -+ } -+ -+ $seenbitshift = 0; -+ @entries = (); -+ -+ # Now parse the entries -+ parse_entries (\*ARGV, $ARGV); -+ -+ # figure out if this was a flags or enums enumeration -+ if (!defined $flags) { -+ $flags = $seenbitshift; -+ } -+ -+ # Autogenerate a prefix -+ if (!defined $enum_prefix) { -+ for (@entries) { -+ my $nick = $_->[2]; -+ if (!defined $nick) { -+ my $name = $_->[0]; -+ if (defined $enum_prefix) { -+ my $tmp = ~ ($name ^ $enum_prefix); -+ ($tmp) = $tmp =~ /(^\xff*)/; -+ $enum_prefix = $enum_prefix & $tmp; -+ } else { -+ $enum_prefix = $name; -+ } -+ } -+ } -+ if (!defined $enum_prefix) { -+ $enum_prefix = ""; -+ } else { -+ # Trim so that it ends in an underscore -+ $enum_prefix =~ s/_[^_]*$/_/; -+ } -+ } else { -+ # canonicalize user defined prefixes -+ $enum_prefix = uc($enum_prefix); -+ $enum_prefix =~ s/-/_/g; -+ $enum_prefix =~ s/(.*)([^_])$/$1$2_/; -+ } -+ -+ for $entry (@entries) { -+ my ($name,$num,$nick) = @{$entry}; -+ if (!defined $nick) { -+ ($nick = $name) =~ s/^$enum_prefix//; -+ $nick =~ tr/_/-/; -+ $nick = lc($nick); -+ @{$entry} = ($name, $num, $nick); -+ } -+ } -+ -+ -+ # Spit out the output -+ if (defined $option_underscore_name) { -+ $enumlong = uc $option_underscore_name; -+ $enumsym = lc $option_underscore_name; -+ $enumshort = $enumlong; -+ $enumshort =~ s/^[A-Z][A-Z0-9]*_//; -+ -+ $enumname_prefix = $enumlong; -+ $enumname_prefix =~ s/$enumshort$//; -+ } else { -+ # enumname is e.g. GMatchType -+ $enspace = $enumname; -+ $enspace =~ s/^([A-Z][a-z]*).*$/$1/; -+ -+ $enumshort = $enumname; -+ $enumshort =~ s/^[A-Z][a-z]*//; -+ $enumshort =~ s/([^A-Z])([A-Z])/$1_$2/g; -+ $enumshort =~ s/([A-Z][A-Z])([A-Z][0-9a-z])/$1_$2/g; -+ $enumshort = uc($enumshort); -+ -+ $enumname_prefix = $enumname; -+ $enumname_prefix =~ s/^([A-Z][a-z]*).*$/$1/; -+ $enumname_prefix = uc($enumname_prefix); -+ -+ $enumlong = uc($enspace) . "_" . $enumshort; -+ $enumsym = lc($enspace) . "_" . lc($enumshort); -+ -+ if (defined($option_lowercase_name)) { -+ $enumsym = $option_lowercase_name; -+ } -+ } -+ -+ if ($firstenum) { -+ $firstenum = 0; -+ -+ if (length($fprod)) { -+ my $prod = $fprod; -+ my $base = basename ($ARGV); -+ -+ $prod =~ s/\@filename\@/$ARGV/g; -+ $prod =~ s/\@basename\@/$base/g; -+ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; -+ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; -+ chomp ($prod); -+ -+ print "$prod\n"; -+ } -+ } -+ -+ if (length($eprod)) { -+ my $prod = $eprod; -+ -+ $prod =~ s/\@enum_name\@/$enumsym/g; -+ $prod =~ s/\@EnumName\@/$enumname/g; -+ $prod =~ s/\@ENUMSHORT\@/$enumshort/g; -+ $prod =~ s/\@ENUMNAME\@/$enumlong/g; -+ $prod =~ s/\@ENUMPREFIX\@/$enumname_prefix/g; -+ if ($flags) { $prod =~ s/\@type\@/flags/g; } else { $prod =~ s/\@type\@/enum/g; } -+ if ($flags) { $prod =~ s/\@Type\@/Flags/g; } else { $prod =~ s/\@Type\@/Enum/g; } -+ if ($flags) { $prod =~ s/\@TYPE\@/FLAGS/g; } else { $prod =~ s/\@TYPE\@/ENUM/g; } -+ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; -+ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; -+ chomp ($prod); -+ -+ print "$prod\n"; -+ } -+ -+ if (length($vhead)) { -+ my $prod = $vhead; -+ -+ $prod =~ s/\@enum_name\@/$enumsym/g; -+ $prod =~ s/\@EnumName\@/$enumname/g; -+ $prod =~ s/\@ENUMSHORT\@/$enumshort/g; -+ $prod =~ s/\@ENUMNAME\@/$enumlong/g; -+ $prod =~ s/\@ENUMPREFIX\@/$enumname_prefix/g; -+ if ($flags) { $prod =~ s/\@type\@/flags/g; } else { $prod =~ s/\@type\@/enum/g; } -+ if ($flags) { $prod =~ s/\@Type\@/Flags/g; } else { $prod =~ s/\@Type\@/Enum/g; } -+ if ($flags) { $prod =~ s/\@TYPE\@/FLAGS/g; } else { $prod =~ s/\@TYPE\@/ENUM/g; } -+ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; -+ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; -+ chomp ($prod); -+ -+ print "$prod\n"; -+ } -+ -+ if (length($vprod)) { -+ my $prod = $vprod; -+ my $next_num = 0; -+ -+ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; -+ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; -+ for (@entries) { -+ my ($name,$num,$nick) = @{$_}; -+ my $tmp_prod = $prod; -+ -+ if ($prod =~ /\@valuenum\@/) { -+ # only attempt to eval the value if it is requested -+ # this prevents us from throwing errors otherwise -+ if (defined $num) { -+ # use sandboxed perl evaluation as a reasonable -+ # approximation to C constant folding -+ $num = $sandbox->reval ($num); -+ -+ # make sure it parsed to an integer -+ if (!defined $num or $num !~ /^-?\d+$/) { -+ die "Unable to parse enum value '$num'"; -+ } -+ } else { -+ $num = $next_num; -+ } -+ -+ $tmp_prod =~ s/\@valuenum\@/$num/g; -+ $next_num = $num + 1; -+ } -+ -+ $tmp_prod =~ s/\@VALUENAME\@/$name/g; -+ $tmp_prod =~ s/\@valuenick\@/$nick/g; -+ if ($flags) { $tmp_prod =~ s/\@type\@/flags/g; } else { $tmp_prod =~ s/\@type\@/enum/g; } -+ if ($flags) { $tmp_prod =~ s/\@Type\@/Flags/g; } else { $tmp_prod =~ s/\@Type\@/Enum/g; } -+ if ($flags) { $tmp_prod =~ s/\@TYPE\@/FLAGS/g; } else { $tmp_prod =~ s/\@TYPE\@/ENUM/g; } -+ chomp ($tmp_prod); -+ -+ print "$tmp_prod\n"; -+ } -+ } -+ -+ if (length($vtail)) { -+ my $prod = $vtail; -+ -+ $prod =~ s/\@enum_name\@/$enumsym/g; -+ $prod =~ s/\@EnumName\@/$enumname/g; -+ $prod =~ s/\@ENUMSHORT\@/$enumshort/g; -+ $prod =~ s/\@ENUMNAME\@/$enumlong/g; -+ $prod =~ s/\@ENUMPREFIX\@/$enumname_prefix/g; -+ if ($flags) { $prod =~ s/\@type\@/flags/g; } else { $prod =~ s/\@type\@/enum/g; } -+ if ($flags) { $prod =~ s/\@Type\@/Flags/g; } else { $prod =~ s/\@Type\@/Enum/g; } -+ if ($flags) { $prod =~ s/\@TYPE\@/FLAGS/g; } else { $prod =~ s/\@TYPE\@/ENUM/g; } -+ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; -+ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; -+ chomp ($prod); -+ -+ print "$prod\n"; -+ } -+ } -+} -+ -+if (length($ftail)) { -+ my $prod = $ftail; -+ my $base = basename ($ARGV); -+ -+ $prod =~ s/\@filename\@/$ARGV/g; -+ $prod =~ s/\@basename\@/$base/g; -+ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; -+ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; -+ chomp ($prod); -+ -+ print "$prod\n"; -+} -+ -+# put auto-generation comment -+{ -+ my $comment = $comment_tmpl; -+ $comment =~ s/\@comment\@/Generated data ends here/; -+ print "\n" . $comment . "\n\n"; -+} --- misc/gdk-pixbuf-2.23.0/msvc_recommended_pragmas.h 2011-03-24 04:59:07.625000000 +0100 +++ misc/build/gdk-pixbuf-2.23.0/msvc_recommended_pragmas.h 2011-03-22 01:58:24.359375000 +0100 @@ -1 +1,31 @@ diff --git a/glib/glib-2.28.1-win32-2.patch b/glib/glib-2.28.1-win32-2.patch new file mode 100644 index 000000000000..ee4b868f6b1a --- /dev/null +++ b/glib/glib-2.28.1-win32-2.patch @@ -0,0 +1,553 @@ +--- misc/glib-2.28.1/build/win32/make.msc 2011-04-01 16:52:15.676157900 +0200 ++++ misc/build/glib-2.28.1/build/win32/make.msc 2011-04-01 16:52:02.168385300 +0200 +@@ -55,7 +55,7 @@ + BABL_LIBS = $(BABL)\babl\babl-1.0.lib + + # force inclusion of the _right_ cairoversion.h even when using without installation +-CAIRO_CFLAGS = -FI $(CAIRO)\cairo-version.h -I $(CAIRO)\src -I $(CAIRO) ++CAIRO_CFLAGS = -I $(CAIRO)\src -I $(CAIRO) + CAIRO_LIBS = $(CAIRO)\src\libcairo.lib + + DIRENT_CFLAGS = -I ..\build\win32\dirent +--- misc/glib-2.28.1/gobject/glib-mkenums 2011-04-01 16:52:15.155128100 +0200 ++++ misc/build/glib-2.28.1/gobject/glib-mkenums 2011-04-01 16:51:30.994602300 +0200 +@@ -1 +1,538 @@ +-dummy ++#! perl.exe ++ ++use warnings; ++use File::Basename; ++use Safe; ++ ++# glib-mkenums.pl ++# Information about the current enumeration ++my $flags; # Is enumeration a bitmask? ++my $option_underscore_name; # Overriden underscore variant of the enum name ++ # for example to fix the cases we don't get the ++ # mixed-case -> underscorized transform right. ++my $option_lowercase_name; # DEPRECATED. A lower case name to use as part ++ # of the *_get_type() function, instead of the ++ # one that we guess. For instance, when an enum ++ # uses abnormal capitalization and we can not ++ # guess where to put the underscores. ++my $seenbitshift; # Have we seen bitshift operators? ++my $enum_prefix; # Prefix for this enumeration ++my $enumname; # Name for this enumeration ++my $enumshort; # $enumname without prefix ++my $enumname_prefix; # prefix of $enumname ++my $enumindex = 0; # Global enum counter ++my $firstenum = 1; # Is this the first enumeration per file? ++my @entries; # [ $name, $val ] for each entry ++my $sandbox = Safe->new; # sandbox for safe evaluation of expressions ++ ++sub parse_trigraph { ++ my $opts = shift; ++ my @opts; ++ ++ for $opt (split /\s*,\s*/, $opts) { ++ $opt =~ s/^\s*//; ++ $opt =~ s/\s*$//; ++ my ($key,$val) = $opt =~ /(\w+)(?:=(.+))?/; ++ defined $val or $val = 1; ++ push @opts, $key, $val; ++ } ++ @opts; ++} ++sub parse_entries { ++ my $file = shift; ++ my $file_name = shift; ++ my $looking_for_name = 0; ++ ++ while (<$file>) { ++ # read lines until we have no open comments ++ while (m@/\*([^*]|\*(?!/))*$@) { ++ my $new; ++ defined ($new = <$file>) || die "Unmatched comment in $ARGV"; ++ $_ .= $new; ++ } ++ # strip comments w/o options ++ s@/\*(?!<) ++ ([^*]+|\*(?!/))* ++ \*/@@gx; ++ ++ # strip newlines ++ s@\n@ @; ++ ++ # skip empty lines ++ next if m@^\s*$@; ++ ++ if ($looking_for_name) { ++ if (/^\s*(\w+)/) { ++ $enumname = $1; ++ return 1; ++ } ++ } ++ ++ # Handle include files ++ if (/^\#include\s*<([^>]*)>/ ) { ++ my $file= "../$1"; ++ open NEWFILE, $file or die "Cannot open include file $file: $!\n"; ++ ++ if (parse_entries (\*NEWFILE, $NEWFILE)) { ++ return 1; ++ } else { ++ next; ++ } ++ } ++ ++ if (/^\s*\}\s*(\w+)/) { ++ $enumname = $1; ++ $enumindex++; ++ return 1; ++ } ++ ++ if (/^\s*\}/) { ++ $enumindex++; ++ $looking_for_name = 1; ++ next; ++ } ++ ++ if (m@^\s* ++ (\w+)\s* # name ++ (?:=( # value ++ \s*\w+\s*\(.*\)\s* # macro with multiple args ++ | # OR ++ (?:[^,/]|/(?!\*))* # anything but a comma or comment ++ ))?,?\s* ++ (?:/\*< # options ++ (([^*]|\*(?!/))*) ++ >\s*\*/)?,? ++ \s*$ ++ @x) { ++ my ($name, $value, $options) = ($1,$2,$3); ++ ++ if (!defined $flags && defined $value && $value =~ /<</) { ++ $seenbitshift = 1; ++ } ++ ++ if (defined $options) { ++ my %options = parse_trigraph($options); ++ if (!defined $options{skip}) { ++ push @entries, [ $name, $value, $options{nick} ]; ++ } ++ } else { ++ push @entries, [ $name, $value ]; ++ } ++ } elsif (m@^\s*\#@) { ++ # ignore preprocessor directives ++ } else { ++ print STDERR "$0: $file_name:$.: Failed to parse `$_'\n"; ++ } ++ } ++ ++ return 0; ++} ++ ++sub version { ++ print "glib-mkenums version glib-@GLIB_VERSION@\n"; ++ print "glib-mkenums comes with ABSOLUTELY NO WARRANTY.\n"; ++ print "You may redistribute copies of glib-mkenums under the terms of\n"; ++ print "the GNU General Public License which can be found in the\n"; ++ print "GLib source package. Sources, examples and contact\n"; ++ print "information are available at http://www.gtk.org\n"; ++ exit 0; ++} ++sub usage { ++ print "Usage:\n"; ++ print " glib-mkenums [OPTION...] [FILES...]\n\n"; ++ print "Help Options:\n"; ++ print " -h, --help Show this help message\n\n"; ++ print "Utility Options:\n"; ++ print " --fhead <text> Output file header\n"; ++ print " --fprod <text> Per input file production\n"; ++ print " --ftail <text> Output file trailer\n"; ++ print " --eprod <text> Per enum text (produced prior to value itarations)\n"; ++ print " --vhead <text> Value header, produced before iterating over enum values\n"; ++ print " --vprod <text> Value text, produced for each enum value\n"; ++ print " --vtail <text> Value tail, produced after iterating over enum values\n"; ++ print " --comments <text> Comment structure\n"; ++ print " --template file Template file\n"; ++ print " -v, --version Print version informations\n\n"; ++ print "Production text substitutions:\n"; ++ print " \@EnumName\@ PrefixTheXEnum\n"; ++ print " \@enum_name\@ prefix_the_xenum\n"; ++ print " \@ENUMNAME\@ PREFIX_THE_XENUM\n"; ++ print " \@ENUMSHORT\@ THE_XENUM\n"; ++ print " \@ENUMPREFIX\@ PREFIX\n"; ++ print " \@VALUENAME\@ PREFIX_THE_XVALUE\n"; ++ print " \@valuenick\@ the-xvalue\n"; ++ print " \@valuenum\@ the integer value (limited support, Since: 2.26)\n"; ++ print " \@type\@ either enum or flags\n"; ++ print " \@Type\@ either Enum or Flags\n"; ++ print " \@TYPE\@ either ENUM or FLAGS\n"; ++ print " \@filename\@ name of current input file\n"; ++ print " \@basename\@ base name of the current input file (Since: 2.22)\n"; ++ exit 0; ++} ++ ++# production variables: ++my $fhead = ""; # output file header ++my $fprod = ""; # per input file production ++my $ftail = ""; # output file trailer ++my $eprod = ""; # per enum text (produced prior to value itarations) ++my $vhead = ""; # value header, produced before iterating over enum values ++my $vprod = ""; # value text, produced for each enum value ++my $vtail = ""; # value tail, produced after iterating over enum values ++my $comment_tmpl = ""; # comment template ++ ++sub read_template_file { ++ my ($file) = @_; ++ my %tmpl = ('file-header', $fhead, ++ 'file-production', $fprod, ++ 'file-tail', $ftail, ++ 'enumeration-production', $eprod, ++ 'value-header', $vhead, ++ 'value-production', $vprod, ++ 'value-tail', $vtail, ++ 'comment', $comment_tmpl); ++ my $in = 'junk'; ++ open (FILE, $file) || die "Can't open $file: $!\n"; ++ while (<FILE>) { ++ if (/^\/\*\*\*\s+(BEGIN|END)\s+([\w-]+)\s+\*\*\*\//) { ++ if (($in eq 'junk') && ($1 eq 'BEGIN') && (exists($tmpl{$2}))) { ++ $in = $2; ++ next; ++ } ++ elsif (($in eq $2) && ($1 eq 'END') && (exists($tmpl{$2}))) { ++ $in = 'junk'; ++ next; ++ } else { ++ die "Malformed template file $file\n"; ++ } ++ } ++ if (!($in eq 'junk')) { ++ $tmpl{$in} .= $_; ++ } ++ } ++ close (FILE); ++ if (!($in eq 'junk')) { ++ die "Malformed template file $file\n"; ++ } ++ $fhead = $tmpl{'file-header'}; ++ $fprod = $tmpl{'file-production'}; ++ $ftail = $tmpl{'file-tail'}; ++ $eprod = $tmpl{'enumeration-production'}; ++ $vhead = $tmpl{'value-header'}; ++ $vprod = $tmpl{'value-production'}; ++ $vtail = $tmpl{'value-tail'}; ++ $comment_tmpl = $tmpl{'comment'}; ++ ++ # default to C-style comments ++ $comment_tmpl = "/* \@comment\@ */" if $comment_tmpl eq ""; ++} ++ ++if (!defined $ARGV[0]) { ++ usage; ++} ++while ($_=$ARGV[0],/^-/) { ++ shift; ++ last if /^--$/; ++ if (/^--template$/) { read_template_file (shift); } ++ elsif (/^--fhead$/) { $fhead = $fhead . shift } ++ elsif (/^--fprod$/) { $fprod = $fprod . shift } ++ elsif (/^--ftail$/) { $ftail = $ftail . shift } ++ elsif (/^--eprod$/) { $eprod = $eprod . shift } ++ elsif (/^--vhead$/) { $vhead = $vhead . shift } ++ elsif (/^--vprod$/) { $vprod = $vprod . shift } ++ elsif (/^--vtail$/) { $vtail = $vtail . shift } ++ elsif (/^--comments$/) { $comment_tmpl = shift } ++ elsif (/^--help$/ || /^-h$/ || /^-\?$/) { usage; } ++ elsif (/^--version$/ || /^-v$/) { version; } ++ else { usage; } ++ last if not defined($ARGV[0]); ++} ++ ++# put auto-generation comment ++{ ++ my $comment = $comment_tmpl; ++ $comment =~ s/\@comment\@/Generated data (by glib-mkenums)/; ++ print "\n" . $comment . "\n\n"; ++} ++ ++if (length($fhead)) { ++ my $prod = $fhead; ++ my $base = basename ($ARGV[0]); ++ ++ $prod =~ s/\@filename\@/$ARGV[0]/g; ++ $prod =~ s/\@basename\@/$base/g; ++ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; ++ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; ++ chomp ($prod); ++ ++ print "$prod\n"; ++} ++ ++while (<>) { ++ if (eof) { ++ close (ARGV); # reset line numbering ++ $firstenum = 1; # Flag to print filename at next enum ++ } ++ ++ # read lines until we have no open comments ++ while (m@/\*([^*]|\*(?!/))*$@) { ++ my $new; ++ defined ($new = <>) || die "Unmatched comment in $ARGV"; ++ $_ .= $new; ++ } ++ # strip comments w/o options ++ s@/\*(?!<) ++ ([^*]+|\*(?!/))* ++ \*/@@gx; ++ ++ if (m@^\s*typedef\s+enum\s* ++ ({)?\s* ++ (?:/\*< ++ (([^*]|\*(?!/))*) ++ >\s*\*/)? ++ \s*({)? ++ @x) { ++ if (defined $2) { ++ my %options = parse_trigraph ($2); ++ next if defined $options{skip}; ++ $enum_prefix = $options{prefix}; ++ $flags = $options{flags}; ++ $option_lowercase_name = $options{lowercase_name}; ++ $option_underscore_name = $options{underscore_name}; ++ } else { ++ $enum_prefix = undef; ++ $flags = undef; ++ $option_lowercase_name = undef; ++ $option_underscore_name = undef; ++ } ++ if (defined $option_lowercase_name) { ++ if (defined $option_underscore_name) { ++ print STDERR "$0: $ARGV:$.: lowercase_name overriden with underscore_name\n"; ++ $option_lowercase_name = undef; ++ } else { ++ print STDERR "$0: $ARGV:$.: lowercase_name is deprecated, use underscore_name\n"; ++ } ++ } ++ # Didn't have trailing '{' look on next lines ++ if (!defined $1 && !defined $4) { ++ while (<>) { ++ if (s/^\s*\{//) { ++ last; ++ } ++ } ++ } ++ ++ $seenbitshift = 0; ++ @entries = (); ++ ++ # Now parse the entries ++ parse_entries (\*ARGV, $ARGV); ++ ++ # figure out if this was a flags or enums enumeration ++ if (!defined $flags) { ++ $flags = $seenbitshift; ++ } ++ ++ # Autogenerate a prefix ++ if (!defined $enum_prefix) { ++ for (@entries) { ++ my $nick = $_->[2]; ++ if (!defined $nick) { ++ my $name = $_->[0]; ++ if (defined $enum_prefix) { ++ my $tmp = ~ ($name ^ $enum_prefix); ++ ($tmp) = $tmp =~ /(^\xff*)/; ++ $enum_prefix = $enum_prefix & $tmp; ++ } else { ++ $enum_prefix = $name; ++ } ++ } ++ } ++ if (!defined $enum_prefix) { ++ $enum_prefix = ""; ++ } else { ++ # Trim so that it ends in an underscore ++ $enum_prefix =~ s/_[^_]*$/_/; ++ } ++ } else { ++ # canonicalize user defined prefixes ++ $enum_prefix = uc($enum_prefix); ++ $enum_prefix =~ s/-/_/g; ++ $enum_prefix =~ s/(.*)([^_])$/$1$2_/; ++ } ++ ++ for $entry (@entries) { ++ my ($name,$num,$nick) = @{$entry}; ++ if (!defined $nick) { ++ ($nick = $name) =~ s/^$enum_prefix//; ++ $nick =~ tr/_/-/; ++ $nick = lc($nick); ++ @{$entry} = ($name, $num, $nick); ++ } ++ } ++ ++ ++ # Spit out the output ++ if (defined $option_underscore_name) { ++ $enumlong = uc $option_underscore_name; ++ $enumsym = lc $option_underscore_name; ++ $enumshort = $enumlong; ++ $enumshort =~ s/^[A-Z][A-Z0-9]*_//; ++ ++ $enumname_prefix = $enumlong; ++ $enumname_prefix =~ s/$enumshort$//; ++ } else { ++ # enumname is e.g. GMatchType ++ $enspace = $enumname; ++ $enspace =~ s/^([A-Z][a-z]*).*$/$1/; ++ ++ $enumshort = $enumname; ++ $enumshort =~ s/^[A-Z][a-z]*//; ++ $enumshort =~ s/([^A-Z])([A-Z])/$1_$2/g; ++ $enumshort =~ s/([A-Z][A-Z])([A-Z][0-9a-z])/$1_$2/g; ++ $enumshort = uc($enumshort); ++ ++ $enumname_prefix = $enumname; ++ $enumname_prefix =~ s/^([A-Z][a-z]*).*$/$1/; ++ $enumname_prefix = uc($enumname_prefix); ++ ++ $enumlong = uc($enspace) . "_" . $enumshort; ++ $enumsym = lc($enspace) . "_" . lc($enumshort); ++ ++ if (defined($option_lowercase_name)) { ++ $enumsym = $option_lowercase_name; ++ } ++ } ++ ++ if ($firstenum) { ++ $firstenum = 0; ++ ++ if (length($fprod)) { ++ my $prod = $fprod; ++ my $base = basename ($ARGV); ++ ++ $prod =~ s/\@filename\@/$ARGV/g; ++ $prod =~ s/\@basename\@/$base/g; ++ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; ++ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; ++ chomp ($prod); ++ ++ print "$prod\n"; ++ } ++ } ++ ++ if (length($eprod)) { ++ my $prod = $eprod; ++ ++ $prod =~ s/\@enum_name\@/$enumsym/g; ++ $prod =~ s/\@EnumName\@/$enumname/g; ++ $prod =~ s/\@ENUMSHORT\@/$enumshort/g; ++ $prod =~ s/\@ENUMNAME\@/$enumlong/g; ++ $prod =~ s/\@ENUMPREFIX\@/$enumname_prefix/g; ++ if ($flags) { $prod =~ s/\@type\@/flags/g; } else { $prod =~ s/\@type\@/enum/g; } ++ if ($flags) { $prod =~ s/\@Type\@/Flags/g; } else { $prod =~ s/\@Type\@/Enum/g; } ++ if ($flags) { $prod =~ s/\@TYPE\@/FLAGS/g; } else { $prod =~ s/\@TYPE\@/ENUM/g; } ++ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; ++ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; ++ chomp ($prod); ++ ++ print "$prod\n"; ++ } ++ ++ if (length($vhead)) { ++ my $prod = $vhead; ++ ++ $prod =~ s/\@enum_name\@/$enumsym/g; ++ $prod =~ s/\@EnumName\@/$enumname/g; ++ $prod =~ s/\@ENUMSHORT\@/$enumshort/g; ++ $prod =~ s/\@ENUMNAME\@/$enumlong/g; ++ $prod =~ s/\@ENUMPREFIX\@/$enumname_prefix/g; ++ if ($flags) { $prod =~ s/\@type\@/flags/g; } else { $prod =~ s/\@type\@/enum/g; } ++ if ($flags) { $prod =~ s/\@Type\@/Flags/g; } else { $prod =~ s/\@Type\@/Enum/g; } ++ if ($flags) { $prod =~ s/\@TYPE\@/FLAGS/g; } else { $prod =~ s/\@TYPE\@/ENUM/g; } ++ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; ++ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; ++ chomp ($prod); ++ ++ print "$prod\n"; ++ } ++ ++ if (length($vprod)) { ++ my $prod = $vprod; ++ my $next_num = 0; ++ ++ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; ++ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; ++ for (@entries) { ++ my ($name,$num,$nick) = @{$_}; ++ my $tmp_prod = $prod; ++ ++ if ($prod =~ /\@valuenum\@/) { ++ # only attempt to eval the value if it is requested ++ # this prevents us from throwing errors otherwise ++ if (defined $num) { ++ # use sandboxed perl evaluation as a reasonable ++ # approximation to C constant folding ++ $num = $sandbox->reval ($num); ++ ++ # make sure it parsed to an integer ++ if (!defined $num or $num !~ /^-?\d+$/) { ++ die "Unable to parse enum value '$num'"; ++ } ++ } else { ++ $num = $next_num; ++ } ++ ++ $tmp_prod =~ s/\@valuenum\@/$num/g; ++ $next_num = $num + 1; ++ } ++ ++ $tmp_prod =~ s/\@VALUENAME\@/$name/g; ++ $tmp_prod =~ s/\@valuenick\@/$nick/g; ++ if ($flags) { $tmp_prod =~ s/\@type\@/flags/g; } else { $tmp_prod =~ s/\@type\@/enum/g; } ++ if ($flags) { $tmp_prod =~ s/\@Type\@/Flags/g; } else { $tmp_prod =~ s/\@Type\@/Enum/g; } ++ if ($flags) { $tmp_prod =~ s/\@TYPE\@/FLAGS/g; } else { $tmp_prod =~ s/\@TYPE\@/ENUM/g; } ++ chomp ($tmp_prod); ++ ++ print "$tmp_prod\n"; ++ } ++ } ++ ++ if (length($vtail)) { ++ my $prod = $vtail; ++ ++ $prod =~ s/\@enum_name\@/$enumsym/g; ++ $prod =~ s/\@EnumName\@/$enumname/g; ++ $prod =~ s/\@ENUMSHORT\@/$enumshort/g; ++ $prod =~ s/\@ENUMNAME\@/$enumlong/g; ++ $prod =~ s/\@ENUMPREFIX\@/$enumname_prefix/g; ++ if ($flags) { $prod =~ s/\@type\@/flags/g; } else { $prod =~ s/\@type\@/enum/g; } ++ if ($flags) { $prod =~ s/\@Type\@/Flags/g; } else { $prod =~ s/\@Type\@/Enum/g; } ++ if ($flags) { $prod =~ s/\@TYPE\@/FLAGS/g; } else { $prod =~ s/\@TYPE\@/ENUM/g; } ++ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; ++ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; ++ chomp ($prod); ++ ++ print "$prod\n"; ++ } ++ } ++} ++ ++if (length($ftail)) { ++ my $prod = $ftail; ++ my $base = basename ($ARGV); ++ ++ $prod =~ s/\@filename\@/$ARGV/g; ++ $prod =~ s/\@basename\@/$base/g; ++ $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; ++ $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; ++ chomp ($prod); ++ ++ print "$prod\n"; ++} ++ ++# put auto-generation comment ++{ ++ my $comment = $comment_tmpl; ++ $comment =~ s/\@comment\@/Generated data ends here/; ++ print "\n" . $comment . "\n\n"; ++} diff --git a/glib/makefile.mk b/glib/makefile.mk index d1ce6a88568b..e724baee219f 100755 --- a/glib/makefile.mk +++ b/glib/makefile.mk @@ -289,21 +289,24 @@ OUT2INC+=gobject/gvaluearray.h .ELIF "$(OS)"=="WNT" CONVERTFILES=gobject/gmarshal.c -PATCH_FILES=glib-2.28.1-win32.patch +PATCH_FILES=glib-2.28.1-win32.patch glib-2.28.1-win32-2.patch CONFIGURE_ACTION= ADDITIONAL_FILES= config.h \ gio/gvdb/makefile.msc \ gio/win32/makefile.msc \ glib/glibconfig.h \ - gmodule/gmoduleconf.h + gmodule/gmoduleconf.h \ + gobject/glib-mkenums BUILD_ACTION=nmake -f makefile.msc -OUT2BIN+=gio/libgio-2.0-0.dll -OUT2BIN+=glib/libglib-2.0-0.dll -OUT2BIN+=gmodule/libgmodule-2.0-0.dll -OUT2BIN+=gobject/libgobject-2.0-0.dll -OUT2BIN+=gthread/libgthread-2.0-0.dll +OUT2BIN+=gio$/libgio-2.0-0.dll +OUT2BIN+=glib$/libglib-2.0-0.dll +OUT2BIN+=gmodule$/libgmodule-2.0-0.dll +OUT2BIN+=gobject$/libgobject-2.0-0.dll +OUT2BIN+=gthread$/libgthread-2.0-0.dll +OUT2BIN+=gobject$/glib-mkenums +OUT2BIN+=gobject$/glib-genmarshal.exe OUT2LIB+=build/win32/dirent/dirent.lib OUT2LIB+=gio/gio-2.0.lib @@ -318,6 +321,8 @@ OUT2LIB+=gobject/glib-genmarshal.lib OUT2LIB+=gobject/gobject-2.0.lib OUT2LIB+=gthread/gthread-2.0.lib +OUT2INC+=build$/win32$/make.msc +OUT2INC+=build$/win32$/module.defs OUT2INC+=glib/glib.h OUT2INC+=glib/glib-object.h diff --git a/glib/prj/d.lst b/glib/prj/d.lst index eb6c2620a08a..851265ca79a2 100644 --- a/glib/prj/d.lst +++ b/glib/prj/d.lst @@ -12,6 +12,7 @@ symlink: %_DEST%\lib%_EXT%\libgobject-2.0.0.dylib %_DEST%\lib%_EXT%\libgobject-2 ..\%__SRC%\bin\*.dll %_DEST%\bin%_EXT% ..\%__SRC%\bin\glib-mkenums %_DEST%\bin%_EXT%\glib-mkenums ..\%__SRC%\bin\glib-genmarshal %_DEST%\bin%_EXT%\glib-genmarshal +..\%__SRC%\bin\glib-genmarshal.exe %_DEST%\bin%_EXT%\glib-genmarshal.exe ..\%__SRC%\lib\gio-2.0.lib %_DEST%\lib%_EXT%\gio-2.0.lib ..\%__SRC%\lib\gmodule-2.0.lib %_DEST%\lib%_EXT%\gmodule-2.0.lib ..\%__SRC%\lib\gthread-2.0.lib %_DEST%\lib%_EXT%\gthread-2.0.lib @@ -36,6 +37,8 @@ mkdir: %_DEST%\inc%_EXT%\external\glib-2.0 ..\%__SRC%\inc\glib.h %_DEST%\inc%_EXT%\external\glib-2.0\glib.h ..\%__SRC%\inc\glibconfig.h %_DEST%\inc%_EXT%\external\glib-2.0\glibconfig.h ..\%__SRC%\inc\gmodule.h %_DEST%\inc%_EXT%\external\glib-2.0\gmodule.h +..\%__SRC%\inc\make.msc %_DEST%\inc%_EXT%\external\glib-2.0\make.msc +..\%__SRC%\inc\module.defs %_DEST%\inc%_EXT%\external\glib-2.0\module.defs mkdir: %_DEST%\inc%_EXT%\external\glib-2.0\gio ..\%__SRC%\inc\gaction.h %_DEST%\inc%_EXT%\external\glib-2.0\gio\gaction.h diff --git a/offapi/com/sun/star/embed/Storage.idl b/offapi/com/sun/star/embed/Storage.idl index d34d736cf5cb..8a793d513476 100644 --- a/offapi/com/sun/star/embed/Storage.idl +++ b/offapi/com/sun/star/embed/Storage.idl @@ -356,7 +356,6 @@ published service Storage </p> */ [property, optional, readonly] boolean HasNonEncryptedEntries; - }; //============================================================================ diff --git a/offapi/com/sun/star/embed/XEncryptionProtectedSource2.idl b/offapi/com/sun/star/embed/XEncryptionProtectedSource2.idl index e590a5764178..5930e8490678 100644 --- a/offapi/com/sun/star/embed/XEncryptionProtectedSource2.idl +++ b/offapi/com/sun/star/embed/XEncryptionProtectedSource2.idl @@ -41,17 +41,19 @@ module com { module sun { module star { module embed { //============================================================================ /** This interface allows to set a password for an object. + + @since OOo 3.4 */ -published interface XEncryptionProtectedSource2: XEncryptionProtectedSource +interface XEncryptionProtectedSource2: XEncryptionProtectedSource { // ----------------------------------------------------------------------- /** sets an encryption data for the object. - @param aEncryptionData - the new encryption data + @param aEncryptionData + the new encryption data - @throws ::com::sun::star::io::IOException - in case the data could not be set + @throws ::com::sun::star::io::IOException + in case the data could not be set */ void setEncryptionData( [in] sequence< ::com::sun::star::beans::NamedValue > aEncryptionData ) raises( ::com::sun::star::io::IOException ); diff --git a/offapi/com/sun/star/embed/XEncryptionProtectedStorage.idl b/offapi/com/sun/star/embed/XEncryptionProtectedStorage.idl new file mode 100644 index 000000000000..30ec5621f669 --- /dev/null +++ b/offapi/com/sun/star/embed/XEncryptionProtectedStorage.idl @@ -0,0 +1,120 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef __com_sun_star_embed_XEncryptionProtectedStorage_idl__ +#define __com_sun_star_embed_XEncryptionProtectedStorage_idl__ + +#ifndef __com_sun_star_embed_XEncryptionProtectedSource2_idl__ +#include <com/sun/star/embed/XEncryptionProtectedSource2.idl> +#endif + +#ifndef __com_sun_star_beans_NamedValue_idl__ +#include <com/sun/star/beans/NamedValue.idl> +#endif + +#ifndef __com_sun_star_lang_IllegalArgumentException_idl__ +#include <com/sun/star/lang/IllegalArgumentException.idl> +#endif + +#ifndef __com_sun_star_xml_crypto_DigestID_idl__ +#include <com/sun/star/xml/crypto/DigestID.idl> +#endif + +#ifndef __com_sun_star_xml_crypto_CipherID_idl__ +#include <com/sun/star/xml/crypto/CipherID.idl> +#endif + +//============================================================================ + +module com { module sun { module star { module embed { + +//============================================================================ +/** This interface allows to set a password for an object. + + @since OOo 3.4 + */ +interface XEncryptionProtectedStorage: XEncryptionProtectedSource2 +{ + // ----------------------------------------------------------------------- + /** allows to set the encryption algorithms for the object. + <p> + The algorithms will of course be used only for streams that have been + marked to be encrypted. If no stream in the storage is marked to be + encrypted, the algorithms-related information may have no effect to + the result package. + </p> + + <p> + The following values could be part of the provided sequence: + </p> + <dl> + <dt>StartKeyGenerationAlgorithm</dt> + <dd> + specifies the algorithm that was used to generate + the EncryptionKey from the original password; in case + the contents should be decrypted, the algorithm might + be already known by the object; if a different one is + set an exception should be thrown to indicate the + error; it should take values from + <type scope="com::sun::star::xml:crypto">DigestID</type>. + </dd> + <dt>EncryptionAlgorithm</dt> + <dd> + specifies the algorithm that should be used to + encrypt/decrypt the contents; in case the contents + should be decrypted, the algorithm might be already + known by the object; if a different one is set + an exception should be thrown to indicate the error; + it should take values from + <type scope="com::sun::star::xml:crypto">CipherID</type>. + </dd> + <dt>ChecksumAlgorithm</dt> + <dd> + specifies the algorithm that was used to generate + the checksum of the encrypted data; in case + the contents should be decrypted, the algorithm might + be already known by the object; if a different one is + set an exception should be thrown to indicate the + error; it should take values from + <type scope="com::sun::star::xml:crypto">DigestID</type>. + </dd> + </dl> + */ + void setEncryptionAlgorithms( [in] sequence< ::com::sun::star::beans::NamedValue > aAlgorithms ) + raises( ::com::sun::star::lang::IllegalArgumentException ); + + // ----------------------------------------------------------------------- + /** allows to get the encryption algorithms of the object. + */ + sequence< ::com::sun::star::beans::NamedValue > getEncryptionAlgorithms(); +}; + +//============================================================================ + +}; }; }; }; + +#endif + diff --git a/offapi/com/sun/star/embed/makefile.mk b/offapi/com/sun/star/embed/makefile.mk index 8ee156af48ba..c142086cdbf8 100644 --- a/offapi/com/sun/star/embed/makefile.mk +++ b/offapi/com/sun/star/embed/makefile.mk @@ -78,6 +78,7 @@ IDLFILES=\ XLinkFactory.idl\ XEncryptionProtectedSource.idl\ XEncryptionProtectedSource2.idl\ + XEncryptionProtectedStorage.idl\ XInplaceClient.idl\ XInsertObjectDialog.idl\ XWindowSupplier.idl\ diff --git a/offapi/com/sun/star/script/vba/VBAEventId.idl b/offapi/com/sun/star/script/vba/VBAEventId.idl index fda83a18d495..18b84b5ef14d 100755 --- a/offapi/com/sun/star/script/vba/VBAEventId.idl +++ b/offapi/com/sun/star/script/vba/VBAEventId.idl @@ -97,11 +97,11 @@ constants VBAEventId const long WORKBOOK_AFTERSAVE = 2007; /** New sheet inserted. Arguments: short nSheet. */ const long WORKBOOK_NEWSHEET = 2008; - /** Document window has been activated. No arguments. */ + /** Document window has been activated. Arguments: XController aController. */ const long WORKBOOK_WINDOWACTIVATE = 2009; - /** Document window has been deactivated. No arguments. */ + /** Document window has been deactivated. Arguments: XController aController. */ const long WORKBOOK_WINDOWDEACTIVATE = 2010; - /** Document window has been resized. No arguments. */ + /** Document window has been resized. Arguments: XController aController. */ const long WORKBOOK_WINDOWRESIZE = 2011; //------------------------------------------------------------------------- diff --git a/offapi/com/sun/star/script/vba/VBAScriptEvent.idl b/offapi/com/sun/star/script/vba/VBAScriptEvent.idl new file mode 100755 index 000000000000..c1fc7096bcee --- /dev/null +++ b/offapi/com/sun/star/script/vba/VBAScriptEvent.idl @@ -0,0 +1,73 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __com_sun_star_script_vba_VBAScriptEvent_idl__ +#define __com_sun_star_script_vba_VBAScriptEvent_idl__ + +#include <com/sun/star/lang/EventObject.idl> + +//============================================================================= + +module com { module sun { module star { module script { module vba { + +//============================================================================= + +/** Describes a VBA script event fired via <member>XVBACompatibility:: + broadcastVBAScriptEvent</member>, and received by <member> + XVBAScriptListener::notifyVBAScriptEvent</member>. + + @see XVBACompatibility + @see XVBAScriptListener + */ +struct VBAScriptEvent : ::com::sun::star::lang::EventObject +{ + //------------------------------------------------------------------------- + + /** Identifies the type of the event. + + @see VBAScriptEventId + */ + long Identifier; + + //------------------------------------------------------------------------- + + /** Contains the name of the involved VBA module. + + @see VBAScriptEventId + */ + string ModuleName; + + //------------------------------------------------------------------------- +}; + +//============================================================================= + +}; }; }; }; }; + +//============================================================================= + +#endif diff --git a/offapi/com/sun/star/script/vba/VBAScriptEventId.idl b/offapi/com/sun/star/script/vba/VBAScriptEventId.idl new file mode 100755 index 000000000000..cc66a3fc098c --- /dev/null +++ b/offapi/com/sun/star/script/vba/VBAScriptEventId.idl @@ -0,0 +1,100 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __com_sun_star_script_vba_VBAScriptEventId_idl__ +#define __com_sun_star_script_vba_VBAScriptEventId_idl__ + +//============================================================================= + +module com { module sun { module star { module script { module vba { + +//============================================================================= + +/** Identifies a VBA script event fired via <member>XVBACompatibility:: + broadcastVBAScriptEvent</member>, and received by <member> + XVBAScriptListener::notifyVBAScriptEvent</member>. + + @see VBAScriptEvent + @see XVBACompatibility + @see XVBAScriptListener + */ +constants VBAScriptEventId +{ + //------------------------------------------------------------------------- + /** This event is fired when a VBA script in the current document has been + started. + + <p>Several scripts may run simultaneously, e.g. when a running script + triggers a document event that starts another script.</p> + + <p>The number of running scripts can be obtained via <member> + XVBACompatibility::RunningVBAScripts</member>. The number returned + there will already contain the new script notified with this event.</p> + + <p>The member <member>VBAScriptEvent::ModuleName</member> of the event + object will contain the name of the code module that contains the + started script.</p> + */ + const long SCRIPT_STARTED = 0; + + //------------------------------------------------------------------------- + /** This event is fired when a VBA script in the current document stops + running. + + <p>Several scripts may run simultaneously, e.g. when a running script + triggers a document event that starts another script.</p> + + <p>The number of scripts still running can be obtained via <member> + XVBACompatibility::RunningVBAScripts</member>. The number returned + there will not contain the stopped script notified with this event + anymore.</p> + + <p>The member <member>VBAScriptEvent::ModuleName</member> of the event + object will contain the name of the code module that contains the + script that has been stopped.</p> + */ + const long SCRIPT_STOPPED = 1; + + //------------------------------------------------------------------------- + /** This event is fired when a VBA script in the current document tries to + instanciate a userform. + + <p>The member <member>VBAScriptEvent::ModuleName</member> of the event + object will contain the name of the userform module.</p> + */ + const long INITIALIZE_USERFORM = 2; + + //------------------------------------------------------------------------- +}; + +//============================================================================= + +}; }; }; }; }; + +//============================================================================= + +#endif diff --git a/offapi/com/sun/star/script/vba/XVBACompatibility.idl b/offapi/com/sun/star/script/vba/XVBACompatibility.idl index bfa9d01655fa..9c77046b1159 100644 --- a/offapi/com/sun/star/script/vba/XVBACompatibility.idl +++ b/offapi/com/sun/star/script/vba/XVBACompatibility.idl @@ -28,7 +28,8 @@ #ifndef __com_sun_star_script_vba_XVBACompatibility_idl__ #define __com_sun_star_script_vba_XVBACompatibility_idl__ -#include <com/sun/star/uno/XInterface.idl> +#include <com/sun/star/frame/XModel.idl> +#include <com/sun/star/script/vba/XVBAScriptListener.idl> //============================================================================= @@ -41,6 +42,22 @@ interface XVBACompatibility [attribute] boolean VBACompatibilityMode; //------------------------------------------------------------------------- + + [attribute, readonly] long RunningVBAScripts; + + //------------------------------------------------------------------------- + + [oneway] void addVBAScriptListener( [in] XVBAScriptListener Listener ); + + //------------------------------------------------------------------------- + + [oneway] void removeVBAScriptListener( [in] XVBAScriptListener Listener ); + + //------------------------------------------------------------------------- + + void broadcastVBAScriptEvent( [in] long Identifier, [in] string ModuleName ); + + //------------------------------------------------------------------------- }; }; }; }; }; }; diff --git a/offapi/com/sun/star/script/vba/XVBAEventProcessor.idl b/offapi/com/sun/star/script/vba/XVBAEventProcessor.idl index 4a3534de8412..1bc139243493 100755 --- a/offapi/com/sun/star/script/vba/XVBAEventProcessor.idl +++ b/offapi/com/sun/star/script/vba/XVBAEventProcessor.idl @@ -30,7 +30,6 @@ #include <com/sun/star/uno/XInterface.idl> #include <com/sun/star/lang/IllegalArgumentException.idl> -#include <com/sun/star/script/provider/ScriptFrameworkErrorException.idl> #include <com/sun/star/util/VetoException.idl> //============================================================================= @@ -75,23 +74,20 @@ interface XVBAEventProcessor The input arguments needed to create the argument list of the VBA event handler. + @return + <TRUE/>, if event handing is enabled, and the event handler macro + exists and has been invoked. + @throws <type scope="::com::sun::star::lang">IllegalArgumentException</type> if the passed event identifier is not supported, or if the passed arguments do not conform to the arguments expected by the specified event. - @throws <type scope="::com::sun::star::script::provider">ScriptFrameworkErrorException</type> - if the VBA event handler could not be invoked. Reasons may be, that - handling of VBA events is not enabled, that the VBA event handler - macro has not been found, or that the execution of the macro has - been aborted with an error. - @throws <type scope="::com::sun::star::util">VetoException</type> if the VBA event handler has indicated to veto the event. **/ - void processVbaEvent( [in] long nEventId, [in] sequence< any > aArgs ) + boolean processVbaEvent( [in] long nEventId, [in] sequence< any > aArgs ) raises (::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::script::provider::ScriptFrameworkErrorException, ::com::sun::star::util::VetoException); //------------------------------------------------------------------------- diff --git a/package/source/zipapi/XMemoryStream.cxx b/offapi/com/sun/star/script/vba/XVBAScriptListener.idl index c5ffe9ac874c..2f5594d3b416 100644..100755 --- a/package/source/zipapi/XMemoryStream.cxx +++ b/offapi/com/sun/star/script/vba/XVBAScriptListener.idl @@ -25,28 +25,27 @@ * ************************************************************************/ -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <XMemoryStream.hxx> +#ifndef __com_sun_star_script_vba_XVBAScriptListener_idl__ +#define __com_sun_star_script_vba_XVBAScriptListener_idl__ -using namespace com::sun::star::io; -using namespace com::sun::star::uno; +#include <com/sun/star/lang/XEventListener.idl> +#include <com/sun/star/script/vba/VBAScriptEvent.idl> -XMemoryStream::XMemoryStream ( com::sun::star::uno::Sequence < sal_Int8 > & rNewBuffer ) -: ZipPackageBuffer ( rNewBuffer ) -{ -} -XMemoryStream::~XMemoryStream(void) -{ -} -::com::sun::star::uno::Any SAL_CALL XMemoryStream::queryInterface( const com::sun::star::uno::Type& rType ) - throw(com::sun::star::uno::RuntimeException) +//============================================================================= + +module com { module sun { module star { module script { module vba { + +//============================================================================= + +interface XVBAScriptListener : ::com::sun::star::lang::XEventListener { - return ::cppu::queryInterface ( rType , - // OWeakObject interfaces - reinterpret_cast< XInterface* > ( this ) , - static_cast< XWeak* > ( this ) , - // my interfaces - static_cast< XInputStream* > ( this ) , - static_cast< XSeekable* > ( this ) ); -} + void notifyVBAScriptEvent( [in] VBAScriptEvent Event ); +}; + +//============================================================================= + +}; }; }; }; }; + +//============================================================================= + +#endif diff --git a/offapi/com/sun/star/script/vba/makefile.mk b/offapi/com/sun/star/script/vba/makefile.mk index 336be1b5e7a6..6f13245f7d1e 100755 --- a/offapi/com/sun/star/script/vba/makefile.mk +++ b/offapi/com/sun/star/script/vba/makefile.mk @@ -41,12 +41,15 @@ IDLFILES=\ VBAEventId.idl \ VBAEventProcessor.idl \ VBAMacroResolver.idl \ + VBAScriptEvent.idl \ + VBAScriptEventId.idl \ VBASpreadsheetEventProcessor.idl \ VBATextEventProcessor.idl \ XVBACompatibility.idl \ XVBAEventProcessor.idl \ XVBAMacroResolver.idl \ - XVBAModuleInfo.idl + XVBAModuleInfo.idl \ + XVBAScriptListener.idl # ------------------------------------------------------------------ diff --git a/offapi/com/sun/star/xml/crypto/CipherID.idl b/offapi/com/sun/star/xml/crypto/CipherID.idl new file mode 100644 index 000000000000..10b058167244 --- /dev/null +++ b/offapi/com/sun/star/xml/crypto/CipherID.idl @@ -0,0 +1,60 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef __com_sun_star_xml_crypto_CipherID_idl__ +#define __com_sun_star_xml_crypto_CipherID_idl__ + + +//============================================================================ + +module com { module sun { module star { module xml { module crypto { + +//============================================================================ +/** The constant set contains identifiers of supported cipher-creation + algorithms. + + @see <type>XCipherContextSupplier</type> + @since OOo 3.4 +*/ +constants CipherID +{ + //------------------------------------------------------------------------ + /** identifier of AES algorithm in CBC mode with W3C padding + */ + const long AES_CBC_W3C_PADDING = 1; + + //------------------------------------------------------------------------ + /** identifier of the Blowfish algorithm in 8-bit CFB mode + */ + const long BLOWFISH_CFB_8 = 2; +}; + +//============================================================================ + +}; }; }; }; }; + +#endif + diff --git a/offapi/com/sun/star/xml/crypto/DigestID.idl b/offapi/com/sun/star/xml/crypto/DigestID.idl new file mode 100644 index 000000000000..14eb822de2fd --- /dev/null +++ b/offapi/com/sun/star/xml/crypto/DigestID.idl @@ -0,0 +1,72 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef __com_sun_star_xml_crypto_DigestID_idl__ +#define __com_sun_star_xml_crypto_DigestID_idl__ + + +//============================================================================ + +module com { module sun { module star { module xml { module crypto { + +//============================================================================ +/** The constant set contains identifiers of supported digest-creation + algorithms. + + @see <type>XDigestContextSupplier</type> + @since OOo 3.4 +*/ +constants DigestID +{ + //------------------------------------------------------------------------ + /** identifier of SHA-1 algorithm + */ + const long SHA1 = 1; + + //------------------------------------------------------------------------ + /** identifier of SHA-256 algorithm + */ + const long SHA256 = 2; + + //------------------------------------------------------------------------ + /** identifier of SHA-1 algorithm that is applied to the first kilobyte + of data. + */ + const long SHA1_1K = 3; + + //------------------------------------------------------------------------ + /** identifier of SHA-256 algorithm that is applied to the first kilobyte + of data. + */ + const long SHA256_1K = 4; +}; + +//============================================================================ + +}; }; }; }; }; + +#endif + diff --git a/offapi/com/sun/star/xml/crypto/SEInitializer.idl b/offapi/com/sun/star/xml/crypto/SEInitializer.idl index e27bafd319e9..239ef92c9693 100644 --- a/offapi/com/sun/star/xml/crypto/SEInitializer.idl +++ b/offapi/com/sun/star/xml/crypto/SEInitializer.idl @@ -28,21 +28,19 @@ #ifndef __com_sun_star_xml_crypto_seinitializer_idl_ #define __com_sun_star_xml_crypto_seinitializer_idl_ -#include <com/sun/star/uno/XInterface.idl> -#include <com/sun/star/uno/Exception.idl> - #include <com/sun/star/xml/crypto/XSEInitializer.idl> - -#include <com/sun/star/lang/XServiceInfo.idl> +#include <com/sun/star/xml/crypto/XDigestContextSupplier.idl> +#include <com/sun/star/xml/crypto/XCipherContextSupplier.idl> module com { module sun { module star { module xml { module crypto { /** * Service of SEInitializer */ -published service SEInitializer { - interface com::sun::star::xml::crypto::XSEInitializer ; - interface com::sun::star::lang::XServiceInfo ; +service SEInitializer { + interface ::com::sun::star::xml::crypto::XSEInitializer; + interface ::com::sun::star::xml::crypto::XDigestContextSupplier; + interface ::com::sun::star::xml::crypto::XCipherContextSupplier; }; } ; } ; } ; } ; } ; diff --git a/offapi/com/sun/star/xml/crypto/XCipherContext.idl b/offapi/com/sun/star/xml/crypto/XCipherContext.idl new file mode 100644 index 000000000000..d2c086163f93 --- /dev/null +++ b/offapi/com/sun/star/xml/crypto/XCipherContext.idl @@ -0,0 +1,89 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef __com_sun_star_xml_crypto_xciphercontext_idl_ +#define __com_sun_star_xml_crypto_xciphercontext_idl_ + +#ifndef __com_sun_star_uno_XInterface_idl__ +#include <com/sun/star/uno/XInterface.idl> +#endif + +#ifndef __com_sun_star_lang_IllegalArgumentException_idl__ +#include <com/sun/star/lang/IllegalArgumentException.idl> +#endif + +#ifndef __com_sun_star_lang_DisposedException_idl__ +#include <com/sun/star/lang/DisposedException.idl> +#endif + +//============================================================================ + + module com { module sun { module star { module xml { module crypto { + +//============================================================================ +/** This interface allows to encrypt/decrypt data using the cipher context. + <p> + The algorithm as well as encryption data are specified on object creation. + </p> + + @see <type>XCipherContextSupplier</type> + @since OOo 3.4 + */ +interface XCipherContext : com::sun::star::uno::XInterface +{ + //------------------------------------------------------------------------ + /** encrypts/decrypts the data using the cipher. + <p> + Please have in mind, the cipher object state might depend from the + already encrypted/decrypted data ( it depends from the used + algorithm ). + </p> + + <p> + Whether the object does encryption or decryption is specified by + creation of the object. + </p> + + @param aData + data that should be encrypted/decrypted + */ + sequence<byte> convertWithCipherContext( [in] sequence< byte > aData ) + raises( ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::lang::DisposedException ); + + //------------------------------------------------------------------------ + /** finalizes cipher and disposes context. + */ + sequence<byte> finalizeCipherContextAndDispose() + raises( ::com::sun::star::lang::DisposedException ); +}; + +//============================================================================ + +}; }; }; }; }; + +#endif + diff --git a/offapi/com/sun/star/xml/crypto/XCipherContextSupplier.idl b/offapi/com/sun/star/xml/crypto/XCipherContextSupplier.idl new file mode 100644 index 000000000000..115cf7b0ee0f --- /dev/null +++ b/offapi/com/sun/star/xml/crypto/XCipherContextSupplier.idl @@ -0,0 +1,91 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef __com_sun_star_xml_crypto_xciphercontextsupplier_idl_ +#define __com_sun_star_xml_crypto_xciphercontextsupplier_idl_ + +#ifndef __com_sun_star_uno_XInterface_idl__ +#include <com/sun/star/uno/XInterface.idl> +#endif + +#ifndef __com_sun_star_beans_NamedValue_idl__ +#include <com/sun/star/beans/NamedValue.idl> +#endif + +#ifndef __com_sun_star_xml_crypto_XCipherContext_idl__ +#include <com/sun/star/xml/crypto/XCipherContext.idl> +#endif + +#ifndef __com_sun_star_lang_IllegalArgumentException_idl__ +#include <com/sun/star/lang/IllegalArgumentException.idl> +#endif + +//============================================================================ + + module com { module sun { module star { module xml { module crypto { + +//============================================================================ +/** This interface allows to get an object that allows to encrypt/decrypt data + using the specified algorithm. + + @since OOo 3.4 + */ +interface XCipherContextSupplier : com::sun::star::uno::XInterface +{ + //------------------------------------------------------------------------ + /** returns an object that allows to encrypt/decrypt data. + + @param nCipherID + the internal ID specifying the algorithm, + should take value from <type>CipherID</type> + + @param aKey + the key that should be used for the encryption + + @param aInitializationVector + the initialization vector that should be used for the encryption + + @param bEncryption + whether an encryption or decryption cipher should be created + <TRUE/> - Encryption + <FALSE/> - Decryption + + @param aParams + optional parameters that could be used to initialize the cipher, + + @throws ::com::sun::star::lang::IllegalArgumentException + one of provided arguments is illegal + */ + + XCipherContext getCipherContext( [in] long nCipherID, [in] sequence< byte > aKey, [in] sequence< byte > aInitializationVector, [in] boolean bEncryption, [in] sequence< ::com::sun::star::beans::NamedValue > aParams ) + raises( ::com::sun::star::lang::IllegalArgumentException ); +}; + +//============================================================================ + +}; }; }; }; }; + +#endif diff --git a/offapi/com/sun/star/xml/crypto/XDigestContext.idl b/offapi/com/sun/star/xml/crypto/XDigestContext.idl new file mode 100644 index 000000000000..f6218d9b6eda --- /dev/null +++ b/offapi/com/sun/star/xml/crypto/XDigestContext.idl @@ -0,0 +1,74 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef __com_sun_star_xml_crypto_xdigestcontext_idl_ +#define __com_sun_star_xml_crypto_xdigestcontext_idl_ + +#ifndef __com_sun_star_uno_XInterface_idl__ +#include <com/sun/star/uno/XInterface.idl> +#endif + +#ifndef __com_sun_star_lang_DisposedException_idl__ +#include <com/sun/star/lang/DisposedException.idl> +#endif + +//============================================================================ + + module com { module sun { module star { module xml { module crypto { + +//============================================================================ +/** This interface allows to generate the digest. + <p> + The algorithm to generate the digest is specified on object creation. + </p> + + @see <type>XDigestContextSupplier</type> + @since OOo 3.4 + */ +interface XDigestContext : com::sun::star::uno::XInterface +{ + //------------------------------------------------------------------------ + /** update the digest with the given data. + + @param aData + data that should be used to update the digest + */ + void updateDigest( [in] sequence< byte > aData ) + raises( ::com::sun::star::lang::DisposedException ); + + //------------------------------------------------------------------------ + /** finalizes digest and disposes context. + */ + sequence<byte> finalizeDigestAndDispose() + raises( ::com::sun::star::lang::DisposedException ); +}; + +//============================================================================ + +}; }; }; }; }; + +#endif + diff --git a/offapi/com/sun/star/xml/crypto/XDigestContextSupplier.idl b/offapi/com/sun/star/xml/crypto/XDigestContextSupplier.idl new file mode 100644 index 000000000000..f421d8ff9c96 --- /dev/null +++ b/offapi/com/sun/star/xml/crypto/XDigestContextSupplier.idl @@ -0,0 +1,83 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef __com_sun_star_xml_crypto_xdigestcontextsupplier_idl_ +#define __com_sun_star_xml_crypto_xdigestcontextsupplier_idl_ + +#ifndef __com_sun_star_uno_XInterface_idl__ +#include <com/sun/star/uno/XInterface.idl> +#endif + +#ifndef __com_sun_star_beans_NamedValue_idl__ +#include <com/sun/star/beans/NamedValue.idl> +#endif + +#ifndef __com_sun_star_xml_crypto_XDigestContext_idl__ +#include <com/sun/star/xml/crypto/XDigestContext.idl> +#endif + +#ifndef __com_sun_star_lang_IllegalArgumentException_idl__ +#include <com/sun/star/lang/IllegalArgumentException.idl> +#endif + +//============================================================================ + + module com { module sun { module star { module xml { module crypto { + +//============================================================================ +/** This interface allows to get an object to generate a digest of a specified + format. + + @since OOo 3.4 + */ +interface XDigestContextSupplier : com::sun::star::uno::XInterface +{ + //------------------------------------------------------------------------ + /** returns an object that allows to generate the specified digest. + + @param nDigestID + the internal ID specifying the algorithm, + should take value from <type>DigestID</type> + + @param aParams + optional parameters that could be used to initialize the digest, + for example, it could contain a key and etc. + + @throws ::com::sun::star::lang::IllegalArgumentException + one of provided arguments is illegal + */ + XDigestContext getDigestContext( + [in] long nDigestID, + [in] sequence< ::com::sun::star::beans::NamedValue > aParams ) + raises( ::com::sun::star::lang::IllegalArgumentException ); +}; + +//============================================================================ + +}; }; }; }; }; + +#endif + diff --git a/offapi/com/sun/star/xml/crypto/XSEInitializer.idl b/offapi/com/sun/star/xml/crypto/XSEInitializer.idl index eedbfa9551a4..bb0422148f57 100644 --- a/offapi/com/sun/star/xml/crypto/XSEInitializer.idl +++ b/offapi/com/sun/star/xml/crypto/XSEInitializer.idl @@ -41,13 +41,14 @@ published interface XXMLSecurityContext; published interface XSEInitializer : com::sun::star::uno::XInterface { /** - * Creates a security context. - * - * @param certificateDatabase the file or directory of the key materials - * @return the security context created + Creates a security context. + + @param aString + reserved for internal use. + + @return the security context created */ - com::sun::star::xml::crypto::XXMLSecurityContext createSecurityContext( - [in] string certificateDatabase); + ::com::sun::star::xml::crypto::XXMLSecurityContext createSecurityContext( [in] string aString ); /** * Frees a security context. diff --git a/offapi/com/sun/star/xml/crypto/makefile.mk b/offapi/com/sun/star/xml/crypto/makefile.mk index 4aa3957ac418..c03b2a76daf7 100644 --- a/offapi/com/sun/star/xml/crypto/makefile.mk +++ b/offapi/com/sun/star/xml/crypto/makefile.mk @@ -58,6 +58,12 @@ IDLFILES=\ XMLSignatureException.idl \ XMLEncryptionException.idl \ XUriBinding.idl \ + CipherID.idl \ + DigestID.idl \ + XCipherContext.idl \ + XCipherContextSupplier.idl \ + XDigestContext.idl \ + XDigestContextSupplier.idl \ SecurityOperationStatus.idl # ------------------------------------------------------------------ diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs index 2475bd6f35ba..3572b37e3e82 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs @@ -2392,9 +2392,23 @@ <desc>ODFVER_LATEST</desc> </info> </enumeration> - </constraints> - <value>3</value> - </prop> + </constraints> + <value>3</value> + </prop> + <prop oor:name="UseSHA1InODF12" oor:type="xs:boolean"> + <info> + <author>MAV</author> + <desc>Specifies whether SHA1 algorithm instead of SHA256 should be used in ODF12 for StartKey and Checksum generation during encryption.</desc> + </info> + <value>false</value> + </prop> + <prop oor:name="UseBlowfishInODF12" oor:type="xs:boolean"> + <info> + <author>MAV</author> + <desc>Specifies whether Blowfish algorithm instead of AES should be used in ODF12 for encryption.</desc> + </info> + <value>false</value> + </prop> </group> </group> <group oor:name="Load"> diff --git a/oovbaapi/ooo/vba/XApplicationBase.idl b/oovbaapi/ooo/vba/XApplicationBase.idl index 1291276ae643..3d0e6c9ce0f5 100644 --- a/oovbaapi/ooo/vba/XApplicationBase.idl +++ b/oovbaapi/ooo/vba/XApplicationBase.idl @@ -45,7 +45,6 @@ interface XApplicationBase [attribute, readonly] string Version; [attribute, readonly] any VBE; - [attribute, readonly] any VBProjects; void Quit(); diff --git a/oovbaapi/ooo/vba/XCollectionBase.idl b/oovbaapi/ooo/vba/XCollectionBase.idl new file mode 100755 index 000000000000..245b252f7856 --- /dev/null +++ b/oovbaapi/ooo/vba/XCollectionBase.idl @@ -0,0 +1,56 @@ +/************************************************************************* + * + * Copyright 2010, Oracle and/or its affiliates. All rights reserved. + * + ************************************************************************/ + +#ifndef OOO_VBA_XOLLECTIONBASE_IDL +#define OOO_VBA_XOLLECTIONBASE_IDL + +#include <com/sun/star/container/XEnumerationAccess.idl> +#include <com/sun/star/script/XDefaultMethod.idl> + +//============================================================================= + +module ooo { module vba { + +//============================================================================= + +/** Base interface for VBA collections. + + Every VBA collection provides the number of items, an enumeration access of + all collection items (e.g. for the "For Each" loop), and a way to access + single items, usually via the method "Item". + + The various VBA collection objects expect a specific number of arguments in + the "Item" method, therefore this method is not part of this base interface + but has to be specified seperately in every derived interface. + */ +interface XCollectionBase +{ + //------------------------------------------------------------------------- + /** Provides an enumeration of all items in this collection. + */ + interface ::com::sun::star::container::XEnumerationAccess; + + //------------------------------------------------------------------------- + /** Provides the name of the default item access method. + + Usually this method is called "Item". The access method has to be + specified and implemented separately by every derived class. + */ + interface ::com::sun::star::script::XDefaultMethod; + + //------------------------------------------------------------------------- + /** Returns the number of items contained in this collection. + */ + [attribute, readonly] long Count; + + //------------------------------------------------------------------------- +}; + +//============================================================================= + +}; }; + +#endif diff --git a/oovbaapi/ooo/vba/XControlProvider.idl b/oovbaapi/ooo/vba/XControlProvider.idl index 23f890d5a1c3..df8b53bdfc72 100644 --- a/oovbaapi/ooo/vba/XControlProvider.idl +++ b/oovbaapi/ooo/vba/XControlProvider.idl @@ -51,8 +51,6 @@ module ooo { module vba { interface XControlProvider { ::ooo::vba::msforms::XControl createControl( [in] ::com::sun::star::drawing::XControlShape xControl, [in] ::com::sun::star::frame::XModel xDocOwner ); - ::ooo::vba::msforms::XControl createUserformControl( [in] ::com::sun::star::awt::XControl xControl, [in] ::com::sun::star::awt::XControl xDialog, [in] ::com::sun::star::frame::XModel xDocOwner ); - }; }; }; diff --git a/oovbaapi/ooo/vba/XExecutableDialog.idl b/oovbaapi/ooo/vba/XExecutableDialog.idl new file mode 100755 index 000000000000..8754c8071348 --- /dev/null +++ b/oovbaapi/ooo/vba/XExecutableDialog.idl @@ -0,0 +1,58 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __ooo_vba_XExecutableDialog_idl__ +#define __ooo_vba_XExecutableDialog_idl__ + +#include <com/sun/star/uno/XInterface.idl> + +//============================================================================= + +module ooo { module vba { + +/** The VBA equivalent to the UNO interface + <type scope="com::sun::star::ui::dialogs">XExecutableDialog</type>. + */ +interface XExecutableDialog +{ + /** Executes the dialog. + + @return + The return value is dependent on the calling context. Usually, on + cancelling the dialog the implementation will return <FALSE/>, + otherwise the return value will contain the expected result. + */ + any execute(); +}; + +//============================================================================= + +}; }; + +#endif + + diff --git a/oovbaapi/ooo/vba/excel/SheetObjects.idl b/oovbaapi/ooo/vba/excel/SheetObjects.idl index 5947c52ff4a0..0a2a3fd9ffe9 100644 --- a/oovbaapi/ooo/vba/excel/SheetObjects.idl +++ b/oovbaapi/ooo/vba/excel/SheetObjects.idl @@ -74,10 +74,10 @@ interface XGraphicObjects : com::sun::star::uno::XInterface /** Adds a new graphic object to the sheet this collection belongs to. The type of the object is determined by the type of the collection. - @param fLeft Position of the left border in points (1/72 inch). - @param fTop Position of the top border in points (1/72 inch). - @param fWidth Width of the object in points (1/72 inch). - @param fHeight Height of the object in points (1/72 inch). + @param Left Position of the left border in points (1/72 inch). + @param Top Position of the top border in points (1/72 inch). + @param Width Width of the object in points (1/72 inch). + @param Height Height of the object in points (1/72 inch). @return The created graphic object. */ @@ -102,10 +102,10 @@ interface XLineObjects : com::sun::star::uno::XInterface /** Adds a new line object to the sheet this collection belongs to. The type of the object is determined by the type of the collection. - @param fX1 Position of the first X coordinate in points (1/72 inch). - @param fY1 Position of the first Y coordinate in points (1/72 inch). - @param fX2 Position of the last X coordinate in points (1/72 inch). - @param fY2 Position of the last Y coordinate in points (1/72 inch). + @param X1 Position of the first X coordinate in points (1/72 inch). + @param Y1 Position of the first Y coordinate in points (1/72 inch). + @param X2 Position of the last X coordinate in points (1/72 inch). + @param Y2 Position of the last Y coordinate in points (1/72 inch). @return The created line object. */ @@ -123,11 +123,11 @@ interface XDrawings : com::sun::star::uno::XInterface { /** Adds a new polygon object to the sheet this collection belongs to. - @param fX1 Position of the first X coordinate in points (1/72 inch). - @param fY1 Position of the first Y coordinate in points (1/72 inch). - @param fX2 Position of the last X coordinate in points (1/72 inch). - @param fY2 Position of the last Y coordinate in points (1/72 inch). - @param bClosed True = outline closed (last and first point connected). + @param X1 Position of the first X coordinate in points (1/72 inch). + @param Y1 Position of the first Y coordinate in points (1/72 inch). + @param X2 Position of the last X coordinate in points (1/72 inch). + @param Y2 Position of the last Y coordinate in points (1/72 inch). + @param Closed True = outline closed (last and first point connected). @return The created polygon object. */ diff --git a/oovbaapi/ooo/vba/excel/XApplication.idl b/oovbaapi/ooo/vba/excel/XApplication.idl index 5ec821dbe8bb..267c9589bfae 100644 --- a/oovbaapi/ooo/vba/excel/XApplication.idl +++ b/oovbaapi/ooo/vba/excel/XApplication.idl @@ -64,15 +64,12 @@ interface XApplication [attribute] any CutCopyMode; [attribute] any StatusBar; [attribute] long Cursor; - [attribute] boolean EnableEvents; + [attribute] boolean EnableEvents; + [attribute] string DefaultFilePath; + [attribute, readonly] string LibraryPath; + [attribute, readonly] string TemplatesPath; + [attribute, readonly] string PathSeparator; - void setDefaultFilePath([in] string DefaultFilePath) raises(com::sun::star::script::BasicErrorException); - - string getDefaultFilePath() raises(com::sun::star::script::BasicErrorException); - - string LibraryPath() raises(com::sun::star::script::BasicErrorException); - string TemplatesPath() raises(com::sun::star::script::BasicErrorException); - string PathSeparator() raises(com::sun::star::script::BasicErrorException); //any CommandBars( [in] any Index ); any Workbooks( [in] any Index ); any Worksheets( [in] any Index ); @@ -93,10 +90,10 @@ interface XApplication void Volatile([in] any Volatile); void DoEvents(); any Caller( [in] any Index ); + any GetOpenFilename( [in] any FileFilter, [in] any FilterIndex, [in] any Title, [in] any ButtonText, [in] any MultiSelect ); + any GetSaveAsFilename( [in] any InitialFileName, [in] any FileFilter, [in] any FilterIndex, [in] any Title, [in] any ButtonText ); }; }; }; }; #endif - - diff --git a/oovbaapi/ooo/vba/makefile.mk b/oovbaapi/ooo/vba/makefile.mk index 4f6d378cfe3f..d1adc1c4252e 100644 --- a/oovbaapi/ooo/vba/makefile.mk +++ b/oovbaapi/ooo/vba/makefile.mk @@ -39,6 +39,7 @@ PACKAGE=ooo$/vba IDLFILES=\ XErrObject.idl \ XCollection.idl\ + XCollectionBase.idl\ XVBAToOOEventDescGen.idl\ XPropValue.idl\ XHelperInterface.idl\ @@ -58,6 +59,7 @@ IDLFILES=\ XGlobalsBase.idl\ XDocumentProperty.idl\ XDocumentProperties.idl\ + XExecutableDialog.idl\ XFontBase.idl\ XDialogsBase.idl\ XDialogBase.idl\ diff --git a/oovbaapi/ooo/vba/msforms/XButton.idl b/oovbaapi/ooo/vba/msforms/XCheckBox.idl index 24cf1ba26c60..7520a559b0d5 100644..100755 --- a/oovbaapi/ooo/vba/msforms/XButton.idl +++ b/oovbaapi/ooo/vba/msforms/XCheckBox.idl @@ -24,20 +24,23 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ -#ifndef __ooo_vba_msforms_XButton_idl__ -#define __ooo_vba_msforms_XButton_idl__ -#ifndef __com_sun_star_uno_XInterface_idl__ -#include <com/sun/star/uno/XInterface.idl> -#endif +#ifndef __ooo_vba_msforms_XCheckBox_idl__ +#define __ooo_vba_msforms_XCheckBox_idl__ + +#include <ooo/vba/msforms/XNewFont.idl> + //============================================================================= module ooo { module vba { module msforms { //============================================================================= -interface XButton: com::sun::star::uno::XInterface + +interface XCheckBox { [attribute] string Caption; + [attribute] any Value; + [attribute, readonly] XNewFont Font; }; //============================================================================= diff --git a/oovbaapi/ooo/vba/msforms/XComboBox.idl b/oovbaapi/ooo/vba/msforms/XComboBox.idl index 5f2b66431eb8..51ca4a4135d1 100644 --- a/oovbaapi/ooo/vba/msforms/XComboBox.idl +++ b/oovbaapi/ooo/vba/msforms/XComboBox.idl @@ -24,26 +24,33 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #ifndef __ooo_vba_msforms_XComboBox_idl__ #define __ooo_vba_msforms_XComboBox_idl__ -#ifndef __com_sun_star_uno_XInterface_idl__ -#include <com/sun/star/uno/XInterface.idl> -#endif - +#include <ooo/vba/msforms/XNewFont.idl> //============================================================================= module ooo { module vba { module msforms { - //============================================================================= -interface XComboBox: ::com::sun::star::uno::XInterface + +interface XComboBox { [attribute] any Value; [attribute] any ListIndex; - [attribute, readonly ] long ListCount; + [attribute, readonly] long ListCount; [attribute] string Text; + [attribute] long Style; + [attribute] long DropButtonStyle; + [attribute] long DragBehavior; + [attribute] long EnterFieldBehavior; + [attribute] long ListStyle; + [attribute] long TextAlign; + [attribute, readonly] long TextLength; + [attribute, readonly] XNewFont Font; + void AddItem( [in] any pvargItem, [in] any pvargIndex ); void removeItem( [in] any index ); void Clear(); diff --git a/oovbaapi/ooo/vba/msforms/XCommandButton.idl b/oovbaapi/ooo/vba/msforms/XCommandButton.idl new file mode 100644 index 000000000000..0e7697cbd162 --- /dev/null +++ b/oovbaapi/ooo/vba/msforms/XCommandButton.idl @@ -0,0 +1,56 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __ooo_vba_msforms_XCommandButton_idl__ +#define __ooo_vba_msforms_XCommandButton_idl__ + +#include <ooo/vba/msforms/XNewFont.idl> + +//============================================================================= + +module ooo { module vba { module msforms { + +//============================================================================= + +interface XCommandButton +{ + [attribute] string Caption; + [attribute] boolean AutoSize; + [attribute] boolean Cancel; + [attribute] boolean Default; + [attribute] long BackColor; + [attribute] long ForeColor; + [attribute, readonly] XNewFont Font; +}; + +//============================================================================= + +}; }; }; + +#endif + + diff --git a/oovbaapi/ooo/vba/msforms/XControl.idl b/oovbaapi/ooo/vba/msforms/XControl.idl index 97ca9d152716..3cd1f2c3e75c 100644 --- a/oovbaapi/ooo/vba/msforms/XControl.idl +++ b/oovbaapi/ooo/vba/msforms/XControl.idl @@ -63,6 +63,7 @@ interface XControl [attribute] string Name; [attribute] string ControlTipText; [attribute] string Tag; + [attribute] long TabIndex; }; //============================================================================= diff --git a/package/source/zipapi/XMemoryStream.hxx b/oovbaapi/ooo/vba/msforms/XFrame.idl index 89db08a6c4ed..6038b61dd3bd 100644..100755 --- a/package/source/zipapi/XMemoryStream.hxx +++ b/oovbaapi/ooo/vba/msforms/XFrame.idl @@ -24,19 +24,32 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ -#ifndef _XMEMORY_STREAM_HXX -#define _XMEMORY_STREAM_HXX -#include <ZipPackageBuffer.hxx> +#ifndef __ooo_vba_msforms_XFrame_idl__ +#define __ooo_vba_msforms_XFrame_idl__ -class ZipPackage; +#include <ooo/vba/msforms/XNewFont.idl> -class XMemoryStream: public ZipPackageBuffer +//============================================================================= + +module ooo { module vba { module msforms { + +//============================================================================= + +interface XFrame { -public: - XMemoryStream ( com::sun::star::uno::Sequence < sal_Int8 > & rNewBuffer ); - virtual ~XMemoryStream(void); - virtual com::sun::star::uno::Any SAL_CALL queryInterface( const com::sun::star::uno::Type& rType ) - throw(com::sun::star::uno::RuntimeException); + [attribute] string Caption; + [attribute] long SpecialEffect; + [attribute] long BorderStyle; + [attribute, readonly] XNewFont Font; + + any Controls( [in] any Index ); }; + +//============================================================================= + +}; }; }; + +//============================================================================= + #endif diff --git a/oovbaapi/ooo/vba/msforms/XGroupBox.idl b/oovbaapi/ooo/vba/msforms/XGroupBox.idl index 9ed6f9d45046..9718f23e1c66 100644 --- a/oovbaapi/ooo/vba/msforms/XGroupBox.idl +++ b/oovbaapi/ooo/vba/msforms/XGroupBox.idl @@ -24,19 +24,22 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #ifndef __ooo_vba_msforms_XGroupBox_idl__ #define __ooo_vba_msforms_XGroupBox_idl__ -#ifndef __com_sun_star_uno_XInterface_idl__ -#include <com/sun/star/uno/XInterface.idl> -#endif +#include <ooo/vba/msforms/XNewFont.idl> + //============================================================================= module ooo { module vba { module msforms { + //============================================================================= + interface XGroupBox { [attribute] string Caption; + [attribute, readonly] XNewFont Font; }; //============================================================================= diff --git a/oovbaapi/ooo/vba/msforms/XLabel.idl b/oovbaapi/ooo/vba/msforms/XLabel.idl index d757af5074d8..399127a091c8 100644 --- a/oovbaapi/ooo/vba/msforms/XLabel.idl +++ b/oovbaapi/ooo/vba/msforms/XLabel.idl @@ -24,21 +24,23 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #ifndef __ooo_vba_msforms_XLabel_idl__ #define __ooo_vba_msforms_XLabel_idl__ -#ifndef __com_sun_star_uno_XInterface_idl__ -#include <com/sun/star/uno/XInterface.idl> -#endif +#include <ooo/vba/msforms/XNewFont.idl> + //============================================================================= module ooo { module vba { module msforms { //============================================================================= -interface XLabel: com::sun::star::uno::XInterface + +interface XLabel { [attribute] string Caption; [attribute] any Value; + [attribute, readonly] XNewFont Font; }; //============================================================================= diff --git a/oovbaapi/ooo/vba/msforms/XListBox.idl b/oovbaapi/ooo/vba/msforms/XListBox.idl index bdc0c6bfc660..63f9cce0bdf8 100644 --- a/oovbaapi/ooo/vba/msforms/XListBox.idl +++ b/oovbaapi/ooo/vba/msforms/XListBox.idl @@ -24,25 +24,27 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #ifndef __ooo_vba_msforms_XListBox_idl__ #define __ooo_vba_msforms_XListBox_idl__ -#ifndef __com_sun_star_uno_XInterface_idl__ -#include <com/sun/star/uno/XInterface.idl> -#endif +#include <ooo/vba/msforms/XNewFont.idl> + //============================================================================= module ooo { module vba { module msforms { - //============================================================================= -interface XListBox: com::sun::star::uno::XInterface + +interface XListBox { [attribute] any Value; [attribute] string Text; [attribute] boolean MultiSelect; [attribute] any ListIndex; - [attribute, readonly ] long ListCount; + [attribute, readonly] long ListCount; + [attribute, readonly] XNewFont Font; + void AddItem( [in] any pvargItem, [in] any pvargIndex ); void removeItem( [in] any index ); void Clear(); diff --git a/oovbaapi/ooo/vba/msforms/XNewFont.idl b/oovbaapi/ooo/vba/msforms/XNewFont.idl new file mode 100755 index 000000000000..755dd510b63a --- /dev/null +++ b/oovbaapi/ooo/vba/msforms/XNewFont.idl @@ -0,0 +1,57 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __ooo_vba_msforms_XNewFont_idl__ +#define __ooo_vba_msforms_XNewFont_idl__ + +#include <com/sun/star/uno/XInterface.idl> + +//============================================================================= + +module ooo { module vba { module msforms { + +//============================================================================= + +interface XNewFont +{ + [attribute] string Name; + [attribute] double Size; + [attribute] short Charset; + [attribute] short Weight; + [attribute] boolean Bold; + [attribute] boolean Italic; + [attribute] boolean Underline; + [attribute] boolean Strikethrough; +}; + +//============================================================================= + +}; }; }; + +//============================================================================= + +#endif diff --git a/oovbaapi/ooo/vba/msforms/XRadioButton.idl b/oovbaapi/ooo/vba/msforms/XRadioButton.idl index b2289ce33331..2aced0e92e30 100644 --- a/oovbaapi/ooo/vba/msforms/XRadioButton.idl +++ b/oovbaapi/ooo/vba/msforms/XRadioButton.idl @@ -24,21 +24,23 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #ifndef __ooo_vba_msforms_XRadioButton_idl__ #define __ooo_vba_msforms_XRadioButton_idl__ -#ifndef __com_sun_star_uno_XInterface_idl__ -#include <com/sun/star/uno/XInterface.idl> -#endif +#include <ooo/vba/msforms/XNewFont.idl> + //============================================================================= module ooo { module vba { module msforms { //============================================================================= -interface XRadioButton: com::sun::star::uno::XInterface + +interface XRadioButton { [attribute] string Caption; [attribute] any Value; + [attribute, readonly] XNewFont Font; }; //============================================================================= diff --git a/oovbaapi/ooo/vba/msforms/XTextBox.idl b/oovbaapi/ooo/vba/msforms/XTextBox.idl index 9c6b55e5ca6d..267fbf7f01cb 100644 --- a/oovbaapi/ooo/vba/msforms/XTextBox.idl +++ b/oovbaapi/ooo/vba/msforms/XTextBox.idl @@ -24,23 +24,28 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #ifndef __ooo_vba_msforms_XTextBox_idl__ #define __ooo_vba_msforms_XTextBox_idl__ -#ifndef __com_sun_star_uno_XInterface_idl__ -#include <com/sun/star/uno/XInterface.idl> -#endif +#include <ooo/vba/msforms/XNewFont.idl> + //============================================================================= module ooo { module vba { module msforms { //============================================================================= -interface XTextBox: com::sun::star::uno::XInterface + +interface XTextBox { [attribute] string Text; [attribute] any Value; [attribute] long MaxLength; [attribute] boolean Multiline; + [attribute] long SpecialEffect; + [attribute] long BorderStyle; + [attribute, readonly] long TextLength; + [attribute, readonly] XNewFont Font; }; //============================================================================= diff --git a/oovbaapi/ooo/vba/msforms/XToggleButton.idl b/oovbaapi/ooo/vba/msforms/XToggleButton.idl index e66eea54babb..923f7e1e2203 100644 --- a/oovbaapi/ooo/vba/msforms/XToggleButton.idl +++ b/oovbaapi/ooo/vba/msforms/XToggleButton.idl @@ -24,22 +24,21 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #ifndef __ooo_vba_msforms_XToggleButton_idl__ #define __ooo_vba_msforms_XToggleButton_idl__ -#ifndef __ooo_vba_msforms_XButton_idl__ -#include <ooo/vba/msforms/XButton.idl> -#endif -#ifndef __com_sun_star_uno_XInterface_idl__ -#include <com/sun/star/uno/XInterface.idl> -#endif +#include <ooo/vba/msforms/XCommandButton.idl> + //============================================================================= module ooo { module vba { module msforms { + //============================================================================= + interface XToggleButton { - interface XButton; + interface XCommandButton; [attribute] any Value; }; diff --git a/oovbaapi/ooo/vba/msforms/XUserForm.idl b/oovbaapi/ooo/vba/msforms/XUserForm.idl index c06aa2902b53..1e54dd1b8f41 100644 --- a/oovbaapi/ooo/vba/msforms/XUserForm.idl +++ b/oovbaapi/ooo/vba/msforms/XUserForm.idl @@ -39,6 +39,8 @@ interface XUserForm //interface ::ooo::vba::XHelperInterface; interface ::com::sun::star::script::XInvocation; [attribute] string Caption; + [attribute] double InnerWidth; + [attribute] double InnerHeight; void Show(); void Hide(); void RePaint(); diff --git a/oovbaapi/ooo/vba/msforms/makefile.mk b/oovbaapi/ooo/vba/msforms/makefile.mk index 56ac4caf87cb..1d7d9ee166e5 100644 --- a/oovbaapi/ooo/vba/msforms/makefile.mk +++ b/oovbaapi/ooo/vba/msforms/makefile.mk @@ -38,10 +38,13 @@ PACKAGE=ooo$/vba$/msforms IDLFILES=\ MSFormReturnTypes.idl \ + XCheckBox.idl \ XComboBox.idl \ - XButton.idl \ + XCommandButton.idl \ XControl.idl \ + XFrame.idl \ XLabel.idl \ + XNewFont.idl \ XTextBox.idl \ XRadioButton.idl \ XShape.idl \ diff --git a/package/inc/EncryptedDataHeader.hxx b/package/inc/EncryptedDataHeader.hxx index a166397cce34..be2c7643ec51 100644 --- a/package/inc/EncryptedDataHeader.hxx +++ b/package/inc/EncryptedDataHeader.hxx @@ -31,21 +31,25 @@ /* The structure of this header is as follows: - Header signature 4 bytes - Version number 2 bytes - Iteraction count 4 bytes - Size 4 bytes - Salt length 2 bytes - IV length 2 bytes - Digest length 2 bytes - MediaType length 2 bytes - Salt content X bytes - IV content X bytes - digest content X bytes - MediaType X bytes + Header signature 4 bytes + Version number 2 bytes + Iteraction count 4 bytes + Size 4 bytes + EncAlgorithm 4 bytes + DigestAlgorithm 4 bytes + DerivedKeySize 4 bytes + StartKeyAlgorithm 4 bytes + Salt length 2 bytes + IV length 2 bytes + Digest length 2 bytes + MediaType length 2 bytes + Salt content X bytes + IV content X bytes + digest content X bytes + MediaType X bytes */ -const sal_uInt32 n_ConstHeader = 0x0502474dL; // "MG\002\005" -const sal_Int32 n_ConstHeaderSize = 22; // + salt length + iv length + digest length + mediatype length +const sal_uInt32 n_ConstHeader = 0x05024d4dL; // "MM\002\005" +const sal_Int32 n_ConstHeaderSize = 38; // + salt length + iv length + digest length + mediatype length const sal_Int16 n_ConstCurrentVersion = 1; #endif diff --git a/package/inc/EncryptionData.hxx b/package/inc/EncryptionData.hxx index 66d74f739b9c..5d49ae2b7b0f 100644 --- a/package/inc/EncryptionData.hxx +++ b/package/inc/EncryptionData.hxx @@ -30,14 +30,52 @@ #include <com/sun/star/uno/Sequence.hxx> #include <cppuhelper/weak.hxx> -class EncryptionData : public cppu::OWeakObject +class BaseEncryptionData : public cppu::OWeakObject { public: - // On export aKey holds the derived key - // On import aKey holds the hash of the user enterred key - com::sun::star::uno::Sequence < sal_Int8 > aKey; - com::sun::star::uno::Sequence < sal_uInt8 > aSalt, aInitVector, aDigest; - sal_Int32 nIterationCount; - EncryptionData(): nIterationCount ( 0 ){} + ::com::sun::star::uno::Sequence< sal_Int8 > m_aSalt; + ::com::sun::star::uno::Sequence< sal_Int8 > m_aInitVector; + ::com::sun::star::uno::Sequence< sal_Int8 > m_aDigest; + sal_Int32 m_nIterationCount; + + BaseEncryptionData() + : m_nIterationCount ( 0 ){} + + BaseEncryptionData( const BaseEncryptionData& aData ) + : cppu::OWeakObject() + , m_aSalt( aData.m_aSalt ) + , m_aInitVector( aData.m_aInitVector ) + , m_aDigest( aData.m_aDigest ) + , m_nIterationCount( aData.m_nIterationCount ) + {} }; + +class EncryptionData : public BaseEncryptionData +{ +public: + ::com::sun::star::uno::Sequence < sal_Int8 > m_aKey; + sal_Int32 m_nEncAlg; + sal_Int32 m_nCheckAlg; + sal_Int32 m_nDerivedKeySize; + sal_Int32 m_nStartKeyGenID; + + EncryptionData( const BaseEncryptionData& aData, const ::com::sun::star::uno::Sequence< sal_Int8 >& aKey, sal_Int32 nEncAlg, sal_Int32 nCheckAlg, sal_Int32 nDerivedKeySize, sal_Int32 nStartKeyGenID ) + : BaseEncryptionData( aData ) + , m_aKey( aKey ) + , m_nEncAlg( nEncAlg ) + , m_nCheckAlg( nCheckAlg ) + , m_nDerivedKeySize( nDerivedKeySize ) + , m_nStartKeyGenID( nStartKeyGenID ) + {} + + EncryptionData( const EncryptionData& aData ) + : BaseEncryptionData( aData ) + , m_aKey( aData.m_aKey ) + , m_nEncAlg( aData.m_nEncAlg ) + , m_nCheckAlg( aData.m_nCheckAlg ) + , m_nDerivedKeySize( aData.m_nDerivedKeySize ) + , m_nStartKeyGenID( aData.m_nStartKeyGenID ) + {} +}; + #endif diff --git a/package/inc/PackageConstants.hxx b/package/inc/PackageConstants.hxx index a23a22fcb888..90c73edf2ba7 100644 --- a/package/inc/PackageConstants.hxx +++ b/package/inc/PackageConstants.hxx @@ -31,21 +31,39 @@ const sal_Int32 n_ConstBufferSize = 32768; const sal_Int32 n_ConstMaxMemoryStreamSize = 20480; + +// by calculation of the digest we read 32 bytes more ( if available ) +// it allows to ignore the padding if the stream is longer than n_ConstDigestDecrypt since we read at least two blocks more; +// if the stream is shorter or equal the padding will be done successfully const sal_Int32 n_ConstDigestLength = 1024; +const sal_Int32 n_ConstDigestDecrypt = 1056; // 1024 + 32 // the constants related to the manifest.xml entries -#define PKG_MNFST_MEDIATYPE 0 -#define PKG_MNFST_VERSION 1 -#define PKG_MNFST_FULLPATH 2 +#define PKG_MNFST_MEDIATYPE 0 +#define PKG_MNFST_VERSION 1 +#define PKG_MNFST_FULLPATH 2 -#define PKG_MNFST_INIVECTOR 3 -#define PKG_MNFST_SALT 4 -#define PKG_MNFST_ITERATION 5 -#define PKG_MNFST_UCOMPSIZE 6 -#define PKG_MNFST_DIGEST 7 +#define PKG_MNFST_INIVECTOR 3 +#define PKG_MNFST_SALT 4 +#define PKG_MNFST_ITERATION 5 +#define PKG_MNFST_UCOMPSIZE 6 +#define PKG_MNFST_DIGEST 7 +#define PKG_MNFST_ENCALG 8 +#define PKG_MNFST_STARTALG 9 +#define PKG_MNFST_DIGESTALG 10 +#define PKG_MNFST_DERKEYSIZE 11 #define PKG_SIZE_NOENCR_MNFST 3 -#define PKG_SIZE_ENCR_MNFST 8 +#define PKG_SIZE_ENCR_MNFST 12 + +// the properties related constants +#define ENCRYPTION_KEY_PROPERTY "EncryptionKey" +#define STORAGE_ENCRYPTION_KEYS_PROPERTY "StorageEncryptionKeys" +#define ENCRYPTION_ALGORITHMS_PROPERTY "EncryptionAlgorithms" +#define HAS_ENCRYPTED_ENTRIES_PROPERTY "HasEncryptedEntries" +#define HAS_NONENCRYPTED_ENTRIES_PROPERTY "HasNonEncryptedEntries" +#define IS_INCONSISTENT_PROPERTY "IsInconsistent" +#define MEDIATYPE_FALLBACK_USED_PROPERTY "MediaTypeFallbackUsed" #endif diff --git a/package/inc/ZipFile.hxx b/package/inc/ZipFile.hxx index be8158c0ba4e..2be52615c90b 100644 --- a/package/inc/ZipFile.hxx +++ b/package/inc/ZipFile.hxx @@ -31,11 +31,15 @@ #include <com/sun/star/packages/zip/ZipIOException.hpp> #include <com/sun/star/packages/NoEncryptionException.hpp> #include <com/sun/star/packages/WrongPasswordException.hpp> +#include <com/sun/star/xml/crypto/XCipherContext.hpp> +#include <com/sun/star/xml/crypto/XDigestContext.hpp> + +#include <rtl/ref.hxx> + #include <ByteGrabber.hxx> #include <HashMaps.hxx> -#ifndef _INFLATER_HXX #include <Inflater.hxx> -#endif +#include <EncryptionData.hxx> #include <mutexholder.hxx> @@ -43,10 +47,7 @@ namespace com { namespace sun { namespace star { namespace lang { class XMultiServiceFactory; } namespace ucb { class XProgressHandler; } } } } -namespace vos -{ - template < class T > class ORef; -} + /* * We impose arbitrary but reasonable limit on ZIP files. */ @@ -55,9 +56,7 @@ namespace vos #define ZIP_MAXEXTRA 256 #define ZIP_MAXENTRIES (0x10000 - 2) -typedef void* rtlCipher; class ZipEnumeration; -class EncryptionData; class ZipFile { @@ -70,20 +69,20 @@ protected: Inflater aInflater; com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xStream; com::sun::star::uno::Reference < com::sun::star::io::XSeekable > xSeek; - const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > xFactory; + const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > m_xFactory; ::com::sun::star::uno::Reference < ::com::sun::star::ucb::XProgressHandler > xProgressHandler; sal_Bool bRecoveryMode; com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createMemoryStream( ZipEntry & rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference < EncryptionData > &rData, sal_Bool bRawStream, sal_Bool bDecrypt ); com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createFileStream( ZipEntry & rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference < EncryptionData > &rData, sal_Bool bRawStream, sal_Bool bDecrypt ); @@ -91,12 +90,12 @@ protected: com::sun::star::uno::Reference < com::sun::star::io::XInputStream > createUnbufferedStream( SotMutexHolderRef aMutexHolder, ZipEntry & rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference < EncryptionData > &rData, sal_Int8 nStreamMode, sal_Bool bDecrypt, ::rtl::OUString aMediaType = ::rtl::OUString() ); - sal_Bool hasValidPassword ( ZipEntry & rEntry, const vos::ORef < EncryptionData > &rData ); + sal_Bool hasValidPassword ( ZipEntry & rEntry, const ::rtl::Reference < EncryptionData > &rData ); sal_Bool checkSizeAndCRC( const ZipEntry& aEntry ); @@ -127,44 +126,59 @@ public: void setInputStream ( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewStream ); ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawData( ZipEntry& rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference < EncryptionData > &rData, sal_Bool bDecrypt, SotMutexHolderRef aMutexHolder ) throw(::com::sun::star::io::IOException, ::com::sun::star::packages::zip::ZipException, ::com::sun::star::uno::RuntimeException); - static sal_Bool StaticGetCipher ( const vos::ORef < EncryptionData > & xEncryptionData, rtlCipher &rCipher, sal_Bool bDecode ); - static void StaticFillHeader ( const vos::ORef < EncryptionData > & rData, + static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > StaticGetDigestContextForChecksum( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xArgFactory, + const ::rtl::Reference< EncryptionData >& xEncryptionData ); + + static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > StaticGetCipher( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xArgFactory, + const ::rtl::Reference< EncryptionData >& xEncryptionData, + bool bEncrypt ); + + static void StaticFillHeader ( const ::rtl::Reference < EncryptionData > & rData, sal_Int32 nSize, const ::rtl::OUString& aMediaType, sal_Int8 * & pHeader ); - static sal_Bool StaticFillData ( vos::ORef < EncryptionData > & rData, + static sal_Bool StaticFillData ( ::rtl::Reference < BaseEncryptionData > & rData, + sal_Int32 &rEncAlgorithm, + sal_Int32 &rChecksumAlgorithm, + sal_Int32 &rDerivedKeySize, + sal_Int32 &rStartKeyGenID, sal_Int32 &rSize, ::rtl::OUString& aMediaType, - ::com::sun::star::uno::Reference < com::sun::star::io::XInputStream > &rStream ); + const ::com::sun::star::uno::Reference < com::sun::star::io::XInputStream >& rStream ); static ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > StaticGetDataFromRawStream( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xStream, - const vos::ORef < EncryptionData > &rData ) + const ::rtl::Reference < EncryptionData > &rData ) throw ( ::com::sun::star::packages::WrongPasswordException, ::com::sun::star::packages::zip::ZipIOException, ::com::sun::star::uno::RuntimeException ); - static sal_Bool StaticHasValidPassword ( const ::com::sun::star::uno::Sequence< sal_Int8 > &aReadBuffer, - const vos::ORef < EncryptionData > &rData ); + static sal_Bool StaticHasValidPassword ( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, + const ::com::sun::star::uno::Sequence< sal_Int8 > &aReadBuffer, + const ::rtl::Reference < EncryptionData > &rData ); ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ZipEntry& rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference < EncryptionData > &rData, sal_Bool bDecrypt, SotMutexHolderRef aMutexHolder ) throw(::com::sun::star::io::IOException, ::com::sun::star::packages::zip::ZipException, ::com::sun::star::uno::RuntimeException); ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getDataStream( ZipEntry& rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference < EncryptionData > &rData, sal_Bool bDecrypt, SotMutexHolderRef aMutexHolder ) throw ( ::com::sun::star::packages::WrongPasswordException, @@ -174,7 +188,7 @@ public: ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getWrappedRawStream( ZipEntry& rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference < EncryptionData > &rData, const ::rtl::OUString& aMediaType, SotMutexHolderRef aMutexHolder ) throw ( ::com::sun::star::packages::NoEncryptionException, diff --git a/package/inc/ZipOutputStream.hxx b/package/inc/ZipOutputStream.hxx index 345fe332b8cc..48fafb4c4a9c 100644 --- a/package/inc/ZipOutputStream.hxx +++ b/package/inc/ZipOutputStream.hxx @@ -27,43 +27,48 @@ #ifndef _ZIP_OUTPUT_STREAM_HXX #define _ZIP_OUTPUT_STREAM_HXX +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/xml/crypto/XCipherContext.hpp> +#include <com/sun/star/xml/crypto/XDigestContext.hpp> + #include <ByteChucker.hxx> -#ifndef _DEFLATER_HXX #include <Deflater.hxx> -#endif #include <CRC32.hxx> -#include <rtl/cipher.h> -#ifndef RTL_DIGEST_H_ -#include <rtl/digest.h> -#endif #include <vector> struct ZipEntry; -class EncryptionData; -namespace vos -{ - template < class T > class ORef; -} +class ZipPackageStream; + class ZipOutputStream { protected: - com::sun::star::uno::Reference < com::sun::star::io::XOutputStream > xStream; + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; + ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > xStream; + ::std::vector < ZipEntry * > aZipList; - com::sun::star::uno::Sequence < sal_Int8 > aBuffer, aEncryptionBuffer; + + ::com::sun::star::uno::Sequence< sal_Int8 > m_aDeflateBuffer; + ::rtl::OUString sComment; Deflater aDeflater; - rtlCipher aCipher; - rtlDigest aDigest; + + ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > m_xCipherContext; + ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > m_xDigestContext; + CRC32 aCRC; ByteChucker aChucker; ZipEntry *pCurrentEntry; sal_Int16 nMethod, nLevel, mnDigested; sal_Bool bFinished, bEncryptCurrentEntry; - EncryptionData *pCurrentEncryptData; + ZipPackageStream* m_pCurrentStream; public: - ZipOutputStream( com::sun::star::uno::Reference < com::sun::star::io::XOutputStream > &xOStream ); + ZipOutputStream( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, + const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > &xOStream ); ~ZipOutputStream(); // rawWrite to support a direct write to the output stream @@ -78,7 +83,7 @@ public: void SAL_CALL setLevel( sal_Int32 nNewLevel ) throw(::com::sun::star::uno::RuntimeException); void SAL_CALL putNextEntry( ZipEntry& rEntry, - vos::ORef < EncryptionData > &rData, + ZipPackageStream* pStream, sal_Bool bEncrypt = sal_False ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); void SAL_CALL closeEntry( ) diff --git a/package/inc/ZipPackage.hxx b/package/inc/ZipPackage.hxx index e3b8d44be183..f7b80f38b359 100644 --- a/package/inc/ZipPackage.hxx +++ b/package/inc/ZipPackage.hxx @@ -35,11 +35,12 @@ #include <com/sun/star/lang/XUnoTunnel.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/PropertyValue.hpp> -#ifndef _COM_SUN_STAR_LANG_XPSERVICEINFO_HPP_ +#include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> -#endif -#include <HashMaps.hxx> +#include <com/sun/star/xml/crypto/CipherID.hpp> #include <com/sun/star/lang/IllegalArgumentException.hpp> + +#include <HashMaps.hxx> #include <osl/file.h> #include <mutexholder.hxx> @@ -83,18 +84,24 @@ class ZipPackage : public cppu::WeakImplHelper7 protected: SotMutexHolderRef m_aMutexHolder; - ::com::sun::star::uno::Sequence < sal_Int8 > m_aEncryptionKey; - FolderHash m_aRecent; - ::rtl::OUString m_aURL; - sal_Bool m_bHasEncryptedEntries; - sal_Bool m_bHasNonEncryptedEntries; - sal_Bool m_bInconsistent; - sal_Bool m_bUseManifest; - sal_Bool m_bForceRecovery; + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > m_aStorageEncryptionKeys; + ::com::sun::star::uno::Sequence< sal_Int8 > m_aEncryptionKey; - sal_Bool m_bMediaTypeFallbackUsed; - sal_Int32 m_nFormat; - sal_Bool m_bAllowRemoveOnInsert; + FolderHash m_aRecent; + ::rtl::OUString m_aURL; + + sal_Int32 m_nStartKeyGenerationID; + sal_Int32 m_nChecksumDigestID; + sal_Int32 m_nCommonEncryptionID; + sal_Bool m_bHasEncryptedEntries; + sal_Bool m_bHasNonEncryptedEntries; + + sal_Bool m_bInconsistent; + sal_Bool m_bForceRecovery; + + sal_Bool m_bMediaTypeFallbackUsed; + sal_Int32 m_nFormat; + sal_Bool m_bAllowRemoveOnInsert; InitialisationMode m_eMode; @@ -121,15 +128,20 @@ protected: const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xTempStream ); public: - ZipPackage (const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > &xNewFactory); + ZipPackage( const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > &xNewFactory ); virtual ~ZipPackage( void ); ZipFile& getZipFile() { return *m_pZipFile;} - const com::sun::star::uno::Sequence < sal_Int8 > & getEncryptionKey ( ) {return m_aEncryptionKey;} sal_Int32 getFormat() const { return m_nFormat; } + sal_Int32 GetStartKeyGenID() const { return m_nStartKeyGenerationID; } + sal_Int32 GetEncAlgID() const { return m_nCommonEncryptionID; } + sal_Int32 GetChecksumAlgID() const { return m_nChecksumDigestID; } + sal_Int32 GetDefaultDerivedKeySize() const { return m_nCommonEncryptionID == ::com::sun::star::xml::crypto::CipherID::AES_CBC_W3C_PADDING ? 32 : 16; } + SotMutexHolderRef GetSharedMutexRef() { return m_aMutexHolder; } void ConnectTo( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream ); + const ::com::sun::star::uno::Sequence< sal_Int8 > GetEncryptionKey(); // XInitialization virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) diff --git a/package/source/zippackage/ZipPackageEntry.hxx b/package/inc/ZipPackageEntry.hxx index 767d84511a12..767d84511a12 100644 --- a/package/source/zippackage/ZipPackageEntry.hxx +++ b/package/inc/ZipPackageEntry.hxx diff --git a/package/inc/ZipPackageFolder.hxx b/package/inc/ZipPackageFolder.hxx index 635aca16ba92..6a80f0effdaa 100644 --- a/package/inc/ZipPackageFolder.hxx +++ b/package/inc/ZipPackageFolder.hxx @@ -90,10 +90,10 @@ public: void setPackageFormat_Impl( sal_Int32 nFormat ) { m_nFormat = nFormat; } void setRemoveOnInsertMode_Impl( sal_Bool bRemove ) { this->mbAllowRemoveOnInsert = bRemove; } - bool saveChild(const rtl::OUString &rShortName, const com::sun::star::packages::ContentInfo &rInfo, rtl::OUString &rPath, std::vector < com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > > &rManList, ZipOutputStream & rZipOut, com::sun::star::uno::Sequence < sal_Int8 > &rEncryptionKey, rtlRandomPool & rRandomPool); + bool saveChild(const rtl::OUString &rShortName, const com::sun::star::packages::ContentInfo &rInfo, rtl::OUString &rPath, std::vector < com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > > &rManList, ZipOutputStream & rZipOut, const com::sun::star::uno::Sequence < sal_Int8 >& rEncryptionKey, rtlRandomPool & rRandomPool); // Recursive functions - void saveContents(rtl::OUString &rPath, std::vector < com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > > &rManList, ZipOutputStream & rZipOut, com::sun::star::uno::Sequence < sal_Int8 > &rEncryptionKey, rtlRandomPool & rRandomPool) + void saveContents(rtl::OUString &rPath, std::vector < com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > > &rManList, ZipOutputStream & rZipOut, const com::sun::star::uno::Sequence< sal_Int8 > &rEncryptionKey, rtlRandomPool & rRandomPool) throw(::com::sun::star::uno::RuntimeException); void releaseUpwardRef(); diff --git a/package/source/zippackage/ZipPackageStream.hxx b/package/inc/ZipPackageStream.hxx index 38301d5e7d12..a3bbf73bf84c 100644 --- a/package/source/zippackage/ZipPackageStream.hxx +++ b/package/inc/ZipPackageStream.hxx @@ -29,15 +29,14 @@ #include <com/sun/star/io/XActiveDataSink.hpp> #include <com/sun/star/io/XSeekable.hpp> +#include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/packages/XDataSinkEncrSupport.hpp> + +#include <rtl/ref.hxx> +#include <cppuhelper/implbase2.hxx> + #include <ZipPackageEntry.hxx> -#ifndef _VOS_REF_H_ -#include <vos/ref.hxx> -#endif #include <EncryptionData.hxx> -#ifndef _CPPUHELPER_IMPLBASE2_HXX -#include <cppuhelper/implbase2.hxx> -#endif #include <mutexholder.hxx> #define PACKAGE_STREAM_NOTSET 0 @@ -60,7 +59,15 @@ protected: const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > m_xFactory; ZipPackage &rZipPackage; sal_Bool bToBeCompressed, bToBeEncrypted, bHaveOwnKey, bIsEncrypted; - vos::ORef < EncryptionData > xEncryptionData; + + ::rtl::Reference< BaseEncryptionData > m_xBaseEncryptionData; + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > m_aStorageEncryptionKeys; + ::com::sun::star::uno::Sequence< sal_Int8 > m_aEncryptionKey; + + sal_Int32 m_nImportedStartKeyAlgorithm; + sal_Int32 m_nImportedEncryptionAlgorithm; + sal_Int32 m_nImportedChecksumAlgorithm; + sal_Int32 m_nImportedDerivedKeySize; sal_uInt8 m_nStreamMode; sal_uInt32 m_nMagicalHackPos; @@ -72,7 +79,9 @@ protected: sal_Bool m_bFromManifest; - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& GetOwnSeekStream(); + bool m_bUseWinEncoding; + + ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetOwnSeekStream(); public: sal_Bool HasOwnKey () const { return bHaveOwnKey;} @@ -84,46 +93,56 @@ public: sal_Bool IsFromManifest() const { return m_bFromManifest; } void SetFromManifest( sal_Bool bValue ) { m_bFromManifest = bValue; } - vos::ORef < EncryptionData > & getEncryptionData () - { return xEncryptionData;} - const com::sun::star::uno::Sequence < sal_Int8 >& getKey () const - { return xEncryptionData->aKey;} - const com::sun::star::uno::Sequence < sal_uInt8 >& getInitialisationVector () const - { return xEncryptionData->aInitVector;} - const com::sun::star::uno::Sequence < sal_uInt8 >& getDigest () const - { return xEncryptionData->aDigest;} - const com::sun::star::uno::Sequence < sal_uInt8 >& getSalt () const - { return xEncryptionData->aSalt;} + ::rtl::Reference< EncryptionData > GetEncryptionData( bool bWinEncoding = false ); + void SetBaseEncryptionData( const ::rtl::Reference< BaseEncryptionData >& xData ); + + ::com::sun::star::uno::Sequence< sal_Int8 > GetEncryptionKey( bool bWinEncoding = false ); + + sal_Int32 GetStartKeyGenID(); + + const com::sun::star::uno::Sequence < sal_Int8 > getInitialisationVector () const + { return m_xBaseEncryptionData->m_aInitVector;} + const com::sun::star::uno::Sequence < sal_Int8 > getDigest () const + { return m_xBaseEncryptionData->m_aDigest;} + const com::sun::star::uno::Sequence < sal_Int8 > getSalt () const + { return m_xBaseEncryptionData->m_aSalt;} sal_Int32 getIterationCount () const - { return xEncryptionData->nIterationCount;} + { return m_xBaseEncryptionData->m_nIterationCount;} sal_Int32 getSize () const { return aEntry.nSize;} sal_uInt8 GetStreamMode() const { return m_nStreamMode; } sal_uInt32 GetMagicalHackPos() const { return m_nMagicalHackPos; } sal_uInt32 GetMagicalHackSize() const { return m_nMagicalHackSize; } + sal_Int32 GetEncryptionAlgorithm() const; + sal_Int32 GetBlockSize() const; void SetToBeCompressed (sal_Bool bNewValue) { bToBeCompressed = bNewValue;} void SetIsEncrypted (sal_Bool bNewValue) { bIsEncrypted = bNewValue;} + void SetImportedStartKeyAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedStartKeyAlgorithm = nAlgorithm; } + void SetImportedEncryptionAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedEncryptionAlgorithm = nAlgorithm; } + void SetImportedChecksumAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedChecksumAlgorithm = nAlgorithm; } + void SetImportedDerivedKeySize( sal_Int32 nSize ) { m_nImportedDerivedKeySize = nSize; } void SetToBeEncrypted (sal_Bool bNewValue) { bToBeEncrypted = bNewValue; - if ( bToBeEncrypted && xEncryptionData.isEmpty()) - xEncryptionData = new EncryptionData; - else if ( !bToBeEncrypted && !xEncryptionData.isEmpty() ) - xEncryptionData.unbind(); + if ( bToBeEncrypted && !m_xBaseEncryptionData.is()) + m_xBaseEncryptionData = new BaseEncryptionData; + else if ( !bToBeEncrypted && m_xBaseEncryptionData.is() ) + m_xBaseEncryptionData.clear(); } void SetPackageMember (sal_Bool bNewValue); + void setKey (const com::sun::star::uno::Sequence < sal_Int8 >& rNewKey ) - { xEncryptionData->aKey = rNewKey;} - void setInitialisationVector (const com::sun::star::uno::Sequence < sal_uInt8 >& rNewVector ) - { xEncryptionData->aInitVector = rNewVector;} - void setSalt (const com::sun::star::uno::Sequence < sal_uInt8 >& rNewSalt ) - { xEncryptionData->aSalt = rNewSalt;} - void setDigest (const com::sun::star::uno::Sequence < sal_uInt8 >& rNewDigest ) - { xEncryptionData->aDigest = rNewDigest;} + { m_aEncryptionKey = rNewKey; m_aStorageEncryptionKeys.realloc( 0 ); } + void setInitialisationVector (const com::sun::star::uno::Sequence < sal_Int8 >& rNewVector ) + { m_xBaseEncryptionData->m_aInitVector = rNewVector;} + void setSalt (const com::sun::star::uno::Sequence < sal_Int8 >& rNewSalt ) + { m_xBaseEncryptionData->m_aSalt = rNewSalt;} + void setDigest (const com::sun::star::uno::Sequence < sal_Int8 >& rNewDigest ) + { m_xBaseEncryptionData->m_aDigest = rNewDigest;} void setIterationCount (const sal_Int32 nNewCount) - { xEncryptionData->nIterationCount = nNewCount;} + { m_xBaseEncryptionData->m_nIterationCount = nNewCount;} void setSize (const sal_Int32 nNewSize); ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetOwnStreamNoWrap() { return xStream; } diff --git a/package/qa/storages/TestHelper.java b/package/qa/storages/TestHelper.java index dc28786513b1..1a67f2bfdf79 100644 --- a/package/qa/storages/TestHelper.java +++ b/package/qa/storages/TestHelper.java @@ -1434,24 +1434,24 @@ public class TestHelper { try { - byte pData[][] = new byte[1][22]; - if ( xHeadRawStream.readBytes( pData, 22 ) != 22 ) + byte pData[][] = new byte[1][38]; + if ( xHeadRawStream.readBytes( pData, 38 ) != 38 ) { Error( "Can't read header of encrypted stream '" + sStreamName + "' raw representations!" ); return false; } - if ( pData[0][0] != 0x4d || pData[0][1] != 0x47 || pData[0][2] != 0x02 || pData[0][3] != 0x05 ) + if ( pData[0][0] != 0x4d || pData[0][1] != 0x4d || pData[0][2] != 0x02 || pData[0][3] != 0x05 ) { Error( "No signature in the header of encrypted stream '" + sStreamName + "' raw representations!" ); return false; } int nVariableHeaderLength = - ( pData[0][14] + pData[0][15] * 0x100 ) // salt length - + ( pData[0][16] + pData[0][17] * 0x100 ) // iv length - + ( pData[0][18] + pData[0][19] * 0x100 ) // digest length - + ( pData[0][20] + pData[0][21] * 0x100 ); // mediatype length + ( pData[0][30] + pData[0][31] * 0x100 ) // salt length + + ( pData[0][32] + pData[0][33] * 0x100 ) // iv length + + ( pData[0][34] + pData[0][35] * 0x100 ) // digest length + + ( pData[0][36] + pData[0][37] * 0x100 ); // mediatype length xHeadRawStream.skipBytes( nVariableHeaderLength ); @@ -1467,7 +1467,7 @@ public class TestHelper { if ( nRead1 != nRead2 ) { - Error( "The encrypted stream '" + sStreamName + "' raw representations have different size!" ); + Error( "The encrypted stream '" + sStreamName + "' raw representations have different size! nRead1 - nRead2 = " + ( new Integer( nRead1 - nRead2 ) ).toString() ); return false; } diff --git a/package/source/manifest/Base64Codec.cxx b/package/source/manifest/Base64Codec.cxx index b9ffed0b0514..3539b2bb75b4 100644 --- a/package/source/manifest/Base64Codec.cxx +++ b/package/source/manifest/Base64Codec.cxx @@ -129,11 +129,11 @@ void ThreeByteToFourByte (const sal_uInt8* pBuffer, const sal_Int32 nStart, cons sBuffer.setCharAt(3, aBase64EncodeTable [nIndex]); } -void Base64Codec::encodeBase64(rtl::OUStringBuffer& aStrBuffer, const uno::Sequence < sal_uInt8 >& aPass) +void Base64Codec::encodeBase64(rtl::OUStringBuffer& aStrBuffer, const uno::Sequence < sal_Int8 >& aPass) { sal_Int32 i(0); sal_Int32 nBufferLength(aPass.getLength()); - const sal_uInt8* pBuffer = aPass.getConstArray(); + const sal_uInt8* pBuffer = reinterpret_cast< const sal_uInt8* >( aPass.getConstArray() ); while (i < nBufferLength) { rtl::OUStringBuffer sBuffer; @@ -183,7 +183,7 @@ void FourByteToThreeByte (sal_uInt8* pBuffer, sal_Int32& nLength, const sal_Int3 pBuffer[nStart + 2] = OneByte; } -void Base64Codec::decodeBase64(uno::Sequence< sal_uInt8 >& aBuffer, const rtl::OUString& sBuffer) +void Base64Codec::decodeBase64(uno::Sequence< sal_Int8 >& aBuffer, const rtl::OUString& sBuffer) { sal_Int32 nFirstLength((sBuffer.getLength() / 4) * 3); sal_uInt8* pBuffer = new sal_uInt8[nFirstLength]; @@ -199,6 +199,6 @@ void Base64Codec::decodeBase64(uno::Sequence< sal_uInt8 >& aBuffer, const rtl::O i += 4; k += 3; } - aBuffer = uno::Sequence<sal_uInt8>(pBuffer, nSecondLength); + aBuffer = uno::Sequence<sal_Int8>( reinterpret_cast< sal_Int8* >( pBuffer ), nSecondLength ); delete[] pBuffer; } diff --git a/package/source/manifest/Base64Codec.hxx b/package/source/manifest/Base64Codec.hxx index 04398c7bba29..f655ee54431a 100644 --- a/package/source/manifest/Base64Codec.hxx +++ b/package/source/manifest/Base64Codec.hxx @@ -39,7 +39,7 @@ class OUStringBuffer; class Base64Codec { public: - static void encodeBase64(rtl::OUStringBuffer& aStrBuffer, const com::sun::star::uno::Sequence<sal_uInt8>& aPass); - static void decodeBase64(com::sun::star::uno::Sequence<sal_uInt8>& aPass, const rtl::OUString& sBuffer); + static void encodeBase64(rtl::OUStringBuffer& aStrBuffer, const com::sun::star::uno::Sequence<sal_Int8>& aPass); + static void decodeBase64(com::sun::star::uno::Sequence<sal_Int8>& aPass, const rtl::OUString& sBuffer); }; #endif diff --git a/package/source/manifest/ManifestDefines.hxx b/package/source/manifest/ManifestDefines.hxx index d53337236bb2..a34648d892ec 100644 --- a/package/source/manifest/ManifestDefines.hxx +++ b/package/source/manifest/ManifestDefines.hxx @@ -53,15 +53,28 @@ #define ELEMENT_START_KEY_GENERATION "manifest:start-key-generation" #define ATTRIBUTE_START_KEY_GENERATION_NAME "manifest:start-key-generation-name" -#define ALGORITHM_SHA1 "SHA1" #define ATTRIBUTE_KEY_SIZE "manifest:key-size" -#define START_KEY_SIZE "20" #define ELEMENT_KEY_DERIVATION "manifest:key-derivation" #define ATTRIBUTE_KEY_DERIVATION_NAME "manifest:key-derivation-name" #define ATTRIBUTE_SALT "manifest:salt" #define ATTRIBUTE_ITERATION_COUNT "manifest:iteration-count" -#define CHECKSUM_TYPE "SHA1/1K" -#define DERIVED_KEY_SIZE "16" + +#define SHA256_URL "http://www.w3.org/2000/09/xmldsig#sha256" +#define SHA1_NAME "SHA1" +#define SHA1_URL "http://www.w3.org/2000/09/xmldsig#sha1" + +#define SHA1_1K_NAME "SHA1/1K" +#define SHA1_1K_URL "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#sha1-1k" +#define SHA256_1K_URL "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#sha256-1k" + +#define BLOWFISH_NAME "Blowfish CFB" +#define BLOWFISH_URL "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#blowfish" +#define AES128_URL "http://www.w3.org/2001/04/xmlenc#aes128-cbc" +#define AES192_URL "http://www.w3.org/2001/04/xmlenc#aes192-cbc" +#define AES256_URL "http://www.w3.org/2001/04/xmlenc#aes256-cbc" + +#define PBKDF2_NAME "PBKDF2" +#define PBKDF2_URL "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#pbkdf2" #endif diff --git a/package/source/manifest/ManifestExport.cxx b/package/source/manifest/ManifestExport.cxx index 6175bdc4e613..068ff48e2c69 100644 --- a/package/source/manifest/ManifestExport.cxx +++ b/package/source/manifest/ManifestExport.cxx @@ -27,86 +27,89 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_package.hxx" -#include <ManifestExport.hxx> -#include <ManifestDefines.hxx> -#ifndef _COM_SUN_STAR_XML_SAX_XATTRIBUTELIST_HXX -#include <com/sun/star/xml/sax/XAttributeList.hpp> -#endif -#include <rtl/ustrbuf.hxx> -#ifndef _BASE64_CODEC_HXX_ -#include <Base64Codec.hxx> -#endif + #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> -#ifndef _COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HXX #include <com/sun/star/xml/sax/XDocumentHandler.hpp> -#endif -#ifndef _COM_SUN_STAR_XML_BEANS_PROPERTYVALUE_HPP +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#include <com/sun/star/xml/crypto/DigestID.hpp> +#include <com/sun/star/xml/crypto/CipherID.hpp> #include <com/sun/star/beans/PropertyValue.hpp> -#endif +#include <com/sun/star/uno/RuntimeException.hpp> +#include <ManifestDefines.hxx> +#include <ManifestExport.hxx> +#include <Base64Codec.hxx> + +#include <rtl/ustrbuf.hxx> #include <comphelper/documentconstants.hxx> #include <comphelper/attributelist.hxx> -using namespace rtl; -using namespace com::sun::star::beans; -using namespace com::sun::star::uno; -using namespace com::sun::star::xml::sax; +using namespace ::com::sun::star; -ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const Sequence < Sequence < PropertyValue > > &rManList ) +ManifestExport::ManifestExport( uno::Reference< xml::sax::XDocumentHandler > xHandler, const uno::Sequence< uno::Sequence < beans::PropertyValue > >& rManList ) { - const OUString sFileEntryElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_FILE_ENTRY ) ); - const OUString sManifestElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_MANIFEST ) ); - const OUString sEncryptionDataElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ENCRYPTION_DATA ) ); - const OUString sAlgorithmElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ALGORITHM ) ); - const OUString sStartKeyGenerationElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_START_KEY_GENERATION ) ); - const OUString sKeyDerivationElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_KEY_DERIVATION ) ); - - const OUString sCdataAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CDATA ) ); - const OUString sMediaTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_MEDIA_TYPE ) ); - const OUString sVersionAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_VERSION ) ); - const OUString sFullPathAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_FULL_PATH ) ); - const OUString sSizeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SIZE ) ); - const OUString sKeySizeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_SIZE ) ); - const OUString sSaltAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SALT ) ); - const OUString sInitialisationVectorAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_INITIALISATION_VECTOR ) ); - const OUString sIterationCountAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ITERATION_COUNT ) ); - const OUString sAlgorithmNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ALGORITHM_NAME ) ); - const OUString sStartKeyGenerationNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_START_KEY_GENERATION_NAME ) ); - const OUString sKeyDerivationNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_DERIVATION_NAME ) ); - const OUString sChecksumTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM_TYPE ) ); - const OUString sChecksumAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM) ); - - const OUString sFullPathProperty ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); - const OUString sVersionProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ); - const OUString sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); - const OUString sIterationCountProperty ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ); - const OUString sSaltProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) ); - const OUString sInitialisationVectorProperty( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) ); - const OUString sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ); - const OUString sDigestProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) ); - - const OUString sWhiteSpace ( RTL_CONSTASCII_USTRINGPARAM ( " " ) ); - const OUString sBlowfish ( RTL_CONSTASCII_USTRINGPARAM ( "Blowfish CFB" ) ); - const OUString sPBKDF2 ( RTL_CONSTASCII_USTRINGPARAM ( "PBKDF2" ) ); - const OUString sChecksumType ( RTL_CONSTASCII_USTRINGPARAM ( CHECKSUM_TYPE ) ); - const OUString sStartKeySize ( RTL_CONSTASCII_USTRINGPARAM ( START_KEY_SIZE ) ); - const OUString sDerivedKeySize ( RTL_CONSTASCII_USTRINGPARAM ( DERIVED_KEY_SIZE ) ); - const OUString sSHA1 ( RTL_CONSTASCII_USTRINGPARAM ( ALGORITHM_SHA1 ) ); + const ::rtl::OUString sFileEntryElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_FILE_ENTRY ) ); + const ::rtl::OUString sManifestElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_MANIFEST ) ); + const ::rtl::OUString sEncryptionDataElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ENCRYPTION_DATA ) ); + const ::rtl::OUString sAlgorithmElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ALGORITHM ) ); + const ::rtl::OUString sStartKeyGenerationElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_START_KEY_GENERATION ) ); + const ::rtl::OUString sKeyDerivationElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_KEY_DERIVATION ) ); + + const ::rtl::OUString sCdataAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CDATA ) ); + const ::rtl::OUString sMediaTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_MEDIA_TYPE ) ); + const ::rtl::OUString sVersionAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_VERSION ) ); + const ::rtl::OUString sFullPathAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_FULL_PATH ) ); + const ::rtl::OUString sSizeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SIZE ) ); + const ::rtl::OUString sKeySizeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_SIZE ) ); + const ::rtl::OUString sSaltAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SALT ) ); + const ::rtl::OUString sInitialisationVectorAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_INITIALISATION_VECTOR ) ); + const ::rtl::OUString sIterationCountAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ITERATION_COUNT ) ); + const ::rtl::OUString sAlgorithmNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ALGORITHM_NAME ) ); + const ::rtl::OUString sStartKeyGenerationNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_START_KEY_GENERATION_NAME ) ); + const ::rtl::OUString sKeyDerivationNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_DERIVATION_NAME ) ); + const ::rtl::OUString sChecksumTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM_TYPE ) ); + const ::rtl::OUString sChecksumAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM) ); + + const ::rtl::OUString sFullPathProperty ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); + const ::rtl::OUString sVersionProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ); + const ::rtl::OUString sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); + const ::rtl::OUString sIterationCountProperty ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ); + const ::rtl::OUString sDerivedKeySizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DerivedKeySize" ) ); + const ::rtl::OUString sSaltProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) ); + const ::rtl::OUString sInitialisationVectorProperty( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) ); + const ::rtl::OUString sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ); + const ::rtl::OUString sDigestProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) ); + const ::rtl::OUString sEncryptionAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "EncryptionAlgorithm" ) ); + const ::rtl::OUString sStartKeyAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "StartKeyAlgorithm" ) ); + const ::rtl::OUString sDigestAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DigestAlgorithm" ) ); + + const ::rtl::OUString sWhiteSpace ( RTL_CONSTASCII_USTRINGPARAM ( " " ) ); + + const ::rtl::OUString sSHA256_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_URL ) ); + const ::rtl::OUString sSHA1_Name ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_NAME ) ); + + const ::rtl::OUString sSHA1_1k_Name ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_1K_NAME ) ); + const ::rtl::OUString sSHA256_1k_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_1K_URL ) ); + + const ::rtl::OUString sBlowfish_Name ( RTL_CONSTASCII_USTRINGPARAM ( BLOWFISH_NAME ) ); + const ::rtl::OUString sAES256_URL ( RTL_CONSTASCII_USTRINGPARAM ( AES256_URL ) ); + + const ::rtl::OUString sPBKDF2_Name ( RTL_CONSTASCII_USTRINGPARAM ( PBKDF2_NAME ) ); ::comphelper::AttributeList * pRootAttrList = new ::comphelper::AttributeList; - const Sequence < PropertyValue > *pSequence = rManList.getConstArray(); + const uno::Sequence < beans::PropertyValue > *pSequence = rManList.getConstArray(); const sal_uInt32 nManLength = rManList.getLength(); // find the mediatype of the document if any - OUString aDocMediaType; - OUString aDocVersion; + ::rtl::OUString aDocMediaType; + ::rtl::OUString aDocVersion; for (sal_uInt32 nInd = 0; nInd < nManLength ; nInd++ ) { - OUString aMediaType; - OUString aPath; - OUString aVersion; + ::rtl::OUString aMediaType; + ::rtl::OUString aPath; + ::rtl::OUString aVersion; - const PropertyValue *pValue = pSequence[nInd].getConstArray(); + const beans::PropertyValue *pValue = pSequence[nInd].getConstArray(); for (sal_uInt32 j = 0, nNum = pSequence[nInd].getLength(); j < nNum; j++, pValue++) { if (pValue->Name.equals (sMediaTypeProperty) ) @@ -126,7 +129,7 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S break; } - if ( aPath.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ) ) + if ( aPath.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ) ) { aDocMediaType = aMediaType; aDocVersion = aVersion; @@ -139,28 +142,28 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S sal_Bool bStoreStartKeyGeneration = sal_False; if ( aDocMediaType.getLength() ) { - if ( aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_WEB_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_GLOBAL_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_CHART_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_ASCII ) ) ) - - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_TEMPLATE_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_TEMPLATE_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_TEMPLATE_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_TEMPLATE_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_CHART_TEMPLATE_ASCII ) ) ) - || aDocMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_TEMPLATE_ASCII ) ) ) ) + if ( aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_WEB_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_GLOBAL_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_CHART_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_ASCII ) ) ) + + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_TEMPLATE_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_TEMPLATE_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_TEMPLATE_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_TEMPLATE_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_CHART_TEMPLATE_ASCII ) ) ) + || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_TEMPLATE_ASCII ) ) ) ) { // oasis format - pRootAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_XMLNS ) ), + pRootAttrList->AddAttribute ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_XMLNS ) ), sCdataAttribute, - OUString( RTL_CONSTASCII_USTRINGPARAM ( MANIFEST_OASIS_NAMESPACE ) ) ); + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( MANIFEST_OASIS_NAMESPACE ) ) ); bAcceptNonemptyVersion = sal_True; if ( aDocVersion.compareTo( ODFVER_012_TEXT ) >= 0 ) { @@ -168,7 +171,7 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S bStoreStartKeyGeneration = sal_True; // starting from ODF12 the version should be also in manifest:manifest element - pRootAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_VERSION ) ), + pRootAttrList->AddAttribute ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_VERSION ) ), sCdataAttribute, aDocVersion ); } @@ -177,21 +180,21 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S { // even if it is no SO6 format the namespace must be specified // thus SO6 format is used as default one - pRootAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_XMLNS ) ), + pRootAttrList->AddAttribute ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_XMLNS ) ), sCdataAttribute, - OUString( RTL_CONSTASCII_USTRINGPARAM ( MANIFEST_NAMESPACE ) ) ); + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( MANIFEST_NAMESPACE ) ) ); bProvideDTD = sal_True; } } - Reference < XAttributeList > xRootAttrList (pRootAttrList); + uno::Reference < xml::sax::XAttributeList > xRootAttrList (pRootAttrList); xHandler->startDocument(); - Reference < XExtendedDocumentHandler > xExtHandler ( xHandler, UNO_QUERY ); + uno::Reference < xml::sax::XExtendedDocumentHandler > xExtHandler ( xHandler, uno::UNO_QUERY ); if ( xExtHandler.is() && bProvideDTD ) { - OUString aDocType ( RTL_CONSTASCII_USTRINGPARAM ( MANIFEST_DOCTYPE ) ); + ::rtl::OUString aDocType ( RTL_CONSTASCII_USTRINGPARAM ( MANIFEST_DOCTYPE ) ); xExtHandler->unknown ( aDocType ); xHandler->ignorableWhitespace ( sWhiteSpace ); } @@ -200,9 +203,9 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S for (sal_uInt32 i = 0 ; i < nManLength ; i++) { ::comphelper::AttributeList *pAttrList = new ::comphelper::AttributeList; - const PropertyValue *pValue = pSequence[i].getConstArray(); - OUString aString; - const PropertyValue *pVector = NULL, *pSalt = NULL, *pIterationCount = NULL, *pDigest = NULL; + const beans::PropertyValue *pValue = pSequence[i].getConstArray(); + ::rtl::OUString aString; + const uno::Any *pVector = NULL, *pSalt = NULL, *pIterationCount = NULL, *pDigest = NULL, *pDigestAlg = NULL, *pEncryptAlg = NULL, *pStartKeyAlg = NULL, *pDerivedKeySize = NULL; for (sal_uInt32 j = 0, nNum = pSequence[i].getLength(); j < nNum; j++, pValue++) { if (pValue->Name.equals (sMediaTypeProperty) ) @@ -226,47 +229,87 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S { sal_Int32 nSize = 0; pValue->Value >>= nSize; - OUStringBuffer aBuffer; + ::rtl::OUStringBuffer aBuffer; aBuffer.append ( nSize ); pAttrList->AddAttribute ( sSizeAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); } else if (pValue->Name.equals (sInitialisationVectorProperty) ) - pVector = pValue; + pVector = &pValue->Value; else if (pValue->Name.equals (sSaltProperty) ) - pSalt = pValue; + pSalt = &pValue->Value; else if (pValue->Name.equals (sIterationCountProperty) ) - pIterationCount = pValue; + pIterationCount = &pValue->Value; else if (pValue->Name.equals ( sDigestProperty ) ) - pDigest = pValue; + pDigest = &pValue->Value; + else if (pValue->Name.equals ( sDigestAlgProperty ) ) + pDigestAlg = &pValue->Value; + else if (pValue->Name.equals ( sEncryptionAlgProperty ) ) + pEncryptAlg = &pValue->Value; + else if (pValue->Name.equals ( sStartKeyAlgProperty ) ) + pStartKeyAlg = &pValue->Value; + else if (pValue->Name.equals ( sDerivedKeySizeProperty ) ) + pDerivedKeySize = &pValue->Value; } + xHandler->ignorableWhitespace ( sWhiteSpace ); - Reference < XAttributeList > xAttrList ( pAttrList ); + uno::Reference < xml::sax::XAttributeList > xAttrList ( pAttrList ); xHandler->startElement( sFileEntryElement , xAttrList); - if ( pVector && pSalt && pIterationCount ) + if ( pVector && pSalt && pIterationCount && pDigest && pDigestAlg && pEncryptAlg && pStartKeyAlg && pDerivedKeySize ) { // ==== Encryption Data ::comphelper::AttributeList * pNewAttrList = new ::comphelper::AttributeList; - Reference < XAttributeList > xNewAttrList (pNewAttrList); - OUStringBuffer aBuffer; - Sequence < sal_uInt8 > aSequence; + uno::Reference < xml::sax::XAttributeList > xNewAttrList (pNewAttrList); + ::rtl::OUStringBuffer aBuffer; + uno::Sequence < sal_Int8 > aSequence; xHandler->ignorableWhitespace ( sWhiteSpace ); - if ( pDigest ) - { - pNewAttrList->AddAttribute ( sChecksumTypeAttribute, sCdataAttribute, sChecksumType ); - pDigest->Value >>= aSequence; - Base64Codec::encodeBase64 ( aBuffer, aSequence ); - pNewAttrList->AddAttribute ( sChecksumAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); - } + + // ==== Digest + ::rtl::OUString sChecksumType; + sal_Int32 nDigestAlgID = 0; + *pDigestAlg >>= nDigestAlgID; + if ( nDigestAlgID == xml::crypto::DigestID::SHA256_1K ) + sChecksumType = sSHA256_1k_URL; + else if ( nDigestAlgID == xml::crypto::DigestID::SHA1_1K ) + sChecksumType = sSHA1_1k_Name; + else + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected digest algorithm is provided!" ) ), uno::Reference< uno::XInterface >() ); + + pNewAttrList->AddAttribute ( sChecksumTypeAttribute, sCdataAttribute, sChecksumType ); + *pDigest >>= aSequence; + Base64Codec::encodeBase64( aBuffer, aSequence ); + pNewAttrList->AddAttribute ( sChecksumAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); + xHandler->startElement( sEncryptionDataElement , xNewAttrList); // ==== Algorithm pNewAttrList = new ::comphelper::AttributeList; xNewAttrList = pNewAttrList; - pNewAttrList->AddAttribute ( sAlgorithmNameAttribute, sCdataAttribute, sBlowfish ); + sal_Int32 nEncAlgID = 0; + sal_Int32 nDerivedKeySize = 0; + *pEncryptAlg >>= nEncAlgID; + *pDerivedKeySize >>= nDerivedKeySize; - pVector->Value >>= aSequence; + ::rtl::OUString sEncAlgName; + if ( nEncAlgID == xml::crypto::CipherID::AES_CBC_W3C_PADDING ) + { + OSL_ENSURE( nDerivedKeySize, "Unexpected key size is provided!" ); + if ( nDerivedKeySize != 32 ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected key size is provided!" ) ), uno::Reference< uno::XInterface >() ); + + sEncAlgName = sAES256_URL; + } + else if ( nEncAlgID == xml::crypto::CipherID::BLOWFISH_CFB_8 ) + { + sEncAlgName = sBlowfish_Name; + } + else + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpecte encryption algorithm is provided!" ) ), uno::Reference< uno::XInterface >() ); + + pNewAttrList->AddAttribute ( sAlgorithmNameAttribute, sCdataAttribute, sEncAlgName ); + + *pVector >>= aSequence; Base64Codec::encodeBase64 ( aBuffer, aSequence ); pNewAttrList->AddAttribute ( sInitialisationVectorAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); @@ -279,17 +322,20 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S pNewAttrList = new ::comphelper::AttributeList; xNewAttrList = pNewAttrList; - pNewAttrList->AddAttribute ( sKeyDerivationNameAttribute, sCdataAttribute, sPBKDF2 ); + pNewAttrList->AddAttribute ( sKeyDerivationNameAttribute, sCdataAttribute, sPBKDF2_Name ); if ( bStoreStartKeyGeneration ) - pNewAttrList->AddAttribute ( sKeySizeAttribute, sCdataAttribute, sDerivedKeySize ); + { + aBuffer.append( nDerivedKeySize ); + pNewAttrList->AddAttribute ( sKeySizeAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); + } sal_Int32 nCount = 0; - pIterationCount->Value >>= nCount; + *pIterationCount >>= nCount; aBuffer.append (nCount); pNewAttrList->AddAttribute ( sIterationCountAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); - pSalt->Value >>= aSequence; + *pSalt >>= aSequence; Base64Codec::encodeBase64 ( aBuffer, aSequence ); pNewAttrList->AddAttribute ( sSaltAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); @@ -306,8 +352,26 @@ ManifestExport::ManifestExport(Reference < XDocumentHandler > xHandler, const S pNewAttrList = new ::comphelper::AttributeList; xNewAttrList = pNewAttrList; - // currently SHA1 is used to generate 20-bytes start key - pNewAttrList->AddAttribute ( sStartKeyGenerationNameAttribute, sCdataAttribute, sSHA1 ); + ::rtl::OUString sStartKeyAlg; + ::rtl::OUString sStartKeySize; + sal_Int32 nStartKeyAlgID = 0; + *pStartKeyAlg >>= nStartKeyAlgID; + if ( nStartKeyAlgID == xml::crypto::DigestID::SHA256 ) + { + sStartKeyAlg = sSHA256_URL; + aBuffer.append( (sal_Int32)32 ); + sStartKeySize = aBuffer.makeStringAndClear(); + } + else if ( nStartKeyAlgID == xml::crypto::DigestID::SHA1 ) + { + sStartKeyAlg = sSHA1_Name; + aBuffer.append( (sal_Int32)20 ); + sStartKeySize = aBuffer.makeStringAndClear(); + } + else + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected start key algorithm is provided!" ) ), uno::Reference< uno::XInterface >() ); + + pNewAttrList->AddAttribute ( sStartKeyGenerationNameAttribute, sCdataAttribute, sStartKeyAlg ); pNewAttrList->AddAttribute ( sKeySizeAttribute, sCdataAttribute, sStartKeySize ); xHandler->ignorableWhitespace ( sWhiteSpace ); diff --git a/package/source/manifest/ManifestImport.cxx b/package/source/manifest/ManifestImport.cxx index 85de919a9acf..08999765cf7d 100644 --- a/package/source/manifest/ManifestImport.cxx +++ b/package/source/manifest/ManifestImport.cxx @@ -29,10 +29,11 @@ #include "precompiled_package.hxx" #include <ManifestImport.hxx> #include <ManifestDefines.hxx> -#ifndef _BASE64_CODEC_HXX_ #include <Base64Codec.hxx> -#endif + #include <com/sun/star/xml/sax/XAttributeList.hpp> +#include <com/sun/star/xml/crypto/DigestID.hpp> +#include <com/sun/star/xml/crypto/CipherID.hpp> #include <com/sun/star/beans/PropertyValue.hpp> using namespace com::sun::star::uno; @@ -45,12 +46,14 @@ using namespace std; ManifestImport::ManifestImport( vector < Sequence < PropertyValue > > & rNewManVector ) : nNumProperty ( 0 ) , bIgnoreEncryptData ( sal_False ) +, nDerivedKeySize( 0 ) , rManVector ( rNewManVector ) , sFileEntryElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_FILE_ENTRY ) ) , sManifestElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_MANIFEST ) ) , sEncryptionDataElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ENCRYPTION_DATA ) ) , sAlgorithmElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ALGORITHM ) ) +, sStartKeyAlgElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_START_KEY_GENERATION ) ) , sKeyDerivationElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_KEY_DERIVATION ) ) , sCdataAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CDATA ) ) @@ -61,7 +64,9 @@ ManifestImport::ManifestImport( vector < Sequence < PropertyValue > > & rNewManV , sSaltAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SALT ) ) , sInitialisationVectorAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_INITIALISATION_VECTOR ) ) , sIterationCountAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ITERATION_COUNT ) ) +, sKeySizeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_SIZE ) ) , sAlgorithmNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ALGORITHM_NAME ) ) +, sStartKeyAlgNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_START_KEY_GENERATION_NAME ) ) , sKeyDerivationNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_DERIVATION_NAME ) ) , sChecksumAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM ) ) , sChecksumTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM_TYPE ) ) @@ -70,15 +75,33 @@ ManifestImport::ManifestImport( vector < Sequence < PropertyValue > > & rNewManV , sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ) , sVersionProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ) , sIterationCountProperty ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ) +, sDerivedKeySizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DerivedKeySize" ) ) , sSaltProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) ) , sInitialisationVectorProperty ( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) ) , sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ) , sDigestProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) ) +, sEncryptionAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "EncryptionAlgorithm" ) ) +, sStartKeyAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "StartKeyAlgorithm" ) ) +, sDigestAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DigestAlgorithm" ) ) , sWhiteSpace ( RTL_CONSTASCII_USTRINGPARAM ( " " ) ) -, sBlowfish ( RTL_CONSTASCII_USTRINGPARAM ( "Blowfish CFB" ) ) -, sPBKDF2 ( RTL_CONSTASCII_USTRINGPARAM ( "PBKDF2" ) ) -, sChecksumType ( RTL_CONSTASCII_USTRINGPARAM ( CHECKSUM_TYPE ) ) + +, sSHA256_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_URL ) ) +, sSHA1_Name ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_NAME ) ) +, sSHA1_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_URL ) ) + +, sSHA256_1k_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_1K_URL ) ) +, sSHA1_1k_Name ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_1K_NAME ) ) +, sSHA1_1k_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_1K_URL ) ) + +, sBlowfish_Name ( RTL_CONSTASCII_USTRINGPARAM ( BLOWFISH_NAME ) ) +, sBlowfish_URL ( RTL_CONSTASCII_USTRINGPARAM ( BLOWFISH_URL ) ) +, sAES128_URL ( RTL_CONSTASCII_USTRINGPARAM ( AES128_URL ) ) +, sAES192_URL ( RTL_CONSTASCII_USTRINGPARAM ( AES192_URL ) ) +, sAES256_URL ( RTL_CONSTASCII_USTRINGPARAM ( AES256_URL ) ) + +, sPBKDF2_Name ( RTL_CONSTASCII_USTRINGPARAM ( PBKDF2_NAME ) ) +, sPBKDF2_URL ( RTL_CONSTASCII_USTRINGPARAM ( PBKDF2_URL ) ) { aStack.reserve( 10 ); } @@ -143,15 +166,32 @@ void SAL_CALL ManifestImport::startElement( const OUString& aName, const uno::Re if ( aConvertedName.equals( sEncryptionDataElement ) ) { // If this element exists, then this stream is encrypted and we need - // to store the initialisation vector, salt and iteration count used + // to import the initialisation vector, salt and iteration count used + nDerivedKeySize = 0; OUString aString = aConvertedAttribs[sChecksumTypeAttribute]; - if ( aString == sChecksumType && !bIgnoreEncryptData ) + if ( !bIgnoreEncryptData ) { - aString = aConvertedAttribs[sChecksumAttribute]; - Sequence < sal_uInt8 > aDecodeBuffer; - Base64Codec::decodeBase64 ( aDecodeBuffer, aString ); - aSequence[nNumProperty].Name = sDigestProperty; - aSequence[nNumProperty++].Value <<= aDecodeBuffer; + if ( aString.equals( sSHA1_1k_Name ) || aString.equals( sSHA1_1k_URL ) ) + { + aSequence[nNumProperty].Name = sDigestAlgProperty; + aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA1_1K; + } + else if ( aString.equals( sSHA256_1k_URL ) ) + { + aSequence[nNumProperty].Name = sDigestAlgProperty; + aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA256_1K; + } + else + bIgnoreEncryptData = sal_True; + + if ( !bIgnoreEncryptData ) + { + aString = aConvertedAttribs[sChecksumAttribute]; + uno::Sequence < sal_Int8 > aDecodeBuffer; + Base64Codec::decodeBase64( aDecodeBuffer, aString ); + aSequence[nNumProperty].Name = sDigestProperty; + aSequence[nNumProperty++].Value <<= aDecodeBuffer; + } } } } @@ -159,38 +199,98 @@ void SAL_CALL ManifestImport::startElement( const OUString& aName, const uno::Re { if ( aConvertedName == sAlgorithmElement ) { - OUString aString = aConvertedAttribs[sAlgorithmNameAttribute]; - if ( aString == sBlowfish && !bIgnoreEncryptData ) + if ( !bIgnoreEncryptData ) { - aString = aConvertedAttribs[sInitialisationVectorAttribute]; - Sequence < sal_uInt8 > aDecodeBuffer; - Base64Codec::decodeBase64 ( aDecodeBuffer, aString ); - aSequence[nNumProperty].Name = sInitialisationVectorProperty; - aSequence[nNumProperty++].Value <<= aDecodeBuffer; + OUString aString = aConvertedAttribs[sAlgorithmNameAttribute]; + if ( aString.equals( sBlowfish_Name ) || aString.equals( sBlowfish_URL ) ) + { + aSequence[nNumProperty].Name = sEncryptionAlgProperty; + aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::BLOWFISH_CFB_8; + } + else if ( aString.equals( sAES256_URL ) ) + { + aSequence[nNumProperty].Name = sEncryptionAlgProperty; + aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING; + OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 32, "Unexpected derived key length!" ); + nDerivedKeySize = 32; + } + else if ( aString.equals( sAES192_URL ) ) + { + aSequence[nNumProperty].Name = sEncryptionAlgProperty; + aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING; + OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 24, "Unexpected derived key length!" ); + nDerivedKeySize = 24; + } + else if ( aString.equals( sAES128_URL ) ) + { + aSequence[nNumProperty].Name = sEncryptionAlgProperty; + aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING; + OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 16, "Unexpected derived key length!" ); + nDerivedKeySize = 16; + } + else + bIgnoreEncryptData = sal_True; + + if ( !bIgnoreEncryptData ) + { + aString = aConvertedAttribs[sInitialisationVectorAttribute]; + uno::Sequence < sal_Int8 > aDecodeBuffer; + Base64Codec::decodeBase64 ( aDecodeBuffer, aString ); + aSequence[nNumProperty].Name = sInitialisationVectorProperty; + aSequence[nNumProperty++].Value <<= aDecodeBuffer; + } } - else - // If we don't recognise the algorithm, then the key derivation info - // is useless to us - bIgnoreEncryptData = sal_True; } else if ( aConvertedName == sKeyDerivationElement ) { - OUString aString = aConvertedAttribs[sKeyDerivationNameAttribute]; - if ( aString == sPBKDF2 && !bIgnoreEncryptData ) + if ( !bIgnoreEncryptData ) + { + OUString aString = aConvertedAttribs[sKeyDerivationNameAttribute]; + if ( aString.equals( sPBKDF2_Name ) || aString.equals( sPBKDF2_URL ) ) + { + aString = aConvertedAttribs[sSaltAttribute]; + uno::Sequence < sal_Int8 > aDecodeBuffer; + Base64Codec::decodeBase64 ( aDecodeBuffer, aString ); + aSequence[nNumProperty].Name = sSaltProperty; + aSequence[nNumProperty++].Value <<= aDecodeBuffer; + + aString = aConvertedAttribs[sIterationCountAttribute]; + aSequence[nNumProperty].Name = sIterationCountProperty; + aSequence[nNumProperty++].Value <<= aString.toInt32(); + + aString = aConvertedAttribs[sKeySizeAttribute]; + if ( aString.getLength() ) + { + sal_Int32 nKey = aString.toInt32(); + OSL_ENSURE( !nDerivedKeySize || nKey == nDerivedKeySize , "Provided derived key length differs from the expected one!" ); + nDerivedKeySize = nKey; + } + else if ( !nDerivedKeySize ) + nDerivedKeySize = 16; + else if ( nDerivedKeySize != 16 ) + OSL_ENSURE( sal_False, "Default derived key length differs from the expected one!" ); + + aSequence[nNumProperty].Name = sDerivedKeySizeProperty; + aSequence[nNumProperty++].Value <<= nDerivedKeySize; + } + else + bIgnoreEncryptData = sal_True; + } + } + else if ( aConvertedName == sStartKeyAlgElement ) + { + OUString aString = aConvertedAttribs[sStartKeyAlgNameAttribute]; + if ( aString.equals( sSHA256_URL ) ) + { + aSequence[nNumProperty].Name = sStartKeyAlgProperty; + aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA256; + } + else if ( aString.equals( sSHA1_Name ) || aString.equals( sSHA1_URL ) ) { - aString = aConvertedAttribs[sSaltAttribute]; - Sequence < sal_uInt8 > aDecodeBuffer; - Base64Codec::decodeBase64 ( aDecodeBuffer, aString ); - aSequence[nNumProperty].Name = sSaltProperty; - aSequence[nNumProperty++].Value <<= aDecodeBuffer; - - aString = aConvertedAttribs[sIterationCountAttribute]; - aSequence[nNumProperty].Name = sIterationCountProperty; - aSequence[nNumProperty++].Value <<= aString.toInt32(); + aSequence[nNumProperty].Name = sStartKeyAlgProperty; + aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA1; } else - // If we don't recognise the key derivation technique, then the - // algorithm info is useless to us bIgnoreEncryptData = sal_True; } } diff --git a/package/source/manifest/ManifestImport.hxx b/package/source/manifest/ManifestImport.hxx index f83c8b6c49df..8c42960c220f 100644 --- a/package/source/manifest/ManifestImport.hxx +++ b/package/source/manifest/ManifestImport.hxx @@ -66,12 +66,14 @@ protected: sal_Int16 nNumProperty; ManifestStack aStack; sal_Bool bIgnoreEncryptData; + sal_Int32 nDerivedKeySize; ::std::vector < ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > > & rManVector; const ::rtl::OUString sFileEntryElement; const ::rtl::OUString sManifestElement; const ::rtl::OUString sEncryptionDataElement; const ::rtl::OUString sAlgorithmElement; + const ::rtl::OUString sStartKeyAlgElement; const ::rtl::OUString sKeyDerivationElement; const ::rtl::OUString sCdataAttribute; @@ -82,7 +84,9 @@ protected: const ::rtl::OUString sSaltAttribute; const ::rtl::OUString sInitialisationVectorAttribute; const ::rtl::OUString sIterationCountAttribute; + const ::rtl::OUString sKeySizeAttribute; const ::rtl::OUString sAlgorithmNameAttribute; + const ::rtl::OUString sStartKeyAlgNameAttribute; const ::rtl::OUString sKeyDerivationNameAttribute; const ::rtl::OUString sChecksumAttribute; const ::rtl::OUString sChecksumTypeAttribute; @@ -91,15 +95,33 @@ protected: const ::rtl::OUString sMediaTypeProperty; const ::rtl::OUString sVersionProperty; const ::rtl::OUString sIterationCountProperty; + const ::rtl::OUString sDerivedKeySizeProperty; const ::rtl::OUString sSaltProperty; const ::rtl::OUString sInitialisationVectorProperty; const ::rtl::OUString sSizeProperty; const ::rtl::OUString sDigestProperty; + const ::rtl::OUString sEncryptionAlgProperty; + const ::rtl::OUString sStartKeyAlgProperty; + const ::rtl::OUString sDigestAlgProperty; const ::rtl::OUString sWhiteSpace; - const ::rtl::OUString sBlowfish; - const ::rtl::OUString sPBKDF2; - const ::rtl::OUString sChecksumType; + + const ::rtl::OUString sSHA256_URL; + const ::rtl::OUString sSHA1_Name; + const ::rtl::OUString sSHA1_URL; + + const ::rtl::OUString sSHA256_1k_URL; + const ::rtl::OUString sSHA1_1k_Name; + const ::rtl::OUString sSHA1_1k_URL; + + const ::rtl::OUString sBlowfish_Name; + const ::rtl::OUString sBlowfish_URL; + const ::rtl::OUString sAES128_URL; + const ::rtl::OUString sAES192_URL; + const ::rtl::OUString sAES256_URL; + + const ::rtl::OUString sPBKDF2_Name; + const ::rtl::OUString sPBKDF2_URL; ::rtl::OUString PushNameAndNamespaces( const ::rtl::OUString& aName, diff --git a/package/source/manifest/UnoRegister.cxx b/package/source/manifest/UnoRegister.cxx index 34dd874206e1..41b35c95af57 100644 --- a/package/source/manifest/UnoRegister.cxx +++ b/package/source/manifest/UnoRegister.cxx @@ -39,6 +39,7 @@ #include <zipfileaccess.hxx> using namespace ::rtl; +using namespace ::com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::lang; @@ -65,9 +66,9 @@ extern "C" void * SAL_CALL component_getFactory( const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ ) { void * pRet = 0; - Reference< XMultiServiceFactory > xSMgr( + uno::Reference< XMultiServiceFactory > xSMgr( reinterpret_cast< XMultiServiceFactory * >( pServiceManager ) ); - Reference< XSingleServiceFactory > xFactory; + uno::Reference< XSingleServiceFactory > xFactory; if (ManifestReader::static_getImplementationName().compareToAscii( pImplName ) == 0) xFactory = ManifestReader::createServiceFactory ( xSMgr ); diff --git a/package/source/xstor/owriteablestream.cxx b/package/source/xstor/owriteablestream.cxx index 9a5876b3e6df..2fd6a47c12ff 100644 --- a/package/source/xstor/owriteablestream.cxx +++ b/package/source/xstor/owriteablestream.cxx @@ -46,16 +46,18 @@ #include <comphelper/storagehelper.hxx> #include <comphelper/ofopxmlhelper.hxx> +#include <rtl/digest.h> +#include <rtl/logfile.hxx> +#include <rtl/instance.hxx> + +#include <PackageConstants.hxx> +#include <mutexholder.hxx> + #include "selfterminatefilestream.hxx" #include "owriteablestream.hxx" #include "oseekinstream.hxx" -#include "mutexholder.hxx" #include "xstorage.hxx" -#include <rtl/digest.h> -#include <rtl/logfile.hxx> -#include <rtl/instance.hxx> - // since the copying uses 32000 blocks usually, it makes sense to have a smaller size #define MAX_STORCACHE_SIZE 30000 @@ -110,15 +112,14 @@ namespace { //----------------------------------------------- void SetEncryptionKeyProperty_Impl( const uno::Reference< beans::XPropertySet >& xPropertySet, - const uno::Sequence< sal_Int8 >& aKey ) + const uno::Sequence< beans::NamedValue >& aKey ) { OSL_ENSURE( xPropertySet.is(), "No property set is provided!\n" ); if ( !xPropertySet.is() ) throw uno::RuntimeException(); - ::rtl::OUString aString_EncryptionKey = ::rtl::OUString::createFromAscii( "EncryptionKey" ); try { - xPropertySet->setPropertyValue( aString_EncryptionKey, uno::makeAny( aKey ) ); + xPropertySet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ), uno::makeAny( aKey ) ); } catch ( uno::Exception& aException ) { @@ -136,9 +137,8 @@ uno::Any GetEncryptionKeyProperty_Impl( const uno::Reference< beans::XPropertySe if ( !xPropertySet.is() ) throw uno::RuntimeException(); - ::rtl::OUString aString_EncryptionKey = ::rtl::OUString::createFromAscii( "EncryptionKey" ); try { - return xPropertySet->getPropertyValue( aString_EncryptionKey ); + return xPropertySet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) ); } catch ( uno::Exception& aException ) { @@ -151,16 +151,65 @@ uno::Any GetEncryptionKeyProperty_Impl( const uno::Reference< beans::XPropertySe } //----------------------------------------------- -sal_Bool SequencesEqual( uno::Sequence< sal_Int8 > aSequence1, uno::Sequence< sal_Int8 > aSequence2 ) +bool SequencesEqual( const uno::Sequence< sal_Int8 >& aSequence1, const uno::Sequence< sal_Int8 >& aSequence2 ) { if ( aSequence1.getLength() != aSequence2.getLength() ) - return sal_False; + return false; for ( sal_Int32 nInd = 0; nInd < aSequence1.getLength(); nInd++ ) if ( aSequence1[nInd] != aSequence2[nInd] ) - return sal_False; + return false; + + return true; +} + +//----------------------------------------------- +bool SequencesEqual( const uno::Sequence< beans::NamedValue >& aSequence1, const uno::Sequence< beans::NamedValue >& aSequence2 ) +{ + if ( aSequence1.getLength() != aSequence2.getLength() ) + return false; + + for ( sal_Int32 nInd = 0; nInd < aSequence1.getLength(); nInd++ ) + { + bool bHasMember = false; + uno::Sequence< sal_Int8 > aMember1; + sal_Int32 nMember1 = 0; + if ( ( aSequence1[nInd].Value >>= aMember1 ) ) + { + for ( sal_Int32 nInd2 = 0; nInd2 < aSequence2.getLength(); nInd2++ ) + { + if ( aSequence1[nInd].Name.equals( aSequence2[nInd2].Name ) ) + { + bHasMember = true; + + uno::Sequence< sal_Int8 > aMember2; + if ( !( aSequence2[nInd2].Value >>= aMember2 ) || !SequencesEqual( aMember1, aMember2 ) ) + return false; + } + } + } + else if ( ( aSequence1[nInd].Value >>= nMember1 ) ) + { + for ( sal_Int32 nInd2 = 0; nInd2 < aSequence2.getLength(); nInd2++ ) + { + if ( aSequence1[nInd].Name.equals( aSequence2[nInd2].Name ) ) + { + bHasMember = true; - return sal_True; + sal_Int32 nMember2 = 0; + if ( !( aSequence2[nInd2].Value >>= nMember2 ) || nMember1 != nMember2 ) + return false; + } + } + } + else + return false; + + if ( !bHasMember ) + return false; + } + + return true; } //----------------------------------------------- @@ -394,7 +443,7 @@ sal_Bool OWriteStream_Impl::IsEncrypted() // since a new key set to the package stream it should not be removed except the case when // the stream becomes nonencrypted - uno::Sequence< sal_Int8 > aKey; + uno::Sequence< beans::NamedValue > aKey; if ( bToBeEncr ) GetEncryptionKeyProperty_Impl( xPropSet ) >>= aKey; @@ -821,8 +870,8 @@ void OWriteStream_Impl::InsertStreamDirectly( const uno::Reference< io::XInputSt throw uno::RuntimeException(); // set to be encrypted but do not use encryption key - xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( "EncryptionKey" ), - uno::makeAny( uno::Sequence< sal_Int8 >() ) ); + xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( STORAGE_ENCRYPTION_KEYS_PROPERTY ), + uno::makeAny( uno::Sequence< beans::NamedValue >() ) ); xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( "Encrypted" ), uno::makeAny( sal_True ) ); } @@ -920,8 +969,8 @@ void OWriteStream_Impl::Commit() throw uno::RuntimeException(); // set to be encrypted but do not use encryption key - xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( "EncryptionKey" ), - uno::makeAny( uno::Sequence< sal_Int8 >() ) ); + xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( STORAGE_ENCRYPTION_KEYS_PROPERTY ), + uno::makeAny( uno::Sequence< beans::NamedValue >() ) ); xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( "Encrypted" ), uno::makeAny( sal_True ) ); } @@ -930,8 +979,8 @@ void OWriteStream_Impl::Commit() if ( m_nStorageType != embed::StorageFormats::PACKAGE ) throw uno::RuntimeException(); - xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( "EncryptionKey" ), - uno::makeAny( m_aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ) ) ); + xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( STORAGE_ENCRYPTION_KEYS_PROPERTY ), + uno::makeAny( m_aEncryptionData.getAsConstNamedValueList() ) ); } // the stream should be free soon, after package is stored @@ -1264,7 +1313,7 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMod } else { - SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ) ); + SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getAsConstNamedValueList() ); try { xResultStream = GetStream_Impl( nStreamMode, bHierarchyAccess ); @@ -1273,55 +1322,22 @@ uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMod m_bHasCachedEncryptionData = sal_True; m_aEncryptionData = aEncryptionData; } - catch( packages::WrongPasswordException& ) - { - // retry with different encoding - SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1MS1252, uno::Sequence< sal_Int8 >() ) ); - try { - // the stream must be cashed to be resaved - xResultStream = GetStream_Impl( nStreamMode | embed::ElementModes::SEEKABLE, bHierarchyAccess ); - - m_bUseCommonEncryption = sal_False; // very important to set it to false - m_bHasCachedEncryptionData = sal_True; - m_aEncryptionData = aEncryptionData; - - // the stream must be resaved with new password encryption - if ( nStreamMode & embed::ElementModes::WRITE ) - { - FillTempGetFileName(); - m_bHasDataToFlush = sal_True; - - // TODO/LATER: should the notification be done? - if ( m_pParent ) - m_pParent->m_bIsModified = sal_True; - } - } - catch( packages::WrongPasswordException& aWrongPasswordException ) - { - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() ); - AddLog( aWrongPasswordException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch ( uno::Exception& aException ) - { - AddLog( aException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - - OSL_ENSURE( sal_False, "Can't write encryption related properties!\n" ); - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() ); - throw io::IOException(); // TODO: - } - } - catch( uno::Exception& aException ) + catch( packages::WrongPasswordException& aWrongPasswordException ) { - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() ); - - AddLog( aException.Message ); + SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() ); + AddLog( aWrongPasswordException.Message ); AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); throw; } + catch ( uno::Exception& aException ) + { + AddLog( aException.Message ); + AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); + OSL_ENSURE( sal_False, "Can't write encryption related properties!\n" ); + SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() ); + throw io::IOException(); // TODO: + } } OSL_ENSURE( xResultStream.is(), "In case stream can not be retrieved an exception must be thrown!\n" ); @@ -1624,8 +1640,7 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar { // TODO: introduce last commited cashed password information and use it here // that means "use common pass" also should be remembered on flash - uno::Sequence< sal_Int8 > aNewKey = aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ); - uno::Sequence< sal_Int8 > aOldKey = aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1MS1252, uno::Sequence< sal_Int8 >() ); + uno::Sequence< beans::NamedValue > aKey = aEncryptionData.getAsConstNamedValueList(); uno::Reference< beans::XPropertySet > xProps( m_xPackageStream, uno::UNO_QUERY ); if ( !xProps.is() ) @@ -1636,9 +1651,9 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar if ( !bEncr ) throw packages::NoEncryptionException(); - uno::Sequence< sal_Int8 > aEncrKey; - xProps->getPropertyValue( ::rtl::OUString::createFromAscii( "EncryptionKey" ) ) >>= aEncrKey; - if ( !SequencesEqual( aNewKey, aEncrKey ) && !SequencesEqual( aOldKey, aEncrKey ) ) + uno::Sequence< beans::NamedValue > aPackKey; + xProps->getPropertyValue( ::rtl::OUString::createFromAscii( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) >>= aPackKey; + if ( !SequencesEqual( aKey, aPackKey ) ) throw packages::WrongPasswordException(); // the correct key must be set already @@ -1647,7 +1662,7 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar else { uno::Reference< beans::XPropertySet > xPropertySet( m_xPackageStream, uno::UNO_QUERY ); - SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ) ); + SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getAsConstNamedValueList() ); try { xDataToCopy = m_xPackageStream->getDataStream(); @@ -1655,42 +1670,19 @@ void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTar if ( !xDataToCopy.is() ) { OSL_ENSURE( sal_False, "Encrypted ZipStream must already have input stream inside!\n" ); - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() ); - } - } - catch( packages::WrongPasswordException& aWrongPasswordException ) - { - SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1MS1252, uno::Sequence< sal_Int8 >() ) ); - try { - xDataToCopy = m_xPackageStream->getDataStream(); - - if ( !xDataToCopy.is() ) - { - OSL_ENSURE( sal_False, "Encrypted ZipStream must already have input stream inside!\n" ); - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() ); - AddLog( aWrongPasswordException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - } - catch( uno::Exception& aException ) - { - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() ); - AddLog( aException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; + SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() ); } } catch( uno::Exception& aException ) { OSL_ENSURE( sal_False, "Can't open encrypted stream!\n" ); - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() ); + SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() ); AddLog( aException.Message ); AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); throw; } - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< sal_Int8 >() ); + SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() ); } // in case of new inserted package stream it is possible that input stream still was not set diff --git a/package/source/xstor/xstorage.cxx b/package/source/xstor/xstorage.cxx index 851fea6b086b..e3c965e790c3 100644 --- a/package/source/xstor/xstorage.cxx +++ b/package/source/xstor/xstorage.cxx @@ -45,6 +45,7 @@ #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/beans/NamedValue.hpp> +#include <PackageConstants.hxx> #include <cppuhelper/typeprovider.hxx> #include <cppuhelper/exc_hlp.hxx> @@ -571,7 +572,7 @@ void OStorage_Impl::GetStorageProperties() if ( !m_bControlMediaType ) { uno::Reference< beans::XPropertySet > xPackageProps( m_xPackage, uno::UNO_QUERY_THROW ); - xPackageProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaTypeFallbackUsed" ) ) ) >>= m_bMTFallbackUsed; + xPackageProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) ) >>= m_bMTFallbackUsed; xProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ) ) >>= m_aMediaType; m_bControlMediaType = sal_True; @@ -749,9 +750,17 @@ void OStorage_Impl::CopyToStorage( const uno::Reference< embed::XStorage >& xDes { try { - uno::Reference< embed::XEncryptionProtectedSource2 > xEncr( xDest, uno::UNO_QUERY ); + uno::Reference< embed::XEncryptionProtectedStorage > xEncr( xDest, uno::UNO_QUERY ); if ( xEncr.is() ) + { xEncr->setEncryptionData( GetCommonRootEncryptionData().getAsConstNamedValueList() ); + + uno::Sequence< beans::NamedValue > aAlgorithms; + uno::Reference< beans::XPropertySet > xPackPropSet( m_xPackage, uno::UNO_QUERY_THROW ); + xPackPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ) ) + >>= aAlgorithms; + xEncr->setEncryptionAlgorithms( aAlgorithms ); + } } catch( packages::NoEncryptionException& aNoEncryptionException ) { @@ -984,7 +993,9 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement, AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Handled exception" ) ) ); // If the common storage password does not allow to open the stream - // it must be copyed in raw way + // it could be copyed in raw way, the problem is that the StartKey should be the same + // in the ODF1.2 package, so an invalid package could be produced if the stream + // is copied from ODF1.1 package, where it is allowed to have different StartKeys uno::Reference< embed::XStorageRawAccess > xRawDest( xDest, uno::UNO_QUERY_THROW ); uno::Reference< io::XInputStream > xRawInStream = pElement->m_pStream->GetRawInStream(); xRawDest->insertRawEncrStreamElement( aName, xRawInStream ); @@ -2277,7 +2288,8 @@ uno::Any SAL_CALL OStorage::queryInterface( const uno::Type& rType ) ( rType , static_cast<embed::XStorageRawAccess*> ( this ) , static_cast<embed::XEncryptionProtectedSource*> ( this ) - , static_cast<embed::XEncryptionProtectedSource2*> ( this ) ); + , static_cast<embed::XEncryptionProtectedSource2*> ( this ) + , static_cast<embed::XEncryptionProtectedStorage*> ( this ) ); } else { @@ -2337,6 +2349,7 @@ uno::Sequence< uno::Type > SAL_CALL OStorage::getTypes() , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL ) , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) , ::getCppuType( ( const uno::Reference< util::XModifiable >* )NULL ) + , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedStorage >* )NULL ) , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource2 >* )NULL ) , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource >* )NULL ) , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); @@ -4696,18 +4709,23 @@ void SAL_CALL OStorage::removeEncryption() // TODO: check if the password is valid // update all streams that was encrypted with old password - uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY ); - if ( !xPackPropSet.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - + uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW ); try { - xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionKey" ) ), - uno::makeAny( uno::Sequence< sal_Int8 >() ) ); + xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ), + uno::makeAny( uno::Sequence< beans::NamedValue >() ) ); m_pImpl->m_bHasCommonEncryptionData = sal_False; m_pImpl->m_aCommonEncryptionData.clear(); } + catch( uno::RuntimeException& aRException ) + { + m_pImpl->AddLog( aRException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + + OSL_ENSURE( sal_False, "The call must not fail, it is pretty simple!" ); + throw; + } catch( uno::Exception& aException ) { m_pImpl->AddLog( aException.Message ); @@ -4761,24 +4779,161 @@ void SAL_CALL OStorage::setEncryptionData( const uno::Sequence< beans::NamedValu m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); uno::Any aCaught( ::cppu::getCaughtException() ); + throw lang::WrappedTargetRuntimeException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ), + uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ), + aCaught ); + } + + uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW ); + try + { + ::comphelper::SequenceAsHashMap aEncryptionMap( aEncryptionData ); + xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ), + uno::makeAny( aEncryptionMap.getAsConstNamedValueList() ) ); + + m_pImpl->m_bHasCommonEncryptionData = sal_True; + m_pImpl->m_aCommonEncryptionData = aEncryptionMap; + } + catch( uno::Exception& aException ) + { + m_pImpl->AddLog( aException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + + throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); + } + } +} + +//____________________________________________________________________________________________________ +// XEncryptionProtectedStorage +//____________________________________________________________________________________________________ + +//----------------------------------------------- +void SAL_CALL OStorage::setEncryptionAlgorithms( const uno::Sequence< beans::NamedValue >& aAlgorithms ) + throw (lang::IllegalArgumentException, uno::RuntimeException) +{ + RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::setEncryptionAlgorithms" ); + + ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); + + if ( !m_pImpl ) + { + ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); + throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); + } + + if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface must be visible only for package storage + + if ( !aAlgorithms.getLength() ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected empty encryption algorithms list!") ), uno::Reference< uno::XInterface >() ); + + OSL_ENSURE( m_pData->m_bIsRoot, "setEncryptionAlgorithms() method is not available for nonroot storages!\n" ); + if ( m_pData->m_bIsRoot ) + { + try { + m_pImpl->ReadContents(); + } + catch ( uno::RuntimeException& aRuntimeException ) + { + m_pImpl->AddLog( aRuntimeException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; + } + catch ( uno::Exception& aException ) + { + m_pImpl->AddLog( aException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + + uno::Any aCaught( ::cppu::getCaughtException() ); throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ), uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ), aCaught ); } - uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY ); - if ( !xPackPropSet.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - + uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW ); try { - ::comphelper::SequenceAsHashMap aEncryptionMap( aEncryptionData ); - xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionKey" ) ), - uno::makeAny( aEncryptionMap.getUnpackedValueOrDefault( PACKAGE_ENCRYPTIONDATA_SHA1UTF8, uno::Sequence< sal_Int8 >() ) ) ); + xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ), + uno::makeAny( aAlgorithms ) ); + } + catch ( uno::RuntimeException& aRuntimeException ) + { + m_pImpl->AddLog( aRuntimeException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; + } + catch( lang::IllegalArgumentException& aIAException ) + { + m_pImpl->AddLog( aIAException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - m_pImpl->m_bHasCommonEncryptionData = sal_True; - m_pImpl->m_aCommonEncryptionData = aEncryptionMap; + throw; + } + catch( uno::Exception& aException ) + { + m_pImpl->AddLog( aException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + + throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); + } + } +} + +//----------------------------------------------- +uno::Sequence< beans::NamedValue > SAL_CALL OStorage::getEncryptionAlgorithms() + throw (uno::RuntimeException) +{ + RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getEncryptionAlgorithms" ); + + ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); + + if ( !m_pImpl ) + { + ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); + throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); + } + + if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface must be visible only for package storage + + uno::Sequence< beans::NamedValue > aResult; + OSL_ENSURE( m_pData->m_bIsRoot, "getEncryptionAlgorithms() method is not available for nonroot storages!\n" ); + if ( m_pData->m_bIsRoot ) + { + try { + m_pImpl->ReadContents(); + } + catch ( uno::RuntimeException& aRuntimeException ) + { + m_pImpl->AddLog( aRuntimeException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; + } + catch ( uno::Exception& aException ) + { + m_pImpl->AddLog( aException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + + uno::Any aCaught( ::cppu::getCaughtException() ); + throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ), + uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), + uno::UNO_QUERY ), + aCaught ); + } + + uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW ); + try + { + xPackPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ) ) >>= aResult; + } + catch ( uno::RuntimeException& aRuntimeException ) + { + m_pImpl->AddLog( aRuntimeException.Message ); + m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); + throw; } catch( uno::Exception& aException ) { @@ -4789,6 +4944,7 @@ void SAL_CALL OStorage::setEncryptionData( const uno::Sequence< beans::NamedValu } } + return aResult; } @@ -4863,13 +5019,13 @@ void SAL_CALL OStorage::setPropertyValue( const ::rtl::OUString& aPropertyName, m_pImpl->m_bIsModified = sal_True; } } - else if ( ( m_pData->m_bIsRoot && ( aPropertyName.equalsAscii( "HasEncryptedEntries" ) - || aPropertyName.equalsAscii( "HasNonEncryptedEntries" ) - || aPropertyName.equalsAscii( "IsInconsistent" ) + else if ( ( m_pData->m_bIsRoot && ( aPropertyName.equalsAscii( HAS_ENCRYPTED_ENTRIES_PROPERTY ) + || aPropertyName.equalsAscii( HAS_NONENCRYPTED_ENTRIES_PROPERTY ) + || aPropertyName.equalsAscii( IS_INCONSISTENT_PROPERTY ) || aPropertyName.equalsAscii( "URL" ) || aPropertyName.equalsAscii( "RepairPackage" ) ) ) || aPropertyName.equalsAscii( "IsRoot" ) - || aPropertyName.equalsAscii( "MediaTypeFallbackUsed" ) ) + || aPropertyName.equalsAscii( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); else throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); @@ -4943,7 +5099,7 @@ uno::Any SAL_CALL OStorage::getPropertyValue( const ::rtl::OUString& aPropertyNa if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE && ( aPropertyName.equalsAscii( "MediaType" ) - || aPropertyName.equalsAscii( "MediaTypeFallbackUsed" ) + || aPropertyName.equalsAscii( MEDIATYPE_FALLBACK_USED_PROPERTY ) || aPropertyName.equalsAscii( "Version" ) ) ) { try @@ -5000,9 +5156,9 @@ uno::Any SAL_CALL OStorage::getPropertyValue( const ::rtl::OUString& aPropertyNa return uno::makeAny( sal_False ); // RepairPackage } else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE - && ( aPropertyName.equalsAscii( "HasEncryptedEntries" ) - || aPropertyName.equalsAscii( "HasNonEncryptedEntries" ) - || aPropertyName.equalsAscii( "IsInconsistent" ) ) ) + && ( aPropertyName.equalsAscii( HAS_ENCRYPTED_ENTRIES_PROPERTY ) + || aPropertyName.equalsAscii( HAS_NONENCRYPTED_ENTRIES_PROPERTY ) + || aPropertyName.equalsAscii( IS_INCONSISTENT_PROPERTY ) ) ) { try { m_pImpl->ReadContents(); diff --git a/package/source/xstor/xstorage.hxx b/package/source/xstor/xstorage.hxx index a49de3af6f3a..2baba695a55f 100644 --- a/package/source/xstor/xstorage.hxx +++ b/package/source/xstor/xstorage.hxx @@ -36,7 +36,7 @@ #include <com/sun/star/embed/XTransactedObject.hpp> #include <com/sun/star/embed/XTransactionBroadcaster.hpp> #include <com/sun/star/embed/XClassifiedObject.hpp> -#include <com/sun/star/embed/XEncryptionProtectedSource2.hpp> +#include <com/sun/star/embed/XEncryptionProtectedStorage.hpp> #include <com/sun/star/embed/XRelationshipAccess.hpp> #include <com/sun/star/util/XModifiable.hpp> #include <com/sun/star/container/XNameAccess.hpp> @@ -298,7 +298,7 @@ class OStorage : public ::com::sun::star::lang::XTypeProvider , public ::com::sun::star::util::XModifiable // , public ::com::sun::star::container::XNameAccess // , public ::com::sun::star::lang::XComponent - , public ::com::sun::star::embed::XEncryptionProtectedSource2 + , public ::com::sun::star::embed::XEncryptionProtectedStorage , public ::com::sun::star::beans::XPropertySet , public ::com::sun::star::embed::XOptimizedStorage , public ::com::sun::star::embed::XRelationshipAccess @@ -648,6 +648,13 @@ public: throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException ); + //____________________________________________________________________________________________________ + // XEncryptionProtectedStorage + //____________________________________________________________________________________________________ + + virtual void SAL_CALL setEncryptionAlgorithms( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aAlgorithms ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > SAL_CALL getEncryptionAlgorithms() throw (::com::sun::star::uno::RuntimeException); //____________________________________________________________________________________________________ // XPropertySet diff --git a/package/source/zipapi/EntryInputStream.cxx b/package/source/zipapi/EntryInputStream.cxx deleted file mode 100644 index 671ef7381f9d..000000000000 --- a/package/source/zipapi/EntryInputStream.cxx +++ /dev/null @@ -1,201 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <EntryInputStream.hxx> -#include <com/sun/star/packages/zip/ZipConstants.hpp> -#include <rtl/cipher.h> -#include <rtl/digest.h> -#include <memory.h> // for memcpy - -using namespace rtl; -using namespace com::sun::star; -using namespace com::sun::star::uno; -using namespace com::sun::star::packages::zip; -using namespace com::sun::star::packages::zip::ZipConstants; - -/** Provides access to the compressed data in a zipfile. - * - * 04/12/00 - uncompresses the stream into memory and seeks on it 'in memory' - * This and the ZipPackageBuffer used in the ZipOutputStream are memory hogs - * and will hopefully be replaced eventually - * - * Acts on the same underlying XInputStream as both the full Zip File and other - * EntryInputStreams, and thus must maintain its current position in the stream and - * seek to it before performing any reads. - */ - -EntryInputStream::EntryInputStream( Reference < io::XInputStream > xNewInput, - const ZipEntry & rNewEntry, - const vos::ORef < EncryptionData > &xEncryptData, - sal_Bool bGetRawStream) -: xStream( xNewInput ) -, xSeek( xNewInput, UNO_QUERY ) -, aEntry (rNewEntry ) -, nCurrent( 0 ) -, bHaveInMemory ( sal_False ) -, aInflater( sal_True ) -, aBuffer( 0 ) -, xEncryptionData (xEncryptData) -, bRawStream (bGetRawStream) -{ - if (bGetRawStream) - { - nUncompressedSize = aEntry.nMethod == DEFLATED ? aEntry.nCompressedSize : aEntry.nSize; - nEnd = aEntry.nOffset + nUncompressedSize; - } - else - { - nEnd = aEntry.nMethod == DEFLATED ? aEntry.nOffset + aEntry.nCompressedSize : aEntry.nOffset + aEntry.nSize; - nUncompressedSize = aEntry.nSize; - } -} -void EntryInputStream::readIntoMemory() - throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException) -{ - if (!bHaveInMemory) - { - Sequence < sal_Int8 > aReadBuffer; - xSeek->seek(aEntry.nOffset); - sal_Int32 nSize = aEntry.nMethod == DEFLATED ? aEntry.nCompressedSize : aEntry.nSize; - - if (nSize <0) - throw io::BufferSizeExceededException(::rtl::OUString(), *this); - - xStream->readBytes( aReadBuffer, nSize ); // Now it holds the raw stuff from disk - - if (xEncryptionData->aSalt.getLength()) - { - // Have salt, will travel - Sequence < sal_uInt8 > aDerivedKey (16); - rtlCipherError aResult; - Sequence < sal_Int8 > aDecryptBuffer; - - // Get the key - rtl_digest_PBKDF2 ( aDerivedKey.getArray(), 16, - reinterpret_cast < const sal_uInt8 * > (xEncryptionData->aKey.getConstArray()), - xEncryptionData->aKey.getLength(), - xEncryptionData->aSalt.getConstArray(), - xEncryptionData->aSalt.getLength(), - xEncryptionData->nIterationCount ); - - rtlCipher aCipher = rtl_cipher_create (rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream); - aResult = rtl_cipher_init( aCipher, rtl_Cipher_DirectionDecode, - aDerivedKey.getConstArray(), - aDerivedKey.getLength(), - xEncryptionData->aInitVector.getConstArray(), - xEncryptionData->aInitVector.getLength()); - OSL_ASSERT (aResult == rtl_Cipher_E_None); - aDecryptBuffer.realloc ( nSize ); - aResult = rtl_cipher_decode ( aCipher, - aReadBuffer.getConstArray(), - nSize, - reinterpret_cast < sal_uInt8 * > (aDecryptBuffer.getArray()), - nSize); - OSL_ASSERT (aResult == rtl_Cipher_E_None); - aReadBuffer = aDecryptBuffer; // Now it holds the decrypted data - } - if (bRawStream || aEntry.nMethod == STORED) - aBuffer = aReadBuffer; // bRawStream means the caller doesn't want it decompressed - else - { - aInflater.setInputSegment(aReadBuffer, 0, nSize ); - aBuffer.realloc( aEntry.nSize ); - aInflater.doInflate(aBuffer); - aInflater.end(); - } - bHaveInMemory = sal_True; - } -} -EntryInputStream::~EntryInputStream( void ) -{ -} - -sal_Int32 SAL_CALL EntryInputStream::readBytes( Sequence< sal_Int8 >& aData, - sal_Int32 nBytesToRead ) - throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException) -{ - if (nBytesToRead <0) - throw io::BufferSizeExceededException(::rtl::OUString(), *this); - if (!bHaveInMemory) - readIntoMemory(); - if (nBytesToRead + nCurrent > nUncompressedSize) - nBytesToRead = static_cast < sal_Int32> ( nUncompressedSize - nCurrent ); - - aData.realloc( nBytesToRead ); - memcpy(aData.getArray(), aBuffer.getConstArray() + nCurrent, nBytesToRead); - nCurrent+=nBytesToRead; - - return nBytesToRead; -} -sal_Int32 SAL_CALL EntryInputStream::readSomeBytes( Sequence< sal_Int8 >& aData, - sal_Int32 nMaxBytesToRead ) - throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException) -{ - return readBytes( aData, nMaxBytesToRead ); -} -void SAL_CALL EntryInputStream::skipBytes( sal_Int32 nBytesToSkip ) - throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, RuntimeException) -{ - if (nBytesToSkip < 0) - throw io::BufferSizeExceededException(::rtl::OUString(), *this); - - if (nBytesToSkip + nCurrent > nUncompressedSize) - nBytesToSkip = static_cast < sal_Int32 > (nUncompressedSize- nCurrent); - - nCurrent+=nBytesToSkip; -} -sal_Int32 SAL_CALL EntryInputStream::available( ) - throw(io::NotConnectedException, io::IOException, RuntimeException) -{ - return static_cast < sal_Int32 > (nUncompressedSize - nCurrent); -} -void SAL_CALL EntryInputStream::closeInput( ) - throw(io::NotConnectedException, io::IOException, RuntimeException) -{ -} - -void SAL_CALL EntryInputStream::seek( sal_Int64 location ) - throw(lang::IllegalArgumentException, io::IOException, RuntimeException) -{ - if (location > nUncompressedSize) - location = nUncompressedSize; - if (location <0) - location = 0; - nCurrent = location; -} -sal_Int64 SAL_CALL EntryInputStream::getPosition( ) - throw(io::IOException, RuntimeException) -{ - return nCurrent; -} -sal_Int64 SAL_CALL EntryInputStream::getLength( ) - throw(io::IOException, RuntimeException) -{ - return nUncompressedSize; -} diff --git a/package/source/zipapi/EntryInputStream.hxx b/package/source/zipapi/EntryInputStream.hxx deleted file mode 100644 index c04a5dc2d33b..000000000000 --- a/package/source/zipapi/EntryInputStream.hxx +++ /dev/null @@ -1,86 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#ifndef _ENTRY_INPUT_STREAM_HXX -#define _ENTRY_INPUT_STREAM_HXX - -#include <cppuhelper/implbase2.hxx> // helper for implementations -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/io/XSeekable.hpp> -#include <Inflater.hxx> -#include <com/sun/star/packages/zip/ZipEntry.hpp> -#ifndef _VOS_REF_H_ -#include <vos/ref.hxx> -#endif -#ifndef _ENCRYPTION_DATA_HXX -#include <EncryptionData.hxx> -#endif -class EntryInputStream : public cppu::WeakImplHelper2< com::sun::star::io::XInputStream, - com::sun::star::io::XSeekable > -{ -protected: - com::sun::star::uno::Reference< com::sun::star::io::XInputStream > xStream; - com::sun::star::uno::Reference< com::sun::star::io::XSeekable > xSeek; - sal_Int64 nEnd, nCurrent, nUncompressedSize; - sal_Bool bRawStream, bHaveInMemory, bEncrypted; - com::sun::star::uno::Sequence < sal_Int8 > aBuffer; - const vos::ORef < EncryptionData > xEncryptionData; - const com::sun::star::packages::zip::ZipEntry aEntry; - Inflater aInflater; - void readIntoMemory() - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); -public: - EntryInputStream( com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xInput, - const com::sun::star::packages::zip::ZipEntry &rNewEntry, - const vos::ORef < EncryptionData > &xEncryptData, - sal_Bool bGetRawStream = sal_False); - virtual ~EntryInputStream(); - - // XInputStream - virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL available( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeInput( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - // XSeekable - virtual void SAL_CALL seek( sal_Int64 location ) - throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getPosition( ) - throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getLength( ) - throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - /* -private: - void fill( void ); - */ -}; - -#endif diff --git a/package/source/zipapi/MemoryByteGrabber.hxx b/package/source/zipapi/MemoryByteGrabber.hxx index 8a8d96556bae..f27eaf4826ad 100644 --- a/package/source/zipapi/MemoryByteGrabber.hxx +++ b/package/source/zipapi/MemoryByteGrabber.hxx @@ -62,7 +62,7 @@ public: nBytesToRead = mnEnd - mnCurrent; aData.realloc ( nBytesToRead ); - memcpy ( aData.getArray(), mpBuffer + mnCurrent, nBytesToRead ); + rtl_copyMemory( aData.getArray(), mpBuffer + mnCurrent, nBytesToRead ); mnCurrent += nBytesToRead; return nBytesToRead; } diff --git a/package/source/zipapi/XFileStream.cxx b/package/source/zipapi/XFileStream.cxx deleted file mode 100644 index 9e7156ee82b3..000000000000 --- a/package/source/zipapi/XFileStream.cxx +++ /dev/null @@ -1,227 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <XFileStream.hxx> -#include <EncryptionData.hxx> -#include <com/sun/star/packages/zip/ZipConstants.hpp> -#include <PackageConstants.hxx> -#include <rtl/cipher.h> -#include <ZipFile.hxx> -#include <EncryptedDataHeader.hxx> -#include <com/sun/star/io/XOutputStream.hpp> - -using namespace com::sun::star::packages::zip::ZipConstants; -using namespace com::sun::star::io; -using namespace com::sun::star::uno; -using com::sun::star::lang::IllegalArgumentException; -using ::rtl::OUString; - -XFileStream::XFileStream( ZipEntry & rEntry, - com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewZipStream, - com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewTempStream, - const vos::ORef < EncryptionData > &rData, - sal_Bool bNewRawStream, - sal_Bool bIsEncrypted ) -: maEntry ( rEntry ) -, mxData ( rData ) -, mbRawStream ( bNewRawStream ) -, mbFinished ( sal_False ) -, mxTempIn ( xNewTempStream ) -, mxTempSeek ( xNewTempStream, UNO_QUERY ) -, mxTempOut ( xNewTempStream, UNO_QUERY ) -, mxZipStream ( xNewZipStream ) -, mxZipSeek ( xNewZipStream, UNO_QUERY ) -, maInflater ( sal_True ) -, maCipher ( NULL ) -{ - mnZipCurrent = maEntry.nOffset; - if (mbRawStream) - { - mnZipSize = maEntry.nMethod == DEFLATED ? maEntry.nCompressedSize : maEntry.nSize; - mnZipEnd = maEntry.nOffset + mnZipSize; - } - else - { - mnZipSize = maEntry.nSize; - mnZipEnd = maEntry.nMethod == DEFLATED ? maEntry.nOffset + maEntry.nCompressedSize : maEntry.nOffset + maEntry.nSize; - } - - if ( bIsEncrypted ) - { - sal_Bool bHaveEncryptData = ( !rData.isEmpty() && rData->aSalt.getLength() && rData->aInitVector.getLength() && rData->nIterationCount != 0 ) ? sal_True : sal_False; - - // if we have all the encrypted data, and want a raw stream, then prepend it to the stream, otherwise - // make a cipher so we can decrypt it - if ( bHaveEncryptData ) - { - if ( !bNewRawStream ) - ZipFile::StaticGetCipher ( rData, maCipher, sal_True ); - else - { - // Put in the EncryptedDataHeader - Sequence < sal_Int8 > aEncryptedDataHeader ( n_ConstHeaderSize + - rData->aInitVector.getLength() + - rData->aSalt.getLength() + - rData->aDigest.getLength() ); - sal_Int8 * pHeader = aEncryptedDataHeader.getArray(); - ZipFile::StaticFillHeader ( rData, rEntry.nSize, pHeader ); - mxTempOut->writeBytes ( aEncryptedDataHeader ); - mnZipSize += mxTempSeek->getPosition(); - mxTempSeek->seek ( 0 ); - } - } - } -} - -XFileStream::~XFileStream() -{ - if ( maCipher ) - rtl_cipher_destroy ( maCipher ); -} - -void XFileStream::fill( sal_Int64 nUntil) -{ - sal_Int32 nRead; - sal_Int64 nPosition = mxTempSeek->getPosition(); - mxTempSeek->seek ( mxTempSeek->getLength() ); - maBuffer.realloc ( n_ConstBufferSize ); - - while ( mxTempSeek->getLength() < nUntil ) - { - if ( !mbRawStream ) - { - while ( 0 == ( nRead = maInflater.doInflate( maBuffer ) ) ) - { - if ( maInflater.finished() || maInflater.needsDictionary() ) - { - // some error handling ? - return; - } - - sal_Int64 nDiff = mnZipEnd - mnZipCurrent; - if ( nDiff > 0 ) - { - mxZipSeek->seek ( mnZipCurrent ); - nRead = mxZipStream->readBytes ( maCompBuffer, static_cast < sal_Int32 > ( nDiff < n_ConstBufferSize ? nDiff : n_ConstBufferSize ) ); - mnZipCurrent += nRead; - // maCompBuffer now has the uncompressed data, check if we need to decrypt - // before passing to the Inflater - if ( maCipher ) - { - Sequence < sal_Int8 > aCryptBuffer ( nRead ); - rtlCipherError aResult = rtl_cipher_decode ( maCipher, - maCompBuffer.getConstArray(), - nRead, - reinterpret_cast < sal_uInt8 * > (aCryptBuffer.getArray()), - nRead); - OSL_ASSERT (aResult == rtl_Cipher_E_None); - maCompBuffer = aCryptBuffer; // Now it holds the decrypted data - - } - maInflater.setInput ( maCompBuffer ); - } - else - { - // some error handling ? - return; - } - } - } - else - { - sal_Int64 nDiff = mnZipEnd - mnZipCurrent; - mxZipSeek->seek ( mnZipCurrent ); - nRead = mxZipStream->readBytes ( maBuffer, static_cast < sal_Int32 > ( nDiff < n_ConstBufferSize ? nDiff : n_ConstBufferSize ) ); - mnZipCurrent += nRead; - } - Sequence < sal_Int8 > aTmpBuffer ( maBuffer.getConstArray(), nRead ); - mxTempOut->writeBytes ( aTmpBuffer ); - } - mxTempSeek->seek ( nPosition ); -} - -sal_Int32 SAL_CALL XFileStream::readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) -{ - sal_Int64 nPosition = mxTempSeek->getPosition(); - if ( nPosition + nBytesToRead > mnZipSize ) - nBytesToRead = static_cast < sal_Int32 > ( mnZipSize - nPosition ); - - sal_Int64 nUntil = nBytesToRead + nPosition + n_ConstBufferSize; - if (nUntil > mnZipSize ) - nUntil = mnZipSize; - if ( nUntil > mxTempSeek->getLength() ) - fill ( nUntil ); - sal_Int32 nRead = mxTempIn->readBytes ( aData, nBytesToRead ); - return nRead; -} - -sal_Int32 SAL_CALL XFileStream::readSomeBytes( Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) -{ - return readBytes ( aData, nMaxBytesToRead ); -} -void SAL_CALL XFileStream::skipBytes( sal_Int32 nBytesToSkip ) - throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) -{ - seek ( mxTempSeek->getPosition() + nBytesToSkip ); -} - -sal_Int32 SAL_CALL XFileStream::available( ) - throw( NotConnectedException, IOException, RuntimeException) -{ - return static_cast < sal_Int32 > ( mnZipSize - mxTempSeek->getPosition() ); -} - -void SAL_CALL XFileStream::closeInput( ) - throw( NotConnectedException, IOException, RuntimeException) -{ -} -void SAL_CALL XFileStream::seek( sal_Int64 location ) - throw( IllegalArgumentException, IOException, RuntimeException) -{ - if ( location > mnZipSize || location < 0 ) - throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - if ( location > mxTempSeek->getLength() ) - { - sal_Int64 nUntil = location + n_ConstBufferSize > mnZipSize ? mnZipSize : location + n_ConstBufferSize; - fill ( nUntil ); - } - mxTempSeek->seek ( location ); -} -sal_Int64 SAL_CALL XFileStream::getPosition( ) - throw(IOException, RuntimeException) -{ - return mxTempSeek->getPosition(); -} -sal_Int64 SAL_CALL XFileStream::getLength( ) - throw(IOException, RuntimeException) -{ - return mnZipSize; -} diff --git a/package/source/zipapi/XFileStream.hxx b/package/source/zipapi/XFileStream.hxx deleted file mode 100644 index 0cf82c5f35cd..000000000000 --- a/package/source/zipapi/XFileStream.hxx +++ /dev/null @@ -1,96 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#ifndef _XFILE_STREAM_HXX -#define _XFILE_STREAM_HXX - -#include <com/sun/star/lang/IllegalArgumentException.hpp> -#include <com/sun/star/io/XSeekable.hpp> -#include <com/sun/star/io/XInputStream.hpp> -#include <cppuhelper/implbase2.hxx> -#ifndef _VOS_REF_H_ -#include <vos/ref.hxx> -#endif -#ifndef _INFLATER_HXX -#include <Inflater.hxx> -#endif -#include <ZipEntry.hxx> - -namespace com { namespace sun { namespace star { - namespace io { class XOutputStream; } -} } } -class EncryptionData; -typedef void* rtlCipher; -class XFileStream : public cppu::WeakImplHelper2 -< - com::sun::star::io::XInputStream, - com::sun::star::io::XSeekable -> -{ -protected: - com::sun::star::uno::Reference < com::sun::star::io::XInputStream > mxZipStream; - com::sun::star::uno::Reference < com::sun::star::io::XSeekable > mxZipSeek; - com::sun::star::uno::Reference < com::sun::star::io::XInputStream > mxTempIn; - com::sun::star::uno::Reference < com::sun::star::io::XSeekable > mxTempSeek; - com::sun::star::uno::Reference < com::sun::star::io::XOutputStream > mxTempOut; - com::sun::star::uno::Sequence < sal_Int8 > maBuffer, maCompBuffer; - ZipEntry maEntry; - vos::ORef < EncryptionData > mxData; - rtlCipher maCipher; - Inflater maInflater; - sal_Bool mbRawStream, mbFinished; - sal_Int64 mnZipCurrent, mnZipEnd, mnZipSize; - void fill( sal_Int64 nUntil ); - -public: - XFileStream( ZipEntry & rEntry, - com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewZipStream, - com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewTempStream, - const vos::ORef < EncryptionData > &rData, - sal_Bool bRawStream, - sal_Bool bIsEncrypted ); - virtual ~XFileStream(); - - // XInputStream - virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL available( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeInput( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - // XSeekable - virtual void SAL_CALL seek( sal_Int64 location ) - throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getPosition( ) - throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getLength( ) - throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); -}; -#endif diff --git a/package/source/zipapi/XUnbufferedStream.cxx b/package/source/zipapi/XUnbufferedStream.cxx index a75af35914a1..e8e16329eccc 100644 --- a/package/source/zipapi/XUnbufferedStream.cxx +++ b/package/source/zipapi/XUnbufferedStream.cxx @@ -27,12 +27,14 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_package.hxx" -#include <XUnbufferedStream.hxx> -#include <EncryptionData.hxx> + #include <com/sun/star/packages/zip/ZipConstants.hpp> #include <com/sun/star/packages/zip/ZipIOException.hpp> +#include <com/sun/star/xml/crypto/CipherID.hpp> + +#include <XUnbufferedStream.hxx> +#include <EncryptionData.hxx> #include <PackageConstants.hxx> -#include <rtl/cipher.h> #include <ZipFile.hxx> #include <EncryptedDataHeader.hxx> #include <algorithm> @@ -47,6 +49,7 @@ using namespace ::com::sun::star; #endif +using namespace ::com::sun::star; using namespace com::sun::star::packages::zip::ZipConstants; using namespace com::sun::star::io; using namespace com::sun::star::uno; @@ -54,20 +57,22 @@ using com::sun::star::lang::IllegalArgumentException; using com::sun::star::packages::zip::ZipIOException; using ::rtl::OUString; -XUnbufferedStream::XUnbufferedStream( SotMutexHolderRef aMutexHolder, - ZipEntry & rEntry, - Reference < XInputStream > xNewZipStream, - const vos::ORef < EncryptionData > &rData, - sal_Int8 nStreamMode, - sal_Bool bIsEncrypted, - const ::rtl::OUString& aMediaType, - sal_Bool bRecoveryMode ) +XUnbufferedStream::XUnbufferedStream( + const uno::Reference< lang::XMultiServiceFactory >& xFactory, + SotMutexHolderRef aMutexHolder, + ZipEntry & rEntry, + Reference < XInputStream > xNewZipStream, + const ::rtl::Reference< EncryptionData >& rData, + sal_Int8 nStreamMode, + sal_Bool bIsEncrypted, + const ::rtl::OUString& aMediaType, + sal_Bool bRecoveryMode ) : maMutexHolder( aMutexHolder.Is() ? aMutexHolder : SotMutexHolderRef( new SotMutexHolder ) ) , mxZipStream ( xNewZipStream ) , mxZipSeek ( xNewZipStream, UNO_QUERY ) , maEntry ( rEntry ) , mxData ( rData ) -, maCipher ( NULL ) +, mnBlockSize( 1 ) , maInflater ( sal_True ) , mbRawStream ( nStreamMode == UNBUFF_STREAM_RAW || nStreamMode == UNBUFF_STREAM_WRAPPEDRAW ) , mbWrappedRaw ( nStreamMode == UNBUFF_STREAM_WRAPPEDRAW ) @@ -90,11 +95,15 @@ XUnbufferedStream::XUnbufferedStream( SotMutexHolderRef aMutexHolder, mnZipSize = maEntry.nSize; mnZipEnd = maEntry.nMethod == DEFLATED ? maEntry.nOffset + maEntry.nCompressedSize : maEntry.nOffset + maEntry.nSize; } - sal_Bool bHaveEncryptData = ( !rData.isEmpty() && rData->aSalt.getLength() && rData->aInitVector.getLength() && rData->nIterationCount != 0 ) ? sal_True : sal_False; + sal_Bool bHaveEncryptData = ( rData.is() && rData->m_aSalt.getLength() && rData->m_aInitVector.getLength() && rData->m_nIterationCount != 0 ) ? sal_True : sal_False; sal_Bool bMustDecrypt = ( nStreamMode == UNBUFF_STREAM_DATA && bHaveEncryptData && bIsEncrypted ) ? sal_True : sal_False; if ( bMustDecrypt ) - ZipFile::StaticGetCipher ( rData, maCipher, sal_True ); + { + m_xCipherContext = ZipFile::StaticGetCipher( xFactory, rData, false ); + mnBlockSize = ( rData->m_nEncAlg == xml::crypto::CipherID::AES_CBC_W3C_PADDING ? 16 : 1 ); + } + if ( bHaveEncryptData && mbWrappedRaw && bIsEncrypted ) { // if we have the data needed to decrypt it, but didn't want it decrypted (or @@ -103,24 +112,26 @@ XUnbufferedStream::XUnbufferedStream( SotMutexHolderRef aMutexHolder, // Make a buffer big enough to hold both the header and the data itself maHeader.realloc ( n_ConstHeaderSize + - rData->aInitVector.getLength() + - rData->aSalt.getLength() + - rData->aDigest.getLength() + + rData->m_aInitVector.getLength() + + rData->m_aSalt.getLength() + + rData->m_aDigest.getLength() + aMediaType.getLength() * sizeof( sal_Unicode ) ); sal_Int8 * pHeader = maHeader.getArray(); - ZipFile::StaticFillHeader ( rData, rEntry.nSize, aMediaType, pHeader ); + ZipFile::StaticFillHeader( rData, rEntry.nSize, aMediaType, pHeader ); mnHeaderToRead = static_cast < sal_Int16 > ( maHeader.getLength() ); } } // allows to read package raw stream -XUnbufferedStream::XUnbufferedStream( const Reference < XInputStream >& xRawStream, - const vos::ORef < EncryptionData > &rData ) +XUnbufferedStream::XUnbufferedStream( + const uno::Reference< lang::XMultiServiceFactory >& /*xFactory*/, + const Reference < XInputStream >& xRawStream, + const ::rtl::Reference< EncryptionData >& rData ) : maMutexHolder( new SotMutexHolder ) , mxZipStream ( xRawStream ) , mxZipSeek ( xRawStream, UNO_QUERY ) , mxData ( rData ) -, maCipher ( NULL ) +, mnBlockSize( 1 ) , maInflater ( sal_True ) , mbRawStream ( sal_False ) , mbWrappedRaw ( sal_False ) @@ -136,8 +147,8 @@ XUnbufferedStream::XUnbufferedStream( const Reference < XInputStream >& xRawStre OSL_ENSURE( mxZipSeek.is(), "The stream must be seekable!\n" ); // skip raw header, it must be already parsed to rData - mnZipCurrent = n_ConstHeaderSize + rData->aInitVector.getLength() + - rData->aSalt.getLength() + rData->aDigest.getLength(); + mnZipCurrent = n_ConstHeaderSize + rData->m_aInitVector.getLength() + + rData->m_aSalt.getLength() + rData->m_aDigest.getLength(); try { if ( mxZipSeek.is() ) @@ -149,13 +160,12 @@ XUnbufferedStream::XUnbufferedStream( const Reference < XInputStream >& xRawStre mnZipEnd = mnZipCurrent + mnZipSize; - ZipFile::StaticGetCipher ( rData, maCipher, sal_True ); + // the raw data will not be decrypted, no need for the cipher + // m_xCipherContext = ZipFile::StaticGetCipher( xFactory, rData, false ); } XUnbufferedStream::~XUnbufferedStream() { - if ( maCipher ) - rtl_cipher_destroy ( maCipher ); } sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) @@ -180,7 +190,7 @@ sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sa { sal_Int16 nHeadRead = static_cast< sal_Int16 >(( nRequestedBytes > mnHeaderToRead ? mnHeaderToRead : nRequestedBytes )); - memcpy ( aData.getArray(), maHeader.getConstArray() + maHeader.getLength() - mnHeaderToRead, nHeadRead ); + rtl_copyMemory ( aData.getArray(), maHeader.getConstArray() + maHeader.getLength() - mnHeaderToRead, nHeadRead ); mnHeaderToRead = mnHeaderToRead - nHeadRead; if ( nHeadRead < nRequestedBytes ) @@ -242,12 +252,17 @@ sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sa throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "Dictionaries are not supported!" ) ), Reference< XInterface >() ); - sal_Int32 nDiff = static_cast < sal_Int32 > ( mnZipEnd - mnZipCurrent ); + sal_Int32 nDiff = static_cast< sal_Int32 >( mnZipEnd - mnZipCurrent ); if ( nDiff > 0 ) { mxZipSeek->seek ( mnZipCurrent ); - sal_Int32 nToRead = std::min ( nDiff, std::max ( nRequestedBytes, static_cast< sal_Int32 >( 8192 ) ) ); - sal_Int32 nZipRead = mxZipStream->readBytes ( maCompBuffer, nToRead ); + + sal_Int32 nToRead = std::max( nRequestedBytes, static_cast< sal_Int32 >( 8192 ) ); + if ( mnBlockSize > 1 ) + nToRead = nToRead + mnBlockSize - nToRead % mnBlockSize; + nToRead = std::min( nDiff, nToRead ); + + sal_Int32 nZipRead = mxZipStream->readBytes( maCompBuffer, nToRead ); if ( nZipRead < nToRead ) throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "No expected data!" ) ), Reference< XInterface >() ); @@ -255,23 +270,22 @@ sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sa mnZipCurrent += nZipRead; // maCompBuffer now has the data, check if we need to decrypt // before passing to the Inflater - if ( maCipher ) + if ( m_xCipherContext.is() ) { if ( mbCheckCRC ) maCRC.update( maCompBuffer ); - Sequence < sal_Int8 > aCryptBuffer ( nZipRead ); - rtlCipherError aResult = - rtl_cipher_decode ( maCipher, - maCompBuffer.getConstArray(), - nZipRead, - reinterpret_cast < sal_uInt8 * > (aCryptBuffer.getArray()), - nZipRead); - if( aResult != rtl_Cipher_E_None ) { - OSL_ASSERT (aResult == rtl_Cipher_E_None); + maCompBuffer = m_xCipherContext->convertWithCipherContext( maCompBuffer ); + if ( mnZipCurrent == mnZipEnd ) + { + uno::Sequence< sal_Int8 > aSuffix = m_xCipherContext->finalizeCipherContextAndDispose(); + if ( aSuffix.getLength() ) + { + sal_Int32 nOldLen = maCompBuffer.getLength(); + maCompBuffer.realloc( nOldLen + aSuffix.getLength() ); + rtl_copyMemory( maCompBuffer.getArray() + nOldLen, aSuffix.getConstArray(), aSuffix.getLength() ); + } } - maCompBuffer = aCryptBuffer; // Now it holds the decrypted data - } maInflater.setInput ( maCompBuffer ); } @@ -290,7 +304,7 @@ sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sa if ( mbCheckCRC && ( !mbRawStream || mbWrappedRaw ) ) { - if ( !maCipher && !mbWrappedRaw ) + if ( !m_xCipherContext.is() && !mbWrappedRaw ) maCRC.update( aData ); #if 0 diff --git a/package/source/zipapi/XUnbufferedStream.hxx b/package/source/zipapi/XUnbufferedStream.hxx index 321ec10b8032..f8878c25979a 100644 --- a/package/source/zipapi/XUnbufferedStream.hxx +++ b/package/source/zipapi/XUnbufferedStream.hxx @@ -32,8 +32,10 @@ #include <com/sun/star/io/XSeekable.hpp> #include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/xml/crypto/XCipherContext.hpp> + #include <cppuhelper/implbase1.hxx> -#include <vos/ref.hxx> +#include <rtl/ref.hxx> #include <Inflater.hxx> #include <ZipEntry.hxx> #include <CRC32.hxx> @@ -44,7 +46,6 @@ #define UNBUFF_STREAM_WRAPPEDRAW 2 class EncryptionData; -typedef void* rtlCipher; class XUnbufferedStream : public cppu::WeakImplHelper1 < com::sun::star::io::XInputStream @@ -57,8 +58,9 @@ protected: com::sun::star::uno::Reference < com::sun::star::io::XSeekable > mxZipSeek; com::sun::star::uno::Sequence < sal_Int8 > maCompBuffer, maHeader; ZipEntry maEntry; - vos::ORef < EncryptionData > mxData; - rtlCipher maCipher; + ::rtl::Reference< EncryptionData > mxData; + sal_Int32 mnBlockSize; + ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > m_xCipherContext; Inflater maInflater; sal_Bool mbRawStream, mbWrappedRaw, mbFinished; sal_Int16 mnHeaderToRead; @@ -68,18 +70,21 @@ protected: public: XUnbufferedStream( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, SotMutexHolderRef aMutexHolder, ZipEntry & rEntry, com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewZipStream, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference< EncryptionData >& rData, sal_Int8 nStreamMode, sal_Bool bIsEncrypted, const ::rtl::OUString& aMediaType, sal_Bool bRecoveryMode ); // allows to read package raw stream - XUnbufferedStream( const com::sun::star::uno::Reference < com::sun::star::io::XInputStream >& xRawStream, - const vos::ORef < EncryptionData > &rData ); + XUnbufferedStream( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, + const com::sun::star::uno::Reference < com::sun::star::io::XInputStream >& xRawStream, + const ::rtl::Reference< EncryptionData >& rData ); virtual ~XUnbufferedStream(); diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx index dcd5669897e3..4827f6879853 100644 --- a/package/source/zipapi/ZipFile.cxx +++ b/package/source/zipapi/ZipFile.cxx @@ -27,31 +27,36 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_package.hxx" -#include <ZipFile.hxx> -#include <ZipEnumeration.hxx> + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/ucb/XProgressHandler.hpp> #include <com/sun/star/packages/zip/ZipConstants.hpp> -#include <rtl/cipher.h> +#include <com/sun/star/xml/crypto/XCipherContext.hpp> +#include <com/sun/star/xml/crypto/XDigestContext.hpp> +#include <com/sun/star/xml/crypto/XCipherContextSupplier.hpp> +#include <com/sun/star/xml/crypto/XDigestContextSupplier.hpp> +#include <com/sun/star/xml/crypto/CipherID.hpp> +#include <com/sun/star/xml/crypto/DigestID.hpp> + +#include <comphelper/storagehelper.hxx> +#include <comphelper/processfactory.hxx> #include <rtl/digest.h> -/* -#include <XMemoryStream.hxx> -#include <XFileStream.hxx> -*/ + +#include <vector> + +#include "blowfishcontext.hxx" +#include "sha1context.hxx" +#include <ZipFile.hxx> +#include <ZipEnumeration.hxx> #include <XUnbufferedStream.hxx> #include <PackageConstants.hxx> #include <EncryptedDataHeader.hxx> #include <EncryptionData.hxx> #include <MemoryByteGrabber.hxx> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/ucb/XProgressHandler.hpp> -#ifndef _CRC32_HXX_ #include <CRC32.hxx> -#endif -#include <string.h> // for memcpy -#include <vector> - -#include <comphelper/storagehelper.hxx> +#define AES_CBC_BLOCK_SIZE 16 using namespace vos; using namespace rtl; @@ -67,13 +72,13 @@ using namespace com::sun::star::packages::zip::ZipConstants; /** This class is used to read entries from a zip file */ -ZipFile::ZipFile( Reference < XInputStream > &xInput, const Reference < XMultiServiceFactory > &xNewFactory, sal_Bool bInitialise ) +ZipFile::ZipFile( uno::Reference < XInputStream > &xInput, const uno::Reference < XMultiServiceFactory > &xNewFactory, sal_Bool bInitialise ) throw(IOException, ZipException, RuntimeException) : aGrabber(xInput) , aInflater (sal_True) , xStream(xInput) , xSeek(xInput, UNO_QUERY) -, xFactory ( xNewFactory ) +, m_xFactory ( xNewFactory ) , bRecoveryMode( sal_False ) { if (bInitialise) @@ -81,20 +86,20 @@ ZipFile::ZipFile( Reference < XInputStream > &xInput, const Reference < XMultiSe if ( readCEN() == -1 ) { aEntries.clear(); - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "stream data looks to be broken" ) ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "stream data looks to be broken" ) ), uno::Reference < XInterface > () ); } } } -ZipFile::ZipFile( Reference < XInputStream > &xInput, const Reference < XMultiServiceFactory > &xNewFactory, sal_Bool bInitialise, sal_Bool bForceRecovery, Reference < XProgressHandler > xProgress ) +ZipFile::ZipFile( uno::Reference < XInputStream > &xInput, const uno::Reference < XMultiServiceFactory > &xNewFactory, sal_Bool bInitialise, sal_Bool bForceRecovery, uno::Reference < XProgressHandler > xProgress ) throw(IOException, ZipException, RuntimeException) : aGrabber(xInput) , aInflater (sal_True) , xStream(xInput) , xSeek(xInput, UNO_QUERY) -, xFactory ( xNewFactory ) +, m_xFactory ( xNewFactory ) , xProgressHandler( xProgress ) , bRecoveryMode( bForceRecovery ) { @@ -107,7 +112,7 @@ ZipFile::ZipFile( Reference < XInputStream > &xInput, const Reference < XMultiSe else if ( readCEN() == -1 ) { aEntries.clear(); - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "stream data looks to be broken" ) ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "stream data looks to be broken" ) ), uno::Reference < XInterface > () ); } } } @@ -117,55 +122,94 @@ ZipFile::~ZipFile() aEntries.clear(); } -void ZipFile::setInputStream ( Reference < XInputStream > xNewStream ) +void ZipFile::setInputStream ( uno::Reference < XInputStream > xNewStream ) { ::osl::MutexGuard aGuard( m_aMutex ); xStream = xNewStream; - xSeek = Reference < XSeekable > ( xStream, UNO_QUERY ); + xSeek = uno::Reference < XSeekable > ( xStream, UNO_QUERY ); aGrabber.setInputStream ( xStream ); } -sal_Bool ZipFile::StaticGetCipher ( const ORef < EncryptionData > & xEncryptionData, rtlCipher &rCipher, sal_Bool bDecode ) +uno::Reference< xml::crypto::XDigestContext > ZipFile::StaticGetDigestContextForChecksum( const uno::Reference< lang::XMultiServiceFactory >& xArgFactory, const ::rtl::Reference< EncryptionData >& xEncryptionData ) +{ + uno::Reference< xml::crypto::XDigestContext > xDigestContext; + if ( xEncryptionData->m_nCheckAlg == xml::crypto::DigestID::SHA256_1K ) + { + uno::Reference< lang::XMultiServiceFactory > xFactory = xArgFactory; + if ( !xFactory.is() ) + xFactory.set( comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW ); + + uno::Reference< xml::crypto::XDigestContextSupplier > xDigestContextSupplier( + xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.crypto.NSSInitializer" ) ) ), + uno::UNO_QUERY_THROW ); + + xDigestContext.set( xDigestContextSupplier->getDigestContext( xEncryptionData->m_nCheckAlg, uno::Sequence< beans::NamedValue >() ), uno::UNO_SET_THROW ); + } + else if ( xEncryptionData->m_nCheckAlg == xml::crypto::DigestID::SHA1_1K ) + xDigestContext.set( SHA1DigestContext::Create(), uno::UNO_SET_THROW ); + + return xDigestContext; +} + +uno::Reference< xml::crypto::XCipherContext > ZipFile::StaticGetCipher( const uno::Reference< lang::XMultiServiceFactory >& xArgFactory, const ::rtl::Reference< EncryptionData >& xEncryptionData, bool bEncrypt ) { - sal_Bool bResult = sal_False; - if ( ! xEncryptionData.isEmpty() ) + uno::Reference< xml::crypto::XCipherContext > xResult; + + try + { + uno::Sequence< sal_Int8 > aDerivedKey( xEncryptionData->m_nDerivedKeySize ); + if ( rtl_Digest_E_None != rtl_digest_PBKDF2( reinterpret_cast< sal_uInt8* >( aDerivedKey.getArray() ), + aDerivedKey.getLength(), + reinterpret_cast< const sal_uInt8 * > (xEncryptionData->m_aKey.getConstArray() ), + xEncryptionData->m_aKey.getLength(), + reinterpret_cast< const sal_uInt8 * > ( xEncryptionData->m_aSalt.getConstArray() ), + xEncryptionData->m_aSalt.getLength(), + xEncryptionData->m_nIterationCount ) ) + { + throw ZipIOException( ::rtl::OUString::createFromAscii( "Can not create derived key!\n" ), + uno::Reference< XInterface >() ); + } + + if ( xEncryptionData->m_nEncAlg == xml::crypto::CipherID::AES_CBC_W3C_PADDING ) + { + uno::Reference< lang::XMultiServiceFactory > xFactory = xArgFactory; + if ( !xFactory.is() ) + xFactory.set( comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW ); + + uno::Reference< xml::crypto::XCipherContextSupplier > xCipherContextSupplier( + xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.crypto.NSSInitializer" ) ) ), + uno::UNO_QUERY_THROW ); + + xResult = xCipherContextSupplier->getCipherContext( xEncryptionData->m_nEncAlg, aDerivedKey, xEncryptionData->m_aInitVector, bEncrypt, uno::Sequence< beans::NamedValue >() ); + } + else if ( xEncryptionData->m_nEncAlg == xml::crypto::CipherID::BLOWFISH_CFB_8 ) + { + xResult = BlowfishCFB8CipherContext::Create( aDerivedKey, xEncryptionData->m_aInitVector, bEncrypt ); + } + else + { + throw ZipIOException( ::rtl::OUString::createFromAscii( "Unknown cipher algorithm is requested!\n" ), + uno::Reference< XInterface >() ); + } + } + catch( uno::Exception& ) { - Sequence < sal_uInt8 > aDerivedKey (16); - rtlCipherError aResult; - Sequence < sal_Int8 > aDecryptBuffer; - - // Get the key - rtl_digest_PBKDF2 ( aDerivedKey.getArray(), 16, - reinterpret_cast < const sal_uInt8 * > (xEncryptionData->aKey.getConstArray() ), - xEncryptionData->aKey.getLength(), - reinterpret_cast < const sal_uInt8 * > ( xEncryptionData->aSalt.getConstArray() ), - xEncryptionData->aSalt.getLength(), - xEncryptionData->nIterationCount ); - - rCipher = rtl_cipher_create (rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream); - aResult = rtl_cipher_init( rCipher, bDecode ? rtl_Cipher_DirectionDecode : rtl_Cipher_DirectionEncode, - aDerivedKey.getConstArray(), - aDerivedKey.getLength(), - reinterpret_cast < const sal_uInt8 * > ( xEncryptionData->aInitVector.getConstArray() ), - xEncryptionData->aInitVector.getLength()); - OSL_ASSERT (aResult == rtl_Cipher_E_None); - - bResult = ( aResult == rtl_Cipher_E_None ); + OSL_ENSURE( sal_False, "Can not create cipher context!" ); } - return bResult; + return xResult; } -void ZipFile::StaticFillHeader ( const ORef < EncryptionData > & rData, +void ZipFile::StaticFillHeader( const ::rtl::Reference< EncryptionData >& rData, sal_Int32 nSize, const ::rtl::OUString& aMediaType, sal_Int8 * & pHeader ) { // I think it's safe to restrict vector and salt length to 2 bytes ! - sal_Int16 nIVLength = static_cast < sal_Int16 > ( rData->aInitVector.getLength() ); - sal_Int16 nSaltLength = static_cast < sal_Int16 > ( rData->aSalt.getLength() ); - sal_Int16 nDigestLength = static_cast < sal_Int16 > ( rData->aDigest.getLength() ); + sal_Int16 nIVLength = static_cast < sal_Int16 > ( rData->m_aInitVector.getLength() ); + sal_Int16 nSaltLength = static_cast < sal_Int16 > ( rData->m_aSalt.getLength() ); + sal_Int16 nDigestLength = static_cast < sal_Int16 > ( rData->m_aDigest.getLength() ); sal_Int16 nMediaTypeLength = static_cast < sal_Int16 > ( aMediaType.getLength() * sizeof( sal_Unicode ) ); // First the header @@ -179,7 +223,7 @@ void ZipFile::StaticFillHeader ( const ORef < EncryptionData > & rData, *(pHeader++) = ( n_ConstCurrentVersion >> 8 ) & 0xFF; // Then the iteration Count - sal_Int32 nIterationCount = rData->nIterationCount; + sal_Int32 nIterationCount = rData->m_nIterationCount; *(pHeader++) = static_cast< sal_Int8 >(( nIterationCount >> 0 ) & 0xFF); *(pHeader++) = static_cast< sal_Int8 >(( nIterationCount >> 8 ) & 0xFF); *(pHeader++) = static_cast< sal_Int8 >(( nIterationCount >> 16 ) & 0xFF); @@ -191,6 +235,34 @@ void ZipFile::StaticFillHeader ( const ORef < EncryptionData > & rData, *(pHeader++) = static_cast< sal_Int8 >(( nSize >> 16 ) & 0xFF); *(pHeader++) = static_cast< sal_Int8 >(( nSize >> 24 ) & 0xFF); + // Then the encryption algorithm + sal_Int32 nEncAlgID = rData->m_nEncAlg; + *(pHeader++) = static_cast< sal_Int8 >(( nEncAlgID >> 0 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nEncAlgID >> 8 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nEncAlgID >> 16 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nEncAlgID >> 24 ) & 0xFF); + + // Then the checksum algorithm + sal_Int32 nChecksumAlgID = rData->m_nCheckAlg; + *(pHeader++) = static_cast< sal_Int8 >(( nChecksumAlgID >> 0 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nChecksumAlgID >> 8 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nChecksumAlgID >> 16 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nChecksumAlgID >> 24 ) & 0xFF); + + // Then the derived key size + sal_Int32 nDerivedKeySize = rData->m_nDerivedKeySize; + *(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 0 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 8 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 16 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nDerivedKeySize >> 24 ) & 0xFF); + + // Then the start key generation algorithm + sal_Int32 nKeyAlgID = rData->m_nStartKeyGenID; + *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 0 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 8 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 16 ) & 0xFF); + *(pHeader++) = static_cast< sal_Int8 >(( nKeyAlgID >> 24 ) & 0xFF); + // Then the salt length *(pHeader++) = static_cast< sal_Int8 >(( nSaltLength >> 0 ) & 0xFF); *(pHeader++) = static_cast< sal_Int8 >(( nSaltLength >> 8 ) & 0xFF); @@ -208,26 +280,30 @@ void ZipFile::StaticFillHeader ( const ORef < EncryptionData > & rData, *(pHeader++) = static_cast< sal_Int8 >(( nMediaTypeLength >> 8 ) & 0xFF); // Then the salt content - memcpy ( pHeader, rData->aSalt.getConstArray(), nSaltLength ); + rtl_copyMemory ( pHeader, rData->m_aSalt.getConstArray(), nSaltLength ); pHeader += nSaltLength; // Then the IV content - memcpy ( pHeader, rData->aInitVector.getConstArray(), nIVLength ); + rtl_copyMemory ( pHeader, rData->m_aInitVector.getConstArray(), nIVLength ); pHeader += nIVLength; // Then the digest content - memcpy ( pHeader, rData->aDigest.getConstArray(), nDigestLength ); + rtl_copyMemory ( pHeader, rData->m_aDigest.getConstArray(), nDigestLength ); pHeader += nDigestLength; // Then the mediatype itself - memcpy ( pHeader, aMediaType.getStr(), nMediaTypeLength ); + rtl_copyMemory ( pHeader, aMediaType.getStr(), nMediaTypeLength ); pHeader += nMediaTypeLength; } -sal_Bool ZipFile::StaticFillData ( ORef < EncryptionData > & rData, +sal_Bool ZipFile::StaticFillData ( ::rtl::Reference< BaseEncryptionData > & rData, + sal_Int32 &rEncAlg, + sal_Int32 &rChecksumAlg, + sal_Int32 &rDerivedKeySize, + sal_Int32 &rStartKeyGenID, sal_Int32 &rSize, ::rtl::OUString& aMediaType, - Reference < XInputStream > &rStream ) + const uno::Reference< XInputStream >& rStream ) { sal_Bool bOk = sal_False; const sal_Int32 nHeaderSize = n_ConstHeaderSize - 4; @@ -244,13 +320,33 @@ sal_Bool ZipFile::StaticFillData ( ORef < EncryptionData > & rData, nCount |= ( pBuffer[nPos++] & 0xFF ) << 8; nCount |= ( pBuffer[nPos++] & 0xFF ) << 16; nCount |= ( pBuffer[nPos++] & 0xFF ) << 24; - rData->nIterationCount = nCount; + rData->m_nIterationCount = nCount; rSize = pBuffer[nPos++] & 0xFF; rSize |= ( pBuffer[nPos++] & 0xFF ) << 8; rSize |= ( pBuffer[nPos++] & 0xFF ) << 16; rSize |= ( pBuffer[nPos++] & 0xFF ) << 24; + rEncAlg = pBuffer[nPos++] & 0xFF; + rEncAlg |= ( pBuffer[nPos++] & 0xFF ) << 8; + rEncAlg |= ( pBuffer[nPos++] & 0xFF ) << 16; + rEncAlg |= ( pBuffer[nPos++] & 0xFF ) << 24; + + rChecksumAlg = pBuffer[nPos++] & 0xFF; + rChecksumAlg |= ( pBuffer[nPos++] & 0xFF ) << 8; + rChecksumAlg |= ( pBuffer[nPos++] & 0xFF ) << 16; + rChecksumAlg |= ( pBuffer[nPos++] & 0xFF ) << 24; + + rDerivedKeySize = pBuffer[nPos++] & 0xFF; + rDerivedKeySize |= ( pBuffer[nPos++] & 0xFF ) << 8; + rDerivedKeySize |= ( pBuffer[nPos++] & 0xFF ) << 16; + rDerivedKeySize |= ( pBuffer[nPos++] & 0xFF ) << 24; + + rStartKeyGenID = pBuffer[nPos++] & 0xFF; + rStartKeyGenID |= ( pBuffer[nPos++] & 0xFF ) << 8; + rStartKeyGenID |= ( pBuffer[nPos++] & 0xFF ) << 16; + rStartKeyGenID |= ( pBuffer[nPos++] & 0xFF ) << 24; + sal_Int16 nSaltLength = pBuffer[nPos++] & 0xFF; nSaltLength |= ( pBuffer[nPos++] & 0xFF ) << 8; sal_Int16 nIVLength = ( pBuffer[nPos++] & 0xFF ); @@ -263,16 +359,16 @@ sal_Bool ZipFile::StaticFillData ( ORef < EncryptionData > & rData, if ( nSaltLength == rStream->readBytes ( aBuffer, nSaltLength ) ) { - rData->aSalt.realloc ( nSaltLength ); - memcpy ( rData->aSalt.getArray(), aBuffer.getConstArray(), nSaltLength ); + rData->m_aSalt.realloc ( nSaltLength ); + rtl_copyMemory ( rData->m_aSalt.getArray(), aBuffer.getConstArray(), nSaltLength ); if ( nIVLength == rStream->readBytes ( aBuffer, nIVLength ) ) { - rData->aInitVector.realloc ( nIVLength ); - memcpy ( rData->aInitVector.getArray(), aBuffer.getConstArray(), nIVLength ); + rData->m_aInitVector.realloc ( nIVLength ); + rtl_copyMemory ( rData->m_aInitVector.getArray(), aBuffer.getConstArray(), nIVLength ); if ( nDigestLength == rStream->readBytes ( aBuffer, nDigestLength ) ) { - rData->aDigest.realloc ( nDigestLength ); - memcpy ( rData->aDigest.getArray(), aBuffer.getConstArray(), nDigestLength ); + rData->m_aDigest.realloc ( nDigestLength ); + rtl_copyMemory ( rData->m_aDigest.getArray(), aBuffer.getConstArray(), nDigestLength ); if ( nMediaTypeLength == rStream->readBytes ( aBuffer, nMediaTypeLength ) ) { @@ -288,84 +384,107 @@ sal_Bool ZipFile::StaticFillData ( ORef < EncryptionData > & rData, return bOk; } -Reference< XInputStream > ZipFile::StaticGetDataFromRawStream( const Reference< XInputStream >& xStream, - const ORef < EncryptionData > &rData ) +uno::Reference< XInputStream > ZipFile::StaticGetDataFromRawStream( const uno::Reference< lang::XMultiServiceFactory >& xFactory, + const uno::Reference< XInputStream >& xStream, + const ::rtl::Reference< EncryptionData > &rData ) throw ( packages::WrongPasswordException, ZipIOException, RuntimeException ) { - if ( rData.isEmpty() ) + if ( !rData.is() ) throw ZipIOException( OUString::createFromAscii( "Encrypted stream without encryption data!\n" ), - Reference< XInterface >() ); + uno::Reference< XInterface >() ); - if ( !rData->aKey.getLength() ) + if ( !rData->m_aKey.getLength() ) throw packages::WrongPasswordException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - Reference< XSeekable > xSeek( xStream, UNO_QUERY ); + uno::Reference< XSeekable > xSeek( xStream, UNO_QUERY ); if ( !xSeek.is() ) throw ZipIOException( OUString::createFromAscii( "The stream must be seekable!\n" ), - Reference< XInterface >() ); + uno::Reference< XInterface >() ); // if we have a digest, then this file is an encrypted one and we should // check if we can decrypt it or not - OSL_ENSURE( rData->aDigest.getLength(), "Can't detect password correctness without digest!\n" ); - if ( rData->aDigest.getLength() ) + OSL_ENSURE( rData->m_aDigest.getLength(), "Can't detect password correctness without digest!\n" ); + if ( rData->m_aDigest.getLength() ) { - sal_Int32 nSize = sal::static_int_cast< sal_Int32 >( xSeek->getLength() ); - nSize = nSize > n_ConstDigestLength ? n_ConstDigestLength : nSize; + sal_Int32 nSize = sal::static_int_cast< sal_Int32 >( xSeek->getLength() ); + if ( nSize > n_ConstDigestLength + 32 ) + nSize = n_ConstDigestLength + 32; // skip header - xSeek->seek( n_ConstHeaderSize + rData->aInitVector.getLength() + - rData->aSalt.getLength() + rData->aDigest.getLength() ); + xSeek->seek( n_ConstHeaderSize + rData->m_aInitVector.getLength() + + rData->m_aSalt.getLength() + rData->m_aDigest.getLength() ); // Only want to read enough to verify the digest Sequence < sal_Int8 > aReadBuffer ( nSize ); xStream->readBytes( aReadBuffer, nSize ); - if ( !StaticHasValidPassword( aReadBuffer, rData ) ) + if ( !StaticHasValidPassword( xFactory, aReadBuffer, rData ) ) throw packages::WrongPasswordException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); } - return new XUnbufferedStream ( xStream, rData ); + return new XUnbufferedStream( xFactory, xStream, rData ); } -sal_Bool ZipFile::StaticHasValidPassword( const Sequence< sal_Int8 > &aReadBuffer, const ORef < EncryptionData > &rData ) +#if 0 +// for debugging purposes +void CheckSequence( const uno::Sequence< sal_Int8 >& aSequence ) { - if ( !rData.isValid() || !rData->aKey.getLength() ) + if ( aSequence.getLength() ) + { + sal_Int32* pPointer = *( (sal_Int32**)&aSequence ); + sal_Int32 nSize = *( pPointer + 1 ); + sal_Int32 nMemSize = *( pPointer - 2 ); + sal_Int32 nUsedMemSize = ( nSize + 4 * sizeof( sal_Int32 ) ); + OSL_ENSURE( nSize == aSequence.getLength() && nUsedMemSize + 7 - ( nUsedMemSize - 1 ) % 8 == nMemSize, "Broken Sequence!" ); + } +} +#endif + +sal_Bool ZipFile::StaticHasValidPassword( const uno::Reference< lang::XMultiServiceFactory >& xFactory, const Sequence< sal_Int8 > &aReadBuffer, const ::rtl::Reference< EncryptionData > &rData ) +{ + if ( !rData.is() || !rData->m_aKey.getLength() ) return sal_False; sal_Bool bRet = sal_False; - sal_Int32 nSize = aReadBuffer.getLength(); - - // make a temporary cipher - rtlCipher aCipher; - StaticGetCipher ( rData, aCipher, sal_True ); - - Sequence < sal_Int8 > aDecryptBuffer ( nSize ); - rtlDigest aDigest = rtl_digest_createSHA1(); - rtlDigestError aDigestResult; - Sequence < sal_uInt8 > aDigestSeq ( RTL_DIGEST_LENGTH_SHA1 ); - rtlCipherError aResult = rtl_cipher_decode ( aCipher, - aReadBuffer.getConstArray(), - nSize, - reinterpret_cast < sal_uInt8 * > (aDecryptBuffer.getArray()), - nSize); - if(aResult != rtl_Cipher_E_None ) { - OSL_ASSERT ( aResult == rtl_Cipher_E_None); + + uno::Reference< xml::crypto::XCipherContext > xCipher( StaticGetCipher( xFactory, rData, false ), uno::UNO_SET_THROW ); + + uno::Sequence< sal_Int8 > aDecryptBuffer; + uno::Sequence< sal_Int8 > aDecryptBuffer2; + try + { + aDecryptBuffer = xCipher->convertWithCipherContext( aReadBuffer ); + aDecryptBuffer2 = xCipher->finalizeCipherContextAndDispose(); + } + catch( uno::Exception& ) + { + // decryption with padding will throw the exception in finalizing if the buffer represent only part of the stream + // it is no problem, actually this is why we read 32 additional bytes ( two of maximal possible encryption blocks ) + } + + if ( aDecryptBuffer2.getLength() ) + { + sal_Int32 nOldLen = aDecryptBuffer.getLength(); + aDecryptBuffer.realloc( nOldLen + aDecryptBuffer2.getLength() ); + rtl_copyMemory( aDecryptBuffer.getArray() + nOldLen, aDecryptBuffer2.getArray(), aDecryptBuffer2.getLength() ); } - aDigestResult = rtl_digest_updateSHA1 ( aDigest, - static_cast < const void * > ( aDecryptBuffer.getConstArray() ), nSize ); - OSL_ASSERT ( aDigestResult == rtl_Digest_E_None ); + if ( aDecryptBuffer.getLength() > n_ConstDigestLength ) + aDecryptBuffer.realloc( n_ConstDigestLength ); + + uno::Sequence< sal_Int8 > aDigestSeq; + uno::Reference< xml::crypto::XDigestContext > xDigestContext( StaticGetDigestContextForChecksum( xFactory, rData ), uno::UNO_SET_THROW ); - aDigestResult = rtl_digest_getSHA1 ( aDigest, aDigestSeq.getArray(), RTL_DIGEST_LENGTH_SHA1 ); - OSL_ASSERT ( aDigestResult == rtl_Digest_E_None ); + xDigestContext->updateDigest( aDecryptBuffer ); + aDigestSeq = xDigestContext->finalizeDigestAndDispose(); // If we don't have a digest, then we have to assume that the password is correct - if ( rData->aDigest.getLength() != 0 && - ( aDigestSeq.getLength() != rData->aDigest.getLength() || + if ( rData->m_aDigest.getLength() != 0 && + ( aDigestSeq.getLength() != rData->m_aDigest.getLength() || 0 != rtl_compareMemory ( aDigestSeq.getConstArray(), - rData->aDigest.getConstArray(), + rData->m_aDigest.getConstArray(), aDigestSeq.getLength() ) ) ) { // We should probably tell the user that the password they entered was wrong @@ -373,136 +492,44 @@ sal_Bool ZipFile::StaticHasValidPassword( const Sequence< sal_Int8 > &aReadBuffe else bRet = sal_True; - rtl_digest_destroySHA1 ( aDigest ); - return bRet; } -sal_Bool ZipFile::hasValidPassword ( ZipEntry & rEntry, const ORef < EncryptionData > &rData ) +sal_Bool ZipFile::hasValidPassword ( ZipEntry & rEntry, const ::rtl::Reference< EncryptionData >& rData ) { ::osl::MutexGuard aGuard( m_aMutex ); sal_Bool bRet = sal_False; - if ( rData->aKey.getLength() ) + if ( rData.is() && rData->m_aKey.getLength() ) { xSeek->seek( rEntry.nOffset ); sal_Int32 nSize = rEntry.nMethod == DEFLATED ? rEntry.nCompressedSize : rEntry.nSize; // Only want to read enough to verify the digest - nSize = nSize > n_ConstDigestLength ? n_ConstDigestLength : nSize; + if ( nSize > n_ConstDigestDecrypt ) + nSize = n_ConstDigestDecrypt; + Sequence < sal_Int8 > aReadBuffer ( nSize ); xStream->readBytes( aReadBuffer, nSize ); - bRet = StaticHasValidPassword( aReadBuffer, rData ); + bRet = StaticHasValidPassword( m_xFactory, aReadBuffer, rData ); } + return bRet; } -#if 0 -Reference < XInputStream > ZipFile::createFileStream( - ZipEntry & rEntry, - const ORef < EncryptionData > &rData, - sal_Bool bRawStream, - sal_Bool bIsEncrypted ) -{ - static OUString sServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.io.TempFile" ) ); - Reference < XInputStream > xTempStream = Reference < XInputStream > ( xFactory->createInstance ( sServiceName ), UNO_QUERY ); - return new XFileStream ( rEntry, xStream, xTempStream, rData, bRawStream, bIsEncrypted ); -} -Reference < XInputStream > ZipFile::createMemoryStream( - ZipEntry & rEntry, - const ORef < EncryptionData > &rData, - sal_Bool bRawStream, - sal_Bool bIsEncrypted ) -{ - sal_Int32 nUncompressedSize, nEnd; - if (bRawStream) - { - nUncompressedSize = rEntry.nMethod == DEFLATED ? rEntry.nCompressedSize : rEntry.nSize; - nEnd = rEntry.nOffset + nUncompressedSize; - } - else - { - nUncompressedSize = rEntry.nSize; - nEnd = rEntry.nMethod == DEFLATED ? rEntry.nOffset + rEntry.nCompressedSize : rEntry.nOffset + rEntry.nSize; - } - sal_Int32 nSize = rEntry.nMethod == DEFLATED ? rEntry.nCompressedSize : rEntry.nSize; - Sequence < sal_Int8 > aReadBuffer ( nSize ), aDecryptBuffer, aWriteBuffer; - rtlCipher aCipher; - - // If the encryption key is zero, we need to return the raw stream. First check if - // we have the salt. If we have the salt, then check if we have the encryption key - // if not, return rawStream instead. - - sal_Bool bHaveEncryptData = ( !rData.isEmpty() && rData->aSalt.getLength() && rData->aInitVector.getLength() && rData->nIterationCount != 0 ) ? sal_True : sal_False; - sal_Bool bMustDecrypt = ( !bRawStream && bHaveEncryptData && bIsEncrypted ) ? sal_True : sal_False; - - if ( bMustDecrypt ) - { - StaticGetCipher ( rData, aCipher, sal_True ); - aDecryptBuffer.realloc ( nSize ); - } - - if ( nSize <0 ) - throw IOException ( ); - - xSeek->seek( rEntry.nOffset ); - xStream->readBytes( aReadBuffer, nSize ); // Now it holds the raw stuff from disk - - if ( bMustDecrypt ) - { - rtlCipherError aResult = rtl_cipher_decode ( aCipher, - aReadBuffer.getConstArray(), - nSize, - reinterpret_cast < sal_uInt8 * > (aDecryptBuffer.getArray()), - nSize); - OSL_ASSERT (aResult == rtl_Cipher_E_None); - aReadBuffer = aDecryptBuffer; // Now it holds the decrypted data - } - if (bRawStream || rEntry.nMethod == STORED) - aWriteBuffer = aReadBuffer; // bRawStream means the caller doesn't want it decompressed - else - { - aInflater.setInputSegment( aReadBuffer, 0, nSize ); - aWriteBuffer.realloc( nUncompressedSize ); - aInflater.doInflate( aWriteBuffer ); - aInflater.reset(); - } - - if ( bHaveEncryptData && !bMustDecrypt && bIsEncrypted ) - { - // if we have the data needed to decrypt it, but didn't want it decrypted (or - // we couldn't decrypt it due to wrong password), then we prepend this - // data to the stream - - // Make a buffer big enough to hold both the header and the data itself - Sequence < sal_Int8 > aEncryptedDataHeader ( n_ConstHeaderSize + - rData->aInitVector.getLength() + - rData->aSalt.getLength() + - rData->aDigest.getLength() + - aWriteBuffer.getLength() ); - sal_Int8 * pHeader = aEncryptedDataHeader.getArray(); - StaticFillHeader ( rData, rEntry.nSize, pHeader ); - memcpy ( pHeader, aWriteBuffer.getConstArray(), aWriteBuffer.getLength() ); - - // dump old buffer and point aWriteBuffer to the new one with the header - aWriteBuffer = aEncryptedDataHeader; - } - return Reference < XInputStream > ( new XMemoryStream ( aWriteBuffer ) ); -} -#endif -Reference < XInputStream > ZipFile::createUnbufferedStream( +uno::Reference< XInputStream > ZipFile::createUnbufferedStream( SotMutexHolderRef aMutexHolder, ZipEntry & rEntry, - const ORef < EncryptionData > &rData, + const ::rtl::Reference< EncryptionData > &rData, sal_Int8 nStreamMode, sal_Bool bIsEncrypted, ::rtl::OUString aMediaType ) { ::osl::MutexGuard aGuard( m_aMutex ); - return new XUnbufferedStream ( aMutexHolder, rEntry, xStream, rData, nStreamMode, bIsEncrypted, aMediaType, bRecoveryMode ); + return new XUnbufferedStream ( m_xFactory, aMutexHolder, rEntry, xStream, rData, nStreamMode, bIsEncrypted, aMediaType, bRecoveryMode ); } @@ -511,8 +538,8 @@ ZipEnumeration * SAL_CALL ZipFile::entries( ) return new ZipEnumeration ( aEntries ); } -Reference< XInputStream > SAL_CALL ZipFile::getInputStream( ZipEntry& rEntry, - const vos::ORef < EncryptionData > &rData, +uno::Reference< XInputStream > SAL_CALL ZipFile::getInputStream( ZipEntry& rEntry, + const ::rtl::Reference< EncryptionData > &rData, sal_Bool bIsEncrypted, SotMutexHolderRef aMutexHolder ) throw(IOException, ZipException, RuntimeException) @@ -529,7 +556,7 @@ Reference< XInputStream > SAL_CALL ZipFile::getInputStream( ZipEntry& rEntry, // if we have a digest, then this file is an encrypted one and we should // check if we can decrypt it or not - if ( bIsEncrypted && !rData.isEmpty() && rData->aDigest.getLength() ) + if ( bIsEncrypted && rData.is() && rData->m_aDigest.getLength() ) bNeedRawStream = !hasValidPassword ( rEntry, rData ); return createUnbufferedStream ( aMutexHolder, @@ -539,8 +566,8 @@ Reference< XInputStream > SAL_CALL ZipFile::getInputStream( ZipEntry& rEntry, bIsEncrypted ); } -Reference< XInputStream > SAL_CALL ZipFile::getDataStream( ZipEntry& rEntry, - const vos::ORef < EncryptionData > &rData, +uno::Reference< XInputStream > SAL_CALL ZipFile::getDataStream( ZipEntry& rEntry, + const ::rtl::Reference< EncryptionData > &rData, sal_Bool bIsEncrypted, SotMutexHolderRef aMutexHolder ) throw ( packages::WrongPasswordException, @@ -560,14 +587,14 @@ Reference< XInputStream > SAL_CALL ZipFile::getDataStream( ZipEntry& rEntry, { // in case no digest is provided there is no way // to detect password correctness - if ( rData.isEmpty() ) + if ( !rData.is() ) throw ZipException( OUString::createFromAscii( "Encrypted stream without encryption data!\n" ), - Reference< XInterface >() ); + uno::Reference< XInterface >() ); // if we have a digest, then this file is an encrypted one and we should // check if we can decrypt it or not - OSL_ENSURE( rData->aDigest.getLength(), "Can't detect password correctness without digest!\n" ); - if ( rData->aDigest.getLength() && !hasValidPassword ( rEntry, rData ) ) + OSL_ENSURE( rData->m_aDigest.getLength(), "Can't detect password correctness without digest!\n" ); + if ( rData->m_aDigest.getLength() && !hasValidPassword ( rEntry, rData ) ) throw packages::WrongPasswordException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); } else @@ -580,8 +607,8 @@ Reference< XInputStream > SAL_CALL ZipFile::getDataStream( ZipEntry& rEntry, bIsEncrypted ); } -Reference< XInputStream > SAL_CALL ZipFile::getRawData( ZipEntry& rEntry, - const vos::ORef < EncryptionData > &rData, +uno::Reference< XInputStream > SAL_CALL ZipFile::getRawData( ZipEntry& rEntry, + const ::rtl::Reference< EncryptionData >& rData, sal_Bool bIsEncrypted, SotMutexHolderRef aMutexHolder ) throw(IOException, ZipException, RuntimeException) @@ -594,9 +621,9 @@ Reference< XInputStream > SAL_CALL ZipFile::getRawData( ZipEntry& rEntry, return createUnbufferedStream ( aMutexHolder, rEntry, rData, UNBUFF_STREAM_RAW, bIsEncrypted ); } -Reference< XInputStream > SAL_CALL ZipFile::getWrappedRawStream( +uno::Reference< XInputStream > SAL_CALL ZipFile::getWrappedRawStream( ZipEntry& rEntry, - const vos::ORef < EncryptionData > &rData, + const ::rtl::Reference< EncryptionData >& rData, const ::rtl::OUString& aMediaType, SotMutexHolderRef aMutexHolder ) throw ( packages::NoEncryptionException, @@ -606,7 +633,7 @@ Reference< XInputStream > SAL_CALL ZipFile::getWrappedRawStream( { ::osl::MutexGuard aGuard( m_aMutex ); - if ( rData.isEmpty() ) + if ( !rData.is() ) throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); if ( rEntry.nOffset <= 0 ) @@ -628,7 +655,7 @@ sal_Bool ZipFile::readLOC( ZipEntry &rEntry ) aGrabber >> nTestSig; if (nTestSig != LOCSIG) - throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid LOC header (bad signature") ), Reference < XInterface > () ); + throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid LOC header (bad signature") ), uno::Reference < XInterface > () ); aGrabber >> nVersion; aGrabber >> nFlag; aGrabber >> nHow; @@ -665,7 +692,7 @@ sal_Bool ZipFile::readLOC( ZipEntry &rEntry ) if ( bBroken && !bRecoveryMode ) throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "The stream seems to be broken!" ) ), - Reference< XInterface >() ); + uno::Reference< XInterface >() ); return sal_True; } @@ -699,17 +726,17 @@ sal_Int32 ZipFile::findEND( ) } catch ( IllegalArgumentException& ) { - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () ); } catch ( NotConnectedException& ) { - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () ); } catch ( BufferSizeExceededException& ) { - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () ); } - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () ); } sal_Int32 ZipFile::readCEN() @@ -730,25 +757,25 @@ sal_Int32 ZipFile::readCEN() aGrabber >> nCenOff; if ( nTotal * CENHDR > nCenLen ) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "invalid END header (bad entry count)") ), Reference < XInterface > () ); + throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "invalid END header (bad entry count)") ), uno::Reference < XInterface > () ); if ( nTotal > ZIP_MAXENTRIES ) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "too many entries in ZIP File") ), Reference < XInterface > () ); + throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "too many entries in ZIP File") ), uno::Reference < XInterface > () ); if ( nCenLen < 0 || nCenLen > nEndPos ) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid END header (bad central directory size)") ), Reference < XInterface > () ); + throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid END header (bad central directory size)") ), uno::Reference < XInterface > () ); nCenPos = nEndPos - nCenLen; if ( nCenOff < 0 || nCenOff > nCenPos ) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid END header (bad central directory size)") ), Reference < XInterface > () ); + throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid END header (bad central directory size)") ), uno::Reference < XInterface > () ); nLocPos = nCenPos - nCenOff; aGrabber.seek( nCenPos ); Sequence < sal_Int8 > aCENBuffer ( nCenLen ); sal_Int64 nRead = aGrabber.readBytes ( aCENBuffer, nCenLen ); if ( static_cast < sal_Int64 > ( nCenLen ) != nRead ) - throw ZipException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Error reading CEN into memory buffer!") ), Reference < XInterface > () ); + throw ZipException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Error reading CEN into memory buffer!") ), uno::Reference < XInterface > () ); MemoryByteGrabber aMemGrabber ( aCENBuffer ); @@ -760,19 +787,19 @@ sal_Int32 ZipFile::readCEN() { aMemGrabber >> nTestSig; if ( nTestSig != CENSIG ) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (bad signature)") ), Reference < XInterface > () ); + throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (bad signature)") ), uno::Reference < XInterface > () ); aMemGrabber.skipBytes ( 2 ); aMemGrabber >> aEntry.nVersion; if ( ( aEntry.nVersion & 1 ) == 1 ) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (encrypted entry)") ), Reference < XInterface > () ); + throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (encrypted entry)") ), uno::Reference < XInterface > () ); aMemGrabber >> aEntry.nFlag; aMemGrabber >> aEntry.nMethod; if ( aEntry.nMethod != STORED && aEntry.nMethod != DEFLATED) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (bad compression method)") ), Reference < XInterface > () ); + throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (bad compression method)") ), uno::Reference < XInterface > () ); aMemGrabber >> aEntry.nTime; aMemGrabber >> aEntry.nCrc; @@ -788,13 +815,13 @@ sal_Int32 ZipFile::readCEN() aEntry.nOffset *= -1; if ( aEntry.nPathLen < 0 ) - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected name length" ) ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected name length" ) ), uno::Reference < XInterface > () ); if ( nCommentLen < 0 ) - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected comment length" ) ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected comment length" ) ), uno::Reference < XInterface > () ); if ( aEntry.nExtraLen < 0 ) - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected extra header info length") ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected extra header info length") ), uno::Reference < XInterface > () ); // read always in UTF8, some tools seem not to set UTF8 bit aEntry.sPath = rtl::OUString::intern ( (sal_Char *) aMemGrabber.getCurrentPos(), @@ -802,14 +829,14 @@ sal_Int32 ZipFile::readCEN() RTL_TEXTENCODING_UTF8 ); if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aEntry.sPath, sal_True ) ) - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip entry has an invalid name.") ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip entry has an invalid name.") ), uno::Reference < XInterface > () ); aMemGrabber.skipBytes( aEntry.nPathLen + aEntry.nExtraLen + nCommentLen ); aEntries[aEntry.sPath] = aEntry; } if (nCount != nTotal) - throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Count != Total") ), Reference < XInterface > () ); + throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Count != Total") ), uno::Reference < XInterface > () ); } catch ( IllegalArgumentException & ) { @@ -982,15 +1009,15 @@ sal_Int32 ZipFile::recover() } catch ( IllegalArgumentException& ) { - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () ); } catch ( NotConnectedException& ) { - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () ); } catch ( BufferSizeExceededException& ) { - throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () ); + throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), uno::Reference < XInterface > () ); } } diff --git a/package/source/zipapi/ZipOutputStream.cxx b/package/source/zipapi/ZipOutputStream.cxx index 16457ec12493..338feb556378 100644 --- a/package/source/zipapi/ZipOutputStream.cxx +++ b/package/source/zipapi/ZipOutputStream.cxx @@ -27,19 +27,22 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_package.hxx" -#include <ZipOutputStream.hxx> + #include <com/sun/star/packages/zip/ZipConstants.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include <comphelper/storagehelper.hxx> + #include <osl/time.h> + #include <EncryptionData.hxx> #include <PackageConstants.hxx> #include <ZipEntry.hxx> #include <ZipFile.hxx> -#include <vos/ref.hxx> -#include <com/sun/star/io/XOutputStream.hpp> - -#include <comphelper/storagehelper.hxx> +#include <ZipPackageStream.hxx> +#include <ZipOutputStream.hxx> using namespace rtl; +using namespace com::sun::star; using namespace com::sun::star::io; using namespace com::sun::star::uno; using namespace com::sun::star::packages; @@ -48,17 +51,18 @@ using namespace com::sun::star::packages::zip::ZipConstants; /** This class is used to write Zip files */ -ZipOutputStream::ZipOutputStream( Reference < XOutputStream > &xOStream ) -: xStream(xOStream) -, aBuffer(n_ConstBufferSize) +ZipOutputStream::ZipOutputStream( const uno::Reference< lang::XMultiServiceFactory >& xFactory, + const uno::Reference < XOutputStream > &xOStream ) +: m_xFactory( xFactory ) +, xStream(xOStream) +, m_aDeflateBuffer(n_ConstBufferSize) , aDeflater(DEFAULT_COMPRESSION, sal_True) , aChucker(xOStream) , pCurrentEntry(NULL) , nMethod(DEFLATED) , bFinished(sal_False) , bEncryptCurrentEntry(sal_False) - - +, m_pCurrentStream(NULL) { } @@ -80,7 +84,7 @@ void SAL_CALL ZipOutputStream::setLevel( sal_Int32 nNewLevel ) } void SAL_CALL ZipOutputStream::putNextEntry( ZipEntry& rEntry, - vos::ORef < EncryptionData > &xEncryptData, + ZipPackageStream* pStream, sal_Bool bEncrypt) throw(IOException, RuntimeException) { @@ -94,18 +98,20 @@ void SAL_CALL ZipOutputStream::putNextEntry( ZipEntry& rEntry, rEntry.nFlag = 1 << 11; if (rEntry.nSize == -1 || rEntry.nCompressedSize == -1 || rEntry.nCrc == -1) + { + rEntry.nSize = rEntry.nCompressedSize = 0; rEntry.nFlag |= 8; + } if (bEncrypt) { bEncryptCurrentEntry = sal_True; - ZipFile::StaticGetCipher( xEncryptData, aCipher, sal_False ); - - aDigest = rtl_digest_createSHA1(); + m_xCipherContext = ZipFile::StaticGetCipher( m_xFactory, pStream->GetEncryptionData(), true ); + m_xDigestContext = ZipFile::StaticGetDigestContextForChecksum( m_xFactory, pStream->GetEncryptionData() ); mnDigested = 0; rEntry.nFlag |= 1 << 4; - pCurrentEncryptData = xEncryptData.getBodyPtr(); + m_pCurrentStream = pStream; } sal_Int32 nLOCLength = writeLOC(rEntry); rEntry.nOffset = static_cast < sal_Int32 > (aChucker.GetPosition()) - nLOCLength; @@ -145,11 +151,12 @@ void SAL_CALL ZipOutputStream::closeEntry( ) } else { - pEntry->nSize = aDeflater.getTotalIn(); - pEntry->nCompressedSize = aDeflater.getTotalOut(); + if ( !bEncryptCurrentEntry ) + { + pEntry->nSize = aDeflater.getTotalIn(); + pEntry->nCompressedSize = aDeflater.getTotalOut(); + } pEntry->nCrc = aCRC.getValue(); - if ( bEncryptCurrentEntry ) - pEntry->nSize = pEntry->nCompressedSize; writeEXT(*pEntry); } aDeflater.reset(); @@ -166,18 +173,22 @@ void SAL_CALL ZipOutputStream::closeEntry( ) if (bEncryptCurrentEntry) { - rtlDigestError aDigestResult; - aEncryptionBuffer.realloc ( 0 ); bEncryptCurrentEntry = sal_False; - rtl_cipher_destroy ( aCipher ); - pCurrentEncryptData->aDigest.realloc ( RTL_DIGEST_LENGTH_SHA1 ); - aDigestResult = rtl_digest_getSHA1 ( aDigest, - reinterpret_cast < sal_uInt8 * > ( pCurrentEncryptData->aDigest.getArray() ), - RTL_DIGEST_LENGTH_SHA1 ); - OSL_ASSERT( aDigestResult == rtl_Digest_E_None ); - rtl_digest_destroySHA1 ( aDigest ); + + m_xCipherContext.clear(); + + uno::Sequence< sal_Int8 > aDigestSeq; + if ( m_xDigestContext.is() ) + { + aDigestSeq = m_xDigestContext->finalizeDigestAndDispose(); + m_xDigestContext.clear(); + } + + if ( m_pCurrentStream ) + m_pCurrentStream->setDigest( aDigestSeq ); } pCurrentEntry = NULL; + m_pCurrentStream = NULL; } } @@ -242,41 +253,53 @@ void SAL_CALL ZipOutputStream::finish( ) void ZipOutputStream::doDeflate() { - sal_Int32 nLength = aDeflater.doDeflateSegment(aBuffer, 0, aBuffer.getLength()); - sal_Int32 nOldLength = aBuffer.getLength(); + sal_Int32 nLength = aDeflater.doDeflateSegment(m_aDeflateBuffer, 0, m_aDeflateBuffer.getLength()); if ( nLength > 0 ) { - Sequence < sal_Int8 > aTmpBuffer ( aBuffer.getConstArray(), nLength ); - const void *pTmpBuffer = static_cast < const void * > ( aTmpBuffer.getConstArray() ); - if (bEncryptCurrentEntry) + uno::Sequence< sal_Int8 > aTmpBuffer( m_aDeflateBuffer.getConstArray(), nLength ); + if ( bEncryptCurrentEntry && m_xDigestContext.is() && m_xCipherContext.is() ) { // Need to update our digest before encryption... - rtlDigestError aDigestResult = rtl_Digest_E_None; - sal_Int16 nDiff = n_ConstDigestLength - mnDigested; + sal_Int32 nDiff = n_ConstDigestLength - mnDigested; if ( nDiff ) { - sal_Int16 nEat = static_cast < sal_Int16 > ( nDiff > nLength ? nLength : nDiff ); - aDigestResult = rtl_digest_updateSHA1 ( aDigest, pTmpBuffer, nEat ); - mnDigested = mnDigested + nEat; + sal_Int32 nEat = ::std::min( nLength, nDiff ); + uno::Sequence< sal_Int8 > aTmpSeq( aTmpBuffer.getConstArray(), nEat ); + m_xDigestContext->updateDigest( aTmpSeq ); + mnDigested = mnDigested + static_cast< sal_Int16 >( nEat ); } - OSL_ASSERT( aDigestResult == rtl_Digest_E_None ); - - aEncryptionBuffer.realloc ( nLength ); - rtlCipherError aCipherResult; - aCipherResult = rtl_cipher_encode ( aCipher, pTmpBuffer, - nLength, reinterpret_cast < sal_uInt8 * > (aEncryptionBuffer.getArray()), nLength ); - OSL_ASSERT( aCipherResult == rtl_Cipher_E_None ); + uno::Sequence< sal_Int8 > aEncryptionBuffer = m_xCipherContext->convertWithCipherContext( aTmpBuffer ); aChucker.WriteBytes( aEncryptionBuffer ); - aCRC.update ( aEncryptionBuffer ); - aEncryptionBuffer.realloc ( nOldLength ); + + // the sizes as well as checksum for encrypted streams is calculated here + pCurrentEntry->nCompressedSize += aEncryptionBuffer.getLength(); + pCurrentEntry->nSize = pCurrentEntry->nCompressedSize; + aCRC.update( aEncryptionBuffer ); } else + { aChucker.WriteBytes ( aTmpBuffer ); + } + } + + if ( aDeflater.finished() && bEncryptCurrentEntry && m_xDigestContext.is() && m_xCipherContext.is() ) + { + uno::Sequence< sal_Int8 > aEncryptionBuffer = m_xCipherContext->finalizeCipherContextAndDispose(); + if ( aEncryptionBuffer.getLength() ) + { + aChucker.WriteBytes( aEncryptionBuffer ); + + // the sizes as well as checksum for encrypted streams is calculated hier + pCurrentEntry->nCompressedSize += aEncryptionBuffer.getLength(); + pCurrentEntry->nSize = pCurrentEntry->nCompressedSize; + aCRC.update( aEncryptionBuffer ); + } } } + void ZipOutputStream::writeEND(sal_uInt32 nOffset, sal_uInt32 nLength) throw(IOException, RuntimeException) { @@ -293,7 +316,7 @@ void ZipOutputStream::writeCEN( const ZipEntry &rEntry ) throw(IOException, RuntimeException) { if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( rEntry.sPath, sal_True ) ) - throw IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), Reference< XInterface >() ); + throw IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), uno::Reference< XInterface >() ); ::rtl::OString sUTF8Name = ::rtl::OUStringToOString( rEntry.sPath, RTL_TEXTENCODING_UTF8 ); sal_Int16 nNameLength = static_cast < sal_Int16 > ( sUTF8Name.getLength() ); @@ -342,7 +365,7 @@ sal_Int32 ZipOutputStream::writeLOC( const ZipEntry &rEntry ) throw(IOException, RuntimeException) { if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( rEntry.sPath, sal_True ) ) - throw IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), Reference< XInterface >() ); + throw IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected character is used in file name." ) ), uno::Reference< XInterface >() ); ::rtl::OString sUTF8Name = ::rtl::OUStringToOString( rEntry.sPath, RTL_TEXTENCODING_UTF8 ); sal_Int16 nNameLength = static_cast < sal_Int16 > ( sUTF8Name.getLength() ); diff --git a/package/source/zipapi/blowfishcontext.cxx b/package/source/zipapi/blowfishcontext.cxx new file mode 100644 index 000000000000..1739bb15cde8 --- /dev/null +++ b/package/source/zipapi/blowfishcontext.cxx @@ -0,0 +1,122 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_package.hxx" + +#include <rtl/cipher.h> +#include <rtl/ref.hxx> + +#include "blowfishcontext.hxx" + +using namespace ::com::sun::star; + +// static +uno::Reference< xml::crypto::XCipherContext > BlowfishCFB8CipherContext::Create( const uno::Sequence< sal_Int8 >& aDerivedKey, const uno::Sequence< sal_Int8 >& aInitVector, bool bEncrypt ) +{ + ::rtl::Reference< BlowfishCFB8CipherContext > xResult = new BlowfishCFB8CipherContext(); + xResult->m_pCipher = rtl_cipher_create( rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream ); + if ( !xResult->m_pCipher ) + throw uno::RuntimeException( ::rtl::OUString::createFromAscii( "Can not create cipher!\n" ), + uno::Reference< XInterface >() ); + + if ( rtl_Cipher_E_None != rtl_cipher_init( + xResult->m_pCipher, + bEncrypt ? rtl_Cipher_DirectionEncode : rtl_Cipher_DirectionDecode, + reinterpret_cast< const sal_uInt8* >( aDerivedKey.getConstArray() ), + aDerivedKey.getLength(), + reinterpret_cast< const sal_uInt8* >( aInitVector.getConstArray() ), + aInitVector.getLength() ) ) + { + throw uno::RuntimeException( ::rtl::OUString::createFromAscii( "Can not initialize cipher!\n" ), + uno::Reference< XInterface >() ); + } + + xResult->m_bEncrypt = bEncrypt; + + return uno::Reference< xml::crypto::XCipherContext >( xResult.get() ); +} + +BlowfishCFB8CipherContext::~BlowfishCFB8CipherContext() +{ + if ( m_pCipher ) + { + rtl_cipher_destroy ( m_pCipher ); + m_pCipher = NULL; + } +} + +uno::Sequence< sal_Int8 > SAL_CALL BlowfishCFB8CipherContext::convertWithCipherContext( const uno::Sequence< ::sal_Int8 >& aData ) + throw( lang::IllegalArgumentException, lang::DisposedException, uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_pCipher ) + throw lang::DisposedException(); + + uno::Sequence< sal_Int8 > aResult( aData.getLength() ); + rtlCipherError nError = rtl_Cipher_E_None; + + if ( m_bEncrypt ) + { + rtl_cipher_encode( m_pCipher, + aData.getConstArray(), + aData.getLength(), + reinterpret_cast< sal_uInt8* >( aResult.getArray() ), + aResult.getLength() ); + } + else + { + rtl_cipher_decode( m_pCipher, + aData.getConstArray(), + aData.getLength(), + reinterpret_cast< sal_uInt8* >( aResult.getArray() ), + aResult.getLength() ); + } + + if ( rtl_Cipher_E_None != nError ) + { + throw uno::RuntimeException( ::rtl::OUString::createFromAscii( "Can not decrypt/encrypt with cipher!\n" ), + uno::Reference< uno::XInterface >() ); + } + + return aResult; +} + +uno::Sequence< ::sal_Int8 > SAL_CALL BlowfishCFB8CipherContext::finalizeCipherContextAndDispose() + throw( lang::DisposedException, uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_pCipher ) + throw lang::DisposedException(); + + rtl_cipher_destroy ( m_pCipher ); + m_pCipher = NULL; + + return uno::Sequence< sal_Int8 >(); +} + + diff --git a/package/source/zipapi/blowfishcontext.hxx b/package/source/zipapi/blowfishcontext.hxx new file mode 100644 index 000000000000..49cce2fc0e65 --- /dev/null +++ b/package/source/zipapi/blowfishcontext.hxx @@ -0,0 +1,58 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _BLOWFISHCONTEXT_HXX +#define _BLOWFISHCONTEXT_HXX + +#include <com/sun/star/xml/crypto/XCipherContext.hpp> + +#include <cppuhelper/implbase1.hxx> +#include <osl/mutex.hxx> + +class BlowfishCFB8CipherContext : public cppu::WeakImplHelper1< ::com::sun::star::xml::crypto::XCipherContext > +{ + ::osl::Mutex m_aMutex; + void* m_pCipher; + bool m_bEncrypt; + + BlowfishCFB8CipherContext() + : m_pCipher( NULL ) + , m_bEncrypt( false ) + {} + +public: + + virtual ~BlowfishCFB8CipherContext(); + + static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > + Create( const ::com::sun::star::uno::Sequence< sal_Int8 >& aDerivedKey, const ::com::sun::star::uno::Sequence< sal_Int8 >& aInitVector, bool bEncrypt ); + + virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL convertWithCipherContext( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL finalizeCipherContextAndDispose( ) throw (::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException); +}; + +#endif // _BLOWFISHCONTEXT_HXX + diff --git a/package/source/zipapi/makefile.mk b/package/source/zipapi/makefile.mk index a9548ace659b..79dbb0289a1c 100644 --- a/package/source/zipapi/makefile.mk +++ b/package/source/zipapi/makefile.mk @@ -45,8 +45,10 @@ SLOFILES= \ $(SLO)$/CRC32.obj \ $(SLO)$/ByteChucker.obj \ $(SLO)$/ByteGrabber.obj \ + $(SLO)$/blowfishcontext.obj \ $(SLO)$/Inflater.obj \ $(SLO)$/Deflater.obj \ + $(SLO)$/sha1context.obj \ $(SLO)$/ZipEnumeration.obj \ $(SLO)$/ZipFile.obj \ $(SLO)$/ZipOutputStream.obj \ diff --git a/package/source/zipapi/sha1context.cxx b/package/source/zipapi/sha1context.cxx new file mode 100644 index 000000000000..a71f20ad6f36 --- /dev/null +++ b/package/source/zipapi/sha1context.cxx @@ -0,0 +1,97 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_package.hxx" + +#include <rtl/digest.h> +#include <rtl/ref.hxx> + +#include "sha1context.hxx" + +using namespace ::com::sun::star; + +// static +uno::Reference< xml::crypto::XDigestContext > SHA1DigestContext::Create() +{ + ::rtl::Reference< SHA1DigestContext > xResult = new SHA1DigestContext(); + xResult->m_pDigest = rtl_digest_createSHA1(); + if ( !xResult->m_pDigest ) + throw uno::RuntimeException( ::rtl::OUString::createFromAscii( "Can not create cipher!\n" ), + uno::Reference< XInterface >() ); + + return uno::Reference< xml::crypto::XDigestContext >( xResult.get() ); +} + +SHA1DigestContext::~SHA1DigestContext() +{ + if ( m_pDigest ) + { + rtl_digest_destroySHA1( m_pDigest ); + m_pDigest = NULL; + } +} + +void SAL_CALL SHA1DigestContext::updateDigest( const uno::Sequence< ::sal_Int8 >& aData ) + throw( lang::DisposedException, uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_pDigest ) + throw lang::DisposedException(); + + if ( rtl_Digest_E_None != rtl_digest_updateSHA1( m_pDigest, aData.getConstArray(), aData.getLength() ) ) + { + rtl_digest_destroySHA1( m_pDigest ); + m_pDigest = NULL; + + throw uno::RuntimeException(); + } +} + +uno::Sequence< ::sal_Int8 > SAL_CALL SHA1DigestContext::finalizeDigestAndDispose() + throw( lang::DisposedException, uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_pDigest ) + throw lang::DisposedException(); + + uno::Sequence< sal_Int8 > aResult( RTL_DIGEST_LENGTH_SHA1 ); + if ( rtl_Digest_E_None != rtl_digest_getSHA1( m_pDigest, reinterpret_cast< sal_uInt8* >( aResult.getArray() ), aResult.getLength() ) ) + { + rtl_digest_destroySHA1( m_pDigest ); + m_pDigest = NULL; + + throw uno::RuntimeException(); + } + + rtl_digest_destroySHA1( m_pDigest ); + m_pDigest = NULL; + + return aResult; +} + + diff --git a/package/source/zipapi/sha1context.hxx b/package/source/zipapi/sha1context.hxx new file mode 100644 index 000000000000..dbd1207ca792 --- /dev/null +++ b/package/source/zipapi/sha1context.hxx @@ -0,0 +1,57 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _SHA1CONTEXT_HXX +#define _SHA1CONTEXT_HXX + +#include <com/sun/star/xml/crypto/XDigestContext.hpp> + +#include <cppuhelper/implbase1.hxx> +#include <osl/mutex.hxx> + +class SHA1DigestContext : public cppu::WeakImplHelper1< ::com::sun::star::xml::crypto::XDigestContext > +{ + ::osl::Mutex m_aMutex; + void* m_pDigest; + + SHA1DigestContext() + : m_pDigest( NULL ) + {} + +public: + + virtual ~SHA1DigestContext(); + + static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XDigestContext > + Create(); + + virtual void SAL_CALL updateDigest( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData ) throw (::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL finalizeDigestAndDispose() throw (::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException); + +}; + +#endif // _SHA1CONTEXT_HXX + diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index fca0e09f63bd..41d944288d53 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -16,7 +16,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). + * ( a copy is included in the LICENSE file that accompanied this code ). * * You should have received a copy of the GNU Lesser General Public License * version 3 along with OpenOffice.org. If not, see @@ -25,7 +25,7 @@ * ************************************************************************/ -// MARKER(update_precomp.py): autogen include statement, do not remove +// MARKER( update_precomp.py ): autogen include statement, do not remove #include "precompiled_package.hxx" #include <ZipPackage.hxx> #include <ZipPackageSink.hxx> @@ -63,6 +63,8 @@ #include <com/sun/star/embed/UseBackupException.hpp> #include <com/sun/star/embed/StorageFormats.hpp> #include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/xml/crypto/DigestID.hpp> +#include <com/sun/star/xml/crypto/CipherID.hpp> #include <cppuhelper/implbase1.hxx> #include <ContentInfo.hxx> #include <cppuhelper/typeprovider.hxx> @@ -83,6 +85,7 @@ #include <comphelper/storagehelper.hxx> #include <comphelper/ofopxmlhelper.hxx> #include <comphelper/documentconstants.hxx> +#include <comphelper/sequenceashashmap.hxx> using namespace rtl; using namespace std; @@ -154,35 +157,37 @@ public: class DummyInputStream : public ::cppu::WeakImplHelper1< XInputStream > { - virtual sal_Int32 SAL_CALL readBytes( Sequence< sal_Int8 >&, sal_Int32 ) - throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) + virtual sal_Int32 SAL_CALL readBytes( uno::Sequence< sal_Int8 >&, sal_Int32 ) + throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) { return 0; } - virtual sal_Int32 SAL_CALL readSomeBytes( Sequence< sal_Int8 >&, sal_Int32 ) - throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) + virtual sal_Int32 SAL_CALL readSomeBytes( uno::Sequence< sal_Int8 >&, sal_Int32 ) + throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) { return 0; } virtual void SAL_CALL skipBytes( sal_Int32 ) - throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) + throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) {} virtual sal_Int32 SAL_CALL available() - throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) + throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) { return 0; } virtual void SAL_CALL closeInput() - throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) + throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) {} }; //=========================================================================== -ZipPackage::ZipPackage (const uno::Reference < XMultiServiceFactory > &xNewFactory) +ZipPackage::ZipPackage ( const uno::Reference < XMultiServiceFactory > &xNewFactory ) : m_aMutexHolder( new SotMutexHolder ) +, m_nStartKeyGenerationID( xml::crypto::DigestID::SHA1 ) +, m_nChecksumDigestID( xml::crypto::DigestID::SHA1_1K ) +, m_nCommonEncryptionID( xml::crypto::CipherID::BLOWFISH_CFB_8 ) , m_bHasEncryptedEntries ( sal_False ) , m_bHasNonEncryptedEntries ( sal_False ) , m_bInconsistent ( sal_False ) -, m_bUseManifest ( sal_True ) , m_bForceRecovery ( sal_False ) , m_bMediaTypeFallbackUsed ( sal_False ) , m_nFormat( embed::StorageFormats::PACKAGE ) // package is the default format @@ -204,28 +209,19 @@ ZipPackage::~ZipPackage( void ) // So there is no need in explicit m_pRootFolder->releaseUpwardRef() call here any more // since m_pRootFolder has no parent and cleaning of it's children will be done automatically // during m_pRootFolder dieing by refcount. - -#if 0 - // As all folders and streams contain references to their parents, - // we must remove these references so that they will be deleted when - // the hash_map of the root folder is cleared, releasing all subfolders - // and substreams which in turn release theirs, etc. When m_xRootFolder is - // released when this destructor completes, the folder tree should be - // deleted fully (and automagically). - - m_pRootFolder->releaseUpwardRef(); -#endif } +//-------------------------------------------------------- void ZipPackage::parseManifest() { if ( m_nFormat == embed::StorageFormats::PACKAGE ) { sal_Bool bManifestParsed = sal_False; + bool bDifferentStartKeyAlgorithm = false; const OUString sMeta ( RTL_CONSTASCII_USTRINGPARAM ( "META-INF" ) ); if ( m_xRootFolder->hasByName( sMeta ) ) { - const OUString sManifest (RTL_CONSTASCII_USTRINGPARAM( "manifest.xml") ); + const OUString sManifest ( RTL_CONSTASCII_USTRINGPARAM( "manifest.xml" ) ); try { uno::Reference< XUnoTunnel > xTunnel; @@ -236,11 +232,11 @@ void ZipPackage::parseManifest() { aAny = xMetaInfFolder->getByName( sManifest ); aAny >>= xTunnel; - uno::Reference < XActiveDataSink > xSink (xTunnel, UNO_QUERY); - if (xSink.is()) + uno::Reference < XActiveDataSink > xSink ( xTunnel, UNO_QUERY ); + if ( xSink.is() ) { OUString sManifestReader ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestReader" ) ); - uno::Reference < XManifestReader > xReader (m_xFactory->createInstance( sManifestReader ), UNO_QUERY ); + uno::Reference < XManifestReader > xReader ( m_xFactory->createInstance( sManifestReader ), UNO_QUERY ); if ( xReader.is() ) { const OUString sPropFullPath ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); @@ -251,45 +247,57 @@ void ZipPackage::parseManifest() const OUString sPropIterationCount ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ); const OUString sPropSize ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ); const OUString sPropDigest ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) ); + const OUString sPropDerivedKeySize ( RTL_CONSTASCII_USTRINGPARAM ( "DerivedKeySize" ) ); + const OUString sPropDigestAlgorithm ( RTL_CONSTASCII_USTRINGPARAM ( "DigestAlgorithm" ) ); + const OUString sPropEncryptionAlgorithm ( RTL_CONSTASCII_USTRINGPARAM ( "EncryptionAlgorithm" ) ); + const OUString sPropStartKeyAlgorithm ( RTL_CONSTASCII_USTRINGPARAM ( "StartKeyAlgorithm" ) ); - Sequence < Sequence < PropertyValue > > aManifestSequence = xReader->readManifestSequence ( xSink->getInputStream() ); + uno::Sequence < uno::Sequence < PropertyValue > > aManifestSequence = xReader->readManifestSequence ( xSink->getInputStream() ); sal_Int32 nLength = aManifestSequence.getLength(); - const Sequence < PropertyValue > *pSequence = aManifestSequence.getConstArray(); + const uno::Sequence < PropertyValue > *pSequence = aManifestSequence.getConstArray(); ZipPackageStream *pStream = NULL; ZipPackageFolder *pFolder = NULL; - for (sal_Int32 i = 0; i < nLength ; i++, pSequence++) + for ( sal_Int32 i = 0; i < nLength ; i++, pSequence++ ) { OUString sPath, sMediaType, sVersion; const PropertyValue *pValue = pSequence->getConstArray(); - const Any *pSalt = NULL, *pVector = NULL, *pCount = NULL, *pSize = NULL, *pDigest = NULL; - for (sal_Int32 j = 0, nNum = pSequence->getLength(); j < nNum; j++ ) + const Any *pSalt = NULL, *pVector = NULL, *pCount = NULL, *pSize = NULL, *pDigest = NULL, *pDigestAlg = NULL, *pEncryptionAlg = NULL, *pStartKeyAlg = NULL, *pDerivedKeySize = NULL; + for ( sal_Int32 j = 0, nNum = pSequence->getLength(); j < nNum; j++ ) { - if (pValue[j].Name.equals( sPropFullPath ) ) + if ( pValue[j].Name.equals( sPropFullPath ) ) pValue[j].Value >>= sPath; - else if (pValue[j].Name.equals( sPropVersion ) ) + else if ( pValue[j].Name.equals( sPropVersion ) ) pValue[j].Value >>= sVersion; - else if (pValue[j].Name.equals( sPropMediaType ) ) + else if ( pValue[j].Name.equals( sPropMediaType ) ) pValue[j].Value >>= sMediaType; - else if (pValue[j].Name.equals( sPropSalt ) ) - pSalt = &(pValue[j].Value); - else if (pValue[j].Name.equals( sPropInitialisationVector ) ) - pVector = &(pValue[j].Value); - else if (pValue[j].Name.equals( sPropIterationCount ) ) - pCount = &(pValue[j].Value); - else if (pValue[j].Name.equals( sPropSize ) ) - pSize = &(pValue[j].Value); - else if (pValue[j].Name.equals( sPropDigest ) ) - pDigest = &(pValue[j].Value); + else if ( pValue[j].Name.equals( sPropSalt ) ) + pSalt = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropInitialisationVector ) ) + pVector = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropIterationCount ) ) + pCount = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropSize ) ) + pSize = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropDigest ) ) + pDigest = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropDigestAlgorithm ) ) + pDigestAlg = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropEncryptionAlgorithm ) ) + pEncryptionAlg = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropStartKeyAlgorithm ) ) + pStartKeyAlg = &( pValue[j].Value ); + else if ( pValue[j].Name.equals( sPropDerivedKeySize ) ) + pDerivedKeySize = &( pValue[j].Value ); } - if (sPath.getLength() && hasByHierarchicalName ( sPath ) ) + if ( sPath.getLength() && hasByHierarchicalName ( sPath ) ) { aAny = getByHierarchicalName( sPath ); uno::Reference < XUnoTunnel > xUnoTunnel; aAny >>= xUnoTunnel; sal_Int64 nTest=0; - if ((nTest = xUnoTunnel->getSomething(ZipPackageFolder::static_getImplementationId())) != 0) + if ( (nTest = xUnoTunnel->getSomething( ZipPackageFolder::static_getImplementationId() )) != 0 ) { pFolder = reinterpret_cast < ZipPackageFolder* > ( nTest ); pFolder->SetMediaType ( sMediaType ); @@ -297,15 +305,16 @@ void ZipPackage::parseManifest() } else { - pStream = reinterpret_cast < ZipPackageStream* > ( xUnoTunnel->getSomething(ZipPackageStream::static_getImplementationId())); + pStream = reinterpret_cast < ZipPackageStream* > ( xUnoTunnel->getSomething( ZipPackageStream::static_getImplementationId() )); pStream->SetMediaType ( sMediaType ); pStream->SetFromManifest( sal_True ); - if (pSalt && pVector && pCount && pSize) + if ( pSalt && pVector && pCount && pSize && pDigest && pDigestAlg && pEncryptionAlg ) { - Sequence < sal_uInt8 > aSequence; - sal_Int32 nCount = 0, nSize = 0; - pStream->SetToBeEncrypted ( sal_True ); + uno::Sequence < sal_Int8 > aSequence; + sal_Int32 nCount = 0, nSize = 0, nDigestAlg = 0, nEncryptionAlg = 0, nDerivedKeySize = 16, nStartKeyAlg = xml::crypto::DigestID::SHA1; + + pStream->SetToBeEncrypted ( sal_True ); *pSalt >>= aSequence; pStream->setSalt ( aSequence ); @@ -319,18 +328,34 @@ void ZipPackage::parseManifest() *pSize >>= nSize; pStream->setSize ( nSize ); - if ( pDigest ) - { - *pDigest >>= aSequence; - pStream->setDigest ( aSequence ); - } + *pDigest >>= aSequence; + pStream->setDigest ( aSequence ); + + *pDigestAlg >>= nDigestAlg; + pStream->SetImportedChecksumAlgorithm( nDigestAlg ); + + *pEncryptionAlg >>= nEncryptionAlg; + pStream->SetImportedEncryptionAlgorithm( nEncryptionAlg ); + + if ( pDerivedKeySize ) + *pDerivedKeySize >>= nDerivedKeySize; + pStream->SetImportedDerivedKeySize( nDerivedKeySize ); + + if ( pStartKeyAlg ) + *pStartKeyAlg >>= nStartKeyAlg; + pStream->SetImportedStartKeyAlgorithm( nStartKeyAlg ); pStream->SetToBeCompressed ( sal_True ); pStream->SetToBeEncrypted ( sal_True ); pStream->SetIsEncrypted ( sal_True ); if ( !m_bHasEncryptedEntries && pStream->getName().equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "content.xml" ) ) ) ) + { m_bHasEncryptedEntries = sal_True; + m_nStartKeyGenerationID = nStartKeyAlg; + m_nChecksumDigestID = nDigestAlg; + m_nCommonEncryptionID = nEncryptionAlg; + } } else m_bHasNonEncryptedEntries = sal_True; @@ -380,7 +405,7 @@ void ZipPackage::parseManifest() nRead = aData.getLength(); if ( nRead ) - aPackageMediatype = ::rtl::OUString( (sal_Char*)aData.getConstArray(), nRead, RTL_TEXTENCODING_ASCII_US ); + aPackageMediatype = ::rtl::OUString( ( sal_Char* )aData.getConstArray(), nRead, RTL_TEXTENCODING_ASCII_US ); } } @@ -409,24 +434,35 @@ void ZipPackage::parseManifest() m_bInconsistent = m_pRootFolder->LookForUnexpectedODF12Streams( ::rtl::OUString() ); - sal_Bool bODF12AndOlder = ( m_pRootFolder->GetVersion().compareTo( ODFVER_012_TEXT ) >= 0 ); - if ( !m_bForceRecovery && bODF12AndOlder && m_bInconsistent ) + sal_Bool bODF12AndNewer = ( m_pRootFolder->GetVersion().compareTo( ODFVER_012_TEXT ) >= 0 ); + if ( !m_bForceRecovery && bODF12AndNewer ) { - // this is an ODF1.2 document that contains streams not referred in the manifest.xml; - // in case of ODF1.2 documents without version in manifest.xml the property IsInconsistent - // should be checked later - throw ZipIOException( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "there are streams not referred in manifest.xml\n" ) ), - uno::Reference< uno::XInterface >() ); + if ( m_bInconsistent ) + { + // this is an ODF1.2 document that contains streams not referred in the manifest.xml; + // in case of ODF1.2 documents without version in manifest.xml the property IsInconsistent + // should be checked later + throw ZipIOException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "there are streams not referred in manifest.xml\n" ) ), + uno::Reference< uno::XInterface >() ); + } + else if ( bDifferentStartKeyAlgorithm ) + { + // all the streams should be encrypted with the same StartKey in ODF1.2 + // TODO/LATER: in future the exception should be thrown + OSL_ENSURE( false, "ODF1.2 contains different StartKey Algorithms" ); + // throw ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "More than one Start Key Generation algorithm is specified!" ) ), uno::Reference< uno::XInterface >() ); + } } // in case it is a correct ODF1.2 document, the version must be set // and the META-INF folder is reserved for package format - if ( bODF12AndOlder ) + if ( bODF12AndNewer ) m_xRootFolder->removeByName( sMeta ); } } +//-------------------------------------------------------- void ZipPackage::parseContentType() { if ( m_nFormat == embed::StorageFormats::OFOPXML ) @@ -463,7 +499,7 @@ void ZipPackage::parseContentType() for ( nInd = 0; nInd < aContentTypeInfo[1].getLength(); nInd++ ) { ::rtl::OUString aPath; - if ( aContentTypeInfo[1][nInd].First.toChar() == (sal_Unicode)'/' ) + if ( aContentTypeInfo[1][nInd].First.toChar() == ( sal_Unicode )'/' ) aPath = aContentTypeInfo[1][nInd].First.copy( 1 ); else aPath = aContentTypeInfo[1][nInd].First; @@ -495,6 +531,7 @@ void ZipPackage::parseContentType() } } +//-------------------------------------------------------- void ZipPackage::getZipFileContents() { auto_ptr < ZipEnumeration > pEnum ( m_pZipFile->entries() ); @@ -504,7 +541,7 @@ void ZipPackage::getZipFileContents() sal_Int32 nOldIndex, nIndex, nStreamIndex; FolderHash::iterator aIter; - while (pEnum->hasMoreElements()) + while ( pEnum->hasMoreElements() ) { nIndex = nOldIndex = 0; pCurrent = m_pRootFolder; @@ -521,18 +558,18 @@ void ZipPackage::getZipFileContents() nStreamIndex = rName.lastIndexOf ( '/' ); if ( nStreamIndex != -1 ) { - sDirName = rName.copy ( 0, nStreamIndex); + sDirName = rName.copy ( 0, nStreamIndex ); aIter = m_aRecent.find ( sDirName ); if ( aIter != m_aRecent.end() ) - pCurrent = (*aIter).second; + pCurrent = ( *aIter ).second; } if ( pCurrent == m_pRootFolder ) { - while ( (nIndex = rName.indexOf('/', nOldIndex) ) != -1 ) + while ( ( nIndex = rName.indexOf( '/', nOldIndex ) ) != -1 ) { sTemp = rName.copy ( nOldIndex, nIndex - nOldIndex ); - if (nIndex == nOldIndex) + if ( nIndex == nOldIndex ) break; if ( !pCurrent->hasByName( sTemp ) ) { @@ -542,7 +579,7 @@ void ZipPackage::getZipFileContents() pCurrent = pPkgFolder; } else - pCurrent = pCurrent->doGetByName(sTemp).pFolder; + pCurrent = pCurrent->doGetByName( sTemp ).pFolder; nOldIndex = nIndex+1; } if ( nStreamIndex != -1 && sDirName.getLength() ) @@ -551,7 +588,7 @@ void ZipPackage::getZipFileContents() if ( rName.getLength() -1 != nStreamIndex ) { nStreamIndex++; - sTemp = rName.copy( nStreamIndex, rName.getLength() - nStreamIndex); + sTemp = rName.copy( nStreamIndex, rName.getLength() - nStreamIndex ); pPkgStream = new ZipPackageStream( *this, m_xFactory, m_bAllowRemoveOnInsert ); pPkgStream->SetPackageMember( sal_True ); pPkgStream->setZipEntryOnLoading( rEntry ); @@ -566,9 +603,9 @@ void ZipPackage::getZipFileContents() parseContentType(); } -// XInitialization -void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) - throw(Exception, RuntimeException) +//-------------------------------------------------------- +void SAL_CALL ZipPackage::initialize( const uno::Sequence< Any >& aArguments ) + throw( Exception, RuntimeException ) { RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "{ ZipPackage::initialize" ); sal_Bool bBadZipFile = sal_False, bHaveZipFile = sal_True; @@ -580,7 +617,7 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) for( int ind = 0; ind < aArguments.getLength(); ind++ ) { OUString aParamUrl; - if ( (aArguments[ind] >>= aParamUrl)) + if ( ( aArguments[ind] >>= aParamUrl )) { m_eMode = e_IMode_URL; try @@ -627,13 +664,13 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) if( !bHasSizeProperty || ( bHasSizeProperty && aSize ) ) { uno::Reference < XActiveDataSink > xSink = new ZipPackageSink; - if (aContent.openStream ( xSink ) ) + if ( aContent.openStream ( xSink ) ) m_xContentStream = xSink->getInputStream(); } else bHaveZipFile = sal_False; } - catch (com::sun::star::uno::Exception&) + catch ( com::sun::star::uno::Exception& ) { // Exception derived from uno::Exception thrown. This probably // means the file doesn't exist...we'll create it at @@ -641,13 +678,13 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) bHaveZipFile = sal_False; } } - else if ( (aArguments[ind] >>= m_xStream ) ) + else if ( ( aArguments[ind] >>= m_xStream ) ) { // a writable stream can implement both XStream & XInputStream m_eMode = e_IMode_XStream; m_xContentStream = m_xStream->getInputStream(); } - else if ( (aArguments[ind] >>= m_xContentStream) ) + else if ( ( aArguments[ind] >>= m_xContentStream ) ) { m_eMode = e_IMode_XInputStream; } @@ -715,7 +752,7 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) try { - if (m_xContentStream.is()) + if ( m_xContentStream.is() ) { // the stream must be seekable, if it is not it will be wrapped m_xContentStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( m_xContentStream, m_xFactory ); @@ -730,7 +767,7 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) else bHaveZipFile = sal_False; } - catch (com::sun::star::uno::Exception&) + catch ( com::sun::star::uno::Exception& ) { // Exception derived from uno::Exception thrown. This probably // means the file doesn't exist...we'll create it at @@ -773,22 +810,23 @@ void SAL_CALL ZipPackage::initialize( const Sequence< Any >& aArguments ) RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "} ZipPackage::initialize" ); } +//-------------------------------------------------------- Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) - throw(NoSuchElementException, RuntimeException) + throw( NoSuchElementException, RuntimeException ) { OUString sTemp, sDirName; sal_Int32 nOldIndex, nIndex, nStreamIndex; FolderHash::iterator aIter; - if ( (nIndex = aName.getLength() ) == 1 && *aName.getStr() == '/' ) - return makeAny ( uno::Reference < XUnoTunnel > (m_pRootFolder) ); + if ( ( nIndex = aName.getLength() ) == 1 && *aName.getStr() == '/' ) + return makeAny ( uno::Reference < XUnoTunnel > ( m_pRootFolder ) ); else { nStreamIndex = aName.lastIndexOf ( '/' ); bool bFolder = nStreamIndex == nIndex-1; if ( nStreamIndex != -1 ) { - sDirName = aName.copy ( 0, nStreamIndex); + sDirName = aName.copy ( 0, nStreamIndex ); aIter = m_aRecent.find ( sDirName ); if ( aIter != m_aRecent.end() ) { @@ -796,16 +834,16 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) { sal_Int32 nDirIndex = aName.lastIndexOf ( '/', nStreamIndex ); sTemp = aName.copy ( nDirIndex == -1 ? 0 : nDirIndex+1, nStreamIndex-nDirIndex-1 ); - if ( sTemp == (*aIter).second->getName() ) - return makeAny ( uno::Reference < XUnoTunnel > ( (*aIter).second ) ); + if ( sTemp == ( *aIter ).second->getName() ) + return makeAny ( uno::Reference < XUnoTunnel > ( ( *aIter ).second ) ); else m_aRecent.erase ( aIter ); } else { sTemp = aName.copy ( nStreamIndex + 1 ); - if ( (*aIter).second->hasByName( sTemp ) ) - return (*aIter).second->getByName( sTemp ); + if ( ( *aIter ).second->hasByName( sTemp ) ) + return ( *aIter ).second->getByName( sTemp ); else m_aRecent.erase( aIter ); } @@ -819,15 +857,15 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) nOldIndex = 0; ZipPackageFolder * pCurrent = m_pRootFolder; ZipPackageFolder * pPrevious = NULL; - while ( ( nIndex = aName.indexOf('/', nOldIndex)) != -1) + while ( ( nIndex = aName.indexOf( '/', nOldIndex )) != -1 ) { - sTemp = aName.copy (nOldIndex, nIndex - nOldIndex); + sTemp = aName.copy ( nOldIndex, nIndex - nOldIndex ); if ( nIndex == nOldIndex ) break; if ( pCurrent->hasByName( sTemp ) ) { pPrevious = pCurrent; - pCurrent = pCurrent->doGetByName(sTemp).pFolder; + pCurrent = pCurrent->doGetByName( sTemp ).pFolder; } else throw NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); @@ -835,16 +873,16 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) } if ( bFolder ) { - if (nStreamIndex != -1 ) + if ( nStreamIndex != -1 ) m_aRecent[sDirName] = pPrevious; return makeAny ( uno::Reference < XUnoTunnel > ( pCurrent ) ); } else { - sTemp = aName.copy( nOldIndex, aName.getLength() - nOldIndex); + sTemp = aName.copy( nOldIndex, aName.getLength() - nOldIndex ); if ( pCurrent->hasByName ( sTemp ) ) { - if (nStreamIndex != -1 ) + if ( nStreamIndex != -1 ) m_aRecent[sDirName] = pCurrent; return pCurrent->getByName( sTemp ); } @@ -854,14 +892,15 @@ Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) } } +//-------------------------------------------------------- sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) - throw(RuntimeException) + throw( RuntimeException ) { OUString sTemp, sDirName; sal_Int32 nOldIndex, nIndex, nStreamIndex; FolderHash::iterator aIter; - if ( (nIndex = aName.getLength() ) == 1 && *aName.getStr() == '/' ) + if ( ( nIndex = aName.getLength() ) == 1 && *aName.getStr() == '/' ) return sal_True; else { @@ -869,7 +908,7 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) bool bFolder = nStreamIndex == nIndex-1; if ( nStreamIndex != -1 ) { - sDirName = aName.copy ( 0, nStreamIndex); + sDirName = aName.copy ( 0, nStreamIndex ); aIter = m_aRecent.find ( sDirName ); if ( aIter != m_aRecent.end() ) { @@ -877,7 +916,7 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) { sal_Int32 nDirIndex = aName.lastIndexOf ( '/', nStreamIndex ); sTemp = aName.copy ( nDirIndex == -1 ? 0 : nDirIndex+1, nStreamIndex-nDirIndex-1 ); - if ( sTemp == (*aIter).second->getName() ) + if ( sTemp == ( *aIter ).second->getName() ) return sal_True; else m_aRecent.erase ( aIter ); @@ -885,7 +924,7 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) else { sTemp = aName.copy ( nStreamIndex + 1 ); - if ( (*aIter).second->hasByName( sTemp ) ) + if ( ( *aIter ).second->hasByName( sTemp ) ) return sal_True; else m_aRecent.erase( aIter ); @@ -900,9 +939,9 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) ZipPackageFolder * pCurrent = m_pRootFolder; ZipPackageFolder * pPrevious = NULL; nOldIndex = 0; - while ( ( nIndex = aName.indexOf('/', nOldIndex)) != -1) + while ( ( nIndex = aName.indexOf( '/', nOldIndex )) != -1 ) { - sTemp = aName.copy (nOldIndex, nIndex - nOldIndex); + sTemp = aName.copy ( nOldIndex, nIndex - nOldIndex ); if ( nIndex == nOldIndex ) break; if ( pCurrent->hasByName( sTemp ) ) @@ -921,7 +960,7 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) } else { - sTemp = aName.copy( nOldIndex, aName.getLength() - nOldIndex); + sTemp = aName.copy( nOldIndex, aName.getLength() - nOldIndex ); if ( pCurrent->hasByName( sTemp ) ) { @@ -933,21 +972,22 @@ sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName ) } } -// XSingleServiceFactory -uno::Reference< XInterface > SAL_CALL ZipPackage::createInstance( ) - throw(Exception, RuntimeException) +//-------------------------------------------------------- +uno::Reference< XInterface > SAL_CALL ZipPackage::createInstance() + throw( Exception, RuntimeException ) { - uno::Reference < XInterface > xRef = *(new ZipPackageStream ( *this, m_xFactory, m_bAllowRemoveOnInsert )); + uno::Reference < XInterface > xRef = *( new ZipPackageStream ( *this, m_xFactory, m_bAllowRemoveOnInsert ) ); return xRef; } -uno::Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( const Sequence< Any >& aArguments ) - throw(Exception, RuntimeException) +//-------------------------------------------------------- +uno::Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( const uno::Sequence< Any >& aArguments ) + throw( Exception, RuntimeException ) { sal_Bool bArg = sal_False; uno::Reference < XInterface > xRef; if ( aArguments.getLength() ) aArguments[0] >>= bArg; - if (bArg) + if ( bArg ) xRef = *new ZipPackageFolder ( m_xFactory, m_nFormat, m_bAllowRemoveOnInsert ); else xRef = *new ZipPackageStream ( *this, m_xFactory, m_bAllowRemoveOnInsert ); @@ -955,16 +995,17 @@ uno::Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( c return xRef; } +//-------------------------------------------------------- void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut ) { const OUString sMime ( RTL_CONSTASCII_USTRINGPARAM ( "mimetype" ) ); - if (m_xRootFolder->hasByName( sMime ) ) + if ( m_xRootFolder->hasByName( sMime ) ) m_xRootFolder->removeByName( sMime ); ZipEntry * pEntry = new ZipEntry; - sal_Int32 nBufferLength = m_pRootFolder->GetMediaType( ).getLength(); + sal_Int32 nBufferLength = m_pRootFolder->GetMediaType().getLength(); OString sMediaType = OUStringToOString( m_pRootFolder->GetMediaType(), RTL_TEXTENCODING_ASCII_US ); - Sequence< sal_Int8 > aType( (sal_Int8*)sMediaType.getStr(), + uno::Sequence< sal_Int8 > aType( ( sal_Int8* )sMediaType.getStr(), nBufferLength ); @@ -979,14 +1020,12 @@ void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut ) try { - vos::ORef < EncryptionData > xEmpty; - aZipOut.putNextEntry( *pEntry, xEmpty ); + aZipOut.putNextEntry( *pEntry, NULL ); aZipOut.write( aType, 0, nBufferLength ); aZipOut.closeEntry(); } catch ( ::com::sun::star::io::IOException & r ) { - VOS_ENSURE( 0, "Error adding mimetype to the ZipOutputStream" ); throw WrappedTargetException( OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "Error adding mimetype to the ZipOutputStream!" ) ), static_cast < OWeakObject * > ( this ), @@ -994,7 +1033,8 @@ void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut ) } } -void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< Sequence < PropertyValue > >& aManList ) +//-------------------------------------------------------- +void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< uno::Sequence < PropertyValue > >& aManList ) { // Write the manifest uno::Reference < XOutputStream > xManOutStream; @@ -1004,28 +1044,29 @@ void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< Sequence { ZipEntry * pEntry = new ZipEntry; ZipPackageBuffer *pBuffer = new ZipPackageBuffer( n_ConstBufferSize ); - xManOutStream = uno::Reference < XOutputStream > (*pBuffer, UNO_QUERY); + xManOutStream = uno::Reference < XOutputStream > ( *pBuffer, UNO_QUERY ); - pEntry->sPath = OUString( RTL_CONSTASCII_USTRINGPARAM ( "META-INF/manifest.xml") ); + pEntry->sPath = OUString( RTL_CONSTASCII_USTRINGPARAM ( "META-INF/manifest.xml" ) ); pEntry->nMethod = DEFLATED; pEntry->nCrc = pEntry->nSize = pEntry->nCompressedSize = -1; pEntry->nTime = ZipOutputStream::getCurrentDosTime(); - // Convert vector into a Sequence - Sequence < Sequence < PropertyValue > > aManifestSequence ( aManList.size() ); - Sequence < PropertyValue > * pSequence = aManifestSequence.getArray(); - for (vector < Sequence < PropertyValue > >::const_iterator aIter = aManList.begin(), aEnd = aManList.end(); + // Convert vector into a uno::Sequence + uno::Sequence < uno::Sequence < PropertyValue > > aManifestSequence ( aManList.size() ); + sal_Int32 nInd = 0; + for ( vector < uno::Sequence < PropertyValue > >::const_iterator aIter = aManList.begin(), aEnd = aManList.end(); aIter != aEnd; - aIter++, pSequence++) - *pSequence= (*aIter); + aIter++, nInd++ ) + { + aManifestSequence[nInd] = ( *aIter ); + } xWriter->writeManifestSequence ( xManOutStream, aManifestSequence ); sal_Int32 nBufferLength = static_cast < sal_Int32 > ( pBuffer->getPosition() ); pBuffer->realloc( nBufferLength ); // the manifest.xml is never encrypted - so pass an empty reference - vos::ORef < EncryptionData > xEmpty; - aZipOut.putNextEntry( *pEntry, xEmpty ); + aZipOut.putNextEntry( *pEntry, NULL ); aZipOut.write( pBuffer->getSequence(), 0, nBufferLength ); aZipOut.closeEntry(); } @@ -1040,7 +1081,8 @@ void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< Sequence } } -void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< Sequence < PropertyValue > >& aManList ) +//-------------------------------------------------------- +void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< uno::Sequence < PropertyValue > >& aManList ) { const OUString sFullPath ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); const OUString sMediaType ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); @@ -1049,12 +1091,12 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< Sequ ZipPackageBuffer *pBuffer = new ZipPackageBuffer( n_ConstBufferSize ); uno::Reference< io::XOutputStream > xConTypeOutStream( *pBuffer, UNO_QUERY ); - pEntry->sPath = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "[Content_Types].xml") ); + pEntry->sPath = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "[Content_Types].xml" ) ); pEntry->nMethod = DEFLATED; pEntry->nCrc = pEntry->nSize = pEntry->nCompressedSize = -1; pEntry->nTime = ZipOutputStream::getCurrentDosTime(); - // Convert vector into a Sequence + // Convert vector into a uno::Sequence // TODO/LATER: use Defaulst entries in future uno::Sequence< beans::StringPair > aDefaultsSequence; uno::Sequence< beans::StringPair > aOverridesSequence( aManList.size() ); @@ -1062,18 +1104,18 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< Sequ for ( vector< uno::Sequence< beans::PropertyValue > >::const_iterator aIter = aManList.begin(), aEnd = aManList.end(); aIter != aEnd; - aIter++) + aIter++ ) { ::rtl::OUString aPath; ::rtl::OUString aType; - OSL_ENSURE( (*aIter)[PKG_MNFST_MEDIATYPE].Name.equals( sMediaType ) && (*aIter)[PKG_MNFST_FULLPATH].Name.equals( sFullPath ), + OSL_ENSURE( ( *aIter )[PKG_MNFST_MEDIATYPE].Name.equals( sMediaType ) && ( *aIter )[PKG_MNFST_FULLPATH].Name.equals( sFullPath ), "The mediatype sequence format is wrong!\n" ); - (*aIter)[PKG_MNFST_MEDIATYPE].Value >>= aType; + ( *aIter )[PKG_MNFST_MEDIATYPE].Value >>= aType; if ( aType.getLength() ) { // only nonempty type makes sence here nSeqLength++; - (*aIter)[PKG_MNFST_FULLPATH].Value >>= aPath; + ( *aIter )[PKG_MNFST_FULLPATH].Value >>= aPath; aOverridesSequence[nSeqLength-1].First = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) + aPath; aOverridesSequence[nSeqLength-1].Second = aType; } @@ -1087,12 +1129,12 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< Sequ pBuffer->realloc( nBufferLength ); // there is no encryption in this format currently - vos::ORef < EncryptionData > xEmpty; - aZipOut.putNextEntry( *pEntry, xEmpty ); + aZipOut.putNextEntry( *pEntry, NULL ); aZipOut.write( pBuffer->getSequence(), 0, nBufferLength ); aZipOut.closeEntry(); } +//-------------------------------------------------------- void ZipPackage::ConnectTo( const uno::Reference< io::XInputStream >& xInStream ) { m_xContentSeek.set( xInStream, uno::UNO_QUERY_THROW ); @@ -1106,6 +1148,7 @@ void ZipPackage::ConnectTo( const uno::Reference< io::XInputStream >& xInStream m_pZipFile = new ZipFile ( m_xContentStream, m_xFactory, sal_False ); } +//-------------------------------------------------------- uno::Reference< io::XInputStream > ZipPackage::writeTempFile() { // In case the target local file does not exist or empty @@ -1152,9 +1195,9 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() } // Hand it to the ZipOutputStream: - ZipOutputStream aZipOut ( xTempOut ); - aZipOut.setMethod(DEFLATED); - aZipOut.setLevel(DEFAULT_COMPRESSION); + ZipOutputStream aZipOut( m_xFactory, xTempOut ); + aZipOut.setMethod( DEFLATED ); + aZipOut.setLevel( DEFAULT_COMPRESSION ); try { @@ -1167,7 +1210,7 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() if ( m_xRootFolder->hasByName( sMeta ) ) { - const OUString sManifest (RTL_CONSTASCII_USTRINGPARAM( "manifest.xml") ); + const OUString sManifest ( RTL_CONSTASCII_USTRINGPARAM( "manifest.xml" ) ); uno::Reference< XUnoTunnel > xTunnel; Any aAny = m_xRootFolder->getByName( sMeta ); @@ -1192,7 +1235,7 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() } // Create a vector to store data for the manifest.xml file - vector < Sequence < PropertyValue > > aManList; + vector < uno::Sequence < PropertyValue > > aManList; const OUString sMediaType ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); const OUString sVersion ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ); @@ -1200,11 +1243,11 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() if ( m_nFormat == embed::StorageFormats::PACKAGE ) { - Sequence < PropertyValue > aPropSeq ( PKG_SIZE_NOENCR_MNFST ); + uno::Sequence < PropertyValue > aPropSeq( PKG_SIZE_NOENCR_MNFST ); aPropSeq [PKG_MNFST_MEDIATYPE].Name = sMediaType; - aPropSeq [PKG_MNFST_MEDIATYPE].Value <<= m_pRootFolder->GetMediaType( ); + aPropSeq [PKG_MNFST_MEDIATYPE].Value <<= m_pRootFolder->GetMediaType(); aPropSeq [PKG_MNFST_VERSION].Name = sVersion; - aPropSeq [PKG_MNFST_VERSION].Value <<= m_pRootFolder->GetVersion( ); + aPropSeq [PKG_MNFST_VERSION].Value <<= m_pRootFolder->GetVersion(); aPropSeq [PKG_MNFST_FULLPATH].Name = sFullPath; aPropSeq [PKG_MNFST_FULLPATH].Value <<= OUString ( RTL_CONSTASCII_USTRINGPARAM ( "/" ) ); @@ -1219,15 +1262,14 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() rtlRandomPool aRandomPool = rtl_random_createPool (); rtl_random_addBytes ( aRandomPool, &aTime, 8 ); - - // call saveContents (it will recursively save sub-directories + // call saveContents ( it will recursively save sub-directories OUString aEmptyString; - m_pRootFolder->saveContents( aEmptyString, aManList, aZipOut, m_aEncryptionKey, aRandomPool ); + m_pRootFolder->saveContents( aEmptyString, aManList, aZipOut, GetEncryptionKey(), aRandomPool ); // Clean up random pool memory rtl_random_destroyPool ( aRandomPool ); - if( m_bUseManifest && m_nFormat == embed::StorageFormats::PACKAGE ) + if( m_nFormat == embed::StorageFormats::PACKAGE ) { WriteManifest( aZipOut, aManList ); } @@ -1296,10 +1338,11 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() return xResult; } +//-------------------------------------------------------- uno::Reference< XActiveDataStreamer > ZipPackage::openOriginalForOutput() { // open and truncate the original file - Content aOriginalContent (m_aURL, uno::Reference < XCommandEnvironment >() ); + Content aOriginalContent ( m_aURL, uno::Reference < XCommandEnvironment >() ); uno::Reference< XActiveDataStreamer > xSink = new ActiveDataStreamer; if ( m_eMode == e_IMode_URL ) @@ -1333,7 +1376,7 @@ uno::Reference< XActiveDataStreamer > ZipPackage::openOriginalForOutput() aArg.Mode = OpenMode::DOCUMENT; aArg.Priority = 0; // unused aArg.Sink = xSink; - aArg.Properties = Sequence< Property >( 0 ); // unused + aArg.Properties = uno::Sequence< Property >( 0 ); // unused aOriginalContent.executeCommand( OUString::createFromAscii( "open" ), makeAny( aArg ) ); } @@ -1347,9 +1390,9 @@ uno::Reference< XActiveDataStreamer > ZipPackage::openOriginalForOutput() return xSink; } -// XChangesBatch +//-------------------------------------------------------- void SAL_CALL ZipPackage::commitChanges() - throw(WrappedTargetException, RuntimeException) + throw( WrappedTargetException, RuntimeException ) { // lock the component for the time of commiting ::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() ); @@ -1412,8 +1455,8 @@ void SAL_CALL ZipPackage::commitChanges() ::comphelper::OStorageHelper::CopyInputToOutput( xTempInStream, xOutputStream ); xOutputStream->flush(); uno::Reference< io::XAsyncOutputMonitor > asyncOutputMonitor( - xOutputStream, uno::UNO_QUERY); - if (asyncOutputMonitor.is()) { + xOutputStream, uno::UNO_QUERY ); + if ( asyncOutputMonitor.is() ) { asyncOutputMonitor->waitForCompletion(); } } @@ -1499,7 +1542,7 @@ void SAL_CALL ZipPackage::commitChanges() // if the file is still not corrupted, it can become after the next step aContent.executeCommand ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "transfer" ) ), aAny ); } - catch (::com::sun::star::uno::Exception& r) + catch ( ::com::sun::star::uno::Exception& r ) { if ( bCanBeCorrupted ) DisconnectFromTargetAndThrowException_Impl( xTempInStream ); @@ -1519,6 +1562,7 @@ void SAL_CALL ZipPackage::commitChanges() RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "} ZipPackage::commitChanges" ); } +//-------------------------------------------------------- void ZipPackage::DisconnectFromTargetAndThrowException_Impl( const uno::Reference< io::XInputStream >& xTempStream ) { m_xStream = uno::Reference< io::XStream >( xTempStream, uno::UNO_QUERY ); @@ -1547,15 +1591,47 @@ void ZipPackage::DisconnectFromTargetAndThrowException_Impl( const uno::Referenc makeAny ( aException ) ); } -sal_Bool SAL_CALL ZipPackage::hasPendingChanges( ) - throw(RuntimeException) +//-------------------------------------------------------- +const uno::Sequence< sal_Int8 > ZipPackage::GetEncryptionKey() +{ + uno::Sequence< sal_Int8 > aResult; + + if ( m_aStorageEncryptionKeys.getLength() ) + { + ::rtl::OUString aNameToFind; + if ( m_nStartKeyGenerationID == xml::crypto::DigestID::SHA256 ) + aNameToFind = PACKAGE_ENCRYPTIONDATA_SHA256UTF8; + else if ( m_nStartKeyGenerationID == xml::crypto::DigestID::SHA1 ) + aNameToFind = PACKAGE_ENCRYPTIONDATA_SHA1UTF8; + else + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No expected key is provided!" ) ), uno::Reference< uno::XInterface >() ); + + for ( sal_Int32 nInd = 0; nInd < m_aStorageEncryptionKeys.getLength(); nInd++ ) + if ( m_aStorageEncryptionKeys[nInd].Name.equals( aNameToFind ) ) + m_aStorageEncryptionKeys[nInd].Value >>= aResult; + + // empty keys are not allowed here + // so it is not important whether there is no key, or the key is empty, it is an error + if ( !aResult.getLength() ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No expected key is provided!" ) ), uno::Reference< uno::XInterface >() ); + } + else + aResult = m_aEncryptionKey; + + return aResult; +} + +//-------------------------------------------------------- +sal_Bool SAL_CALL ZipPackage::hasPendingChanges() + throw( RuntimeException ) { return sal_False; } -Sequence< ElementChange > SAL_CALL ZipPackage::getPendingChanges( ) - throw(RuntimeException) +//-------------------------------------------------------- +Sequence< ElementChange > SAL_CALL ZipPackage::getPendingChanges() + throw( RuntimeException ) { - return Sequence < ElementChange > (); + return uno::Sequence < ElementChange > (); } /** @@ -1565,149 +1641,246 @@ Sequence< ElementChange > SAL_CALL ZipPackage::getPendingChanges( ) uno::Reference < XInterface >SAL_CALL ZipPackage_createInstance( const uno::Reference< XMultiServiceFactory > & xMgr ) { - return uno::Reference< XInterface >( *new ZipPackage(xMgr) ); + return uno::Reference< XInterface >( *new ZipPackage( xMgr ) ); } +//-------------------------------------------------------- OUString ZipPackage::static_getImplementationName() { return OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.comp.ZipPackage" ) ); } +//-------------------------------------------------------- Sequence< OUString > ZipPackage::static_getSupportedServiceNames() { - Sequence< OUString > aNames(1); + uno::Sequence< OUString > aNames( 1 ); aNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.Package" ) ); return aNames; } +//-------------------------------------------------------- sal_Bool SAL_CALL ZipPackage::static_supportsService( OUString const & rServiceName ) { return rServiceName == getSupportedServiceNames()[0]; } +//-------------------------------------------------------- OUString ZipPackage::getImplementationName() - throw (RuntimeException) + throw ( RuntimeException ) { return static_getImplementationName(); } +//-------------------------------------------------------- Sequence< OUString > ZipPackage::getSupportedServiceNames() - throw (RuntimeException) + throw ( RuntimeException ) { return static_getSupportedServiceNames(); } +//-------------------------------------------------------- sal_Bool SAL_CALL ZipPackage::supportsService( OUString const & rServiceName ) - throw (RuntimeException) + throw ( RuntimeException ) { return static_supportsService ( rServiceName ); } +//-------------------------------------------------------- uno::Reference < XSingleServiceFactory > ZipPackage::createServiceFactory( uno::Reference < XMultiServiceFactory > const & rServiceFactory ) { - return cppu::createSingleFactory (rServiceFactory, + return cppu::createSingleFactory ( rServiceFactory, static_getImplementationName(), ZipPackage_createInstance, - static_getSupportedServiceNames()); + static_getSupportedServiceNames() ); } namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; } -// XUnoTunnel +//-------------------------------------------------------- Sequence< sal_Int8 > ZipPackage::getUnoTunnelImplementationId( void ) - throw (RuntimeException) + throw ( RuntimeException ) { ::cppu::OImplementationId &rId = lcl_ImplId::get(); return rId.getImplementationId(); } -sal_Int64 SAL_CALL ZipPackage::getSomething( const Sequence< sal_Int8 >& aIdentifier ) - throw(RuntimeException) +//-------------------------------------------------------- +sal_Int64 SAL_CALL ZipPackage::getSomething( const uno::Sequence< sal_Int8 >& aIdentifier ) + throw( RuntimeException ) { - if (aIdentifier.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), aIdentifier.getConstArray(), 16 ) ) + if ( aIdentifier.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelImplementationId().getConstArray(), aIdentifier.getConstArray(), 16 ) ) return reinterpret_cast < sal_Int64 > ( this ); return 0; } -uno::Reference< XPropertySetInfo > SAL_CALL ZipPackage::getPropertySetInfo( ) - throw(RuntimeException) +//-------------------------------------------------------- +uno::Reference< XPropertySetInfo > SAL_CALL ZipPackage::getPropertySetInfo() + throw( RuntimeException ) { return uno::Reference < XPropertySetInfo > (); } + +//-------------------------------------------------------- void SAL_CALL ZipPackage::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) - throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException) + throw( UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException ) { if ( m_nFormat != embed::StorageFormats::PACKAGE ) throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("HasEncryptedEntries") ) - ||aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("HasNonEncryptedEntries") ) - ||aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("IsInconsistent") ) - ||aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("MediaTypeFallbackUsed") ) ) + if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( HAS_ENCRYPTED_ENTRIES_PROPERTY ) ) + ||aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( HAS_NONENCRYPTED_ENTRIES_PROPERTY ) ) + ||aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( IS_INCONSISTENT_PROPERTY ) ) + ||aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) ) throw PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("EncryptionKey") ) ) + else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_KEY_PROPERTY ) ) ) { - if (!( aValue >>= m_aEncryptionKey ) || m_aEncryptionKey.getLength() == 0 ) + if ( !( aValue >>= m_aEncryptionKey ) ) throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); + + m_aStorageEncryptionKeys.realloc( 0 ); } - else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("UseManifest") ) ) + else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) ) { - if (!( aValue >>= m_bUseManifest ) ) + // this property is only necessary to support raw passwords in storage API; + // because of this support the storage has to operate with more than one key dependent on storage generation algorithm; + // when this support is removed, the storage will get only one key from outside + // TODO/LATER: Get rid of this property as well as of support of raw passwords in storages + uno::Sequence< beans::NamedValue > aKeys; + if ( !( aValue >>= aKeys ) || ( aKeys.getLength() && aKeys.getLength() < 2 ) ) throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); + + if ( aKeys.getLength() ) + { + bool bHasSHA256 = false; + bool bHasSHA1 = false; + for ( sal_Int32 nInd = 0; nInd < aKeys.getLength(); nInd++ ) + { + if ( aKeys[nInd].Name.equals( PACKAGE_ENCRYPTIONDATA_SHA256UTF8 ) ) + bHasSHA256 = true; + if ( aKeys[nInd].Name.equals( PACKAGE_ENCRYPTIONDATA_SHA1UTF8 ) ) + bHasSHA1 = true; + } + + if ( !bHasSHA256 || !bHasSHA1 ) + throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Expected keys are not provided!" ) ), uno::Reference< uno::XInterface >(), 2 ); + } + + m_aStorageEncryptionKeys = aKeys; + m_aEncryptionKey.realloc( 0 ); + } + else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ) ) + { + uno::Sequence< beans::NamedValue > aAlgorithms; + if ( m_pZipFile || !( aValue >>= aAlgorithms ) || aAlgorithms.getLength() == 0 ) + { + // the algorithms can not be changed if the file has a persistence based on the algorithms ( m_pZipFile ) + throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "unexpected algorithms list is provided." ) ), uno::Reference< uno::XInterface >(), 2 ); + } + + for ( sal_Int32 nInd = 0; nInd < aAlgorithms.getLength(); nInd++ ) + { + if ( aAlgorithms[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "StartKeyGenerationAlgorithm" ) ) ) + { + sal_Int32 nID = 0; + if ( !( aAlgorithms[nInd].Value >>= nID ) + || ( nID != xml::crypto::DigestID::SHA256 && nID != xml::crypto::DigestID::SHA1 ) ) + throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected start key generation algorithm is provided!" ) ), uno::Reference< uno::XInterface >(), 2 ); + + m_nStartKeyGenerationID = nID; + } + else if ( aAlgorithms[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "EncryptionAlgorithm" ) ) ) + { + sal_Int32 nID = 0; + if ( !( aAlgorithms[nInd].Value >>= nID ) + || ( nID != xml::crypto::CipherID::AES_CBC_W3C_PADDING && nID != xml::crypto::CipherID::BLOWFISH_CFB_8 ) ) + throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected start key generation algorithm is provided!" ) ), uno::Reference< uno::XInterface >(), 2 ); + + m_nCommonEncryptionID = nID; + } + else if ( aAlgorithms[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ChecksumAlgorithm" ) ) ) + { + sal_Int32 nID = 0; + if ( !( aAlgorithms[nInd].Value >>= nID ) + || ( nID != xml::crypto::DigestID::SHA1_1K && nID != xml::crypto::DigestID::SHA256_1K ) ) + throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected start key generation algorithm is provided!" ) ), uno::Reference< uno::XInterface >(), 2 ); + + m_nChecksumDigestID = nID; + } + else + { + OSL_ENSURE( sal_False, "Unexpected encryption algorithm is provided!" ); + throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "unexpected algorithms list is provided." ) ), uno::Reference< uno::XInterface >(), 2 ); + } + } } else throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); } + +//-------------------------------------------------------- Any SAL_CALL ZipPackage::getPropertyValue( const OUString& PropertyName ) - throw(UnknownPropertyException, WrappedTargetException, RuntimeException) + throw( UnknownPropertyException, WrappedTargetException, RuntimeException ) { // TODO/LATER: Activate the check when zip-ucp is ready // if ( m_nFormat != embed::StorageFormats::PACKAGE ) // throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); Any aAny; - if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "EncryptionKey" ) ) ) + if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( ENCRYPTION_KEY_PROPERTY ) ) ) { aAny <<= m_aEncryptionKey; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "HasEncryptedEntries" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ) ) { - aAny <<= m_bHasEncryptedEntries; + ::comphelper::SequenceAsHashMap aAlgorithms; + aAlgorithms[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StartKeyGenerationAlgorithm" ) ) ] <<= m_nStartKeyGenerationID; + aAlgorithms[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionAlgorithm" ) ) ] <<= m_nCommonEncryptionID; + aAlgorithms[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ChecksumAlgorithm" ) ) ] <<= m_nChecksumDigestID; + aAny <<= aAlgorithms.getAsConstNamedValueList(); return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "HasNonEncryptedEntries" ) ) ) + if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) ) { - aAny <<= m_bHasNonEncryptedEntries; + aAny <<= m_aStorageEncryptionKeys; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "IsInconsistent" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( HAS_ENCRYPTED_ENTRIES_PROPERTY ) ) ) { - aAny <<= m_bInconsistent; + aAny <<= m_bHasEncryptedEntries; + return aAny; + } + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( HAS_NONENCRYPTED_ENTRIES_PROPERTY ) ) ) + { + aAny <<= m_bHasNonEncryptedEntries; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "UseManifest" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( IS_INCONSISTENT_PROPERTY ) ) ) { - aAny <<= m_bUseManifest; + aAny <<= m_bInconsistent; return aAny; } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "MediaTypeFallbackUsed" ) ) ) + else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) ) { aAny <<= m_bMediaTypeFallbackUsed; return aAny; } throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); } +//-------------------------------------------------------- void SAL_CALL ZipPackage::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ ) - throw(UnknownPropertyException, WrappedTargetException, RuntimeException) + throw( UnknownPropertyException, WrappedTargetException, RuntimeException ) { } +//-------------------------------------------------------- void SAL_CALL ZipPackage::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*aListener*/ ) - throw(UnknownPropertyException, WrappedTargetException, RuntimeException) + throw( UnknownPropertyException, WrappedTargetException, RuntimeException ) { } +//-------------------------------------------------------- void SAL_CALL ZipPackage::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< XVetoableChangeListener >& /*aListener*/ ) - throw(UnknownPropertyException, WrappedTargetException, RuntimeException) + throw( UnknownPropertyException, WrappedTargetException, RuntimeException ) { } +//-------------------------------------------------------- void SAL_CALL ZipPackage::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< XVetoableChangeListener >& /*aListener*/ ) - throw(UnknownPropertyException, WrappedTargetException, RuntimeException) + throw( UnknownPropertyException, WrappedTargetException, RuntimeException ) { } diff --git a/package/source/zippackage/ZipPackageEntry.cxx b/package/source/zippackage/ZipPackageEntry.cxx index 7514e7b6f55a..a1f752174dc6 100644 --- a/package/source/zippackage/ZipPackageEntry.cxx +++ b/package/source/zippackage/ZipPackageEntry.cxx @@ -73,18 +73,18 @@ void SAL_CALL ZipPackageEntry::setName( const OUString& aName ) // unfortunately no other exception than RuntimeException can be thrown here // usually the package is used through storage implementation, the problem should be detected there if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName, sal_True ) ) - throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected character is used in file name." ) ), Reference< XInterface >() ); + throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected character is used in file name." ) ), uno::Reference< XInterface >() ); msName = aName; if ( pParent ) pParent->doInsertByName ( this, sal_False ); } -Reference< XInterface > SAL_CALL ZipPackageEntry::getParent( ) +uno::Reference< XInterface > SAL_CALL ZipPackageEntry::getParent( ) throw(RuntimeException) { - // return Reference< XInterface >( xParent, UNO_QUERY ); - return Reference< XInterface >( static_cast< ::cppu::OWeakObject* >( pParent ), UNO_QUERY ); + // return uno::Reference< XInterface >( xParent, UNO_QUERY ); + return uno::Reference< XInterface >( static_cast< ::cppu::OWeakObject* >( pParent ), UNO_QUERY ); } void ZipPackageEntry::doSetParent ( ZipPackageFolder * pNewParent, sal_Bool bInsert ) @@ -95,11 +95,11 @@ void ZipPackageEntry::doSetParent ( ZipPackageFolder * pNewParent, sal_Bool bIns pNewParent->doInsertByName ( this, sal_False ); } -void SAL_CALL ZipPackageEntry::setParent( const Reference< XInterface >& xNewParent ) +void SAL_CALL ZipPackageEntry::setParent( const uno::Reference< XInterface >& xNewParent ) throw(NoSupportException, RuntimeException) { sal_Int64 nTest(0); - Reference < XUnoTunnel > xTunnel ( xNewParent, UNO_QUERY ); + uno::Reference < XUnoTunnel > xTunnel ( xNewParent, UNO_QUERY ); if ( !xNewParent.is() || ( nTest = xTunnel->getSomething ( ZipPackageFolder::static_getImplementationId () ) ) == 0 ) throw NoSupportException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); @@ -113,24 +113,24 @@ void SAL_CALL ZipPackageEntry::setParent( const Reference< XInterface >& xNewPar } } //XPropertySet -Reference< beans::XPropertySetInfo > SAL_CALL ZipPackageEntry::getPropertySetInfo( ) +uno::Reference< beans::XPropertySetInfo > SAL_CALL ZipPackageEntry::getPropertySetInfo( ) throw(RuntimeException) { - return Reference < beans::XPropertySetInfo > (); + return uno::Reference < beans::XPropertySetInfo > (); } -void SAL_CALL ZipPackageEntry::addPropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< beans::XPropertyChangeListener >& /*xListener*/ ) +void SAL_CALL ZipPackageEntry::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ ) throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException) { } -void SAL_CALL ZipPackageEntry::removePropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< beans::XPropertyChangeListener >& /*aListener*/ ) +void SAL_CALL ZipPackageEntry::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ ) throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException) { } -void SAL_CALL ZipPackageEntry::addVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< beans::XVetoableChangeListener >& /*aListener*/ ) +void SAL_CALL ZipPackageEntry::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException) { } -void SAL_CALL ZipPackageEntry::removeVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< beans::XVetoableChangeListener >& /*aListener*/ ) +void SAL_CALL ZipPackageEntry::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException) { } diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx index 5bb5b4db89b6..0d78fe42cd34 100644 --- a/package/source/zippackage/ZipPackageFolder.cxx +++ b/package/source/zippackage/ZipPackageFolder.cxx @@ -46,23 +46,22 @@ #include <rtl/instance.hxx> #include <memory> +using namespace com::sun::star; using namespace com::sun::star::packages::zip::ZipConstants; using namespace com::sun::star::packages::zip; using namespace com::sun::star::package |