summaryrefslogtreecommitdiff
path: root/comphelper/source/misc
diff options
context:
space:
mode:
authorMikhail Voytenko <mav@openoffice.org>2010-03-30 16:47:18 +0200
committerMikhail Voytenko <mav@openoffice.org>2010-03-30 16:47:18 +0200
commit07f5876bd07cc60e5c1bf153e5d8617c74306b29 (patch)
treebf96181a6ec0eb0927538c576ee690daeeed7ff4 /comphelper/source/misc
parent1e2362e323f52c3a998a18d735fffeb1bd7ca80a (diff)
tl78: #i110383# support password to modify
Diffstat (limited to 'comphelper/source/misc')
-rw-r--r--comphelper/source/misc/docpasswordhelper.cxx39
-rw-r--r--comphelper/source/misc/docpasswordrequest.cxx65
2 files changed, 83 insertions, 21 deletions
diff --git a/comphelper/source/misc/docpasswordhelper.cxx b/comphelper/source/misc/docpasswordhelper.cxx
index ea25cb795a53..5a5d2110deff 100644
--- a/comphelper/source/misc/docpasswordhelper.cxx
+++ b/comphelper/source/misc/docpasswordhelper.cxx
@@ -33,6 +33,7 @@
#include "comphelper/mediadescriptor.hxx"
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;
@@ -51,6 +52,44 @@ IDocPasswordVerifier::~IDocPasswordVerifier()
}
// ============================================================================
+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..beed6d7342b3 100644
--- a/comphelper/source/misc/docpasswordrequest.cxx
+++ b/comphelper/source/misc/docpasswordrequest.cxx
@@ -29,10 +29,10 @@
#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;
@@ -41,12 +41,12 @@ 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;
namespace comphelper {
@@ -57,52 +57,65 @@ 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() : mbSelected( sal_False ), mbReadOnly( 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( const 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 +132,12 @@ DocPasswordRequest::~DocPasswordRequest()
{
}
-bool DocPasswordRequest::isAbort() const
+sal_Bool DocPasswordRequest::isAbort() const
{
return mpAbort->isSelected();
}
-bool DocPasswordRequest::isPassword() const
+sal_Bool DocPasswordRequest::isPassword() const
{
return mpPassword->isSelected();
}
@@ -134,6 +147,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;