summaryrefslogtreecommitdiff
path: root/svl
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 /svl
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>
Diffstat (limited to 'svl')
-rw-r--r--svl/source/misc/documentlockfile.cxx28
-rw-r--r--svl/source/misc/lockfilecommon.cxx38
-rw-r--r--svl/source/misc/sharecontrolfile.cxx100
3 files changed, 72 insertions, 94 deletions
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();