summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorJoachim Lingner <jl@openoffice.org>2010-06-30 17:12:59 +0200
committerJoachim Lingner <jl@openoffice.org>2010-06-30 17:12:59 +0200
commitb4044311c5352fa76f833486ae26b90a35eae484 (patch)
treed0a9d6c3644aa3766d4c7523dcee3ba301479699 /comphelper
parent02db8f758ee7b9e8f4538312ffdc2f79f4df3c12 (diff)
parentbe588658ea127a6a05390435126f1d739a477b58 (diff)
jl154 merge with DEV300_m84
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/inc/comphelper/docpasswordhelper.hxx111
-rwxr-xr-x[-rw-r--r--]comphelper/inc/comphelper/docpasswordrequest.hxx23
-rw-r--r--comphelper/inc/comphelper/mediadescriptor.hxx51
-rw-r--r--comphelper/source/misc/docpasswordhelper.cxx233
-rw-r--r--comphelper/source/misc/docpasswordrequest.cxx86
-rw-r--r--comphelper/source/misc/mediadescriptor.cxx93
-rw-r--r--comphelper/source/misc/officerestartmanager.cxx4
7 files changed, 539 insertions, 62 deletions
diff --git a/comphelper/inc/comphelper/docpasswordhelper.hxx b/comphelper/inc/comphelper/docpasswordhelper.hxx
index 0a60c4b53ce9..dbbb68372a07 100644
--- a/comphelper/inc/comphelper/docpasswordhelper.hxx
+++ b/comphelper/inc/comphelper/docpasswordhelper.hxx
@@ -33,6 +33,7 @@
#include "comphelper/docpasswordrequest.hxx"
namespace com { namespace sun { namespace star { namespace task { class XInteractionHandler; } } } }
+namespace com { namespace sun { namespace star { namespace beans { struct PropertyValue; } } } }
namespace comphelper {
@@ -84,6 +85,116 @@ class COMPHELPER_DLLPUBLIC DocPasswordHelper
public:
// ------------------------------------------------------------------------
+ /** This helper function generates the information related
+ to "Password to modify" provided by user. The result
+ sequence contains the hash and the algorithm-related
+ info.
+
+ @param aString
+ The string for which the info should be generated
+
+ @return
+ The sequence containing the hash and the algorithm-related info
+ */
+
+ static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >
+ GenerateNewModifyPasswordInfo( const ::rtl::OUString& aPassword );
+
+ // ------------------------------------------------------------------------
+
+ /** This helper function allows to check whether
+ the "Password to modify" provided by user is the correct one.
+
+ @param aString
+ The string containing the provided password
+
+ @param aInfo
+ The sequence containing the hash and the algorithm-info
+
+ @return
+ <TRUE/> if the password is correct one
+ <FALSE/> otherwise
+ */
+
+ static sal_Bool IsModifyPasswordCorrect(
+ const ::rtl::OUString& aPassword,
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aInfo );
+
+
+ // ------------------------------------------------------------------------
+
+ /** This helper function generates the hash code based on the algorithm
+ specified by MS for "Password to modify" feature of Word.
+
+ @param aString
+ The string for which the hash should be calculated
+
+ @return
+ The hash represented by sal_uInt32
+ */
+
+ static sal_uInt32 GetWordHashAsUINT32(
+ const ::rtl::OUString& aString );
+
+ // ------------------------------------------------------------------------
+
+ /** This helper function generates the hash code based on the algorithm
+ specified by MS for "Password to modify" feature of Word.
+
+ @param aString
+ The string for which the hash should be calculated
+
+ @return
+ The hash represented by sequence of bytes in BigEndian form
+ */
+
+ static ::com::sun::star::uno::Sequence< sal_Int8 > GetWordHashAsSequence(
+ const ::rtl::OUString& aString );
+
+ // ------------------------------------------------------------------------
+
+ /** This helper function generates the hash code based on the algorithm
+ specified by MS for "Password to modify" and passwords related to
+ table protection of Excel.
+
+ @param aString
+ The string for which the hash should be calculated
+
+ @param nEnc
+ The encoding that should be used to generate the 8-bit string
+ before the hash is generated
+
+ @return
+ The hash represented by sal_uInt16
+ */
+
+ static sal_uInt16 GetXLHashAsUINT16(
+ const ::rtl::OUString& aString,
+ rtl_TextEncoding nEnc = RTL_TEXTENCODING_UTF8 );
+
+ // ------------------------------------------------------------------------
+
+ /** This helper function generates the hash code based on the algorithm
+ specified by MS for "Password to modify" and passwords related to
+ table protection.
+
+ @param aString
+ The string for which the hash should be calculated
+
+ @param nEnc
+ The encoding that should be used to generate the 8-bit string
+ before the hash is generated
+
+ @return
+ The hash represented by sequence of bytes in BigEndian form
+ */
+
+ static ::com::sun::star::uno::Sequence< sal_Int8 > GetXLHashAsSequence(
+ const ::rtl::OUString& aString,
+ rtl_TextEncoding nEnc = RTL_TEXTENCODING_UTF8 );
+
+ // ------------------------------------------------------------------------
+
/** This helper function tries to request and verify a password to load a
protected document.
diff --git a/comphelper/inc/comphelper/docpasswordrequest.hxx b/comphelper/inc/comphelper/docpasswordrequest.hxx
index 7b186b3a261a..cf04d22c7a6d 100644..100755
--- a/comphelper/inc/comphelper/docpasswordrequest.hxx
+++ b/comphelper/inc/comphelper/docpasswordrequest.hxx
@@ -32,6 +32,7 @@
#include <com/sun/star/task/PasswordRequestMode.hpp>
#include <com/sun/star/task/XInteractionRequest.hpp>
#include <cppuhelper/implbase1.hxx>
+#include <cppuhelper/weak.hxx>
namespace comphelper {
@@ -52,19 +53,31 @@ class PasswordContinuation;
/** Implements the task.XInteractionRequest interface for requesting a password
string for a document.
*/
-class COMPHELPER_DLLPUBLIC DocPasswordRequest : public ::cppu::WeakImplHelper1< ::com::sun::star::task::XInteractionRequest >
+class COMPHELPER_DLLPUBLIC DocPasswordRequest :
+ public ::com::sun::star::task::XInteractionRequest,
+ public ::cppu::OWeakObject
{
public:
explicit DocPasswordRequest(
DocPasswordRequestType eType,
::com::sun::star::task::PasswordRequestMode eMode,
- const ::rtl::OUString& rDocumentName );
+ const ::rtl::OUString& rDocumentName,
+ sal_Bool bPasswordToModify = sal_False );
virtual ~DocPasswordRequest();
- bool isAbort() const;
- bool isPassword() const;
+ // XInterface / OWeakObject
+ virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL acquire( ) throw ();
+ virtual void SAL_CALL release( ) throw ();
+
+ sal_Bool isAbort() const;
+ sal_Bool isPassword() const;
+
::rtl::OUString getPassword() const;
+ ::rtl::OUString getPasswordToModify() const;
+ sal_Bool getRecommendReadOnly() const;
+
private:
virtual ::com::sun::star::uno::Any SAL_CALL
getRequest() throw( ::com::sun::star::uno::RuntimeException );
@@ -78,6 +91,8 @@ private:
::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > > maContinuations;
AbortContinuation* mpAbort;
PasswordContinuation* mpPassword;
+
+ sal_Bool mbPasswordToModify;
};
// ============================================================================
diff --git a/comphelper/inc/comphelper/mediadescriptor.hxx b/comphelper/inc/comphelper/mediadescriptor.hxx
index e20440a3d30d..7d2333045390 100644
--- a/comphelper/inc/comphelper/mediadescriptor.hxx
+++ b/comphelper/inc/comphelper/mediadescriptor.hxx
@@ -127,6 +127,9 @@ class COMPHELPER_DLLPUBLIC MediaDescriptor : public SequenceAsHashMap
//-------------------------------------------
// interface
public:
+ /** Value type of the 'ComponentData' property.
+ */
+ typedef ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > ComponentDataSequence;
//---------------------------------------
/** @short these ctors do nothing - excepting that they forward
@@ -197,6 +200,54 @@ class COMPHELPER_DLLPUBLIC MediaDescriptor : public SequenceAsHashMap
*/
sal_Bool isStreamReadOnly() const;
+ //---------------------------------------
+ /** Returns a value from the sequence contained in the property
+ 'ComponentData' of this media descriptor.
+
+ @descr The property 'ComponentData' should be empty or should
+ contain a value of type ComponentDataSequence (see above).
+
+ @return The value with the specified name, if existing in the
+ sequence of the 'ComponentData' property, otherwise an empty
+ Any.
+ */
+ ::com::sun::star::uno::Any getComponentDataEntry(
+ const ::rtl::OUString& rName ) const;
+
+ //---------------------------------------
+ /** Inserts a value into the sequence contained in the property
+ 'ComponentData' of the media descriptor.
+
+ @descr The property 'ComponentData' should be empty or should
+ contain a value of type ComponentDataSequence (see above). The
+ passed value will be inserted into the sequence, or, if already
+ existing, will be overwritten.
+
+ @param rName The name of the value to be inserted into the
+ sequence of the 'ComponentData' property.
+
+ @param rValue The value to be inserted into the sequence of the
+ 'ComponentData' property.
+ */
+ void setComponentDataEntry(
+ const ::rtl::OUString& rName,
+ const ::com::sun::star::uno::Any& rValue );
+
+ //---------------------------------------
+ /** Removes a value from the sequence contained in the property
+ 'ComponentData' of the media descriptor.
+
+ @descr The property 'ComponentData' should be empty or should
+ contain a value of type ComponentDataSequence (see above). The
+ value with the passed name will be removed from the sequence,
+ if existing.
+
+ @param rName The name of the value to be removed from the sequence
+ of the 'ComponentData' property.
+ */
+ void clearComponentDataEntry(
+ const ::rtl::OUString& rName );
+
//-------------------------------------------
// helper
private:
diff --git a/comphelper/source/misc/docpasswordhelper.cxx b/comphelper/source/misc/docpasswordhelper.cxx
index ea25cb795a53..37941352ae28 100644
--- a/comphelper/source/misc/docpasswordhelper.cxx
+++ b/comphelper/source/misc/docpasswordhelper.cxx
@@ -1,4 +1,4 @@
-/*************************************************************************
+/***********************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -32,7 +32,12 @@
#include <com/sun/star/task/XInteractionHandler.hpp>
#include "comphelper/mediadescriptor.hxx"
+#include <osl/time.h>
+#include <rtl/digest.h>
+#include <rtl/random.h>
+
using ::rtl::OUString;
+using ::com::sun::star::uno::Sequence;
using ::com::sun::star::uno::Exception;
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::UNO_SET_THROW;
@@ -42,15 +47,241 @@ using ::com::sun::star::task::PasswordRequestMode_PASSWORD_REENTER;
using ::com::sun::star::task::XInteractionHandler;
using ::com::sun::star::task::XInteractionRequest;
+using namespace ::com::sun::star;
+
namespace comphelper {
// ============================================================================
+static uno::Sequence< sal_Int8 > GeneratePBKDF2Hash( const ::rtl::OUString& aPassword, const uno::Sequence< sal_Int8 >& aSalt, sal_Int32 nCount, sal_Int32 nHashLength )
+{
+ uno::Sequence< sal_Int8 > aResult;
+
+ if ( aPassword.getLength() && aSalt.getLength() && nCount && nHashLength )
+ {
+ ::rtl::OString aBytePass = ::rtl::OUStringToOString( aPassword, RTL_TEXTENCODING_UTF8 );
+ aResult.realloc( 16 );
+ rtl_digest_PBKDF2( reinterpret_cast < sal_uInt8 * > ( aResult.getArray() ),
+ aResult.getLength(),
+ reinterpret_cast < const sal_uInt8 * > ( aBytePass.getStr() ),
+ aBytePass.getLength(),
+ reinterpret_cast < const sal_uInt8 * > ( aSalt.getConstArray() ),
+ aSalt.getLength(),
+ nCount );
+ }
+
+ return aResult;
+}
+
+// ============================================================================
+
IDocPasswordVerifier::~IDocPasswordVerifier()
{
}
// ============================================================================
+uno::Sequence< beans::PropertyValue > DocPasswordHelper::GenerateNewModifyPasswordInfo( const ::rtl::OUString& aPassword )
+{
+ uno::Sequence< beans::PropertyValue > aResult;
+
+ uno::Sequence< sal_Int8 > aSalt( 16 );
+ sal_Int32 nCount = 1024;
+
+ TimeValue aTime;
+ osl_getSystemTime( &aTime );
+ rtlRandomPool aRandomPool = rtl_random_createPool ();
+ rtl_random_addBytes ( aRandomPool, &aTime, 8 );
+
+ rtl_random_getBytes ( aRandomPool, aSalt.getArray(), 16 );
+
+ uno::Sequence< sal_Int8 > aNewHash = GeneratePBKDF2Hash( aPassword, aSalt, nCount, 16 );
+ if ( aNewHash.getLength() )
+ {
+ aResult.realloc( 4 );
+ aResult[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "algorithm-name" ) );
+ aResult[0].Value <<= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PBKDF2" ) );
+ aResult[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "salt" ) );
+ aResult[1].Value <<= aSalt;
+ aResult[2].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "iteration-count" ) );
+ aResult[2].Value <<= nCount;
+ aResult[3].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "hash" ) );
+ aResult[3].Value <<= aNewHash;
+ }
+
+ // Clean up random pool memory
+ rtl_random_destroyPool ( aRandomPool );
+
+ return aResult;
+}
+
+// ============================================================================
+sal_Bool DocPasswordHelper::IsModifyPasswordCorrect( const ::rtl::OUString& aPassword, const uno::Sequence< beans::PropertyValue >& aInfo )
+{
+ sal_Bool bResult = sal_False;
+ if ( aPassword.getLength() && aInfo.getLength() )
+ {
+ ::rtl::OUString sAlgorithm;
+ uno::Sequence< sal_Int8 > aSalt;
+ uno::Sequence< sal_Int8 > aHash;
+ sal_Int32 nCount = 0;
+
+ for ( sal_Int32 nInd = 0; nInd < aInfo.getLength(); nInd++ )
+ {
+ if ( aInfo[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "algorithm-name" ) ) ) )
+ aInfo[nInd].Value >>= sAlgorithm;
+ else if ( aInfo[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "salt" ) ) ) )
+ aInfo[nInd].Value >>= aSalt;
+ else if ( aInfo[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "iteration-count" ) ) ) )
+ aInfo[nInd].Value >>= nCount;
+ else if ( aInfo[nInd].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "hash" ) ) ) )
+ aInfo[nInd].Value >>= aHash;
+ }
+
+ if ( sAlgorithm.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PBKDF2" ) ) )
+ && aSalt.getLength() && nCount > 0 && aHash.getLength() )
+ {
+ uno::Sequence< sal_Int8 > aNewHash = GeneratePBKDF2Hash( aPassword, aSalt, nCount, aHash.getLength() );
+ for ( sal_Int32 nInd = 0; nInd < aNewHash.getLength() && nInd < aHash.getLength() && aNewHash[nInd] == aHash[nInd]; nInd ++ )
+ {
+ if ( nInd == aNewHash.getLength() - 1 && nInd == aHash.getLength() - 1 )
+ bResult = sal_True;
+ }
+ }
+ }
+
+ return bResult;
+}
+
+// ============================================================================
+sal_uInt32 DocPasswordHelper::GetWordHashAsUINT32(
+ const ::rtl::OUString& aUString )
+{
+ static sal_uInt16 pInitialCode[] = {
+ 0xE1F0, // 1
+ 0x1D0F, // 2
+ 0xCC9C, // 3
+ 0x84C0, // 4
+ 0x110C, // 5
+ 0x0E10, // 6
+ 0xF1CE, // 7
+ 0x313E, // 8
+ 0x1872, // 9
+ 0xE139, // 10
+ 0xD40F, // 11
+ 0x84F9, // 12
+ 0x280C, // 13
+ 0xA96A, // 14
+ 0x4EC3 // 15
+ };
+
+ static sal_uInt16 pEncryptionMatrix[15][7] = {
+ { 0xAEFC, 0x4DD9, 0x9BB2, 0x2745, 0x4E8A, 0x9D14, 0x2A09}, // last-14
+ { 0x7B61, 0xF6C2, 0xFDA5, 0xEB6B, 0xC6F7, 0x9DCF, 0x2BBF}, // last-13
+ { 0x4563, 0x8AC6, 0x05AD, 0x0B5A, 0x16B4, 0x2D68, 0x5AD0}, // last-12
+ { 0x0375, 0x06EA, 0x0DD4, 0x1BA8, 0x3750, 0x6EA0, 0xDD40}, // last-11
+ { 0xD849, 0xA0B3, 0x5147, 0xA28E, 0x553D, 0xAA7A, 0x44D5}, // last-10
+ { 0x6F45, 0xDE8A, 0xAD35, 0x4A4B, 0x9496, 0x390D, 0x721A}, // last-9
+ { 0xEB23, 0xC667, 0x9CEF, 0x29FF, 0x53FE, 0xA7FC, 0x5FD9}, // last-8
+ { 0x47D3, 0x8FA6, 0x8FA6, 0x1EDA, 0x3DB4, 0x7B68, 0xF6D0}, // last-7
+ { 0xB861, 0x60E3, 0xC1C6, 0x93AD, 0x377B, 0x6EF6, 0xDDEC}, // last-6
+ { 0x45A0, 0x8B40, 0x06A1, 0x0D42, 0x1A84, 0x3508, 0x6A10}, // last-5
+ { 0xAA51, 0x4483, 0x8906, 0x022D, 0x045A, 0x08B4, 0x1168}, // last-4
+ { 0x76B4, 0xED68, 0xCAF1, 0x85C3, 0x1BA7, 0x374E, 0x6E9C}, // last-3
+ { 0x3730, 0x6E60, 0xDCC0, 0xA9A1, 0x4363, 0x86C6, 0x1DAD}, // last-2
+ { 0x3331, 0x6662, 0xCCC4, 0x89A9, 0x0373, 0x06E6, 0x0DCC}, // last-1
+ { 0x1021, 0x2042, 0x4084, 0x8108, 0x1231, 0x2462, 0x48C4} // last
+ };
+
+ sal_uInt32 nResult = 0;
+ sal_uInt32 nLen = aUString.getLength();
+
+ if ( nLen )
+ {
+ if ( nLen > 15 )
+ nLen = 15;
+
+ sal_uInt16 nHighResult = pInitialCode[nLen - 1];
+ sal_uInt16 nLowResult = 0;
+
+ const sal_Unicode* pStr = aUString.getStr();
+ for ( sal_uInt32 nInd = 0; nInd < nLen; nInd++ )
+ {
+ // NO Encoding during conversion!
+ // The specification says that the low byte should be used in case it is not NULL
+ char nHighChar = (char)( pStr[nInd] >> 8 );
+ char nLowChar = (char)( pStr[nInd] & 0xFF );
+ char nChar = nLowChar ? nLowChar : nHighChar;
+
+ for ( int nMatrixInd = 0; nMatrixInd < 7; ++nMatrixInd )
+ {
+ if ( ( nChar & ( 1 << nMatrixInd ) ) != 0 )
+ nHighResult = nHighResult ^ pEncryptionMatrix[15 - nLen + nInd][nMatrixInd];
+ }
+
+ nLowResult = ( ( ( nLowResult >> 14 ) & 0x0001 ) | ( ( nLowResult << 1 ) & 0x7FFF ) ) ^ nChar;
+ }
+
+ nLowResult = (sal_uInt16)( ( ( ( nLowResult >> 14 ) & 0x001 ) | ( ( nLowResult << 1 ) & 0x7FF ) ) ^ nLen ^ 0xCE4B );
+
+ nResult = ( nHighResult << 16 ) | nLowResult;
+ }
+
+ return nResult;
+}
+
+// ============================================================================
+Sequence< sal_Int8 > DocPasswordHelper::GetWordHashAsSequence(
+ const ::rtl::OUString& aUString )
+{
+ sal_uInt32 nHash = GetWordHashAsUINT32( aUString );
+ Sequence< sal_Int8 > aResult( 4 );
+ aResult[0] = ( nHash >> 24 );
+ aResult[1] = ( ( nHash >> 16 ) & 0xFF );
+ aResult[2] = ( ( nHash >> 8 ) & 0xFF );
+ aResult[3] = ( nHash & 0xFF );
+
+ return aResult;
+}
+
+// ============================================================================
+sal_uInt16 DocPasswordHelper::GetXLHashAsUINT16(
+ const ::rtl::OUString& aUString,
+ rtl_TextEncoding nEnc )
+{
+ sal_uInt16 nResult = 0;
+
+ ::rtl::OString aString = ::rtl::OUStringToOString( aUString, nEnc );
+
+ if ( aString.getLength() && aString.getLength() <= SAL_MAX_UINT16 )
+ {
+ for ( sal_Int32 nInd = aString.getLength() - 1; nInd >= 0; nInd-- )
+ {
+ nResult = ( ( nResult >> 14 ) & 0x01 ) | ( ( nResult << 1 ) & 0x7FFF );
+ nResult ^= aString.getStr()[nInd];
+ }
+
+ nResult = ( ( nResult >> 14 ) & 0x01 ) | ( ( nResult << 1 ) & 0x7FFF );
+ nResult ^= ( 0x8000 | ( 'N' << 8 ) | 'K' );
+ nResult ^= aString.getLength();
+ }
+
+ return nResult;
+}
+
+// ============================================================================
+Sequence< sal_Int8 > DocPasswordHelper::GetXLHashAsSequence(
+ const ::rtl::OUString& aUString,
+ rtl_TextEncoding nEnc )
+{
+ sal_uInt16 nHash = GetXLHashAsUINT16( aUString, nEnc );
+ Sequence< sal_Int8 > aResult( 2 );
+ aResult[0] = ( nHash >> 8 );
+ aResult[1] = ( nHash & 0xFF );
+
+ return aResult;
+}
+
+// ============================================================================
/*static*/ OUString DocPasswordHelper::requestAndVerifyDocPassword(
IDocPasswordVerifier& rVerifier,
diff --git a/comphelper/source/misc/docpasswordrequest.cxx b/comphelper/source/misc/docpasswordrequest.cxx
index 9377d6c7c473..17cdb0ae2d92 100644
--- a/comphelper/source/misc/docpasswordrequest.cxx
+++ b/comphelper/source/misc/docpasswordrequest.cxx
@@ -29,24 +29,26 @@
#include "precompiled_comphelper.hxx"
#include "comphelper/docpasswordrequest.hxx"
-#include <com/sun/star/task/DocumentMSPasswordRequest.hpp>
-#include <com/sun/star/task/DocumentPasswordRequest.hpp>
+#include <com/sun/star/task/DocumentMSPasswordRequest2.hpp>
+#include <com/sun/star/task/DocumentPasswordRequest2.hpp>
#include <com/sun/star/task/XInteractionAbort.hpp>
-#include <com/sun/star/task/XInteractionPassword.hpp>
+#include <com/sun/star/task/XInteractionPassword2.hpp>
using ::rtl::OUString;
using ::com::sun::star::uno::Any;
+using ::com::sun::star::uno::Type;
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::RuntimeException;
using ::com::sun::star::uno::Sequence;
using ::com::sun::star::uno::XInterface;
using ::com::sun::star::task::InteractionClassification_QUERY;
-using ::com::sun::star::task::DocumentMSPasswordRequest;
-using ::com::sun::star::task::DocumentPasswordRequest;
+using ::com::sun::star::task::DocumentMSPasswordRequest2;
+using ::com::sun::star::task::DocumentPasswordRequest2;
using ::com::sun::star::task::PasswordRequestMode;
using ::com::sun::star::task::XInteractionAbort;
using ::com::sun::star::task::XInteractionContinuation;
-using ::com::sun::star::task::XInteractionPassword;
+using ::com::sun::star::task::XInteractionPassword2;
+using ::com::sun::star::task::XInteractionRequest;
namespace comphelper {
@@ -57,52 +59,64 @@ class AbortContinuation : public ::cppu::WeakImplHelper1< XInteractionAbort >
public:
inline explicit AbortContinuation() : mbSelected( false ) {}
- inline bool isSelected() const { return mbSelected; }
+ inline sal_Bool isSelected() const { return mbSelected; }
inline void reset() { mbSelected = false; }
virtual void SAL_CALL select() throw( RuntimeException ) { mbSelected = true; }
private:
- bool mbSelected;
+ sal_Bool mbSelected;
};
// ============================================================================
-class PasswordContinuation : public ::cppu::WeakImplHelper1< XInteractionPassword >
+class PasswordContinuation : public ::cppu::WeakImplHelper1< XInteractionPassword2 >
{
public:
- inline explicit PasswordContinuation() : mbSelected( false ) {}
+ inline explicit PasswordContinuation() : mbReadOnly( sal_False ), mbSelected( sal_False ) {}
- inline bool isSelected() const { return mbSelected; }
- inline void reset() { mbSelected = false; }
+ inline sal_Bool isSelected() const { return mbSelected; }
+ inline void reset() { mbSelected = sal_False; }
+
+ virtual void SAL_CALL select() throw( RuntimeException ) { mbSelected = sal_True; }
- virtual void SAL_CALL select() throw( RuntimeException ) { mbSelected = true; }
virtual void SAL_CALL setPassword( const OUString& rPass ) throw( RuntimeException ) { maPassword = rPass; }
virtual OUString SAL_CALL getPassword() throw( RuntimeException ) { return maPassword; }
+ virtual void SAL_CALL setPasswordToModify( const OUString& rPass ) throw( RuntimeException ) { maModifyPassword = rPass; }
+ virtual OUString SAL_CALL getPasswordToModify() throw( RuntimeException ) { return maModifyPassword; }
+
+ virtual void SAL_CALL setRecommendReadOnly( sal_Bool bReadOnly ) throw( RuntimeException ) { mbReadOnly = bReadOnly; }
+ virtual sal_Bool SAL_CALL getRecommendReadOnly() throw( RuntimeException ) { return mbReadOnly; }
+
private:
OUString maPassword;
- bool mbSelected;
+ OUString maModifyPassword;
+ sal_Bool mbReadOnly;
+ sal_Bool mbSelected;
};
// ============================================================================
DocPasswordRequest::DocPasswordRequest( DocPasswordRequestType eType,
- PasswordRequestMode eMode, const OUString& rDocumentName )
+ PasswordRequestMode eMode, const OUString& rDocumentName, sal_Bool bPasswordToModify )
+: mpAbort( NULL )
+, mpPassword( NULL )
+, mbPasswordToModify( bPasswordToModify )
{
switch( eType )
{
case DocPasswordRequestType_STANDARD:
{
- DocumentPasswordRequest aRequest( OUString(), Reference< XInterface >(),
- InteractionClassification_QUERY, eMode, rDocumentName );
+ DocumentPasswordRequest2 aRequest( OUString(), Reference< XInterface >(),
+ InteractionClassification_QUERY, eMode, rDocumentName, bPasswordToModify );
maRequest <<= aRequest;
}
break;
case DocPasswordRequestType_MS:
{
- DocumentMSPasswordRequest aRequest( OUString(), Reference< XInterface >(),
- InteractionClassification_QUERY, eMode, rDocumentName );
+ DocumentMSPasswordRequest2 aRequest( OUString(), Reference< XInterface >(),
+ InteractionClassification_QUERY, eMode, rDocumentName, bPasswordToModify );
maRequest <<= aRequest;
}
break;
@@ -119,12 +133,32 @@ DocPasswordRequest::~DocPasswordRequest()
{
}
-bool DocPasswordRequest::isAbort() const
+/*uno::*/Any SAL_CALL DocPasswordRequest::queryInterface( const /*uno::*/Type& rType ) throw (RuntimeException)
+{
+ return ::cppu::queryInterface ( rType,
+ // OWeakObject interfaces
+ dynamic_cast< XInterface* > ( (XInteractionRequest *) this ),
+ static_cast< XWeak* > ( this ),
+ // my own interfaces
+ static_cast< XInteractionRequest* > ( this ) );
+}
+
+void SAL_CALL DocPasswordRequest::acquire( ) throw ()
+{
+ OWeakObject::acquire();
+}
+
+void SAL_CALL DocPasswordRequest::release( ) throw ()
+{
+ OWeakObject::release();
+}
+
+sal_Bool DocPasswordRequest::isAbort() const
{
return mpAbort->isSelected();
}
-bool DocPasswordRequest::isPassword() const
+sal_Bool DocPasswordRequest::isPassword() const
{
return mpPassword->isSelected();
}
@@ -134,6 +168,16 @@ OUString DocPasswordRequest::getPassword() const
return mpPassword->getPassword();
}
+OUString DocPasswordRequest::getPasswordToModify() const
+{
+ return mpPassword->getPasswordToModify();
+}
+
+sal_Bool DocPasswordRequest::getRecommendReadOnly() const
+{
+ return mpPassword->getRecommendReadOnly();
+}
+
Any SAL_CALL DocPasswordRequest::getRequest() throw( RuntimeException )
{
return maRequest;
diff --git a/comphelper/source/misc/mediadescriptor.cxx b/comphelper/source/misc/mediadescriptor.cxx
index 1bc40a454d43..9e02afe8c56c 100644
--- a/comphelper/source/misc/mediadescriptor.cxx
+++ b/comphelper/source/misc/mediadescriptor.cxx
@@ -30,47 +30,21 @@
#include <comphelper/mediadescriptor.hxx>
#include <comphelper/stillreadwriteinteraction.hxx>
-//_______________________________________________
-// includes
-
-#ifndef __COM_SUN_STAR_UCB_XCONTENT_HPP__
#include <com/sun/star/ucb/XContent.hpp>
-#endif
-
-#ifndef __COM_SUN_STAR_UCB_XCOMMANDENVIRONMENT_HPP__
#include <com/sun/star/ucb/XCommandEnvironment.hpp>
-#endif
-
-#ifndef __COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP__
#include <com/sun/star/task/XInteractionHandler.hpp>
-#endif
-
-#ifndef __COM_SUN_STAR_IO_XSTREAM_HPP__
#include <com/sun/star/io/XStream.hpp>
-#endif
#include <com/sun/star/io/XActiveDataSink.hpp>
#include <com/sun/star/io/XSeekable.hpp>
-
-#ifndef __COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP__
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#endif
#include <com/sun/star/lang/IllegalArgumentException.hpp>
-
-#ifndef __COM_SUN_STAR_UTIL_XURLTRANSFORMER_HPP__
#include <com/sun/star/util/XURLTransformer.hpp>
-#endif
-
-#ifndef __COM_SUN_STAR_UCB_COMMANDFAILEDEXCEPTION_HPP__
+#include <com/sun/star/ucb/InteractiveIOException.hpp>
+#include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
#include <com/sun/star/ucb/CommandFailedException.hpp>
-#endif
-
-#ifndef __COM_SUN_STAR_URI_XURIREFERENCEFACTORY_HPP__
+#include <com/sun/star/task/XInteractionAbort.hpp>
#include <com/sun/star/uri/XUriReferenceFactory.hpp>
-#endif
-
-#ifndef __COM_SUN_STAR_URI_XURIREFERENCE_HPP__
#include <com/sun/star/uri/XUriReference.hpp>
-#endif
#include <com/sun/star/ucb/PostCommandArgument2.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
@@ -81,11 +55,7 @@
#include <comphelper/processfactory.hxx>
#include <comphelper/configurationhelper.hxx>
-#if OSL_DEBUG_LEVEL>0
- #ifndef _RTL_USTRBUF_HXX_
- #include <rtl/ustrbuf.hxx>
- #endif
-#endif
+#include <rtl/ustrbuf.hxx>
//_______________________________________________
// namespace
@@ -503,6 +473,61 @@ sal_Bool MediaDescriptor::isStreamReadOnly() const
return bReadOnly;
}
+// ----------------------------------------------------------------------------
+
+css::uno::Any MediaDescriptor::getComponentDataEntry( const ::rtl::OUString& rName ) const
+{
+ SequenceAsHashMap aCompDataMap( getUnpackedValueOrDefault( PROP_COMPONENTDATA(), ComponentDataSequence() ) );
+ SequenceAsHashMap::iterator aIt = aCompDataMap.find( rName );
+ return (aIt == aCompDataMap.end()) ? css::uno::Any() : aIt->second;
+}
+
+void MediaDescriptor::setComponentDataEntry( const ::rtl::OUString& rName, const css::uno::Any& rValue )
+{
+ if( rValue.hasValue() )
+ {
+ // get or craete the 'ComponentData' property entry
+ css::uno::Any& rCompDataAny = operator[]( PROP_COMPONENTDATA() );
+ // check type, insert the value
+ OSL_ENSURE( !rCompDataAny.hasValue() || rCompDataAny.has< ComponentDataSequence >(),
+ "MediaDescriptor::setComponentDataEntry - incompatible 'ComponentData' property in media descriptor" );
+ if( !rCompDataAny.hasValue() || rCompDataAny.has< ComponentDataSequence >() )
+ {
+ // insert or overwrite the passed value
+ SequenceAsHashMap aCompDataMap( rCompDataAny );
+ aCompDataMap[ rName ] = rValue;
+ // write back the sequence (sal_False = use NamedValue instead of PropertyValue)
+ rCompDataAny = aCompDataMap.getAsConstAny( sal_False );
+ }
+ }
+ else
+ {
+ // if an empty Any is passed, clear the entry
+ clearComponentDataEntry( rName );
+ }
+}
+
+void MediaDescriptor::clearComponentDataEntry( const ::rtl::OUString& rName )
+{
+ SequenceAsHashMap::iterator aPropertyIter = find( PROP_COMPONENTDATA() );
+ if( aPropertyIter != end() )
+ {
+ OSL_ENSURE( aPropertyIter->second.has< ComponentDataSequence >(),
+ "MediaDescriptor::clearComponentDataEntry - incompatible 'ComponentData' property in media descriptor" );
+ if( aPropertyIter->second.has< ComponentDataSequence >() )
+ {
+ // remove the value with the passed name
+ SequenceAsHashMap aCompDataMap( aPropertyIter->second );
+ aCompDataMap.erase( rName );
+ // write back the sequence, or remove it completely if it is empty
+ if( aCompDataMap.empty() )
+ erase( aPropertyIter );
+ else
+ aPropertyIter->second = aCompDataMap.getAsConstAny( sal_False );
+ }
+ }
+}
+
/*-----------------------------------------------
10.03.2004 09:02
-----------------------------------------------*/
diff --git a/comphelper/source/misc/officerestartmanager.cxx b/comphelper/source/misc/officerestartmanager.cxx
index 1a98ddfce8da..974b8d65e7ae 100644
--- a/comphelper/source/misc/officerestartmanager.cxx
+++ b/comphelper/source/misc/officerestartmanager.cxx
@@ -87,9 +87,9 @@ void SAL_CALL OOfficeRestartManager::requestRestart( const uno::Reference< task:
// if the restart already running there is no need to trigger it again
if ( m_bRestartRequested )
return;
-
+#ifndef MACOSX
m_bRestartRequested = sal_True;
-
+#endif
// the office is still not initialized, no need to terminate, changing the state is enough
if ( !m_bOfficeInitialized )
return;