Changeset 31 for box/nick


Ignore:
Timestamp:
24/10/2005 19:44:10 (7 years ago)
Author:
nick
Message:

update world - should be all the same now

Location:
box/nick/win
Files:
7 added
47 edited

Legend:

Unmodified
Added
Removed
  • box/nick/win/infrastructure/makebuildenv.pl

    r19 r31  
    11#!/usr/bin/perl 
    22use strict; 
     3use Symbol; 
    34 
    45my @modules; 
     
    323324# seed autogen code 
    324325print "Seeding autogen code...\n"; 
    325 open FINDAUTOGEN,"find . -name Makefile.extra |" or die "Can't use find for locating files"; 
     326open FINDAUTOGEN,"find . -follow -name Makefile.extra |" or die "Can't use find for locating files"; 
    326327while(<FINDAUTOGEN>) 
    327328{ 
     
    396397$extra_platform_defines .= ' -DPLATFORM_GCC3' if $gcc_v3; 
    397398 
    398 # read in module definitions file and prepare directories 
    399 open MODULES,"modules.txt" or die "Can't open modules file\n"; 
     399# read in module definitions file, and any files it includes 
     400my @modules_files; 
     401sub read_modules_file 
     402{ 
     403        my ($mf) = @_; 
     404        my $f = gensym; 
     405        open $f,$mf or die "Can't open modules file '$mf'\n"; 
     406        while(<$f>) 
     407        { 
     408                if(m/\AINCLUDE\s+(\S+)\Z/) 
     409                { 
     410                        # include another file 
     411                        read_modules_file($1) 
     412                } 
     413                else 
     414                { 
     415                        push @modules_files,$_ 
     416                } 
     417        } 
     418        close $f; 
     419} 
     420read_modules_file('modules.txt'); 
    400421 
    401422# prepare directories... 
     
    403424mkdir "debug",0755; 
    404425 
     426# is the library code in another directory? 
     427my $external_lib = readlink('lib'); 
     428if($external_lib ne '') 
     429{ 
     430        # adjust to root of the library distribution 
     431        $external_lib =~ s!/lib\Z!!; 
     432        $external_lib = '../'.$external_lib; 
     433        # make symlinks 
     434        make_obj_symlink('debug'); 
     435        make_obj_symlink('release'); 
     436} 
     437sub make_obj_symlink 
     438{ 
     439        my $m = $_[0]; 
     440        my $target = $external_lib."/$m/lib/"; 
     441        my $link = "$m/lib"; 
     442        # check link 
     443        if(-e $link) 
     444        { 
     445                if(-l $link) 
     446                { 
     447                        if(readlink($link) ne $target) 
     448                        { 
     449                                print "Warning: replacing $link with new link to $target\n"; 
     450                                unlink $link; 
     451                        } 
     452                } 
     453                else 
     454                { 
     455                        die "$link already exists, but it isn't a symbolic link" 
     456                } 
     457        } 
     458        if(!-e $link) 
     459        { 
     460                symlink $target,$link or die "Can't make $m/lib symlink"; 
     461        } 
     462} 
     463 
    405464print "Scanning code...\n"; 
    406465 
    407466my $modules_omitted = 0; 
    408467 
    409 while(<MODULES>) 
     468# process lines in flattened modules files 
     469for(@modules_files) 
    410470{ 
    411471        # clean up line 
    412         chomp; s/\A\s+//; s/#.+\Z//; s/\s+\Z//; s/\s+/ /g; 
     472        chomp; s/\A\s+//; s/#.*\Z//; s/\s+\Z//; s/\s+/ /g; 
    413473        next unless m/\S/; 
    414474         
     
    484544        $module_library_link_opts{$mod} = [@lo]; 
    485545         
    486         # make directories 
     546        # make directories, but not if we're using an external library and this a library module 
    487547        my ($s,$d) = split /\//,$mod; 
    488         mkdir "release/$s",0755; 
    489         mkdir "release/$s/$d",0755; 
    490         mkdir "debug/$s",0755; 
    491         mkdir "debug/$s/$d",0755; 
    492 } 
    493 close MODULES; 
     548        if($s ne 'lib' || $external_lib eq '') 
     549        { 
     550                mkdir "release/$s",0755; 
     551                mkdir "release/$s/$d",0755; 
     552                mkdir "debug/$s",0755; 
     553                mkdir "debug/$s/$d",0755; 
     554        } 
     555} 
    494556 
    495557# make dirs for implicit dep 
     
    10111073                if(exists $t{'SuccessFlags'}) 
    10121074                { 
    1013                         $env_flags{$_} = 1 for(@{$t{'SuccessFlags'}}) 
     1075                        for(@{$t{'SuccessFlags'}}) 
     1076                        { 
     1077                                my ($k,$v) = split /=>/,$_; 
     1078                                $v = 1 if $v eq ''; 
     1079                                $env_flags{$k} = $v 
     1080                        } 
    10141081                } 
    10151082                $compile_line_extra .= $t{'SuccessCompileFlags'}.' ' if exists $t{'SuccessCompileFlags'}; 
     
    10291096                if(exists $t{'FailureFlags'}) 
    10301097                { 
    1031                         $env_flags{$_} = 1 for(@{$t{'FailureFlags'}}) 
     1098                        for(@{$t{'FailureFlags'}}) 
     1099                        { 
     1100                                my ($k,$v) = split /=>/,$_; 
     1101                                $v = 1 if $v eq ''; 
     1102                                $env_flags{$k} = $v 
     1103                        } 
    10321104                } 
    10331105                $compile_line_extra .= $t{'FailureCompileFlags'}.' ' if exists $t{'FailureCompileFlags'}; 
     
    10351107                $test_failure_text .= $t{'FailureText'} if exists $t{'FailureText'}; 
    10361108        } 
    1037 } 
    1038  
    1039  
    1040  
     1109        $result 
     1110} 
     1111 
     1112 
     1113 
  • box/nick/win/lib/backupclient/BackupClientFileAttributes.cpp

    r19 r31  
    273273// -------------------------------------------------------------------------- 
    274274void BackupClientFileAttributes::ReadAttributes(const char *Filename, bool ZeroModificationTimes, box_time_t *pModTime, 
    275         box_time_t *pAttrModTime, int64_t *pFileSize, ino_t *pInodeNumber, bool *pHasMultipleLinks) 
     275        box_time_t *pAttrModTime, int64_t *pFileSize, InodeRefType *pInodeNumber, bool *pHasMultipleLinks) 
    276276{ 
    277277        StreamableMemBlock *pnewAttr = 0; 
     
    334334                FILL_IN_ATTRIBUTES 
    335335                FILL_IN_ATTRIBUTES_2 
     336 
     337#ifdef WIN32 
     338                //this is to catch those problems with invalid time stamps stored... 
     339                //need to find out the reason why - but also a catch as well. 
     340                 
     341                //__time64_t winTime = BoxTimeToSeconds(pattr->ModificationTime); 
     342 
     343                box_time_t bob = BoxTimeToSeconds(pattr->ModificationTime); 
     344                __time64_t winTime = bob; 
     345                if (_gmtime64(&winTime) == 0 ) 
     346                { 
     347                        ::syslog(LOG_ERR, "Corrupt value in store Modification Time in file %s", Filename); 
     348                        pattr->ModificationTime = 0; 
     349                } 
     350 
     351                bob = BoxTimeToSeconds(pattr->AttrModificationTime); 
     352                winTime = bob; 
     353                if (_gmtime64(&winTime) == 0 ) 
     354                { 
     355                        ::syslog(LOG_ERR, "Corrupt value in store Attr Modification Time in file %s", Filename); 
     356                        pattr->AttrModificationTime = 0; 
     357                } 
     358#endif 
    336359                 
    337360                // Attributes ready. Encrypt into this block 
  • box/nick/win/lib/backupclient/BackupClientFileAttributes.h

    r19 r31  
    4545        void ReadAttributes(const char *Filename, bool ZeroModificationTimes = false, 
    4646                box_time_t *pModTime = 0, box_time_t *pAttrModTime = 0, int64_t *pFileSize = 0, 
    47                 ino_t *pInodeNumber = 0, bool *pHasMultipleLinks = 0); 
     47                InodeRefType *pInodeNumber = 0, bool *pHasMultipleLinks = 0); 
    4848        void WriteAttributes(const char *Filename) const; 
    4949 
  • box/nick/win/lib/backupclient/BackupClientRestore.cpp

    r19 r31  
    1616#include <unistd.h> 
    1717#include <limits.h> 
     18#include <stdio.h> 
    1819 
    1920#include "BackupClientRestore.h" 
     
    224225 
    225226        // Create the local directory (if not already done) -- path and owner set later, just use restrictive owner mode 
    226         if(ObjectExists(rLocalDirectoryName.c_str()) != ObjectExists_Dir) 
    227         { 
    228                 if(::mkdir(rLocalDirectoryName.c_str(), S_IRWXU) != 0) 
    229                 { 
    230                         THROW_EXCEPTION(CommonException, OSFileError); 
    231                 } 
     227        switch(ObjectExists(rLocalDirectoryName.c_str())) 
     228        { 
     229                case ObjectExists_Dir: 
     230                        // Do nothing 
     231                        break; 
     232                case ObjectExists_File: 
     233                        { 
     234                                // File exists with this name, which is fun. Get rid of it. 
     235                                ::printf("WARNING: File present with name '%s', removing out of the way of restored directory. Use specific restore with ID to restore this object.", rLocalDirectoryName.c_str()); 
     236                                if(::unlink(rLocalDirectoryName.c_str()) != 0) 
     237                                { 
     238                                        THROW_EXCEPTION(CommonException, OSFileError); 
     239                                } 
     240                                TRACE1("In restore, directory name collision with file %s", rLocalDirectoryName.c_str()); 
     241                        } 
     242                        // follow through to... (no break) 
     243                case ObjectExists_NoObject: 
     244                        if(::mkdir(rLocalDirectoryName.c_str(), S_IRWXU) != 0) 
     245                        { 
     246                                THROW_EXCEPTION(CommonException, OSFileError); 
     247                        } 
     248                        break; 
     249                default: 
     250                        ASSERT(false); 
     251                        break; 
    232252        } 
    233253         
  • box/nick/win/lib/backupclient/BackupDaemonConfigVerify.cpp

    r19 r31  
    8585 
    8686        {"CommandSocket", 0, 0, 0},                             // not compulsory to have this 
     87        {"StoreObjectInfoFile", 0, 0, 0},                               // optional 
     88        {"KeepAliveTime", 0, ConfigTest_IsInt, 0},                              // optional 
    8789 
    8890        {"NotifyScript", 0, 0, 0},                              // optional script to run when backup needs attention, eg store full 
  • box/nick/win/lib/backupclient/BackupStoreDirectory.h

    r19 r31  
    182182                        return (*(i++)); 
    183183                } 
    184          
     184 
     185                // WARNING: This function is really very inefficient. 
     186                // Only use when you want to look up ONE filename, not in a loop looking up lots. 
     187                // In a looping situation, cache the decrypted filenames in another memory structure. 
    185188                BackupStoreDirectory::Entry *FindMatchingClearName(const BackupStoreFilenameClear &rFilename, int16_t FlagsMustBeSet = Entry::Flags_INCLUDE_EVERYTHING, int16_t FlagsNotToBeSet = Entry::Flags_EXCLUDE_NOTHING) 
    186189                { 
  • box/nick/win/lib/backupclient/BackupStoreFile.cpp

    r19 r31  
    1414#include <string.h> 
    1515#include <new> 
     16#include <string.h> 
    1617#ifndef BOX_DISABLE_BACKWARDS_COMPATIBILITY_BACKUPSTOREFILE 
    1718        #include <syslog.h> 
     
    366367        if(mpEncodedData) 
    367368        { 
    368                 ::free(mpEncodedData); 
     369                BackupStoreFile::CodingChunkFree(mpEncodedData); 
    369370        } 
    370371        if(mpClearData) 
     
    531532                 
    532533                // Allocate those blocks! 
    533                 mpEncodedData = (uint8_t*)::malloc(maxEncodedDataSize + 32); 
     534                mpEncodedData = (uint8_t*)BackupStoreFile::CodingChunkAlloc(maxEncodedDataSize + 32); 
    534535 
    535536                // Allocate the block for the clear data, using the hint from the header. 
     
    913914// 
    914915// Function 
    915 //              Name:    BackupStoreFile::EncodeChunk(const void *, int, void *, int) 
    916 //              Purpose: Encodes a chunk (encryption, possible encrypted beforehand) 
     916//              Name:    BackupStoreFile::EncodeChunk(const void *, int, BackupStoreFile::EncodingBuffer &) 
     917//              Purpose: Encodes a chunk (encryption, possible compressed beforehand) 
    917918//              Created: 8/12/03 
    918919// 
    919920// -------------------------------------------------------------------------- 
    920 int BackupStoreFile::EncodeChunk(const void *Chunk, int ChunkSize, void *Output, int OutputSize) 
     921int BackupStoreFile::EncodeChunk(const void *Chunk, int ChunkSize, BackupStoreFile::EncodingBuffer &rOutput) 
    921922{ 
    922923        ASSERT(spEncrypt != 0); 
    923924 
    924         // Check there's enough space in the output block 
    925         if(OutputSize < MaxBlockSizeForChunkSize(ChunkSize)) 
    926         { 
    927                 THROW_EXCEPTION(BackupStoreException, OutputSizeTooSmallForChunk) 
    928         } 
    929          
     925        // Check there's some space in the output block 
     926        if(rOutput.mBufferSize < 256) 
     927        { 
     928                rOutput.Reallocate(256); 
     929        } 
     930         
     931        // Check alignment of the block 
     932        ASSERT((((uint32_t)rOutput.mpBuffer) % BACKUPSTOREFILE_CODING_BLOCKSIZE) == BACKUPSTOREFILE_CODING_OFFSET); 
     933 
    930934        // Want to compress it? 
    931935        bool compressChunk = (ChunkSize >= BACKUP_FILE_MIN_COMPRESSED_CHUNK_SIZE); 
     
    936940 
    937941        // Store header 
    938         uint8_t *output = (uint8_t*)Output; 
    939         output[0] = header; 
     942        rOutput.mpBuffer[0] = header; 
    940943        int outOffset = 1; 
    941944 
     
    943946        int ivLen = 0; 
    944947        const void *iv = spEncrypt->SetRandomIV(ivLen); 
    945         ::memcpy(output + outOffset, iv, ivLen); 
     948        ::memcpy(rOutput.mpBuffer + outOffset, iv, ivLen); 
    946949        outOffset += ivLen; 
    947950         
    948951        // Start encryption process 
    949952        spEncrypt->Begin(); 
     953         
     954        #define ENCODECHUNK_CHECK_SPACE(ToEncryptSize)                                                                  \ 
     955                {                                                                                                                                                       \ 
     956                        if((rOutput.mBufferSize - outOffset) < ((ToEncryptSize) + 128))                 \ 
     957                        {                                                                                                                                               \ 
     958                                rOutput.Reallocate(rOutput.mBufferSize + (ToEncryptSize) + 128);        \ 
     959                        }                                                                                                                                               \ 
     960                } 
    950961         
    951962        // Encode the chunk 
     
    966977                        if(s > 0) 
    967978                        { 
    968                                 outOffset += spEncrypt->Transform(output + outOffset, OutputSize - outOffset, buffer, s);                                
     979                                ENCODECHUNK_CHECK_SPACE(s) 
     980                                outOffset += spEncrypt->Transform(rOutput.mpBuffer + outOffset, rOutput.mBufferSize - outOffset, buffer, s);                             
    969981                        } 
    970982                        else 
     
    975987                        } 
    976988                } 
    977                 outOffset += spEncrypt->Final(output + outOffset, OutputSize - outOffset); 
     989                ENCODECHUNK_CHECK_SPACE(16) 
     990                outOffset += spEncrypt->Final(rOutput.mpBuffer + outOffset, rOutput.mBufferSize - outOffset); 
    978991        } 
    979992        else 
    980993        { 
    981994                // Straight encryption 
    982                 outOffset += spEncrypt->Transform(output + outOffset, OutputSize - outOffset, Chunk, ChunkSize); 
    983                 outOffset += spEncrypt->Final(output + outOffset, OutputSize - outOffset); 
    984         } 
    985          
    986         ASSERT(outOffset < OutputSize);         // first check should have sorted this -- merely logic check 
     995                ENCODECHUNK_CHECK_SPACE(ChunkSize) 
     996                outOffset += spEncrypt->Transform(rOutput.mpBuffer + outOffset, rOutput.mBufferSize - outOffset, Chunk, ChunkSize); 
     997                ENCODECHUNK_CHECK_SPACE(16) 
     998                outOffset += spEncrypt->Final(rOutput.mpBuffer + outOffset, rOutput.mBufferSize - outOffset); 
     999        } 
     1000         
     1001        ASSERT(outOffset < rOutput.mBufferSize);                // first check should have sorted this -- merely logic check 
    9871002 
    9881003        return outOffset; 
     
    9951010//              Purpose: Decode an encoded chunk -- use OutputBufferSizeForKnownOutputSize() to find 
    9961011//                               the extra output buffer size needed before calling. 
     1012//                               See notes in EncodeChunk() for notes re alignment of the  
     1013//                               encoded data. 
    9971014//              Created: 8/12/03 
    9981015// 
     
    10001017int BackupStoreFile::DecodeChunk(const void *Encoded, int EncodedSize, void *Output, int OutputSize) 
    10011018{ 
     1019        // Check alignment of the encoded block 
     1020        ASSERT((((uint32_t)Encoded) % BACKUPSTOREFILE_CODING_BLOCKSIZE) == BACKUPSTOREFILE_CODING_OFFSET); 
     1021 
    10021022        // First check 
    10031023        if(EncodedSize < 1) 
     
    13931413} 
    13941414 
     1415 
     1416// -------------------------------------------------------------------------- 
     1417// 
     1418// Function 
     1419//              Name:    BackupStoreFile::EncodingBuffer::EncodingBuffer() 
     1420//              Purpose: Constructor 
     1421//              Created: 25/11/04 
     1422// 
     1423// -------------------------------------------------------------------------- 
     1424BackupStoreFile::EncodingBuffer::EncodingBuffer() 
     1425        : mpBuffer(0), 
     1426          mBufferSize(0) 
     1427{ 
     1428} 
     1429 
     1430 
     1431// -------------------------------------------------------------------------- 
     1432// 
     1433// Function 
     1434//              Name:    BackupStoreFile::EncodingBuffer::~EncodingBuffer() 
     1435//              Purpose: Destructor 
     1436//              Created: 25/11/04 
     1437// 
     1438// -------------------------------------------------------------------------- 
     1439BackupStoreFile::EncodingBuffer::~EncodingBuffer() 
     1440{ 
     1441        if(mpBuffer != 0) 
     1442        { 
     1443                BackupStoreFile::CodingChunkFree(mpBuffer); 
     1444                mpBuffer = 0; 
     1445        } 
     1446} 
     1447 
     1448 
     1449// -------------------------------------------------------------------------- 
     1450// 
     1451// Function 
     1452//              Name:    BackupStoreFile::EncodingBuffer::Allocate(int) 
     1453//              Purpose: Do initial allocation of block 
     1454//              Created: 25/11/04 
     1455// 
     1456// -------------------------------------------------------------------------- 
     1457void BackupStoreFile::EncodingBuffer::Allocate(int Size) 
     1458{ 
     1459        ASSERT(mpBuffer == 0); 
     1460        uint8_t *buffer = (uint8_t*)BackupStoreFile::CodingChunkAlloc(Size); 
     1461        if(buffer == 0) 
     1462        { 
     1463                throw std::bad_alloc(); 
     1464        } 
     1465        mpBuffer = buffer; 
     1466        mBufferSize = Size; 
     1467} 
     1468 
     1469 
     1470// -------------------------------------------------------------------------- 
     1471// 
     1472// Function 
     1473//              Name:    BackupStoreFile::EncodingBuffer::Reallocate(int) 
     1474//              Purpose: Reallocate the block. Try not to call this, it has to copy 
     1475//                               the entire contents as the block can't be reallocated straight. 
     1476//              Created: 25/11/04 
     1477// 
     1478// -------------------------------------------------------------------------- 
     1479void BackupStoreFile::EncodingBuffer::Reallocate(int NewSize) 
     1480{ 
     1481        TRACE2("Reallocating EncodingBuffer from %d to %d\n", mBufferSize, NewSize); 
     1482        ASSERT(mpBuffer != 0); 
     1483        uint8_t *buffer = (uint8_t*)BackupStoreFile::CodingChunkAlloc(NewSize); 
     1484        if(buffer == 0) 
     1485        { 
     1486                throw std::bad_alloc(); 
     1487        } 
     1488        // Copy data 
     1489        ::memcpy(buffer, mpBuffer, (NewSize > mBufferSize)?mBufferSize:NewSize); 
     1490         
     1491        // Free old 
     1492        BackupStoreFile::CodingChunkFree(mpBuffer); 
     1493         
     1494        // Store new buffer 
     1495        mpBuffer = buffer; 
     1496        mBufferSize = NewSize; 
     1497} 
     1498 
     1499 
  • box/nick/win/lib/backupclient/BackupStoreFile.h

    r20 r31  
    2323        int64_t mTotalFileStreamSize; 
    2424} BackupStoreFileStats; 
     25 
     26// BOX_PRIVATE_BEGIN 
     27// Interal builds don't have backwards compatibility 
     28#define BOX_DISABLE_BACKWARDS_COMPATIBILITY_BACKUPSTOREFILE 
     29// BOX_PRIVATE_END 
     30 
     31 
     32// Output buffer to EncodeChunk and input data to DecodeChunk must 
     33// have specific alignment, see function comments. 
     34#define BACKUPSTOREFILE_CODING_BLOCKSIZE                16 
     35#define BACKUPSTOREFILE_CODING_OFFSET                   15 
     36 
     37// Have some memory allocation commands, note closing "Off" at end of file. 
     38#include "MemLeakFindOn.h" 
    2539 
    2640// -------------------------------------------------------------------------- 
     
    106120#endif 
    107121 
    108         // Limits 
    109         static void SetMaximumDiffingTime(int Seconds); 
     122        // Allocation of properly aligning chunks for decoding and encoding chunks 
     123        inline static void *CodingChunkAlloc(int Size) 
     124        { 
     125                uint8_t *a = (uint8_t*)malloc((Size) + (BACKUPSTOREFILE_CODING_BLOCKSIZE * 3)); 
     126                if(a == 0) return 0; 
     127                // Align to main block size 
     128                ASSERT(sizeof(uint32_t) == sizeof(void*));      // make sure casting the right pointer size, will need to fix on platforms with 64 bit pointers 
     129                uint32_t adjustment = BACKUPSTOREFILE_CODING_BLOCKSIZE - (((uint32_t)a) % BACKUPSTOREFILE_CODING_BLOCKSIZE); 
     130                uint8_t *b = (a + adjustment); 
     131                // Store adjustment 
     132                *b = (uint8_t)adjustment; 
     133                // Return offset 
     134                return b + BACKUPSTOREFILE_CODING_OFFSET; 
     135        } 
     136        inline static void CodingChunkFree(void *Block) 
     137        { 
     138                // Check alignment is as expected 
     139                ASSERT(sizeof(uint32_t) == sizeof(void*));      // make sure casting the right pointer size, will need to fix on platforms with 64 bit pointers 
     140                ASSERT((((uint32_t)Block) % BACKUPSTOREFILE_CODING_BLOCKSIZE) == BACKUPSTOREFILE_CODING_OFFSET); 
     141                uint8_t *a = (uint8_t*)Block; 
     142                a -= BACKUPSTOREFILE_CODING_OFFSET; 
     143                // Adjust downwards... 
     144                a -= *a; 
     145                free(a); 
     146        } 
     147 
     148 
     149        // -------------------------------------------------------------------------- 
     150        // 
     151        // Function 
     152        //              Name:    BackupStoreFile::SuspendFileDiff() 
     153        //              Purpose: Notifies BackupStoreFile object that a diff operation should be 
     154        //                               terminated ASAP. Usually called from an external timer. 
     155        // 
     156        //              Created: 12/1/04 
     157        // 
     158        // -------------------------------------------------------------------------- 
     159        static void SuspendFileDiff(); 
    110160 
    111161        // Building blocks 
     162        class EncodingBuffer 
     163        { 
     164        public: 
     165                EncodingBuffer(); 
     166                ~EncodingBuffer(); 
     167        private: 
     168                // No copying 
     169                EncodingBuffer(const EncodingBuffer &); 
     170                EncodingBuffer &operator=(const EncodingBuffer &); 
     171        public: 
     172                void Allocate(int Size); 
     173                void Reallocate(int NewSize); 
     174                 
     175                uint8_t *mpBuffer; 
     176                int mBufferSize; 
     177        }; 
    112178        static int MaxBlockSizeForChunkSize(int ChunkSize); 
    113         static int EncodeChunk(const void *Chunk, int ChunkSize, void *Output, int OutputSize); 
     179        static int EncodeChunk(const void *Chunk, int ChunkSize, BackupStoreFile::EncodingBuffer &rOutput); 
    114180 
    115181        // Caller should know how big the output size is, but also allocate a bit more memory to cover various 
     
    135201}; 
    136202 
     203#include "MemLeakFindOff.h" 
     204 
    137205#endif // BACKUPSTOREFILE__H 
    138206 
  • box/nick/win/lib/backupclient/BackupStoreFileCombine.cpp

    r19 r31  
    322322                } 
    323323                 
    324                 // Free buffer 
    325                 ::free(buffer); 
    326                 buffer = 0; 
     324                // Free buffer, if allocated 
     325                if(buffer != 0) 
     326                { 
     327                        ::free(buffer); 
     328                        buffer = 0; 
     329                } 
    327330        } 
    328331        catch(...) 
  • box/nick/win/lib/backupclient/BackupStoreFileDiff.cpp

    r19 r31  
    1313#include <map> 
    1414#include <signal.h> 
     15#ifdef WIN32 
     16#include <time.h> 
     17#else 
    1518#include <sys/time.h> 
     19#endif 
    1620 
    1721#include "BackupStoreFile.h" 
     
    4549static void GenerateRecipe(BackupStoreFileEncodeStream::Recipe &rRecipe, BlocksAvailableEntry *pIndex, int64_t NumBlocks, std::map<int64_t, int64_t> &rFoundBlocks, int64_t SizeOfInputFile); 
    4650 
    47 // Avoid running on too long with diffs 
    48 static int sMaximumDiffTime = 10;               // maximum time to spend diffing 
     51// control whether a currently active diff should be terminated ASAP 
    4952static bool sDiffTimedOut = false; 
    50 static bool sSetTimerSignelHandler = false; 
    51 static void TimerSignalHandler(int signal); 
    52 static void StartDiffTimer(); 
    53  
    5453 
    5554// -------------------------------------------------------------------------- 
    5655// 
    5756// Function 
    58 //              Name:    BackupStoreFile::SetMaximumDiffingTime(int) 
    59 //              Purpose: Sets the maximum time to spend diffing, in seconds. Time is 
    60 //                               process virutal time. 
    61 //              Created: 19/3/04 
    62 // 
    63 // -------------------------------------------------------------------------- 
    64 void BackupStoreFile::SetMaximumDiffingTime(int Seconds) 
     57//              Name:    BackupStoreFile::SuspendFileDiff() 
     58//              Purpose: Notifies BackupStoreFile object that a diff operation should be 
     59//                               terminated ASAP. Usually called from an external timer. 
     60// 
     61//              Created: 12/1/04 
     62// 
     63// -------------------------------------------------------------------------- 
     64void BackupStoreFile::SuspendFileDiff() 
    6565{ 
    66         sMaximumDiffTime = Seconds; 
    67         TRACE1("Set maximum diffing time to %d seconds\n", Seconds); 
     66        sDiffTimedOut = true; 
    6867} 
    69  
    7068 
    7169// -------------------------------------------------------------------------- 
     
    176174        // Pointer to recipe we're going to create 
    177175        BackupStoreFileEncodeStream::Recipe *precipe = 0; 
    178  
    179         // Start the timeout timer, so that the operation doesn't continue for ever 
    180         StartDiffTimer(); 
    181176         
    182177        try 
     
    471466        BlocksAvailableEntry *pIndex, int64_t NumBlocks, int32_t Sizes[BACKUP_FILE_DIFF_MAX_BLOCK_SIZES]) 
    472467{ 
     468        // reset state in case we got timing/call-order mess-up somewhere else 
     469        sDiffTimedOut = false; 
     470 
    473471        // Allocate the hash lookup table 
    474472        BlocksAvailableEntry **phashTable = (BlocksAvailableEntry **)::malloc(sizeof(BlocksAvailableEntry *) * (64*1024)); 
     
    912910                        { 
    913911                                char b[64]; 
     912#ifdef WIN32 
     913                                sprintf(b, "%8I64d", (int64_t)(rRecipe[e].mpStartBlock - pIndex)); 
     914#else 
    914915                                sprintf(b, "%8lld", (int64_t)(rRecipe[e].mpStartBlock - pIndex)); 
     916#endif 
    915917                                TRACE3("%8lld %s %8lld\n", rRecipe[e].mSpaceBefore, (rRecipe[e].mpStartBlock == 0)?"       -":b, (int64_t)rRecipe[e].mBlocks); 
    916918                        } 
     
    920922#endif 
    921923} 
    922  
    923  
    924 // -------------------------------------------------------------------------- 
    925 // 
    926 // Function 
    927 //              Name:    static TimerSignalHandler(int) 
    928 //              Purpose: Signal handler 
    929 //              Created: 19/3/04 
    930 // 
    931 // -------------------------------------------------------------------------- 
    932 void TimerSignalHandler(int signal) 
    933 { 
    934         sDiffTimedOut = true; 
    935 } 
    936  
    937  
    938 // -------------------------------------------------------------------------- 
    939 // 
    940 // Function 
    941 //              Name:    static StartDiffTimer() 
    942 //              Purpose: Starts the diff timeout timer 
    943 //              Created: 19/3/04 
    944 // 
    945 // -------------------------------------------------------------------------- 
    946 void StartDiffTimer() 
    947 { 
    948         // Set timer signal handler 
    949         if(!sSetTimerSignelHandler) 
    950         { 
    951                 ::signal(SIGVTALRM, TimerSignalHandler); 
    952                 sSetTimerSignelHandler = true; 
    953         } 
    954  
    955         struct itimerval timeout; 
    956         // Don't want this to repeat 
    957         timeout.it_interval.tv_sec = 0; 
    958         timeout.it_interval.tv_usec = 0; 
    959         // Single timeout after the specified number of seconds 
    960         timeout.it_value.tv_sec = sMaximumDiffTime; 
    961         timeout.it_value.tv_usec = 0; 
    962         // Set timer 
    963         if(::setitimer(ITIMER_VIRTUAL, &timeout, NULL) != 0) 
    964         { 
    965                 TRACE0("WARNING: couldn't set diff timeout\n"); 
    966         } 
    967          
    968         // Unset flag (last thing) 
    969         sDiffTimedOut = false; 
    970 } 
    971  
    972  
    973  
  • box/nick/win/lib/backupclient/BackupStoreFileEncodeStream.cpp

    r19 r31  
    5151          mLastBlockSize(0), 
    5252          mpRawBuffer(0), 
    53           mpEncodedBuffer(0), 
    5453          mAllocatedBufferSize(0), 
    5554          mEntryIVBase(0) 
     
    7271                ::free(mpRawBuffer); 
    7372                mpRawBuffer = 0; 
    74         } 
    75         if(mpEncodedBuffer) 
    76         { 
    77                 ::free(mpEncodedBuffer); 
    78                 mpEncodedBuffer = 0; 
    7973        } 
    8074         
     
    212206                        // Then allocate two blocks of this size 
    213207                        mpRawBuffer = (uint8_t*)::malloc(mAllocatedBufferSize); 
    214                         mpEncodedBuffer = (uint8_t*)::malloc(mAllocatedBufferSize); 
    215                         if(mpRawBuffer == 0 || mpEncodedBuffer == 0) 
     208                        if(mpRawBuffer == 0) 
    216209                        { 
    217210                                throw std::bad_alloc(); 
    218211                        } 
     212#ifndef NDEBUG 
     213                        // In debug builds, make sure that the reallocation code is exercised. 
     214                        mEncodedBuffer.Allocate(mAllocatedBufferSize / 4); 
     215#else 
     216                        mEncodedBuffer.Allocate(mAllocatedBufferSize); 
     217#endif 
    219218                } 
    220219                else 
     
    412411                                 
    413412                                // Copy it in 
    414                                 ::memcpy(buffer, mpEncodedBuffer + mPositionInCurrentBlock, s); 
     413                                ::memcpy(buffer, mEncodedBuffer.mpBuffer + mPositionInCurrentBlock, s); 
    415414                                 
    416415                                // Update variables 
     
    535534         
    536535        // Encode it 
    537         mCurrentBlockEncodedSize = BackupStoreFile::EncodeChunk(mpRawBuffer, blockRawSize, mpEncodedBuffer, mAllocatedBufferSize); 
     536        mCurrentBlockEncodedSize = BackupStoreFile::EncodeChunk(mpRawBuffer, blockRawSize, mEncodedBuffer); 
    538537         
    539538        //TRACE2("Encode: Encoded size of block %d is %d\n", (int32_t)mCurrentBlock, (int32_t)mCurrentBlockEncodedSize); 
  • box/nick/win/lib/backupclient/BackupStoreFileEncodeStream.h

    r19 r31  
    1717#include "CollectInBufferStream.h" 
    1818#include "MD5Digest.h" 
     19#include "BackupStoreFile.h" 
    1920 
    2021namespace BackupStoreFileCreation 
     
    115116        // Buffers 
    116117        uint8_t *mpRawBuffer;                           // buffer for raw data 
    117         uint8_t *mpEncodedBuffer;                       // buffer for encoded data 
     118        BackupStoreFile::EncodingBuffer mEncodedBuffer; 
     119                                                                                // buffer for encoded data 
    118120        int32_t mAllocatedBufferSize;           // size of above two allocated blocks 
    119121        uint64_t mEntryIVBase;                          // base for block entry IV 
  • box/nick/win/lib/backupclient/BackupStoreObjectDump.cpp

    r19 r31  
    9797                if((*i)->GetDependsNewer() != 0) 
    9898                { 
     99#ifdef WIN32 
     100                        depends_l += ::sprintf(depends + depends_l, " depNew(%I64x)", (*i)->GetDependsNewer()); 
     101#else 
    99102                        depends_l += ::sprintf(depends + depends_l, " depNew(%llx)", (*i)->GetDependsNewer()); 
     103#endif 
    100104                } 
    101105                if((*i)->GetDependsOlder() != 0) 
    102106                { 
     107#ifdef WIN32 
     108                        depends_l += ::sprintf(depends + depends_l, " depOld(%I64x)", (*i)->GetDependsOlder()); 
     109#else 
    103110                        depends_l += ::sprintf(depends + depends_l, " depOld(%llx)", (*i)->GetDependsOlder()); 
     111#endif 
    104112                } 
    105113 
  • box/nick/win/lib/common/Box.h

    r20 r31  
    8383        #define EXCEPTION_CODENAMES_EXTENDED 
    8484        #define EXCEPTION_CODENAMES_EXTENDED_WITH_DESCRIPTION 
    85  
     85         
     86        // But in private builds, these get disabled 
     87        // BOX_PRIVATE_BEGIN 
     88        #undef EXCEPTION_CODENAMES_EXTENDED 
     89        #undef EXCEPTION_CODENAMES_EXTENDED_WITH_DESCRIPTION 
     90        // BOX_PRIVATE_END 
    8691#endif 
    8792 
  • box/nick/win/lib/common/BoxPlatform.h

    r19 r31  
    1212#define BOXPLATFORM__H 
    1313 
     14#ifdef WIN32 
     15#define DIRECTORY_SEPARATOR                     "\\" 
     16#define DIRECTORY_SEPARATOR_ASCHAR      '\\' 
     17#else 
    1418#define DIRECTORY_SEPARATOR                     "/" 
    1519#define DIRECTORY_SEPARATOR_ASCHAR      '/' 
     20#endif 
    1621 
    1722#define PLATFORM_DEV_NULL                       "/dev/null" 
     
    2631//        -- regex support not available on this platform 
    2732 
    28  
    2933#ifdef PLATFORM_OPENBSD 
    3034 
     
    135139 
    136140        #define PLATFORM_RANDOM_DEVICE  "/dev/urandom" 
     141 
     142        // If large file support is on, can't do the intercepts in the test/raidfile 
     143        #if _FILE_OFFSET_BITS == 64 
     144                #define PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE 
     145        #endif 
    137146 
    138147#endif // PLATFORM_LINUX 
     
    184193#endif // PLATFORM_CYGWIN 
    185194 
     195#ifdef WIN32 
     196 
     197        typedef unsigned __int16 u_int16_t; 
     198        typedef unsigned __int64 u_int64_t; 
     199        typedef unsigned __int64 uint64_t; 
     200        typedef __int64 int64_t; 
     201        typedef unsigned __int32 uint32_t; 
     202        typedef unsigned __int32 u_int32_t; 
     203        typedef __int32 int32_t; 
     204        typedef unsigned __int16 uint16_t; 
     205        typedef __int16 int16_t; 
     206        typedef unsigned __int8 uint8_t; 
     207        typedef __int8 int8_t; 
     208 
     209        typedef unsigned int uid_t; 
     210        typedef unsigned int gid_t; 
     211        typedef int pid_t; 
     212         
     213        #define WIN32_LEAN_AND_MEAN 
     214        #define PLATFORM_BERKELEY_DB_NOT_SUPPORTED 
     215        //#define BERKELY_V4 
     216        //any prefs? - to be changed in the future 
     217        #define COMMAND_PORT 9035 
     218        //#define PLATFORM_REGEX_NOT_SUPPORTED 
     219 
     220        #define PLATFORM_KQUEUE_NOT_SUPPORTED 
     221        #define PLATFORM_dirent_BROKEN_d_type 
     222        #define PLATFORM_stat_SHORT_mtime 
     223        #define PLATFORM_stat_NO_st_flags 
     224        //#define PLATFORM_USES_MTAB_FILE_FOR_MOUNTS 
     225        //#define PLATFORM_open_NO_O_EXLOCK 
     226        #define PLATFORM_sockaddr_NO_len 
     227        #define PLATFORM_NO_BUILT_IN_SWAP64 
     228 
     229    #define PLATFORM_STATIC_TEMP_DIRECTORY_NAME "c:\\tmp" 
     230 
     231        #define PLATFORM_READLINE_NOT_SUPPORTED 
     232        #define PLATFORM_LCHOWN_NOT_SUPPORTED 
     233 
     234        #define INFTIM -1 
     235 
     236        // File listing canonical interesting mount points.   
     237        #define MNTTAB          _PATH_MNTTAB    
     238 
     239        // File listing currently active mount points.   
     240        #define MOUNTED         _PATH_MOUNTED    
     241 
     242        #define __need_FILE 
     243 
     244        // Extra includes 
     245    #include "emu.h" 
     246        //#include <stdint.h> 
     247        #include <stdlib.h> 
     248        //#include <netinet/in.h> 
     249        //#include <sys/socket.h> 
     250    #include <winsock2.h> 
     251        #include <sys/stat.h> 
     252        #include <sys/types.h> 
     253        //#include <dirent.h> 
     254        #include <stdio.h> 
     255        //#include <paths.h> 
     256    #include <time.h> 
     257 
     258        // No easy random entropy source 
     259        #define PLATFORM_RANDOM_DEVICE_NONE 
     260 
     261#endif // WIN32 
    186262 
    187263// Find out if credentials on UNIX sockets can be obtained 
     
    219295 
    220296        #endif 
    221  
     297#elif WIN32 
     298        #define STRUCTURE_PATCKING_FOR_WIRE_USE_HEADERS 
    222299#else 
    223300        compiler not supported! 
    224301#endif 
    225302 
     303//sorry ben I thought the best place was here 
     304//there was a function referencing ino_t which 
     305//is a short on win32 - broke it... 
     306#ifdef WIN32 
     307typedef u_int64_t InodeRefType; 
     308#else 
     309typedef ino_t InodeRefType; 
     310#endif 
    226311 
    227312#endif // BOXPLATFORM__H 
  • box/nick/win/lib/common/BoxPortsAndFiles.h

    r20 r31  
    1313#define BOX_PORT_BASE           2200 
    1414 
     15// BOX_PRIVATE_BEGIN 
     16 
     17// Locator daemon 
     18#define BOX_PORT_BLOCATORD                                      (BOX_PORT_BASE+0) 
     19#define BOX_FILE_BLOCATORD                                      "/etc/box/blocatord.conf" 
     20 
     21// BOX_PRIVATE_END 
     22 
    1523// Backup store daemon 
    1624#define BOX_PORT_BBSTORED                                       (BOX_PORT_BASE+1) 
     
    2028 
    2129// Backup client daemon 
     30#ifdef WIN32 
     31#define BOX_FILE_BBACKUPD_DEFAULT_CONFIG        "C:\\Program Files\\Box Backup\\bbackupd.conf" 
     32#else 
    2233#define BOX_FILE_BBACKUPD_DEFAULT_CONFIG        "/etc/box/bbackupd.conf" 
    23  
     34#endif 
    2435 
    2536// RaidFile conf location efault 
    2637#define BOX_FILE_RAIDFILE_DEFAULT_CONFIG        "/etc/box/raidfile.conf" 
    2738 
     39// BOX_PRIVATE_BEGIN 
     40 
     41// smbpasswd authentication daemon (courier-imap authdaemon compatible) 
     42#define BOX_PORT_BAUTHSMBPWD                            (BOX_PORT_BASE+2) 
     43#define BOX_FILE_BAUTHSMBPWD_DEFAULT_CONFIG     "/etc/box/bauthsmbpwd.conf" 
     44 
     45// Message default config location 
     46#define BOX_FILE_BOXMSG_DEFAULT_CONFIG          "/etc/box/boxmsg.conf" 
     47 
     48// Message daemons 
     49#define BOX_FILE_BMSGD_DEFAULT_CONFIG           "/etc/box/bmsgd.conf" 
     50#define BOX_FILE_BMSGRECVD_DEFAULT_CONFIG       "/etc/box/bmsgrecvd.conf" 
     51#define BOX_PORT_BMSGRECVD                                      (BOX_PORT_BASE+3) 
     52 
     53// BOX_PRIVATE_END 
     54 
    2855#endif // BOXPORTSANDFILES__H 
    2956 
  • box/nick/win/lib/common/BoxTime.h

    r19 r31  
    3232        return ((box_time_t)Seconds * MICRO_SEC_IN_SEC_LL); 
    3333} 
    34 inline int64_t BoxTimeToSeconds(box_time_t Time) 
     34inline box_time_t BoxTimeToSeconds(box_time_t Time) 
    3535{ 
    3636        return Time / MICRO_SEC_IN_SEC_LL; 
    3737} 
    38 inline int64_t BoxTimeToMilliSeconds(box_time_t Time) 
     38inline box_time_t BoxTimeToMilliSeconds(box_time_t Time) 
    3939{ 
    4040        return Time / MILLI_SEC_IN_NANO_SEC_LL; 
  • box/nick/win/lib/common/BoxTimeToText.cpp

    r19 r31  
    2828std::string BoxTimeToISO8601String(box_time_t Time) 
    2929{ 
    30         time_t timeInSecs = (time_t)BoxTimeToSeconds(Time); 
     30#ifdef WIN32 
     31        struct tm *time; 
     32        box_time_t bob = BoxTimeToSeconds(Time); 
     33 
     34        __time64_t winTime = bob; 
     35 
     36        time = _gmtime64(&winTime); 
     37        char str[128];  // more than enough space 
     38         
     39        if ( time == NULL ) 
     40        { 
     41                //::sprintf(str, "%016I64x ", bob); 
     42                return std::string(""); 
     43        } 
     44 
     45         
     46        sprintf(str, "%04d-%02d-%02dT%02d:%02d:%02d", time->tm_year + 1900, 
     47                time->tm_mon + 1, time->tm_mday, time->tm_hour, time->tm_min, time->tm_sec); 
     48 
     49#else 
     50        box_time_t bob = BoxTimeToSeconds(Time); 
     51        time_t timeInSecs = bob; 
     52        //timeInSecs = _time64(NULL); 
    3153        struct tm time; 
    3254        gmtime_r(&timeInSecs, &time); 
     
    3557        sprintf(str, "%04d-%02d-%02dT%02d:%02d:%02d", time.tm_year + 1900, 
    3658                time.tm_mon + 1, time.tm_mday, time.tm_hour, time.tm_min, time.tm_sec); 
    37                  
     59#endif   
    3860        return std::string(str); 
    3961} 
  • box/nick/win/lib/common/BoxTimeToUnix.h

    r19 r31  
    1111#define FILEMODIFICATIONTIMETOTIMEVAL__H 
    1212 
     13#ifdef WIN32 
     14#include <time.h> 
     15#else 
    1316#include <sys/time.h> 
     17#endif 
    1418 
    1519#include "BoxTime.h" 
  • box/nick/win/lib/common/Configuration.cpp

    r19 r31  
    2020#include "MemLeakFindOn.h" 
    2121 
     22#include "FileModificationTime.h" 
     23 
    2224// utility whitespace function 
    2325inline bool iw(int c) 
     
    3032static const bool sValueBooleanValue[] = {true, true, false, false}; 
    3133 
    32  
    33  
    34 // -------------------------------------------------------------------------- 
    35 // 
    36 // Function 
    37 //              Name:    Configuration::Configuration(const std::string &) 
     34// -------------------------------------------------------------------------- 
     35// 
     36// Function 
     37//              Name:    Configuration::Configuration(const std::string &, box_time_t) 
    3838//              Purpose: Constructor 
    3939//              Created: 2003/07/23 
    4040// 
    4141// -------------------------------------------------------------------------- 
    42 Configuration::Configuration(const std::string &rName) 
    43         : mName(rName) 
    44 { 
    45 } 
    46  
     42Configuration::Configuration(const std::string &rName, box_time_t configModTime) 
     43        : mName(rName), mConfigModTime(configModTime) 
     44{ 
     45} 
    4746 
    4847// -------------------------------------------------------------------------- 
     
    5756        : mName(rToCopy.mName), 
    5857          mSubConfigurations(rToCopy.mSubConfigurations), 
    59           mKeys(rToCopy.mKeys) 
     58          mKeys(rToCopy.mKeys), 
     59          mConfigModTime(rToCopy.mConfigModTime) 
    6060{ 
    6161} 
     
    9595        rErrorMsg.erase(); 
    9696         
     97        // Save modification time to be able to distinguish across configuration sets 
     98        struct stat st; 
     99        if(::stat(Filename, &st) != 0) 
     100        { 
     101                THROW_EXCEPTION(CommonException, OSFileError) 
     102        } 
     103 
    97104        // Open the file 
    98105        FileHandleGuard<O_RDONLY> file(Filename); 
     
    102109         
    103110        // Object to create 
    104         Configuration *pconfig = new Configuration(std::string("<root>")); 
     111        Configuration *pconfig = new Configuration(std::string("<root>"), FileModificationTime(st)); 
    105112         
    106113        try 
     
    177184                        { 
    178185                                // New config object 
    179                                 Configuration config(blockName); 
     186                                Configuration config(blockName, rConfig.mConfigModTime); 
    180187                                 
    181188                                // Continue processing into this block 
  • box/nick/win/lib/common/Configuration.h

    r19 r31  
    1616#include <string> 
    1717#include <memory> 
     18 
     19#include "BoxTime.h" 
    1820 
    1921// For defining tests 
     
    5961{ 
    6062private: 
    61         Configuration(const std::string &rName); 
     63        Configuration(const std::string &rName, box_time_t configModTime); 
    6264public: 
    6365        Configuration(const Configuration &rToCopy); 
    6466        ~Configuration(); 
    6567         
     68        box_time_t GetModTime() const { return mConfigModTime; } 
     69 
    6670        enum 
    6771        { 
     
    8993        // Order of keys, not preserved 
    9094        std::map<std::string, std::string> mKeys; 
    91          
     95protected: 
     96        box_time_t mConfigModTime; 
    9297private: 
    9398        static bool LoadInto(Configuration &rConfig, FdGetLine &rGetLine, std::string &rErrorMsg, bool RootLevel); 
  • box/nick/win/lib/common/Conversion.h

    r19 r31  
    8787        } 
    8888         
     89        // Specialise for bool -> string 
     90        template<> 
     91        inline std::string Convert<std::string, bool>(bool From) 
     92        { 
     93                return std::string(From?"true":"false"); 
     94        } 
    8995}; 
    9096 
  • box/nick/win/lib/common/DebugPrintf.cpp

    r19 r31  
    5656        if(BoxDebugTraceToSyslog) 
    5757        { 
     58#ifdef WIN32             
    5859                // Remove trailing '\n', if it's there 
     60                if(r > 0 && text[r-1] == '\n') 
     61                { 
     62 
     63                        text[r-1] = '\0'; 
     64#else 
    5965                if(r > 0 && text[r] == '\n') 
    6066                { 
     67 
    6168                        text[r] = '\0'; 
     69#endif 
    6270                        --r; 
    6371                } 
  • box/nick/win/lib/common/ExcludeList.cpp

    r19 r31  
    99 
    1010#include "Box.h" 
    11  
     11#ifdef WIN32 
     12    #include <boost/regex.hpp> 
     13#else 
    1214#ifndef PLATFORM_REGEX_NOT_SUPPORTED 
    1315        #include <regex.h> 
    1416        #define EXCLUDELIST_IMPLEMENTATION_REGEX_T_DEFINED 
     17#endif 
    1518#endif 
    1619 
     
    4548ExcludeList::~ExcludeList() 
    4649{ 
     50#ifdef WIN32 
     51        //under win32 and boost - we didn't use pointers so all should aotu distruct. 
     52#else 
    4753#ifndef PLATFORM_REGEX_NOT_SUPPORTED 
    4854        // free regex memory 
     
    5561                delete pregex; 
    5662        } 
     63#endif 
    5764#endif 
    5865 
     
    107114void ExcludeList::AddRegexEntries(const std::string &rEntries) 
    108115{ 
     116#ifdef WIN32 
     117        //Under Win32 we use the boost library for the regular expression matching 
     118 
     119        // Split strings up 
     120        std::vector<std::string> ens; 
     121        SplitString(rEntries, Configuration::MultiValueSeparator, ens); 
     122         
     123        // Create and add new regular expressions 
     124        for(std::vector<std::string>::const_iterator i(ens.begin()); i != ens.end(); ++i) 
     125        { 
     126                if(i->size() > 0) 
     127                { 
     128                        try{ 
     129                                boost::regex ourReg(i->c_str()); 
     130                                this->mRegex.push_back(ourReg); 
     131                                // Store in list of regular expression string for Serialize 
     132                                this->mRegexStr.push_back(i->c_str()); 
     133                        } 
     134                        catch(...) 
     135                        { 
     136                                THROW_EXCEPTION(CommonException, BadRegularExpression) 
     137                        } 
     138                } 
     139        } 
     140#else 
    109141#ifndef PLATFORM_REGEX_NOT_SUPPORTED 
    110142 
     
    131163                                // Store in list of regular expressions 
    132164                                mRegex.push_back(pregex); 
     165                                // Store in list of regular expression string for Serialize 
     166                                mRegexStr.push_back(i->c_str()); 
    133167                        } 
    134168                        catch(...) 
     
    142176#else 
    143177        THROW_EXCEPTION(CommonException, RegexNotSupportedOnThisPlatform) 
     178#endif 
    144179#endif 
    145180} 
     
    174209         
    175210        // Check against regular expressions 
     211#ifdef WIN32 
     212        for(std::vector<boost::regex>::const_iterator i(mRegex.begin()); i != mRegex.end(); ++i) 
     213        { 
     214                // Test against this expression 
     215                try 
     216                { 
     217                boost::smatch what; 
     218                if(boost::regex_match(rTest, what, *i, boost::match_extra)) 
     219                { 
     220                        // match happened 
     221                        return true; 
     222                } 
     223                // In all other cases, including an error, just continue to the next expression 
     224                } 
     225                catch(...) 
     226                { 
     227                        //just continue of no match 
     228                } 
     229        } 
     230#else 
    176231#ifndef PLATFORM_REGEX_NOT_SUPPORTED 
    177232        for(std::vector<regex_t *>::const_iterator i(mRegex.begin()); i != mRegex.end(); ++i) 
     
    185240                // In all other cases, including an error, just continue to the next expression 
    186241        } 
     242#endif 
    187243#endif 
    188244 
     
    214270} 
    215271 
    216  
    217          
    218  
    219  
     272// -------------------------------------------------------------------------- 
     273// 
     274// Function 
     275//              Name:    ExcludeList::Deserialize(Archive & rArchive) 
     276//              Purpose: Deserializes this object instance from a stream of bytes, using an Archive abstraction. 
     277// 
     278//              Created: 2005/04/11 
     279// 
     280// -------------------------------------------------------------------------- 
     281void ExcludeList::Deserialize(Archive & rArchive) 
     282{ 
     283        // 
     284        // 
     285        // 
     286        mDefinite.clear(); 
     287 
     288#ifdef WIN32 
     289        //under win32 and boost - we didn't use pointers so all should aotu distruct. 
     290#else 
     291#ifndef PLATFORM_REGEX_NOT_SUPPORTED 
     292        // free regex memory 
     293        while(mRegex.size() > 0) 
     294        { 
     295                regex_t *pregex = mRegex.back(); 
     296                mRegex.pop_back(); 
     297                // Free regex storage, and the structure itself 
     298                ::regfree(pregex); 
     299                delete pregex; 
     300        } 
     301 
     302        mRegexStr.clear(); 
     303#endif 
     304#endif 
     305 
     306        // Clean up exceptions list 
     307        if(mpAlwaysInclude != 0) 
     308        { 
     309                delete mpAlwaysInclude; 
     310                mpAlwaysInclude = 0; 
     311        } 
     312 
     313        // 
     314        // 
     315        // 
     316        int64_t iCount = 0; 
     317        rArchive.Get(iCount); 
     318 
     319        if (iCount > 0) 
     320        { 
     321                for (int v = 0; v < iCount; v++) 
     322                { 
     323                        std::string strItem; 
     324                        rArchive.Get(strItem); 
     325 
     326                        /**** LOAD ****/ mDefinite.insert(strItem); 
     327                } 
     328        } 
     329 
     330        // 
     331        // 
     332        // 
     333#ifndef PLATFORM_REGEX_NOT_SUPPORTED 
     334        rArchive.Get(iCount); 
     335 
     336        if (iCount > 0) 
     337        { 
     338                for (int v = 0; v < iCount; v++) 
     339                { 
     340                        std::string strItem; 
     341                        rArchive.Get(strItem); 
     342 
     343#ifdef WIN32 
     344                        try 
     345                        { 
     346                                boost::regex ourReg(strItem.c_str()); 
     347                                this->mRegex.push_back(ourReg); 
     348                                // Store in list of regular expression string for Serialize 
     349                                /**** LOAD ****/ this->mRegexStr.push_back(strItem); 
     350                        } 
     351                        catch(...) 
     352                        { 
     353                                THROW_EXCEPTION(CommonException, BadRegularExpression) 
     354                        } 
     355#else 
     356                        // Allocate memory 
     357                        regex_t* pregex = new regex_t; 
     358                         
     359                        try 
     360                        { 
     361                                // Compile 
     362                                if(::regcomp(pregex, strItem.c_str(), REG_EXTENDED | REG_NOSUB) != 0) 
     363                                { 
     364                                        THROW_EXCEPTION(CommonException, BadRegularExpression) 
     365                                } 
     366                                 
     367                                // Store in list of regular expressions 
     368                                /**** LOAD ****/ mRegex.push_back(pregex); 
     369                                // Store in list of regular expression string for Serialize 
     370                                /**** LOAD ****/ mRegexStr.push_back(strItem); 
     371                        } 
     372                        catch(...) 
     373                        { 
     374                                delete pregex; 
     375                                throw; 
     376                        } 
     377#endif 
     378                } 
     379        } 
     380#endif // PLATFORM_REGEX_NOT_SUPPORTED 
     381 
     382        // 
     383        // 
     384        // 
     385        int64_t aMagicMarker = 0; 
     386        rArchive.Get(aMagicMarker); 
     387 
     388        if (aMagicMarker == ARCHIVE_MAGIC_VALUE_NOOP) 
     389        { 
     390                // NOOP 
     391        } 
     392        else if (aMagicMarker == ARCHIVE_MAGIC_VALUE_RECURSE) 
     393        { 
     394                /**** LOAD ****/ mpAlwaysInclude = new ExcludeList; 
     395                if (!mpAlwaysInclude) 
     396                        throw std::bad_alloc(); 
     397 
     398                mpAlwaysInclude->Deserialize(rArchive); 
     399        } 
     400        else 
     401        { 
     402                // there is something going on here 
     403                THROW_EXCEPTION(CommonException, Internal) 
     404        } 
     405} 
     406 
     407// -------------------------------------------------------------------------- 
     408// 
     409// Function 
     410//              Name:    ExcludeList::Serialize(Archive & rArchive) 
     411//              Purpose: Serializes this object instance into a stream of bytes, using an Archive abstraction. 
     412// 
     413//              Created: 2005/04/11 
     414// 
     415// -------------------------------------------------------------------------- 
     416void ExcludeList::Serialize(Archive & rArchive) const 
     417{ 
     418        // 
     419        // 
     420        // 
     421        int64_t iCount = mDefinite.size(); 
     422        rArchive.Add(iCount); 
     423 
     424        for (std::set<std::string>::const_iterator i = mDefinite.begin(); i != mDefinite.end(); i++) 
     425                rArchive.Add(*i); 
     426 
     427        // 
     428        // 
     429        // 
     430#ifndef PLATFORM_REGEX_NOT_SUPPORTED 
     431        ASSERT(mRegex.size() == mRegexStr.size());      // don't even try to save compiled regular expressions - use string copies 
     432 
     433        iCount = mRegexStr.size(); 
     434        rArchive.Add(iCount); 
     435 
     436        for (std::vector<std::string>::const_iterator i = mRegexStr.begin(); i != mRegexStr.end(); i++) 
     437                rArchive.Add(*i); 
     438#endif // PLATFORM_REGEX_NOT_SUPPORTED 
     439 
     440        // 
     441        // 
     442        // 
     443        if (!mpAlwaysInclude) 
     444        { 
     445                int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_NOOP; 
     446                rArchive.Add(aMagicMarker); 
     447        } 
     448        else 
     449        { 
     450                int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_RECURSE; // be explicit about whether recursion follows 
     451                rArchive.Add(aMagicMarker); 
     452 
     453                mpAlwaysInclude->Serialize(rArchive); 
     454        } 
     455} 
  • box/nick/win/lib/common/ExcludeList.h

    r19 r31  
    1515#include <vector> 
    1616 
     17#ifdef WIN32 
     18#include <boost/regex.hpp> 
     19#else 
    1720// avoid including regex.h in lots of places 
    1821#ifndef EXCLUDELIST_IMPLEMENTATION_REGEX_T_DEFINED 
    1922        typedef int regex_t; 
    2023#endif 
     24#endif 
     25#include "Archive.h" 
    2126 
    2227// -------------------------------------------------------------------------- 
     
    3439        ~ExcludeList(); 
    3540 
     41        void Deserialize(Archive & rArchive); 
     42        void Serialize(Archive & rArchive) const; 
     43 
    3644        void AddDefiniteEntries(const std::string &rEntries); 
    3745        void AddRegexEntries(const std::string &rEntries); 
     
    4654        unsigned int SizeOfDefiniteList() const {return mDefinite.size();} 
    4755        unsigned int SizeOfRegexList() const 
     56#ifdef WIN32 
     57                //lets be explicit in this 
     58                {return mRegex.size();} 
     59#else 
    4860#ifndef PLATFORM_REGEX_NOT_SUPPORTED 
    4961                {return mRegex.size();} 
     
    5163                {return 0;} 
    5264#endif 
     65#endif 
    5366 
    5467private: 
    5568        std::set<std::string> mDefinite; 
     69 
     70#ifdef WIN32 
     71        std::vector<boost::regex> mRegex; 
     72        std::vector<std::string> mRegexStr; 
     73#else 
    5674#ifndef PLATFORM_REGEX_NOT_SUPPORTED 
    5775        std::vector<regex_t *> mRegex; 
     76        std::vector<std::string> mRegexStr;     // save original regular expression string-based source for Serialize 
     77#endif 
    5878#endif 
    5979 
  • box/nick/win/lib/common/FileStream.cpp

    r19 r31  
    2323// -------------------------------------------------------------------------- 
    2424FileStream::FileStream(const char *Filename, int flags, int mode) 
     25#ifdef WIN32 
     26        : mOSFileHandle(::openfile(Filename, flags, mode)), 
     27#else 
    2528        : mOSFileHandle(::open(Filename, flags, mode)), 
     29#endif 
    2630          mIsEOF(false) 
    2731{ 
     32#ifdef WIN32 
     33        if(mOSFileHandle == 0) 
     34#else 
    2835        if(mOSFileHandle < 0) 
     36#endif 
    2937        { 
    3038                MEMLEAKFINDER_NOT_A_LEAK(this); 
    3139                THROW_EXCEPTION(CommonException, OSFileOpenError) 
    3240        } 
     41#ifdef WIN32 
     42        this->fileName = Filename; 
     43#endif 
    3344} 
    3445 
     
    4253// 
    4354// -------------------------------------------------------------------------- 
     55#ifdef WIN32 
     56FileStream::FileStream(HANDLE FileDescriptor) 
     57#else 
    4458FileStream::FileStream(int FileDescriptor) 
     59#endif 
    4560        : mOSFileHandle(FileDescriptor), 
    4661          mIsEOF(false) 
     
    6277// 
    6378// -------------------------------------------------------------------------- 
     79#ifndef WIN32 
    6480FileStream::FileStream(const FileStream &rToCopy) 
    6581        : mOSFileHandle(::dup(rToCopy.mOSFileHandle)), 
     
    7288        } 
    7389} 
    74  
     90#endif 
    7591// -------------------------------------------------------------------------- 
    7692// 
     
    99115int FileStream::Read(void *pBuffer, int NBytes, int Timeout) 
    100116{ 
    101         if(mOSFileHandle == -1) {THROW_EXCEPTION(CommonException, FileClosed)} 
     117        if(mOSFileHandle == INVALID_FILE) {THROW_EXCEPTION(CommonException, FileClosed)} 
     118 
     119#ifdef WIN32 
     120        int r; 
     121        DWORD numBytesRead = 0; 
     122        BOOL valid = ReadFile( 
     123                this->mOSFileHandle, 
     124                pBuffer, 
     125                NBytes, 
     126                &numBytesRead, 
     127                NULL 
     128                ); 
     129 
     130        if ( valid ) 
     131        { 
     132        r = numBytesRead; 
     133        } 
     134        else 
     135        { 
     136                r = -1; 
     137        } 
     138#else 
    102139        int r = ::read(mOSFileHandle, pBuffer, NBytes); 
     140#endif 
    103141        if(r == -1) 
    104142        { 
     
    144182void FileStream::Write(const void *pBuffer, int NBytes) 
    145183{ 
    146         if(mOSFileHandle == -1) {THROW_EXCEPTION(CommonException, FileClosed)} 
     184        if(mOSFileHandle == INVALID_FILE) {THROW_EXCEPTION(CommonException, FileClosed)} 
     185#ifdef WIN32 
     186        DWORD numBytesWritten = 0; 
     187        BOOL res = WriteFile( 
     188                this->mOSFileHandle, 
     189                pBuffer, 
     190                NBytes, 
     191                &numBytesWritten, 
     192                NULL 
     193                ); 
     194 
     195        if ( (res == 0) || (numBytesWritten != NBytes)) 
     196        { 
     197                DWORD err = GetLastError(); 
     198                THROW_EXCEPTION(CommonException, OSFileWriteError) 
     199        } 
     200 
     201 
     202#else 
    147203        if(::write(mOSFileHandle, pBuffer, NBytes) != NBytes) 
    148204        { 
    149205                THROW_EXCEPTION(CommonException, OSFileWriteError) 
    150206        } 
     207#endif 
    151208} 
    152209 
     
    162219IOStream::pos_type FileStream::GetPosition() const 
    163220{ 
    164         if(mOSFileHandle == -1) {THROW_EXCEPTION(CommonException, FileClosed)} 
     221#ifdef WIN32 
     222        LARGE_INTEGER conv; 
     223 
     224        conv.HighPart = 0; 
     225        conv.LowPart = 0; 
     226 
     227        conv.LowPart = SetFilePointer(this->mOSFileHandle, 0, &conv.HighPart, FILE_CURRENT); 
     228 
     229        return (IOStream::pos_type)conv.QuadPart; 
     230 
     231#else 
     232        if(mOSFileHandle == INVALID_FILE) {THROW_EXCEPTION(CommonException, FileClosed)} 
    165233        off_t p = ::lseek(mOSFileHandle, 0, SEEK_CUR); 
    166234        if(p == -1) 
     
    170238         
    171239        return (IOStream::pos_type)p; 
     240#endif 
    172241} 
    173242 
     
    183252void FileStream::Seek(IOStream::pos_type Offset, int SeekType) 
    184253{ 
    185         if(mOSFileHandle == -1) {THROW_EXCEPTION(CommonException, FileClosed)} 
     254        if(mOSFileHandle == INVALID_FILE) {THROW_EXCEPTION(CommonException, FileClosed)} 
     255 
     256#ifdef WIN32 
     257        LARGE_INTEGER conv; 
     258 
     259        conv.QuadPart = Offset; 
     260        DWORD retVal = SetFilePointer(this->mOSFileHandle, conv.LowPart, &conv.HighPart, ConvertSeekTypeToOSWhence(SeekType)); 
     261 
     262        if ( retVal == INVALID_SET_FILE_POINTER && (GetLastError() != NO_ERROR) ) 
     263        { 
     264                THROW_EXCEPTION(CommonException, OSFileError) 
     265        } 
     266#else 
    186267        if(::lseek(mOSFileHandle, Offset, ConvertSeekTypeToOSWhence(SeekType)) == -1) 
    187268        { 
    188269                THROW_EXCEPTION(CommonException, OSFileError) 
    189270        } 
    190          
     271#endif 
    191272        // Not end of file any more! 
    192273        mIsEOF = false; 
     
    208289                THROW_EXCEPTION(CommonException, FileAlreadyClosed) 
    209290        } 
     291#ifdef WIN32 
     292        if(::CloseHandle(mOSFileHandle) == 0) 
     293        { 
     294                THROW_EXCEPTION(CommonException, OSFileCloseError) 
     295        } 
     296        mOSFileHandle = NULL; 
     297        mIsEOF = true; 
     298#else 
    210299        if(::close(mOSFileHandle) != 0) 
    211300        { 
     
    214303        mOSFileHandle = -1; 
    215304        mIsEOF = true; 
     305#endif 
     306         
    216307} 
    217308 
  • box/nick/win/lib/common/FileStream.h

    r19 r31  
    1818#include <unistd.h> 
    1919 
     20#ifdef WIN32 
     21#define INVALID_FILE NULL 
     22#else 
     23#define INVALID_FILE -1 
     24#endif 
     25 
    2026class FileStream : public IOStream 
    2127{ 
    2228public: 
     29#ifdef WIN32 
     30        FileStream(const char *Filename, int flags = (O_RDONLY | O_BINARY), int mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); 
     31        FileStream(HANDLE FileDescriptor); 
     32#else 
    2333        FileStream(const char *Filename, int flags = O_RDONLY, int mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); 
    2434        FileStream(int FileDescriptor); 
    2535        FileStream(const FileStream &rToCopy); 
     36#endif 
     37         
    2638        virtual ~FileStream(); 
    2739         
     
    3749 
    3850private: 
     51#ifdef WIN32 
     52        HANDLE mOSFileHandle; 
     53        //for debugging.. 
     54        std::string fileName; 
     55#else 
    3956        int mOSFileHandle; 
     57#endif 
    4058        bool mIsEOF; 
    4159}; 
  • box/nick/win/lib/common/IOStream.cpp

    r19 r31  
    106106        switch(SeekType) 
    107107        { 
     108#ifdef WIN32 
     109        case SeekType_Absolute: 
     110                ostype = FILE_BEGIN; 
     111                break; 
     112        case SeekType_Relative: 
     113                ostype = FILE_CURRENT; 
     114                break; 
     115        case SeekType_End: 
     116                ostype = FILE_END; 
     117                break; 
     118#else 
    108119        case SeekType_Absolute: 
    109120                ostype = SEEK_SET; 
     
    115126                ostype = SEEK_END; 
    116127                break; 
     128#endif 
    117129         
    118130        default: 
  • box/nick/win/lib/crypto/CipherBlowfish.cpp

    r19 r31  
    111111CipherBlowfish::~CipherBlowfish() 
    112112{ 
     113#ifdef PLATFORM_OLD_OPENSSL 
     114        // Zero copy of key 
     115        for(unsigned int l = 0; l < mKey.size(); ++l) 
     116        { 
     117                mKey[l] = '\0'; 
     118        } 
     119#endif 
    113120} 
    114121 
  • box/nick/win/lib/crypto/CipherException.txt

    r19 r31  
    1616EVPSetPaddingFailure                            13 
    1717RandomInitFailed                                        14      Failed to read from random device 
     18LengthRequestedTooLongForRandomHex      15 
  • box/nick/win/lib/crypto/Random.cpp

    r19 r31  
    6060// 
    6161// Function 
     62//              Name:    Random::GenerateHex(int) 
     63//              Purpose: Generate Length bytes of hex encoded data. Note that the 
     64//                               maximum length requested is limited. (Returns a string 
     65//                               2 x Length characters long.) 
     66//              Created: 1/11/04 
     67// 
     68// -------------------------------------------------------------------------- 
     69std::string Random::GenerateHex(int Length) 
     70{ 
     71        uint8_t r[256]; 
     72        if(Length > sizeof(r)) 
     73        { 
     74                THROW_EXCEPTION(CipherException, LengthRequestedTooLongForRandomHex) 
     75        } 
     76        Random::Generate(r, Length); 
     77         
     78        std::string o; 
     79        static const char *h = "0123456789abcdef"; 
     80        for(int l = 0; l < Length; ++l) 
     81        { 
     82                o += h[r[l] >> 4]; 
     83                o += h[r[l] & 0xf]; 
     84        } 
     85         
     86        return o; 
     87} 
     88 
     89 
     90// -------------------------------------------------------------------------- 
     91// 
     92// Function 
    6293//              Name:    Random::RandomInt(int) 
    6394//              Purpose: Return a random integer between 0 and MaxValue inclusive. 
  • box/nick/win/lib/crypto/Random.h

    r19 r31  
    1111#define RANDOM__H 
    1212 
     13#include <string> 
     14 
    1315namespace Random 
    1416{ 
    1517        void Initialise(); 
    1618        void Generate(void *pOutput, int Length); 
     19        std::string GenerateHex(int Length); 
    1720        uint32_t RandomInt(uint32_t MaxValue); 
    1821}; 
  • box/nick/win/lib/raidfile/RaidFileWrite.cpp

    r19 r31  
    183183         
    184184        // Use lseek to find the current file position 
    185         off_t p = ::lseek(mOSFileHandle, SEEK_CUR, 0); 
     185        off_t p = ::lseek(mOSFileHandle, 0, SEEK_CUR); 
    186186        if(p == -1) 
    187187        { 
  • box/nick/win/lib/server/Daemon.cpp

    r19 r31  
    140140                // Let the derived class have a go at setting up stuff in the initial process 
    141141                SetupInInitialProcess(); 
    142                  
     142#ifndef WIN32            
    143143                // Set signal handler 
    144144                if(::signal(SIGHUP, SignalHandler) == SIG_ERR || ::signal(SIGTERM, SignalHandler) == SIG_ERR) 
     
    216216                        } 
    217217                } 
     218#endif 
    218219 
    219220                // open the log 
     
    222223                ::syslog(LOG_INFO, "Starting daemon (config: %s) (version " BOX_VERSION ")", configfile); 
    223224 
     225#ifndef WIN32 
    224226                // Write PID to file 
    225227                char pid[32]; 
     
    230232                        THROW_EXCEPTION(ServerException, DaemoniseFailed) 
    231233                } 
     234#endif 
    232235                 
    233236                // Set up memory leak reporting 
     
    242245                if(asDaemon) 
    243246                { 
     247#ifndef WIN32 
    244248                        // Close standard streams 
    245249                        ::close(0); 
    246250                        ::close(1); 
    247251                        ::close(2); 
    248                          
     252                 
    249253                        // Open and redirect them into /dev/null 
    250254                        int devnull = ::open(PLATFORM_DEV_NULL, O_RDWR, 0); 
     
    262266                                ::close(devnull); 
    263267                        } 
    264                          
     268#endif                   
    265269                        // And definately don't try and send anything to those file descriptors 
    266270                        // -- this has in the past sent text to something which isn't expecting it. 
     
    354358void Daemon::EnterChild() 
    355359{ 
     360#ifndef WIN32 
    356361        // Unset signal handlers 
    357362        ::signal(SIGHUP, SIG_DFL); 
    358363        ::signal(SIGTERM, SIG_DFL); 
     364#endif 
    359365} 
    360366 
     
    370376void Daemon::SignalHandler(int sigraised) 
    371377{ 
     378#ifndef WIN32 
    372379        if(spDaemon != 0) 
    373380        { 
     
    386393                } 
    387394        } 
     395#endif 
    388396} 
    389397 
  • box/nick/win/lib/server/LocalProcessStream.cpp

    r19 r31  
    1010#include "Box.h" 
    1111 
     12#ifndef WIN32 
    1213#include <sys/socket.h> 
     14#endif 
    1315#include <unistd.h> 
    1416 
     
    3739        std::vector<std::string> command; 
    3840        SplitString(std::string(CommandLine), ' ', command); 
     41#ifndef WIN32 
    3942        // Build arguments 
    4043        char *args[MAX_ARGUMENTS + 4]; 
     
    9598        rPidOut = pid; 
    9699        return stream;   
     100#else 
     101        ::syslog(LOG_ERR, "vfork not implimented - LocalProcessStream.cpp"); 
     102        std::auto_ptr<IOStream> stream; 
     103        return stream; 
     104#endif 
     105 
    97106} 
    98107 
  • box/nick/win/lib/server/ServerStream.h

    r19 r31  
    121121                        { 
    122122                                // Get the address we need to bind to 
    123                                 const Configuration &config(GetConfiguration()); 
     123                                // this-> in next line required to build under some gcc versions 
     124                                const Configuration &config(this->GetConfiguration()); 
    124125                                const Configuration &server(config.GetSubConfiguration("Server")); 
    125126                                std::string addrs = server.GetKeyValue("ListenAddresses"); 
  • box/nick/win/lib/server/ServerTLS.h

    r19 r31  
    4747                // First, set up the SSL context. 
    4848                // Get parameters from the configuration 
    49                 const Configuration &conf(GetConfiguration()); 
     49                // this-> in next line required to build under some gcc versions 
     50                const Configuration &conf(this->GetConfiguration()); 
    5051                const Configuration &serverconf(conf.GetSubConfiguration("Server")); 
    5152                std::string certFile(serverconf.GetKeyValue("CertificateFile")); 
     
    6162        { 
    6263                rStream.Handshake(mContext, true /* is server */); 
    63                 Connection(rStream); 
     64                // this-> in next line required to build under some gcc versions 
     65                this->Connection(rStream); 
    6466        } 
    6567         
  • box/nick/win/lib/server/Socket.cpp

    r19 r31  
    1212#include <unistd.h> 
    1313#include <sys/types.h> 
     14#ifndef WIN32 
    1415#include <sys/socket.h> 
    1516#include <netdb.h> 
     
    1718#include <netinet/in.h> 
    1819#include <arpa/inet.h> 
     20#endif 
    1921 
    2022#include <string.h> 
     
    7274                } 
    7375                break; 
    74          
     76 
     77#ifndef WIN32 
    7578        case TypeUNIX: 
    7679                sockDomain = AF_UNIX; 
     
    9093                } 
    9194                break; 
    92                  
     95#endif 
     96 
    9397        default: 
    9498                THROW_EXCEPTION(CommonException, BadArguments) 
  • box/nick/win/lib/server/Socket.h

    r19 r31  
    1111#define SOCKET__H 
    1212 
     13#ifdef WIN32 
     14#include "emu.h" 
     15typedef int socklen_t; 
     16#else 
    1317#include <sys/socket.h> 
    1418#include <netinet/in.h> 
    1519#include <sys/un.h> 
     20#endif 
    1621 
    1722#include <string> 
     
    2025        struct sockaddr sa_generic; 
    2126        struct sockaddr_in sa_inet; 
     27#ifndef WIN32 
    2228        struct sockaddr_un sa_unix; 
     29#endif 
    2330} SocketAllAddr; 
    2431 
  • box/nick/win/lib/server/SocketListen.h

    r19 r31  
    9595                if(mSocketHandle != -1) 
    9696                { 
     97#ifdef WIN32 
     98                        if(::closesocket(mSocketHandle) == -1) 
     99#else 
    97100                        if(::close(mSocketHandle) == -1) 
     101#endif 
    98102                        { 
    99103                                THROW_EXCEPTION(ServerException, SocketCloseError) 
     
    129133                 
    130134                // Set an option to allow reuse (useful for -HUP situations!) 
     135#ifdef WIN32 
     136                if(::setsockopt(mSocketHandle, SOL_SOCKET, SO_REUSEADDR, "", 0) == -1) 
     137#else 
    131138                int option = true; 
    132139                if(::setsockopt(mSocketHandle, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option)) == -1) 
     140#endif 
    133141                { 
    134142                        THROW_EXCEPTION(ServerException, SocketOpenError) 
  • box/nick/win/lib/server/SocketStream.cpp

    r19 r31  
    141141        { 
    142142                // Dispose of the socket 
     143#ifdef WIN32 
     144                ::closesocket(mSocketHandle); 
     145#else 
    143146                ::close(mSocketHandle); 
     147#endif 
    144148                mSocketHandle = -1; 
    145149                THROW_EXCEPTION(ConnectionException, Conn_SocketConnectError) 
     
    192196        } 
    193197 
     198#ifdef WIN32 
     199        int r = ::recv(mSocketHandle, (char*)pBuffer, NBytes, 0); 
     200#else 
    194201        int r = ::read(mSocketHandle, pBuffer, NBytes); 
     202#endif 
    195203        if(r == -1) 
    196204        { 
     
    237245        { 
    238246                // Try to send. 
     247#ifdef WIN32 
     248                int sent = ::send(mSocketHandle, buffer, bytesLeft, 0); 
     249#else 
    239250                int sent = ::write(mSocketHandle, buffer, bytesLeft); 
     251#endif 
    240252                if(sent == -1) 
    241253                { 
     
    284296{ 
    285297        if(mSocketHandle == -1) {THROW_EXCEPTION(ServerException, BadSocketHandle)} 
    286          
     298#ifdef WIN32 
     299        if(::closesocket(mSocketHandle) == -1) 
     300#elif 
    287301        if(::close(mSocketHandle) == -1) 
     302#endif 
    288303        { 
    289304                THROW_EXCEPTION(ServerException, SocketCloseError) 
     
    355370// 
    356371// -------------------------------------------------------------------------- 
     372#ifdef WIN32 
     373SOCKET SocketStream::GetSocketHandle() 
     374#else 
    357375int SocketStream::GetSocketHandle() 
     376#endif 
    358377{ 
    359378        if(mSocketHandle == -1) {THROW_EXCEPTION(ServerException, BadSocketHandle)} 
  • box/nick/win/lib/server/SocketStream.h

    r19 r31  
    4343 
    4444protected: 
     45#ifdef WIN32 
     46        SOCKET GetSocketHandle(); 
     47#else 
    4548        int GetSocketHandle(); 
     49#endif 
    4650        void MarkAsReadClosed() {mReadClosed = true;} 
    4751        void MarkAsWriteClosed() {mWriteClosed = true;} 
    4852 
    4953private: 
     54#ifdef WIN32 
     55        SOCKET mSocketHandle; 
     56#else 
    5057        int mSocketHandle; 
     58#endif 
    5159        bool mReadClosed; 
    5260        bool mWriteClosed; 
  • box/nick/win/lib/server/SocketStreamTLS.cpp

    r19 r31  
    1515#include <poll.h> 
    1616#include <errno.h> 
     17#ifndef WIN32 
    1718#include <sys/ioctl.h> 
     19#endif 
    1820 
    1921#include "SocketStreamTLS.h" 
     
    121123                THROW_EXCEPTION(ServerException, TLSAllocationFailed) 
    122124        } 
     125#ifdef WIN32 
     126        SOCKET socket = GetSocketHandle(); 
     127#else 
    123128        int socket = GetSocketHandle(); 
     129#endif 
    124130        BIO_set_fd(mpBIO, socket, BIO_NOCLOSE); 
    125131         
  • box/nick/win/lib/server/makeprotocol.pl

    r19 r31  
    312312        ~$classname_base$cmd(); 
    313313        int GetType() const; 
     314        enum 
     315        { 
     316                TypeID = $cmd_id{$cmd} 
     317        }; 
    314318__E 
    315319        # constants 
     
    522526        virtual ~$classname_base(); 
    523527 
     528        std::auto_ptr<$derive_objects_from> Receive(); 
     529        void Send(const ${derive_objects_from} &rObject); 
    524530__E 
    525531if($implement_syslog) 
     
    649655} 
    650656__E 
     657# write receieve and send functions 
     658print CPP <<__E; 
     659std::auto_ptr<$derive_objects_from> ${prefix}Receive() 
     660{ 
     661        std::auto_ptr<${derive_objects_from}> preply((${derive_objects_from}*)(Protocol::Receive().release())); 
     662 
     663__E 
     664        if($implement_syslog) 
     665        { 
     666                print CPP <<__E; 
     667        if(mLogToSysLog) 
     668        { 
     669                preply->LogSysLog("Receive"); 
     670        } 
     671__E 
     672        } 
     673        if($implement_filelog) 
     674        { 
     675                print CPP <<__E; 
     676        if(mLogToFile != 0) 
     677        { 
     678                preply->LogFile("Receive", mLogToFile); 
     679        } 
     680__E 
     681        } 
     682print CPP <<__E; 
     683 
     684        return preply; 
     685} 
     686 
     687void ${prefix}Send(const ${derive_objects_from} &rObject) 
     688{ 
     689__E 
     690        if($implement_syslog) 
     691        { 
     692                print CPP <<__E; 
     693        if(mLogToSysLog) 
     694        { 
     695                rObject.LogSysLog("Send"); 
     696        } 
     697__E 
     698        } 
     699        if($implement_filelog) 
     700        { 
     701                print CPP <<__E; 
     702        if(mLogToFile != 0) 
     703        { 
     704                rObject.LogFile("Send", mLogToFile); 
     705        } 
     706__E 
     707        } 
     708 
     709print CPP <<__E; 
     710        Protocol::Send(rObject); 
     711} 
     712 
     713__E 
    651714# write server function? 
    652715if($type eq 'Server') 
     
    663726        { 
    664727                // Get an object from the conversation 
    665                 std::auto_ptr<ProtocolObject> o1(Receive()); 
    666                 std::auto_ptr<${derive_objects_from}> pobj((${derive_objects_from}*)o1.release()); 
     728                std::auto_ptr<${derive_objects_from}> pobj(Receive()); 
    667729 
    668730__E 
     
    802864std::auto_ptr<$classname_base$reply> ${classname_base}::Query(const $classname_base$cmd &rQuery$argextra) 
    803865{ 
    804 __E 
    805         if($implement_syslog) 
    806         { 
    807                 print CPP <<__E; 
    808         if(mLogToSysLog) 
    809         { 
    810                 rQuery.LogSysLog("Send"); 
    811         } 
    812 __E 
    813         } 
    814         if($implement_filelog) 
    815         { 
    816                 print CPP <<__E; 
    817         if(mLogToFile != 0) 
    818         { 
    819                 rQuery.LogFile("Send", mLogToFile); 
    820         } 
    821 __E 
    822         } 
    823         print CPP <<__E; 
    824          
    825866        // Send query 
    826867        Send(rQuery); 
    827868        $send_stream_extra 
    828869        // Wait for the reply 
    829         std::auto_ptr<${derive_objects_from}> preply((${derive_objects_from}*)(Receive().release())); 
    830  
    831 __E 
    832         if($implement_syslog) 
    833         { 
    834                 print CPP <<__E; 
    835         if(mLogToSysLog) 
    836         { 
    837                 preply->LogSysLog("Receive"); 
    838         } 
    839 __E 
    840         } 
    841         if($implement_filelog) 
    842         { 
    843                 print CPP <<__E; 
    844         if(mLogToFile != 0) 
    845         { 
    846                 preply->LogFile("Receive", mLogToFile); 
    847         } 
    848 __E 
    849         } 
    850         print CPP <<__E; 
    851  
     870        std::auto_ptr<${derive_objects_from}> preply(Receive().release()); 
    852871 
    853872        if(preply->GetType() == $reply_id) 
  • box/nick/win/modules.txt

    r20 r31  
    4848# END_IF_DISTRIBUTION 
    4949 
     50 
  • box/nick/win/test/basicserver/testbasicserver.cpp

    r19 r31  
    350350        for(unsigned int c = 0; c < conns.size(); ++c) 
    351351        { 
    352                 delete getline[c]; 
    353         } 
    354         delete [] getline; 
     352                if ( getline[c] ) delete getline[c]; 
     353                getline[c] = 0; 
     354        } 
     355        if ( getline ) delete [] getline; 
     356        getline = 0; 
    355357} 
    356358 
  • box/nick/win/test/bbackupd/testbbackupd.cpp

    r19 r31  
    374374                TEST_THAT(::mkdir("testfiles/TestDir1/symlink-to-dir", 0755) == 0); 
    375375                TEST_THAT(::mkdir("testfiles/TestDir1/x1/dir-to-file", 0755) == 0); 
     376                // NOTE: create a file within the directory to avoid deletion by the housekeeping process later 
     377                TEST_THAT(::symlink("does-not-exist", "testfiles/TestDir1/x1/dir-to-file/contents") == 0); 
    376378                wait_for_backup_operation(); 
    377379                compareReturnValue = ::system("../../bin/bbackupquery/bbackupquery -q -c testfiles/bbackupd.conf -l testfiles/query3s.log \"compare -ac\" quit"); 
     
    381383                // And the inverse, replace a directory with a file/symlink 
    382384                printf("Replace directory with symlink\n"); 
     385                TEST_THAT(::unlink("testfiles/TestDir1/x1/dir-to-file/contents") == 0); 
    383386                TEST_THAT(::rmdir("testfiles/TestDir1/x1/dir-to-file") == 0); 
    384387                TEST_THAT(::symlink("does-not-exist", "testfiles/TestDir1/x1/dir-to-file") == 0); 
     
    386389                compareReturnValue = ::system("../../bin/bbackupquery/bbackupquery -q -c testfiles/bbackupd.conf -l testfiles/query3s.log \"compare -ac\" quit"); 
    387390                TEST_THAT(compareReturnValue == 1*256); 
    388                 TestRemoteProcessMemLeaks("bbackupquery.memleaks");              
    389                  
     391                TestRemoteProcessMemLeaks("bbackupquery.memleaks"); 
     392                 
     393                // And then, put it back to how it was before. 
     394                printf("Replace symlink with directory (which was a symlink)\n"); 
     395                TEST_THAT(::unlink("testfiles/TestDir1/x1/dir-to-file") == 0); 
     396                TEST_THAT(::mkdir("testfiles/TestDir1/x1/dir-to-file", 0755) == 0); 
     397                TEST_THAT(::symlink("does-not-exist", "testfiles/TestDir1/x1/dir-to-file/contents2") == 0); 
     398                wait_for_backup_operation(); 
     399                compareReturnValue = ::system("../../bin/bbackupquery/bbackupquery -q -c testfiles/bbackupd.conf -l testfiles/query3s.log \"compare -ac\" quit"); 
     400                TEST_THAT(compareReturnValue == 1*256); 
     401                TestRemoteProcessMemLeaks("bbackupquery.memleaks"); 
     402                 
     403                // And finally, put it back to how it was before it was put back to how it was before 
     404                // This gets lots of nasty things in the store with directories over other old directories. 
     405                printf("Put it all back to how it was\n"); 
     406                TEST_THAT(::unlink("testfiles/TestDir1/x1/dir-to-file/contents2") == 0); 
     407                TEST_THAT(::rmdir("testfiles/TestDir1/x1/dir-to-file") == 0); 
     408                TEST_THAT(::symlink("does-not-exist", "testfiles/TestDir1/x1/dir-to-file") == 0); 
     409                wait_for_backup_operation(); 
     410                compareReturnValue = ::system("../../bin/bbackupquery/bbackupquery -q -c testfiles/bbackupd.conf -l testfiles/query3s.log \"compare -ac\" quit"); 
     411                TEST_THAT(compareReturnValue == 1*256); 
     412                TestRemoteProcessMemLeaks("bbackupquery.memleaks"); 
     413 
    390414                // case which went wrong: rename a tracked file over a deleted file 
    391415                printf("Rename an existing file over a deleted file\n"); 
Note: See TracChangeset for help on using the changeset viewer.