- Timestamp:
- 24/10/2005 19:44:10 (7 years ago)
- Location:
- box/nick/win
- Files:
-
- 7 added
- 47 edited
-
bbackupctl.vcproj (added)
-
bbackupd.vcproj (added)
-
boxbackup.sln (added)
-
boxbackup.suo (added)
-
boxquery.vcproj (added)
-
common.vcproj (added)
-
infrastructure/makebuildenv.pl (modified) (8 diffs)
-
lib/backupclient/BackupClientFileAttributes.cpp (modified) (2 diffs)
-
lib/backupclient/BackupClientFileAttributes.h (modified) (1 diff)
-
lib/backupclient/BackupClientRestore.cpp (modified) (2 diffs)
-
lib/backupclient/BackupDaemonConfigVerify.cpp (modified) (1 diff)
-
lib/backupclient/BackupStoreDirectory.h (modified) (1 diff)
-
lib/backupclient/BackupStoreFile.cpp (modified) (11 diffs)
-
lib/backupclient/BackupStoreFile.h (modified) (3 diffs)
-
lib/backupclient/BackupStoreFileCombine.cpp (modified) (1 diff)
-
lib/backupclient/BackupStoreFileDiff.cpp (modified) (6 diffs)
-
lib/backupclient/BackupStoreFileEncodeStream.cpp (modified) (5 diffs)
-
lib/backupclient/BackupStoreFileEncodeStream.h (modified) (2 diffs)
-
lib/backupclient/BackupStoreObjectDump.cpp (modified) (1 diff)
-
lib/common/Box.h (modified) (1 diff)
-
lib/common/BoxPlatform.h (modified) (5 diffs)
-
lib/common/BoxPortsAndFiles.h (modified) (2 diffs)
-
lib/common/BoxTime.h (modified) (1 diff)
-
lib/common/BoxTimeToText.cpp (modified) (2 diffs)
-
lib/common/BoxTimeToUnix.h (modified) (1 diff)
-
lib/common/Configuration.cpp (modified) (6 diffs)
-
lib/common/Configuration.h (modified) (3 diffs)
-
lib/common/Conversion.h (modified) (1 diff)
-
lib/common/DebugPrintf.cpp (modified) (1 diff)
-
lib/common/ExcludeList.cpp (modified) (9 diffs)
-
lib/common/ExcludeList.h (modified) (4 diffs)
-
lib/common/FileStream.cpp (modified) (11 diffs)
-
lib/common/FileStream.h (modified) (2 diffs)
-
lib/common/IOStream.cpp (modified) (2 diffs)
-
lib/crypto/CipherBlowfish.cpp (modified) (1 diff)
-
lib/crypto/CipherException.txt (modified) (1 diff)
-
lib/crypto/Random.cpp (modified) (1 diff)
-
lib/crypto/Random.h (modified) (1 diff)
-
lib/raidfile/RaidFileWrite.cpp (modified) (1 diff)
-
lib/server/Daemon.cpp (modified) (9 diffs)
-
lib/server/LocalProcessStream.cpp (modified) (3 diffs)
-
lib/server/ServerStream.h (modified) (1 diff)
-
lib/server/ServerTLS.h (modified) (2 diffs)
-
lib/server/Socket.cpp (modified) (4 diffs)
-
lib/server/Socket.h (modified) (2 diffs)
-
lib/server/SocketListen.h (modified) (2 diffs)
-
lib/server/SocketStream.cpp (modified) (5 diffs)
-
lib/server/SocketStream.h (modified) (1 diff)
-
lib/server/SocketStreamTLS.cpp (modified) (2 diffs)
-
lib/server/makeprotocol.pl (modified) (5 diffs)
-
modules.txt (modified) (1 diff)
-
test/basicserver/testbasicserver.cpp (modified) (1 diff)
-
test/bbackupd/testbbackupd.cpp (modified) (3 diffs)
-
win32test.vcproj (added)
Legend:
- Unmodified
- Added
- Removed
-
box/nick/win/infrastructure/makebuildenv.pl
r19 r31 1 1 #!/usr/bin/perl 2 2 use strict; 3 use Symbol; 3 4 4 5 my @modules; … … 323 324 # seed autogen code 324 325 print "Seeding autogen code...\n"; 325 open FINDAUTOGEN,"find . - name Makefile.extra |" or die "Can't use find for locating files";326 open FINDAUTOGEN,"find . -follow -name Makefile.extra |" or die "Can't use find for locating files"; 326 327 while(<FINDAUTOGEN>) 327 328 { … … 396 397 $extra_platform_defines .= ' -DPLATFORM_GCC3' if $gcc_v3; 397 398 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 400 my @modules_files; 401 sub 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 } 420 read_modules_file('modules.txt'); 400 421 401 422 # prepare directories... … … 403 424 mkdir "debug",0755; 404 425 426 # is the library code in another directory? 427 my $external_lib = readlink('lib'); 428 if($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 } 437 sub 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 405 464 print "Scanning code...\n"; 406 465 407 466 my $modules_omitted = 0; 408 467 409 while(<MODULES>) 468 # process lines in flattened modules files 469 for(@modules_files) 410 470 { 411 471 # 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; 413 473 next unless m/\S/; 414 474 … … 484 544 $module_library_link_opts{$mod} = [@lo]; 485 545 486 # make directories 546 # make directories, but not if we're using an external library and this a library module 487 547 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 } 494 556 495 557 # make dirs for implicit dep … … 1011 1073 if(exists $t{'SuccessFlags'}) 1012 1074 { 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 } 1014 1081 } 1015 1082 $compile_line_extra .= $t{'SuccessCompileFlags'}.' ' if exists $t{'SuccessCompileFlags'}; … … 1029 1096 if(exists $t{'FailureFlags'}) 1030 1097 { 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 } 1032 1104 } 1033 1105 $compile_line_extra .= $t{'FailureCompileFlags'}.' ' if exists $t{'FailureCompileFlags'}; … … 1035 1107 $test_failure_text .= $t{'FailureText'} if exists $t{'FailureText'}; 1036 1108 } 1037 } 1038 1039 1040 1109 $result 1110 } 1111 1112 1113 -
box/nick/win/lib/backupclient/BackupClientFileAttributes.cpp
r19 r31 273 273 // -------------------------------------------------------------------------- 274 274 void 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) 276 276 { 277 277 StreamableMemBlock *pnewAttr = 0; … … 334 334 FILL_IN_ATTRIBUTES 335 335 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 336 359 337 360 // Attributes ready. Encrypt into this block -
box/nick/win/lib/backupclient/BackupClientFileAttributes.h
r19 r31 45 45 void ReadAttributes(const char *Filename, bool ZeroModificationTimes = false, 46 46 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); 48 48 void WriteAttributes(const char *Filename) const; 49 49 -
box/nick/win/lib/backupclient/BackupClientRestore.cpp
r19 r31 16 16 #include <unistd.h> 17 17 #include <limits.h> 18 #include <stdio.h> 18 19 19 20 #include "BackupClientRestore.h" … … 224 225 225 226 // 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; 232 252 } 233 253 -
box/nick/win/lib/backupclient/BackupDaemonConfigVerify.cpp
r19 r31 85 85 86 86 {"CommandSocket", 0, 0, 0}, // not compulsory to have this 87 {"StoreObjectInfoFile", 0, 0, 0}, // optional 88 {"KeepAliveTime", 0, ConfigTest_IsInt, 0}, // optional 87 89 88 90 {"NotifyScript", 0, 0, 0}, // optional script to run when backup needs attention, eg store full -
box/nick/win/lib/backupclient/BackupStoreDirectory.h
r19 r31 182 182 return (*(i++)); 183 183 } 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. 185 188 BackupStoreDirectory::Entry *FindMatchingClearName(const BackupStoreFilenameClear &rFilename, int16_t FlagsMustBeSet = Entry::Flags_INCLUDE_EVERYTHING, int16_t FlagsNotToBeSet = Entry::Flags_EXCLUDE_NOTHING) 186 189 { -
box/nick/win/lib/backupclient/BackupStoreFile.cpp
r19 r31 14 14 #include <string.h> 15 15 #include <new> 16 #include <string.h> 16 17 #ifndef BOX_DISABLE_BACKWARDS_COMPATIBILITY_BACKUPSTOREFILE 17 18 #include <syslog.h> … … 366 367 if(mpEncodedData) 367 368 { 368 ::free(mpEncodedData);369 BackupStoreFile::CodingChunkFree(mpEncodedData); 369 370 } 370 371 if(mpClearData) … … 531 532 532 533 // Allocate those blocks! 533 mpEncodedData = (uint8_t*) ::malloc(maxEncodedDataSize + 32);534 mpEncodedData = (uint8_t*)BackupStoreFile::CodingChunkAlloc(maxEncodedDataSize + 32); 534 535 535 536 // Allocate the block for the clear data, using the hint from the header. … … 913 914 // 914 915 // 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) 917 918 // Created: 8/12/03 918 919 // 919 920 // -------------------------------------------------------------------------- 920 int BackupStoreFile::EncodeChunk(const void *Chunk, int ChunkSize, void *Output, int OutputSize)921 int BackupStoreFile::EncodeChunk(const void *Chunk, int ChunkSize, BackupStoreFile::EncodingBuffer &rOutput) 921 922 { 922 923 ASSERT(spEncrypt != 0); 923 924 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 930 934 // Want to compress it? 931 935 bool compressChunk = (ChunkSize >= BACKUP_FILE_MIN_COMPRESSED_CHUNK_SIZE); … … 936 940 937 941 // Store header 938 uint8_t *output = (uint8_t*)Output; 939 output[0] = header; 942 rOutput.mpBuffer[0] = header; 940 943 int outOffset = 1; 941 944 … … 943 946 int ivLen = 0; 944 947 const void *iv = spEncrypt->SetRandomIV(ivLen); 945 ::memcpy( output+ outOffset, iv, ivLen);948 ::memcpy(rOutput.mpBuffer + outOffset, iv, ivLen); 946 949 outOffset += ivLen; 947 950 948 951 // Start encryption process 949 952 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 } 950 961 951 962 // Encode the chunk … … 966 977 if(s > 0) 967 978 { 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); 969 981 } 970 982 else … … 975 987 } 976 988 } 977 outOffset += spEncrypt->Final(output + outOffset, OutputSize - outOffset); 989 ENCODECHUNK_CHECK_SPACE(16) 990 outOffset += spEncrypt->Final(rOutput.mpBuffer + outOffset, rOutput.mBufferSize - outOffset); 978 991 } 979 992 else 980 993 { 981 994 // 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 987 1002 988 1003 return outOffset; … … 995 1010 // Purpose: Decode an encoded chunk -- use OutputBufferSizeForKnownOutputSize() to find 996 1011 // the extra output buffer size needed before calling. 1012 // See notes in EncodeChunk() for notes re alignment of the 1013 // encoded data. 997 1014 // Created: 8/12/03 998 1015 // … … 1000 1017 int BackupStoreFile::DecodeChunk(const void *Encoded, int EncodedSize, void *Output, int OutputSize) 1001 1018 { 1019 // Check alignment of the encoded block 1020 ASSERT((((uint32_t)Encoded) % BACKUPSTOREFILE_CODING_BLOCKSIZE) == BACKUPSTOREFILE_CODING_OFFSET); 1021 1002 1022 // First check 1003 1023 if(EncodedSize < 1) … … 1393 1413 } 1394 1414 1415 1416 // -------------------------------------------------------------------------- 1417 // 1418 // Function 1419 // Name: BackupStoreFile::EncodingBuffer::EncodingBuffer() 1420 // Purpose: Constructor 1421 // Created: 25/11/04 1422 // 1423 // -------------------------------------------------------------------------- 1424 BackupStoreFile::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 // -------------------------------------------------------------------------- 1439 BackupStoreFile::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 // -------------------------------------------------------------------------- 1457 void 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 // -------------------------------------------------------------------------- 1479 void 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 23 23 int64_t mTotalFileStreamSize; 24 24 } 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" 25 39 26 40 // -------------------------------------------------------------------------- … … 106 120 #endif 107 121 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(); 110 160 111 161 // 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 }; 112 178 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); 114 180 115 181 // Caller should know how big the output size is, but also allocate a bit more memory to cover various … … 135 201 }; 136 202 203 #include "MemLeakFindOff.h" 204 137 205 #endif // BACKUPSTOREFILE__H 138 206 -
box/nick/win/lib/backupclient/BackupStoreFileCombine.cpp
r19 r31 322 322 } 323 323 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 } 327 330 } 328 331 catch(...) -
box/nick/win/lib/backupclient/BackupStoreFileDiff.cpp
r19 r31 13 13 #include <map> 14 14 #include <signal.h> 15 #ifdef WIN32 16 #include <time.h> 17 #else 15 18 #include <sys/time.h> 19 #endif 16 20 17 21 #include "BackupStoreFile.h" … … 45 49 static void GenerateRecipe(BackupStoreFileEncodeStream::Recipe &rRecipe, BlocksAvailableEntry *pIndex, int64_t NumBlocks, std::map<int64_t, int64_t> &rFoundBlocks, int64_t SizeOfInputFile); 46 50 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 49 52 static bool sDiffTimedOut = false; 50 static bool sSetTimerSignelHandler = false;51 static void TimerSignalHandler(int signal);52 static void StartDiffTimer();53 54 53 55 54 // -------------------------------------------------------------------------- 56 55 // 57 56 // 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 // -------------------------------------------------------------------------- 64 void BackupStoreFile::SuspendFileDiff() 65 65 { 66 sMaximumDiffTime = Seconds; 67 TRACE1("Set maximum diffing time to %d seconds\n", Seconds); 66 sDiffTimedOut = true; 68 67 } 69 70 68 71 69 // -------------------------------------------------------------------------- … … 176 174 // Pointer to recipe we're going to create 177 175 BackupStoreFileEncodeStream::Recipe *precipe = 0; 178 179 // Start the timeout timer, so that the operation doesn't continue for ever180 StartDiffTimer();181 176 182 177 try … … 471 466 BlocksAvailableEntry *pIndex, int64_t NumBlocks, int32_t Sizes[BACKUP_FILE_DIFF_MAX_BLOCK_SIZES]) 472 467 { 468 // reset state in case we got timing/call-order mess-up somewhere else 469 sDiffTimedOut = false; 470 473 471 // Allocate the hash lookup table 474 472 BlocksAvailableEntry **phashTable = (BlocksAvailableEntry **)::malloc(sizeof(BlocksAvailableEntry *) * (64*1024)); … … 912 910 { 913 911 char b[64]; 912 #ifdef WIN32 913 sprintf(b, "%8I64d", (int64_t)(rRecipe[e].mpStartBlock - pIndex)); 914 #else 914 915 sprintf(b, "%8lld", (int64_t)(rRecipe[e].mpStartBlock - pIndex)); 916 #endif 915 917 TRACE3("%8lld %s %8lld\n", rRecipe[e].mSpaceBefore, (rRecipe[e].mpStartBlock == 0)?" -":b, (int64_t)rRecipe[e].mBlocks); 916 918 } … … 920 922 #endif 921 923 } 922 923 924 // --------------------------------------------------------------------------925 //926 // Function927 // Name: static TimerSignalHandler(int)928 // Purpose: Signal handler929 // Created: 19/3/04930 //931 // --------------------------------------------------------------------------932 void TimerSignalHandler(int signal)933 {934 sDiffTimedOut = true;935 }936 937 938 // --------------------------------------------------------------------------939 //940 // Function941 // Name: static StartDiffTimer()942 // Purpose: Starts the diff timeout timer943 // Created: 19/3/04944 //945 // --------------------------------------------------------------------------946 void StartDiffTimer()947 {948 // Set timer signal handler949 if(!sSetTimerSignelHandler)950 {951 ::signal(SIGVTALRM, TimerSignalHandler);952 sSetTimerSignelHandler = true;953 }954 955 struct itimerval timeout;956 // Don't want this to repeat957 timeout.it_interval.tv_sec = 0;958 timeout.it_interval.tv_usec = 0;959 // Single timeout after the specified number of seconds960 timeout.it_value.tv_sec = sMaximumDiffTime;961 timeout.it_value.tv_usec = 0;962 // Set timer963 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 51 51 mLastBlockSize(0), 52 52 mpRawBuffer(0), 53 mpEncodedBuffer(0),54 53 mAllocatedBufferSize(0), 55 54 mEntryIVBase(0) … … 72 71 ::free(mpRawBuffer); 73 72 mpRawBuffer = 0; 74 }75 if(mpEncodedBuffer)76 {77 ::free(mpEncodedBuffer);78 mpEncodedBuffer = 0;79 73 } 80 74 … … 212 206 // Then allocate two blocks of this size 213 207 mpRawBuffer = (uint8_t*)::malloc(mAllocatedBufferSize); 214 mpEncodedBuffer = (uint8_t*)::malloc(mAllocatedBufferSize); 215 if(mpRawBuffer == 0 || mpEncodedBuffer == 0) 208 if(mpRawBuffer == 0) 216 209 { 217 210 throw std::bad_alloc(); 218 211 } 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 219 218 } 220 219 else … … 412 411 413 412 // Copy it in 414 ::memcpy(buffer, m pEncodedBuffer + mPositionInCurrentBlock, s);413 ::memcpy(buffer, mEncodedBuffer.mpBuffer + mPositionInCurrentBlock, s); 415 414 416 415 // Update variables … … 535 534 536 535 // Encode it 537 mCurrentBlockEncodedSize = BackupStoreFile::EncodeChunk(mpRawBuffer, blockRawSize, m pEncodedBuffer, mAllocatedBufferSize);536 mCurrentBlockEncodedSize = BackupStoreFile::EncodeChunk(mpRawBuffer, blockRawSize, mEncodedBuffer); 538 537 539 538 //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 17 17 #include "CollectInBufferStream.h" 18 18 #include "MD5Digest.h" 19 #include "BackupStoreFile.h" 19 20 20 21 namespace BackupStoreFileCreation … … 115 116 // Buffers 116 117 uint8_t *mpRawBuffer; // buffer for raw data 117 uint8_t *mpEncodedBuffer; // buffer for encoded data 118 BackupStoreFile::EncodingBuffer mEncodedBuffer; 119 // buffer for encoded data 118 120 int32_t mAllocatedBufferSize; // size of above two allocated blocks 119 121 uint64_t mEntryIVBase; // base for block entry IV -
box/nick/win/lib/backupclient/BackupStoreObjectDump.cpp
r19 r31 97 97 if((*i)->GetDependsNewer() != 0) 98 98 { 99 #ifdef WIN32 100 depends_l += ::sprintf(depends + depends_l, " depNew(%I64x)", (*i)->GetDependsNewer()); 101 #else 99 102 depends_l += ::sprintf(depends + depends_l, " depNew(%llx)", (*i)->GetDependsNewer()); 103 #endif 100 104 } 101 105 if((*i)->GetDependsOlder() != 0) 102 106 { 107 #ifdef WIN32 108 depends_l += ::sprintf(depends + depends_l, " depOld(%I64x)", (*i)->GetDependsOlder()); 109 #else 103 110 depends_l += ::sprintf(depends + depends_l, " depOld(%llx)", (*i)->GetDependsOlder()); 111 #endif 104 112 } 105 113 -
box/nick/win/lib/common/Box.h
r20 r31 83 83 #define EXCEPTION_CODENAMES_EXTENDED 84 84 #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 86 91 #endif 87 92 -
box/nick/win/lib/common/BoxPlatform.h
r19 r31 12 12 #define BOXPLATFORM__H 13 13 14 #ifdef WIN32 15 #define DIRECTORY_SEPARATOR "\\" 16 #define DIRECTORY_SEPARATOR_ASCHAR '\\' 17 #else 14 18 #define DIRECTORY_SEPARATOR "/" 15 19 #define DIRECTORY_SEPARATOR_ASCHAR '/' 20 #endif 16 21 17 22 #define PLATFORM_DEV_NULL "/dev/null" … … 26 31 // -- regex support not available on this platform 27 32 28 29 33 #ifdef PLATFORM_OPENBSD 30 34 … … 135 139 136 140 #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 137 146 138 147 #endif // PLATFORM_LINUX … … 184 193 #endif // PLATFORM_CYGWIN 185 194 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 186 262 187 263 // Find out if credentials on UNIX sockets can be obtained … … 219 295 220 296 #endif 221 297 #elif WIN32 298 #define STRUCTURE_PATCKING_FOR_WIRE_USE_HEADERS 222 299 #else 223 300 compiler not supported! 224 301 #endif 225 302 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 307 typedef u_int64_t InodeRefType; 308 #else 309 typedef ino_t InodeRefType; 310 #endif 226 311 227 312 #endif // BOXPLATFORM__H -
box/nick/win/lib/common/BoxPortsAndFiles.h
r20 r31 13 13 #define BOX_PORT_BASE 2200 14 14 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 15 23 // Backup store daemon 16 24 #define BOX_PORT_BBSTORED (BOX_PORT_BASE+1) … … 20 28 21 29 // Backup client daemon 30 #ifdef WIN32 31 #define BOX_FILE_BBACKUPD_DEFAULT_CONFIG "C:\\Program Files\\Box Backup\\bbackupd.conf" 32 #else 22 33 #define BOX_FILE_BBACKUPD_DEFAULT_CONFIG "/etc/box/bbackupd.conf" 23 34 #endif 24 35 25 36 // RaidFile conf location efault 26 37 #define BOX_FILE_RAIDFILE_DEFAULT_CONFIG "/etc/box/raidfile.conf" 27 38 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 28 55 #endif // BOXPORTSANDFILES__H 29 56 -
box/nick/win/lib/common/BoxTime.h
r19 r31 32 32 return ((box_time_t)Seconds * MICRO_SEC_IN_SEC_LL); 33 33 } 34 inline int64_t BoxTimeToSeconds(box_time_t Time)34 inline box_time_t BoxTimeToSeconds(box_time_t Time) 35 35 { 36 36 return Time / MICRO_SEC_IN_SEC_LL; 37 37 } 38 inline int64_t BoxTimeToMilliSeconds(box_time_t Time)38 inline box_time_t BoxTimeToMilliSeconds(box_time_t Time) 39 39 { 40 40 return Time / MILLI_SEC_IN_NANO_SEC_LL; -
box/nick/win/lib/common/BoxTimeToText.cpp
r19 r31 28 28 std::string BoxTimeToISO8601String(box_time_t Time) 29 29 { 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); 31 53 struct tm time; 32 54 gmtime_r(&timeInSecs, &time); … … 35 57 sprintf(str, "%04d-%02d-%02dT%02d:%02d:%02d", time.tm_year + 1900, 36 58 time.tm_mon + 1, time.tm_mday, time.tm_hour, time.tm_min, time.tm_sec); 37 59 #endif 38 60 return std::string(str); 39 61 } -
box/nick/win/lib/common/BoxTimeToUnix.h
r19 r31 11 11 #define FILEMODIFICATIONTIMETOTIMEVAL__H 12 12 13 #ifdef WIN32 14 #include <time.h> 15 #else 13 16 #include <sys/time.h> 17 #endif 14 18 15 19 #include "BoxTime.h" -
box/nick/win/lib/common/Configuration.cpp
r19 r31 20 20 #include "MemLeakFindOn.h" 21 21 22 #include "FileModificationTime.h" 23 22 24 // utility whitespace function 23 25 inline bool iw(int c) … … 30 32 static const bool sValueBooleanValue[] = {true, true, false, false}; 31 33 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) 38 38 // Purpose: Constructor 39 39 // Created: 2003/07/23 40 40 // 41 41 // -------------------------------------------------------------------------- 42 Configuration::Configuration(const std::string &rName) 43 : mName(rName) 44 { 45 } 46 42 Configuration::Configuration(const std::string &rName, box_time_t configModTime) 43 : mName(rName), mConfigModTime(configModTime) 44 { 45 } 47 46 48 47 // -------------------------------------------------------------------------- … … 57 56 : mName(rToCopy.mName), 58 57 mSubConfigurations(rToCopy.mSubConfigurations), 59 mKeys(rToCopy.mKeys) 58 mKeys(rToCopy.mKeys), 59 mConfigModTime(rToCopy.mConfigModTime) 60 60 { 61 61 } … … 95 95 rErrorMsg.erase(); 96 96 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 97 104 // Open the file 98 105 FileHandleGuard<O_RDONLY> file(Filename); … … 102 109 103 110 // Object to create 104 Configuration *pconfig = new Configuration(std::string("<root>") );111 Configuration *pconfig = new Configuration(std::string("<root>"), FileModificationTime(st)); 105 112 106 113 try … … 177 184 { 178 185 // New config object 179 Configuration config(blockName );186 Configuration config(blockName, rConfig.mConfigModTime); 180 187 181 188 // Continue processing into this block -
box/nick/win/lib/common/Configuration.h
r19 r31 16 16 #include <string> 17 17 #include <memory> 18 19 #include "BoxTime.h" 18 20 19 21 // For defining tests … … 59 61 { 60 62 private: 61 Configuration(const std::string &rName );63 Configuration(const std::string &rName, box_time_t configModTime); 62 64 public: 63 65 Configuration(const Configuration &rToCopy); 64 66 ~Configuration(); 65 67 68 box_time_t GetModTime() const { return mConfigModTime; } 69 66 70 enum 67 71 { … … 89 93 // Order of keys, not preserved 90 94 std::map<std::string, std::string> mKeys; 91 95 protected: 96 box_time_t mConfigModTime; 92 97 private: 93 98 static bool LoadInto(Configuration &rConfig, FdGetLine &rGetLine, std::string &rErrorMsg, bool RootLevel); -
box/nick/win/lib/common/Conversion.h
r19 r31 87 87 } 88 88 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 } 89 95 }; 90 96 -
box/nick/win/lib/common/DebugPrintf.cpp
r19 r31 56 56 if(BoxDebugTraceToSyslog) 57 57 { 58 #ifdef WIN32 58 59 // Remove trailing '\n', if it's there 60 if(r > 0 && text[r-1] == '\n') 61 { 62 63 text[r-1] = '\0'; 64 #else 59 65 if(r > 0 && text[r] == '\n') 60 66 { 67 61 68 text[r] = '\0'; 69 #endif 62 70 --r; 63 71 } -
box/nick/win/lib/common/ExcludeList.cpp
r19 r31 9 9 10 10 #include "Box.h" 11 11 #ifdef WIN32 12 #include <boost/regex.hpp> 13 #else 12 14 #ifndef PLATFORM_REGEX_NOT_SUPPORTED 13 15 #include <regex.h> 14 16 #define EXCLUDELIST_IMPLEMENTATION_REGEX_T_DEFINED 17 #endif 15 18 #endif 16 19 … … 45 48 ExcludeList::~ExcludeList() 46 49 { 50 #ifdef WIN32 51 //under win32 and boost - we didn't use pointers so all should aotu distruct. 52 #else 47 53 #ifndef PLATFORM_REGEX_NOT_SUPPORTED 48 54 // free regex memory … … 55 61 delete pregex; 56 62 } 63 #endif 57 64 #endif 58 65 … … 107 114 void ExcludeList::AddRegexEntries(const std::string &rEntries) 108 115 { 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 109 141 #ifndef PLATFORM_REGEX_NOT_SUPPORTED 110 142 … … 131 163 // Store in list of regular expressions 132 164 mRegex.push_back(pregex); 165 // Store in list of regular expression string for Serialize 166 mRegexStr.push_back(i->c_str()); 133 167 } 134 168 catch(...) … … 142 176 #else 143 177 THROW_EXCEPTION(CommonException, RegexNotSupportedOnThisPlatform) 178 #endif 144 179 #endif 145 180 } … … 174 209 175 210 // 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 176 231 #ifndef PLATFORM_REGEX_NOT_SUPPORTED 177 232 for(std::vector<regex_t *>::const_iterator i(mRegex.begin()); i != mRegex.end(); ++i) … … 185 240 // In all other cases, including an error, just continue to the next expression 186 241 } 242 #endif 187 243 #endif 188 244 … … 214 270 } 215 271 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 // -------------------------------------------------------------------------- 281 void 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 // -------------------------------------------------------------------------- 416 void 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 15 15 #include <vector> 16 16 17 #ifdef WIN32 18 #include <boost/regex.hpp> 19 #else 17 20 // avoid including regex.h in lots of places 18 21 #ifndef EXCLUDELIST_IMPLEMENTATION_REGEX_T_DEFINED 19 22 typedef int regex_t; 20 23 #endif 24 #endif 25 #include "Archive.h" 21 26 22 27 // -------------------------------------------------------------------------- … … 34 39 ~ExcludeList(); 35 40 41 void Deserialize(Archive & rArchive); 42 void Serialize(Archive & rArchive) const; 43 36 44 void AddDefiniteEntries(const std::string &rEntries); 37 45 void AddRegexEntries(const std::string &rEntries); … … 46 54 unsigned int SizeOfDefiniteList() const {return mDefinite.size();} 47 55 unsigned int SizeOfRegexList() const 56 #ifdef WIN32 57 //lets be explicit in this 58 {return mRegex.size();} 59 #else 48 60 #ifndef PLATFORM_REGEX_NOT_SUPPORTED 49 61 {return mRegex.size();} … … 51 63 {return 0;} 52 64 #endif 65 #endif 53 66 54 67 private: 55 68 std::set<std::string> mDefinite; 69 70 #ifdef WIN32 71 std::vector<boost::regex> mRegex; 72 std::vector<std::string> mRegexStr; 73 #else 56 74 #ifndef PLATFORM_REGEX_NOT_SUPPORTED 57 75 std::vector<regex_t *> mRegex; 76 std::vector<std::string> mRegexStr; // save original regular expression string-based source for Serialize 77 #endif 58 78 #endif 59 79 -
box/nick/win/lib/common/FileStream.cpp
r19 r31 23 23 // -------------------------------------------------------------------------- 24 24 FileStream::FileStream(const char *Filename, int flags, int mode) 25 #ifdef WIN32 26 : mOSFileHandle(::openfile(Filename, flags, mode)), 27 #else 25 28 : mOSFileHandle(::open(Filename, flags, mode)), 29 #endif 26 30 mIsEOF(false) 27 31 { 32 #ifdef WIN32 33 if(mOSFileHandle == 0) 34 #else 28 35 if(mOSFileHandle < 0) 36 #endif 29 37 { 30 38 MEMLEAKFINDER_NOT_A_LEAK(this); 31 39 THROW_EXCEPTION(CommonException, OSFileOpenError) 32 40 } 41 #ifdef WIN32 42 this->fileName = Filename; 43 #endif 33 44 } 34 45 … … 42 53 // 43 54 // -------------------------------------------------------------------------- 55 #ifdef WIN32 56 FileStream::FileStream(HANDLE FileDescriptor) 57 #else 44 58 FileStream::FileStream(int FileDescriptor) 59 #endif 45 60 : mOSFileHandle(FileDescriptor), 46 61 mIsEOF(false) … … 62 77 // 63 78 // -------------------------------------------------------------------------- 79 #ifndef WIN32 64 80 FileStream::FileStream(const FileStream &rToCopy) 65 81 : mOSFileHandle(::dup(rToCopy.mOSFileHandle)), … … 72 88 } 73 89 } 74 90 #endif 75 91 // -------------------------------------------------------------------------- 76 92 // … … 99 115 int FileStream::Read(void *pBuffer, int NBytes, int Timeout) 100 116 { 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 102 139 int r = ::read(mOSFileHandle, pBuffer, NBytes); 140 #endif 103 141 if(r == -1) 104 142 { … … 144 182 void FileStream::Write(const void *pBuffer, int NBytes) 145 183 { 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 147 203 if(::write(mOSFileHandle, pBuffer, NBytes) != NBytes) 148 204 { 149 205 THROW_EXCEPTION(CommonException, OSFileWriteError) 150 206 } 207 #endif 151 208 } 152 209 … … 162 219 IOStream::pos_type FileStream::GetPosition() const 163 220 { 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)} 165 233 off_t p = ::lseek(mOSFileHandle, 0, SEEK_CUR); 166 234 if(p == -1) … … 170 238 171 239 return (IOStream::pos_type)p; 240 #endif 172 241 } 173 242 … … 183 252 void FileStream::Seek(IOStream::pos_type Offset, int SeekType) 184 253 { 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 186 267 if(::lseek(mOSFileHandle, Offset, ConvertSeekTypeToOSWhence(SeekType)) == -1) 187 268 { 188 269 THROW_EXCEPTION(CommonException, OSFileError) 189 270 } 190 271 #endif 191 272 // Not end of file any more! 192 273 mIsEOF = false; … … 208 289 THROW_EXCEPTION(CommonException, FileAlreadyClosed) 209 290 } 291 #ifdef WIN32 292 if(::CloseHandle(mOSFileHandle) == 0) 293 { 294 THROW_EXCEPTION(CommonException, OSFileCloseError) 295 } 296 mOSFileHandle = NULL; 297 mIsEOF = true; 298 #else 210 299 if(::close(mOSFileHandle) != 0) 211 300 { … … 214 303 mOSFileHandle = -1; 215 304 mIsEOF = true; 305 #endif 306 216 307 } 217 308 -
box/nick/win/lib/common/FileStream.h
r19 r31 18 18 #include <unistd.h> 19 19 20 #ifdef WIN32 21 #define INVALID_FILE NULL 22 #else 23 #define INVALID_FILE -1 24 #endif 25 20 26 class FileStream : public IOStream 21 27 { 22 28 public: 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 23 33 FileStream(const char *Filename, int flags = O_RDONLY, int mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); 24 34 FileStream(int FileDescriptor); 25 35 FileStream(const FileStream &rToCopy); 36 #endif 37 26 38 virtual ~FileStream(); 27 39 … … 37 49 38 50 private: 51 #ifdef WIN32 52 HANDLE mOSFileHandle; 53 //for debugging.. 54 std::string fileName; 55 #else 39 56 int mOSFileHandle; 57 #endif 40 58 bool mIsEOF; 41 59 }; -
box/nick/win/lib/common/IOStream.cpp
r19 r31 106 106 switch(SeekType) 107 107 { 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 108 119 case SeekType_Absolute: 109 120 ostype = SEEK_SET; … … 115 126 ostype = SEEK_END; 116 127 break; 128 #endif 117 129 118 130 default: -
box/nick/win/lib/crypto/CipherBlowfish.cpp
r19 r31 111 111 CipherBlowfish::~CipherBlowfish() 112 112 { 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 113 120 } 114 121 -
box/nick/win/lib/crypto/CipherException.txt
r19 r31 16 16 EVPSetPaddingFailure 13 17 17 RandomInitFailed 14 Failed to read from random device 18 LengthRequestedTooLongForRandomHex 15 -
box/nick/win/lib/crypto/Random.cpp
r19 r31 60 60 // 61 61 // 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 // -------------------------------------------------------------------------- 69 std::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 62 93 // Name: Random::RandomInt(int) 63 94 // Purpose: Return a random integer between 0 and MaxValue inclusive. -
box/nick/win/lib/crypto/Random.h
r19 r31 11 11 #define RANDOM__H 12 12 13 #include <string> 14 13 15 namespace Random 14 16 { 15 17 void Initialise(); 16 18 void Generate(void *pOutput, int Length); 19 std::string GenerateHex(int Length); 17 20 uint32_t RandomInt(uint32_t MaxValue); 18 21 }; -
box/nick/win/lib/raidfile/RaidFileWrite.cpp
r19 r31 183 183 184 184 // 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); 186 186 if(p == -1) 187 187 { -
box/nick/win/lib/server/Daemon.cpp
r19 r31 140 140 // Let the derived class have a go at setting up stuff in the initial process 141 141 SetupInInitialProcess(); 142 142 #ifndef WIN32 143 143 // Set signal handler 144 144 if(::signal(SIGHUP, SignalHandler) == SIG_ERR || ::signal(SIGTERM, SignalHandler) == SIG_ERR) … … 216 216 } 217 217 } 218 #endif 218 219 219 220 // open the log … … 222 223 ::syslog(LOG_INFO, "Starting daemon (config: %s) (version " BOX_VERSION ")", configfile); 223 224 225 #ifndef WIN32 224 226 // Write PID to file 225 227 char pid[32]; … … 230 232 THROW_EXCEPTION(ServerException, DaemoniseFailed) 231 233 } 234 #endif 232 235 233 236 // Set up memory leak reporting … … 242 245 if(asDaemon) 243 246 { 247 #ifndef WIN32 244 248 // Close standard streams 245 249 ::close(0); 246 250 ::close(1); 247 251 ::close(2); 248 252 249 253 // Open and redirect them into /dev/null 250 254 int devnull = ::open(PLATFORM_DEV_NULL, O_RDWR, 0); … … 262 266 ::close(devnull); 263 267 } 264 268 #endif 265 269 // And definately don't try and send anything to those file descriptors 266 270 // -- this has in the past sent text to something which isn't expecting it. … … 354 358 void Daemon::EnterChild() 355 359 { 360 #ifndef WIN32 356 361 // Unset signal handlers 357 362 ::signal(SIGHUP, SIG_DFL); 358 363 ::signal(SIGTERM, SIG_DFL); 364 #endif 359 365 } 360 366 … … 370 376 void Daemon::SignalHandler(int sigraised) 371 377 { 378 #ifndef WIN32 372 379 if(spDaemon != 0) 373 380 { … … 386 393 } 387 394 } 395 #endif 388 396 } 389 397 -
box/nick/win/lib/server/LocalProcessStream.cpp
r19 r31 10 10 #include "Box.h" 11 11 12 #ifndef WIN32 12 13 #include <sys/socket.h> 14 #endif 13 15 #include <unistd.h> 14 16 … … 37 39 std::vector<std::string> command; 38 40 SplitString(std::string(CommandLine), ' ', command); 41 #ifndef WIN32 39 42 // Build arguments 40 43 char *args[MAX_ARGUMENTS + 4]; … … 95 98 rPidOut = pid; 96 99 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 97 106 } 98 107 -
box/nick/win/lib/server/ServerStream.h
r19 r31 121 121 { 122 122 // 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()); 124 125 const Configuration &server(config.GetSubConfiguration("Server")); 125 126 std::string addrs = server.GetKeyValue("ListenAddresses"); -
box/nick/win/lib/server/ServerTLS.h
r19 r31 47 47 // First, set up the SSL context. 48 48 // 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()); 50 51 const Configuration &serverconf(conf.GetSubConfiguration("Server")); 51 52 std::string certFile(serverconf.GetKeyValue("CertificateFile")); … … 61 62 { 62 63 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); 64 66 } 65 67 -
box/nick/win/lib/server/Socket.cpp
r19 r31 12 12 #include <unistd.h> 13 13 #include <sys/types.h> 14 #ifndef WIN32 14 15 #include <sys/socket.h> 15 16 #include <netdb.h> … … 17 18 #include <netinet/in.h> 18 19 #include <arpa/inet.h> 20 #endif 19 21 20 22 #include <string.h> … … 72 74 } 73 75 break; 74 76 77 #ifndef WIN32 75 78 case TypeUNIX: 76 79 sockDomain = AF_UNIX; … … 90 93 } 91 94 break; 92 95 #endif 96 93 97 default: 94 98 THROW_EXCEPTION(CommonException, BadArguments) -
box/nick/win/lib/server/Socket.h
r19 r31 11 11 #define SOCKET__H 12 12 13 #ifdef WIN32 14 #include "emu.h" 15 typedef int socklen_t; 16 #else 13 17 #include <sys/socket.h> 14 18 #include <netinet/in.h> 15 19 #include <sys/un.h> 20 #endif 16 21 17 22 #include <string> … … 20 25 struct sockaddr sa_generic; 21 26 struct sockaddr_in sa_inet; 27 #ifndef WIN32 22 28 struct sockaddr_un sa_unix; 29 #endif 23 30 } SocketAllAddr; 24 31 -
box/nick/win/lib/server/SocketListen.h
r19 r31 95 95 if(mSocketHandle != -1) 96 96 { 97 #ifdef WIN32 98 if(::closesocket(mSocketHandle) == -1) 99 #else 97 100 if(::close(mSocketHandle) == -1) 101 #endif 98 102 { 99 103 THROW_EXCEPTION(ServerException, SocketCloseError) … … 129 133 130 134 // 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 131 138 int option = true; 132 139 if(::setsockopt(mSocketHandle, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option)) == -1) 140 #endif 133 141 { 134 142 THROW_EXCEPTION(ServerException, SocketOpenError) -
box/nick/win/lib/server/SocketStream.cpp
r19 r31 141 141 { 142 142 // Dispose of the socket 143 #ifdef WIN32 144 ::closesocket(mSocketHandle); 145 #else 143 146 ::close(mSocketHandle); 147 #endif 144 148 mSocketHandle = -1; 145 149 THROW_EXCEPTION(ConnectionException, Conn_SocketConnectError) … … 192 196 } 193 197 198 #ifdef WIN32 199 int r = ::recv(mSocketHandle, (char*)pBuffer, NBytes, 0); 200 #else 194 201 int r = ::read(mSocketHandle, pBuffer, NBytes); 202 #endif 195 203 if(r == -1) 196 204 { … … 237 245 { 238 246 // Try to send. 247 #ifdef WIN32 248 int sent = ::send(mSocketHandle, buffer, bytesLeft, 0); 249 #else 239 250 int sent = ::write(mSocketHandle, buffer, bytesLeft); 251 #endif 240 252 if(sent == -1) 241 253 { … … 284 296 { 285 297 if(mSocketHandle == -1) {THROW_EXCEPTION(ServerException, BadSocketHandle)} 286 298 #ifdef WIN32 299 if(::closesocket(mSocketHandle) == -1) 300 #elif 287 301 if(::close(mSocketHandle) == -1) 302 #endif 288 303 { 289 304 THROW_EXCEPTION(ServerException, SocketCloseError) … … 355 370 // 356 371 // -------------------------------------------------------------------------- 372 #ifdef WIN32 373 SOCKET SocketStream::GetSocketHandle() 374 #else 357 375 int SocketStream::GetSocketHandle() 376 #endif 358 377 { 359 378 if(mSocketHandle == -1) {THROW_EXCEPTION(ServerException, BadSocketHandle)} -
box/nick/win/lib/server/SocketStream.h
r19 r31 43 43 44 44 protected: 45 #ifdef WIN32 46 SOCKET GetSocketHandle(); 47 #else 45 48 int GetSocketHandle(); 49 #endif 46 50 void MarkAsReadClosed() {mReadClosed = true;} 47 51 void MarkAsWriteClosed() {mWriteClosed = true;} 48 52 49 53 private: 54 #ifdef WIN32 55 SOCKET mSocketHandle; 56 #else 50 57 int mSocketHandle; 58 #endif 51 59 bool mReadClosed; 52 60 bool mWriteClosed; -
box/nick/win/lib/server/SocketStreamTLS.cpp
r19 r31 15 15 #include <poll.h> 16 16 #include <errno.h> 17 #ifndef WIN32 17 18 #include <sys/ioctl.h> 19 #endif 18 20 19 21 #include "SocketStreamTLS.h" … … 121 123 THROW_EXCEPTION(ServerException, TLSAllocationFailed) 122 124 } 125 #ifdef WIN32 126 SOCKET socket = GetSocketHandle(); 127 #else 123 128 int socket = GetSocketHandle(); 129 #endif 124 130 BIO_set_fd(mpBIO, socket, BIO_NOCLOSE); 125 131 -
box/nick/win/lib/server/makeprotocol.pl
r19 r31 312 312 ~$classname_base$cmd(); 313 313 int GetType() const; 314 enum 315 { 316 TypeID = $cmd_id{$cmd} 317 }; 314 318 __E 315 319 # constants … … 522 526 virtual ~$classname_base(); 523 527 528 std::auto_ptr<$derive_objects_from> Receive(); 529 void Send(const ${derive_objects_from} &rObject); 524 530 __E 525 531 if($implement_syslog) … … 649 655 } 650 656 __E 657 # write receieve and send functions 658 print CPP <<__E; 659 std::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 } 682 print CPP <<__E; 683 684 return preply; 685 } 686 687 void ${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 709 print CPP <<__E; 710 Protocol::Send(rObject); 711 } 712 713 __E 651 714 # write server function? 652 715 if($type eq 'Server') … … 663 726 { 664 727 // 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()); 667 729 668 730 __E … … 802 864 std::auto_ptr<$classname_base$reply> ${classname_base}::Query(const $classname_base$cmd &rQuery$argextra) 803 865 { 804 __E805 if($implement_syslog)806 {807 print CPP <<__E;808 if(mLogToSysLog)809 {810 rQuery.LogSysLog("Send");811 }812 __E813 }814 if($implement_filelog)815 {816 print CPP <<__E;817 if(mLogToFile != 0)818 {819 rQuery.LogFile("Send", mLogToFile);820 }821 __E822 }823 print CPP <<__E;824 825 866 // Send query 826 867 Send(rQuery); 827 868 $send_stream_extra 828 869 // 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()); 852 871 853 872 if(preply->GetType() == $reply_id) -
box/nick/win/modules.txt
r20 r31 48 48 # END_IF_DISTRIBUTION 49 49 50 -
box/nick/win/test/basicserver/testbasicserver.cpp
r19 r31 350 350 for(unsigned int c = 0; c < conns.size(); ++c) 351 351 { 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; 355 357 } 356 358 -
box/nick/win/test/bbackupd/testbbackupd.cpp
r19 r31 374 374 TEST_THAT(::mkdir("testfiles/TestDir1/symlink-to-dir", 0755) == 0); 375 375 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); 376 378 wait_for_backup_operation(); 377 379 compareReturnValue = ::system("../../bin/bbackupquery/bbackupquery -q -c testfiles/bbackupd.conf -l testfiles/query3s.log \"compare -ac\" quit"); … … 381 383 // And the inverse, replace a directory with a file/symlink 382 384 printf("Replace directory with symlink\n"); 385 TEST_THAT(::unlink("testfiles/TestDir1/x1/dir-to-file/contents") == 0); 383 386 TEST_THAT(::rmdir("testfiles/TestDir1/x1/dir-to-file") == 0); 384 387 TEST_THAT(::symlink("does-not-exist", "testfiles/TestDir1/x1/dir-to-file") == 0); … … 386 389 compareReturnValue = ::system("../../bin/bbackupquery/bbackupquery -q -c testfiles/bbackupd.conf -l testfiles/query3s.log \"compare -ac\" quit"); 387 390 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 390 414 // case which went wrong: rename a tracked file over a deleted file 391 415 printf("Rename an existing file over a deleted file\n");
Note: See TracChangeset
for help on using the changeset viewer.
