summaryrefslogtreecommitdiff
path: root/svtools
diff options
context:
space:
mode:
authorJens-Heiner Rechtien <hr@openoffice.org>2009-09-18 09:04:40 +0000
committerJens-Heiner Rechtien <hr@openoffice.org>2009-09-18 09:04:40 +0000
commit87f5ad0c1a30ba7853de37e56413e8f1f9669560 (patch)
treec086cc1b81f21b581e76e592b3d6f4aff9915d37 /svtools
parentd6e3a5bb1f118cbce7cc1723c6ed99d285d3c885 (diff)
#i10000#: files added (and removed) missing from integration of CWS kso32fixes2
Diffstat (limited to 'svtools')
-rw-r--r--svtools/inc/svtools/loginerr.hxx156
-rw-r--r--svtools/source/misc1/loginerr.cxx45
-rw-r--r--svtools/source/passwordcontainer/syscreds.cxx298
-rw-r--r--svtools/source/passwordcontainer/syscreds.hxx95
4 files changed, 393 insertions, 201 deletions
diff --git a/svtools/inc/svtools/loginerr.hxx b/svtools/inc/svtools/loginerr.hxx
deleted file mode 100644
index f04e569b41e0..000000000000
--- a/svtools/inc/svtools/loginerr.hxx
+++ /dev/null
@@ -1,156 +0,0 @@
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2008 by Sun Microsystems, Inc.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * $RCSfile: loginerr.hxx,v $
- * $Revision: 1.3 $
- *
- * 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 _LOGINERR_HXX
-#define _LOGINERR_HXX
-
-#include <tools/string.hxx>
-#include <tools/errcode.hxx>
-#include <svtools/hint.hxx>
-
-//=========================================================================
-
-#define LOGINERROR_FLAG_SET_SAVE_PASSWORD 1
-#define LOGINERROR_FLAG_MODIFY_ACCOUNT 2
-#define LOGINERROR_FLAG_MODIFY_USER_NAME 4
-#define LOGINERROR_FLAG_PERSISTENT_PASSWORD 8
-
-class LoginErrorInfo
-{
-private:
- String _aTitle;
- String _aServer;
- String _aAccount;
- String _aUserName;
- String _aPassword;
- String _aPath;
- String _aErrorText;
- BYTE _nFlags;
- USHORT _nRet;
-
-public:
- LoginErrorInfo()
- : _nFlags( LOGINERROR_FLAG_MODIFY_USER_NAME ),
- _nRet( ERRCODE_BUTTON_CANCEL )
- {
- }
-
- const String& GetTitle() const { return _aTitle; }
- const String& GetServer() const { return _aServer; }
- const String& GetAccount() const { return _aAccount; }
- const String& GetUserName() const { return _aUserName; }
- const String& GetPassword() const { return _aPassword; }
- const String& GetPath() const { return _aPath; }
- const String& GetErrorText() const { return _aErrorText; }
- BOOL GetIsPersistentPassword() const
- { return ( _nFlags & LOGINERROR_FLAG_PERSISTENT_PASSWORD ); }
- BOOL GetIsSavePassword() const
- { return ( _nFlags & LOGINERROR_FLAG_SET_SAVE_PASSWORD ); }
- BYTE GetFlags() const { return _nFlags; }
- USHORT GetResult() const { return _nRet; }
-
- void SetTitle( const String& aTitle )
- { _aTitle = aTitle; }
- void SetServer( const String& aServer )
- { _aServer = aServer; }
- void SetAccount( const String& aAccount )
- { _aAccount = aAccount; }
- void SetUserName( const String& aUserName )
- { _aUserName = aUserName; }
- void SetPassword( const String& aPassword )
- { _aPassword = aPassword; }
- void SetPath( const String& aPath )
- { _aPath = aPath; }
- void SetErrorText( const String& aErrorText )
- { _aErrorText = aErrorText; }
- void SetFlags( BYTE nFlags )
- { _nFlags = nFlags; }
- inline void SetSavePassword( BOOL bSet );
- inline void SetPersistentPassword( BOOL bSet );
- inline void SetModifyAccount( BOOL bSet );
- inline void SetModifyUserName( BOOL bSet );
- void SetResult( USHORT nRet )
- { _nRet = nRet; }
-};
-
-inline void LoginErrorInfo::SetSavePassword( BOOL bSet )
-{
- if ( bSet )
- _nFlags |= LOGINERROR_FLAG_SET_SAVE_PASSWORD;
- else
- _nFlags &= ~LOGINERROR_FLAG_SET_SAVE_PASSWORD;
-}
-
-inline void LoginErrorInfo::SetPersistentPassword( BOOL bSet )
-{
- if ( bSet )
- _nFlags |= LOGINERROR_FLAG_PERSISTENT_PASSWORD;
- else
- _nFlags &= ~LOGINERROR_FLAG_PERSISTENT_PASSWORD;
-}
-
-inline void LoginErrorInfo::SetModifyAccount( BOOL bSet )
-{
- if ( bSet )
- _nFlags |= LOGINERROR_FLAG_MODIFY_ACCOUNT;
- else
- _nFlags &= ~LOGINERROR_FLAG_MODIFY_ACCOUNT;
-}
-
-inline void LoginErrorInfo::SetModifyUserName( BOOL bSet )
-{
- if ( bSet )
- _nFlags |= LOGINERROR_FLAG_MODIFY_USER_NAME;
- else
- _nFlags &= ~LOGINERROR_FLAG_MODIFY_USER_NAME;
-}
-
-//=========================================================================
-
-class CntLoginErrorHint : public SfxHint
-{
-private:
- LoginErrorInfo* _pInfo;
-
- CntLoginErrorHint( const CntLoginErrorHint& ); // n.i.
- CntLoginErrorHint& operator=( const CntLoginErrorHint& ); // n.i.
-
-public:
- TYPEINFO();
-
- CntLoginErrorHint( LoginErrorInfo* pInfo )
- : _pInfo( pInfo )
- {
- }
-
- LoginErrorInfo& GetErrorInfo() const { return *_pInfo; }
-};
-
-#endif
diff --git a/svtools/source/misc1/loginerr.cxx b/svtools/source/misc1/loginerr.cxx
deleted file mode 100644
index b9802a8be535..000000000000
--- a/svtools/source/misc1/loginerr.cxx
+++ /dev/null
@@ -1,45 +0,0 @@
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2008 by Sun Microsystems, Inc.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * $RCSfile: loginerr.cxx,v $
- * $Revision: 1.6 $
- *
- * 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_svtools.hxx"
-#ifndef GCC
-#endif
-
-#include <svtools/loginerr.hxx>
-
-//============================================================================
-//
-// CntLoginErrorHint Implementation.
-//
-//============================================================================
-
-TYPEINIT1( CntLoginErrorHint, SfxHint );
-
diff --git a/svtools/source/passwordcontainer/syscreds.cxx b/svtools/source/passwordcontainer/syscreds.cxx
new file mode 100644
index 000000000000..b8c223040e6d
--- /dev/null
+++ b/svtools/source/passwordcontainer/syscreds.cxx
@@ -0,0 +1,298 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: $
+ * $Revision: $
+ *
+ * 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.
+ *
+ ************************************************************************/
+
+#include "syscreds.hxx"
+#include "com/sun/star/beans/PropertyValue.hpp"
+
+using namespace com::sun::star;
+
+SysCredentialsConfigItem::SysCredentialsConfigItem(
+ SysCredentialsConfig * pOwner )
+: utl::ConfigItem( rtl::OUString::createFromAscii( "Office.Common/Passwords" ),
+ CONFIG_MODE_IMMEDIATE_UPDATE ),
+ m_bInited( false ),
+ m_pOwner( pOwner )
+{
+ uno::Sequence< ::rtl::OUString > aNode( 1 );
+ aNode[ 0 ] = rtl::OUString::createFromAscii(
+ "Office.Common/Passwords/AuthenticateUsingSystemCredentials" );
+ EnableNotification( aNode );
+}
+
+//virtual
+void SysCredentialsConfigItem::Notify(
+ const uno::Sequence< rtl::OUString > & /*seqPropertyNames*/ )
+{
+ {
+ ::osl::MutexGuard aGuard( m_aMutex );
+ m_bInited = false;
+ // rebuild m_seqURLs
+ getSystemCredentialsURLs();
+ }
+ m_pOwner->persistentConfigChanged();
+}
+
+uno::Sequence< rtl::OUString >
+SysCredentialsConfigItem::getSystemCredentialsURLs()
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( !m_bInited )
+ {
+ // read config item
+ uno::Sequence< ::rtl::OUString > aPropNames( 1 );
+ aPropNames[ 0 ] = rtl::OUString::createFromAscii(
+ "AuthenticateUsingSystemCredentials" );
+ uno::Sequence< uno::Any > aAnyValues(
+ utl::ConfigItem::GetProperties( aPropNames ) );
+
+ OSL_ENSURE(
+ aAnyValues.getLength() == 1,
+ "SysCredentialsConfigItem::getSystemCredentialsURLs: "
+ "Error reading config item!" );
+
+ uno::Sequence< rtl::OUString > aValues;
+ if ( ( aAnyValues[ 0 ] >>= aValues ) ||
+ ( !aAnyValues[ 0 ].hasValue() ) )
+ {
+ m_seqURLs = aValues;
+ m_bInited = true;
+ }
+ }
+ return m_seqURLs;
+}
+
+void SysCredentialsConfigItem::setSystemCredentialsURLs(
+ const uno::Sequence< rtl::OUString > & seqURLList )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ // write config item.
+ uno::Sequence< rtl::OUString > aPropNames( 1 );
+ uno::Sequence< uno::Any > aPropValues( 1 );
+ aPropNames[ 0 ]
+ = ::rtl::OUString::createFromAscii(
+ "AuthenticateUsingSystemCredentials" );
+ aPropValues[ 0 ] <<= seqURLList;
+
+ utl::ConfigItem::SetModified();
+ utl::ConfigItem::PutProperties( aPropNames, aPropValues );
+
+ m_seqURLs = seqURLList;
+ m_bInited = true;
+}
+
+//============================================================================
+
+namespace
+{
+ // TODO: This code is actually copied from svtools/source/passwordcontainer.cxx
+ bool removeLastSegment( ::rtl::OUString & aURL )
+ {
+ sal_Int32 aInd = aURL.lastIndexOf( sal_Unicode( '/' ) );
+
+ if( aInd > 0 )
+ {
+ sal_Int32 aPrevInd = aURL.lastIndexOf( sal_Unicode( '/' ), aInd );
+ if ( aURL.indexOf( ::rtl::OUString::createFromAscii( "://" ) )
+ != aPrevInd - 2 ||
+ aInd != aURL.getLength() - 1 )
+ {
+ aURL = aURL.copy( 0, aInd );
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ bool findURL( StringSet const & rContainer, rtl::OUString const & aURL, rtl::OUString & aResult )
+ {
+ // TODO: This code is actually copied from svtools/source/passwordcontainer.cxx
+ if( !rContainer.empty() && aURL.getLength() )
+ {
+ ::rtl::OUString aUrl( aURL );
+
+ // each iteration remove last '/...' section from the aUrl
+ // while it's possible, up to the most left '://'
+ do
+ {
+ // first look for <url>/somename and then look for <url>/somename/...
+ StringSet::const_iterator aIter = rContainer.find( aUrl );
+ if( aIter != rContainer.end() )
+ {
+ aResult = *aIter;
+ return true;
+ }
+ else
+ {
+ ::rtl::OUString tmpUrl( aUrl );
+ if ( tmpUrl.getStr()[tmpUrl.getLength() - 1] != (sal_Unicode)'/' )
+ tmpUrl += ::rtl::OUString::createFromAscii( "/" );
+
+ aIter = rContainer.lower_bound( tmpUrl );
+ if( aIter != rContainer.end() && aIter->match( tmpUrl ) )
+ {
+ aResult = *aIter;
+ return true;
+ }
+ }
+ }
+ while( removeLastSegment( aUrl ) && aUrl.getLength() );
+ }
+ aResult = rtl::OUString();
+ return false;
+ }
+
+} // namespace
+
+SysCredentialsConfig::SysCredentialsConfig()
+: m_aConfigItem( this ),
+ m_bCfgInited( false )
+{
+}
+
+void SysCredentialsConfig::initCfg()
+{
+ osl::MutexGuard aGuard( m_aMutex );
+ if ( !m_bCfgInited )
+ {
+ uno::Sequence< rtl::OUString > aURLs(
+ m_aConfigItem.getSystemCredentialsURLs() );
+ for ( sal_Int32 n = 0; n < aURLs.getLength(); ++n )
+ m_aCfgContainer.insert( aURLs[ n ] );
+
+ m_bCfgInited = true;
+ }
+}
+
+void SysCredentialsConfig::writeCfg()
+{
+ osl::MutexGuard aGuard( m_aMutex );
+
+ OSL_ENSURE( m_bCfgInited, "SysCredentialsConfig::writeCfg : not initialized!" );
+
+ uno::Sequence< rtl::OUString > aURLs( m_aCfgContainer.size() );
+ StringSet::const_iterator it = m_aCfgContainer.begin();
+ const StringSet::const_iterator end = m_aCfgContainer.end();
+ sal_Int32 n = 0;
+
+ while ( it != end )
+ {
+ aURLs[ n ] = *it;
+ ++it;
+ ++n;
+ }
+
+ m_aConfigItem.setSystemCredentialsURLs( aURLs );
+}
+
+rtl::OUString SysCredentialsConfig::find( rtl::OUString const & aURL )
+{
+ osl::MutexGuard aGuard( m_aMutex );
+ rtl::OUString aResult;
+ if ( findURL( m_aMemContainer, aURL, aResult ) )
+ return aResult;
+
+ initCfg();
+ if ( findURL( m_aCfgContainer, aURL, aResult ) )
+ return aResult;
+
+ return rtl::OUString();
+}
+
+void SysCredentialsConfig::add( rtl::OUString const & rURL, bool bPersistent )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( bPersistent )
+ {
+ m_aMemContainer.erase( rURL );
+
+ initCfg();
+ m_aCfgContainer.insert( rURL );
+ writeCfg();
+ }
+ else
+ {
+ initCfg();
+ if ( m_aCfgContainer.erase( rURL ) > 0 )
+ writeCfg();
+
+ m_aMemContainer.insert( rURL );
+ }
+}
+
+void SysCredentialsConfig::remove( rtl::OUString const & rURL )
+{
+ m_aMemContainer.erase( rURL );
+
+ initCfg();
+ if ( m_aCfgContainer.erase( rURL ) > 0 )
+ writeCfg();
+}
+
+uno::Sequence< rtl::OUString > SysCredentialsConfig::list( bool bOnlyPersistent )
+{
+ initCfg();
+ sal_Int32 nCount = m_aCfgContainer.size()
+ + ( bOnlyPersistent ? 0 : m_aMemContainer.size() );
+ uno::Sequence< rtl::OUString > aResult( nCount );
+
+ StringSet::const_iterator it = m_aCfgContainer.begin();
+ StringSet::const_iterator end = m_aCfgContainer.end();
+ sal_Int32 n = 0;
+
+ while ( it != end )
+ {
+ aResult[ n ] = *it;
+ ++it;
+ ++n;
+ }
+
+ if ( !bOnlyPersistent )
+ {
+ it = m_aMemContainer.begin();
+ end = m_aMemContainer.end();
+
+ while ( it != end )
+ {
+ aResult[ n ] = *it;
+ ++it;
+ ++n;
+ }
+ }
+ return aResult;
+}
+
+void SysCredentialsConfig::persistentConfigChanged()
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ m_bCfgInited = false; // re-init on demand.
+}
diff --git a/svtools/source/passwordcontainer/syscreds.hxx b/svtools/source/passwordcontainer/syscreds.hxx
new file mode 100644
index 000000000000..b037e17c348e
--- /dev/null
+++ b/svtools/source/passwordcontainer/syscreds.hxx
@@ -0,0 +1,95 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: $
+ * $Revision: $
+ *
+ * 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 INCLUDED_SVTOOLS_SYSCREDS_HXX
+#define INCLUDED_SVTOOLS_SYSCREDS_HXX
+
+#include <set>
+#include <memory>
+#include "osl/mutex.hxx"
+#include "rtl/ustring.hxx"
+#include "com/sun/star/uno/Sequence.hxx"
+#include "unotools/configitem.hxx"
+
+class SysCredentialsConfig;
+
+class SysCredentialsConfigItem : public utl::ConfigItem
+{
+ public:
+ SysCredentialsConfigItem( SysCredentialsConfig * pOwner );
+ //virtual ~SysCredentialsConfigItem();
+
+ virtual void Notify(
+ const com::sun::star::uno::Sequence< rtl::OUString > &
+ seqPropertyNames );
+ //virtual void Commit();
+
+ com::sun::star::uno::Sequence< rtl::OUString >
+ getSystemCredentialsURLs();
+
+ void setSystemCredentialsURLs(
+ const com::sun::star::uno::Sequence< rtl::OUString > &
+ seqURLList );
+
+ //bool isSystemCredentialsURL( const rtl::OUString & rURL ) const;
+
+private:
+ ::osl::Mutex m_aMutex;
+ bool m_bInited;
+ com::sun::star::uno::Sequence< rtl::OUString > m_seqURLs;
+ SysCredentialsConfig * m_pOwner;
+};
+
+typedef std::set< rtl::OUString > StringSet;
+
+class SysCredentialsConfig
+{
+ public:
+ SysCredentialsConfig();
+
+ rtl::OUString find( rtl::OUString const & rURL );
+ void add( rtl::OUString const & rURL, bool bPersistent );
+ void remove( rtl::OUString const & rURL );
+ com::sun::star::uno::Sequence< rtl::OUString > list( bool bOnlyPersistent );
+
+ void persistentConfigChanged();
+
+ private:
+ void initCfg();
+ void writeCfg();
+
+ ::osl::Mutex m_aMutex;
+ StringSet m_aMemContainer;
+ StringSet m_aCfgContainer;
+ SysCredentialsConfigItem m_aConfigItem;
+ bool m_bCfgInited;
+};
+
+#endif // INCLUDED_SVTOOLS_SYSCREDS_HXX