summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2015-04-14 13:47:01 +0200
committerNoel Grandin <noelgrandin@gmail.com>2015-04-15 11:36:58 +0000
commitf0461e8360e13137c29dfcc1d20ba93e7bbd3073 (patch)
treef50b6a25aeb7609f7bc11443bdb18bd2c343af66
parentba9acdf799bf556c8a20b1dc27eb116e23d481db (diff)
convert LOCKFILE_ constants to scoped enum and cleanup
Change-Id: I9a2339cc953a718403b3cd0960d5d8d34abae455 Reviewed-on: https://gerrit.libreoffice.org/15304 Tested-by: Noel Grandin <noelgrandin@gmail.com> Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
-rw-r--r--include/sfx2/docfile.hxx3
-rw-r--r--include/svl/documentlockfile.hxx4
-rw-r--r--include/svl/lockfilecommon.hxx20
-rw-r--r--include/svl/sharecontrolfile.hxx20
-rw-r--r--sc/source/ui/docshell/docsh.cxx17
-rw-r--r--sc/source/ui/docshell/docsh4.cxx17
-rw-r--r--sc/source/ui/miscdlgs/sharedocdlg.cxx19
-rw-r--r--sfx2/source/doc/docfile.cxx38
-rw-r--r--svl/source/misc/documentlockfile.cxx28
-rw-r--r--svl/source/misc/lockfilecommon.cxx38
-rw-r--r--svl/source/misc/sharecontrolfile.cxx100
11 files changed, 134 insertions, 170 deletions
diff --git a/include/sfx2/docfile.hxx b/include/sfx2/docfile.hxx
index 2964e1998f77..f6f4fb16669c 100644
--- a/include/sfx2/docfile.hxx
+++ b/include/sfx2/docfile.hxx
@@ -24,6 +24,7 @@
#include <sal/config.h>
#include <sfx2/dllapi.h>
#include <sfx2/signaturestate.hxx>
+#include <svl/lockfilecommon.hxx>
#include <sal/types.h>
#include <com/sun/star/util/RevisionTag.hpp>
#include <com/sun/star/util/DateTime.hpp>
@@ -160,7 +161,7 @@ public:
bool Commit();
bool IsStorage();
- sal_Int8 ShowLockedDocumentDialog( const css::uno::Sequence< OUString >& aData, bool bIsLoading, bool bOwnLock );
+ sal_Int8 ShowLockedDocumentDialog( const LockFileEntry& aData, bool bIsLoading, bool bOwnLock );
void LockOrigFileOnDemand( bool bLoading, bool bNoUI );
void UnlockFile( bool bReleaseLockStream );
diff --git a/include/svl/documentlockfile.hxx b/include/svl/documentlockfile.hxx
index e698a0e28249..944999450281 100644
--- a/include/svl/documentlockfile.hxx
+++ b/include/svl/documentlockfile.hxx
@@ -39,14 +39,14 @@ class SVL_DLLPUBLIC DocumentLockFile : public LockFileCommon
::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > OpenStream();
- void WriteEntryToStream( const ::com::sun::star::uno::Sequence< OUString >& aEntry, ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > xStream );
+ void WriteEntryToStream( const LockFileEntry& aEntry, ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > xStream );
public:
DocumentLockFile( const OUString& aOrigURL );
~DocumentLockFile();
bool CreateOwnLockFile();
- ::com::sun::star::uno::Sequence< OUString > GetLockData();
+ LockFileEntry GetLockData();
bool OverwriteOwnLockFile();
void RemoveFile();
diff --git a/include/svl/lockfilecommon.hxx b/include/svl/lockfilecommon.hxx
index 7f32d8494911..767df068180b 100644
--- a/include/svl/lockfilecommon.hxx
+++ b/include/svl/lockfilecommon.hxx
@@ -30,13 +30,15 @@
#include <osl/mutex.hxx>
#include <tools/urlobj.hxx>
+#include <o3tl/enumarray.hxx>
+#include <vector>
-#define LOCKFILE_OOOUSERNAME_ID 0
-#define LOCKFILE_SYSUSERNAME_ID 1
-#define LOCKFILE_LOCALHOST_ID 2
-#define LOCKFILE_EDITTIME_ID 3
-#define LOCKFILE_USERURL_ID 4
-#define LOCKFILE_ENTRYSIZE 5
+enum class LockFileComponent
+{
+ OOOUSERNAME, SYSUSERNAME, LOCALHOST, EDITTIME, USERURL, LAST=USERURL
+};
+
+typedef o3tl::enumarray<LockFileComponent,OUString> LockFileEntry;
namespace svt {
@@ -53,13 +55,13 @@ public:
LockFileCommon( const OUString& aOrigURL, const OUString& aPrefix );
~LockFileCommon();
- static ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< OUString > > ParseList( const ::com::sun::star::uno::Sequence< sal_Int8 >& aBuffer );
- static ::com::sun::star::uno::Sequence< OUString > ParseEntry( const ::com::sun::star::uno::Sequence< sal_Int8 >& aBuffer, sal_Int32& o_nCurPos );
+ static void ParseList( const ::com::sun::star::uno::Sequence< sal_Int8 >& aBuffer, std::vector< LockFileEntry > &rOutput );
+ static LockFileEntry ParseEntry( const ::com::sun::star::uno::Sequence< sal_Int8 >& aBuffer, sal_Int32& o_nCurPos );
static OUString ParseName( const ::com::sun::star::uno::Sequence< sal_Int8 >& aBuffer, sal_Int32& o_nCurPos );
static OUString EscapeCharacters( const OUString& aSource );
static OUString GetOOOUserName();
static OUString GetCurrentLocalTime();
- static ::com::sun::star::uno::Sequence< OUString > GenerateOwnEntry();
+ static LockFileEntry GenerateOwnEntry();
};
}
diff --git a/include/svl/sharecontrolfile.hxx b/include/svl/sharecontrolfile.hxx
index 04f46d7a6b7c..26ec50702e2a 100644
--- a/include/svl/sharecontrolfile.hxx
+++ b/include/svl/sharecontrolfile.hxx
@@ -29,13 +29,8 @@
#include <com/sun/star/io/XTruncate.hpp>
#include <svl/lockfilecommon.hxx>
-
-#define SHARED_OOOUSERNAME_ID LOCKFILE_OOOUSERNAME_ID
-#define SHARED_SYSUSERNAME_ID LOCKFILE_SYSUSERNAME_ID
-#define SHARED_LOCALHOST_ID LOCKFILE_LOCALHOST_ID
-#define SHARED_EDITTIME_ID LOCKFILE_EDITTIME_ID
-#define SHARED_USERURL_ID LOCKFILE_USERURL_ID
-#define SHARED_ENTRYSIZE LOCKFILE_ENTRYSIZE
+#include <o3tl/enumarray.hxx>
+#include <vector>
namespace svt {
@@ -47,7 +42,7 @@ class SVL_DLLPUBLIC ShareControlFile : public LockFileCommon
::com::sun::star::uno::Reference< ::com::sun::star::io::XSeekable > m_xSeekable;
::com::sun::star::uno::Reference< ::com::sun::star::io::XTruncate > m_xTruncate;
- ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< OUString > > m_aUsersData;
+ std::vector< LockFileEntry > m_aUsersData;
void OpenStream();
void Close();
@@ -62,11 +57,12 @@ public:
ShareControlFile( const OUString& aOrigURL );
~ShareControlFile();
- ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< OUString > > GetUsersData();
- void SetUsersDataAndStore( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< OUString > >& aUserNames );
- ::com::sun::star::uno::Sequence< OUString > InsertOwnEntry();
+ std::vector< LockFileEntry > GetUsersData();
+ void SetUsersDataAndStore( const std::vector< LockFileEntry >& aUserNames );
+ LockFileEntry InsertOwnEntry();
bool HasOwnEntry();
- void RemoveEntry( const ::com::sun::star::uno::Sequence< OUString >& aOptionalSpecification = ::com::sun::star::uno::Sequence< OUString >() );
+ void RemoveEntry( const LockFileEntry& aOptionalSpecification );
+ void RemoveEntry();
void RemoveFile();
};
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 79ce486e6e6c..a422041945e6 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -793,17 +793,14 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
try
{
::svt::DocumentLockFile aLockFile( GetSharedFileURL() );
- uno::Sequence< OUString > aData = aLockFile.GetLockData();
- if ( aData.getLength() > LOCKFILE_SYSUSERNAME_ID )
+ LockFileEntry aData = aLockFile.GetLockData();
+ if ( !aData[LockFileComponent::OOOUSERNAME].isEmpty() )
{
- if ( !aData[LOCKFILE_OOOUSERNAME_ID].isEmpty() )
- {
- aUserName = aData[LOCKFILE_OOOUSERNAME_ID];
- }
- else if ( !aData[LOCKFILE_SYSUSERNAME_ID].isEmpty() )
- {
- aUserName = aData[LOCKFILE_SYSUSERNAME_ID];
- }
+ aUserName = aData[LockFileComponent::OOOUSERNAME];
+ }
+ else if ( !aData[LockFileComponent::SYSUSERNAME].isEmpty() )
+ {
+ aUserName = aData[LockFileComponent::SYSUSERNAME];
}
}
catch ( uno::Exception& )
diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx
index a9dd15cf948b..4a9c0d7e8fb8 100644
--- a/sc/source/ui/docshell/docsh4.cxx
+++ b/sc/source/ui/docshell/docsh4.cxx
@@ -997,17 +997,14 @@ void ScDocShell::Execute( SfxRequest& rReq )
try
{
::svt::DocumentLockFile aLockFile( GetSharedFileURL() );
- uno::Sequence< OUString > aData = aLockFile.GetLockData();
- if ( aData.getLength() > LOCKFILE_SYSUSERNAME_ID )
+ LockFileEntry aData = aLockFile.GetLockData();
+ if ( !aData[LockFileComponent::OOOUSERNAME].isEmpty() )
{
- if ( !aData[LOCKFILE_OOOUSERNAME_ID].isEmpty() )
- {
- aUserName = aData[LOCKFILE_OOOUSERNAME_ID];
- }
- else if ( !aData[LOCKFILE_SYSUSERNAME_ID].isEmpty() )
- {
- aUserName = aData[LOCKFILE_SYSUSERNAME_ID];
- }
+ aUserName = aData[LockFileComponent::OOOUSERNAME];
+ }
+ else if ( !aData[LockFileComponent::SYSUSERNAME].isEmpty() )
+ {
+ aUserName = aData[LockFileComponent::SYSUSERNAME];
}
}
catch ( uno::Exception& )
diff --git a/sc/source/ui/miscdlgs/sharedocdlg.cxx b/sc/source/ui/miscdlgs/sharedocdlg.cxx
index d934ff77ea27..911b74d3d1d8 100644
--- a/sc/source/ui/miscdlgs/sharedocdlg.cxx
+++ b/sc/source/ui/miscdlgs/sharedocdlg.cxx
@@ -135,9 +135,8 @@ void ScShareDocumentDlg::UpdateView()
try
{
::svt::ShareControlFile aControlFile( mpDocShell->GetSharedFileURL() );
- uno::Sequence< uno::Sequence< OUString > > aUsersData = aControlFile.GetUsersData();
- const uno::Sequence< OUString >* pUsersData = aUsersData.getConstArray();
- sal_Int32 nLength = aUsersData.getLength();
+ std::vector<LockFileEntry> aUsersData = aControlFile.GetUsersData();
+ sal_Int32 nLength = aUsersData.size();
if ( nLength > 0 )
{
@@ -145,24 +144,24 @@ void ScShareDocumentDlg::UpdateView()
for ( sal_Int32 i = 0; i < nLength; ++i )
{
- if ( pUsersData[i].getLength() > SHARED_EDITTIME_ID )
+ if ( !aUsersData[i][LockFileComponent::EDITTIME].isEmpty() )
{
OUString aUser;
- if ( !pUsersData[i][SHARED_OOOUSERNAME_ID].isEmpty() )
+ if ( !aUsersData[i][LockFileComponent::OOOUSERNAME].isEmpty() )
{
- aUser = pUsersData[i][SHARED_OOOUSERNAME_ID];
+ aUser = aUsersData[i][LockFileComponent::OOOUSERNAME];
}
- else if ( !pUsersData[i][SHARED_SYSUSERNAME_ID].isEmpty() )
+ else if ( !aUsersData[i][LockFileComponent::SYSUSERNAME].isEmpty() )
{
- aUser = pUsersData[i][SHARED_SYSUSERNAME_ID];
+ aUser = aUsersData[i][LockFileComponent::SYSUSERNAME];
}
else
{
- aUser = OUString(m_aStrUnknownUser) + " " + OUString::number( nUnknownUser++ );
+ aUser = m_aStrUnknownUser + " " + OUString::number( nUnknownUser++ );
}
// parse the edit time string of the format "DD.MM.YYYY hh:mm"
- OUString aDateTimeStr = pUsersData[i][SHARED_EDITTIME_ID];
+ OUString aDateTimeStr = aUsersData[i][LockFileComponent::EDITTIME];
sal_Int32 nIndex = 0;
OUString aDateStr = aDateTimeStr.getToken( 0, ' ', nIndex );
OUString aTimeStr = aDateTimeStr.getToken( 0, ' ', nIndex );
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index cdd18ce638a2..8fff9b0f4001 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -823,7 +823,7 @@ void SfxMedium::SetEncryptionDataToStorage_Impl()
// not for some URL scheme belongs in UCB, not here.
-sal_Int8 SfxMedium::ShowLockedDocumentDialog( const uno::Sequence< OUString >& aData, bool bIsLoading, bool bOwnLock )
+sal_Int8 SfxMedium::ShowLockedDocumentDialog( const LockFileEntry& aData, bool bIsLoading, bool bOwnLock )
{
sal_Int8 nResult = LOCK_UI_NOLOCK;
@@ -838,27 +838,23 @@ sal_Int8 SfxMedium::ShowLockedDocumentDialog( const uno::Sequence< OUString >& a
if ( bOwnLock )
{
- if ( aData.getLength() > LOCKFILE_EDITTIME_ID )
- aInfo = aData[LOCKFILE_EDITTIME_ID];
+ aInfo = aData[LockFileComponent::EDITTIME];
xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny(
document::OwnLockOnDocumentRequest( OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo, !bIsLoading ) ) );
}
else /*logically therefore bIsLoading is set */
{
- if ( aData.getLength() > LOCKFILE_EDITTIME_ID )
- {
- if ( !aData[LOCKFILE_OOOUSERNAME_ID].isEmpty() )
- aInfo = aData[LOCKFILE_OOOUSERNAME_ID];
- else
- aInfo = aData[LOCKFILE_SYSUSERNAME_ID];
+ if ( !aData[LockFileComponent::OOOUSERNAME].isEmpty() )
+ aInfo = aData[LockFileComponent::OOOUSERNAME];
+ else
+ aInfo = aData[LockFileComponent::SYSUSERNAME];
- if ( !aInfo.isEmpty() && !aData[LOCKFILE_EDITTIME_ID].isEmpty() )
- {
- aInfo += " ( " ;
- aInfo += aData[LOCKFILE_EDITTIME_ID];
- aInfo += " )";
- }
+ if ( !aInfo.isEmpty() && !aData[LockFileComponent::EDITTIME].isEmpty() )
+ {
+ aInfo += " ( " ;
+ aInfo += aData[LockFileComponent::EDITTIME];
+ aInfo += " )";
}
xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny(
@@ -1104,7 +1100,7 @@ void SfxMedium::LockOrigFileOnDemand( bool bLoading, bool bNoUI )
if ( !bResult )
{
- uno::Sequence< OUString > aData;
+ LockFileEntry aData;
try
{
// impossibility to get data is no real problem
@@ -1118,14 +1114,12 @@ void SfxMedium::LockOrigFileOnDemand( bool bLoading, bool bNoUI )
if ( !bHandleSysLocked )
{
- uno::Sequence< OUString > aOwnData = svt::LockFileCommon::GenerateOwnEntry();
- bOwnLock = ( aData.getLength() > LOCKFILE_USERURL_ID
- && aOwnData.getLength() > LOCKFILE_USERURL_ID
- && aOwnData[LOCKFILE_SYSUSERNAME_ID].equals( aData[LOCKFILE_SYSUSERNAME_ID] ) );
+ LockFileEntry aOwnData = svt::LockFileCommon::GenerateOwnEntry();
+ bOwnLock = aOwnData[LockFileComponent::SYSUSERNAME].equals( aData[LockFileComponent::SYSUSERNAME] );
if ( bOwnLock
- && aOwnData[LOCKFILE_LOCALHOST_ID].equals( aData[LOCKFILE_LOCALHOST_ID] )
- && aOwnData[LOCKFILE_USERURL_ID].equals( aData[LOCKFILE_USERURL_ID] ) )
+ && aOwnData[LockFileComponent::LOCALHOST].equals( aData[LockFileComponent::LOCALHOST] )
+ && aOwnData[LockFileComponent::USERURL].equals( aData[LockFileComponent::USERURL] ) )
{
// this is own lock from the same installation, it could remain because of crash
bResult = true;
diff --git a/svl/source/misc/documentlockfile.cxx b/svl/source/misc/documentlockfile.cxx
index 71b84f98cbfe..db7b76999c6c 100644
--- a/svl/source/misc/documentlockfile.cxx
+++ b/svl/source/misc/documentlockfile.cxx
@@ -30,6 +30,7 @@
#include <osl/time.h>
#include <osl/security.hxx>
#include <osl/socket.hxx>
+#include <o3tl/enumrange.hxx>
#include <rtl/string.hxx>
#include <rtl/ustring.hxx>
@@ -64,16 +65,16 @@ DocumentLockFile::~DocumentLockFile()
}
-void DocumentLockFile::WriteEntryToStream( const uno::Sequence< OUString >& aEntry, uno::Reference< io::XOutputStream > xOutput )
+void DocumentLockFile::WriteEntryToStream( const LockFileEntry& aEntry, uno::Reference< io::XOutputStream > xOutput )
{
::osl::MutexGuard aGuard( m_aMutex );
OUStringBuffer aBuffer;
- for ( sal_Int32 nEntryInd = 0; nEntryInd < aEntry.getLength(); nEntryInd++ )
+ for ( LockFileComponent lft : o3tl::enumrange<LockFileComponent>() )
{
- aBuffer.append( EscapeCharacters( aEntry[nEntryInd] ) );
- if ( nEntryInd < aEntry.getLength() - 1 )
+ aBuffer.append( EscapeCharacters( aEntry[lft] ) );
+ if ( lft < LockFileComponent::LAST )
aBuffer.append( ',' );
else
aBuffer.append( ';' );
@@ -102,7 +103,7 @@ bool DocumentLockFile::CreateOwnLockFile()
if ( !xInput.is() || !xOutput.is() )
throw uno::RuntimeException();
- uno::Sequence< OUString > aNewEntry = GenerateOwnEntry();
+ LockFileEntry aNewEntry = GenerateOwnEntry();
WriteEntryToStream( aNewEntry, xOutput );
xOutput->closeOutput();
@@ -132,7 +133,7 @@ bool DocumentLockFile::CreateOwnLockFile()
}
-uno::Sequence< OUString > DocumentLockFile::GetLockData()
+LockFileEntry DocumentLockFile::GetLockData()
{
::osl::MutexGuard aGuard( m_aMutex );
@@ -176,7 +177,7 @@ bool DocumentLockFile::OverwriteOwnLockFile()
uno::Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv;
::ucbhelper::Content aTargetContent( m_aURL, xEnv, comphelper::getProcessComponentContext() );
- uno::Sequence< OUString > aNewEntry = GenerateOwnEntry();
+ LockFileEntry aNewEntry = GenerateOwnEntry();
uno::Reference< io::XStream > xStream = aTargetContent.openWriteableStreamNoLock();
uno::Reference< io::XOutputStream > xOutput = xStream->getOutputStream();
@@ -200,15 +201,12 @@ void DocumentLockFile::RemoveFile()
::osl::MutexGuard aGuard( m_aMutex );
// TODO/LATER: the removing is not atomic, is it possible in general to make it atomic?
- uno::Sequence< OUString > aNewEntry = GenerateOwnEntry();
- uno::Sequence< OUString > aFileData = GetLockData();
+ LockFileEntry aNewEntry = GenerateOwnEntry();
+ LockFileEntry aFileData = GetLockData();
- if ( aFileData.getLength() < LOCKFILE_ENTRYSIZE )
- throw io::WrongFormatException();
-
- if ( !aFileData[LOCKFILE_SYSUSERNAME_ID].equals( aNewEntry[LOCKFILE_SYSUSERNAME_ID] )
- || !aFileData[LOCKFILE_LOCALHOST_ID].equals( aNewEntry[LOCKFILE_LOCALHOST_ID] )
- || !aFileData[LOCKFILE_USERURL_ID].equals( aNewEntry[LOCKFILE_USERURL_ID] ) )
+ if ( !aFileData[LockFileComponent::SYSUSERNAME].equals( aNewEntry[LockFileComponent::SYSUSERNAME] )
+ || !aFileData[LockFileComponent::LOCALHOST].equals( aNewEntry[LockFileComponent::LOCALHOST] )
+ || !aFileData[LockFileComponent::USERURL].equals( aNewEntry[LockFileComponent::USERURL] ) )
throw io::IOException(); // not the owner, access denied
uno::Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv;
diff --git a/svl/source/misc/lockfilecommon.cxx b/svl/source/misc/lockfilecommon.cxx
index ea0a5965649f..e19bd44fd710 100644
--- a/svl/source/misc/lockfilecommon.cxx
+++ b/svl/source/misc/lockfilecommon.cxx
@@ -30,6 +30,7 @@
#include <osl/security.hxx>
#include <osl/socket.hxx>
#include <osl/file.hxx>
+#include <o3tl/enumrange.hxx>
#include <rtl/string.hxx>
#include <rtl/ustring.hxx>
@@ -95,35 +96,26 @@ INetURLObject LockFileCommon::ResolveLinks( const INetURLObject& aDocURL )
}
-uno::Sequence< uno::Sequence< OUString > > LockFileCommon::ParseList( const uno::Sequence< sal_Int8 >& aBuffer )
+void LockFileCommon::ParseList( const uno::Sequence< sal_Int8 >& aBuffer, std::vector< LockFileEntry > & aResult )
{
sal_Int32 nCurPos = 0;
- sal_Int32 nCurEntry = 0;
- uno::Sequence< uno::Sequence< OUString > > aResult( 10 );
-
while ( nCurPos < aBuffer.getLength() )
{
- if ( nCurEntry >= aResult.getLength() )
- aResult.realloc( nCurEntry + 10 );
- aResult[nCurEntry] = ParseEntry( aBuffer, nCurPos );
- nCurEntry++;
+ aResult.push_back( ParseEntry( aBuffer, nCurPos ) );
}
-
- aResult.realloc( nCurEntry );
- return aResult;
}
-uno::Sequence< OUString > LockFileCommon::ParseEntry( const uno::Sequence< sal_Int8 >& aBuffer, sal_Int32& io_nCurPos )
+LockFileEntry LockFileCommon::ParseEntry( const uno::Sequence< sal_Int8 >& aBuffer, sal_Int32& io_nCurPos )
{
- uno::Sequence< OUString > aResult( LOCKFILE_ENTRYSIZE );
+ LockFileEntry aResult;
- for ( int nInd = 0; nInd < LOCKFILE_ENTRYSIZE; nInd++ )
+ for ( LockFileComponent nInd : o3tl::enumrange<LockFileComponent>() )
{
aResult[nInd] = ParseName( aBuffer, io_nCurPos );
if ( io_nCurPos >= aBuffer.getLength()
- || ( nInd < LOCKFILE_ENTRYSIZE - 1 && aBuffer[io_nCurPos++] != ',' )
- || ( nInd == LOCKFILE_ENTRYSIZE - 1 && aBuffer[io_nCurPos++] != ';' ) )
+ || ( nInd < LockFileComponent::LAST && aBuffer[io_nCurPos++] != ',' )
+ || ( nInd == LockFileComponent::LAST && aBuffer[io_nCurPos++] != ';' ) )
throw io::WrongFormatException();
}
@@ -220,20 +212,20 @@ OUString LockFileCommon::GetCurrentLocalTime()
}
-uno::Sequence< OUString > LockFileCommon::GenerateOwnEntry()
+LockFileEntry LockFileCommon::GenerateOwnEntry()
{
- uno::Sequence< OUString > aResult( LOCKFILE_ENTRYSIZE );
+ LockFileEntry aResult;
- aResult[LOCKFILE_OOOUSERNAME_ID] = GetOOOUserName();
+ aResult[LockFileComponent::OOOUSERNAME] = GetOOOUserName();
::osl::Security aSecurity;
- aSecurity.getUserName( aResult[LOCKFILE_SYSUSERNAME_ID] );
+ aSecurity.getUserName( aResult[LockFileComponent::SYSUSERNAME] );
- aResult[LOCKFILE_LOCALHOST_ID] = ::osl::SocketAddr::getLocalHostname();
+ aResult[LockFileComponent::LOCALHOST] = ::osl::SocketAddr::getLocalHostname();
- aResult[LOCKFILE_EDITTIME_ID] = GetCurrentLocalTime();
+ aResult[LockFileComponent::EDITTIME] = GetCurrentLocalTime();
- ::utl::Bootstrap::locateUserInstallation( aResult[LOCKFILE_USERURL_ID] );
+ ::utl::Bootstrap::locateUserInstallation( aResult[LockFileComponent::USERURL] );
return aResult;
diff --git a/svl/source/misc/sharecontrolfile.cxx b/svl/source/misc/sharecontrolfile.cxx
index b2b3ded20d55..b866e8475503 100644
--- a/svl/source/misc/sharecontrolfile.cxx
+++ b/svl/source/misc/sharecontrolfile.cxx
@@ -30,6 +30,7 @@
#include <osl/time.h>
#include <osl/security.hxx>
#include <osl/socket.hxx>
+#include <o3tl/enumrange.hxx>
#include <rtl/string.hxx>
#include <rtl/ustring.hxx>
@@ -150,19 +151,19 @@ void ShareControlFile::Close()
m_xOutputStream = uno::Reference< io::XOutputStream >();
m_xSeekable = uno::Reference< io::XSeekable >();
m_xTruncate = uno::Reference< io::XTruncate >();
- m_aUsersData.realloc( 0 );
+ m_aUsersData.clear();
}
}
-uno::Sequence< uno::Sequence< OUString > > ShareControlFile::GetUsersData()
+std::vector< o3tl::enumarray< LockFileComponent, OUString > > ShareControlFile::GetUsersData()
{
::osl::MutexGuard aGuard( m_aMutex );
if ( !IsValid() )
throw io::NotConnectedException();
- if ( !m_aUsersData.getLength() )
+ if ( m_aUsersData.empty() )
{
sal_Int64 nLength = m_xSeekable->getLength();
if ( nLength > SAL_MAX_INT32 )
@@ -185,14 +186,14 @@ uno::Sequence< uno::Sequence< OUString > > ShareControlFile::GetUsersData()
nLength -= nRead;
}
- m_aUsersData = ParseList( aBuffer );
+ ParseList( aBuffer, m_aUsersData );
}
return m_aUsersData;
}
-void ShareControlFile::SetUsersDataAndStore( const uno::Sequence< uno::Sequence< OUString > >& aUsersData )
+void ShareControlFile::SetUsersDataAndStore( const std::vector< LockFileEntry >& aUsersData )
{
::osl::MutexGuard aGuard( m_aMutex );
@@ -206,15 +207,12 @@ void ShareControlFile::SetUsersDataAndStore( const uno::Sequence< uno::Sequence<
m_xSeekable->seek( 0 );
OUStringBuffer aBuffer;
- for ( sal_Int32 nInd = 0; nInd < aUsersData.getLength(); nInd++ )
+ for ( size_t nInd = 0; nInd < aUsersData.size(); nInd++ )
{
- if ( aUsersData[nInd].getLength() != SHARED_ENTRYSIZE )
- throw lang::IllegalArgumentException();
-
- for ( sal_Int32 nEntryInd = 0; nEntryInd < SHARED_ENTRYSIZE; nEntryInd++ )
+ for ( LockFileComponent nEntryInd : o3tl::enumrange<LockFileComponent>() )
{
aBuffer.append( EscapeCharacters( aUsersData[nInd][nEntryInd] ) );
- if ( nEntryInd < SHARED_ENTRYSIZE - 1 )
+ if ( nEntryInd < LockFileComponent::LAST )
aBuffer.append( ',' );
else
aBuffer.append( ';' );
@@ -228,7 +226,7 @@ void ShareControlFile::SetUsersDataAndStore( const uno::Sequence< uno::Sequence<
}
-uno::Sequence< OUString > ShareControlFile::InsertOwnEntry()
+LockFileEntry ShareControlFile::InsertOwnEntry()
{
::osl::MutexGuard aGuard( m_aMutex );
@@ -236,38 +234,34 @@ uno::Sequence< OUString > ShareControlFile::InsertOwnEntry()
throw io::NotConnectedException();
GetUsersData();
- uno::Sequence< ::uno::Sequence< OUString > > aNewData( m_aUsersData.getLength() + 1 );
- uno::Sequence< OUString > aNewEntry = GenerateOwnEntry();
+ std::vector< LockFileEntry > aNewData( m_aUsersData );
+ LockFileEntry aNewEntry = GenerateOwnEntry();
bool bExists = false;
sal_Int32 nNewInd = 0;
- for ( sal_Int32 nInd = 0; nInd < m_aUsersData.getLength(); nInd++ )
+ for ( size_t nInd = 0; nInd < m_aUsersData.size(); nInd++ )
{
- if ( m_aUsersData[nInd].getLength() == SHARED_ENTRYSIZE )
+ if ( m_aUsersData[nInd][LockFileComponent::LOCALHOST] == aNewEntry[LockFileComponent::LOCALHOST]
+ && m_aUsersData[nInd][LockFileComponent::SYSUSERNAME] == aNewEntry[LockFileComponent::SYSUSERNAME]
+ && m_aUsersData[nInd][LockFileComponent::USERURL] == aNewEntry[LockFileComponent::USERURL] )
{
- if ( m_aUsersData[nInd][SHARED_LOCALHOST_ID] == aNewEntry[SHARED_LOCALHOST_ID]
- && m_aUsersData[nInd][SHARED_SYSUSERNAME_ID] == aNewEntry[SHARED_SYSUSERNAME_ID]
- && m_aUsersData[nInd][SHARED_USERURL_ID] == aNewEntry[SHARED_USERURL_ID] )
- {
- if ( !bExists )
- {
- aNewData[nNewInd] = aNewEntry;
- bExists = true;
- }
- }
- else
+ if ( !bExists )
{
- aNewData[nNewInd] = m_aUsersData[nInd];
+ aNewData[nNewInd] = aNewEntry;
+ bExists = true;
}
-
- nNewInd++;
}
+ else
+ {
+ aNewData[nNewInd] = m_aUsersData[nInd];
+ }
+
+ nNewInd++;
}
if ( !bExists )
- aNewData[nNewInd++] = aNewEntry;
+ aNewData.push_back( aNewEntry );
- aNewData.realloc( nNewInd );
SetUsersDataAndStore( aNewData );
return aNewEntry;
@@ -284,14 +278,13 @@ bool ShareControlFile::HasOwnEntry()
}
GetUsersData();
- uno::Sequence< OUString > aEntry = GenerateOwnEntry();
+ LockFileEntry aEntry = GenerateOwnEntry();
- for ( sal_Int32 nInd = 0; nInd < m_aUsersData.getLength(); ++nInd )
+ for ( size_t nInd = 0; nInd < m_aUsersData.size(); ++nInd )
{
- if ( m_aUsersData[nInd].getLength() == SHARED_ENTRYSIZE &&
- m_aUsersData[nInd][SHARED_LOCALHOST_ID] == aEntry[SHARED_LOCALHOST_ID] &&
- m_aUsersData[nInd][SHARED_SYSUSERNAME_ID] == aEntry[SHARED_SYSUSERNAME_ID] &&
- m_aUsersData[nInd][SHARED_USERURL_ID] == aEntry[SHARED_USERURL_ID] )
+ if ( m_aUsersData[nInd][LockFileComponent::LOCALHOST] == aEntry[LockFileComponent::LOCALHOST] &&
+ m_aUsersData[nInd][LockFileComponent::SYSUSERNAME] == aEntry[LockFileComponent::SYSUSERNAME] &&
+ m_aUsersData[nInd][LockFileComponent::USERURL] == aEntry[LockFileComponent::USERURL] )
{
return true;
}
@@ -301,7 +294,12 @@ bool ShareControlFile::HasOwnEntry()
}
-void ShareControlFile::RemoveEntry( const uno::Sequence< OUString >& aArgEntry )
+void ShareControlFile::RemoveEntry()
+{
+ RemoveEntry(GenerateOwnEntry());
+}
+
+void ShareControlFile::RemoveEntry( const LockFileEntry& aEntry )
{
::osl::MutexGuard aGuard( m_aMutex );
@@ -310,31 +308,21 @@ void ShareControlFile::RemoveEntry( const uno::Sequence< OUString >& aArgEntry )
GetUsersData();
- uno::Sequence< OUString > aEntry = aArgEntry;
- if ( aEntry.getLength() != SHARED_ENTRYSIZE )
- aEntry = GenerateOwnEntry();
-
- uno::Sequence< ::uno::Sequence< OUString > > aNewData( m_aUsersData.getLength() + 1 );
+ std::vector< LockFileEntry > aNewData;
- sal_Int32 nNewInd = 0;
- for ( sal_Int32 nInd = 0; nInd < m_aUsersData.getLength(); nInd++ )
+ for ( size_t nInd = 0; nInd < m_aUsersData.size(); nInd++ )
{
- if ( m_aUsersData[nInd].getLength() == SHARED_ENTRYSIZE )
+ if ( m_aUsersData[nInd][LockFileComponent::LOCALHOST] != aEntry[LockFileComponent::LOCALHOST]
+ || m_aUsersData[nInd][LockFileComponent::SYSUSERNAME] != aEntry[LockFileComponent::SYSUSERNAME]
+ || m_aUsersData[nInd][LockFileComponent::USERURL] != aEntry[LockFileComponent::USERURL] )
{
- if ( m_aUsersData[nInd][SHARED_LOCALHOST_ID] != aEntry[SHARED_LOCALHOST_ID]
- || m_aUsersData[nInd][SHARED_SYSUSERNAME_ID] != aEntry[SHARED_SYSUSERNAME_ID]
- || m_aUsersData[nInd][SHARED_USERURL_ID] != aEntry[SHARED_USERURL_ID] )
- {
- aNewData[nNewInd] = m_aUsersData[nInd];
- nNewInd++;
- }
+ aNewData.push_back( m_aUsersData[nInd] );
}
}
- aNewData.realloc( nNewInd );
SetUsersDataAndStore( aNewData );
- if ( !nNewInd )
+ if ( aNewData.empty() )
{
// try to remove the file if it is empty
RemoveFile();