include/osl/profile.h | 151 - include/osl/profile.hxx | 213 -- odk/Package_odk_headers.mk | 2 sal/CppunitTest_sal_osl.mk | 1 sal/Library_sal.mk | 2 sal/inc/pch/precompiled_sal.hxx | 1 sal/osl/all/compat.cxx | 48 sal/osl/unx/profile.cxx | 1874 ----------------------- sal/osl/w32/profile.cxx | 2344 ----------------------------- sal/qa/osl/profile/osl_old_testprofile.cxx | 60 solenv/clang-format/excludelist | 5 11 files changed, 48 insertions(+), 4653 deletions(-)
New commits: commit f268a212e77a99f62147762402d539def0b4a6a8 Author: shlok3640 <[email protected]> AuthorDate: Wed Dec 31 16:55:17 2025 +0000 Commit: Stephan Bergmann <[email protected]> CommitDate: Fri Jan 23 19:36:08 2026 +0100 [API CHANGE] tdf#49602: Remove legacy osl/profile Implementation Change-Id: Ida2f39cd657f846c4b31fa88a46ef3e02baabdf7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196372 Reviewed-by: Stephan Bergmann <[email protected]> Tested-by: Jenkins diff --git a/include/osl/profile.h b/include/osl/profile.h deleted file mode 100644 index 082f0e0a0bc6..000000000000 --- a/include/osl/profile.h +++ /dev/null @@ -1,151 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -/* - * This file is part of LibreOffice published API. - */ - -#ifndef INCLUDED_OSL_PROFILE_H -#define INCLUDED_OSL_PROFILE_H - -#include "sal/config.h" - -#include "rtl/ustring.h" -#include "sal/saldllapi.h" -#include "sal/types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef sal_uInt32 oslProfileOption; - -#define osl_Profile_DEFAULT 0x0000 -#define osl_Profile_SYSTEM 0x0001 /* use system depended functionality */ -#define osl_Profile_READLOCK 0x0002 /* lock file for reading */ -#define osl_Profile_WRITELOCK 0x0004 /* lock file for writing */ -#define osl_Profile_FLUSHWRITE 0x0010 /* writing only with flush */ - - -typedef void* oslProfile; - -/** Deprecated API. - Open or create a configuration profile. - @retval 0 if the profile could not be created, otherwise a handle to the profile. - @deprecated -*/ -SAL_DLLPUBLIC oslProfile SAL_CALL osl_openProfile( - rtl_uString *strProfileName, oslProfileOption Options) SAL_COLD; - -/** Deprecated API. - Close the opened profile an flush all data to the disk. - @param Profile handle to an opened profile. - @deprecated -*/ -SAL_DLLPUBLIC sal_Bool SAL_CALL osl_closeProfile( - oslProfile Profile) SAL_COLD; - -/** Deprecated API. - @deprecated -*/ - -SAL_DLLPUBLIC sal_Bool SAL_CALL osl_flushProfile( - oslProfile Profile) SAL_COLD; -/** Deprecated API. - @deprecated -*/ -SAL_DLLPUBLIC sal_Bool SAL_CALL osl_readProfileString( - oslProfile Profile, - const char* pszSection, const char* pszEntry, - char* pszString, sal_uInt32 MaxLen, - const char* pszDefault) SAL_COLD; -/** Deprecated API. - @deprecated -*/ -SAL_DLLPUBLIC sal_Bool SAL_CALL osl_readProfileBool( - oslProfile Profile, - const char* pszSection, const char* pszEntry, - sal_Bool Default) SAL_COLD; -/** Deprecated API. - @deprecated -*/ -SAL_DLLPUBLIC sal_uInt32 SAL_CALL osl_readProfileIdent( - oslProfile Profile, - const char* pszSection, const char* pszEntry, - sal_uInt32 FirstId, const char* Strings[], - sal_uInt32 Default) SAL_COLD; - -/** Deprecated API. - @deprecated -*/ -SAL_DLLPUBLIC sal_Bool SAL_CALL osl_writeProfileString( - oslProfile Profile, - const char* pszSection, const char* pszEntry, - const char* pszString) SAL_COLD; - -/** Deprecated API. - @deprecated -*/ -SAL_DLLPUBLIC sal_Bool SAL_CALL osl_writeProfileBool( - oslProfile Profile, - const char* pszSection, const char* pszEntry, - sal_Bool Value) SAL_COLD; - -/** Deprecated API. - @deprecated -*/ -SAL_DLLPUBLIC sal_Bool SAL_CALL osl_writeProfileIdent( - oslProfile Profile, - const char* pszSection, const char* pszEntry, - sal_uInt32 FirstId, const char* Strings[], - sal_uInt32 Value) SAL_COLD; - -/** Deprecated API. - Acquire the mutex, block if already acquired by another thread. - @retval False if section or entry could not be found. - @deprecated -*/ -SAL_DLLPUBLIC sal_Bool SAL_CALL osl_removeProfileEntry( - oslProfile Profile, - const char *pszSection, const char *pszEntry) SAL_COLD; - -/** Deprecated API. - Get all entries belonging to the specified section. - @returns Pointer to an array of pointers. - @deprecated -*/ -SAL_DLLPUBLIC sal_uInt32 SAL_CALL osl_getProfileSectionEntries( - oslProfile Profile, const char *pszSection, - char* pszBuffer, sal_uInt32 MaxLen) SAL_COLD; - -/** Deprecated API. - Get all section entries - @retval Pointer to an array of pointers. - @deprecated -*/ -SAL_DLLPUBLIC sal_uInt32 SAL_CALL osl_getProfileSections( - oslProfile Profile, char* pszBuffer, sal_uInt32 MaxLen) SAL_COLD; - -#ifdef __cplusplus -} -#endif - -#endif // INCLUDED_OSL_PROFILE_H - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/osl/profile.hxx b/include/osl/profile.hxx deleted file mode 100644 index e83fef0c665c..000000000000 --- a/include/osl/profile.hxx +++ /dev/null @@ -1,213 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -/* - * This file is part of LibreOffice published API. - */ - -#ifndef INCLUDED_OSL_PROFILE_HXX -#define INCLUDED_OSL_PROFILE_HXX - -#include "osl/profile.h" -#include "rtl/ustring.hxx" - -#include <string.h> -#include <exception> -#include <list> - -namespace osl { - - typedef oslProfileOption ProfileOption; - - const int Profile_DEFAULT = osl_Profile_DEFAULT; - const int Profile_SYSTEM = osl_Profile_SYSTEM; /* use system depended functionality */ - const int Profile_READLOCK = osl_Profile_READLOCK; /* lock file for reading */ - const int Profile_WRITELOCK = osl_Profile_WRITELOCK; /* lock file for writing */ - - /** Deprecated API. - @deprecated - */ - class Profile { - oslProfile profile; - - public: - /** Open or create a configuration profile. - - Sets a handle to the profile, otherwise if the profile could not be opened then throw an exception. - */ - Profile(const rtl::OUString & strProfileName, oslProfileOption Options = Profile_DEFAULT ) - { - profile = osl_openProfile(strProfileName.pData, Options); - if( ! profile ) - throw std::exception(); - } - - - /** Close the opened profile an flush all data to the disk. - */ - ~Profile() - { - osl_closeProfile(profile); - } - - - bool flush() - { - return osl_flushProfile(profile); - } - - rtl::OString readString( const rtl::OString& rSection, const rtl::OString& rEntry, - const rtl::OString& rDefault) - { - char aBuf[1024]; - return osl_readProfileString( profile, - rSection.getStr(), - rEntry.getStr(), - aBuf, - sizeof( aBuf ), - rDefault.getStr() ) ? rtl::OString( aBuf ) : rtl::OString(); - - } - - bool readBool( const rtl::OString& rSection, const rtl::OString& rEntry, bool bDefault ) - { - return osl_readProfileBool( profile, rSection.getStr(), rEntry.getStr(), bDefault ); - } - - sal_uInt32 readIdent(const rtl::OString& rSection, const rtl::OString& rEntry, - sal_uInt32 nFirstId, const std::list< rtl::OString >& rStrings, - sal_uInt32 nDefault) - { - size_t nItems = rStrings.size(); - const char** pStrings = new const char*[ nItems+1 ]; - std::list< rtl::OString >::const_iterator it = rStrings.begin(); - nItems = 0; - while( it != rStrings.end() ) - { - pStrings[ nItems++ ] = it->getStr(); - ++it; - } - pStrings[ nItems ] = NULL; - sal_uInt32 nRet = osl_readProfileIdent(profile, rSection.getStr(), rEntry.getStr(), nFirstId, pStrings, nDefault); - delete[] pStrings; - return nRet; - } - - bool writeString(const rtl::OString& rSection, const rtl::OString& rEntry, - const rtl::OString& rString) - { - return osl_writeProfileString(profile, rSection.getStr(), rEntry.getStr(), rString.getStr()); - } - - bool writeBool(const rtl::OString& rSection, const rtl::OString& rEntry, bool Value) - { - return osl_writeProfileBool(profile, rSection.getStr(), rEntry.getStr(), Value); - } - - bool writeIdent(const rtl::OString& rSection, const rtl::OString& rEntry, - sal_uInt32 nFirstId, const std::list< rtl::OString >& rStrings, - sal_uInt32 nValue) - { - size_t nItems = rStrings.size(); - const char** pStrings = new const char*[ nItems+1 ]; - std::list< rtl::OString >::const_iterator it = rStrings.begin(); - nItems = 0; - while( it != rStrings.end() ) - { - pStrings[ nItems++ ] = it->getStr(); - ++it; - } - pStrings[ nItems ] = NULL; - bool bRet = - osl_writeProfileIdent(profile, rSection.getStr(), rEntry.getStr(), nFirstId, pStrings, nValue ); - delete[] pStrings; - return bRet; - } - - /** Remove an entry from a section. - @param rSection Name of the section. - @param rEntry Name of the entry to remove. - @retval False if section or entry could not be found. - */ - bool removeEntry(const rtl::OString& rSection, const rtl::OString& rEntry) - { - return osl_removeProfileEntry(profile, rSection.getStr(), rEntry.getStr()); - } - - /** Get all entries belonging to the specified section. - @param rSection Name of the section. - @return Pointer to an array of pointers. - */ - std::list< rtl::OString > getSectionEntries(const rtl::OString& rSection ) - { - std::list< rtl::OString > aEntries; - - // count buffer size necessary - size_t n = osl_getProfileSectionEntries( profile, rSection.getStr(), NULL, 0 ); - if( n > 1 ) - { - char* pBuf = new char[ n+1 ]; - osl_getProfileSectionEntries( profile, rSection.getStr(), pBuf, n+1 ); - size_t nLen; - for( n = 0; ; n += nLen+1 ) - { - nLen = strlen( pBuf+n ); - if (!nLen) - break; - aEntries.push_back( rtl::OString( pBuf+n ) ); - } - delete[] pBuf; - } - - return aEntries; - } - - /** Get all section entries - @return Pointer to an array of pointers. - */ - std::list< rtl::OString > getSections() - { - std::list< rtl::OString > aSections; - - // count buffer size necessary - size_t n = osl_getProfileSections( profile, NULL, 0 ); - if( n > 1 ) - { - char* pBuf = new char[ n+1 ]; - osl_getProfileSections( profile, pBuf, n+1 ); - size_t nLen; - for( n = 0; ; n += nLen+1 ) - { - nLen = strlen( pBuf+n ); - if (!nLen) - break; - aSections.push_back( rtl::OString( pBuf+n ) ); - } - delete[] pBuf; - } - - return aSections; - } - }; -} - -#endif // INCLUDED_OSL_PROFILE_HXX - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/Package_odk_headers.mk b/odk/Package_odk_headers.mk index e9af36c0fe25..45d6b0f5baba 100644 --- a/odk/Package_odk_headers.mk +++ b/odk/Package_odk_headers.mk @@ -102,8 +102,6 @@ $(eval $(call gb_Package_add_files_with_dir,odk_headers,$(SDKDIRNAME)/include,\ osl/pipe.hxx \ osl/pipe_decl.hxx \ osl/process.h \ - osl/profile.h \ - osl/profile.hxx \ osl/security.h \ osl/security.hxx \ osl/security_decl.hxx \ diff --git a/sal/CppunitTest_sal_osl.mk b/sal/CppunitTest_sal_osl.mk index aede7abdd6d4..105653c5f3bd 100644 --- a/sal/CppunitTest_sal_osl.mk +++ b/sal/CppunitTest_sal_osl.mk @@ -21,7 +21,6 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sal_osl,\ sal/qa/osl/pipe/osl_Pipe \ sal/qa/osl/process/osl_process \ sal/qa/osl/process/osl_Thread \ - sal/qa/osl/profile/osl_old_testprofile \ sal/qa/osl/setthreadname/test-setthreadname \ sal/qa/osl/socket \ )) diff --git a/sal/Library_sal.mk b/sal/Library_sal.mk index dae08b235a41..eef90ebf497c 100644 --- a/sal/Library_sal.mk +++ b/sal/Library_sal.mk @@ -171,7 +171,6 @@ $(eval $(call gb_Library_add_exception_objects,sal,\ sal/osl/unx/pipe \ sal/osl/unx/process \ sal/osl/unx/process_impl \ - sal/osl/unx/profile \ sal/osl/unx/random \ sal/osl/unx/readwrite_helper \ sal/osl/unx/salinit \ @@ -235,7 +234,6 @@ $(eval $(call gb_Library_add_exception_objects,sal,\ sal/osl/w32/pipe \ sal/osl/w32/process \ sal/osl/w32/procimpl \ - sal/osl/w32/profile \ sal/osl/w32/random \ sal/osl/w32/salinit \ sal/osl/w32/security \ diff --git a/sal/inc/pch/precompiled_sal.hxx b/sal/inc/pch/precompiled_sal.hxx index 006c691a31e6..9aeaf72d3342 100644 --- a/sal/inc/pch/precompiled_sal.hxx +++ b/sal/inc/pch/precompiled_sal.hxx @@ -59,7 +59,6 @@ #include <osl/mutex.hxx> #include <osl/pipe.h> #include <osl/process.h> -#include <osl/profile.hxx> #include <osl/security.hxx> #include <osl/signal.h> #include <osl/socket.h> diff --git a/sal/osl/all/compat.cxx b/sal/osl/all/compat.cxx index 8fafc628b57e..69d1444556d7 100644 --- a/sal/osl/all/compat.cxx +++ b/sal/osl/all/compat.cxx @@ -47,6 +47,10 @@ SAL_DLLPUBLIC void SAL_CALL osl_clearSocketSet(void *) { std::abort(); } +SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL osl_closeProfile(void*) { + std::abort(); +} + SAL_DLLPUBLIC_EXPORT void * SAL_CALL osl_createSemaphore(sal_uInt32) { for (;;) { std::abort(); } // avoid "must return a value" warnings } @@ -69,14 +73,42 @@ SAL_DLLPUBLIC void SAL_CALL osl_destroySocketSet(void *) { std::abort(); } +SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL osl_flushProfile(void*) { + std::abort(); +} + SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL osl_getEthernetAddress(sal_uInt8 *) { for (;;) { std::abort(); } // avoid "must return a value" warnings } +SAL_DLLPUBLIC_EXPORT sal_uInt32 SAL_CALL osl_getProfileSectionEntries(void*, const char*, char*, sal_uInt32) { + std::abort(); +} + +SAL_DLLPUBLIC_EXPORT sal_uInt32 SAL_CALL osl_getProfileSections(void*, char*, sal_uInt32) { + std::abort(); +} + SAL_DLLPUBLIC sal_Bool SAL_CALL osl_isInSocketSet(void *, oslSocket) { for (;;) { std::abort(); } // avoid "must return a value" warnings } +SAL_DLLPUBLIC_EXPORT void* SAL_CALL osl_openProfile(rtl_uString*, sal_uInt32) { + std::abort(); +} + +SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL osl_readProfileBool(void*, const char*, const char*, sal_Bool) { + std::abort(); +} + +SAL_DLLPUBLIC_EXPORT sal_uInt32 SAL_CALL osl_readProfileIdent(void*, const char*, const char*, sal_uInt32, const char**, sal_uInt32) { + std::abort(); +} + +SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL osl_readProfileString(void*, const char*, const char*, char*, sal_uInt32, const char*) { + std::abort(); +} + SAL_DLLPUBLIC_EXPORT oslSocket SAL_CALL osl_receiveResourcePipe(oslPipe) { for (;;) { std::abort(); } // avoid "must return a value" warnings } @@ -85,6 +117,10 @@ SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL osl_releaseSemaphore(void *) { for (;;) { std::abort(); } // avoid "must return a value" warnings } +SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL osl_removeProfileEntry(void*, const char*, const char*) { + std::abort(); +} + SAL_DLLPUBLIC_EXPORT sal_Int32 SAL_CALL osl_reportError( sal_uInt32, char const *) { @@ -125,6 +161,18 @@ SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL osl_tryToAcquireSemaphore(void *) { for (;;) { std::abort(); } // avoid "must return a value" warnings } +SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL osl_writeProfileBool(void*, const char*, const char*, sal_Bool) { + std::abort(); +} + +SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL osl_writeProfileIdent(void*, const char*, const char*, sal_uInt32, const char**, sal_uInt32) { + std::abort(); +} + +SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL osl_writeProfileString(void*, const char*, const char*, const char*) { + std::abort(); +} + SAL_DLLPUBLIC_EXPORT sal_Int32 SAL_CALL rtl_addUnloadingListener( void (SAL_CALL *)(void *), void *) { diff --git a/sal/osl/unx/profile.cxx b/sal/osl/unx/profile.cxx deleted file mode 100644 index d8953648b2dc..000000000000 --- a/sal/osl/unx/profile.cxx +++ /dev/null @@ -1,1874 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include "system.hxx" -#include "readwrite_helper.hxx" -#include "file_url.hxx" -#include "file_impl.hxx" -#include "unixerrnostring.hxx" - -#include <osl/diagnose.h> -#include <osl/profile.h> -#include <sal/log.hxx> - -#include <fcntl.h> -#include <limits.h> -#include <string.h> -#include <sys/stat.h> -#include <unistd.h> - -#define LINES_INI 32 -#define LINES_ADD 10 -#define SECTIONS_INI 5 -#define SECTIONS_ADD 3 -#define ENTRIES_INI 5 -#define ENTRIES_ADD 3 - -#define STR_INI_BOOLYES "yes" -#define STR_INI_BOOLON "on" -#define STR_INI_BOOLONE "1" -#define STR_INI_BOOLNO "no" -#define STR_INI_BOOLOFF "off" -#define STR_INI_BOOLZERO "0" - -#define FLG_USER 0x00FF -#define FLG_AUTOOPEN 0x0100 -#define FLG_MODIFIED 0x0200 - -#define DEFAULT_PMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) - -typedef time_t osl_TStamp; - -namespace { - -enum osl_TLockMode -{ - un_lock, read_lock, write_lock -}; - -struct osl_TFile -{ - int m_Handle; - char* m_pReadPtr; - char m_ReadBuf[512]; - char* m_pWriteBuf; - sal_uInt32 m_nWriteBufLen; - sal_uInt32 m_nWriteBufFree; -}; - -struct osl_TProfileEntry -{ - sal_uInt32 m_Line; - sal_uInt32 m_Offset; - sal_uInt32 m_Len; -}; - -struct osl_TProfileSection -{ - sal_uInt32 m_Line; - sal_uInt32 m_Offset; - sal_uInt32 m_Len; - sal_uInt32 m_NoEntries; - sal_uInt32 m_MaxEntries; - osl_TProfileEntry* m_Entries; -}; - -/* Profile-data structure hidden behind oslProfile: */ -struct osl_TProfileImpl -{ - sal_uInt32 m_Flags; - osl_TFile* m_pFile; - osl_TStamp m_Stamp; - char m_FileName[PATH_MAX + 1]; - sal_uInt32 m_NoLines; - sal_uInt32 m_MaxLines; - sal_uInt32 m_NoSections; - sal_uInt32 m_MaxSections; - char** m_Lines; - osl_TProfileSection* m_Sections; - pthread_mutex_t m_AccessLock; - bool m_bIsValid; -}; - -} - -static osl_TFile* openFileImpl(const char* pszFilename, oslProfileOption ProfileFlags); -static osl_TStamp closeFileImpl(osl_TFile* pFile, oslProfileOption Flags); -static bool OslProfile_lockFile(const osl_TFile* pFile, osl_TLockMode eMode); -static bool OslProfile_rewindFile(osl_TFile* pFile, bool bTruncate); -static osl_TStamp OslProfile_getFileStamp(osl_TFile* pFile); - -static char* OslProfile_getLine(osl_TFile* pFile); -static bool OslProfile_putLine(osl_TFile* pFile, const char *pszLine); -static char* stripBlanks(char* String, sal_uInt32* pLen); -static char* addLine(osl_TProfileImpl* pProfile, const char* Line); -static char* insertLine(osl_TProfileImpl* pProfile, const char* Line, sal_uInt32 LineNo); -static void removeLine(osl_TProfileImpl* pProfile, sal_uInt32 LineNo); -static void setEntry(osl_TProfileImpl* pProfile, osl_TProfileSection* pSection, - sal_uInt32 NoEntry, sal_uInt32 Line, - char* Entry, sal_uInt32 Len); -static bool addEntry(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection, - int Line, char* Entry, sal_uInt32 Len); -static void removeEntry(osl_TProfileSection *pSection, sal_uInt32 NoEntry); -static bool addSection(osl_TProfileImpl* pProfile, int Line, const char* Section, sal_uInt32 Len); -static void removeSection(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection); -static osl_TProfileSection* findEntry(osl_TProfileImpl* pProfile, const char* Section, - const char* Entry, sal_uInt32 *pNoEntry); -static bool loadProfile(osl_TFile* pFile, osl_TProfileImpl* pProfile); -static bool storeProfile(osl_TProfileImpl* pProfile, bool bCleanup); -static osl_TProfileImpl* acquireProfile(oslProfile Profile, bool bWriteable); -static bool releaseProfile(osl_TProfileImpl* pProfile); - -static bool writeProfileImpl (osl_TFile* pFile); -static osl_TFile* osl_openTmpProfileImpl(osl_TProfileImpl*); -static bool osl_ProfileSwapProfileNames(osl_TProfileImpl*); -static void osl_ProfileGenerateExtension(const char* pszFileName, const char* pszExtension, char* pszTmpName, int BufferMaxLen); -static oslProfile osl_psz_openProfile(const char *pszProfileName, oslProfileOption Flags); - -oslProfile SAL_CALL osl_openProfile(rtl_uString *ustrProfileName, oslProfileOption Options) -{ - char profilePath[PATH_MAX] = ""; - return - (ustrProfileName == nullptr - || ustrProfileName->buffer[0] == 0 - || (FileURLToPath(profilePath, PATH_MAX, ustrProfileName) - == osl_File_E_None)) - ? osl_psz_openProfile(profilePath, Options) - : nullptr; -} - -static oslProfile osl_psz_openProfile(const char *pszProfileName, oslProfileOption Flags) -{ - osl_TFile* pFile; - osl_TProfileImpl* pProfile; - bool bRet = false; - - if ( ( pFile = openFileImpl(pszProfileName, Flags ) ) == nullptr ) - { - return nullptr; - } - - pProfile = static_cast<osl_TProfileImpl*>(calloc(1, sizeof(osl_TProfileImpl))); - - if ( pProfile == nullptr ) - { - closeFileImpl(pFile, Flags); - return nullptr; - } - - pProfile->m_Flags = Flags & FLG_USER; - - if ( Flags & ( osl_Profile_READLOCK | osl_Profile_WRITELOCK | osl_Profile_FLUSHWRITE ) ) - { - pProfile->m_pFile = pFile; - } - - pthread_mutex_init(&(pProfile->m_AccessLock),PTHREAD_MUTEXATTR_DEFAULT); - pProfile->m_bIsValid = true; - - pProfile->m_Stamp = OslProfile_getFileStamp(pFile); - bRet=loadProfile(pFile, pProfile); - bRet &= realpath(pszProfileName, pProfile->m_FileName) != nullptr; - SAL_WARN_IF(!bRet, "sal.osl", "realpath(pszProfileName, pProfile->m_FileName) != NULL ==> false"); - - if (pProfile->m_pFile == nullptr) - closeFileImpl(pFile,pProfile->m_Flags); - - return pProfile; -} - -sal_Bool SAL_CALL osl_closeProfile(oslProfile Profile) -{ - osl_TProfileImpl* pProfile = static_cast<osl_TProfileImpl*>(Profile); - osl_TProfileImpl* pTmpProfile; - - if ( Profile == nullptr ) - { - return false; - } - - pthread_mutex_lock(&(pProfile->m_AccessLock)); - - if ( !pProfile->m_bIsValid ) - { - SAL_WARN("sal.osl", "!pProfile->m_bIsValid"); - pthread_mutex_unlock(&(pProfile->m_AccessLock)); - - return false; - } - - pProfile->m_bIsValid = false; - - if ( ! ( pProfile->m_Flags & osl_Profile_READLOCK ) && ( pProfile->m_Flags & FLG_MODIFIED ) ) - { - pTmpProfile = acquireProfile(Profile, true); - - if ( pTmpProfile != nullptr ) - { - bool bRet = storeProfile(pTmpProfile, true); - SAL_WARN_IF(!bRet, "sal.osl", "storeProfile(pTmpProfile, true) ==> false"); - } - } - else - { - pTmpProfile = acquireProfile(Profile, false); - } - - if ( pTmpProfile == nullptr ) - { - pthread_mutex_unlock(&(pProfile->m_AccessLock)); - - SAL_INFO("sal.osl", "Out osl_closeProfile [pProfile==0]"); - return false; - } - - pProfile = pTmpProfile; - - if (pProfile->m_pFile != nullptr) - closeFileImpl(pProfile->m_pFile,pProfile->m_Flags); - - pProfile->m_pFile = nullptr; - pProfile->m_FileName[0] = ' - - /* release whole profile data types memory */ - if ( pProfile->m_NoLines > 0) - { - unsigned int idx=0; - if ( pProfile->m_Lines != nullptr ) - { - for ( idx = 0 ; idx < pProfile->m_NoLines ; ++idx) - { - if ( pProfile->m_Lines[idx] != nullptr ) - { - free(pProfile->m_Lines[idx]); - pProfile->m_Lines[idx]=nullptr; - } - } - free(pProfile->m_Lines); - pProfile->m_Lines=nullptr; - } - if ( pProfile->m_Sections != nullptr ) - { - /*osl_TProfileSection* pSections=pProfile->m_Sections;*/ - for ( idx = 0 ; idx < pProfile->m_NoSections ; ++idx ) - { - if ( pProfile->m_Sections[idx].m_Entries != nullptr ) - { - free(pProfile->m_Sections[idx].m_Entries); - pProfile->m_Sections[idx].m_Entries=nullptr; - } - } - free(pProfile->m_Sections); - pProfile->m_Sections=nullptr; - } - } - - pthread_mutex_unlock(&(pProfile->m_AccessLock)); - - pthread_mutex_destroy(&(pProfile->m_AccessLock)); - - free(pProfile); - - return true; -} - -sal_Bool SAL_CALL osl_flushProfile(oslProfile Profile) -{ - osl_TProfileImpl* pProfile = static_cast<osl_TProfileImpl*>(Profile); - osl_TFile* pFile; - bool bRet = false; - - if ( pProfile == nullptr ) - { - return false; - } - - pthread_mutex_lock(&(pProfile->m_AccessLock)); - - if ( !pProfile->m_bIsValid ) - { - SAL_WARN_IF(!pProfile->m_bIsValid, "sal.osl", "!pProfile->m_bIsValid"); - pthread_mutex_unlock(&(pProfile->m_AccessLock)); - return false; - } - - pFile = pProfile->m_pFile; - if ( pFile == nullptr || pFile->m_Handle < 0 ) - { - pthread_mutex_unlock(&(pProfile->m_AccessLock)); - - return false; - } - - if ( pProfile->m_Flags & FLG_MODIFIED ) - { - bRet = storeProfile(pProfile, false); - SAL_WARN_IF(!bRet, "sal.osl", "storeProfile(pProfile, false) ==> false"); - } - - pthread_mutex_unlock(&(pProfile->m_AccessLock)); - return bRet; -} - -static bool writeProfileImpl(osl_TFile* pFile) -{ - if ( pFile == nullptr || pFile->m_Handle < 0 || pFile->m_pWriteBuf == nullptr ) - { - return false; - } - - SAL_WARN_IF( - (strlen(pFile->m_pWriteBuf) - != pFile->m_nWriteBufLen - pFile->m_nWriteBufFree), - "sal.osl", - strlen(pFile->m_pWriteBuf) << " != " - << (pFile->m_nWriteBufLen - pFile->m_nWriteBufFree)); - - if ( !safeWrite(pFile->m_Handle, pFile->m_pWriteBuf, pFile->m_nWriteBufLen - pFile->m_nWriteBufFree) ) - { - SAL_INFO("sal.osl", "write failed: " << UnixErrnoString(errno)); - return false; - } - - free(pFile->m_pWriteBuf); - pFile->m_pWriteBuf=nullptr; - pFile->m_nWriteBufLen=0; - pFile->m_nWriteBufFree=0; - - return true; -} - -sal_Bool SAL_CALL osl_readProfileString(oslProfile Profile, - const char* pszSection, - const char* pszEntry, - char* pszString, - sal_uInt32 MaxLen, - const char* pszDefault) -{ - sal_uInt32 NoEntry; - char* pStr=nullptr; - osl_TProfileImpl* pProfile=nullptr; - osl_TProfileImpl* pTmpProfile=nullptr; - bool bRet = false; - - pTmpProfile = static_cast<osl_TProfileImpl*>(Profile); - - if ( pTmpProfile == nullptr ) - { - return false; - } - - pthread_mutex_lock(&(pTmpProfile->m_AccessLock)); - - if ( !pTmpProfile->m_bIsValid ) - { - pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); - - return false; - } - - pProfile = acquireProfile(Profile, false); - - if ( pProfile == nullptr ) - { - pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); - - return false; - } - - if (! (pProfile->m_Flags & osl_Profile_SYSTEM)) - { - osl_TProfileSection* pSec = findEntry(pProfile, pszSection, pszEntry, &NoEntry); - if ((pSec != nullptr) && - (NoEntry < pSec->m_NoEntries) && - ((pStr = strchr(pProfile->m_Lines[pSec->m_Entries[NoEntry].m_Line], - '=')) != nullptr)) - { - pStr++; - } - else - { - pStr=const_cast<char*>(pszDefault); - } - - if ( pStr != nullptr ) - { - pStr = stripBlanks(pStr, nullptr); - MaxLen = (MaxLen - 1 < strlen(pStr)) ? (MaxLen - 1) : strlen(pStr); - pStr = stripBlanks(pStr, &MaxLen); - strncpy(pszString, pStr, MaxLen); - pszString[MaxLen] = ' - } - } - else - { /* not implemented */ } - - bRet=releaseProfile(pProfile); - SAL_WARN_IF(!bRet, "sal.osl", "releaseProfile(pProfile) ==> false"); - - if ( pStr == nullptr ) - { - pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); - - return false; - } - - pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); - - return true; -} - -sal_Bool SAL_CALL osl_readProfileBool(oslProfile Profile, - const char* pszSection, - const char* pszEntry, - sal_Bool Default) -{ - char Line[32]; - Line[0] = ' - - if (osl_readProfileString(Profile, pszSection, pszEntry, Line, sizeof(Line), "")) - { - if ((strcasecmp(Line, STR_INI_BOOLYES) == 0) || - (strcasecmp(Line, STR_INI_BOOLON) == 0) || - (strcasecmp(Line, STR_INI_BOOLONE) == 0)) - Default = true; - else - if ((strcasecmp(Line, STR_INI_BOOLNO) == 0) || - (strcasecmp(Line, STR_INI_BOOLOFF) == 0) || - (strcasecmp(Line, STR_INI_BOOLZERO) == 0)) - Default = false; - } - - return Default; -} - -sal_uInt32 SAL_CALL osl_readProfileIdent(oslProfile Profile, - const char* pszSection, - const char* pszEntry, - sal_uInt32 FirstId, - const char* Strings[], - sal_uInt32 Default) -{ - sal_uInt32 i; - char Line[256]; - Line[0] = ' - - if (osl_readProfileString(Profile, pszSection, pszEntry, Line, sizeof(Line), "")) - { - i = 0; - while (Strings[i] != nullptr) - { - if (strcasecmp(Line, Strings[i]) == 0) - { - Default = i + FirstId; - break; - } - i++; - } - } - - return Default; -} - -sal_Bool SAL_CALL osl_writeProfileString(oslProfile Profile, - const char* pszSection, - const char* pszEntry, - const char* pszString) -{ - bool bRet = false; - sal_uInt32 NoEntry; - char* pStr; - char* Line = nullptr; - osl_TProfileImpl* pProfile = nullptr; - osl_TProfileImpl* pTmpProfile = static_cast<osl_TProfileImpl*>(Profile); - - if ( pTmpProfile == nullptr ) - { - return false; - } - - pthread_mutex_lock(&(pTmpProfile->m_AccessLock)); - - if ( !pTmpProfile->m_bIsValid ) - { - SAL_WARN_IF(!pTmpProfile->m_bIsValid, "sal.osl", "!pTmpProfile->m_bIsValid"); - pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); - - return false; - } - - pProfile=acquireProfile(Profile, true); - - if (pProfile == nullptr) - { - pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); - - return false; - } - - Line = static_cast<char*>(malloc(strlen(pszEntry)+strlen(pszString)+48)); - - if (! (pProfile->m_Flags & osl_Profile_SYSTEM)) - { - osl_TProfileSection* pSec; - if ((pSec = findEntry(pProfile, pszSection, pszEntry, &NoEntry)) == nullptr) - { - Line[0] = ' - addLine(pProfile, Line); - - Line[0] = '['; - strcpy(&Line[1], pszSection); - Line[1 + strlen(pszSection)] = ']'; - Line[2 + strlen(pszSection)] = ' - - pStr = addLine(pProfile, Line); - if ((pStr == nullptr) || - (! addSection(pProfile, pProfile->m_NoLines - 1, &pStr[1], strlen(pszSection)))) - { - bRet=releaseProfile(pProfile); - SAL_WARN_IF(!bRet, "sal.osl", "releaseProfile(pProfile) ==> false"); - - pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); - - free(Line); - return false; - } - - pSec = &pProfile->m_Sections[pProfile->m_NoSections - 1]; - NoEntry = pSec->m_NoEntries; - } - - Line[0] = ' - strcpy(&Line[0], pszEntry); - Line[0 + strlen(pszEntry)] = '='; - strcpy(&Line[1 + strlen(pszEntry)], pszString); - - if (NoEntry >= pSec->m_NoEntries) - { - sal_uInt32 i; - if (pSec->m_NoEntries > 0) - i = pSec->m_Entries[pSec->m_NoEntries - 1].m_Line + 1; - else - i = pSec->m_Line + 1; - - pStr = insertLine(pProfile, Line, i); - if ((pStr == nullptr) || - (! addEntry(pProfile, pSec, i, pStr, strlen(pszEntry)))) - { - bRet=releaseProfile(pProfile); - SAL_WARN_IF(!bRet, "sal.osl", "releaseProfile(pProfile) ==> false"); - - pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); - free(Line); - - return false; - } - - pProfile->m_Flags |= FLG_MODIFIED; - } - else - { - sal_uInt32 i = pSec->m_Entries[NoEntry].m_Line; - free(pProfile->m_Lines[i]); - pProfile->m_Lines[i] = strdup(Line); - setEntry(pProfile, pSec, NoEntry, i, pProfile->m_Lines[i], strlen(pszEntry)); - - pProfile->m_Flags |= FLG_MODIFIED; - } - } - else { - /* not implemented */ - } - - bRet = releaseProfile(pProfile); - SAL_WARN_IF(!bRet, "sal.osl", "releaseProfile(pProfile) ==> false"); - - pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); - if ( Line!= nullptr ) - { - free(Line); - } - - return bRet; -} - -sal_Bool SAL_CALL osl_writeProfileBool(oslProfile Profile, - const char* pszSection, - const char* pszEntry, - sal_Bool Value) -{ - bool bRet = false; - - if (Value) - bRet=osl_writeProfileString(Profile, pszSection, pszEntry, STR_INI_BOOLONE); - else - bRet=osl_writeProfileString(Profile, pszSection, pszEntry, STR_INI_BOOLZERO); - - return bRet; -} - -sal_Bool SAL_CALL osl_writeProfileIdent(oslProfile Profile, - const char* pszSection, - const char* pszEntry, - sal_uInt32 FirstId, - const char* Strings[], - sal_uInt32 Value) -{ - int i, n = 0; - bool bRet = false; - - while (Strings[n] != nullptr) - ++n; - - if ((i = Value - FirstId) >= n) - bRet = false; - else - bRet = osl_writeProfileString(Profile, pszSection, pszEntry, Strings[i]); - - return bRet; -} - -sal_Bool SAL_CALL osl_removeProfileEntry(oslProfile Profile, - const char *pszSection, - const char *pszEntry) -{ - sal_uInt32 NoEntry; - osl_TProfileImpl* pProfile = nullptr; - osl_TProfileImpl* pTmpProfile = nullptr; - bool bRet = false; - - pTmpProfile = static_cast<osl_TProfileImpl*>(Profile); - - if ( pTmpProfile == nullptr ) - { - return false; - } - - pthread_mutex_lock(&(pTmpProfile->m_AccessLock)); - - if ( !pTmpProfile->m_bIsValid ) - { - SAL_WARN_IF(!pTmpProfile->m_bIsValid, "sal.osl", "!pTmpProfile->m_bIsValid"); - pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); - return false; - } - - pProfile = acquireProfile(Profile, true); - - if (pProfile == nullptr) - { - pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); - - return false; - } - - if (! (pProfile->m_Flags & osl_Profile_SYSTEM)) - { - osl_TProfileSection* pSec = findEntry(pProfile, pszSection, pszEntry, &NoEntry); - if ((pSec != nullptr) && - (NoEntry < pSec->m_NoEntries)) - { - removeLine(pProfile, pSec->m_Entries[NoEntry].m_Line); - removeEntry(pSec, NoEntry); - if (pSec->m_NoEntries == 0) - { - removeLine(pProfile, pSec->m_Line); - - /* remove any empty separation line */ - if ((pSec->m_Line > 0) && (pProfile->m_Lines[pSec->m_Line - 1][0] == ' - removeLine(pProfile, pSec->m_Line - 1); - - removeSection(pProfile, pSec); - } - - pProfile->m_Flags |= FLG_MODIFIED; - } - } - else - { /* not implemented */ } - - bRet = releaseProfile(pProfile); - SAL_WARN_IF(!bRet, "sal.osl", "releaseProfile(pProfile) ==> false"); - - pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); - - return bRet; -} - -sal_uInt32 SAL_CALL osl_getProfileSectionEntries(oslProfile Profile, - const char *pszSection, - char* pszBuffer, - sal_uInt32 MaxLen) -{ - sal_uInt32 i, n = 0; - sal_uInt32 NoEntry; - osl_TProfileImpl* pProfile = nullptr; - osl_TProfileImpl* pTmpProfile = nullptr; - bool bRet = false; - - pTmpProfile = static_cast<osl_TProfileImpl*>(Profile); - - if ( pTmpProfile == nullptr ) - { - return 0; - - } - - pthread_mutex_lock(&(pTmpProfile->m_AccessLock)); - - if ( !pTmpProfile->m_bIsValid ) - { - SAL_WARN_IF(!pTmpProfile->m_bIsValid, "sal.osl", "!pTmpProfile->m_bIsValid"); - - pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); - - return 0; - } - - pProfile = acquireProfile(Profile, false); - - if (pProfile == nullptr) - { - pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); - - return 0; - } - - if (! (pProfile->m_Flags & osl_Profile_SYSTEM)) - { - osl_TProfileSection* pSec; - if ((pSec = findEntry(pProfile, pszSection, "", &NoEntry)) != nullptr) - { - if (MaxLen != 0) - { - for (i = 0; i < pSec->m_NoEntries; i++) - { - if ((n + pSec->m_Entries[i].m_Len + 1) < MaxLen) - { - strncpy(&pszBuffer[n], &pProfile->m_Lines[pSec->m_Entries[i].m_Line] - [pSec->m_Entries[i].m_Offset], pSec->m_Entries[i].m_Len); - n += pSec->m_Entries[i].m_Len; - pszBuffer[n++] = ' - } - else - break; - - } - - pszBuffer[n++] = ' - } - else - { - for (i = 0; i < pSec->m_NoEntries; i++) - n += pSec->m_Entries[i].m_Len + 1; - - n += 1; - } - } - else - n = 0; - } - else { - /* not implemented */ - } - - bRet=releaseProfile(pProfile); - SAL_WARN_IF(!bRet, "sal.osl", "releaseProfile(pProfile) ==> false"); - - pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); - - return n; -} - -sal_uInt32 SAL_CALL osl_getProfileSections(oslProfile Profile, - char* pszBuffer, - sal_uInt32 MaxLen) -{ - sal_uInt32 i, n = 0; - osl_TProfileImpl* pProfile = nullptr; - osl_TProfileImpl* pTmpProfile = nullptr; - bool bRet = false; - - pTmpProfile = static_cast<osl_TProfileImpl*>(Profile); - - if ( pTmpProfile == nullptr ) - { - return 0; - } - - pthread_mutex_lock(&(pTmpProfile->m_AccessLock)); - - if ( !pTmpProfile->m_bIsValid ) - { - SAL_WARN_IF(!pTmpProfile->m_bIsValid, "sal.osl", "!pTmpProfile->m_bIsValid"); - pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); - - return 0; - } - - pProfile = acquireProfile(Profile, false); - - if (pProfile == nullptr) - { - pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); - - return 0; - } - - if (! (pProfile->m_Flags & osl_Profile_SYSTEM)) - { - if (MaxLen != 0) - { - for (i = 0; i < pProfile->m_NoSections; i++) - { - osl_TProfileSection* pSec = &pProfile->m_Sections[i]; - - if ((n + pSec->m_Len + 1) < MaxLen) - { - strncpy(&pszBuffer[n], &pProfile->m_Lines[pSec->m_Line][pSec->m_Offset], - pSec->m_Len); - n += pSec->m_Len; - pszBuffer[n++] = ' - } - else - break; - } - - pszBuffer[n++] = ' - } - else - { - for (i = 0; i < pProfile->m_NoSections; i++) - n += pProfile->m_Sections[i].m_Len + 1; - - n += 1; - } - } - else - { /* not implemented */ } - - bRet=releaseProfile(pProfile); - SAL_WARN_IF(!bRet, "sal.osl", "releaseProfile(pProfile) ==> false"); - - pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); - - return n; -} - -static osl_TStamp OslProfile_getFileStamp(osl_TFile* pFile) -{ - struct stat status; - - if ( (pFile->m_Handle < 0) || (fstat(pFile->m_Handle, &status) < 0) ) - { - return 0; - } - - return status.st_mtime; -} - -static bool OslProfile_lockFile(const osl_TFile* pFile, osl_TLockMode eMode) -{ - struct flock lock; - static bool const bLockingDisabled = getenv( "STAR_PROFILE_LOCKING_DISABLED" ) != nullptr; - - if (pFile->m_Handle < 0) - { - return false; - } - - if ( bLockingDisabled ) - { - return true; - } - - lock.l_start = 0; - lock.l_whence = SEEK_SET; - lock.l_len = 0; - - switch (eMode) - { - case un_lock: - lock.l_type = F_UNLCK; - break; - - case read_lock: - lock.l_type = F_RDLCK; - break; - - case write_lock: - lock.l_type = F_WRLCK; - break; - } - -#ifndef MACOSX - if ( fcntl(pFile->m_Handle, F_SETLKW, &lock) == -1 ) -#else - /* Mac OSX will return ENOTSUP for webdav drives so we should ignore it */ - if ( fcntl(pFile->m_Handle, F_SETLKW, &lock) == -1 && errno != ENOTSUP ) -#endif - { - SAL_INFO("sal.osl", "fcntl failed: " << UnixErrnoString(errno)); - return false; - } - - return true; -} - -static osl_TFile* openFileImpl(const char* pszFilename, oslProfileOption ProfileFlags ) -{ - int Flags; - bool bWriteable = false; - - if ( isForbidden( pszFilename, osl_File_OpenFlag_Write ) ) - return nullptr; - - osl_TFile* pFile = static_cast<osl_TFile*>(calloc(1, sizeof(osl_TFile))); - - if ( ProfileFlags & ( osl_Profile_WRITELOCK | osl_Profile_FLUSHWRITE ) ) - { - bWriteable = true; - } - - if (! bWriteable) - { - pFile->m_Handle = open(pszFilename, O_RDONLY); - - if (pFile->m_Handle == -1) - { - int e = errno; - SAL_INFO("sal.file", "open(" << pszFilename << ",O_RDONLY): " << UnixErrnoString(e)); - } - else - SAL_INFO("sal.file", "open(" << pszFilename << ",O_RDONLY) => " << pFile->m_Handle); - - /* mfe: argghh!!! do not check if the file could be opened */ - /* default mode expects it that way!!! */ - } - else - { - if (((pFile->m_Handle = open(pszFilename, O_RDWR | O_CREAT | O_EXCL, DEFAULT_PMODE)) < 0) && - ((pFile->m_Handle = open(pszFilename, O_RDWR)) < 0)) - { - int e = errno; - SAL_INFO("sal.file", "open(" << pszFilename << ",...): " << UnixErrnoString(e)); - free(pFile); - return nullptr; - } - else - SAL_INFO("sal.file", "open(" << pszFilename << ",...) => " << pFile->m_Handle); - } - - /* set close-on-exec flag */ - if ((Flags = fcntl(pFile->m_Handle, F_GETFD, 0)) != -1) - { - Flags |= FD_CLOEXEC; - int e = fcntl(pFile->m_Handle, F_SETFD, Flags); - SAL_INFO_IF( - e != 0, "sal.osl", - "fcntl to set FD_CLOEXEC failed for " << pszFilename); - } - - pFile->m_pWriteBuf=nullptr; - pFile->m_nWriteBufFree=0; - pFile->m_nWriteBufLen=0; - - if ( ProfileFlags & (osl_Profile_WRITELOCK | osl_Profile_READLOCK ) ) - { - OslProfile_lockFile(pFile, bWriteable ? write_lock : read_lock); - } - - return pFile; -} - -static osl_TStamp closeFileImpl(osl_TFile* pFile, oslProfileOption Flags) -{ - osl_TStamp stamp = 0; - - if ( pFile == nullptr ) - { - return stamp; - } - - if ( pFile->m_Handle >= 0 ) - { - stamp = OslProfile_getFileStamp(pFile); - - if ( Flags & (osl_Profile_WRITELOCK | osl_Profile_READLOCK ) ) - { - OslProfile_lockFile(pFile, un_lock); - } - - close(pFile->m_Handle); - SAL_INFO("sal.file", "close(" << pFile->m_Handle << ")"); - pFile->m_Handle = -1; - } - - if ( pFile->m_pWriteBuf ) - { - free(pFile->m_pWriteBuf); - } - - free(pFile); - - return stamp; -} - -static bool OslProfile_rewindFile(osl_TFile* pFile, bool bTruncate) -{ - bool bRet = true; - - if (pFile->m_Handle >= 0) - { - pFile->m_pReadPtr = pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf); - - bRet = (lseek(pFile->m_Handle, SEEK_SET, 0) == 0); - - if (bTruncate) - { - bRet &= (ftruncate(pFile->m_Handle, 0) == 0); - } - - } - - return bRet; -} - -static char* OslProfile_getLine(osl_TFile* pFile) -{ - ssize_t Max, nLineBytes = 0; - char* pChr; - char* pLine = nullptr; - char* pNewLine; - - if ( pFile == nullptr ) - { - return nullptr; - } - - if (pFile->m_Handle < 0) - return nullptr; - - do - { - ssize_t Bytes = sizeof(pFile->m_ReadBuf) - (pFile->m_pReadPtr - pFile->m_ReadBuf); - - if (Bytes <= 1) - { - /* refill buffer */ - memcpy(pFile->m_ReadBuf, pFile->m_pReadPtr, Bytes); - pFile->m_pReadPtr = pFile->m_ReadBuf; - - ssize_t Free = sizeof(pFile->m_ReadBuf) - Bytes; - - Max = read(pFile->m_Handle, &pFile->m_ReadBuf[Bytes], Free); - if (Max < 0) - { - SAL_INFO("sal.osl", "read failed: " << UnixErrnoString(errno)); - - if( pLine ) - free( pLine ); - pLine = nullptr; - break; - } - - if (Max < Free) - { - if ((Max == 0) && ! pLine) - break; - - pFile->m_ReadBuf[Bytes + Max] = ' - } - } - - for (pChr = pFile->m_pReadPtr; - (*pChr != ' ') && (*pChr != ' ') && (*pChr != ' - (pChr < (pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf) - 1)); - pChr++); - - Max = pChr - pFile->m_pReadPtr; - pNewLine = static_cast<char*>(malloc( nLineBytes + Max + 1 )); - if( pLine ) - { - memcpy( pNewLine, pLine, nLineBytes ); - free( pLine ); - } - memcpy(pNewLine+nLineBytes, pFile->m_pReadPtr, Max); - nLineBytes += Max; - pNewLine[ nLineBytes ] = 0; - pLine = pNewLine; - - if (pChr < (pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf) - 1)) - { - if (*pChr != ' - { - if ((pChr[0] == ' ') && (pChr[1] == ' ')) - pChr += 2; - else - pChr += 1; - } - - if ((pChr < (pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf))) && - (*pChr == ' - pChr = pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf); - - /* setting Max to -1 indicates terminating read loop */ - Max = -1; - } - - pFile->m_pReadPtr = pChr; - } - while (Max > 0) ; - - return pLine; -} - -static bool OslProfile_putLine(osl_TFile* pFile, const char *pszLine) -{ - unsigned int Len = strlen(pszLine); - - if ( pFile == nullptr || pFile->m_Handle < 0 ) - { - return false; - } - - if ( pFile->m_pWriteBuf == nullptr ) - { - pFile->m_pWriteBuf = static_cast<char*>(malloc(Len+3)); - pFile->m_nWriteBufLen = Len+3; - pFile->m_nWriteBufFree = Len+3; - } - else - { - if ( pFile->m_nWriteBufFree <= Len + 3 ) - { - char* pTmp; - - pTmp=static_cast<char*>(realloc(pFile->m_pWriteBuf,( ( pFile->m_nWriteBufLen + Len ) * 2) )); - if ( pTmp == nullptr ) - { - return false; - } - pFile->m_pWriteBuf = pTmp; - pFile->m_nWriteBufFree = pFile->m_nWriteBufFree + pFile->m_nWriteBufLen + ( 2 * Len ); - pFile->m_nWriteBufLen = ( pFile->m_nWriteBufLen + Len ) * 2; - memset( (pFile->m_pWriteBuf) + ( pFile->m_nWriteBufLen - pFile->m_nWriteBufFree ), 0, pFile->m_nWriteBufFree); - } - } - - memcpy(pFile->m_pWriteBuf + ( pFile->m_nWriteBufLen - pFile->m_nWriteBufFree ),pszLine,Len+1); - pFile->m_pWriteBuf[pFile->m_nWriteBufLen - pFile->m_nWriteBufFree + Len]=' '; - pFile->m_pWriteBuf[pFile->m_nWriteBufLen - pFile->m_nWriteBufFree + Len + 1]=' - - pFile->m_nWriteBufFree-=Len+1; - - return true; -} - -static char* stripBlanks(char* String, sal_uInt32* pLen) -{ - if ( ( pLen != nullptr ) && ( *pLen != 0 ) ) - { - while ((String[*pLen - 1] == ' ') || (String[*pLen - 1] == ' ')) - (*pLen)--; - - while ( (*String == ' ') || (*String == ' ') ) - { - String++; - (*pLen)--; - } - } - else - while ( (*String == ' ') || (*String == ' ') ) - String++; - - return String; -} - -static char* addLine(osl_TProfileImpl* pProfile, const char* Line) -{ - if (pProfile->m_NoLines >= pProfile->m_MaxLines) - { - if (pProfile->m_Lines == nullptr) - { - pProfile->m_MaxLines = LINES_INI; - pProfile->m_Lines = static_cast<char **>(calloc(pProfile->m_MaxLines, sizeof(char *))); - } - else - { - unsigned int idx=0; - unsigned int oldmax=pProfile->m_MaxLines; - - pProfile->m_MaxLines += LINES_ADD; - pProfile->m_Lines = static_cast<char **>(realloc(pProfile->m_Lines, - pProfile->m_MaxLines * sizeof(char *))); - for ( idx = oldmax ; idx < pProfile->m_MaxLines ; ++idx ) - { - pProfile->m_Lines[idx]=nullptr; - } - } - } - if (pProfile->m_Lines == nullptr) - { - pProfile->m_NoLines = 0; - pProfile->m_MaxLines = 0; - return nullptr; - } - - if ( pProfile->m_Lines[pProfile->m_NoLines] != nullptr ) - { - free(pProfile->m_Lines[pProfile->m_NoLines]); - } - pProfile->m_Lines[pProfile->m_NoLines++] = strdup(Line); - - return pProfile->m_Lines[pProfile->m_NoLines - 1]; -} - -static char* insertLine(osl_TProfileImpl* pProfile, const char* Line, sal_uInt32 LineNo) -{ - if (pProfile->m_NoLines >= pProfile->m_MaxLines) - { - if (pProfile->m_Lines == nullptr) - { - pProfile->m_MaxLines = LINES_INI; - pProfile->m_Lines = static_cast<char **>(calloc(pProfile->m_MaxLines, sizeof(char *))); - } - else - { - pProfile->m_MaxLines += LINES_ADD; - pProfile->m_Lines = static_cast<char **>(realloc(pProfile->m_Lines, - pProfile->m_MaxLines * sizeof(char *))); - - memset(&pProfile->m_Lines[pProfile->m_NoLines], - 0, - (pProfile->m_MaxLines - pProfile->m_NoLines - 1) * sizeof(char*)); - } - - if (pProfile->m_Lines == nullptr) - { - pProfile->m_NoLines = 0; - pProfile->m_MaxLines = 0; - return nullptr; - } - } - - LineNo = std::min(LineNo, pProfile->m_NoLines); - - if (LineNo < pProfile->m_NoLines) - { - sal_uInt32 i, n; - - memmove(&pProfile->m_Lines[LineNo + 1], &pProfile->m_Lines[LineNo], - (pProfile->m_NoLines - LineNo) * sizeof(char *)); - - /* adjust line references */ - for (i = 0; i < pProfile->m_NoSections; i++) - { - osl_TProfileSection* pSec = &pProfile->m_Sections[i]; - - if (pSec->m_Line >= LineNo) - pSec->m_Line++; - - for (n = 0; n < pSec->m_NoEntries; n++) - if (pSec->m_Entries[n].m_Line >= LineNo) - pSec->m_Entries[n].m_Line++; - } - } - - pProfile->m_NoLines++; - - pProfile->m_Lines[LineNo] = strdup(Line); - - return pProfile->m_Lines[LineNo]; -} - -static void removeLine(osl_TProfileImpl* pProfile, sal_uInt32 LineNo) -{ - if (LineNo >= pProfile->m_NoLines) - return; - - free(pProfile->m_Lines[LineNo]); - pProfile->m_Lines[LineNo]=nullptr; - if (pProfile->m_NoLines - LineNo > 1) - { - sal_uInt32 i, n; - - memmove(&pProfile->m_Lines[LineNo], &pProfile->m_Lines[LineNo + 1], - (pProfile->m_NoLines - LineNo - 1) * sizeof(char *)); - - memset(&pProfile->m_Lines[pProfile->m_NoLines - 1], - 0, - (pProfile->m_MaxLines - pProfile->m_NoLines) * sizeof(char*)); - - /* adjust line references */ - for (i = 0; i < pProfile->m_NoSections; i++) - { - osl_TProfileSection* pSec = &pProfile->m_Sections[i]; - - if (pSec->m_Line > LineNo) - pSec->m_Line--; - - for (n = 0; n < pSec->m_NoEntries; n++) - if (pSec->m_Entries[n].m_Line > LineNo) - pSec->m_Entries[n].m_Line--; - } - } - else - { - pProfile->m_Lines[LineNo] = nullptr; - } - - pProfile->m_NoLines--; -} - -static void setEntry(osl_TProfileImpl* pProfile, osl_TProfileSection* pSection, - sal_uInt32 NoEntry, sal_uInt32 Line, - char* Entry, sal_uInt32 Len) -{ - Entry = stripBlanks(Entry, &Len); - pSection->m_Entries[NoEntry].m_Line = Line; - pSection->m_Entries[NoEntry].m_Offset = Entry - pProfile->m_Lines[Line]; - pSection->m_Entries[NoEntry].m_Len = Len; -} - -static bool addEntry(osl_TProfileImpl* pProfile, - osl_TProfileSection *pSection, - int Line, char* Entry, - sal_uInt32 Len) -{ - if (pSection != nullptr) - { - if (pSection->m_NoEntries >= pSection->m_MaxEntries) - { - if (pSection->m_Entries == nullptr) - { - pSection->m_MaxEntries = ENTRIES_INI; - pSection->m_Entries = static_cast<osl_TProfileEntry *>(malloc( - pSection->m_MaxEntries * sizeof(osl_TProfileEntry))); - } - else - { - pSection->m_MaxEntries += ENTRIES_ADD; - pSection->m_Entries = static_cast<osl_TProfileEntry *>(realloc(pSection->m_Entries, - pSection->m_MaxEntries * sizeof(osl_TProfileEntry))); - } - - if (pSection->m_Entries == nullptr) - { - pSection->m_NoEntries = 0; - pSection->m_MaxEntries = 0; - return false; - } - } - - pSection->m_NoEntries++; - - Entry = stripBlanks(Entry, &Len); - setEntry(pProfile, pSection, pSection->m_NoEntries - 1, Line, - Entry, Len); - - return true; - } - - return false; -} - -static void removeEntry(osl_TProfileSection *pSection, sal_uInt32 NoEntry) -{ - if (NoEntry >= pSection->m_NoEntries) - return; - - if (pSection->m_NoEntries - NoEntry > 1) - { - memmove(&pSection->m_Entries[NoEntry], - &pSection->m_Entries[NoEntry + 1], - (pSection->m_NoEntries - NoEntry - 1) * sizeof(osl_TProfileEntry)); - pSection->m_Entries[pSection->m_NoEntries - 1].m_Line=0; - pSection->m_Entries[pSection->m_NoEntries - 1].m_Offset=0; - pSection->m_Entries[pSection->m_NoEntries - 1].m_Len=0; - } - - pSection->m_NoEntries--; - -} - -static bool addSection(osl_TProfileImpl* pProfile, int Line, const char* Section, sal_uInt32 Len) -{ - if (pProfile->m_NoSections >= pProfile->m_MaxSections) - { - if (pProfile->m_Sections == nullptr) - { - pProfile->m_MaxSections = SECTIONS_INI; - pProfile->m_Sections = static_cast<osl_TProfileSection *>(calloc(pProfile->m_MaxSections, sizeof(osl_TProfileSection))); - } - else - { - unsigned int idx=0; - unsigned int oldmax=pProfile->m_MaxSections; - - pProfile->m_MaxSections += SECTIONS_ADD; - pProfile->m_Sections = static_cast<osl_TProfileSection *>(realloc(pProfile->m_Sections, - pProfile->m_MaxSections * sizeof(osl_TProfileSection))); - for ( idx = oldmax ; idx < pProfile->m_MaxSections ; ++idx ) - { - pProfile->m_Sections[idx].m_Entries=nullptr; - } - } - - if (pProfile->m_Sections == nullptr) - { - pProfile->m_NoSections = 0; - pProfile->m_MaxSections = 0; - return false; - } - } - - pProfile->m_NoSections++; - - if ( pProfile->m_Sections[(pProfile->m_NoSections) - 1].m_Entries != nullptr ) - { - free(pProfile->m_Sections[(pProfile->m_NoSections) - 1].m_Entries); - } - pProfile->m_Sections[pProfile->m_NoSections - 1].m_Entries = nullptr; - pProfile->m_Sections[pProfile->m_NoSections - 1].m_NoEntries = 0; - pProfile->m_Sections[pProfile->m_NoSections - 1].m_MaxEntries = 0; - - pProfile->m_Sections[pProfile->m_NoSections - 1].m_Line = Line; - pProfile->m_Sections[pProfile->m_NoSections - 1].m_Offset = Section - pProfile->m_Lines[Line]; - pProfile->m_Sections[pProfile->m_NoSections - 1].m_Len = Len; - - return true; -} - -static void removeSection(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection) -{ - sal_uInt32 Section; - - if ((Section = pSection - pProfile->m_Sections) >= pProfile->m_NoSections) - return; - - free (pSection->m_Entries); - pSection->m_Entries=nullptr; - if (pProfile->m_NoSections - Section > 1) - { - memmove(&pProfile->m_Sections[Section], &pProfile->m_Sections[Section + 1], - (pProfile->m_NoSections - Section - 1) * sizeof(osl_TProfileSection)); - - memset(&pProfile->m_Sections[pProfile->m_NoSections - 1], - 0, - (pProfile->m_MaxSections - pProfile->m_NoSections) * sizeof(osl_TProfileSection)); - pProfile->m_Sections[pProfile->m_NoSections - 1].m_Entries = nullptr; - } - else - { - pSection->m_Entries = nullptr; - } - - pProfile->m_NoSections--; -} - -static osl_TProfileSection* findEntry(osl_TProfileImpl* pProfile, - const char* Section, - const char* Entry, - sal_uInt32 *pNoEntry) -{ - static sal_uInt32 Sect = 0; - sal_uInt32 i, n; - sal_uInt32 Len; - osl_TProfileSection* pSec=nullptr; - - Len = strlen(Section); - - n = Sect; - - for (i = 0; i < pProfile->m_NoSections; i++) - { - n %= pProfile->m_NoSections; - pSec = &pProfile->m_Sections[n]; - if ((Len == pSec->m_Len) && - (strncasecmp(Section, &pProfile->m_Lines[pSec->m_Line][pSec->m_Offset], pSec->m_Len) - == 0)) - break; - n++; - } - - Sect = n; - - if (i < pProfile->m_NoSections) - { - Len = strlen(Entry); - - *pNoEntry = pSec->m_NoEntries; - - for (i = 0; i < pSec->m_NoEntries; i++) - { - const char* pStr = &pProfile->m_Lines[pSec->m_Entries[i].m_Line] - [pSec->m_Entries[i].m_Offset]; - if ((Len == pSec->m_Entries[i].m_Len) && - (strncasecmp(Entry, pStr, pSec->m_Entries[i].m_Len) - == 0)) - { - *pNoEntry = i; - break; - } - } - } - else - pSec = nullptr; - - return pSec; -} - -static bool loadProfile(osl_TFile* pFile, osl_TProfileImpl* pProfile) -{ - sal_uInt32 i; - char* pStr; - char* pChar; - - char* pLine; - - if ( !pFile ) - { - return false; - } - - if ( !pProfile ) - { - return false; - } - - pProfile->m_NoLines = 0; - pProfile->m_NoSections = 0; - - OSL_VERIFY(OslProfile_rewindFile(pFile, false)); - - while ( ( pLine=OslProfile_getLine(pFile) ) != nullptr ) - { - char* bWasAdded = addLine( pProfile, pLine ); - free( pLine ); - SAL_WARN_IF(!bWasAdded, "sal.osl", "addLine( pProfile, pLine ) ==> false"); - if ( ! bWasAdded ) - return false; - } - - for (i = 0; i < pProfile->m_NoLines; i++) - { - pStr = stripBlanks(pProfile->m_Lines[i], nullptr); - - if ((*pStr == ' - continue; - - if ((*pStr != '[') || ((pChar = strrchr(pStr, ']')) == nullptr) || - ((pChar - pStr) <= 2)) - { - /* insert entry */ - - if (pProfile->m_NoSections < 1) - continue; - - if ((pChar = strchr(pStr, '=')) == nullptr) - pChar = pStr + strlen(pStr); - - if (! addEntry(pProfile, &pProfile->m_Sections[pProfile->m_NoSections - 1], - i, pStr, pChar - pStr)) - { - SAL_WARN("sal.osl", "Adding entry => false"); - continue; - } - - } - else - { - /* new section */ - - if (! addSection(pProfile, i, pStr + 1, pChar - pStr - 1)) - { - SAL_WARN("sal.osl", "Adding section => false"); - continue; - } - - } - } - - return true; -} - -static bool storeProfile(osl_TProfileImpl* pProfile, bool bCleanup) -{ - if (pProfile->m_Lines != nullptr) - { - if (pProfile->m_Flags & FLG_MODIFIED) - { - sal_uInt32 i; - - osl_TFile* pTmpFile = osl_openTmpProfileImpl(pProfile); - - if ( pTmpFile == nullptr ) - { - return false; - } - - OSL_VERIFY(OslProfile_rewindFile(pTmpFile, true)); - - for ( i = 0 ; i < pProfile->m_NoLines ; i++ ) - { - OSL_VERIFY(OslProfile_putLine(pTmpFile, pProfile->m_Lines[i])); - } - - if ( ! writeProfileImpl(pTmpFile) ) - { - if ( pTmpFile->m_pWriteBuf != nullptr ) - { - free(pTmpFile->m_pWriteBuf); - } - - pTmpFile->m_pWriteBuf=nullptr; - pTmpFile->m_nWriteBufLen=0; - pTmpFile->m_nWriteBufFree=0; - - closeFileImpl(pTmpFile,pProfile->m_Flags); - - return false; - } - - pProfile->m_Flags &= ~FLG_MODIFIED; - - closeFileImpl(pProfile->m_pFile,pProfile->m_Flags); - closeFileImpl(pTmpFile,pProfile->m_Flags); - - osl_ProfileSwapProfileNames(pProfile); - - pProfile->m_pFile = openFileImpl(pProfile->m_FileName,pProfile->m_Flags); - - } - - if (bCleanup) - { - while (pProfile->m_NoLines > 0) - removeLine(pProfile, pProfile->m_NoLines - 1); - - free(pProfile->m_Lines); - pProfile->m_Lines = nullptr; - pProfile->m_NoLines = 0; - pProfile->m_MaxLines = 0; - - while (pProfile->m_NoSections > 0) - removeSection(pProfile, &pProfile->m_Sections[pProfile->m_NoSections - 1]); - - free(pProfile->m_Sections); - pProfile->m_Sections = nullptr; - pProfile->m_NoSections = 0; - pProfile->m_MaxSections = 0; - } - } - - return true; -} - -static osl_TFile* osl_openTmpProfileImpl(osl_TProfileImpl* pProfile) -{ - osl_TFile* pFile=nullptr; - char const * const pszExtension = "tmp"; - char pszTmpName[PATH_MAX]; - oslProfileOption PFlags=0; - - pszTmpName[0] = ' - - /* generate tmp profilename */ - osl_ProfileGenerateExtension(pProfile->m_FileName, pszExtension, pszTmpName, PATH_MAX); - - if ( pszTmpName[0] == 0 ) - { - return nullptr; - } - - if ( ! ( pProfile->m_Flags & osl_Profile_READLOCK ) ) - { - PFlags |= osl_Profile_WRITELOCK; - } - - /* open this file */ - pFile = openFileImpl(pszTmpName,pProfile->m_Flags | PFlags); - - /* return new pFile */ - return pFile; -} - -static bool osl_ProfileSwapProfileNames(osl_TProfileImpl* pProfile) -{ - char pszBakFile[PATH_MAX]; - char pszTmpFile[PATH_MAX]; - - pszBakFile[0] = ' - pszTmpFile[0] = ' - - osl_ProfileGenerateExtension(pProfile->m_FileName, "bak", pszBakFile, PATH_MAX); - osl_ProfileGenerateExtension(pProfile->m_FileName, "tmp", pszTmpFile, PATH_MAX); - - /* unlink bak */ - unlink( pszBakFile ); - - // Rename ini -> bak, then tmp -> ini: - bool result = rename( pProfile->m_FileName, pszBakFile ) == 0; - if (!result) - { - int e = errno; - SAL_INFO("sal.file", "rename(" << pProfile->m_FileName << "," << pszBakFile << "): " << UnixErrnoString(e)); - } - else - { - SAL_INFO("sal.file", "rename(" << pProfile->m_FileName << "," << pszBakFile << "): OK"); - result = rename( pszTmpFile, pProfile->m_FileName ) == 0; - if (!result) - { - int e = errno; - SAL_INFO("sal.file", "rename(" << pszTmpFile << "," << pProfile->m_FileName << "): " << UnixErrnoString(e)); - } - else - { - SAL_INFO("sal.file", "rename(" << pszTmpFile << "," << pProfile->m_FileName << "): OK"); - } - } - return result; -} - -static void osl_ProfileGenerateExtension(const char* pszFileName, const char* pszExtension, char* pszTmpName, int BufferMaxLen) -{ - char* cursor = pszTmpName; - int len; - - /* concatenate filename + "." + extension, limited to the size of the - * output buffer; in case of overrun, data is truncated at the end... - * and the result is always 0-terminated. - */ - len = strlen(pszFileName); - if(len < BufferMaxLen) - { - memcpy(cursor, pszFileName, len); - cursor += len; - BufferMaxLen -= len; - } - else - { - memcpy(cursor, pszFileName, BufferMaxLen - 1); - cursor += BufferMaxLen - 1; - BufferMaxLen = 1; - } - if(BufferMaxLen > 1) - { - *cursor++ = '.'; - BufferMaxLen -= 1; - } - len = strlen(pszExtension); - if(len < BufferMaxLen) - { - memcpy(cursor, pszExtension, len); - cursor += len; - } - else - { - memcpy(cursor, pszExtension, BufferMaxLen - 1); - cursor += BufferMaxLen - 1; - } - *cursor = 0; -} - -static osl_TProfileImpl* acquireProfile(oslProfile Profile, bool bWriteable) -{ - osl_TProfileImpl* pProfile = static_cast<osl_TProfileImpl*>(Profile); - oslProfileOption PFlags=0; - - if ( bWriteable ) - { - PFlags = osl_Profile_DEFAULT | osl_Profile_WRITELOCK; - } - else - { - PFlags = osl_Profile_DEFAULT; - } - - if (pProfile == nullptr) - { - if ( ( pProfile = static_cast<osl_TProfileImpl*>(osl_openProfile(nullptr, PFlags )) ) != nullptr ) - { - pProfile->m_Flags |= FLG_AUTOOPEN; - } - } - else - { - if (! (pProfile->m_Flags & osl_Profile_SYSTEM)) - { - if (! (pProfile->m_Flags & (osl_Profile_READLOCK | osl_Profile_WRITELOCK | osl_Profile_FLUSHWRITE ))) - { - osl_TStamp Stamp; - - if (! (pProfile->m_pFile = openFileImpl(pProfile->m_FileName, pProfile->m_Flags | PFlags ))) - return nullptr; - - Stamp = OslProfile_getFileStamp(pProfile->m_pFile); - - if (memcmp(&Stamp, &(pProfile->m_Stamp), sizeof(osl_TStamp))) - { - pProfile->m_Stamp = Stamp; - bool bRet = loadProfile(pProfile->m_pFile, pProfile); - SAL_WARN_IF(!bRet, "sal.osl", "loadProfile(pProfile->m_pFile, pProfile) ==> false"); - } - } - else - { - /* A readlock file could not be written */ - if ((pProfile->m_Flags & osl_Profile_READLOCK) && bWriteable) - { - return nullptr; - } - } - } - } - - return pProfile; -} - -static bool releaseProfile(osl_TProfileImpl* pProfile) -{ - if ( pProfile == nullptr ) - { - return false; - } - - if (pProfile->m_Flags & FLG_AUTOOPEN) - { - return osl_closeProfile(static_cast<oslProfile>(pProfile)); - } - - if (! (pProfile->m_Flags & (osl_Profile_READLOCK | osl_Profile_WRITELOCK | osl_Profile_FLUSHWRITE ))) - { - if (pProfile->m_Flags & FLG_MODIFIED) - { - bool bRet = storeProfile(pProfile, false); - SAL_WARN_IF(!bRet, "sal.osl", "storeProfile(pProfile, false) ==> false"); - } - - closeFileImpl(pProfile->m_pFile,pProfile->m_Flags); - pProfile->m_pFile = nullptr; - } - - return true; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/osl/w32/profile.cxx b/sal/osl/w32/profile.cxx deleted file mode 100644 index e5fbfe55d188..000000000000 --- a/sal/osl/w32/profile.cxx +++ /dev/null @@ -1,2344 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include "system.h" - -#include "file_url.hxx" -#include "path_helper.hxx" - -#include <string.h> -#include <osl/diagnose.h> -#include <osl/profile.h> -#include <osl/process.h> -#include <osl/thread.h> -#include <osl/file.h> -#include <rtl/alloc.h> -#include <sal/macros.h> -#include <sal/log.hxx> -#include <o3tl/char16_t2wchar_t.hxx> -#include <systools/win32/extended_max_path.hxx> - -#include <algorithm> -#include <vector> -using std::min; -static void copy_ustr_n( void *dest, const void *source, size_t length ) { memcpy(dest, source, length*sizeof(sal_Unicode)); } - -#define LINES_INI 32 -#define LINES_ADD 10 -#define SECTIONS_INI 5 -#define SECTIONS_ADD 3 -#define ENTRIES_INI 5 -#define ENTRIES_ADD 3 - -#define STR_INI_EXTENSION L".ini" -#define STR_INI_METAHOME "?~" -#define STR_INI_METASYS "?$" -#define STR_INI_METACFG "?^" -#define STR_INI_METAINS "?#" - -#define STR_INI_BOOLYES "yes" -#define STR_INI_BOOLON "on" -#define STR_INI_BOOLONE "1" -#define STR_INI_BOOLNO "no" -#define STR_INI_BOOLOFF "off" -#define STR_INI_BOOLZERO "0" - -#define FLG_USER 0x00FF -#define FLG_AUTOOPEN 0x0100 -#define FLG_MODIFIED 0x0200 - -#define SVERSION_LOCATION STR_INI_METACFG -#define SVERSION_FALLBACK STR_INI_METASYS -#define SVERSION_NAME "sversion" -#define SVERSION_SECTION "Versions" -#define SVERSION_SOFFICE "StarOffice" -#define SVERSION_PROFILE "soffice.ini" -#define SVERSION_DIRS { "bin", "program" } -#define SVERSION_USER "user" - -/*#define DEBUG_OSL_PROFILE 1*/ - -typedef FILETIME osl_TStamp; - -namespace { - -enum osl_TLockMode -{ - un_lock, read_lock, write_lock -}; - -struct osl_TFile -{ - HANDLE m_Handle; - char* m_pReadPtr; - char m_ReadBuf[512]; - char* m_pWriteBuf; - sal_uInt32 m_nWriteBufLen; - sal_uInt32 m_nWriteBufFree; -}; - -struct osl_TProfileEntry -{ - sal_uInt32 m_Line; - sal_uInt32 m_Offset; - sal_uInt32 m_Len; -}; - -struct osl_TProfileSection -{ - sal_uInt32 m_Line; - sal_uInt32 m_Offset; - sal_uInt32 m_Len; - sal_uInt32 m_NoEntries; - sal_uInt32 m_MaxEntries; - osl_TProfileEntry* m_Entries; -}; - -/* - Profile-data structure hidden behind oslProfile: -*/ -struct osl_TProfileImpl -{ - sal_uInt32 m_Flags; - osl_TFile* m_pFile; - osl_TStamp m_Stamp; - sal_uInt32 m_NoLines; - sal_uInt32 m_MaxLines; - sal_uInt32 m_NoSections; - sal_uInt32 m_MaxSections; - char** m_Lines; - rtl_uString *m_strFileName; - osl_TProfileSection* m_Sections; -}; - -} - -static osl_TFile* openFileImpl(rtl_uString * strFileName, oslProfileOption ProfileFlags ); -static osl_TStamp closeFileImpl(osl_TFile* pFile); -static bool lockFile(const osl_TFile* pFile, osl_TLockMode eMode); -static bool rewindFile(osl_TFile* pFile, bool bTruncate); -static osl_TStamp getFileStamp(osl_TFile* pFile); - -static bool getLine(osl_TFile* pFile, char *pszLine, int MaxLen); -static bool putLine(osl_TFile* pFile, const char *pszLine); -static const char* stripBlanks(const char* String, sal_uInt32* pLen); -static const char* addLine(osl_TProfileImpl* pProfile, const char* Line); -static const char* insertLine(osl_TProfileImpl* pProfile, const char* Line, sal_uInt32 LineNo); -static void removeLine(osl_TProfileImpl* pProfile, sal_uInt32 LineNo); -static void setEntry(osl_TProfileImpl* pProfile, osl_TProfileSection* pSection, - sal_uInt32 NoEntry, sal_uInt32 Line, - const char* Entry, sal_uInt32 Len); -static bool addEntry(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection, - int Line, const char* Entry, sal_uInt32 Len); -static void removeEntry(osl_TProfileSection *pSection, sal_uInt32 NoEntry); -static bool addSection(osl_TProfileImpl* pProfile, int Line, const char* Section, sal_uInt32 Len); -static void removeSection(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection); -static osl_TProfileSection* findEntry(osl_TProfileImpl* pProfile, const char* Section, - const char* Entry, sal_uInt32 *pNoEntry); -static bool loadProfile(osl_TFile* pFile, osl_TProfileImpl* pProfile); -static bool storeProfile(osl_TProfileImpl* pProfile, bool bCleanup); -static osl_TProfileImpl* acquireProfile(oslProfile Profile, bool bWriteable); -static bool releaseProfile(osl_TProfileImpl* pProfile); -static bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *strFile, sal_Unicode *strProfile); - -static bool writeProfileImpl (osl_TFile* pFile); -static osl_TFile* osl_openTmpProfileImpl(osl_TProfileImpl*); -static bool osl_ProfileSwapProfileNames(osl_TProfileImpl*); -static rtl_uString* osl_ProfileGenerateExtension(rtl_uString* ustrFileName, rtl_uString* ustrExtension); - -static bool osl_getProfileName(rtl_uString* strPath, rtl_uString* strName, rtl_uString** strProfileName); - -oslProfile SAL_CALL osl_openProfile(rtl_uString *strProfileName, oslProfileOption Flags) -{ - osl_TFile* pFile = nullptr; - osl_TProfileImpl* pProfile; - rtl_uString *FileName=nullptr; - - OSL_VERIFY(strProfileName); - - if (rtl_uString_getLength(strProfileName) == 0 ) - { - OSL_VERIFY(osl_getProfileName(nullptr, nullptr, &FileName)); - } - else - { - rtl_uString_assign(&FileName, strProfileName); - } - - osl_getSystemPathFromFileURL(FileName, &FileName); - -#ifdef DEBUG_OSL_PROFILE - Flags=osl_Profile_FLUSHWRITE; - - if ( Flags == osl_Profile_DEFAULT ) - { - SAL_INFO("sal.osl", "with osl_Profile_DEFAULT"); - } - if ( Flags & osl_Profile_SYSTEM ) - { - SAL_INFO("sal.osl", "with osl_Profile_SYSTEM"); - } - if ( Flags & osl_Profile_READLOCK ) - { - SAL_INFO("sal.osl", "with osl_Profile_READLOCK"); - } - if ( Flags & osl_Profile_WRITELOCK ) - { - SAL_INFO("sal.osl", "with osl_Profile_WRITELOCK"); - } - if ( Flags & osl_Profile_FLUSHWRITE ) - { - SAL_INFO("sal.osl", "with osl_Profile_FLUSHWRITE"); - } -#endif - - if ( (! (Flags & osl_Profile_SYSTEM)) && ( (pFile = openFileImpl(FileName, Flags) ) == nullptr ) ) - { - if( FileName) - rtl_uString_release( FileName); - - return nullptr; - } - - pProfile = static_cast<osl_TProfileImpl*>(calloc(1, sizeof(osl_TProfileImpl))); - if (!pProfile) - return nullptr; - - pProfile->m_Flags = Flags & FLG_USER; - osl_getSystemPathFromFileURL(strProfileName, &pProfile->m_strFileName); - - if (Flags & (osl_Profile_READLOCK | osl_Profile_WRITELOCK | osl_Profile_FLUSHWRITE )) - pProfile->m_pFile = pFile; - - pProfile->m_Stamp = getFileStamp(pFile); - - loadProfile(pFile, pProfile); - - if (pProfile->m_pFile == nullptr) - closeFileImpl(pFile); - - if( FileName) - rtl_uString_release( FileName); - - return pProfile; -} - -sal_Bool SAL_CALL osl_closeProfile(oslProfile Profile) -{ - osl_TProfileImpl* pProfile = static_cast<osl_TProfileImpl*>(Profile); - - - if ( Profile == nullptr ) - { - return false; - } - - if (! (pProfile->m_Flags & osl_Profile_SYSTEM)) - { - pProfile = acquireProfile(Profile,true); - - if ( pProfile != nullptr ) - { - if ( !( pProfile->m_Flags & osl_Profile_READLOCK ) && ( pProfile->m_Flags & FLG_MODIFIED ) ) - { - storeProfile(pProfile, false); - } - } - else - { - pProfile = acquireProfile(Profile,false); - } - - if ( pProfile == nullptr ) - { - return false; - } - - if (pProfile->m_pFile != nullptr) - closeFileImpl(pProfile->m_pFile); - } - - pProfile->m_pFile = nullptr; - rtl_uString_release(pProfile->m_strFileName); - pProfile->m_strFileName = nullptr; - - /* release whole profile data types memory */ - if ( pProfile->m_NoLines > 0) - { - unsigned int index=0; - if ( pProfile->m_Lines != nullptr ) - { - for ( index = 0 ; index < pProfile->m_NoLines ; ++index) - { - if ( pProfile->m_Lines[index] != nullptr ) - { - free(pProfile->m_Lines[index]); - } - } - free(pProfile->m_Lines); - } - if ( pProfile->m_Sections != nullptr ) - { - for ( index = 0 ; index < pProfile->m_NoSections ; ++index ) - { - if ( pProfile->m_Sections[index].m_Entries != nullptr ) - free(pProfile->m_Sections[index].m_Entries); - } - free(pProfile->m_Sections); - } - - } - free(pProfile); - - return true; -} - -sal_Bool SAL_CALL osl_flushProfile(oslProfile Profile) -{ - osl_TProfileImpl* pProfile = static_cast<osl_TProfileImpl*>(Profile); - osl_TFile* pFile; - bool bRet = false; - - - if ( pProfile == nullptr ) - { - return false; - } - - pFile = pProfile->m_pFile; - if ( pFile == nullptr || pFile->m_Handle == INVALID_HANDLE_VALUE ) - { - return false; - } - - if ( pProfile->m_Flags & FLG_MODIFIED ) - { -#ifdef DEBUG_OSL_PROFILE - SAL_INFO("sal.osl", "swapping to storeprofile"); -#endif - bRet = storeProfile(pProfile,false); - } - - return bRet; -} - -static bool writeProfileImpl(osl_TFile* pFile) -{ - DWORD BytesWritten=0; - bool bRet; - - if ( pFile == nullptr || pFile->m_Handle == INVALID_HANDLE_VALUE || ( pFile->m_pWriteBuf == nullptr ) ) - { - return false; - } - - bRet=WriteFile(pFile->m_Handle, pFile->m_pWriteBuf, pFile->m_nWriteBufLen - pFile->m_nWriteBufFree,&BytesWritten,nullptr); - - if ( !bRet || BytesWritten == 0 ) - { - OSL_ENSURE(bRet,"WriteFile failed!!!"); - SAL_WARN("sal.osl", "write failed " << strerror(errno)); - - return false; - } - - free(pFile->m_pWriteBuf); - pFile->m_pWriteBuf=nullptr; - pFile->m_nWriteBufLen=0; - pFile->m_nWriteBufFree=0; - - return true; -} - -namespace { -// Use Unicode version of GetPrivateProfileString, to work with Multi-language paths -DWORD GetPrivateProfileStringWrapper(const osl_TProfileImpl* pProfile, - const char* pszSection, const char* pszEntry, - char* pszString, sal_uInt32 MaxLen, - const char* pszDefault) -{ - assert(pProfile && (!MaxLen || pszString)); - - rtl_uString *pSection = nullptr, *pEntry = nullptr, *pDefault = nullptr; - if (pszSection) - { - rtl_string2UString(&pSection, pszSection, strlen(pszSection), osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS); - OSL_ASSERT(pSection); - } - if (pszEntry) - { - rtl_string2UString(&pEntry, pszEntry, strlen(pszEntry), osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS); - OSL_ASSERT(pEntry); - } - if (pszDefault) - { - rtl_string2UString(&pDefault, pszDefault, strlen(pszDefault), osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS); - OSL_ASSERT(pDefault); - } - - LPCWSTR pWSection = (pSection ? o3tl::toW(rtl_uString_getStr(pSection)) : nullptr), - pWEntry = (pEntry ? o3tl::toW(rtl_uString_getStr(pEntry)) : nullptr), - pWDefault = (pDefault ? o3tl::toW(rtl_uString_getStr(pDefault)) : nullptr); - - std::vector<wchar_t> aBuf(MaxLen + 1); - GetPrivateProfileStringW(pWSection, pWEntry, pWDefault, aBuf.data(), MaxLen, o3tl::toW(rtl_uString_getStr(pProfile->m_strFileName))); - - if (pDefault) - rtl_uString_release(pDefault); - if (pEntry) - rtl_uString_release(pEntry); - if (pSection) - rtl_uString_release(pSection); - - return WideCharToMultiByte(CP_ACP, 0, aBuf.data(), -1, pszString, MaxLen, nullptr, nullptr); -} - -// Use Unicode version of WritePrivateProfileString, to work with Multi-language paths -bool WritePrivateProfileStringWrapper(const osl_TProfileImpl* pProfile, - const char* pszSection, const char* pszEntry, - const char* pszString) -{ - assert(pProfile && pszSection); - rtl_uString *pSection, *pEntry = nullptr, *pString = nullptr; - rtl_string2UString(&pSection, pszSection, strlen(pszSection), osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS); - assert(pSection); - if (pszEntry) - { - rtl_string2UString(&pEntry, pszEntry, strlen(pszEntry), osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS); - OSL_ASSERT(pEntry); - } - if (pszString) - { - rtl_string2UString(&pString, pszString, strlen(pszString), osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS); - OSL_ASSERT(pString); - } - - LPCWSTR pWSection = o3tl::toW(pSection->buffer), - pWEntry = (pEntry ? o3tl::toW(rtl_uString_getStr(pEntry)) : nullptr), - pWString = (pString ? o3tl::toW(rtl_uString_getStr(pString)) : nullptr); - - bool bResult = WritePrivateProfileStringW(pWSection, pWEntry, pWString, o3tl::toW(rtl_uString_getStr(pProfile->m_strFileName))); - - if (pString) - rtl_uString_release(pString); - if (pEntry) - rtl_uString_release(pEntry); - rtl_uString_release(pSection); - - return bResult; -} -} - -sal_Bool SAL_CALL osl_readProfileString(oslProfile Profile, - const char* pszSection, const char* pszEntry, - char* pszString, sal_uInt32 MaxLen, - const char* pszDefault) -{ - sal_uInt32 NoEntry; - const char* pStr = nullptr; - osl_TProfileImpl* pProfile = nullptr; - - pProfile = acquireProfile(Profile, false); - - if (pProfile == nullptr) - { - return false; - } - - if (! (pProfile->m_Flags & osl_Profile_SYSTEM)) - { - osl_TProfileSection* pSec; - if (((pSec = findEntry(pProfile, pszSection, pszEntry, &NoEntry)) != nullptr) && - (NoEntry < pSec->m_NoEntries) && - ((pStr = strchr(pProfile->m_Lines[pSec->m_Entries[NoEntry].m_Line], - '=')) != nullptr)) - pStr++; - else - pStr = pszDefault; - - if ( pStr != nullptr ) - { - pStr = stripBlanks(pStr, nullptr); - MaxLen = (MaxLen - 1 < strlen(pStr)) ? (MaxLen - 1) : strlen(pStr); - pStr = stripBlanks(pStr, &MaxLen); - strncpy(pszString, pStr, MaxLen); - pszString[MaxLen] = ' - } - } - else - { - if (GetPrivateProfileStringWrapper(pProfile, pszSection, pszEntry, pszString, MaxLen, pszDefault) > 0) - pStr = pszString; // required to return true below - } - - releaseProfile(pProfile); - - if ( pStr == nullptr ) - { - return false; - } - - return true; -} - -sal_Bool SAL_CALL osl_readProfileBool(oslProfile Profile, - const char* pszSection, const char* pszEntry, - sal_Bool Default) -{ - char Line[32]; - - if (osl_readProfileString(Profile, pszSection, pszEntry, Line, sizeof(Line), "")) - { - if ((stricmp(Line, STR_INI_BOOLYES) == 0) || - (stricmp(Line, STR_INI_BOOLON) == 0) || - (stricmp(Line, STR_INI_BOOLONE) == 0)) - Default = true; - else - if ((stricmp(Line, STR_INI_BOOLNO) == 0) || - (stricmp(Line, STR_INI_BOOLOFF) == 0) || - (stricmp(Line, STR_INI_BOOLZERO) == 0)) - Default = false; - } - - return Default; -} - -sal_uInt32 SAL_CALL osl_readProfileIdent(oslProfile Profile, - const char* pszSection, const char* pszEntry, - sal_uInt32 FirstId, const char* Strings[], - sal_uInt32 Default) -{ - sal_uInt32 i; - char Line[256]; - - if (osl_readProfileString(Profile, pszSection, pszEntry, Line, sizeof(Line), "")) - { - i = 0; - while (Strings[i] != nullptr) - { - if (stricmp(Line, Strings[i]) == 0) - { - Default = i + FirstId; - break; - } - i++; - } - } - - return Default; -} - -sal_Bool SAL_CALL osl_writeProfileString(oslProfile Profile, - const char* pszSection, const char* pszEntry, - const char* pszString) -{ - sal_uInt32 i; - bool bRet = false; - sal_uInt32 NoEntry; - const char* pStr; - char Line[4096]; - osl_TProfileSection* pSec; - osl_TProfileImpl* pProfile = nullptr; - - pProfile = acquireProfile(Profile, true); - - if (pProfile == nullptr) - { - return false; - } - - if (! (pProfile->m_Flags & osl_Profile_SYSTEM)) - { - if ((pSec = findEntry(pProfile, pszSection, pszEntry, &NoEntry)) == nullptr) - { - Line[0] = ' - addLine(pProfile, Line); - - Line[0] = '['; - strcpy(&Line[1], pszSection); - Line[1 + strlen(pszSection)] = ']'; - Line[2 + strlen(pszSection)] = ' - - if (((pStr = addLine(pProfile, Line)) == nullptr) || - (! addSection(pProfile, pProfile->m_NoLines - 1, &pStr[1], strlen(pszSection)))) - { - releaseProfile(pProfile); - return false; - } - - pSec = &pProfile->m_Sections[pProfile->m_NoSections - 1]; - NoEntry = pSec->m_NoEntries; - } - - Line[0] = ' - strcpy(&Line[0], pszEntry); - Line[0 + strlen(pszEntry)] = '='; - strcpy(&Line[1 + strlen(pszEntry)], pszString); - - if (NoEntry >= pSec->m_NoEntries) - { - if (pSec->m_NoEntries > 0) - i = pSec->m_Entries[pSec->m_NoEntries - 1].m_Line + 1; - else - i = pSec->m_Line + 1; - - if (((pStr = insertLine(pProfile, Line, i)) == nullptr) || - (! addEntry(pProfile, pSec, i, pStr, strlen(pszEntry)))) - { - releaseProfile(pProfile); - return false; - } - - pProfile->m_Flags |= FLG_MODIFIED; - } - else - { - i = pSec->m_Entries[NoEntry].m_Line; - free(pProfile->m_Lines[i]); - pProfile->m_Lines[i] = strdup(Line); - setEntry(pProfile, pSec, NoEntry, i, pProfile->m_Lines[i], strlen(pszEntry)); - - pProfile->m_Flags |= FLG_MODIFIED; - } - } - else - { - WritePrivateProfileStringWrapper(pProfile, pszSection, pszEntry, pszString); - } - - bRet = releaseProfile(pProfile); - return bRet; -} - -sal_Bool SAL_CALL osl_writeProfileBool(oslProfile Profile, - const char* pszSection, const char* pszEntry, - sal_Bool Value) -{ - bool bRet = false; - - if (Value) - bRet=osl_writeProfileString(Profile, pszSection, pszEntry, STR_INI_BOOLONE); - else - bRet=osl_writeProfileString(Profile, pszSection, pszEntry, STR_INI_BOOLZERO); - - return bRet; -} - -sal_Bool SAL_CALL osl_writeProfileIdent(oslProfile Profile, - const char* pszSection, const char* pszEntry, - sal_uInt32 FirstId, const char* Strings[], - sal_uInt32 Value) -{ - int i, n; - bool bRet = false; - - for (n = 0; Strings[n] != nullptr; n++); - - if ((i = Value - FirstId) >= n) - bRet=false; - else - bRet=osl_writeProfileString(Profile, pszSection, pszEntry, Strings[i]); - - return bRet; -} - -sal_Bool SAL_CALL osl_removeProfileEntry(oslProfile Profile, - const char *pszSection, const char *pszEntry) -{ - sal_uInt32 NoEntry; - osl_TProfileImpl* pProfile = nullptr; - bool bRet = false; - - pProfile = acquireProfile(Profile, true); - - if (pProfile == nullptr) - return false; - - if (!(pProfile->m_Flags & osl_Profile_SYSTEM)) - { - osl_TProfileSection* pSec; - if (((pSec = findEntry(pProfile, pszSection, pszEntry, &NoEntry)) != nullptr) && - (NoEntry < pSec->m_NoEntries)) - { - removeLine(pProfile, pSec->m_Entries[NoEntry].m_Line); - removeEntry(pSec, NoEntry); - if (pSec->m_NoEntries == 0) - { - removeLine(pProfile, pSec->m_Line); - - /* remove any empty separation line */ - if ((pSec->m_Line > 0) && (pProfile->m_Lines[pSec->m_Line - 1][0] == ' - removeLine(pProfile, pSec->m_Line - 1); - - removeSection(pProfile, pSec); - } - - pProfile->m_Flags |= FLG_MODIFIED; - } - } - else - { - WritePrivateProfileStringWrapper(pProfile, pszSection, pszEntry, nullptr); - } - - bRet = releaseProfile(pProfile); - return bRet; -} - -sal_uInt32 SAL_CALL osl_getProfileSectionEntries(oslProfile Profile, const char *pszSection, - char* pszBuffer, sal_uInt32 MaxLen) -{ - sal_uInt32 i, n = 0; - sal_uInt32 NoEntry; - osl_TProfileImpl* pProfile = nullptr; - - pProfile = acquireProfile(Profile, false); - - if (pProfile == nullptr) - return 0; - - if (! (pProfile->m_Flags & osl_Profile_SYSTEM)) - { - osl_TProfileSection* pSec; - if ((pSec = findEntry(pProfile, pszSection, "", &NoEntry)) != nullptr) - { - if (MaxLen != 0) - { - for (i = 0; i < pSec->m_NoEntries; i++) - { - if ((n + pSec->m_Entries[i].m_Len + 1) < MaxLen) - { - strncpy(&pszBuffer[n], &pProfile->m_Lines[pSec->m_Entries[i].m_Line] - [pSec->m_Entries[i].m_Offset], pSec->m_Entries[i].m_Len); - n += pSec->m_Entries[i].m_Len; - pszBuffer[n++] = ' - } - else - { - break; - } - - } - - pszBuffer[n++] = ' - } - else - { - for (i = 0; i < pSec->m_NoEntries; i++) - { - n += pSec->m_Entries[i].m_Len + 1; - } - - n += 1; - } - } - else - { - n = 0; - } - } - else - { - n = GetPrivateProfileStringWrapper(pProfile, pszSection, nullptr, pszBuffer, MaxLen, nullptr); - } - - releaseProfile(pProfile); - - return n; -} - -bool osl_getProfileName(rtl_uString* strPath, rtl_uString* strName, rtl_uString** strProfileName) -{ - bool bFailed; - osl::LongPathBuffer<sal_Unicode> aFile(EXTENDED_MAX_PATH); - osl::LongPathBuffer<sal_Unicode> aPath(EXTENDED_MAX_PATH); - sal_uInt32 nFileLen = 0; - sal_uInt32 nPathLen = 0; - - rtl_uString * strTmp = nullptr; - oslFileError nError; - - /* build file name */ - if (strName && strName->length) - { - if( ::sal::static_int_cast< sal_uInt32 >( strName->length ) >= aFile.getBufSizeInSymbols() ) - return false; - - copy_ustr_n( aFile, strName->buffer, strName->length+1); - nFileLen = strName->length; - - if (rtl_ustr_indexOfChar( aFile, L'.' ) == -1) - { - if (nFileLen + wcslen(STR_INI_EXTENSION) >= aFile.getBufSizeInSymbols()) - return false; - - /* add default extension */ - copy_ustr_n( aFile + nFileLen, STR_INI_EXTENSION, wcslen(STR_INI_EXTENSION)+1 ); - nFileLen += wcslen(STR_INI_EXTENSION); - } - } - else -e ... etc. - the rest is truncated
