| File: | sal/osl/unx/profile.c |
| Location: | line 1561, column 5 |
| Description: | Array access (via field 'm_Lines') results in a null pointer dereference |
| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | |||
| 2 | /************************************************************************* | |||
| 3 | * | |||
| 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |||
| 5 | * | |||
| 6 | * Copyright 2000, 2010 Oracle and/or its affiliates. | |||
| 7 | * | |||
| 8 | * OpenOffice.org - a multi-platform office productivity suite | |||
| 9 | * | |||
| 10 | * This file is part of OpenOffice.org. | |||
| 11 | * | |||
| 12 | * OpenOffice.org is free software: you can redistribute it and/or modify | |||
| 13 | * it under the terms of the GNU Lesser General Public License version 3 | |||
| 14 | * only, as published by the Free Software Foundation. | |||
| 15 | * | |||
| 16 | * OpenOffice.org is distributed in the hope that it will be useful, | |||
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
| 19 | * GNU Lesser General Public License version 3 for more details | |||
| 20 | * (a copy is included in the LICENSE file that accompanied this code). | |||
| 21 | * | |||
| 22 | * You should have received a copy of the GNU Lesser General Public License | |||
| 23 | * version 3 along with OpenOffice.org. If not, see | |||
| 24 | * <http://www.openoffice.org/license.html> | |||
| 25 | * for a copy of the LGPLv3 License. | |||
| 26 | * | |||
| 27 | ************************************************************************/ | |||
| 28 | ||||
| 29 | ||||
| 30 | #include "system.h" | |||
| 31 | #include "readwrite_helper.h" | |||
| 32 | ||||
| 33 | #include <osl/diagnose.h> | |||
| 34 | #include <osl/profile.h> | |||
| 35 | #include <osl/process.h> | |||
| 36 | #include <osl/thread.h> | |||
| 37 | #include <rtl/alloc.h> | |||
| 38 | #include <osl/util.h> | |||
| 39 | ||||
| 40 | #define LINES_INI32 32 | |||
| 41 | #define LINES_ADD10 10 | |||
| 42 | #define SECTIONS_INI5 5 | |||
| 43 | #define SECTIONS_ADD3 3 | |||
| 44 | #define ENTRIES_INI5 5 | |||
| 45 | #define ENTRIES_ADD3 3 | |||
| 46 | ||||
| 47 | ||||
| 48 | #define STR_INI_EXTENSION"rc" "rc" | |||
| 49 | #define STR_INI_METAHOME"?~" "?~" | |||
| 50 | #define STR_INI_METASYS"?$" "?$" | |||
| 51 | #define STR_INI_METACFG"?^" "?^" | |||
| 52 | #define STR_INI_METAINS"?#" "?#" | |||
| 53 | ||||
| 54 | #define STR_INI_BOOLYES"yes" "yes" | |||
| 55 | #define STR_INI_BOOLON"on" "on" | |||
| 56 | #define STR_INI_BOOLONE"1" "1" | |||
| 57 | #define STR_INI_BOOLNO"no" "no" | |||
| 58 | #define STR_INI_BOOLOFF"off" "off" | |||
| 59 | #define STR_INI_BOOLZERO"0" "0" | |||
| 60 | ||||
| 61 | #define FLG_USER0x00FF 0x00FF | |||
| 62 | #define FLG_AUTOOPEN0x0100 0x0100 | |||
| 63 | #define FLG_MODIFIED0x0200 0x0200 | |||
| 64 | ||||
| 65 | #define SVERSION_LOCATION"?^" STR_INI_METACFG"?^" | |||
| 66 | #define SVERSION_FALLBACK"?$" STR_INI_METASYS"?$" | |||
| 67 | #define SVERSION_NAME"sversion" "sversion" | |||
| 68 | #define SVERSION_SECTION"Versions" "Versions" | |||
| 69 | #define SVERSION_SOFFICE"StarOffice" "StarOffice" | |||
| 70 | #define SVERSION_PROFILE"sofficerc" "sofficerc" | |||
| 71 | #define SVERSION_OPTION"userid:" "userid:" | |||
| 72 | #define SVERSION_DIRS{ "bin", "program" } { "bin", "program" } | |||
| 73 | #define SVERSION_USER"user" "user" | |||
| 74 | ||||
| 75 | #define DEFAULT_PMODE(0400 | 0200 | (0400 >> 3) | (0200 >> 3) | ((0400 >> 3) >> 3) | ((0200 >> 3) >> 3)) (S_IRUSR0400 | S_IWUSR0200 | S_IRGRP(0400 >> 3) | S_IWGRP(0200 >> 3) | S_IROTH((0400 >> 3) >> 3) | S_IWOTH((0200 >> 3) >> 3)) | |||
| 76 | ||||
| 77 | #define _BUILD_STR_(n)"n" # n | |||
| 78 | #define BUILD_STR(n)"n" _BUILD_STR_(n)"n" | |||
| 79 | ||||
| 80 | ||||
| 81 | /*#define DEBUG_OSL_PROFILE*/ | |||
| 82 | /*#define TRACE_OSL_PROFILE*/ | |||
| 83 | ||||
| 84 | /*****************************************************************************/ | |||
| 85 | /* Data Type Definition */ | |||
| 86 | /*****************************************************************************/ | |||
| 87 | ||||
| 88 | typedef time_t osl_TStamp; | |||
| 89 | ||||
| 90 | typedef enum _osl_TLockMode | |||
| 91 | { | |||
| 92 | un_lock, read_lock, write_lock | |||
| 93 | } osl_TLockMode; | |||
| 94 | ||||
| 95 | typedef struct _osl_TFile | |||
| 96 | { | |||
| 97 | int m_Handle; | |||
| 98 | sal_Char* m_pReadPtr; | |||
| 99 | sal_Char m_ReadBuf[512]; | |||
| 100 | sal_Char* m_pWriteBuf; | |||
| 101 | sal_uInt32 m_nWriteBufLen; | |||
| 102 | sal_uInt32 m_nWriteBufFree; | |||
| 103 | } osl_TFile; | |||
| 104 | ||||
| 105 | typedef struct _osl_TProfileEntry | |||
| 106 | { | |||
| 107 | sal_uInt32 m_Line; | |||
| 108 | sal_uInt32 m_Offset; | |||
| 109 | sal_uInt32 m_Len; | |||
| 110 | } osl_TProfileEntry; | |||
| 111 | ||||
| 112 | typedef struct _osl_TProfileSection | |||
| 113 | { | |||
| 114 | sal_uInt32 m_Line; | |||
| 115 | sal_uInt32 m_Offset; | |||
| 116 | sal_uInt32 m_Len; | |||
| 117 | sal_uInt32 m_NoEntries; | |||
| 118 | sal_uInt32 m_MaxEntries; | |||
| 119 | osl_TProfileEntry* m_Entries; | |||
| 120 | } osl_TProfileSection; | |||
| 121 | ||||
| 122 | ||||
| 123 | /* | |||
| 124 | Profile-data structure hidden behind oslProfile: | |||
| 125 | */ | |||
| 126 | typedef struct _osl_TProfileImpl | |||
| 127 | { | |||
| 128 | sal_uInt32 m_Flags; | |||
| 129 | osl_TFile* m_pFile; | |||
| 130 | osl_TStamp m_Stamp; | |||
| 131 | sal_Char m_FileName[PATH_MAX4096 + 1]; | |||
| 132 | sal_uInt32 m_NoLines; | |||
| 133 | sal_uInt32 m_MaxLines; | |||
| 134 | sal_uInt32 m_NoSections; | |||
| 135 | sal_uInt32 m_MaxSections; | |||
| 136 | sal_Char** m_Lines; | |||
| 137 | osl_TProfileSection* m_Sections; | |||
| 138 | pthread_mutex_t m_AccessLock; | |||
| 139 | sal_Bool m_bIsValid; | |||
| 140 | } osl_TProfileImpl; | |||
| 141 | ||||
| 142 | ||||
| 143 | /*****************************************************************************/ | |||
| 144 | /* Static Module Function Declarations */ | |||
| 145 | /*****************************************************************************/ | |||
| 146 | ||||
| 147 | static osl_TFile* openFileImpl(const sal_Char* pszFilename, oslProfileOption ProfileFlags); | |||
| 148 | static osl_TStamp closeFileImpl(osl_TFile* pFile, oslProfileOption Flags); | |||
| 149 | static sal_Bool OslProfile_lockFile(const osl_TFile* pFile, osl_TLockMode eMode); | |||
| 150 | static sal_Bool OslProfile_rewindFile(osl_TFile* pFile, sal_Bool bTruncate); | |||
| 151 | static osl_TStamp OslProfile_getFileStamp(osl_TFile* pFile); | |||
| 152 | ||||
| 153 | static sal_Char* OslProfile_getLine(osl_TFile* pFile); | |||
| 154 | static sal_Bool OslProfile_putLine(osl_TFile* pFile, const sal_Char *pszLine); | |||
| 155 | static sal_Char* stripBlanks(sal_Char* String, sal_uInt32* pLen); | |||
| 156 | static sal_Char* addLine(osl_TProfileImpl* pProfile, const sal_Char* Line); | |||
| 157 | static sal_Char* insertLine(osl_TProfileImpl* pProfile, const sal_Char* Line, sal_uInt32 LineNo); | |||
| 158 | static void removeLine(osl_TProfileImpl* pProfile, sal_uInt32 LineNo); | |||
| 159 | static void setEntry(osl_TProfileImpl* pProfile, osl_TProfileSection* pSection, | |||
| 160 | sal_uInt32 NoEntry, sal_uInt32 Line, | |||
| 161 | sal_Char* Entry, sal_uInt32 Len); | |||
| 162 | static sal_Bool addEntry(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection, | |||
| 163 | int Line, sal_Char* Entry, sal_uInt32 Len); | |||
| 164 | static void removeEntry(osl_TProfileSection *pSection, sal_uInt32 NoEntry); | |||
| 165 | static sal_Bool addSection(osl_TProfileImpl* pProfile, int Line, const sal_Char* Section, sal_uInt32 Len); | |||
| 166 | static void removeSection(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection); | |||
| 167 | static osl_TProfileSection* findEntry(osl_TProfileImpl* pProfile, const sal_Char* Section, | |||
| 168 | const sal_Char* Entry, sal_uInt32 *pNoEntry); | |||
| 169 | static sal_Bool loadProfile(osl_TFile* pFile, osl_TProfileImpl* pProfile); | |||
| 170 | static sal_Bool storeProfile(osl_TProfileImpl* pProfile, sal_Bool bCleanup); | |||
| 171 | static osl_TProfileImpl* acquireProfile(oslProfile Profile, sal_Bool bWriteable); | |||
| 172 | static sal_Bool releaseProfile(osl_TProfileImpl* pProfile); | |||
| 173 | ||||
| 174 | static sal_Bool writeProfileImpl (osl_TFile* pFile); | |||
| 175 | static osl_TFile* osl_openTmpProfileImpl(osl_TProfileImpl*); | |||
| 176 | static sal_Bool osl_ProfileSwapProfileNames(osl_TProfileImpl*); | |||
| 177 | static void osl_ProfileGenerateExtension(sal_Char* pszFileName, sal_Char* pszExtension, sal_Char* pszTmpName); | |||
| 178 | static oslProfile SAL_CALL osl_psz_openProfile(const sal_Char *pszProfileName, oslProfileOption Flags); | |||
| 179 | ||||
| 180 | /* implemented in file.c */ | |||
| 181 | extern oslFileError FileURLToPath( char *, size_t, rtl_uString* ); | |||
| 182 | ||||
| 183 | /*****************************************************************************/ | |||
| 184 | /* Exported Module Functions */ | |||
| 185 | /*****************************************************************************/ | |||
| 186 | oslProfile SAL_CALL osl_openProfile(rtl_uString *ustrProfileName, oslProfileOption Options) | |||
| 187 | { | |||
| 188 | char profilePath[PATH_MAX4096] = ""; | |||
| 189 | ||||
| 190 | if ( ustrProfileName != 0 && ustrProfileName->buffer[0] != 0 ) | |||
| 191 | FileURLToPath( profilePath, PATH_MAX4096, ustrProfileName ); | |||
| 192 | ||||
| 193 | return osl_psz_openProfile( profilePath,Options ); | |||
| 194 | } | |||
| 195 | ||||
| 196 | ||||
| 197 | static oslProfile SAL_CALL osl_psz_openProfile(const sal_Char *pszProfileName, oslProfileOption Flags) | |||
| 198 | { | |||
| 199 | osl_TFile* pFile; | |||
| 200 | osl_TProfileImpl* pProfile; | |||
| 201 | sal_Bool bRet = sal_False((sal_Bool)0); | |||
| 202 | ||||
| 203 | #ifdef TRACE_OSL_PROFILE | |||
| 204 | OSL_TRACE("In osl_openProfile")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "204" ": "), "In osl_openProfile"); } } while (((sal_Bool )0)); | |||
| 205 | #endif | |||
| 206 | ||||
| 207 | #ifdef DEBUG_OSL_PROFILE | |||
| 208 | Flags=osl_Profile_FLUSHWRITE0x0010; | |||
| 209 | ||||
| 210 | OSL_TRACE("opening '%s'",pszProfileName)do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "210" ": "), "opening '%s'",pszProfileName); } } while ( ((sal_Bool)0)); | |||
| 211 | if ( Flags == osl_Profile_DEFAULT0x0000 ) | |||
| 212 | { | |||
| 213 | OSL_TRACE("with osl_Profile_DEFAULT")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "213" ": "), "with osl_Profile_DEFAULT"); } } while (((sal_Bool )0)); | |||
| 214 | } | |||
| 215 | if ( Flags & osl_Profile_SYSTEM0x0001 ) | |||
| 216 | { | |||
| 217 | OSL_TRACE("with osl_Profile_SYSTEM")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "217" ": "), "with osl_Profile_SYSTEM"); } } while (((sal_Bool )0)); | |||
| 218 | } | |||
| 219 | if ( Flags & osl_Profile_READLOCK0x0002 ) | |||
| 220 | { | |||
| 221 | OSL_TRACE("with osl_Profile_READLOCK")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "221" ": "), "with osl_Profile_READLOCK"); } } while ((( sal_Bool)0)); | |||
| 222 | } | |||
| 223 | if ( Flags & osl_Profile_WRITELOCK0x0004 ) | |||
| 224 | { | |||
| 225 | OSL_TRACE("with osl_Profile_WRITELOCK")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "225" ": "), "with osl_Profile_WRITELOCK"); } } while (( (sal_Bool)0)); | |||
| 226 | } | |||
| 227 | if ( Flags & osl_Profile_FLUSHWRITE0x0010 ) | |||
| 228 | { | |||
| 229 | OSL_TRACE("with osl_Profile_FLUSHWRITE")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "229" ": "), "with osl_Profile_FLUSHWRITE"); } } while ( ((sal_Bool)0)); | |||
| 230 | } | |||
| 231 | #endif | |||
| 232 | ||||
| 233 | ||||
| 234 | if ( ( pFile = openFileImpl(pszProfileName, Flags ) ) == NULL((void*)0) ) | |||
| 235 | { | |||
| 236 | #ifdef TRACE_OSL_PROFILE | |||
| 237 | OSL_TRACE("Out osl_openProfile [not opened]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "237" ": "), "Out osl_openProfile [not opened]"); } } while (((sal_Bool)0)); | |||
| 238 | #endif | |||
| 239 | return (NULL((void*)0)); | |||
| 240 | } | |||
| 241 | ||||
| 242 | ||||
| 243 | pProfile = (osl_TProfileImpl*)calloc(1, sizeof(osl_TProfileImpl)); | |||
| 244 | ||||
| 245 | if ( pProfile == 0 ) | |||
| 246 | { | |||
| 247 | closeFileImpl(pFile, Flags); | |||
| 248 | return 0; | |||
| 249 | } | |||
| 250 | ||||
| 251 | pProfile->m_Flags = Flags & FLG_USER0x00FF; | |||
| 252 | ||||
| 253 | if ( Flags & ( osl_Profile_READLOCK0x0002 | osl_Profile_WRITELOCK0x0004 | osl_Profile_FLUSHWRITE0x0010 ) ) | |||
| 254 | { | |||
| 255 | pProfile->m_pFile = pFile; | |||
| 256 | } | |||
| 257 | ||||
| 258 | pthread_mutex_init(&(pProfile->m_AccessLock),PTHREAD_MUTEXATTR_DEFAULT((void*)0)); | |||
| 259 | pProfile->m_bIsValid=sal_True((sal_Bool)1); | |||
| 260 | ||||
| 261 | pProfile->m_Stamp = OslProfile_getFileStamp(pFile); | |||
| 262 | bRet=loadProfile(pFile, pProfile); | |||
| 263 | bRet &= realpath(pszProfileName, pProfile->m_FileName) != NULL((void*)0); | |||
| 264 | OSL_ASSERT(bRet)do { if (((sal_Bool)1) && (!(bRet))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "264" ": "), "OSL_ASSERT: %s", "bRet"); } } while (((sal_Bool )0)); | |||
| 265 | ||||
| 266 | if (pProfile->m_pFile == NULL((void*)0)) | |||
| 267 | closeFileImpl(pFile,pProfile->m_Flags); | |||
| 268 | ||||
| 269 | #ifdef TRACE_OSL_PROFILE | |||
| 270 | OSL_TRACE("Out osl_openProfile [ok]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "270" ": "), "Out osl_openProfile [ok]"); } } while (((sal_Bool )0)); | |||
| 271 | #endif | |||
| 272 | return (pProfile); | |||
| 273 | } | |||
| 274 | ||||
| 275 | sal_Bool SAL_CALL osl_closeProfile(oslProfile Profile) | |||
| 276 | { | |||
| 277 | osl_TProfileImpl* pProfile = (osl_TProfileImpl*)Profile; | |||
| 278 | osl_TProfileImpl* pTmpProfile; | |||
| 279 | ||||
| 280 | #ifdef TRACE_OSL_PROFILE | |||
| 281 | OSL_TRACE("In osl_closeProfile")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "281" ": "), "In osl_closeProfile"); } } while (((sal_Bool )0)); | |||
| 282 | #endif | |||
| 283 | ||||
| 284 | if ( Profile == 0 ) | |||
| 285 | { | |||
| 286 | #ifdef TRACE_OSL_PROFILE | |||
| 287 | OSL_TRACE("Out osl_closeProfile [profile==0]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "287" ": "), "Out osl_closeProfile [profile==0]"); } } while (((sal_Bool)0)); | |||
| 288 | #endif | |||
| 289 | return sal_False((sal_Bool)0); | |||
| 290 | } | |||
| 291 | ||||
| 292 | pthread_mutex_lock(&(pProfile->m_AccessLock)); | |||
| 293 | ||||
| 294 | if ( pProfile->m_bIsValid == sal_False((sal_Bool)0) ) | |||
| 295 | { | |||
| 296 | OSL_ASSERT(pProfile->m_bIsValid)do { if (((sal_Bool)1) && (!(pProfile->m_bIsValid) )) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "296" ": "), "OSL_ASSERT: %s", "pProfile->m_bIsValid"); } } while (((sal_Bool)0)); | |||
| 297 | pthread_mutex_unlock(&(pProfile->m_AccessLock)); | |||
| 298 | #ifdef TRACE_OSL_PROFILE | |||
| 299 | OSL_TRACE("Out osl_closeProfile [not valid]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "299" ": "), "Out osl_closeProfile [not valid]"); } } while (((sal_Bool)0)); | |||
| 300 | #endif | |||
| 301 | return sal_False((sal_Bool)0); | |||
| 302 | } | |||
| 303 | ||||
| 304 | pProfile->m_bIsValid=sal_False((sal_Bool)0); | |||
| 305 | ||||
| 306 | if ( ! ( pProfile->m_Flags & osl_Profile_READLOCK0x0002 ) && ( pProfile->m_Flags & FLG_MODIFIED0x0200 ) ) | |||
| 307 | { | |||
| 308 | pTmpProfile = acquireProfile(Profile,sal_True((sal_Bool)1)); | |||
| 309 | ||||
| 310 | if ( pTmpProfile != 0 ) | |||
| 311 | { | |||
| 312 | sal_Bool bRet = storeProfile(pTmpProfile, sal_True((sal_Bool)1)); | |||
| 313 | OSL_ASSERT(bRet)do { if (((sal_Bool)1) && (!(bRet))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "313" ": "), "OSL_ASSERT: %s", "bRet"); } } while (((sal_Bool )0)); | |||
| 314 | (void)bRet; | |||
| 315 | } | |||
| 316 | } | |||
| 317 | else | |||
| 318 | { | |||
| 319 | pTmpProfile = acquireProfile(Profile,sal_False((sal_Bool)0)); | |||
| 320 | } | |||
| 321 | ||||
| 322 | ||||
| 323 | if ( pTmpProfile == 0 ) | |||
| 324 | { | |||
| 325 | pthread_mutex_unlock(&(pProfile->m_AccessLock)); | |||
| 326 | #ifdef TRACE_OSL_PROFILE | |||
| 327 | OSL_TRACE("Out osl_closeProfile [pProfile==0]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "327" ": "), "Out osl_closeProfile [pProfile==0]"); } } while (((sal_Bool)0)); | |||
| 328 | #endif | |||
| 329 | return sal_False((sal_Bool)0); | |||
| 330 | } | |||
| 331 | ||||
| 332 | pProfile = pTmpProfile; | |||
| 333 | ||||
| 334 | if (pProfile->m_pFile != NULL((void*)0)) | |||
| 335 | closeFileImpl(pProfile->m_pFile,pProfile->m_Flags); | |||
| 336 | ||||
| 337 | pProfile->m_pFile = NULL((void*)0); | |||
| 338 | pProfile->m_FileName[0] = '\0'; | |||
| 339 | ||||
| 340 | /* release whole profile data types memory */ | |||
| 341 | if ( pProfile->m_NoLines > 0) | |||
| 342 | { | |||
| 343 | unsigned int idx=0; | |||
| 344 | if ( pProfile->m_Lines != 0 ) | |||
| 345 | { | |||
| 346 | for ( idx = 0 ; idx < pProfile->m_NoLines ; ++idx) | |||
| 347 | { | |||
| 348 | if ( pProfile->m_Lines[idx] != 0 ) | |||
| 349 | { | |||
| 350 | free(pProfile->m_Lines[idx]); | |||
| 351 | pProfile->m_Lines[idx]=0; | |||
| 352 | } | |||
| 353 | } | |||
| 354 | free(pProfile->m_Lines); | |||
| 355 | pProfile->m_Lines=0; | |||
| 356 | } | |||
| 357 | if ( pProfile->m_Sections != 0 ) | |||
| 358 | { | |||
| 359 | /*osl_TProfileSection* pSections=pProfile->m_Sections;*/ | |||
| 360 | for ( idx = 0 ; idx < pProfile->m_NoSections ; ++idx ) | |||
| 361 | { | |||
| 362 | if ( pProfile->m_Sections[idx].m_Entries != 0 ) | |||
| 363 | { | |||
| 364 | free(pProfile->m_Sections[idx].m_Entries); | |||
| 365 | pProfile->m_Sections[idx].m_Entries=0; | |||
| 366 | } | |||
| 367 | } | |||
| 368 | free(pProfile->m_Sections); | |||
| 369 | pProfile->m_Sections=0; | |||
| 370 | } | |||
| 371 | } | |||
| 372 | ||||
| 373 | pthread_mutex_unlock(&(pProfile->m_AccessLock)); | |||
| 374 | ||||
| 375 | pthread_mutex_destroy(&(pProfile->m_AccessLock)); | |||
| 376 | ||||
| 377 | free(pProfile); | |||
| 378 | ||||
| 379 | #ifdef TRACE_OSL_PROFILE | |||
| 380 | OSL_TRACE("Out osl_closeProfile [ok]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "380" ": "), "Out osl_closeProfile [ok]"); } } while ((( sal_Bool)0)); | |||
| 381 | #endif | |||
| 382 | return (sal_True((sal_Bool)1)); | |||
| 383 | } | |||
| 384 | ||||
| 385 | ||||
| 386 | sal_Bool SAL_CALL osl_flushProfile(oslProfile Profile) | |||
| 387 | { | |||
| 388 | osl_TProfileImpl* pProfile = (osl_TProfileImpl*) Profile; | |||
| 389 | osl_TFile* pFile; | |||
| 390 | sal_Bool bRet = sal_False((sal_Bool)0); | |||
| 391 | ||||
| 392 | #ifdef TRACE_OSL_PROFILE | |||
| 393 | OSL_TRACE("In osl_flushProfile()")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "393" ": "), "In osl_flushProfile()"); } } while (((sal_Bool )0)); | |||
| 394 | #endif | |||
| 395 | ||||
| 396 | if ( pProfile == 0 ) | |||
| 397 | { | |||
| 398 | #ifdef TRACE_OSL_PROFILE | |||
| 399 | OSL_TRACE("Out osl_flushProfile() [pProfile == 0]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "399" ": "), "Out osl_flushProfile() [pProfile == 0]"); } } while (((sal_Bool)0)); | |||
| 400 | #endif | |||
| 401 | return sal_False((sal_Bool)0); | |||
| 402 | } | |||
| 403 | ||||
| 404 | pthread_mutex_lock(&(pProfile->m_AccessLock)); | |||
| 405 | ||||
| 406 | if ( pProfile->m_bIsValid == sal_False((sal_Bool)0) ) | |||
| 407 | { | |||
| 408 | OSL_ASSERT(pProfile->m_bIsValid)do { if (((sal_Bool)1) && (!(pProfile->m_bIsValid) )) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "408" ": "), "OSL_ASSERT: %s", "pProfile->m_bIsValid"); } } while (((sal_Bool)0)); | |||
| 409 | pthread_mutex_unlock(&(pProfile->m_AccessLock)); | |||
| 410 | #ifdef TRACE_OSL_PROFILE | |||
| 411 | OSL_TRACE("Out osl_flushProfile [not valid]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "411" ": "), "Out osl_flushProfile [not valid]"); } } while (((sal_Bool)0)); | |||
| 412 | #endif | |||
| 413 | return sal_False((sal_Bool)0); | |||
| 414 | } | |||
| 415 | ||||
| 416 | pFile = pProfile->m_pFile; | |||
| 417 | if ( !( pFile != 0 && pFile->m_Handle >= 0 ) ) | |||
| 418 | { | |||
| 419 | pthread_mutex_unlock(&(pProfile->m_AccessLock)); | |||
| 420 | #ifdef TRACE_OSL_PROFILE | |||
| 421 | OSL_TRACE("Out osl_flushProfile() [invalid file]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "421" ": "), "Out osl_flushProfile() [invalid file]"); } } while (((sal_Bool)0)); | |||
| 422 | #endif | |||
| 423 | return sal_False((sal_Bool)0); | |||
| 424 | } | |||
| 425 | ||||
| 426 | if ( pProfile->m_Flags & FLG_MODIFIED0x0200 ) | |||
| 427 | { | |||
| 428 | #ifdef DEBUG_OSL_PROFILE | |||
| 429 | OSL_TRACE("swapping to storeprofile")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "429" ": "), "swapping to storeprofile"); } } while (((sal_Bool )0)); | |||
| 430 | #endif | |||
| 431 | bRet = storeProfile(pProfile,sal_False((sal_Bool)0)); | |||
| 432 | OSL_ASSERT(bRet)do { if (((sal_Bool)1) && (!(bRet))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "432" ": "), "OSL_ASSERT: %s", "bRet"); } } while (((sal_Bool )0)); | |||
| 433 | } | |||
| 434 | ||||
| 435 | #ifdef TRACE_OSL_PROFILE | |||
| 436 | OSL_TRACE("Out osl_flushProfile() [ok]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "436" ": "), "Out osl_flushProfile() [ok]"); } } while ( ((sal_Bool)0)); | |||
| 437 | #endif | |||
| 438 | pthread_mutex_unlock(&(pProfile->m_AccessLock)); | |||
| 439 | return bRet; | |||
| 440 | } | |||
| 441 | ||||
| 442 | static sal_Bool writeProfileImpl(osl_TFile* pFile) | |||
| 443 | { | |||
| 444 | #if OSL_DEBUG_LEVEL1 > 1 | |||
| 445 | unsigned int nLen=0; | |||
| 446 | #endif | |||
| 447 | ||||
| 448 | #ifdef TRACE_OSL_PROFILE | |||
| 449 | OSL_TRACE("In osl_writeProfileImpl()")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "449" ": "), "In osl_writeProfileImpl()"); } } while (( (sal_Bool)0)); | |||
| 450 | #endif | |||
| 451 | ||||
| 452 | if ( !( pFile != 0 && pFile->m_Handle >= 0 ) || ( pFile->m_pWriteBuf == 0 ) ) | |||
| 453 | { | |||
| 454 | #ifdef TRACE_OSL_PROFILE | |||
| 455 | OSL_TRACE("Out osl_writeProfileImpl() [invalid args]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "455" ": "), "Out osl_writeProfileImpl() [invalid args]" ); } } while (((sal_Bool)0)); | |||
| 456 | #endif | |||
| 457 | return sal_False((sal_Bool)0); | |||
| 458 | } | |||
| 459 | ||||
| 460 | #if OSL_DEBUG_LEVEL1 > 1 | |||
| 461 | nLen=strlen(pFile->m_pWriteBuf); | |||
| 462 | OSL_ASSERT(nLen == (pFile->m_nWriteBufLen - pFile->m_nWriteBufFree))do { if (((sal_Bool)1) && (!(nLen == (pFile->m_nWriteBufLen - pFile->m_nWriteBufFree)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "462" ": "), "OSL_ASSERT: %s", "nLen == (pFile->m_nWriteBufLen - pFile->m_nWriteBufFree)" ); } } while (((sal_Bool)0)); | |||
| 463 | #endif | |||
| 464 | ||||
| 465 | if ( !safeWrite(pFile->m_Handle, pFile->m_pWriteBuf, pFile->m_nWriteBufLen - pFile->m_nWriteBufFree) ) | |||
| 466 | { | |||
| 467 | OSL_TRACE("write failed '%s'",strerror(errno))do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "467" ": "), "write failed '%s'",strerror((*__errno_location ()))); } } while (((sal_Bool)0)); | |||
| 468 | return (sal_False((sal_Bool)0)); | |||
| 469 | } | |||
| 470 | ||||
| 471 | free(pFile->m_pWriteBuf); | |||
| 472 | pFile->m_pWriteBuf=0; | |||
| 473 | pFile->m_nWriteBufLen=0; | |||
| 474 | pFile->m_nWriteBufFree=0; | |||
| 475 | #ifdef TRACE_OSL_PROFILE | |||
| 476 | OSL_TRACE("Out osl_writeProfileImpl() [ok]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "476" ": "), "Out osl_writeProfileImpl() [ok]"); } } while (((sal_Bool)0)); | |||
| 477 | #endif | |||
| 478 | return sal_True((sal_Bool)1); | |||
| 479 | } | |||
| 480 | ||||
| 481 | ||||
| 482 | sal_Bool SAL_CALL osl_readProfileString(oslProfile Profile, | |||
| 483 | const sal_Char* pszSection, const sal_Char* pszEntry, | |||
| 484 | sal_Char* pszString, sal_uInt32 MaxLen, | |||
| 485 | const sal_Char* pszDefault) | |||
| 486 | { | |||
| 487 | sal_uInt32 NoEntry; | |||
| 488 | sal_Char* pStr=0; | |||
| 489 | osl_TProfileSection* pSec; | |||
| 490 | osl_TProfileImpl* pProfile=0; | |||
| 491 | osl_TProfileImpl* pTmpProfile=0; | |||
| 492 | sal_Bool bRet = sal_False((sal_Bool)0); | |||
| 493 | ||||
| 494 | #ifdef TRACE_OSL_PROFILE | |||
| 495 | OSL_TRACE("In osl_readProfileString")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "495" ": "), "In osl_readProfileString"); } } while ((( sal_Bool)0)); | |||
| 496 | #endif | |||
| 497 | ||||
| 498 | pTmpProfile = (osl_TProfileImpl*) Profile; | |||
| 499 | ||||
| 500 | if ( pTmpProfile == 0 ) | |||
| 501 | { | |||
| 502 | #ifdef TRACE_OSL_PROFILE | |||
| 503 | OSL_TRACE("Out osl_readProfileString [pTmpProfile==0]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "503" ": "), "Out osl_readProfileString [pTmpProfile==0]" ); } } while (((sal_Bool)0)); | |||
| 504 | #endif | |||
| 505 | return sal_False((sal_Bool)0); | |||
| 506 | } | |||
| 507 | ||||
| 508 | pthread_mutex_lock(&(pTmpProfile->m_AccessLock)); | |||
| 509 | ||||
| 510 | if ( pTmpProfile->m_bIsValid == sal_False((sal_Bool)0) ) | |||
| 511 | { | |||
| 512 | pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); | |||
| 513 | #ifdef TRACE_OSL_PROFILE | |||
| 514 | OSL_TRACE("Out osl_readProfileString [not valid]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "514" ": "), "Out osl_readProfileString [not valid]"); } } while (((sal_Bool)0)); | |||
| 515 | #endif | |||
| 516 | return sal_False((sal_Bool)0); | |||
| 517 | } | |||
| 518 | ||||
| 519 | pProfile = acquireProfile(Profile, sal_False((sal_Bool)0)); | |||
| 520 | ||||
| 521 | if ( pProfile == NULL((void*)0) ) | |||
| 522 | { | |||
| 523 | #ifdef TRACE_OSL_PROFILE | |||
| 524 | OSL_TRACE("Out osl_readProfileString [pProfile==0]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "524" ": "), "Out osl_readProfileString [pProfile==0]"); } } while (((sal_Bool)0)); | |||
| 525 | #endif | |||
| 526 | return (sal_False((sal_Bool)0)); | |||
| 527 | } | |||
| 528 | ||||
| 529 | if (! (pProfile->m_Flags & osl_Profile_SYSTEM0x0001)) | |||
| 530 | { | |||
| 531 | if (((pSec = findEntry(pProfile, pszSection, pszEntry, &NoEntry)) != NULL((void*)0)) && | |||
| 532 | (NoEntry < pSec->m_NoEntries) && | |||
| 533 | ((pStr = strchr(pProfile->m_Lines[pSec->m_Entries[NoEntry].m_Line], | |||
| 534 | '=')) != NULL((void*)0))) | |||
| 535 | { | |||
| 536 | pStr++; | |||
| 537 | } | |||
| 538 | else | |||
| 539 | { | |||
| 540 | pStr=(sal_Char*)pszDefault; | |||
| 541 | } | |||
| 542 | ||||
| 543 | if ( pStr != 0 ) | |||
| 544 | { | |||
| 545 | pStr = stripBlanks(pStr, NULL((void*)0)); | |||
| 546 | MaxLen = (MaxLen - 1 < strlen(pStr)) ? (MaxLen - 1) : strlen(pStr); | |||
| 547 | pStr = stripBlanks(pStr, &MaxLen); | |||
| 548 | strncpy(pszString, pStr, MaxLen); | |||
| 549 | pszString[MaxLen] = '\0'; | |||
| 550 | } | |||
| 551 | } | |||
| 552 | else | |||
| 553 | { /* not implemented */ } | |||
| 554 | ||||
| 555 | ||||
| 556 | bRet=releaseProfile(pProfile); | |||
| 557 | OSL_ASSERT(bRet)do { if (((sal_Bool)1) && (!(bRet))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "557" ": "), "OSL_ASSERT: %s", "bRet"); } } while (((sal_Bool )0)); | |||
| 558 | (void)bRet; | |||
| 559 | ||||
| 560 | if ( pStr == 0 ) | |||
| 561 | { | |||
| 562 | pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); | |||
| 563 | #ifdef TRACE_OSL_PROFILE | |||
| 564 | OSL_TRACE("Out osl_readProfileString [pStr==0]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "564" ": "), "Out osl_readProfileString [pStr==0]"); } } while (((sal_Bool)0)); | |||
| 565 | #endif | |||
| 566 | return sal_False((sal_Bool)0); | |||
| 567 | } | |||
| 568 | ||||
| 569 | pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); | |||
| 570 | ||||
| 571 | #ifdef TRACE_OSL_PROFILE | |||
| 572 | OSL_TRACE("Out osl_readProfileString [ok]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "572" ": "), "Out osl_readProfileString [ok]"); } } while (((sal_Bool)0)); | |||
| 573 | #endif | |||
| 574 | ||||
| 575 | return (sal_True((sal_Bool)1)); | |||
| 576 | } | |||
| 577 | ||||
| 578 | ||||
| 579 | sal_Bool SAL_CALL osl_readProfileBool(oslProfile Profile, | |||
| 580 | const sal_Char* pszSection, const sal_Char* pszEntry, | |||
| 581 | sal_Bool Default) | |||
| 582 | { | |||
| 583 | sal_Char Line[32]; | |||
| 584 | Line[0] = '\0'; | |||
| 585 | ||||
| 586 | #ifdef TRACE_OSL_PROFILE | |||
| 587 | OSL_TRACE("In osl_readProfileBool")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "587" ": "), "In osl_readProfileBool"); } } while (((sal_Bool )0)); | |||
| 588 | #endif | |||
| 589 | ||||
| 590 | if (osl_readProfileString(Profile, pszSection, pszEntry, Line, sizeof(Line), "")) | |||
| 591 | { | |||
| 592 | if ((strcasecmp(Line, STR_INI_BOOLYES"yes") == 0) || | |||
| 593 | (strcasecmp(Line, STR_INI_BOOLON"on") == 0) || | |||
| 594 | (strcasecmp(Line, STR_INI_BOOLONE"1") == 0)) | |||
| 595 | Default = sal_True((sal_Bool)1); | |||
| 596 | else | |||
| 597 | if ((strcasecmp(Line, STR_INI_BOOLNO"no") == 0) || | |||
| 598 | (strcasecmp(Line, STR_INI_BOOLOFF"off") == 0) || | |||
| 599 | (strcasecmp(Line, STR_INI_BOOLZERO"0") == 0)) | |||
| 600 | Default = sal_False((sal_Bool)0); | |||
| 601 | } | |||
| 602 | ||||
| 603 | #ifdef TRACE_OSL_PROFILE | |||
| 604 | OSL_TRACE("Out osl_readProfileBool [ok]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "604" ": "), "Out osl_readProfileBool [ok]"); } } while ( ((sal_Bool)0)); | |||
| 605 | #endif | |||
| 606 | ||||
| 607 | return (Default); | |||
| 608 | } | |||
| 609 | ||||
| 610 | ||||
| 611 | sal_uInt32 SAL_CALL osl_readProfileIdent(oslProfile Profile, | |||
| 612 | const sal_Char* pszSection, const sal_Char* pszEntry, | |||
| 613 | sal_uInt32 FirstId, const sal_Char* Strings[], | |||
| 614 | sal_uInt32 Default) | |||
| 615 | { | |||
| 616 | sal_uInt32 i; | |||
| 617 | sal_Char Line[256]; | |||
| 618 | Line[0] = '\0'; | |||
| 619 | ||||
| 620 | #ifdef TRACE_OSL_PROFILE | |||
| 621 | OSL_TRACE("In osl_readProfileIdent")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "621" ": "), "In osl_readProfileIdent"); } } while (((sal_Bool )0)); | |||
| 622 | #endif | |||
| 623 | ||||
| 624 | if (osl_readProfileString(Profile, pszSection, pszEntry, Line, sizeof(Line), "")) | |||
| ||||
| 625 | { | |||
| 626 | i = 0; | |||
| 627 | while (Strings[i] != NULL((void*)0)) | |||
| 628 | { | |||
| 629 | if (strcasecmp(Line, Strings[i]) == 0) | |||
| 630 | { | |||
| 631 | Default = i + FirstId; | |||
| 632 | break; | |||
| 633 | } | |||
| 634 | i++; | |||
| 635 | } | |||
| 636 | } | |||
| 637 | ||||
| 638 | #ifdef TRACE_OSL_PROFILE | |||
| 639 | OSL_TRACE("Out osl_readProfileIdent [ok]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "639" ": "), "Out osl_readProfileIdent [ok]"); } } while (((sal_Bool)0)); | |||
| 640 | #endif | |||
| 641 | return (Default); | |||
| 642 | } | |||
| 643 | ||||
| 644 | sal_Bool SAL_CALL osl_writeProfileString(oslProfile Profile, | |||
| 645 | const sal_Char* pszSection, const sal_Char* pszEntry, | |||
| 646 | const sal_Char* pszString) | |||
| 647 | { | |||
| 648 | sal_uInt32 i; | |||
| 649 | sal_Bool bRet = sal_False((sal_Bool)0); | |||
| 650 | sal_uInt32 NoEntry; | |||
| 651 | sal_Char* pStr; | |||
| 652 | sal_Char* Line = 0; | |||
| 653 | osl_TProfileSection* pSec; | |||
| 654 | osl_TProfileImpl* pProfile = 0; | |||
| 655 | osl_TProfileImpl* pTmpProfile = 0; | |||
| 656 | ||||
| 657 | #ifdef TRACE_OSL_PROFILE | |||
| 658 | OSL_TRACE("In osl_writeProfileString")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "658" ": "), "In osl_writeProfileString"); } } while (( (sal_Bool)0)); | |||
| 659 | #endif | |||
| 660 | ||||
| 661 | pTmpProfile = (osl_TProfileImpl*) Profile; | |||
| 662 | ||||
| 663 | if ( pTmpProfile == 0 ) | |||
| 664 | { | |||
| 665 | #ifdef TRACE_OSL_PROFILE | |||
| 666 | OSL_TRACE("Out osl_writeProfileString [pTmpProfile==0]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "666" ": "), "Out osl_writeProfileString [pTmpProfile==0]" ); } } while (((sal_Bool)0)); | |||
| 667 | #endif | |||
| 668 | return sal_False((sal_Bool)0); | |||
| 669 | } | |||
| 670 | ||||
| 671 | pthread_mutex_lock(&(pTmpProfile->m_AccessLock)); | |||
| 672 | ||||
| 673 | if ( pTmpProfile->m_bIsValid == sal_False((sal_Bool)0) ) | |||
| 674 | { | |||
| 675 | OSL_ASSERT(pTmpProfile->m_bIsValid)do { if (((sal_Bool)1) && (!(pTmpProfile->m_bIsValid ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "675" ": "), "OSL_ASSERT: %s", "pTmpProfile->m_bIsValid"); } } while (((sal_Bool)0)); | |||
| 676 | pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); | |||
| 677 | #ifdef TRACE_OSL_PROFILE | |||
| 678 | OSL_TRACE("Out osl_writeProfileString [not valid]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "678" ": "), "Out osl_writeProfileString [not valid]"); } } while (((sal_Bool)0)); | |||
| 679 | #endif | |||
| 680 | return sal_False((sal_Bool)0); | |||
| 681 | } | |||
| 682 | ||||
| 683 | pProfile=acquireProfile(Profile, sal_True((sal_Bool)1)); | |||
| 684 | ||||
| 685 | if (pProfile == NULL((void*)0)) | |||
| 686 | { | |||
| 687 | pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); | |||
| 688 | #ifdef TRACE_OSL_PROFILE | |||
| 689 | OSL_TRACE("Out osl_writeProfileString [pProfile==0]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "689" ": "), "Out osl_writeProfileString [pProfile==0]") ; } } while (((sal_Bool)0)); | |||
| 690 | #endif | |||
| 691 | return (sal_False((sal_Bool)0)); | |||
| 692 | } | |||
| 693 | ||||
| 694 | Line = (sal_Char*) malloc(strlen(pszEntry)+strlen(pszString)+48); | |||
| 695 | ||||
| 696 | if (! (pProfile->m_Flags & osl_Profile_SYSTEM0x0001)) | |||
| 697 | { | |||
| 698 | if ((pSec = findEntry(pProfile, pszSection, pszEntry, &NoEntry)) == NULL((void*)0)) | |||
| 699 | { | |||
| 700 | Line[0] = '\0'; | |||
| 701 | addLine(pProfile, Line); | |||
| 702 | ||||
| 703 | Line[0] = '['; | |||
| 704 | strcpy(&Line[1], pszSection); | |||
| 705 | Line[1 + strlen(pszSection)] = ']'; | |||
| 706 | Line[2 + strlen(pszSection)] = '\0'; | |||
| 707 | ||||
| 708 | if (((pStr = addLine(pProfile, Line)) == NULL((void*)0)) || | |||
| 709 | (! addSection(pProfile, pProfile->m_NoLines - 1, &pStr[1], strlen(pszSection)))) | |||
| 710 | { | |||
| 711 | bRet=releaseProfile(pProfile); | |||
| 712 | OSL_ASSERT(bRet)do { if (((sal_Bool)1) && (!(bRet))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "712" ": "), "OSL_ASSERT: %s", "bRet"); } } while (((sal_Bool )0)); | |||
| 713 | ||||
| 714 | pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); | |||
| 715 | ||||
| 716 | free(Line); | |||
| 717 | ||||
| 718 | #ifdef TRACE_OSL_PROFILE | |||
| 719 | OSL_TRACE("Out osl_writeProfileString [not added]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "719" ": "), "Out osl_writeProfileString [not added]"); } } while (((sal_Bool)0)); | |||
| 720 | #endif | |||
| 721 | return (sal_False((sal_Bool)0)); | |||
| 722 | } | |||
| 723 | ||||
| 724 | pSec = &pProfile->m_Sections[pProfile->m_NoSections - 1]; | |||
| 725 | NoEntry = pSec->m_NoEntries; | |||
| 726 | } | |||
| 727 | ||||
| 728 | Line[0] = '\0'; | |||
| 729 | strcpy(&Line[0], pszEntry); | |||
| 730 | Line[0 + strlen(pszEntry)] = '='; | |||
| 731 | strcpy(&Line[1 + strlen(pszEntry)], pszString); | |||
| 732 | ||||
| 733 | if (NoEntry >= pSec->m_NoEntries) | |||
| 734 | { | |||
| 735 | if (pSec->m_NoEntries > 0) | |||
| 736 | i = pSec->m_Entries[pSec->m_NoEntries - 1].m_Line + 1; | |||
| 737 | else | |||
| 738 | i = pSec->m_Line + 1; | |||
| 739 | ||||
| 740 | if (((pStr = insertLine(pProfile, Line, i)) == NULL((void*)0)) || | |||
| 741 | (! addEntry(pProfile, pSec, i, pStr, strlen(pszEntry)))) | |||
| 742 | { | |||
| 743 | bRet=releaseProfile(pProfile); | |||
| 744 | OSL_ASSERT(bRet)do { if (((sal_Bool)1) && (!(bRet))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "744" ": "), "OSL_ASSERT: %s", "bRet"); } } while (((sal_Bool )0)); | |||
| 745 | ||||
| 746 | pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); | |||
| 747 | free(Line); | |||
| 748 | ||||
| 749 | #ifdef TRACE_OSL_PROFILE | |||
| 750 | OSL_TRACE("Out osl_writeProfileString [not inserted]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "750" ": "), "Out osl_writeProfileString [not inserted]" ); } } while (((sal_Bool)0)); | |||
| 751 | #endif | |||
| 752 | return (sal_False((sal_Bool)0)); | |||
| 753 | } | |||
| 754 | ||||
| 755 | pProfile->m_Flags |= FLG_MODIFIED0x0200; | |||
| 756 | } | |||
| 757 | else | |||
| 758 | { | |||
| 759 | i = pSec->m_Entries[NoEntry].m_Line; | |||
| 760 | free(pProfile->m_Lines[i]); | |||
| 761 | pProfile->m_Lines[i] = strdup(Line); | |||
| 762 | setEntry(pProfile, pSec, NoEntry, i, pProfile->m_Lines[i], strlen(pszEntry)); | |||
| 763 | ||||
| 764 | pProfile->m_Flags |= FLG_MODIFIED0x0200; | |||
| 765 | } | |||
| 766 | } | |||
| 767 | else { | |||
| 768 | /* not implemented */ | |||
| 769 | } | |||
| 770 | ||||
| 771 | bRet = releaseProfile(pProfile); | |||
| 772 | OSL_ASSERT(bRet)do { if (((sal_Bool)1) && (!(bRet))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "772" ": "), "OSL_ASSERT: %s", "bRet"); } } while (((sal_Bool )0)); | |||
| 773 | ||||
| 774 | pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); | |||
| 775 | if ( Line!= 0 ) | |||
| 776 | { | |||
| 777 | free(Line); | |||
| 778 | } | |||
| 779 | ||||
| 780 | #ifdef TRACE_OSL_PROFILE | |||
| 781 | OSL_TRACE("Out osl_writeProfileString [ok]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "781" ": "), "Out osl_writeProfileString [ok]"); } } while (((sal_Bool)0)); | |||
| 782 | #endif | |||
| 783 | ||||
| 784 | return bRet; | |||
| 785 | } | |||
| 786 | ||||
| 787 | ||||
| 788 | sal_Bool SAL_CALL osl_writeProfileBool(oslProfile Profile, | |||
| 789 | const sal_Char* pszSection, const sal_Char* pszEntry, | |||
| 790 | sal_Bool Value) | |||
| 791 | { | |||
| 792 | sal_Bool bRet=sal_False((sal_Bool)0); | |||
| 793 | ||||
| 794 | #ifdef TRACE_OSL_PROFILE | |||
| 795 | OSL_TRACE("In osl_writeProfileBool")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "795" ": "), "In osl_writeProfileBool"); } } while (((sal_Bool )0)); | |||
| 796 | #endif | |||
| 797 | ||||
| 798 | if (Value) | |||
| 799 | bRet=osl_writeProfileString(Profile, pszSection, pszEntry, STR_INI_BOOLONE"1"); | |||
| 800 | else | |||
| 801 | bRet=osl_writeProfileString(Profile, pszSection, pszEntry, STR_INI_BOOLZERO"0"); | |||
| 802 | ||||
| 803 | #ifdef TRACE_OSL_PROFILE | |||
| 804 | OSL_TRACE("Out osl_writeProfileBool [ok]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "804" ": "), "Out osl_writeProfileBool [ok]"); } } while (((sal_Bool)0)); | |||
| 805 | #endif | |||
| 806 | ||||
| 807 | return bRet; | |||
| 808 | } | |||
| 809 | ||||
| 810 | ||||
| 811 | sal_Bool SAL_CALL osl_writeProfileIdent(oslProfile Profile, | |||
| 812 | const sal_Char* pszSection, const sal_Char* pszEntry, | |||
| 813 | sal_uInt32 FirstId, const sal_Char* Strings[], | |||
| 814 | sal_uInt32 Value) | |||
| 815 | { | |||
| 816 | int i, n; | |||
| 817 | sal_Bool bRet=sal_False((sal_Bool)0); | |||
| 818 | ||||
| 819 | #ifdef TRACE_OSL_PROFILE | |||
| 820 | OSL_TRACE("In osl_writeProfileIdent")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "820" ": "), "In osl_writeProfileIdent"); } } while ((( sal_Bool)0)); | |||
| 821 | #endif | |||
| 822 | ||||
| 823 | for (n = 0; Strings[n] != NULL((void*)0); n++); | |||
| 824 | ||||
| 825 | if ((i = Value - FirstId) >= n) | |||
| 826 | bRet=sal_False((sal_Bool)0); | |||
| 827 | else | |||
| 828 | bRet = osl_writeProfileString(Profile, pszSection, pszEntry, Strings[i]); | |||
| 829 | ||||
| 830 | #ifdef TRACE_OSL_PROFILE | |||
| 831 | OSL_TRACE("Out osl_writeProfileIdent")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "831" ": "), "Out osl_writeProfileIdent"); } } while ((( sal_Bool)0)); | |||
| 832 | #endif | |||
| 833 | return bRet; | |||
| 834 | } | |||
| 835 | ||||
| 836 | ||||
| 837 | sal_Bool SAL_CALL osl_removeProfileEntry(oslProfile Profile, | |||
| 838 | const sal_Char *pszSection, const sal_Char *pszEntry) | |||
| 839 | { | |||
| 840 | sal_uInt32 NoEntry; | |||
| 841 | osl_TProfileSection* pSec; | |||
| 842 | osl_TProfileImpl* pProfile = 0; | |||
| 843 | osl_TProfileImpl* pTmpProfile = 0; | |||
| 844 | sal_Bool bRet = sal_False((sal_Bool)0); | |||
| 845 | ||||
| 846 | #ifdef TRACE_OSL_PROFILE | |||
| 847 | OSL_TRACE("In osl_removeProfileEntry")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "847" ": "), "In osl_removeProfileEntry"); } } while (( (sal_Bool)0)); | |||
| 848 | #endif | |||
| 849 | ||||
| 850 | pTmpProfile = (osl_TProfileImpl*) Profile; | |||
| 851 | ||||
| 852 | if ( pTmpProfile == 0 ) | |||
| 853 | { | |||
| 854 | #ifdef TRACE_OSL_PROFILE | |||
| 855 | OSL_TRACE("Out osl_removeProfileEntry [pProfile==0]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "855" ": "), "Out osl_removeProfileEntry [pProfile==0]") ; } } while (((sal_Bool)0)); | |||
| 856 | #endif | |||
| 857 | return sal_False((sal_Bool)0); | |||
| 858 | } | |||
| 859 | ||||
| 860 | pthread_mutex_lock(&(pTmpProfile->m_AccessLock)); | |||
| 861 | ||||
| 862 | if ( pTmpProfile->m_bIsValid == sal_False((sal_Bool)0) ) | |||
| 863 | { | |||
| 864 | OSL_ASSERT(pTmpProfile->m_bIsValid)do { if (((sal_Bool)1) && (!(pTmpProfile->m_bIsValid ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "864" ": "), "OSL_ASSERT: %s", "pTmpProfile->m_bIsValid"); } } while (((sal_Bool)0)); | |||
| 865 | pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); | |||
| 866 | #ifdef TRACE_OSL_PROFILE | |||
| 867 | OSL_TRACE("Out osl_removeProfileEntry [not valid]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "867" ": "), "Out osl_removeProfileEntry [not valid]"); } } while (((sal_Bool)0)); | |||
| 868 | #endif | |||
| 869 | return sal_False((sal_Bool)0); | |||
| 870 | } | |||
| 871 | ||||
| 872 | ||||
| 873 | pProfile = acquireProfile(Profile, sal_True((sal_Bool)1)); | |||
| 874 | ||||
| 875 | if (pProfile == NULL((void*)0)) | |||
| 876 | { | |||
| 877 | pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); | |||
| 878 | #ifdef TRACE_OSL_PROFILE | |||
| 879 | OSL_TRACE("Out osl_removeProfileEntry [pProfile==0]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "879" ": "), "Out osl_removeProfileEntry [pProfile==0]") ; } } while (((sal_Bool)0)); | |||
| 880 | #endif | |||
| 881 | return (sal_False((sal_Bool)0)); | |||
| 882 | } | |||
| 883 | ||||
| 884 | ||||
| 885 | if (! (pProfile->m_Flags & osl_Profile_SYSTEM0x0001)) | |||
| 886 | { | |||
| 887 | if (((pSec = findEntry(pProfile, pszSection, pszEntry, &NoEntry)) != NULL((void*)0)) && | |||
| 888 | (NoEntry < pSec->m_NoEntries)) | |||
| 889 | { | |||
| 890 | removeLine(pProfile, pSec->m_Entries[NoEntry].m_Line); | |||
| 891 | removeEntry(pSec, NoEntry); | |||
| 892 | if (pSec->m_NoEntries == 0) | |||
| 893 | { | |||
| 894 | removeLine(pProfile, pSec->m_Line); | |||
| 895 | ||||
| 896 | /* remove any empty separation line */ | |||
| 897 | if ((pSec->m_Line > 0) && (pProfile->m_Lines[pSec->m_Line - 1][0] == '\0')) | |||
| 898 | removeLine(pProfile, pSec->m_Line - 1); | |||
| 899 | ||||
| 900 | removeSection(pProfile, pSec); | |||
| 901 | } | |||
| 902 | ||||
| 903 | pProfile->m_Flags |= FLG_MODIFIED0x0200; | |||
| 904 | } | |||
| 905 | } | |||
| 906 | else | |||
| 907 | { /* not implemented */ } | |||
| 908 | ||||
| 909 | ||||
| 910 | bRet = releaseProfile(pProfile); | |||
| 911 | OSL_ASSERT(bRet)do { if (((sal_Bool)1) && (!(bRet))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "911" ": "), "OSL_ASSERT: %s", "bRet"); } } while (((sal_Bool )0)); | |||
| 912 | ||||
| 913 | pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); | |||
| 914 | ||||
| 915 | #ifdef TRACE_OSL_PROFILE | |||
| 916 | OSL_TRACE("Out osl_removeProfileEntry [ok]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "916" ": "), "Out osl_removeProfileEntry [ok]"); } } while (((sal_Bool)0)); | |||
| 917 | #endif | |||
| 918 | return bRet; | |||
| 919 | } | |||
| 920 | ||||
| 921 | ||||
| 922 | sal_uInt32 SAL_CALL osl_getProfileSectionEntries(oslProfile Profile, const sal_Char *pszSection, | |||
| 923 | sal_Char* pszBuffer, sal_uInt32 MaxLen) | |||
| 924 | { | |||
| 925 | sal_uInt32 i, n = 0; | |||
| 926 | sal_uInt32 NoEntry; | |||
| 927 | osl_TProfileSection* pSec; | |||
| 928 | osl_TProfileImpl* pProfile = 0; | |||
| 929 | osl_TProfileImpl* pTmpProfile = 0; | |||
| 930 | sal_Bool bRet = sal_False((sal_Bool)0); | |||
| 931 | ||||
| 932 | #ifdef TRACE_OSL_PROFILE | |||
| 933 | OSL_TRACE("In osl_getProfileSectionEntries")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "933" ": "), "In osl_getProfileSectionEntries"); } } while (((sal_Bool)0)); | |||
| 934 | #endif | |||
| 935 | ||||
| 936 | pTmpProfile = (osl_TProfileImpl*) Profile; | |||
| 937 | ||||
| 938 | if ( pTmpProfile == 0 ) | |||
| 939 | { | |||
| 940 | #ifdef TRACE_OSL_PROFILE | |||
| 941 | OSL_TRACE("Out osl_getProfileSectionEntries [pTmpProfile==0]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "941" ": "), "Out osl_getProfileSectionEntries [pTmpProfile==0]" ); } } while (((sal_Bool)0)); | |||
| 942 | #endif | |||
| 943 | return sal_False((sal_Bool)0); | |||
| 944 | ||||
| 945 | } | |||
| 946 | ||||
| 947 | pthread_mutex_lock(&(pTmpProfile->m_AccessLock)); | |||
| 948 | ||||
| 949 | if ( pTmpProfile->m_bIsValid == sal_False((sal_Bool)0) ) | |||
| 950 | { | |||
| 951 | OSL_ASSERT(pTmpProfile->m_bIsValid)do { if (((sal_Bool)1) && (!(pTmpProfile->m_bIsValid ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "951" ": "), "OSL_ASSERT: %s", "pTmpProfile->m_bIsValid"); } } while (((sal_Bool)0)); | |||
| 952 | ||||
| 953 | pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); | |||
| 954 | ||||
| 955 | #ifdef TRACE_OSL_PROFILE | |||
| 956 | OSL_TRACE("Out osl_getProfileSectionEntries [not valid]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "956" ": "), "Out osl_getProfileSectionEntries [not valid]" ); } } while (((sal_Bool)0)); | |||
| 957 | #endif | |||
| 958 | ||||
| 959 | return sal_False((sal_Bool)0); | |||
| 960 | } | |||
| 961 | ||||
| 962 | pProfile = acquireProfile(Profile, sal_False((sal_Bool)0)); | |||
| 963 | ||||
| 964 | if (pProfile == NULL((void*)0)) | |||
| 965 | { | |||
| 966 | pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); | |||
| 967 | ||||
| 968 | #ifdef TRACE_OSL_PROFILE | |||
| 969 | OSL_TRACE("Out osl_getProfileSectionEntries [pProfile=0]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "969" ": "), "Out osl_getProfileSectionEntries [pProfile=0]" ); } } while (((sal_Bool)0)); | |||
| 970 | #endif | |||
| 971 | ||||
| 972 | return (0); | |||
| 973 | } | |||
| 974 | ||||
| 975 | ||||
| 976 | if (! (pProfile->m_Flags & osl_Profile_SYSTEM0x0001)) | |||
| 977 | { | |||
| 978 | if ((pSec = findEntry(pProfile, pszSection, "", &NoEntry)) != NULL((void*)0)) | |||
| 979 | { | |||
| 980 | if (MaxLen != 0) | |||
| 981 | { | |||
| 982 | for (i = 0; i < pSec->m_NoEntries; i++) | |||
| 983 | { | |||
| 984 | if ((n + pSec->m_Entries[i].m_Len + 1) < MaxLen) | |||
| 985 | { | |||
| 986 | strncpy(&pszBuffer[n], &pProfile->m_Lines[pSec->m_Entries[i].m_Line] | |||
| 987 | [pSec->m_Entries[i].m_Offset], pSec->m_Entries[i].m_Len); | |||
| 988 | n += pSec->m_Entries[i].m_Len; | |||
| 989 | pszBuffer[n++] = '\0'; | |||
| 990 | } | |||
| 991 | else | |||
| 992 | break; | |||
| 993 | ||||
| 994 | } | |||
| 995 | ||||
| 996 | pszBuffer[n++] = '\0'; | |||
| 997 | } | |||
| 998 | else | |||
| 999 | { | |||
| 1000 | for (i = 0; i < pSec->m_NoEntries; i++) | |||
| 1001 | n += pSec->m_Entries[i].m_Len + 1; | |||
| 1002 | ||||
| 1003 | n += 1; | |||
| 1004 | } | |||
| 1005 | } | |||
| 1006 | else | |||
| 1007 | n = 0; | |||
| 1008 | } | |||
| 1009 | else { | |||
| 1010 | /* not implemented */ | |||
| 1011 | } | |||
| 1012 | ||||
| 1013 | bRet=releaseProfile(pProfile); | |||
| 1014 | OSL_ASSERT(bRet)do { if (((sal_Bool)1) && (!(bRet))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1014" ": "), "OSL_ASSERT: %s", "bRet"); } } while (((sal_Bool )0)); | |||
| 1015 | (void)bRet; | |||
| 1016 | ||||
| 1017 | pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); | |||
| 1018 | ||||
| 1019 | #ifdef TRACE_OSL_PROFILE | |||
| 1020 | OSL_TRACE("Out osl_getProfileSectionEntries [ok]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1020" ": "), "Out osl_getProfileSectionEntries [ok]"); } } while (((sal_Bool)0)); | |||
| 1021 | #endif | |||
| 1022 | ||||
| 1023 | return (n); | |||
| 1024 | } | |||
| 1025 | ||||
| 1026 | sal_uInt32 SAL_CALL osl_getProfileSections(oslProfile Profile, sal_Char* pszBuffer, sal_uInt32 MaxLen) | |||
| 1027 | { | |||
| 1028 | sal_uInt32 i, n = 0; | |||
| 1029 | osl_TProfileSection* pSec; | |||
| 1030 | osl_TProfileImpl* pProfile = 0; | |||
| 1031 | osl_TProfileImpl* pTmpProfile = 0; | |||
| 1032 | sal_Bool bRet = sal_False((sal_Bool)0); | |||
| 1033 | ||||
| 1034 | #ifdef TRACE_OSL_PROFILE | |||
| 1035 | OSL_TRACE("In osl_getProfileSections")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1035" ": "), "In osl_getProfileSections"); } } while ( ((sal_Bool)0)); | |||
| 1036 | #endif | |||
| 1037 | ||||
| 1038 | pTmpProfile = (osl_TProfileImpl*) Profile; | |||
| 1039 | ||||
| 1040 | if ( pTmpProfile == 0 ) | |||
| 1041 | { | |||
| 1042 | #ifdef TRACE_OSL_PROFILE | |||
| 1043 | OSL_TRACE("Out osl_getProfileSections [pTmpProfile==0]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1043" ": "), "Out osl_getProfileSections [pTmpProfile==0]" ); } } while (((sal_Bool)0)); | |||
| 1044 | #endif | |||
| 1045 | return sal_False((sal_Bool)0); | |||
| 1046 | } | |||
| 1047 | ||||
| 1048 | pthread_mutex_lock(&(pTmpProfile->m_AccessLock)); | |||
| 1049 | ||||
| 1050 | if ( pTmpProfile->m_bIsValid == sal_False((sal_Bool)0) ) | |||
| 1051 | { | |||
| 1052 | OSL_ASSERT(pTmpProfile->m_bIsValid)do { if (((sal_Bool)1) && (!(pTmpProfile->m_bIsValid ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1052" ": "), "OSL_ASSERT: %s", "pTmpProfile->m_bIsValid"); } } while (((sal_Bool)0)); | |||
| 1053 | pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); | |||
| 1054 | #ifdef TRACE_OSL_PROFILE | |||
| 1055 | OSL_TRACE("Out osl_getProfileSections [not valid]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1055" ": "), "Out osl_getProfileSections [not valid]"); } } while (((sal_Bool)0)); | |||
| 1056 | #endif | |||
| 1057 | return sal_False((sal_Bool)0); | |||
| 1058 | } | |||
| 1059 | ||||
| 1060 | pProfile = acquireProfile(Profile, sal_False((sal_Bool)0)); | |||
| 1061 | ||||
| 1062 | if (pProfile == NULL((void*)0)) | |||
| 1063 | { | |||
| 1064 | pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); | |||
| 1065 | ||||
| 1066 | #ifdef TRACE_OSL_PROFILE | |||
| 1067 | OSL_TRACE("Out osl_getProfileSections [pProfile==0]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1067" ": "), "Out osl_getProfileSections [pProfile==0]" ); } } while (((sal_Bool)0)); | |||
| 1068 | #endif | |||
| 1069 | return (0); | |||
| 1070 | } | |||
| 1071 | ||||
| 1072 | if (! (pProfile->m_Flags & osl_Profile_SYSTEM0x0001)) | |||
| 1073 | { | |||
| 1074 | if (MaxLen != 0) | |||
| 1075 | { | |||
| 1076 | for (i = 0; i < pProfile->m_NoSections; i++) | |||
| 1077 | { | |||
| 1078 | pSec = &pProfile->m_Sections[i]; | |||
| 1079 | ||||
| 1080 | if ((n + pSec->m_Len + 1) < MaxLen) | |||
| 1081 | { | |||
| 1082 | strncpy(&pszBuffer[n], &pProfile->m_Lines[pSec->m_Line][pSec->m_Offset], | |||
| 1083 | pSec->m_Len); | |||
| 1084 | n += pSec->m_Len; | |||
| 1085 | pszBuffer[n++] = '\0'; | |||
| 1086 | } | |||
| 1087 | else | |||
| 1088 | break; | |||
| 1089 | } | |||
| 1090 | ||||
| 1091 | pszBuffer[n++] = '\0'; | |||
| 1092 | } | |||
| 1093 | else | |||
| 1094 | { | |||
| 1095 | for (i = 0; i < pProfile->m_NoSections; i++) | |||
| 1096 | n += pProfile->m_Sections[i].m_Len + 1; | |||
| 1097 | ||||
| 1098 | n += 1; | |||
| 1099 | } | |||
| 1100 | } | |||
| 1101 | else | |||
| 1102 | { /* not implemented */ } | |||
| 1103 | ||||
| 1104 | ||||
| 1105 | bRet=releaseProfile(pProfile); | |||
| 1106 | OSL_ASSERT(bRet)do { if (((sal_Bool)1) && (!(bRet))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1106" ": "), "OSL_ASSERT: %s", "bRet"); } } while (((sal_Bool )0)); | |||
| 1107 | (void)bRet; | |||
| 1108 | ||||
| 1109 | pthread_mutex_unlock(&(pTmpProfile->m_AccessLock)); | |||
| 1110 | ||||
| 1111 | #ifdef TRACE_OSL_PROFILE | |||
| 1112 | OSL_TRACE("Out osl_getProfileSections [ok]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1112" ": "), "Out osl_getProfileSections [ok]"); } } while (((sal_Bool)0)); | |||
| 1113 | #endif | |||
| 1114 | ||||
| 1115 | return (n); | |||
| 1116 | } | |||
| 1117 | ||||
| 1118 | /*****************************************************************************/ | |||
| 1119 | /* Static Module Functions */ | |||
| 1120 | /*****************************************************************************/ | |||
| 1121 | ||||
| 1122 | static osl_TStamp OslProfile_getFileStamp(osl_TFile* pFile) | |||
| 1123 | { | |||
| 1124 | struct stat status; | |||
| 1125 | ||||
| 1126 | if ( (pFile->m_Handle < 0) || (fstat(pFile->m_Handle, &status) < 0) ) | |||
| 1127 | { | |||
| 1128 | return (0); | |||
| 1129 | } | |||
| 1130 | ||||
| 1131 | ||||
| 1132 | return (status.st_mtimest_mtim.tv_sec); | |||
| 1133 | } | |||
| 1134 | ||||
| 1135 | static sal_Bool OslProfile_lockFile(const osl_TFile* pFile, osl_TLockMode eMode) | |||
| 1136 | { | |||
| 1137 | struct flock lock; | |||
| 1138 | /* boring hack, but initializers for static vars must be constant */ | |||
| 1139 | static sal_Bool bIsInitialized = sal_False((sal_Bool)0); | |||
| 1140 | static sal_Bool bLockingDisabled; | |||
| 1141 | ||||
| 1142 | #ifdef TRACE_OSL_PROFILE | |||
| 1143 | OSL_TRACE("In OslProfile_lockFile")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1143" ": "), "In OslProfile_lockFile"); } } while (((sal_Bool )0)); | |||
| 1144 | #endif | |||
| 1145 | ||||
| 1146 | if ( !bIsInitialized ) | |||
| 1147 | { | |||
| 1148 | sal_Char* pEnvValue; | |||
| 1149 | pEnvValue = getenv( "STAR_PROFILE_LOCKING_DISABLED" ); | |||
| 1150 | ||||
| 1151 | if ( pEnvValue == 0 ) | |||
| 1152 | { | |||
| 1153 | bLockingDisabled = sal_False((sal_Bool)0); | |||
| 1154 | ||||
| 1155 | } | |||
| 1156 | else | |||
| 1157 | { | |||
| 1158 | bLockingDisabled = sal_True((sal_Bool)1); | |||
| 1159 | } | |||
| 1160 | ||||
| 1161 | bIsInitialized = sal_True((sal_Bool)1); | |||
| 1162 | } | |||
| 1163 | ||||
| 1164 | if (pFile->m_Handle < 0) | |||
| 1165 | { | |||
| 1166 | #ifdef TRACE_OSL_PROFILE | |||
| 1167 | OSL_TRACE("Out OslProfile_lockFile [invalid file handle]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1167" ": "), "Out OslProfile_lockFile [invalid file handle]" ); } } while (((sal_Bool)0)); | |||
| 1168 | #endif | |||
| 1169 | return (sal_False((sal_Bool)0)); | |||
| 1170 | } | |||
| 1171 | ||||
| 1172 | ||||
| 1173 | if ( bLockingDisabled ) | |||
| 1174 | { | |||
| 1175 | #ifdef TRACE_OSL_PROFILE | |||
| 1176 | OSL_TRACE("Out OslProfile_lockFile [locking disabled]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1176" ": "), "Out OslProfile_lockFile [locking disabled]" ); } } while (((sal_Bool)0)); | |||
| 1177 | #endif | |||
| 1178 | return (sal_True((sal_Bool)1)); | |||
| 1179 | } | |||
| 1180 | ||||
| 1181 | ||||
| 1182 | lock.l_start = 0; | |||
| 1183 | lock.l_whence = SEEK_SET0; | |||
| 1184 | lock.l_len = 0; | |||
| 1185 | ||||
| 1186 | switch (eMode) | |||
| 1187 | { | |||
| 1188 | case un_lock: | |||
| 1189 | lock.l_type = F_UNLCK2; | |||
| 1190 | break; | |||
| 1191 | ||||
| 1192 | case read_lock: | |||
| 1193 | lock.l_type = F_RDLCK0; | |||
| 1194 | break; | |||
| 1195 | ||||
| 1196 | case write_lock: | |||
| 1197 | lock.l_type = F_WRLCK1; | |||
| 1198 | break; | |||
| 1199 | } | |||
| 1200 | ||||
| 1201 | #ifndef MACOSX // not MAC OSX | |||
| 1202 | if ( fcntl(pFile->m_Handle, F_SETLKW14, &lock) == -1 ) | |||
| 1203 | #else | |||
| 1204 | /* Mac OSX will return ENOTSUP for webdav drives so we should ignore it */ | |||
| 1205 | if ( fcntl(pFile->m_Handle, F_SETLKW14, &lock) == -1 && errno(*__errno_location ()) != ENOTSUP95 ) | |||
| 1206 | #endif /* MACOSX */ | |||
| 1207 | { | |||
| 1208 | OSL_TRACE("fcntl returned -1 (%s)",strerror(errno))do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1208" ": "), "fcntl returned -1 (%s)",strerror((*__errno_location ()))); } } while (((sal_Bool)0)); | |||
| 1209 | #ifdef TRACE_OSL_PROFILE | |||
| 1210 | OSL_TRACE("Out OslProfile_lockFile [fcntl F_SETLKW]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1210" ": "), "Out OslProfile_lockFile [fcntl F_SETLKW]" ); } } while (((sal_Bool)0)); | |||
| 1211 | #endif | |||
| 1212 | return sal_False((sal_Bool)0); | |||
| 1213 | } | |||
| 1214 | ||||
| 1215 | #ifdef TRACE_OSL_PROFILE | |||
| 1216 | OSL_TRACE("Out OslProfile_lockFile [ok]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1216" ": "), "Out OslProfile_lockFile [ok]"); } } while (((sal_Bool)0)); | |||
| 1217 | #endif | |||
| 1218 | return sal_True((sal_Bool)1); | |||
| 1219 | } | |||
| 1220 | ||||
| 1221 | static osl_TFile* openFileImpl(const sal_Char* pszFilename, oslProfileOption ProfileFlags ) | |||
| 1222 | { | |||
| 1223 | int Flags; | |||
| 1224 | osl_TFile* pFile = (osl_TFile*) calloc(1, sizeof(osl_TFile)); | |||
| 1225 | sal_Bool bWriteable = sal_False((sal_Bool)0); | |||
| 1226 | ||||
| 1227 | if ( ProfileFlags & ( osl_Profile_WRITELOCK0x0004 | osl_Profile_FLUSHWRITE0x0010 ) ) | |||
| 1228 | { | |||
| 1229 | #ifdef DEBUG_OSL_PROFILE | |||
| 1230 | OSL_TRACE("setting bWriteable to TRUE")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1230" ": "), "setting bWriteable to TRUE"); } } while ( ((sal_Bool)0)); | |||
| 1231 | #endif | |||
| 1232 | bWriteable=sal_True((sal_Bool)1); | |||
| 1233 | } | |||
| 1234 | ||||
| 1235 | if (! bWriteable) | |||
| 1236 | { | |||
| 1237 | #ifdef DEBUG_OSL_PROFILE | |||
| 1238 | OSL_TRACE("opening '%s' read only",pszFilename)do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1238" ": "), "opening '%s' read only",pszFilename); } } while (((sal_Bool)0)); | |||
| 1239 | #endif | |||
| 1240 | ||||
| 1241 | pFile->m_Handle = open(pszFilename, O_RDONLY00); | |||
| 1242 | /* mfe: argghh!!! do not check if the file could be openend */ | |||
| 1243 | /* default mode expects it that way!!! */ | |||
| 1244 | } | |||
| 1245 | else | |||
| 1246 | { | |||
| 1247 | #ifdef DEBUG_OSL_PROFILE | |||
| 1248 | OSL_TRACE("opening '%s' read/write",pszFilename)do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1248" ": "), "opening '%s' read/write",pszFilename); } } while (((sal_Bool)0)); | |||
| 1249 | #endif | |||
| 1250 | if (((pFile->m_Handle = open(pszFilename, O_RDWR02 | O_CREAT0100 | O_EXCL0200, DEFAULT_PMODE(0400 | 0200 | (0400 >> 3) | (0200 >> 3) | ((0400 >> 3) >> 3) | ((0200 >> 3) >> 3)))) < 0) && | |||
| 1251 | ((pFile->m_Handle = open(pszFilename, O_RDWR02)) < 0)) | |||
| 1252 | { | |||
| 1253 | free(pFile); | |||
| 1254 | #ifdef TRACE_OSL_PROFILE | |||
| 1255 | OSL_TRACE("Out openFileImpl [open read/write]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1255" ": "), "Out openFileImpl [open read/write]"); } } while (((sal_Bool)0)); | |||
| 1256 | #endif | |||
| 1257 | return (NULL((void*)0)); | |||
| 1258 | } | |||
| 1259 | } | |||
| 1260 | ||||
| 1261 | /* set close-on-exec flag */ | |||
| 1262 | if ((Flags = fcntl(pFile->m_Handle, F_GETFD1, 0)) != -1) | |||
| 1263 | { | |||
| 1264 | Flags |= FD_CLOEXEC1; | |||
| 1265 | fcntl(pFile->m_Handle, F_SETFD2, Flags); | |||
| 1266 | } | |||
| 1267 | ||||
| 1268 | pFile->m_pWriteBuf=0; | |||
| 1269 | pFile->m_nWriteBufFree=0; | |||
| 1270 | pFile->m_nWriteBufLen=0; | |||
| 1271 | ||||
| 1272 | if ( ProfileFlags & (osl_Profile_WRITELOCK0x0004 | osl_Profile_READLOCK0x0002 ) ) | |||
| 1273 | { | |||
| 1274 | #ifdef DEBUG_OSL_PROFILE | |||
| 1275 | OSL_TRACE("locking '%s' file",pszFilename)do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1275" ": "), "locking '%s' file",pszFilename); } } while (((sal_Bool)0)); | |||
| 1276 | #endif | |||
| 1277 | OslProfile_lockFile(pFile, bWriteable ? write_lock : read_lock); | |||
| 1278 | } | |||
| 1279 | ||||
| 1280 | #ifdef TRACE_OSL_PROFILE | |||
| 1281 | OSL_TRACE("Out openFileImpl [ok]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1281" ": "), "Out openFileImpl [ok]"); } } while (((sal_Bool )0)); | |||
| 1282 | #endif | |||
| 1283 | return (pFile); | |||
| 1284 | } | |||
| 1285 | ||||
| 1286 | static osl_TStamp closeFileImpl(osl_TFile* pFile, oslProfileOption Flags) | |||
| 1287 | { | |||
| 1288 | osl_TStamp stamp = 0; | |||
| 1289 | ||||
| 1290 | #ifdef TRACE_OSL_PROFILE | |||
| 1291 | OSL_TRACE("In closeFileImpl")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1291" ": "), "In closeFileImpl"); } } while (((sal_Bool )0)); | |||
| 1292 | #endif | |||
| 1293 | ||||
| 1294 | if ( pFile == 0 ) | |||
| 1295 | { | |||
| 1296 | #ifdef TRACE_OSL_PROFILE | |||
| 1297 | OSL_TRACE("Out closeFileImpl [pFile == 0]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1297" ": "), "Out closeFileImpl [pFile == 0]"); } } while (((sal_Bool)0)); | |||
| 1298 | #endif | |||
| 1299 | return stamp; | |||
| 1300 | } | |||
| 1301 | ||||
| 1302 | if ( pFile->m_Handle >= 0 ) | |||
| 1303 | { | |||
| 1304 | stamp = OslProfile_getFileStamp(pFile); | |||
| 1305 | ||||
| 1306 | if ( Flags & (osl_Profile_WRITELOCK0x0004 | osl_Profile_READLOCK0x0002 ) ) | |||
| 1307 | { | |||
| 1308 | OslProfile_lockFile(pFile, un_lock); | |||
| 1309 | } | |||
| 1310 | ||||
| 1311 | close(pFile->m_Handle); | |||
| 1312 | pFile->m_Handle = -1; | |||
| 1313 | } | |||
| 1314 | ||||
| 1315 | ||||
| 1316 | if ( pFile->m_pWriteBuf ) | |||
| 1317 | { | |||
| 1318 | free(pFile->m_pWriteBuf); | |||
| 1319 | } | |||
| 1320 | ||||
| 1321 | free(pFile); | |||
| 1322 | ||||
| 1323 | #ifdef TRACE_OSL_PROFILE | |||
| 1324 | OSL_TRACE("Out closeFileImpl [ok]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1324" ": "), "Out closeFileImpl [ok]"); } } while (((sal_Bool )0)); | |||
| 1325 | #endif | |||
| 1326 | ||||
| 1327 | return(stamp); | |||
| 1328 | } | |||
| 1329 | ||||
| 1330 | static sal_Bool OslProfile_rewindFile(osl_TFile* pFile, sal_Bool bTruncate) | |||
| 1331 | { | |||
| 1332 | sal_Bool bRet = sal_True((sal_Bool)1); | |||
| 1333 | #ifdef TRACE_OSL_PROFILE | |||
| 1334 | OSL_TRACE("In osl_OslProfile_rewindFile")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1334" ": "), "In osl_OslProfile_rewindFile"); } } while (((sal_Bool)0)); | |||
| 1335 | #endif | |||
| 1336 | ||||
| 1337 | if (pFile->m_Handle >= 0) | |||
| 1338 | { | |||
| 1339 | pFile->m_pReadPtr = pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf); | |||
| 1340 | ||||
| 1341 | #ifdef DEBUG_OSL_PROFILE | |||
| 1342 | OSL_TRACE("rewinding")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1342" ": "), "rewinding"); } } while (((sal_Bool)0)); | |||
| 1343 | #endif | |||
| 1344 | bRet = (lseek(pFile->m_Handle, SEEK_SET0, 0L) == 0L); | |||
| 1345 | ||||
| 1346 | if (bTruncate) | |||
| 1347 | { | |||
| 1348 | #ifdef DEBUG_OSL_PROFILE | |||
| 1349 | OSL_TRACE("truncating")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1349" ": "), "truncating"); } } while (((sal_Bool)0)); | |||
| 1350 | #endif | |||
| 1351 | bRet &= (ftruncate(pFile->m_Handle, 0L) == 0); | |||
| 1352 | } | |||
| 1353 | ||||
| 1354 | } | |||
| 1355 | ||||
| 1356 | #ifdef TRACE_OSL_PROFILE | |||
| 1357 | OSL_TRACE("Out osl_OslProfile_rewindFile [ok]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1357" ": "), "Out osl_OslProfile_rewindFile [ok]"); } } while (((sal_Bool)0)); | |||
| 1358 | #endif | |||
| 1359 | return bRet; | |||
| 1360 | } | |||
| 1361 | ||||
| 1362 | ||||
| 1363 | static sal_Char* OslProfile_getLine(osl_TFile* pFile) | |||
| 1364 | { | |||
| 1365 | int Max, Free, Bytes, nLineBytes = 0; | |||
| 1366 | sal_Char* pChr; | |||
| 1367 | sal_Char* pLine = NULL((void*)0); | |||
| 1368 | sal_Char* pNewLine; | |||
| 1369 | ||||
| 1370 | if ( pFile == 0 ) | |||
| 1371 | { | |||
| 1372 | return 0; | |||
| 1373 | } | |||
| 1374 | ||||
| 1375 | if (pFile->m_Handle < 0) | |||
| 1376 | return NULL((void*)0); | |||
| 1377 | ||||
| 1378 | do | |||
| 1379 | { | |||
| 1380 | Bytes = sizeof(pFile->m_ReadBuf) - (pFile->m_pReadPtr - pFile->m_ReadBuf); | |||
| 1381 | ||||
| 1382 | if (Bytes <= 1) | |||
| 1383 | { | |||
| 1384 | /* refill buffer */ | |||
| 1385 | memcpy(pFile->m_ReadBuf, pFile->m_pReadPtr, Bytes); | |||
| 1386 | pFile->m_pReadPtr = pFile->m_ReadBuf; | |||
| 1387 | ||||
| 1388 | Free = sizeof(pFile->m_ReadBuf) - Bytes; | |||
| 1389 | ||||
| 1390 | if ((Max = read(pFile->m_Handle, &pFile->m_ReadBuf[Bytes], Free)) < 0) | |||
| 1391 | { | |||
| 1392 | OSL_TRACE("read failed '%s'",strerror(errno))do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1392" ": "), "read failed '%s'",strerror((*__errno_location ()))); } } while (((sal_Bool)0)); | |||
| 1393 | ||||
| 1394 | if( pLine ) | |||
| 1395 | rtl_freeMemory( pLine ); | |||
| 1396 | pLine = NULL((void*)0); | |||
| 1397 | break; | |||
| 1398 | } | |||
| 1399 | ||||
| 1400 | if (Max < Free) | |||
| 1401 | { | |||
| 1402 | if ((Max == 0) && ! pLine) | |||
| 1403 | break; | |||
| 1404 | ||||
| 1405 | pFile->m_ReadBuf[Bytes + Max] = '\0'; | |||
| 1406 | } | |||
| 1407 | } | |||
| 1408 | ||||
| 1409 | for (pChr = pFile->m_pReadPtr; | |||
| 1410 | (*pChr != '\n') && (*pChr != '\r') && (*pChr != '\0') && | |||
| 1411 | (pChr < (pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf) - 1)); | |||
| 1412 | pChr++); | |||
| 1413 | ||||
| 1414 | Max = pChr - pFile->m_pReadPtr; | |||
| 1415 | pNewLine = (sal_Char*) rtl_allocateMemory( nLineBytes + Max + 1 ); | |||
| 1416 | if( pLine ) | |||
| 1417 | { | |||
| 1418 | memcpy( pNewLine, pLine, nLineBytes ); | |||
| 1419 | rtl_freeMemory( pLine ); | |||
| 1420 | } | |||
| 1421 | memcpy(pNewLine+nLineBytes, pFile->m_pReadPtr, Max); | |||
| 1422 | nLineBytes += Max; | |||
| 1423 | pNewLine[ nLineBytes ] = 0; | |||
| 1424 | pLine = pNewLine; | |||
| 1425 | ||||
| 1426 | if (pChr < (pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf) - 1)) | |||
| 1427 | { | |||
| 1428 | if (*pChr != '\0') | |||
| 1429 | { | |||
| 1430 | if ((pChr[0] == '\r') && (pChr[1] == '\n')) | |||
| 1431 | pChr += 2; | |||
| 1432 | else | |||
| 1433 | pChr += 1; | |||
| 1434 | } | |||
| 1435 | ||||
| 1436 | if ((pChr < (pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf))) && | |||
| 1437 | (*pChr == '\0')) | |||
| 1438 | pChr = pFile->m_ReadBuf + sizeof(pFile->m_ReadBuf); | |||
| 1439 | ||||
| 1440 | /* setting Max to -1 indicates terminating read loop */ | |||
| 1441 | Max = -1; | |||
| 1442 | } | |||
| 1443 | ||||
| 1444 | pFile->m_pReadPtr = pChr; | |||
| 1445 | } | |||
| 1446 | while (Max > 0); | |||
| 1447 | ||||
| 1448 | return pLine; | |||
| 1449 | } | |||
| 1450 | ||||
| 1451 | static sal_Bool OslProfile_putLine(osl_TFile* pFile, const sal_Char *pszLine) | |||
| 1452 | { | |||
| 1453 | unsigned int Len = strlen(pszLine); | |||
| 1454 | ||||
| 1455 | #ifdef DEBUG_OSL_PROFILE | |||
| 1456 | int strLen=0; | |||
| 1457 | #endif | |||
| 1458 | ||||
| 1459 | if ( pFile == 0 || pFile->m_Handle < 0 ) | |||
| 1460 | { | |||
| 1461 | return (sal_False((sal_Bool)0)); | |||
| 1462 | } | |||
| 1463 | ||||
| 1464 | if ( pFile->m_pWriteBuf == 0 ) | |||
| 1465 | { | |||
| 1466 | pFile->m_pWriteBuf = (sal_Char*) malloc(Len+3); | |||
| 1467 | pFile->m_nWriteBufLen = Len+3; | |||
| 1468 | pFile->m_nWriteBufFree = Len+3; | |||
| 1469 | } | |||
| 1470 | else | |||
| 1471 | { | |||
| 1472 | if ( pFile->m_nWriteBufFree <= Len + 3 ) | |||
| 1473 | { | |||
| 1474 | sal_Char* pTmp; | |||
| 1475 | ||||
| 1476 | pTmp=(sal_Char*) realloc(pFile->m_pWriteBuf,( ( pFile->m_nWriteBufLen + Len ) * 2) ); | |||
| 1477 | if ( pTmp == 0 ) | |||
| 1478 | { | |||
| 1479 | return sal_False((sal_Bool)0); | |||
| 1480 | } | |||
| 1481 | pFile->m_pWriteBuf = pTmp; | |||
| 1482 | pFile->m_nWriteBufFree = pFile->m_nWriteBufFree + pFile->m_nWriteBufLen + ( 2 * Len ); | |||
| 1483 | pFile->m_nWriteBufLen = ( pFile->m_nWriteBufLen + Len ) * 2; | |||
| 1484 | memset( (pFile->m_pWriteBuf) + ( pFile->m_nWriteBufLen - pFile->m_nWriteBufFree ), 0, pFile->m_nWriteBufFree); | |||
| 1485 | } | |||
| 1486 | } | |||
| 1487 | ||||
| 1488 | ||||
| 1489 | ||||
| 1490 | memcpy(pFile->m_pWriteBuf + ( pFile->m_nWriteBufLen - pFile->m_nWriteBufFree ),pszLine,Len+1); | |||
| 1491 | #ifdef DEBUG_OSL_PROFILE | |||
| 1492 | strLen = strlen(pFile->m_pWriteBuf); | |||
| 1493 | #endif | |||
| 1494 | pFile->m_pWriteBuf[pFile->m_nWriteBufLen - pFile->m_nWriteBufFree + Len]='\n'; | |||
| 1495 | pFile->m_pWriteBuf[pFile->m_nWriteBufLen - pFile->m_nWriteBufFree + Len + 1]='\0'; | |||
| 1496 | ||||
| 1497 | pFile->m_nWriteBufFree-=Len+1; | |||
| 1498 | ||||
| 1499 | return sal_True((sal_Bool)1); | |||
| 1500 | } | |||
| 1501 | ||||
| 1502 | /* platform specific end */ | |||
| 1503 | ||||
| 1504 | static sal_Char* stripBlanks(sal_Char* String, sal_uInt32* pLen) | |||
| 1505 | { | |||
| 1506 | if ( ( pLen != NULL((void*)0) ) && ( *pLen != 0 ) ) | |||
| 1507 | { | |||
| 1508 | while ((String[*pLen - 1] == ' ') || (String[*pLen - 1] == '\t')) | |||
| 1509 | (*pLen)--; | |||
| 1510 | ||||
| 1511 | while ( (*String == ' ') || (*String == '\t') ) | |||
| 1512 | { | |||
| 1513 | String++; | |||
| 1514 | (*pLen)--; | |||
| 1515 | } | |||
| 1516 | } | |||
| 1517 | else | |||
| 1518 | while ( (*String == ' ') || (*String == '\t') ) | |||
| 1519 | String++; | |||
| 1520 | ||||
| 1521 | return (String); | |||
| 1522 | } | |||
| 1523 | ||||
| 1524 | static sal_Char* addLine(osl_TProfileImpl* pProfile, const sal_Char* Line) | |||
| 1525 | { | |||
| 1526 | if (pProfile->m_NoLines >= pProfile->m_MaxLines) | |||
| 1527 | { | |||
| 1528 | if (pProfile->m_Lines == NULL((void*)0)) | |||
| 1529 | { | |||
| 1530 | pProfile->m_MaxLines = LINES_INI32; | |||
| 1531 | pProfile->m_Lines = (sal_Char **)malloc(pProfile->m_MaxLines * sizeof(sal_Char *)); | |||
| 1532 | memset(pProfile->m_Lines,0,pProfile->m_MaxLines * sizeof(sal_Char *)); | |||
| 1533 | } | |||
| 1534 | else | |||
| 1535 | { | |||
| 1536 | unsigned int idx=0; | |||
| 1537 | unsigned int oldmax=pProfile->m_MaxLines; | |||
| 1538 | ||||
| 1539 | pProfile->m_MaxLines += LINES_ADD10; | |||
| 1540 | pProfile->m_Lines = (sal_Char **)realloc(pProfile->m_Lines, | |||
| 1541 | pProfile->m_MaxLines * sizeof(sal_Char *)); | |||
| 1542 | for ( idx = oldmax ; idx < pProfile->m_MaxLines ; ++idx ) | |||
| 1543 | { | |||
| 1544 | pProfile->m_Lines[idx]=0; | |||
| 1545 | } | |||
| 1546 | } | |||
| 1547 | ||||
| 1548 | if (pProfile->m_Lines == NULL((void*)0)) | |||
| 1549 | { | |||
| 1550 | pProfile->m_NoLines = 0; | |||
| 1551 | pProfile->m_MaxLines = 0; | |||
| 1552 | return (NULL((void*)0)); | |||
| 1553 | } | |||
| 1554 | ||||
| 1555 | } | |||
| 1556 | ||||
| 1557 | if ( pProfile->m_Lines != 0 && pProfile->m_Lines[pProfile->m_NoLines] != 0 ) | |||
| 1558 | { | |||
| 1559 | free(pProfile->m_Lines[pProfile->m_NoLines]); | |||
| 1560 | } | |||
| 1561 | pProfile->m_Lines[pProfile->m_NoLines++] = strdup(Line); | |||
| ||||
| 1562 | ||||
| 1563 | return (pProfile->m_Lines[pProfile->m_NoLines - 1]); | |||
| 1564 | } | |||
| 1565 | ||||
| 1566 | static sal_Char* insertLine(osl_TProfileImpl* pProfile, const sal_Char* Line, sal_uInt32 LineNo) | |||
| 1567 | { | |||
| 1568 | if (pProfile->m_NoLines >= pProfile->m_MaxLines) | |||
| 1569 | { | |||
| 1570 | if (pProfile->m_Lines == NULL((void*)0)) | |||
| 1571 | { | |||
| 1572 | pProfile->m_MaxLines = LINES_INI32; | |||
| 1573 | pProfile->m_Lines = (sal_Char **)malloc(pProfile->m_MaxLines * sizeof(sal_Char *)); | |||
| 1574 | memset(pProfile->m_Lines,0,pProfile->m_MaxLines * sizeof(sal_Char *)); | |||
| 1575 | } | |||
| 1576 | else | |||
| 1577 | { | |||
| 1578 | pProfile->m_MaxLines += LINES_ADD10; | |||
| 1579 | pProfile->m_Lines = (sal_Char **)realloc(pProfile->m_Lines, | |||
| 1580 | pProfile->m_MaxLines * sizeof(sal_Char *)); | |||
| 1581 | ||||
| 1582 | memset(&pProfile->m_Lines[pProfile->m_NoLines], | |||
| 1583 | 0, | |||
| 1584 | (pProfile->m_MaxLines - pProfile->m_NoLines - 1) * sizeof(sal_Char*)); | |||
| 1585 | } | |||
| 1586 | ||||
| 1587 | if (pProfile->m_Lines == NULL((void*)0)) | |||
| 1588 | { | |||
| 1589 | pProfile->m_NoLines = 0; | |||
| 1590 | pProfile->m_MaxLines = 0; | |||
| 1591 | return (NULL((void*)0)); | |||
| 1592 | } | |||
| 1593 | } | |||
| 1594 | ||||
| 1595 | LineNo = LineNo > pProfile->m_NoLines ? pProfile->m_NoLines : LineNo; | |||
| 1596 | ||||
| 1597 | if (LineNo < pProfile->m_NoLines) | |||
| 1598 | { | |||
| 1599 | sal_uInt32 i, n; | |||
| 1600 | osl_TProfileSection* pSec; | |||
| 1601 | ||||
| 1602 | memmove(&pProfile->m_Lines[LineNo + 1], &pProfile->m_Lines[LineNo], | |||
| 1603 | (pProfile->m_NoLines - LineNo) * sizeof(sal_Char *)); | |||
| 1604 | ||||
| 1605 | ||||
| 1606 | /* adjust line references */ | |||
| 1607 | for (i = 0; i < pProfile->m_NoSections; i++) | |||
| 1608 | { | |||
| 1609 | pSec = &pProfile->m_Sections[i]; | |||
| 1610 | ||||
| 1611 | if (pSec->m_Line >= LineNo) | |||
| 1612 | pSec->m_Line++; | |||
| 1613 | ||||
| 1614 | for (n = 0; n < pSec->m_NoEntries; n++) | |||
| 1615 | if (pSec->m_Entries[n].m_Line >= LineNo) | |||
| 1616 | pSec->m_Entries[n].m_Line++; | |||
| 1617 | } | |||
| 1618 | } | |||
| 1619 | ||||
| 1620 | pProfile->m_NoLines++; | |||
| 1621 | ||||
| 1622 | pProfile->m_Lines[LineNo] = strdup(Line); | |||
| 1623 | ||||
| 1624 | return (pProfile->m_Lines[LineNo]); | |||
| 1625 | } | |||
| 1626 | ||||
| 1627 | static void removeLine(osl_TProfileImpl* pProfile, sal_uInt32 LineNo) | |||
| 1628 | { | |||
| 1629 | if (LineNo < pProfile->m_NoLines) | |||
| 1630 | { | |||
| 1631 | free(pProfile->m_Lines[LineNo]); | |||
| 1632 | pProfile->m_Lines[LineNo]=0; | |||
| 1633 | if (pProfile->m_NoLines - LineNo > 1) | |||
| 1634 | { | |||
| 1635 | sal_uInt32 i, n; | |||
| 1636 | osl_TProfileSection* pSec; | |||
| 1637 | ||||
| 1638 | memmove(&pProfile->m_Lines[LineNo], &pProfile->m_Lines[LineNo + 1], | |||
| 1639 | (pProfile->m_NoLines - LineNo - 1) * sizeof(sal_Char *)); | |||
| 1640 | ||||
| 1641 | memset(&pProfile->m_Lines[pProfile->m_NoLines - 1], | |||
| 1642 | 0, | |||
| 1643 | (pProfile->m_MaxLines - pProfile->m_NoLines) * sizeof(sal_Char*)); | |||
| 1644 | ||||
| 1645 | /* adjust line references */ | |||
| 1646 | for (i = 0; i < pProfile->m_NoSections; i++) | |||
| 1647 | { | |||
| 1648 | pSec = &pProfile->m_Sections[i]; | |||
| 1649 | ||||
| 1650 | if (pSec->m_Line > LineNo) | |||
| 1651 | pSec->m_Line--; | |||
| 1652 | ||||
| 1653 | for (n = 0; n < pSec->m_NoEntries; n++) | |||
| 1654 | if (pSec->m_Entries[n].m_Line > LineNo) | |||
| 1655 | pSec->m_Entries[n].m_Line--; | |||
| 1656 | } | |||
| 1657 | } | |||
| 1658 | else | |||
| 1659 | { | |||
| 1660 | pProfile->m_Lines[LineNo] = 0; | |||
| 1661 | } | |||
| 1662 | ||||
| 1663 | pProfile->m_NoLines--; | |||
| 1664 | } | |||
| 1665 | ||||
| 1666 | return; | |||
| 1667 | } | |||
| 1668 | ||||
| 1669 | static void setEntry(osl_TProfileImpl* pProfile, osl_TProfileSection* pSection, | |||
| 1670 | sal_uInt32 NoEntry, sal_uInt32 Line, | |||
| 1671 | sal_Char* Entry, sal_uInt32 Len) | |||
| 1672 | { | |||
| 1673 | Entry = stripBlanks(Entry, &Len); | |||
| 1674 | pSection->m_Entries[NoEntry].m_Line = Line; | |||
| 1675 | pSection->m_Entries[NoEntry].m_Offset = Entry - pProfile->m_Lines[Line]; | |||
| 1676 | pSection->m_Entries[NoEntry].m_Len = Len; | |||
| 1677 | ||||
| 1678 | return; | |||
| 1679 | } | |||
| 1680 | ||||
| 1681 | static sal_Bool addEntry(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection, | |||
| 1682 | int Line, sal_Char* Entry, sal_uInt32 Len) | |||
| 1683 | { | |||
| 1684 | if (pSection != NULL((void*)0)) | |||
| 1685 | { | |||
| 1686 | if (pSection->m_NoEntries >= pSection->m_MaxEntries) | |||
| 1687 | { | |||
| 1688 | if (pSection->m_Entries == NULL((void*)0)) | |||
| 1689 | { | |||
| 1690 | pSection->m_MaxEntries = ENTRIES_INI5; | |||
| 1691 | pSection->m_Entries = (osl_TProfileEntry *)malloc( | |||
| 1692 | pSection->m_MaxEntries * sizeof(osl_TProfileEntry)); | |||
| 1693 | } | |||
| 1694 | else | |||
| 1695 | { | |||
| 1696 | pSection->m_MaxEntries += ENTRIES_ADD3; | |||
| 1697 | pSection->m_Entries = (osl_TProfileEntry *)realloc(pSection->m_Entries, | |||
| 1698 | pSection->m_MaxEntries * sizeof(osl_TProfileEntry)); | |||
| 1699 | } | |||
| 1700 | ||||
| 1701 | if (pSection->m_Entries == NULL((void*)0)) | |||
| 1702 | { | |||
| 1703 | pSection->m_NoEntries = 0; | |||
| 1704 | pSection->m_MaxEntries = 0; | |||
| 1705 | return (sal_False((sal_Bool)0)); | |||
| 1706 | } | |||
| 1707 | } | |||
| 1708 | ||||
| 1709 | pSection->m_NoEntries++; | |||
| 1710 | ||||
| 1711 | Entry = stripBlanks(Entry, &Len); | |||
| 1712 | setEntry(pProfile, pSection, pSection->m_NoEntries - 1, Line, | |||
| 1713 | Entry, Len); | |||
| 1714 | ||||
| 1715 | return (sal_True((sal_Bool)1)); | |||
| 1716 | } | |||
| 1717 | ||||
| 1718 | return (sal_False((sal_Bool)0)); | |||
| 1719 | } | |||
| 1720 | ||||
| 1721 | static void removeEntry(osl_TProfileSection *pSection, sal_uInt32 NoEntry) | |||
| 1722 | { | |||
| 1723 | if (NoEntry < pSection->m_NoEntries) | |||
| 1724 | { | |||
| 1725 | if (pSection->m_NoEntries - NoEntry > 1) | |||
| 1726 | { | |||
| 1727 | memmove(&pSection->m_Entries[NoEntry], | |||
| 1728 | &pSection->m_Entries[NoEntry + 1], | |||
| 1729 | (pSection->m_NoEntries - NoEntry - 1) * sizeof(osl_TProfileEntry)); | |||
| 1730 | pSection->m_Entries[pSection->m_NoEntries - 1].m_Line=0; | |||
| 1731 | pSection->m_Entries[pSection->m_NoEntries - 1].m_Offset=0; | |||
| 1732 | pSection->m_Entries[pSection->m_NoEntries - 1].m_Len=0; | |||
| 1733 | } | |||
| 1734 | ||||
| 1735 | pSection->m_NoEntries--; | |||
| 1736 | } | |||
| 1737 | ||||
| 1738 | return; | |||
| 1739 | } | |||
| 1740 | ||||
| 1741 | static sal_Bool addSection(osl_TProfileImpl* pProfile, int Line, const sal_Char* Section, sal_uInt32 Len) | |||
| 1742 | { | |||
| 1743 | if (pProfile->m_NoSections >= pProfile->m_MaxSections) | |||
| 1744 | { | |||
| 1745 | if (pProfile->m_Sections == NULL((void*)0)) | |||
| 1746 | { | |||
| 1747 | pProfile->m_MaxSections = SECTIONS_INI5; | |||
| 1748 | pProfile->m_Sections = (osl_TProfileSection *)malloc(pProfile->m_MaxSections * sizeof(osl_TProfileSection)); | |||
| 1749 | memset(pProfile->m_Sections,0,pProfile->m_MaxSections * sizeof(osl_TProfileSection)); | |||
| 1750 | } | |||
| 1751 | else | |||
| 1752 | { | |||
| 1753 | unsigned int idx=0; | |||
| 1754 | unsigned int oldmax=pProfile->m_MaxSections; | |||
| 1755 | ||||
| 1756 | pProfile->m_MaxSections += SECTIONS_ADD3; | |||
| 1757 | pProfile->m_Sections = (osl_TProfileSection *)realloc(pProfile->m_Sections, | |||
| 1758 | pProfile->m_MaxSections * sizeof(osl_TProfileSection)); | |||
| 1759 | for ( idx = oldmax ; idx < pProfile->m_MaxSections ; ++idx ) | |||
| 1760 | { | |||
| 1761 | pProfile->m_Sections[idx].m_Entries=0; | |||
| 1762 | } | |||
| 1763 | } | |||
| 1764 | ||||
| 1765 | if (pProfile->m_Sections == NULL((void*)0)) | |||
| 1766 | { | |||
| 1767 | pProfile->m_NoSections = 0; | |||
| 1768 | pProfile->m_MaxSections = 0; | |||
| 1769 | return (sal_False((sal_Bool)0)); | |||
| 1770 | } | |||
| 1771 | } | |||
| 1772 | ||||
| 1773 | pProfile->m_NoSections++; | |||
| 1774 | ||||
| 1775 | if ( pProfile->m_Sections[(pProfile->m_NoSections) - 1].m_Entries != 0 ) | |||
| 1776 | { | |||
| 1777 | free(pProfile->m_Sections[(pProfile->m_NoSections) - 1].m_Entries); | |||
| 1778 | } | |||
| 1779 | pProfile->m_Sections[pProfile->m_NoSections - 1].m_Entries = NULL((void*)0); | |||
| 1780 | pProfile->m_Sections[pProfile->m_NoSections - 1].m_NoEntries = 0; | |||
| 1781 | pProfile->m_Sections[pProfile->m_NoSections - 1].m_MaxEntries = 0; | |||
| 1782 | ||||
| 1783 | pProfile->m_Sections[pProfile->m_NoSections - 1].m_Line = Line; | |||
| 1784 | pProfile->m_Sections[pProfile->m_NoSections - 1].m_Offset = Section - pProfile->m_Lines[Line]; | |||
| 1785 | pProfile->m_Sections[pProfile->m_NoSections - 1].m_Len = Len; | |||
| 1786 | ||||
| 1787 | return (sal_True((sal_Bool)1)); | |||
| 1788 | } | |||
| 1789 | ||||
| 1790 | static void removeSection(osl_TProfileImpl* pProfile, osl_TProfileSection *pSection) | |||
| 1791 | { | |||
| 1792 | sal_uInt32 Section; | |||
| 1793 | ||||
| 1794 | if ((Section = pSection - pProfile->m_Sections) < pProfile->m_NoSections) | |||
| 1795 | { | |||
| 1796 | free (pSection->m_Entries); | |||
| 1797 | pSection->m_Entries=0; | |||
| 1798 | if (pProfile->m_NoSections - Section > 1) | |||
| 1799 | { | |||
| 1800 | memmove(&pProfile->m_Sections[Section], &pProfile->m_Sections[Section + 1], | |||
| 1801 | (pProfile->m_NoSections - Section - 1) * sizeof(osl_TProfileSection)); | |||
| 1802 | ||||
| 1803 | memset(&pProfile->m_Sections[pProfile->m_NoSections - 1], | |||
| 1804 | 0, | |||
| 1805 | (pProfile->m_MaxSections - pProfile->m_NoSections) * sizeof(osl_TProfileSection)); | |||
| 1806 | pProfile->m_Sections[pProfile->m_NoSections - 1].m_Entries = 0; | |||
| 1807 | } | |||
| 1808 | else | |||
| 1809 | { | |||
| 1810 | pSection->m_Entries = 0; | |||
| 1811 | } | |||
| 1812 | ||||
| 1813 | pProfile->m_NoSections--; | |||
| 1814 | } | |||
| 1815 | ||||
| 1816 | return; | |||
| 1817 | } | |||
| 1818 | ||||
| 1819 | static osl_TProfileSection* findEntry(osl_TProfileImpl* pProfile, const sal_Char* Section, | |||
| 1820 | const sal_Char* Entry, sal_uInt32 *pNoEntry) | |||
| 1821 | { | |||
| 1822 | static sal_uInt32 Sect = 0; | |||
| 1823 | sal_uInt32 i, n; | |||
| 1824 | sal_uInt32 Len; | |||
| 1825 | const sal_Char* pStr; | |||
| 1826 | osl_TProfileSection* pSec=0; | |||
| 1827 | ||||
| 1828 | Len = strlen(Section); | |||
| 1829 | ||||
| 1830 | n = Sect; | |||
| 1831 | ||||
| 1832 | for (i = 0; i < pProfile->m_NoSections; i++) | |||
| 1833 | { | |||
| 1834 | n %= pProfile->m_NoSections; | |||
| 1835 | pSec = &pProfile->m_Sections[n]; | |||
| 1836 | if ((Len == pSec->m_Len) && | |||
| 1837 | (strncasecmp(Section, &pProfile->m_Lines[pSec->m_Line][pSec->m_Offset], pSec->m_Len) | |||
| 1838 | == 0)) | |||
| 1839 | break; | |||
| 1840 | n++; | |||
| 1841 | } | |||
| 1842 | ||||
| 1843 | Sect = n; | |||
| 1844 | ||||
| 1845 | if (i < pProfile->m_NoSections) | |||
| 1846 | { | |||
| 1847 | Len = strlen(Entry); | |||
| 1848 | ||||
| 1849 | *pNoEntry = pSec->m_NoEntries; | |||
| 1850 | ||||
| 1851 | for (i = 0; i < pSec->m_NoEntries; i++) | |||
| 1852 | { | |||
| 1853 | pStr = &pProfile->m_Lines[pSec->m_Entries[i].m_Line] | |||
| 1854 | [pSec->m_Entries[i].m_Offset]; | |||
| 1855 | if ((Len == pSec->m_Entries[i].m_Len) && | |||
| 1856 | (strncasecmp(Entry, pStr, pSec->m_Entries[i].m_Len) | |||
| 1857 | == 0)) | |||
| 1858 | { | |||
| 1859 | *pNoEntry = i; | |||
| 1860 | break; | |||
| 1861 | } | |||
| 1862 | } | |||
| 1863 | } | |||
| 1864 | else | |||
| 1865 | pSec = NULL((void*)0); | |||
| 1866 | ||||
| 1867 | return (pSec); | |||
| 1868 | } | |||
| 1869 | ||||
| 1870 | static sal_Bool loadProfile(osl_TFile* pFile, osl_TProfileImpl* pProfile) | |||
| 1871 | { | |||
| 1872 | sal_uInt32 i; | |||
| 1873 | sal_Char* pStr; | |||
| 1874 | sal_Char* pChar; | |||
| 1875 | ||||
| 1876 | sal_Char* pLine; | |||
| 1877 | sal_Char* bWasAdded = NULL((void*)0); | |||
| 1878 | ||||
| 1879 | ||||
| 1880 | if ( !pFile ) | |||
| 1881 | { | |||
| 1882 | return sal_False((sal_Bool)0); | |||
| 1883 | } | |||
| 1884 | ||||
| 1885 | if ( !pProfile ) | |||
| 1886 | { | |||
| 1887 | return sal_False((sal_Bool)0); | |||
| 1888 | } | |||
| 1889 | ||||
| 1890 | pProfile->m_NoLines = 0; | |||
| 1891 | pProfile->m_NoSections = 0; | |||
| 1892 | ||||
| 1893 | OSL_VERIFY(OslProfile_rewindFile(pFile, sal_False))do { if (!(OslProfile_rewindFile(pFile, ((sal_Bool)0)))) do { if (((sal_Bool)1) && (!(0))) { sal_detail_logFormat( (SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1893" ": "), "OSL_ASSERT: %s", "0"); } } while (((sal_Bool )0)); } while (0); | |||
| 1894 | ||||
| 1895 | while ( ( pLine=OslProfile_getLine(pFile) ) != 0 ) | |||
| 1896 | { | |||
| 1897 | bWasAdded = addLine( pProfile, pLine ); | |||
| 1898 | rtl_freeMemory( pLine ); | |||
| 1899 | OSL_ASSERT(bWasAdded)do { if (((sal_Bool)1) && (!(bWasAdded))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1899" ": "), "OSL_ASSERT: %s", "bWasAdded"); } } while ( ((sal_Bool)0)); | |||
| 1900 | if ( ! bWasAdded ) | |||
| 1901 | return (sal_False((sal_Bool)0)); | |||
| 1902 | } | |||
| 1903 | ||||
| 1904 | for (i = 0; i < pProfile->m_NoLines; i++) | |||
| 1905 | { | |||
| 1906 | pStr = (sal_Char *)stripBlanks(pProfile->m_Lines[i], NULL((void*)0)); | |||
| 1907 | ||||
| 1908 | if ((*pStr == '\0') || (*pStr == ';')) | |||
| 1909 | continue; | |||
| 1910 | ||||
| 1911 | if ((*pStr != '[') || ((pChar = strrchr(pStr, ']')) == NULL((void*)0)) || | |||
| 1912 | ((pChar - pStr) <= 2)) | |||
| 1913 | { | |||
| 1914 | /* insert entry */ | |||
| 1915 | ||||
| 1916 | if (pProfile->m_NoSections < 1) | |||
| 1917 | continue; | |||
| 1918 | ||||
| 1919 | if ((pChar = strchr(pStr, '=')) == NULL((void*)0)) | |||
| 1920 | pChar = pStr + strlen(pStr); | |||
| 1921 | ||||
| 1922 | if (! addEntry(pProfile, &pProfile->m_Sections[pProfile->m_NoSections - 1], | |||
| 1923 | i, pStr, pChar - pStr)) | |||
| 1924 | { | |||
| 1925 | OSL_ASSERT(0)do { if (((sal_Bool)1) && (!(0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1925" ": "), "OSL_ASSERT: %s", "0"); } } while (((sal_Bool )0)); | |||
| 1926 | continue; | |||
| 1927 | } | |||
| 1928 | ||||
| 1929 | } | |||
| 1930 | else | |||
| 1931 | { | |||
| 1932 | /* new section */ | |||
| 1933 | ||||
| 1934 | if (! addSection(pProfile, i, pStr + 1, pChar - pStr - 1)) | |||
| 1935 | { | |||
| 1936 | OSL_ASSERT(0)do { if (((sal_Bool)1) && (!(0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1936" ": "), "OSL_ASSERT: %s", "0"); } } while (((sal_Bool )0)); | |||
| 1937 | continue; | |||
| 1938 | } | |||
| 1939 | ||||
| 1940 | } | |||
| 1941 | } | |||
| 1942 | ||||
| 1943 | return (sal_True((sal_Bool)1)); | |||
| 1944 | } | |||
| 1945 | ||||
| 1946 | static sal_Bool storeProfile(osl_TProfileImpl* pProfile, sal_Bool bCleanup) | |||
| 1947 | { | |||
| 1948 | #ifdef TRACE_OSL_PROFILE | |||
| 1949 | OSL_TRACE("In storeProfile")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1949" ": "), "In storeProfile"); } } while (((sal_Bool )0)); | |||
| 1950 | #endif | |||
| 1951 | ||||
| 1952 | if (pProfile->m_Lines != NULL((void*)0)) | |||
| 1953 | { | |||
| 1954 | if (pProfile->m_Flags & FLG_MODIFIED0x0200) | |||
| 1955 | { | |||
| 1956 | sal_uInt32 i; | |||
| 1957 | ||||
| 1958 | osl_TFile* pTmpFile = osl_openTmpProfileImpl(pProfile); | |||
| 1959 | ||||
| 1960 | if ( pTmpFile == 0 ) | |||
| 1961 | { | |||
| 1962 | return sal_False((sal_Bool)0); | |||
| 1963 | } | |||
| 1964 | ||||
| 1965 | OSL_VERIFY(OslProfile_rewindFile(pTmpFile, sal_True))do { if (!(OslProfile_rewindFile(pTmpFile, ((sal_Bool)1)))) do { if (((sal_Bool)1) && (!(0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1965" ": "), "OSL_ASSERT: %s", "0"); } } while (((sal_Bool )0)); } while (0); | |||
| 1966 | ||||
| 1967 | for ( i = 0 ; i < pProfile->m_NoLines ; i++ ) | |||
| 1968 | { | |||
| 1969 | OSL_VERIFY(OslProfile_putLine(pTmpFile, pProfile->m_Lines[i]))do { if (!(OslProfile_putLine(pTmpFile, pProfile->m_Lines[ i]))) do { if (((sal_Bool)1) && (!(0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1969" ": "), "OSL_ASSERT: %s", "0"); } } while (((sal_Bool )0)); } while (0); | |||
| 1970 | } | |||
| 1971 | ||||
| 1972 | if ( ! writeProfileImpl(pTmpFile) ) | |||
| 1973 | { | |||
| 1974 | if ( pTmpFile->m_pWriteBuf != 0 ) | |||
| 1975 | { | |||
| 1976 | free(pTmpFile->m_pWriteBuf); | |||
| 1977 | } | |||
| 1978 | ||||
| 1979 | pTmpFile->m_pWriteBuf=0; | |||
| 1980 | pTmpFile->m_nWriteBufLen=0; | |||
| 1981 | pTmpFile->m_nWriteBufFree=0; | |||
| 1982 | ||||
| 1983 | #ifdef TRACE_OSL_PROFILE | |||
| 1984 | OSL_TRACE("Out storeProfile [not flushed]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "1984" ": "), "Out storeProfile [not flushed]"); } } while (((sal_Bool)0)); | |||
| 1985 | #endif | |||
| 1986 | closeFileImpl(pTmpFile,pProfile->m_Flags); | |||
| 1987 | ||||
| 1988 | return sal_False((sal_Bool)0); | |||
| 1989 | } | |||
| 1990 | ||||
| 1991 | pProfile->m_Flags &= ~FLG_MODIFIED0x0200; | |||
| 1992 | ||||
| 1993 | closeFileImpl(pProfile->m_pFile,pProfile->m_Flags); | |||
| 1994 | closeFileImpl(pTmpFile,pProfile->m_Flags); | |||
| 1995 | ||||
| 1996 | osl_ProfileSwapProfileNames(pProfile); | |||
| 1997 | ||||
| 1998 | pProfile->m_pFile = openFileImpl(pProfile->m_FileName,pProfile->m_Flags); | |||
| 1999 | ||||
| 2000 | } | |||
| 2001 | ||||
| 2002 | if (bCleanup) | |||
| 2003 | { | |||
| 2004 | while (pProfile->m_NoLines > 0) | |||
| 2005 | removeLine(pProfile, pProfile->m_NoLines - 1); | |||
| 2006 | ||||
| 2007 | free(pProfile->m_Lines); | |||
| 2008 | pProfile->m_Lines = NULL((void*)0); | |||
| 2009 | pProfile->m_NoLines = 0; | |||
| 2010 | pProfile->m_MaxLines = 0; | |||
| 2011 | ||||
| 2012 | while (pProfile->m_NoSections > 0) | |||
| 2013 | removeSection(pProfile, &pProfile->m_Sections[pProfile->m_NoSections - 1]); | |||
| 2014 | ||||
| 2015 | free(pProfile->m_Sections); | |||
| 2016 | pProfile->m_Sections = NULL((void*)0); | |||
| 2017 | pProfile->m_NoSections = 0; | |||
| 2018 | pProfile->m_MaxSections = 0; | |||
| 2019 | } | |||
| 2020 | } | |||
| 2021 | ||||
| 2022 | #ifdef TRACE_OSL_PROFILE | |||
| 2023 | OSL_TRACE("Out storeProfile [ok]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "2023" ": "), "Out storeProfile [ok]"); } } while (((sal_Bool )0)); | |||
| 2024 | #endif | |||
| 2025 | return (sal_True((sal_Bool)1)); | |||
| 2026 | } | |||
| 2027 | ||||
| 2028 | ||||
| 2029 | static osl_TFile* osl_openTmpProfileImpl(osl_TProfileImpl* pProfile) | |||
| 2030 | { | |||
| 2031 | osl_TFile* pFile=0; | |||
| 2032 | sal_Char* pszExtension = "tmp"; | |||
| 2033 | sal_Char pszTmpName[PATH_MAX4096]; | |||
| 2034 | oslProfileOption PFlags=0; | |||
| 2035 | ||||
| 2036 | pszTmpName[0] = '\0'; | |||
| 2037 | ||||
| 2038 | /* generate tmp profilename */ | |||
| 2039 | osl_ProfileGenerateExtension(pProfile->m_FileName,pszExtension,pszTmpName); | |||
| 2040 | ||||
| 2041 | if ( pszTmpName[0] == 0 ) | |||
| 2042 | { | |||
| 2043 | return 0; | |||
| 2044 | } | |||
| 2045 | ||||
| 2046 | if ( ! ( pProfile->m_Flags & osl_Profile_READLOCK0x0002 ) ) | |||
| 2047 | { | |||
| 2048 | PFlags |= osl_Profile_WRITELOCK0x0004; | |||
| 2049 | } | |||
| 2050 | ||||
| 2051 | /* open this file */ | |||
| 2052 | pFile = openFileImpl(pszTmpName,pProfile->m_Flags | PFlags); | |||
| 2053 | ||||
| 2054 | ||||
| 2055 | /* return new pFile */ | |||
| 2056 | return pFile; | |||
| 2057 | } | |||
| 2058 | ||||
| 2059 | static sal_Bool osl_ProfileSwapProfileNames(osl_TProfileImpl* pProfile) | |||
| 2060 | { | |||
| 2061 | sal_Bool bRet = sal_False((sal_Bool)0); | |||
| 2062 | ||||
| 2063 | sal_Char pszBakFile[PATH_MAX4096]; | |||
| 2064 | sal_Char pszTmpFile[PATH_MAX4096]; | |||
| 2065 | sal_Char pszIniFile[PATH_MAX4096]; | |||
| 2066 | ||||
| 2067 | pszBakFile[0] = '\0'; | |||
| 2068 | pszTmpFile[0] = '\0'; | |||
| 2069 | pszIniFile[0] = '\0'; | |||
| 2070 | ||||
| 2071 | osl_ProfileGenerateExtension(pProfile->m_FileName,"bak",pszBakFile); | |||
| 2072 | ||||
| 2073 | strcpy(pszIniFile,pProfile->m_FileName); | |||
| 2074 | ||||
| 2075 | osl_ProfileGenerateExtension(pProfile->m_FileName,"tmp",pszTmpFile); | |||
| 2076 | ||||
| 2077 | /* unlink bak */ | |||
| 2078 | unlink( pszBakFile ); | |||
| 2079 | ||||
| 2080 | /* rename ini bak */ | |||
| 2081 | rename( pszIniFile, pszBakFile ); | |||
| 2082 | ||||
| 2083 | /* rename tmp ini */ | |||
| 2084 | rename( pszTmpFile, pszIniFile ); | |||
| 2085 | ||||
| 2086 | return bRet; | |||
| 2087 | } | |||
| 2088 | ||||
| 2089 | ||||
| 2090 | static void osl_ProfileGenerateExtension(sal_Char* pszFileName, sal_Char* pszExtension, sal_Char* pszTmpName) | |||
| 2091 | { | |||
| 2092 | ||||
| 2093 | strcpy(pszTmpName,pszFileName); | |||
| 2094 | strcat(pszTmpName,"."); | |||
| 2095 | strcat(pszTmpName,pszExtension); | |||
| 2096 | ||||
| 2097 | return; | |||
| 2098 | } | |||
| 2099 | ||||
| 2100 | ||||
| 2101 | static osl_TProfileImpl* acquireProfile(oslProfile Profile, sal_Bool bWriteable) | |||
| 2102 | { | |||
| 2103 | osl_TProfileImpl* pProfile = (osl_TProfileImpl*)Profile; | |||
| 2104 | oslProfileOption PFlags=0; | |||
| 2105 | ||||
| 2106 | if ( bWriteable ) | |||
| 2107 | { | |||
| 2108 | PFlags = osl_Profile_DEFAULT0x0000 | osl_Profile_WRITELOCK0x0004; | |||
| 2109 | } | |||
| 2110 | else | |||
| 2111 | { | |||
| 2112 | PFlags = osl_Profile_DEFAULT0x0000; | |||
| 2113 | } | |||
| 2114 | ||||
| 2115 | ||||
| 2116 | if (pProfile == NULL((void*)0)) | |||
| 2117 | { | |||
| 2118 | #ifdef DEBUG_OSL_PROFILE | |||
| 2119 | OSL_TRACE("AUTOOPEN MODE")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "2119" ": "), "AUTOOPEN MODE"); } } while (((sal_Bool)0) ); | |||
| 2120 | #endif | |||
| 2121 | ||||
| 2122 | if ( ( pProfile = (osl_TProfileImpl*) osl_openProfile(0, PFlags ) ) != NULL((void*)0) ) | |||
| 2123 | { | |||
| 2124 | pProfile->m_Flags |= FLG_AUTOOPEN0x0100; | |||
| 2125 | } | |||
| 2126 | } | |||
| 2127 | else | |||
| 2128 | { | |||
| 2129 | #ifdef DEBUG_OSL_PROFILE | |||
| 2130 | OSL_TRACE("try to acquire")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "2130" ": "), "try to acquire"); } } while (((sal_Bool)0 )); | |||
| 2131 | #endif | |||
| 2132 | ||||
| 2133 | if (! (pProfile->m_Flags & osl_Profile_SYSTEM0x0001)) | |||
| 2134 | { | |||
| 2135 | if (! (pProfile->m_Flags & (osl_Profile_READLOCK0x0002 | osl_Profile_WRITELOCK0x0004 | osl_Profile_FLUSHWRITE0x0010 ))) | |||
| 2136 | { | |||
| 2137 | osl_TStamp Stamp; | |||
| 2138 | ||||
| 2139 | #ifdef DEBUG_OSL_PROFILE | |||
| 2140 | OSL_TRACE("Profile acquire DEFAULT MODE")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "2140" ": "), "Profile acquire DEFAULT MODE"); } } while (((sal_Bool)0)); | |||
| 2141 | #endif | |||
| 2142 | if (! (pProfile->m_pFile = openFileImpl(pProfile->m_FileName, pProfile->m_Flags | PFlags ))) | |||
| 2143 | return NULL((void*)0); | |||
| 2144 | ||||
| 2145 | Stamp = OslProfile_getFileStamp(pProfile->m_pFile); | |||
| 2146 | ||||
| 2147 | if (memcmp(&Stamp, &(pProfile->m_Stamp), sizeof(osl_TStamp))) | |||
| 2148 | { | |||
| 2149 | sal_Bool bRet=sal_False((sal_Bool)0); | |||
| 2150 | ||||
| 2151 | pProfile->m_Stamp = Stamp; | |||
| 2152 | ||||
| 2153 | bRet=loadProfile(pProfile->m_pFile, pProfile); | |||
| 2154 | OSL_ASSERT(bRet)do { if (((sal_Bool)1) && (!(bRet))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "2154" ": "), "OSL_ASSERT: %s", "bRet"); } } while (((sal_Bool )0)); | |||
| 2155 | (void)bRet; | |||
| 2156 | } | |||
| 2157 | } | |||
| 2158 | else | |||
| 2159 | { | |||
| 2160 | #ifdef DEBUG_OSL_PROFILE | |||
| 2161 | OSL_TRACE("Profile acquire READ/WRITELOCK MODE")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "2161" ": "), "Profile acquire READ/WRITELOCK MODE"); } } while (((sal_Bool)0)); | |||
| 2162 | #endif | |||
| 2163 | /* A readlock file could not be written */ | |||
| 2164 | if ((pProfile->m_Flags & osl_Profile_READLOCK0x0002) && bWriteable) | |||
| 2165 | { | |||
| 2166 | return (NULL((void*)0)); | |||
| 2167 | } | |||
| 2168 | } | |||
| 2169 | } | |||
| 2170 | } | |||
| 2171 | ||||
| 2172 | return (pProfile); | |||
| 2173 | } | |||
| 2174 | ||||
| 2175 | static sal_Bool releaseProfile(osl_TProfileImpl* pProfile) | |||
| 2176 | { | |||
| 2177 | #ifdef TRACE_OSL_PROFILE | |||
| 2178 | OSL_TRACE("In releaseProfile")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "2178" ": "), "In releaseProfile"); } } while (((sal_Bool )0)); | |||
| 2179 | #endif | |||
| 2180 | ||||
| 2181 | if ( pProfile == 0 ) | |||
| 2182 | { | |||
| 2183 | #ifdef TRACE_OSL_PROFILE | |||
| 2184 | OSL_TRACE("Out releaseProfile [profile==0]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "2184" ": "), "Out releaseProfile [profile==0]"); } } while (((sal_Bool)0)); | |||
| 2185 | #endif | |||
| 2186 | return sal_False((sal_Bool)0); | |||
| 2187 | } | |||
| 2188 | ||||
| 2189 | if (pProfile->m_Flags & FLG_AUTOOPEN0x0100) | |||
| 2190 | { | |||
| 2191 | #ifdef TRACE_OSL_PROFILE | |||
| 2192 | OSL_TRACE("Out releaseProfile [AUTOOPEN]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "2192" ": "), "Out releaseProfile [AUTOOPEN]"); } } while (((sal_Bool)0)); | |||
| 2193 | #endif | |||
| 2194 | return (osl_closeProfile((oslProfile)pProfile)); | |||
| 2195 | } | |||
| 2196 | else | |||
| 2197 | { | |||
| 2198 | #ifdef DEBUG_OSL_PROFILE | |||
| 2199 | OSL_TRACE("DEFAULT MODE")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "2199" ": "), "DEFAULT MODE"); } } while (((sal_Bool)0)); | |||
| 2200 | #endif | |||
| 2201 | if (! (pProfile->m_Flags & (osl_Profile_READLOCK0x0002 | osl_Profile_WRITELOCK0x0004 | osl_Profile_FLUSHWRITE0x0010 ))) | |||
| 2202 | { | |||
| 2203 | if (pProfile->m_Flags & FLG_MODIFIED0x0200) | |||
| 2204 | { | |||
| 2205 | sal_Bool bRet=storeProfile(pProfile, sal_False((sal_Bool)0)); | |||
| 2206 | OSL_ASSERT(bRet)do { if (((sal_Bool)1) && (!(bRet))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "2206" ": "), "OSL_ASSERT: %s", "bRet"); } } while (((sal_Bool )0)); | |||
| 2207 | (void)bRet; | |||
| 2208 | } | |||
| 2209 | ||||
| 2210 | closeFileImpl(pProfile->m_pFile,pProfile->m_Flags); | |||
| 2211 | pProfile->m_pFile = NULL((void*)0); | |||
| 2212 | } | |||
| 2213 | } | |||
| 2214 | ||||
| 2215 | #ifdef TRACE_OSL_PROFILE | |||
| 2216 | OSL_TRACE("Out releaseProfile [ok]")do { if (((sal_Bool)1) && (1 > 0)) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/profile.c" ":" "2216" ": "), "Out releaseProfile [ok]"); } } while (((sal_Bool )0)); | |||
| 2217 | #endif | |||
| 2218 | return (sal_True((sal_Bool)1)); | |||
| 2219 | } | |||
| 2220 | ||||
| 2221 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |