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