diff options
author | Martin Ebourne <martin@ebourne.me.uk> | 2005-12-07 16:34:47 +0000 |
---|---|---|
committer | Martin Ebourne <martin@ebourne.me.uk> | 2005-12-07 16:34:47 +0000 |
commit | 81d8eda2419e7a23088a98cdfc52a305c9ceac0d (patch) | |
tree | 27143d7b539a8bf2e23cc18e2f598804fa8d784d /lib | |
parent | 065dc6f8cd168e3ee6e71ddfb06f42a92abfabbd (diff) |
Merged martin/autoconf at r35 to trunk
Diffstat (limited to 'lib')
51 files changed, 319 insertions, 647 deletions
diff --git a/lib/backupclient/BackupClientCryptoKeys.cpp b/lib/backupclient/BackupClientCryptoKeys.cpp index 015dadd2..46b77f0a 100755 --- a/lib/backupclient/BackupClientCryptoKeys.cpp +++ b/lib/backupclient/BackupClientCryptoKeys.cpp @@ -54,7 +54,7 @@ void BackupClientCryptoKeys_Setup(const char *KeyMaterialFilename) // Tell the files how to encrypt BackupStoreFile::SetBlowfishKeys(KeyMaterial + BACKUPCRYPTOKEYS_ATTRIBUTES_KEY_START, BACKUPCRYPTOKEYS_ATTRIBUTES_KEY_LENGTH, KeyMaterial + BACKUPCRYPTOKEYS_FILE_BLOCK_ENTRY_KEY_START, BACKUPCRYPTOKEYS_FILE_BLOCK_ENTRY_KEY_LENGTH); -#ifndef PLATFORM_OLD_OPENSSL +#ifndef HAVE_OLD_SSL // Use AES where available BackupStoreFile::SetAESKey(KeyMaterial + BACKUPCRYPTOKEYS_FILE_AES_KEY_START, BACKUPCRYPTOKEYS_FILE_AES_KEY_LENGTH); #endif diff --git a/lib/backupclient/BackupClientFileAttributes.cpp b/lib/backupclient/BackupClientFileAttributes.cpp index 24e90697..adc3a91c 100755 --- a/lib/backupclient/BackupClientFileAttributes.cpp +++ b/lib/backupclient/BackupClientFileAttributes.cpp @@ -17,7 +17,7 @@ #include <algorithm> #include <new> #include <vector> -#ifdef PLATFORM_HAVE_XATTR +#ifdef HAVE_SYS_XATTR_H #include <cerrno> #include <sys/xattr.h> #endif @@ -34,7 +34,7 @@ #include "MemLeakFindOn.h" // set packing to one byte -#ifdef STRUCTURE_PATCKING_FOR_WIRE_USE_HEADERS +#ifdef STRUCTURE_PACKING_FOR_WIRE_USE_HEADERS #include "BeginStructPackForWire.h" #else BEGIN_STRUCTURE_PACKING_FOR_WIRE @@ -73,7 +73,7 @@ typedef struct } attributeHashData; // Use default packing -#ifdef STRUCTURE_PATCKING_FOR_WIRE_USE_HEADERS +#ifdef STRUCTURE_PACKING_FOR_WIRE_USE_HEADERS #include "EndStructPackForWire.h" #else END_STRUCTURE_PACKING_FOR_WIRE @@ -359,12 +359,12 @@ void BackupClientFileAttributes::FillAttributes(StreamableMemBlock &outputBlock, } else { - pattr->ModificationTime = hton64(FileModificationTime(st)); - pattr->AttrModificationTime = hton64(FileAttrModificationTime(st)); + pattr->ModificationTime = box_hton64(FileModificationTime(st)); + pattr->AttrModificationTime = box_hton64(FileAttrModificationTime(st)); } pattr->Mode = htons(st.st_mode); -#ifdef PLATFORM_stat_NO_st_flags +#ifndef HAVE_STRUCT_STAT_ST_FLAGS pattr->UserDefinedFlags = 0; pattr->FileGenerationNumber = 0; #else @@ -413,7 +413,7 @@ void BackupClientFileAttributes::FillAttributesLink(StreamableMemBlock &outputBl // -------------------------------------------------------------------------- void BackupClientFileAttributes::FillExtendedAttr(StreamableMemBlock &outputBlock, const char *Filename) { -#ifdef PLATFORM_HAVE_XATTR +#ifdef HAVE_SYS_XATTR_H int listBufferSize = 1000; char* list = new char[listBufferSize]; @@ -587,7 +587,7 @@ void BackupClientFileAttributes::WriteAttributes(const char *Filename) const // If working as root, set user IDs if(::geteuid() == 0) { - #ifdef PLATFORM_LCHOWN_NOT_SUPPORTED + #ifndef HAVE_LCHOWN // only if not a link, can't set their owner on this platform if((mode & S_IFMT) != S_IFLNK) { @@ -617,7 +617,7 @@ void BackupClientFileAttributes::WriteAttributes(const char *Filename) const } // Set modification time? - box_time_t modtime = ntoh64(pattr->ModificationTime); + box_time_t modtime = box_ntoh64(pattr->ModificationTime); if(modtime != 0) { // Work out times as timevals @@ -718,7 +718,7 @@ void BackupClientFileAttributes::EnsureClearAvailable() const // -------------------------------------------------------------------------- void BackupClientFileAttributes::WriteExtendedAttr(const char *Filename, int xattrOffset) const { -#ifdef PLATFORM_HAVE_XATTR +#ifdef HAVE_SYS_XATTR_H const char* buffer = static_cast<char*>(mpClearAttributes->GetBuffer()); u_int32_t xattrBlockLength = 0; diff --git a/lib/backupclient/BackupStoreDirectory.cpp b/lib/backupclient/BackupStoreDirectory.cpp index 31fed78d..6b5a55d1 100755 --- a/lib/backupclient/BackupStoreDirectory.cpp +++ b/lib/backupclient/BackupStoreDirectory.cpp @@ -19,7 +19,7 @@ #include "MemLeakFindOn.h" // set packing to one byte -#ifdef STRUCTURE_PATCKING_FOR_WIRE_USE_HEADERS +#ifdef STRUCTURE_PACKING_FOR_WIRE_USE_HEADERS #include "BeginStructPackForWire.h" #else BEGIN_STRUCTURE_PACKING_FOR_WIRE @@ -59,7 +59,7 @@ typedef struct } en_StreamFormatDepends; // Use default packing -#ifdef STRUCTURE_PATCKING_FOR_WIRE_USE_HEADERS +#ifdef STRUCTURE_PACKING_FOR_WIRE_USE_HEADERS #include "EndStructPackForWire.h" #else END_STRUCTURE_PACKING_FOR_WIRE @@ -135,9 +135,9 @@ void BackupStoreDirectory::ReadFromStream(IOStream &rStream, int Timeout) } // Get data - mObjectID = ntoh64(hdr.mObjectID); - mContainerID = ntoh64(hdr.mContainerID); - mAttributesModTime = ntoh64(hdr.mAttributesModTime); + mObjectID = box_ntoh64(hdr.mObjectID); + mContainerID = box_ntoh64(hdr.mContainerID); + mAttributesModTime = box_ntoh64(hdr.mAttributesModTime); // Options int32_t options = ntohl(hdr.mOptionsPresent); @@ -231,9 +231,9 @@ void BackupStoreDirectory::WriteToStream(IOStream &rStream, int16_t FlagsMustBeS dir_StreamFormat hdr; hdr.mMagicValue = htonl(OBJECTMAGIC_DIR_MAGIC_VALUE); hdr.mNumEntries = htonl(count); - hdr.mObjectID = hton64(mObjectID); - hdr.mContainerID = hton64(mContainerID); - hdr.mAttributesModTime = hton64(mAttributesModTime); + hdr.mObjectID = box_hton64(mObjectID); + hdr.mContainerID = box_hton64(mContainerID); + hdr.mAttributesModTime = box_hton64(mAttributesModTime); hdr.mOptionsPresent = htonl(options); // Write header @@ -480,10 +480,10 @@ void BackupStoreDirectory::Entry::ReadFromStream(IOStream &rStream, int Timeout) mAttributes.ReadFromStream(rStream, Timeout); // Store the rest of the bits - mModificationTime = ntoh64(entry.mModificationTime); - mObjectID = ntoh64(entry.mObjectID); - mSizeInBlocks = ntoh64(entry.mSizeInBlocks); - mAttributesHash = ntoh64(entry.mAttributesHash); + mModificationTime = box_ntoh64(entry.mModificationTime); + mObjectID = box_ntoh64(entry.mObjectID); + mSizeInBlocks = box_ntoh64(entry.mSizeInBlocks); + mAttributesHash = box_ntoh64(entry.mAttributesHash); mFlags = ntohs(entry.mFlags); mName = name; } @@ -501,10 +501,10 @@ void BackupStoreDirectory::Entry::WriteToStream(IOStream &rStream) const { // Build a structure en_StreamFormat entry; - entry.mModificationTime = hton64(mModificationTime); - entry.mObjectID = hton64(mObjectID); - entry.mSizeInBlocks = hton64(mSizeInBlocks); - entry.mAttributesHash = hton64(mAttributesHash); + entry.mModificationTime = box_hton64(mModificationTime); + entry.mObjectID = box_hton64(mObjectID); + entry.mSizeInBlocks = box_hton64(mSizeInBlocks); + entry.mAttributesHash = box_hton64(mAttributesHash); entry.mFlags = htons(mFlags); // Write it @@ -536,8 +536,8 @@ void BackupStoreDirectory::Entry::ReadFromStreamDependencyInfo(IOStream &rStream } // Store the data - mDependsNewer = ntoh64(depends.mDependsNewer); - mDependsOlder = ntoh64(depends.mDependsOlder); + mDependsNewer = box_ntoh64(depends.mDependsNewer); + mDependsOlder = box_ntoh64(depends.mDependsOlder); } @@ -553,8 +553,8 @@ void BackupStoreDirectory::Entry::WriteToStreamDependencyInfo(IOStream &rStream) { // Build structure en_StreamFormatDepends depends; - depends.mDependsNewer = hton64(mDependsNewer); - depends.mDependsOlder = hton64(mDependsOlder); + depends.mDependsNewer = box_hton64(mDependsNewer); + depends.mDependsOlder = box_hton64(mDependsOlder); // Write rStream.Write(&depends, sizeof(depends)); } diff --git a/lib/backupclient/BackupStoreFile.cpp b/lib/backupclient/BackupStoreFile.cpp index e1a8fde7..d31b53bb 100755 --- a/lib/backupclient/BackupStoreFile.cpp +++ b/lib/backupclient/BackupStoreFile.cpp @@ -154,7 +154,7 @@ bool BackupStoreFile::VerifyEncodedFileFormat(IOStream &rFile, int64_t *pDiffFro int64_t headerEnd = rFile.GetPosition(); // Get number of blocks - int64_t numBlocks = ntoh64(hdr.mNumBlocks); + int64_t numBlocks = box_ntoh64(hdr.mNumBlocks); // Calculate where the block index will be, check it's reasonable int64_t blockIndexLoc = fileSize - ((numBlocks * sizeof(file_BlockIndexEntry)) + sizeof(file_BlockIndexHeader)); @@ -179,7 +179,7 @@ bool BackupStoreFile::VerifyEncodedFileFormat(IOStream &rFile, int64_t *pDiffFro && ntohl(blkhdr.mMagicValue) != OBJECTMAGIC_FILE_BLOCKS_MAGIC_VALUE_V0 #endif ) - || (int64_t)ntoh64(blkhdr.mNumBlocks) != numBlocks) + || (int64_t)box_ntoh64(blkhdr.mNumBlocks) != numBlocks) { // Bad header -- either magic value or number of blocks is wrong return false; @@ -201,7 +201,7 @@ bool BackupStoreFile::VerifyEncodedFileFormat(IOStream &rFile, int64_t *pDiffFro } // Check size and location - int64_t blkSize = ntoh64(blk.mEncodedSize); + int64_t blkSize = box_ntoh64(blk.mEncodedSize); if(blkSize <= 0) { // Mark that this file references another file @@ -228,7 +228,7 @@ bool BackupStoreFile::VerifyEncodedFileFormat(IOStream &rFile, int64_t *pDiffFro } // Check that if another block is references, then the ID is there, and if one isn't there is no ID. - int64_t otherID = ntoh64(blkhdr.mOtherFileID); + int64_t otherID = box_ntoh64(blkhdr.mOtherFileID); if((otherID != 0 && blockFromOtherFileReferenced == false) || (otherID == 0 && blockFromOtherFileReferenced == true)) { @@ -245,7 +245,7 @@ bool BackupStoreFile::VerifyEncodedFileFormat(IOStream &rFile, int64_t *pDiffFro // Does the caller want the container ID? if(pContainerIDOut) { - *pContainerIDOut = ntoh64(hdr.mContainerID); + *pContainerIDOut = box_ntoh64(hdr.mContainerID); } // Passes all tests @@ -494,7 +494,7 @@ void BackupStoreFile::DecodedStream::Setup(const BackupClientFileAttributes *pAl int64_t endOfHeaderPos = mrEncodedFile.GetPosition(); // Work out where the index is - int64_t numBlocks = ntoh64(hdr.mNumBlocks); + int64_t numBlocks = box_ntoh64(hdr.mNumBlocks); int64_t blockHeaderPos = fileSize - ((numBlocks * sizeof(file_BlockIndexEntry)) + sizeof(file_BlockIndexHeader)); // Seek to that position @@ -508,7 +508,7 @@ void BackupStoreFile::DecodedStream::Setup(const BackupClientFileAttributes *pAl } // Check view of blocks from block header and file header match - if(mNumBlocks != (int64_t)ntoh64(hdr.mNumBlocks)) + if(mNumBlocks != (int64_t)box_ntoh64(hdr.mNumBlocks)) { THROW_EXCEPTION(BackupStoreException, BadBackupStoreFile) } @@ -523,7 +523,7 @@ void BackupStoreFile::DecodedStream::Setup(const BackupClientFileAttributes *pAl for(int64_t e = 0; e < mNumBlocks; e++) { // Get the clear and encoded size - int32_t encodedSize = ntoh64(entry[e].mEncodedSize); + int32_t encodedSize = box_ntoh64(entry[e].mEncodedSize); ASSERT(encodedSize > 0); // Larger? @@ -587,10 +587,10 @@ void BackupStoreFile::DecodedStream::ReadBlockIndex(bool MagicAlreadyRead) } // Get the number of blocks out of the header - mNumBlocks = ntoh64(blkhdr.mNumBlocks); + mNumBlocks = box_ntoh64(blkhdr.mNumBlocks); // Read the IV base - mEntryIVBase = ntoh64(blkhdr.mEntryIVBase); + mEntryIVBase = box_ntoh64(blkhdr.mEntryIVBase); // Load the block entries in? if(mNumBlocks > 0) @@ -673,7 +673,7 @@ int BackupStoreFile::DecodedStream::Read(void *pBuffer, int NBytes, int Timeout) // Get the size from the block index const file_BlockIndexEntry *entry = (file_BlockIndexEntry *)mpBlockIndex; - int32_t encodedSize = ntoh64(entry[mCurrentBlock].mEncodedSize); + int32_t encodedSize = box_ntoh64(entry[mCurrentBlock].mEncodedSize); if(encodedSize <= 0) { // The caller is attempting to decode a file which is the direct result of a diff @@ -697,7 +697,7 @@ int BackupStoreFile::DecodedStream::Read(void *pBuffer, int NBytes, int Timeout) iv += mCurrentBlock; // Convert to network byte order before encrypting with it, so that restores work on // platforms with different endiannesses. - iv = hton64(iv); + iv = box_hton64(iv); sBlowfishDecryptBlockEntry.SetIV(&iv); // Decrypt the encrypted section @@ -865,7 +865,7 @@ void BackupStoreFile::SetBlowfishKeys(const void *pKey, int KeyLength, const voi } -#ifndef PLATFORM_OLD_OPENSSL +#ifndef HAVE_OLD_SSL // -------------------------------------------------------------------------- // // Function @@ -1036,7 +1036,7 @@ int BackupStoreFile::DecodeChunk(const void *Encoded, int EncodedSize, void *Out THROW_EXCEPTION(BackupStoreException, ChunkHasUnknownEncoding) } -#ifndef PLATFORM_OLD_OPENSSL +#ifndef HAVE_OLD_SSL // Choose cipher CipherContext &cipher((encodingType == HEADER_AES_ENCODING)?sAESDecrypt:sBlowfishDecrypt); #else @@ -1177,7 +1177,7 @@ std::auto_ptr<IOStream> BackupStoreFile::ReorderFileToStreamOrder(IOStream *pStr } // Get number of blocks - int64_t numBlocks = ntoh64(hdr.mNumBlocks); + int64_t numBlocks = box_ntoh64(hdr.mNumBlocks); // Calculate where the block index will be, check it's reasonable int64_t blockIndexSize = ((numBlocks * sizeof(file_BlockIndexEntry)) + sizeof(file_BlockIndexHeader)); @@ -1277,8 +1277,8 @@ bool BackupStoreFile::CompareFileContentsAgainstBlockIndex(const char *Filename, #endif // Get basic information - int64_t numBlocks = ntoh64(hdr.mNumBlocks); - uint64_t entryIVBase = ntoh64(hdr.mEntryIVBase); + int64_t numBlocks = box_ntoh64(hdr.mNumBlocks); + uint64_t entryIVBase = box_ntoh64(hdr.mEntryIVBase); //TODO: Verify that these sizes look reasonable @@ -1303,7 +1303,7 @@ bool BackupStoreFile::CompareFileContentsAgainstBlockIndex(const char *Filename, // Calculate IV for this entry uint64_t iv = entryIVBase; iv += b; - iv = hton64(iv); + iv = box_hton64(iv); #ifndef BOX_DISABLE_BACKWARDS_COMPATIBILITY_BACKUPSTOREFILE if(isOldVersion) { diff --git a/lib/backupclient/BackupStoreFile.h b/lib/backupclient/BackupStoreFile.h index de37e8c8..627de4ce 100755 --- a/lib/backupclient/BackupStoreFile.h +++ b/lib/backupclient/BackupStoreFile.h @@ -113,7 +113,7 @@ public: // Crypto setup static void SetBlowfishKeys(const void *pKey, int KeyLength, const void *pBlockEntryKey, int BlockEntryKeyLength); -#ifndef PLATFORM_OLD_OPENSSL +#ifndef HAVE_OLD_SSL static void SetAESKey(const void *pKey, int KeyLength); #endif diff --git a/lib/backupclient/BackupStoreFileCmbDiff.cpp b/lib/backupclient/BackupStoreFileCmbDiff.cpp index 039b00eb..1a88fa3f 100644 --- a/lib/backupclient/BackupStoreFileCmbDiff.cpp +++ b/lib/backupclient/BackupStoreFileCmbDiff.cpp @@ -63,7 +63,7 @@ void BackupStoreFile::CombineDiffs(IOStream &rDiff1, IOStream &rDiff2, IOStream // Record position diff1DataStarts = rDiff1.GetPosition(); // Skip to index - rDiff1.Seek(0 - (((ntoh64(diff1Hdr.mNumBlocks)) * sizeof(file_BlockIndexEntry)) + sizeof(file_BlockIndexHeader)), IOStream::SeekType_End); + rDiff1.Seek(0 - (((box_ntoh64(diff1Hdr.mNumBlocks)) * sizeof(file_BlockIndexEntry)) + sizeof(file_BlockIndexHeader)), IOStream::SeekType_End); } // Read the index of the first diff @@ -77,7 +77,7 @@ void BackupStoreFile::CombineDiffs(IOStream &rDiff1, IOStream &rDiff2, IOStream { THROW_EXCEPTION(BackupStoreException, BadBackupStoreFile) } - int64_t diff1NumBlocks = ntoh64(diff1IdxHdr.mNumBlocks); + int64_t diff1NumBlocks = box_ntoh64(diff1IdxHdr.mNumBlocks); // Allocate some memory int64_t *diff1BlockStartPositions = (int64_t*)::malloc((diff1NumBlocks + 1) * sizeof(int64_t)); if(diff1BlockStartPositions == 0) @@ -106,7 +106,7 @@ void BackupStoreFile::CombineDiffs(IOStream &rDiff1, IOStream &rDiff2, IOStream } // Where's the block? - int64_t blockEn = ntoh64(e.mEncodedSize); + int64_t blockEn = box_ntoh64(e.mEncodedSize); if(blockEn <= 0) { // Just store the negated block number @@ -157,7 +157,7 @@ void BackupStoreFile::CombineDiffs(IOStream &rDiff1, IOStream &rDiff2, IOStream { THROW_EXCEPTION(BackupStoreException, BadBackupStoreFile) } - int64_t diff2NumBlocks = ntoh64(diff2IdxHdr.mNumBlocks); + int64_t diff2NumBlocks = box_ntoh64(diff2IdxHdr.mNumBlocks); int64_t diff2IndexEntriesStart = rDiff2b.GetPosition(); // Then read all the entries @@ -177,7 +177,7 @@ void BackupStoreFile::CombineDiffs(IOStream &rDiff1, IOStream &rDiff2, IOStream bool fromFileDiff1 = false; // Where's the block? - int64_t blockEn = ntoh64(e.mEncodedSize); + int64_t blockEn = box_ntoh64(e.mEncodedSize); if(blockEn > 0) { // Block is present in this file -- copy to out @@ -274,7 +274,7 @@ void BackupStoreFile::CombineDiffs(IOStream &rDiff1, IOStream &rDiff2, IOStream } // Where's the block? - int64_t blockEn = ntoh64(e.mEncodedSize); + int64_t blockEn = box_ntoh64(e.mEncodedSize); // If it's not in this file, it needs modification... if(blockEn <= 0) @@ -292,12 +292,12 @@ void BackupStoreFile::CombineDiffs(IOStream &rDiff1, IOStream &rDiff2, IOStream ASSERT(nb <= diff1NumBlocks); } int64_t size = diff1BlockStartPositions[nb] - diff1BlockStartPositions[blockIndex]; - e.mEncodedSize = hton64(size); + e.mEncodedSize = box_hton64(size); } else { // Block in the original file, use translated value - e.mEncodedSize = hton64(diff1BlockStartPositions[blockIndex]); + e.mEncodedSize = box_hton64(diff1BlockStartPositions[blockIndex]); } } diff --git a/lib/backupclient/BackupStoreFileCmbIdx.cpp b/lib/backupclient/BackupStoreFileCmbIdx.cpp index 253001c2..c8bcc3b9 100644 --- a/lib/backupclient/BackupStoreFileCmbIdx.cpp +++ b/lib/backupclient/BackupStoreFileCmbIdx.cpp @@ -156,10 +156,10 @@ void BSFCombinedIndexStream::Initialise(IOStream &rFrom) } // Read relevant data. - mNumEntriesToGo = ntoh64(mHeader.mNumBlocks); + mNumEntriesToGo = box_ntoh64(mHeader.mNumBlocks); // Adjust a bit to reflect the fact it's no longer a diff - mHeader.mOtherFileID = hton64(0); + mHeader.mOtherFileID = box_hton64(0); // Now look at the from file: Read header file_BlockIndexHeader fromHdr; @@ -173,7 +173,7 @@ void BSFCombinedIndexStream::Initialise(IOStream &rFrom) } // Then... allocate memory for the list of sizes - mNumEntriesInFromFile = ntoh64(fromHdr.mNumBlocks); + mNumEntriesInFromFile = box_ntoh64(fromHdr.mNumBlocks); mFromBlockSizes = (int64_t*)::malloc(mNumEntriesInFromFile * sizeof(int64_t)); if(mFromBlockSizes == 0) { @@ -190,7 +190,7 @@ void BSFCombinedIndexStream::Initialise(IOStream &rFrom) } // Check that the from file isn't a delta in itself - if(ntoh64(e.mEncodedSize) <= 0) + if(box_ntoh64(e.mEncodedSize) <= 0) { THROW_EXCEPTION(BackupStoreException, OnCombineFromFileIsIncomplete) } @@ -256,7 +256,7 @@ int BSFCombinedIndexStream::Read(void *pBuffer, int NBytes, int Timeout) } // Does this need adjusting? - int s = ntoh64(poutput[b].mEncodedSize); + int s = box_ntoh64(poutput[b].mEncodedSize); if(s <= 0) { // A reference to a block in the from file diff --git a/lib/backupclient/BackupStoreFileCombine.cpp b/lib/backupclient/BackupStoreFileCombine.cpp index 562a32d9..baa331f0 100755 --- a/lib/backupclient/BackupStoreFileCombine.cpp +++ b/lib/backupclient/BackupStoreFileCombine.cpp @@ -94,7 +94,7 @@ void BackupStoreFile::CombineFile(IOStream &rDiff, IOStream &rDiff2, IOStream &r } // Allocate memory for the block index of the From file - int64_t fromNumBlocks = ntoh64(fromHdr.mNumBlocks); + int64_t fromNumBlocks = box_ntoh64(fromHdr.mNumBlocks); // NOTE: An extra entry is required so that the length of the last block can be calculated FromIndexEntry *pFromIndex = (FromIndexEntry*)::malloc((fromNumBlocks+1) * sizeof(FromIndexEntry)); if(pFromIndex == 0) @@ -110,7 +110,7 @@ void BackupStoreFile::CombineFile(IOStream &rDiff, IOStream &rDiff2, IOStream &r // Read in the block index of the Diff file in small chunks, and output data // for each block, either from this file, or the other file. - int64_t diffNumBlocks = ntoh64(hdr.mNumBlocks); + int64_t diffNumBlocks = box_ntoh64(hdr.mNumBlocks); CopyData(rDiff /* positioned at start of data */, rDiff2, diffNumBlocks, rFrom, pFromIndex, fromNumBlocks, rOut); // Read in the block index again, and output the new block index, simply @@ -160,7 +160,7 @@ static void LoadFromIndex(IOStream &rFrom, FromIndexEntry *pIndex, int64_t NumEn THROW_EXCEPTION(BackupStoreException, FailedToReadBlockOnCombine) } if(ntohl(blkhdr.mMagicValue) != OBJECTMAGIC_FILE_BLOCKS_MAGIC_VALUE_V1 - || (int64_t)ntoh64(blkhdr.mNumBlocks) != NumEntries) + || (int64_t)box_ntoh64(blkhdr.mNumBlocks) != NumEntries) { THROW_EXCEPTION(BackupStoreException, BadBackupStoreFile) } @@ -179,7 +179,7 @@ static void LoadFromIndex(IOStream &rFrom, FromIndexEntry *pIndex, int64_t NumEn pIndex[b].mFilePosition = filePos; // Encoded size? - int64_t encodedSize = ntoh64(en.mEncodedSize); + int64_t encodedSize = box_ntoh64(en.mEncodedSize); // Check that the block is actually there if(encodedSize <= 0) { @@ -220,7 +220,7 @@ static void CopyData(IOStream &rDiffData, IOStream &rDiffIndex, int64_t DiffNumB THROW_EXCEPTION(BackupStoreException, FailedToReadBlockOnCombine) } if(ntohl(diffBlkhdr.mMagicValue) != OBJECTMAGIC_FILE_BLOCKS_MAGIC_VALUE_V1 - || (int64_t)ntoh64(diffBlkhdr.mNumBlocks) != DiffNumBlocks) + || (int64_t)box_ntoh64(diffBlkhdr.mNumBlocks) != DiffNumBlocks) { THROW_EXCEPTION(BackupStoreException, BadBackupStoreFile) } @@ -245,7 +245,7 @@ static void CopyData(IOStream &rDiffData, IOStream &rDiffIndex, int64_t DiffNumB } // What's the size value stored in the entry - int64_t encodedSize = ntoh64(en.mEncodedSize); + int64_t encodedSize = box_ntoh64(en.mEncodedSize); // How much data will be read? int32_t blockSize = 0; @@ -362,13 +362,13 @@ static void WriteNewIndex(IOStream &rDiff, int64_t DiffNumBlocks, FromIndexEntry THROW_EXCEPTION(BackupStoreException, FailedToReadBlockOnCombine) } if(ntohl(diffBlkhdr.mMagicValue) != OBJECTMAGIC_FILE_BLOCKS_MAGIC_VALUE_V1 - || (int64_t)ntoh64(diffBlkhdr.mNumBlocks) != DiffNumBlocks) + || (int64_t)box_ntoh64(diffBlkhdr.mNumBlocks) != DiffNumBlocks) { THROW_EXCEPTION(BackupStoreException, BadBackupStoreFile) } // Write it out with a blanked out other file ID - diffBlkhdr.mOtherFileID = hton64(0); + diffBlkhdr.mOtherFileID = box_hton64(0); rOut.Write(&diffBlkhdr, sizeof(diffBlkhdr)); // Rewrite the index @@ -381,7 +381,7 @@ static void WriteNewIndex(IOStream &rDiff, int64_t DiffNumBlocks, FromIndexEntry } // What's the size value stored in the entry - int64_t encodedSize = ntoh64(en.mEncodedSize); + int64_t encodedSize = box_ntoh64(en.mEncodedSize); // Need to adjust it? if(encodedSize <= 0) @@ -396,7 +396,7 @@ static void WriteNewIndex(IOStream &rDiff, int64_t DiffNumBlocks, FromIndexEntry // Calculate size. This operation is safe because of the extra entry at the end int32_t blockSize = pFromIndex[blockIdx + 1].mFilePosition - pFromIndex[blockIdx].mFilePosition; // Then replace entry - en.mEncodedSize = hton64(((uint64_t)blockSize)); + en.mEncodedSize = box_hton64(((uint64_t)blockSize)); } // Write entry diff --git a/lib/backupclient/BackupStoreFileCryptVar.cpp b/lib/backupclient/BackupStoreFileCryptVar.cpp index eeed64e4..e826de4e 100755 --- a/lib/backupclient/BackupStoreFileCryptVar.cpp +++ b/lib/backupclient/BackupStoreFileCryptVar.cpp @@ -17,7 +17,7 @@ CipherContext BackupStoreFileCryptVar::sBlowfishEncrypt; CipherContext BackupStoreFileCryptVar::sBlowfishDecrypt; -#ifndef PLATFORM_OLD_OPENSSL +#ifndef HAVE_OLD_SSL CipherContext BackupStoreFileCryptVar::sAESEncrypt; CipherContext BackupStoreFileCryptVar::sAESDecrypt; #endif diff --git a/lib/backupclient/BackupStoreFileCryptVar.h b/lib/backupclient/BackupStoreFileCryptVar.h index 00a34f71..566813c8 100755 --- a/lib/backupclient/BackupStoreFileCryptVar.h +++ b/lib/backupclient/BackupStoreFileCryptVar.h @@ -22,7 +22,7 @@ namespace BackupStoreFileCryptVar extern CipherContext sBlowfishEncrypt; extern CipherContext sBlowfishDecrypt; // Use AES when available -#ifndef PLATFORM_OLD_OPENSSL +#ifndef HAVE_OLD_SSL extern CipherContext sAESEncrypt; extern CipherContext sAESDecrypt; #endif diff --git a/lib/backupclient/BackupStoreFileDiff.cpp b/lib/backupclient/BackupStoreFileDiff.cpp index 22395151..3699eb49 100755 --- a/lib/backupclient/BackupStoreFileDiff.cpp +++ b/lib/backupclient/BackupStoreFileDiff.cpp @@ -105,7 +105,7 @@ void BackupStoreFile::MoveStreamPositionToBlockIndex(IOStream &rStream) } // Work out where the index is - int64_t numBlocks = ntoh64(hdr.mNumBlocks); + int64_t numBlocks = box_ntoh64(hdr.mNumBlocks); int64_t blockHeaderPosFromEnd = ((numBlocks * sizeof(file_BlockIndexEntry)) + sizeof(file_BlockIndexHeader)); // Sanity check @@ -298,7 +298,7 @@ static void LoadIndex(IOStream &rBlockIndex, int64_t ThisID, BlocksAvailableEntr } // Check that we're not trying to diff against a file which references blocks from another file - if(((int64_t)ntoh64(hdr.mOtherFileID)) != 0) + if(((int64_t)box_ntoh64(hdr.mOtherFileID)) != 0) { THROW_EXCEPTION(BackupStoreException, CannotDiffAnIncompleteStoreFile) } @@ -307,8 +307,8 @@ static void LoadIndex(IOStream &rBlockIndex, int64_t ThisID, BlocksAvailableEntr rCanDiffFromThis = true; // Get basic information - int64_t numBlocks = ntoh64(hdr.mNumBlocks); - uint64_t entryIVBase = ntoh64(hdr.mEntryIVBase); + int64_t numBlocks = box_ntoh64(hdr.mNumBlocks); + uint64_t entryIVBase = box_ntoh64(hdr.mEntryIVBase); //TODO: Verify that these sizes look reasonable @@ -335,7 +335,7 @@ static void LoadIndex(IOStream &rBlockIndex, int64_t ThisID, BlocksAvailableEntr uint64_t iv = entryIVBase; iv += b; // Network byte order - iv = hton64(iv); + iv = box_hton64(iv); sBlowfishDecryptBlockEntry.SetIV(&iv); // Decrypt the encrypted section @@ -348,7 +348,7 @@ static void LoadIndex(IOStream &rBlockIndex, int64_t ThisID, BlocksAvailableEntr } // Check that we're not trying to diff against a file which references blocks from another file - if(((int64_t)ntoh64(entry.mEncodedSize)) <= 0) + if(((int64_t)box_ntoh64(entry.mEncodedSize)) <= 0) { THROW_EXCEPTION(BackupStoreException, CannotDiffAnIncompleteStoreFile) } diff --git a/lib/backupclient/BackupStoreFileEncodeStream.cpp b/lib/backupclient/BackupStoreFileEncodeStream.cpp index 20e1fd80..c692f18e 100755 --- a/lib/backupclient/BackupStoreFileEncodeStream.cpp +++ b/lib/backupclient/BackupStoreFileEncodeStream.cpp @@ -178,9 +178,9 @@ void BackupStoreFileEncodeStream::Setup(const char *Filename, BackupStoreFileEnc // Header file_StreamFormat hdr; hdr.mMagicValue = htonl(OBJECTMAGIC_FILE_MAGIC_VALUE_V1); - hdr.mNumBlocks = (mSendData)?(hton64(mTotalBlocks)):(0); - hdr.mContainerID = hton64(ContainerID); - hdr.mModificationTime = hton64(modTime); + hdr.mNumBlocks = (mSendData)?(box_hton64(mTotalBlocks)):(0); + hdr.mContainerID = box_hton64(ContainerID); + hdr.mModificationTime = box_hton64(modTime); // add a bit to make it harder to tell what's going on -- try not to give away too much info about file size hdr.mMaxBlockClearSize = htonl(maxBlockClearSize + 128); hdr.mOptions = 0; // no options defined yet @@ -221,9 +221,9 @@ void BackupStoreFileEncodeStream::Setup(const char *Filename, BackupStoreFileEnc // Write an empty block index for the symlink file_BlockIndexHeader blkhdr; blkhdr.mMagicValue = htonl(OBJECTMAGIC_FILE_BLOCKS_MAGIC_VALUE_V1); - blkhdr.mOtherFileID = hton64(0); // not other file ID - blkhdr.mEntryIVBase = hton64(0); - blkhdr.mNumBlocks = hton64(0); + blkhdr.mOtherFileID = box_hton64(0); // not other file ID + blkhdr.mEntryIVBase = box_hton64(0); + blkhdr.mNumBlocks = box_hton64(0); mData.Write(&blkhdr, sizeof(blkhdr)); } @@ -338,12 +338,12 @@ int BackupStoreFileEncodeStream::Read(void *pBuffer, int NBytes, int Timeout) file_BlockIndexHeader blkhdr; blkhdr.mMagicValue = htonl(OBJECTMAGIC_FILE_BLOCKS_MAGIC_VALUE_V1); ASSERT(mpRecipe != 0); - blkhdr.mOtherFileID = hton64(mpRecipe->GetOtherFileID()); - blkhdr.mNumBlocks = hton64(mTotalBlocks); + blkhdr.mOtherFileID = box_hton64(mpRecipe->GetOtherFileID()); + blkhdr.mNumBlocks = box_hton64(mTotalBlocks); // Generate the IV base Random::Generate(&mEntryIVBase, sizeof(mEntryIVBase)); - blkhdr.mEntryIVBase = hton64(mEntryIVBase); + blkhdr.mEntryIVBase = box_hton64(mEntryIVBase); mData.Write(&blkhdr, sizeof(blkhdr)); } @@ -568,7 +568,7 @@ void BackupStoreFileEncodeStream::StoreBlockIndexEntry(int64_t EncSizeOrBlkIndex // Then the clear section file_BlockIndexEntry entry; - entry.mEncodedSize = hton64(((uint64_t)EncSizeOrBlkIndex)); + entry.mEncodedSize = box_hton64(((uint64_t)EncSizeOrBlkIndex)); // Then encrypt the encryted section // Generate the IV from the block number @@ -580,7 +580,7 @@ void BackupStoreFileEncodeStream::StoreBlockIndexEntry(int64_t EncSizeOrBlkIndex iv += mAbsoluteBlockNumber; // Convert to network byte order before encrypting with it, so that restores work on // platforms with different endiannesses. - iv = hton64(iv); + iv = box_hton64(iv); sBlowfishEncryptBlockEntry.SetIV(&iv); // Encode the data diff --git a/lib/backupclient/BackupStoreFileRevDiff.cpp b/lib/backupclient/BackupStoreFileRevDiff.cpp index f1dc52d8..509eef61 100644 --- a/lib/backupclient/BackupStoreFileRevDiff.cpp +++ b/lib/backupclient/BackupStoreFileRevDiff.cpp @@ -59,7 +59,7 @@ void BackupStoreFile::ReverseDiffFile(IOStream &rDiff, IOStream &rFrom, IOStream // Build an index of common blocks. // For each block in the from file, we want to know it's index in the // diff file. Allocate memory for this information. - int64_t fromNumBlocks = ntoh64(hdr.mNumBlocks); + int64_t fromNumBlocks = box_ntoh64(hdr.mNumBlocks); int64_t *pfromIndexInfo = (int64_t*)::malloc(fromNumBlocks * sizeof(int64_t)); if(pfromIndexInfo == 0) { @@ -96,7 +96,7 @@ void BackupStoreFile::ReverseDiffFile(IOStream &rDiff, IOStream &rFrom, IOStream } // And then read in each entry - int64_t diffNumBlocks = ntoh64(diffIdxHdr.mNumBlocks); + int64_t diffNumBlocks = box_ntoh64(diffIdxHdr.mNumBlocks); for(int64_t b = 0; b < diffNumBlocks; ++b) { file_BlockIndexEntry e; @@ -106,7 +106,7 @@ void BackupStoreFile::ReverseDiffFile(IOStream &rDiff, IOStream &rFrom, IOStream } // Where's the block? - int64_t blockEn = ntoh64(e.mEncodedSize); + int64_t blockEn = box_ntoh64(e.mEncodedSize); if(blockEn > 0) { // Block is in the delta file, is ignored for now -- not relevant to rebuilding the from file @@ -136,7 +136,7 @@ void BackupStoreFile::ReverseDiffFile(IOStream &rDiff, IOStream &rFrom, IOStream THROW_EXCEPTION(BackupStoreException, CouldntReadEntireStructureFromStream) } if(ntohl(fromIdxHdr.mMagicValue) != OBJECTMAGIC_FILE_BLOCKS_MAGIC_VALUE_V1 - || ntoh64(fromIdxHdr.mOtherFileID) != 0) + || box_ntoh64(fromIdxHdr.mOtherFileID) != 0) { THROW_EXCEPTION(BackupStoreException, BadBackupStoreFile) } @@ -153,7 +153,7 @@ void BackupStoreFile::ReverseDiffFile(IOStream &rDiff, IOStream &rFrom, IOStream } // Get size - int64_t blockSize = hton64(e.mEncodedSize); + int64_t blockSize = box_hton64(e.mEncodedSize); if(blockSize < 0) { THROW_EXCEPTION(BackupStoreException, BadBackupStoreFile) @@ -204,7 +204,7 @@ void BackupStoreFile::ReverseDiffFile(IOStream &rDiff, IOStream &rFrom, IOStream } // Then write the index, modified header first - fromIdxHdr.mOtherFileID = isCompletelyDifferent?0:(hton64(ObjectIDOfFrom)); + fromIdxHdr.mOtherFileID = isCompletelyDifferent?0:(box_hton64(ObjectIDOfFrom)); rOut.Write(&fromIdxHdr, sizeof(fromIdxHdr)); // Move to start of index entries @@ -225,7 +225,7 @@ void BackupStoreFile::ReverseDiffFile(IOStream &rDiff, IOStream &rFrom, IOStream // Adjust to reflect real block index (remember 0 has a different meaning here) if(s < 0) ++s; // Insert - e.mEncodedSize = hton64(s); + e.mEncodedSize = box_hton64(s); // Write rOut.Write(&e, sizeof(e)); } diff --git a/lib/backupclient/BackupStoreFileWire.h b/lib/backupclient/BackupStoreFileWire.h index 5b1bc819..49e94aa5 100755 --- a/lib/backupclient/BackupStoreFileWire.h +++ b/lib/backupclient/BackupStoreFileWire.h @@ -13,7 +13,7 @@ #include "MD5Digest.h" // set packing to one byte -#ifdef STRUCTURE_PATCKING_FOR_WIRE_USE_HEADERS +#ifdef STRUCTURE_PACKING_FOR_WIRE_USE_HEADERS #include "BeginStructPackForWire.h" #else BEGIN_STRUCTURE_PACKING_FOR_WIRE @@ -57,7 +57,7 @@ typedef struct } file_BlockIndexEntry; // Use default packing -#ifdef STRUCTURE_PATCKING_FOR_WIRE_USE_HEADERS +#ifdef STRUCTURE_PACKING_FOR_WIRE_USE_HEADERS #include "EndStructPackForWire.h" #else END_STRUCTURE_PACKING_FOR_WIRE diff --git a/lib/backupclient/BackupStoreFilename.h b/lib/backupclient/BackupStoreFilename.h index 4c951b6f..a7b6c437 100755 --- a/lib/backupclient/BackupStoreFilename.h +++ b/lib/backupclient/BackupStoreFilename.h @@ -30,7 +30,7 @@ class IOStream; // If this is changed, change GetClearFilename() back to returning a reference. #else typedef std::string BackupStoreFilename_base; -#endif // PLATFORM_HAVE_STL_MALLOC_ALLOC +#endif // -------------------------------------------------------------------------- // diff --git a/lib/backupclient/BackupStoreObjectDump.cpp b/lib/backupclient/BackupStoreObjectDump.cpp index caa0e82f..5f902831 100644 --- a/lib/backupclient/BackupStoreObjectDump.cpp +++ b/lib/backupclient/BackupStoreObjectDump.cpp @@ -152,9 +152,9 @@ void BackupStoreFile::DumpFile(void *clibFileHandle, bool ToTrace, IOStream &rFi } OutputLine(file, ToTrace, "File object.\nContainer ID: %llx\nModification time: %llx\n"\ - "Max block clear size: %d\nOptions: %08x\nNum blocks: %d\n", ntoh64(hdr.mContainerID), - ntoh64(hdr.mModificationTime), ntohl(hdr.mMaxBlockClearSize), ntohl(hdr.mOptions), - ntoh64(hdr.mNumBlocks)); + "Max block clear size: %d\nOptions: %08x\nNum blocks: %d\n", box_ntoh64(hdr.mContainerID), + box_ntoh64(hdr.mModificationTime), ntohl(hdr.mMaxBlockClearSize), ntohl(hdr.mOptions), + box_ntoh64(hdr.mNumBlocks)); // Read the next two objects BackupStoreFilename fn; @@ -178,9 +178,9 @@ void BackupStoreFile::DumpFile(void *clibFileHandle, bool ToTrace, IOStream &rFi OutputLine(file, ToTrace, "WARNING: Block header doesn't have the correct magic\n"); } // number of blocks - int64_t nblocks = ntoh64(bhdr.mNumBlocks); + int64_t nblocks = box_ntoh64(bhdr.mNumBlocks); OutputLine(file, ToTrace, "Other file ID (for block refs): %llx\nNum blocks (in blk hdr): %lld\n", - ntoh64(bhdr.mOtherFileID), nblocks); + box_ntoh64(bhdr.mOtherFileID), nblocks); // Dump info about each block OutputLine(file, ToTrace, "======== ===== ==========\n Index Where EncSz/Idx\n"); @@ -193,7 +193,7 @@ void BackupStoreFile::DumpFile(void *clibFileHandle, bool ToTrace, IOStream &rFi OutputLine(file, ToTrace, "Didn't manage to read block %lld from file\n", b); continue; } - int64_t s = ntoh64(en.mEncodedSize); + int64_t s = box_ntoh64(en.mEncodedSize); if(s > 0) { nnew++; diff --git a/lib/backupstore/BackupStoreCheck2.cpp b/lib/backupstore/BackupStoreCheck2.cpp index fe91d00d..63e7c008 100644 --- a/lib/backupstore/BackupStoreCheck2.cpp +++ b/lib/backupstore/BackupStoreCheck2.cpp @@ -377,7 +377,7 @@ void BackupStoreCheck::InsertObjectIntoDirectory(int64_t ObjectID, int64_t Direc THROW_EXCEPTION(BackupStoreException, Internal) } // This tells us nice things - modTime = ntoh64(hdr.mModificationTime); + modTime = box_ntoh64(hdr.mModificationTime); // And the filename comes next objectStoreFilename.ReadFromStream(*file, IOStream::TimeOutInfinite); } diff --git a/lib/backupstore/BackupStoreInfo.cpp b/lib/backupstore/BackupStoreInfo.cpp index a9effe00..ce785dde 100755 --- a/lib/backupstore/BackupStoreInfo.cpp +++ b/lib/backupstore/BackupStoreInfo.cpp @@ -19,7 +19,7 @@ #include "MemLeakFindOn.h" // set packing to one byte -#ifdef STRUCTURE_PATCKING_FOR_WIRE_USE_HEADERS +#ifdef STRUCTURE_PACKING_FOR_WIRE_USE_HEADERS #include "BeginStructPackForWire.h" #else BEGIN_STRUCTURE_PACKING_FOR_WIRE @@ -49,7 +49,7 @@ typedef struct #define INFO_MAGIC_VALUE 0x34832476 // Use default packing -#ifdef STRUCTURE_PATCKING_FOR_WIRE_USE_HEADERS +#ifdef STRUCTURE_PACKING_FOR_WIRE_USE_HEADERS #include "EndStructPackForWire.h" #else END_STRUCTURE_PACKING_FOR_WIRE @@ -111,13 +111,13 @@ void BackupStoreInfo::CreateNew(int32_t AccountID, const std::string &rRootDir, htonl(INFO_MAGIC_VALUE), // mMagicValue htonl(AccountID), // mAccountID 0, // mClientStoreMarker - hton64(1), // mLastObjectIDUsed (which is the root directory) + box_hton64(1), // mLastObjectIDUsed (which is the root directory) 0, // mBlocksUsed 0, // mBlocksInOldFiles 0, // mBlocksInDeletedFiles 0, // mBlocksInDirectories - hton64(BlockSoftLimit), // mBlocksSoftLimit - hton64(BlockHardLimit), // mBlocksHardLimit + box_hton64(BlockSoftLimit), // mBlocksSoftLimit + box_hton64(BlockHardLimit), // mBlocksHardLimit 0, // mCurrentMarkNumber 0, // mOptionsPresent 0 // mNumberDeletedDirectories @@ -179,17 +179,17 @@ std::auto_ptr<BackupStoreInfo> BackupStoreInfo::Load(int32_t AccountID, const st info->mReadOnly = ReadOnly; // Insert info from file - info->mClientStoreMarker = ntoh64(hdr.mClientStoreMarker); - info->mLastObjectIDUsed = ntoh64(hdr.mLastObjectIDUsed); - info->mBlocksUsed = ntoh64(hdr.mBlocksUsed); - info->mBlocksInOldFiles = ntoh64(hdr.mBlocksInOldFiles); - info->mBlocksInDeletedFiles = ntoh64(hdr.mBlocksInDeletedFiles); - info->mBlocksInDirectories = ntoh64(hdr.mBlocksInDirectories); - info->mBlocksSoftLimit = ntoh64(hdr.mBlocksSoftLimit); - info->mBlocksHardLimit = ntoh64(hdr.mBlocksHardLimit); + info->mClientStoreMarker = box_ntoh64(hdr.mClientStoreMarker); + info->mLastObjectIDUsed = box_ntoh64(hdr.mLastObjectIDUsed); + info->mBlocksUsed = box_ntoh64(hdr.mBlocksUsed); + info->mBlocksInOldFiles = box_ntoh64(hdr.mBlocksInOldFiles); + info->mBlocksInDeletedFiles = box_ntoh64(hdr.mBlocksInDeletedFiles); + info->mBlocksInDirectories = box_ntoh64(hdr.mBlocksInDirectories); + info->mBlocksSoftLimit = box_ntoh64(hdr.mBlocksSoftLimit); + info->mBlocksHardLimit = box_ntoh64(hdr.mBlocksHardLimit); // Load up array of deleted objects - int64_t numDelObj = ntoh64(hdr.mNumberDeletedDirectories); + int64_t numDelObj = box_ntoh64(hdr.mNumberDeletedDirectories); // Then load them in if(numDelObj > 0) @@ -210,7 +210,7 @@ std::auto_ptr<BackupStoreInfo> BackupStoreInfo::Load(int32_t AccountID, const st // Add them for(int t = 0; t < b; ++t) { - info->mDeletedDirectories.push_back(ntoh64(objs[t])); + info->mDeletedDirectories.push_back(box_ntoh64(objs[t])); } // Number loaded @@ -298,17 +298,17 @@ void BackupStoreInfo::Save() info_StreamFormat hdr; hdr.mMagicValue = htonl(INFO_MAGIC_VALUE); hdr.mAccountID = htonl(mAccountID); - hdr.mClientStoreMarker = hton64(mClientStoreMarker); - hdr.mLastObjectIDUsed = hton64(mLastObjectIDUsed); - hdr.mBlocksUsed = hton64(mBlocksUsed); - hdr.mBlocksInOldFiles = hton64(mBlocksInOldFiles); - hdr.mBlocksInDeletedFiles = hton64(mBlocksInDeletedFiles); - hdr.mBlocksInDirectories = hton64(mBlocksInDirectories); - hdr.mBlocksSoftLimit = hton64(mBlocksSoftLimit); - hdr.mBlocksHardLimit = hton64(mBlocksHardLimit); + hdr.mClientStoreMarker = box_hton64(mClientStoreMarker); + hdr.mLastObjectIDUsed = box_hton64(mLastObjectIDUsed); + hdr.mBlocksUsed = box_hton64(mBlocksUsed); + hdr.mBlocksInOldFiles = box_hton64(mBlocksInOldFiles); + hdr.mBlocksInDeletedFiles = box_hton64(mBlocksInDeletedFiles); + hdr.mBlocksInDirectories = box_hton64(mBlocksInDirectories); + hdr.mBlocksSoftLimit = box_hton64(mBlocksSoftLimit); + hdr.mBlocksHardLimit = box_hton64(mBlocksHardLimit); hdr.mCurrentMarkNumber = 0; hdr.mOptionsPresent = 0; - hdr.mNumberDeletedDirectories = hton64(mDeletedDirectories.size()); + hdr.mNumberDeletedDirectories = box_hton64(mDeletedDirectories.size()); // Write header rf.Write(&hdr, sizeof(hdr)); @@ -329,7 +329,7 @@ void BackupStoreInfo::Save() for(int t = 0; t < b; ++t) { ASSERT(i != mDeletedDirectories.end()); - objs[t] = hton64((*i)); + objs[t] = box_hton64((*i)); i++; } diff --git a/lib/common/BeginStructPackForWire.h b/lib/common/BeginStructPackForWire.h index f9f8f616..e73bb886 100644 --- a/lib/common/BeginStructPackForWire.h +++ b/lib/common/BeginStructPackForWire.h @@ -9,7 +9,7 @@ // No header guard -- this is intentional -#ifdef STRUCTURE_PATCKING_FOR_WIRE_USE_HEADERS +#ifdef STRUCTURE_PACKING_FOR_WIRE_USE_HEADERS #pragma pack(1) diff --git a/lib/common/Box.h b/lib/common/Box.h index 19e78ada..4a76e74e 100755 --- a/lib/common/Box.h +++ b/lib/common/Box.h @@ -21,12 +21,13 @@ //#define MEMLEAKFINDER_FULL_MALLOC_MONITORING #ifndef NDEBUG - // not available on OpenBSD... oh well. - //#define SHOW_BACKTRACE_ON_EXCEPTION + #ifdef HAVE_EXECINFO_H + #define SHOW_BACKTRACE_ON_EXCEPTION + #endif #endif #ifdef SHOW_BACKTRACE_ON_EXCEPTION - // include "Utils.h" + #include "Utils.h" #define OPTIONAL_DO_BACKTRACE DumpStackBacktrace(); #else #define OPTIONAL_DO_BACKTRACE @@ -126,55 +127,17 @@ inline uint64_t box_swap64(uint64_t x) (x & 0xff00000000000000LL) >> 56); } -// Does the platform provide a built in SWAP64 we can use? -#ifdef PLATFORM_NO_BUILT_IN_SWAP64 - - #define hton64(x) box_swap64(x) - #define ntoh64(x) box_swap64(x) - +#ifdef WORDS_BIGENDIAN + #define box_hton64(x) (x) + #define box_ntoh64(x) (x) #else + #define box_hton64(x) box_swap64(x) + #define box_ntoh64(x) box_swap64(x) +#endif - #if BYTE_ORDER == BIG_ENDIAN - - // Less hassle than trying to find some working things - // on Darwin PPC - #define hton64(x) (x) - #define ntoh64(x) (x) - - #else - - #ifdef PLATFORM_LINUX - // On Linux, use some internal kernal stuff to do this - #include <asm/byteorder.h> - #define hton64 __cpu_to_be64 - #define ntoh64 __be64_to_cpu - #else - #define hton64 htobe64 - #define ntoh64 betoh64 - #endif - - // hack to make some of these work - // version in /usr/include/sys/endian.h doesn't include the 'LL' at the end of the constants - // provoking complaints from the compiler - #ifdef __GNUC__ - #undef __swap64gen - #define __swap64gen(x) __extension__({ \ - u_int64_t __swap64gen_x = (x); \ - \ - (u_int64_t)((__swap64gen_x & 0xff) << 56 | \ - (__swap64gen_x & 0xff00LL) << 40 | \ - (__swap64gen_x & 0xff0000LL) << 24 | \ - (__swap64gen_x & 0xff000000LL) << 8 | \ - (__swap64gen_x & 0xff00000000LL) >> 8 | \ - (__swap64gen_x & 0xff0000000000LL) >> 24 | \ - (__swap64gen_x & 0xff000000000000LL) >> 40 | \ - (__swap64gen_x & 0xff00000000000000LL) >> 56); \ - }) - #endif // __GNUC__ - - #endif // n BYTE_ORDER == BIG_ENDIAN - -#endif // PLATFORM_NO_BUILT_IN_SWAP64 +#ifdef HAVE_NETINET_IN_H + #include <netinet/in.h> +#endif #endif // BOX__H diff --git a/lib/common/BoxPlatform.h b/lib/common/BoxPlatform.h index 3b75f992..6ddd1643 100755 --- a/lib/common/BoxPlatform.h +++ b/lib/common/BoxPlatform.h @@ -16,266 +16,76 @@ #define PLATFORM_DEV_NULL "/dev/null" +#include "config.h" -// Other flags which might be useful... -// -// #define PLATFORM_BERKELEY_DB_NOT_SUPPORTED -// -- dbopen etc not on this platform -// -// #define PLATFORM_REGEX_NOT_SUPPORTED -// -- regex support not available on this platform - - -#ifdef PLATFORM_OPENBSD - - #include <sys/types.h> - - #define PLATFORM_HAVE_setproctitle - - #define PLATFORM_STATIC_TEMP_DIRECTORY_NAME "/tmp" - - #define PLATFORM_HAVE_getpeereid - - #define PLATFORM_RANDOM_DEVICE "/dev/arandom" - -#endif // PLATFORM_OPENBSD - -#ifdef PLATFORM_NETBSD - +#ifdef HAVE_SYS_TYPES_H #include <sys/types.h> - - #define PLATFORM_HAVE_setproctitle - - #define PLATFORM_NO_BUILT_IN_SWAP64 - - #define PLATFORM_STATIC_TEMP_DIRECTORY_NAME "/tmp" - - #define PLATFORM_KQUEUE_NOT_SUPPORTED - - #define PLATFORM_RANDOM_DEVICE "/dev/urandom" - #endif - -#ifdef PLATFORM_FREEBSD - - #include <sys/types.h> - #include <netinet/in.h> - - #define PLATFORM_HAVE_setproctitle - - #define PLATFORM_NO_BUILT_IN_SWAP64 - - #define PLATFORM_STATIC_TEMP_DIRECTORY_NAME "/tmp" - - #define PLATFORM_HAVE_getpeereid - - #define PLATFORM_RANDOM_DEVICE "/dev/urandom" - -#endif // PLATFORM_FREEBSD - -#ifdef PLATFORM_DARWIN - - #include <sys/types.h> - #include <netdb.h> - - // types 'missing' - #ifndef _SOCKLEN_T - typedef int socklen_t; +#ifdef HAVE_INTTYPES_H + #include <inttypes.h> +#else + #ifdef HAVE_STDINT_H + #include <stdint.h> #endif - typedef u_int8_t uint8_t; - typedef signed char int8_t; - typedef u_int64_t uint64_t; - typedef u_int32_t uint32_t; - typedef u_int16_t uint16_t; - - // poll() emulator on Darwin misses this declaration - #define INFTIM -1 +#endif - #define PLATFORM_STATIC_TEMP_DIRECTORY_NAME "/tmp" - - #define PLATFORM_LCHOWN_NOT_SUPPORTED - - #define PLATFORM_READLINE_NOT_SUPPORTED +// Find out if credentials on UNIX sockets can be obtained +#ifndef HAVE_GETPEEREID + #if !HAVE_DECL_SO_PEERCRED + #define PLATFORM_CANNOT_FIND_PEER_UID_OF_UNIX_SOCKET + #endif +#endif - #define PLATFORM_RANDOM_DEVICE "/dev/random" - -#endif // PLATFORM_DARWIN +// Cannot do the intercepts in test/raidfile if large file support is enabled +#ifdef HAVE_LARGE_FILE_SUPPORT + #define PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE +#endif -#ifdef PLATFORM_LINUX - - #include <sys/types.h> +#ifdef HAVE_DEFINE_PRAGMA + // set packing to one bytes (can't use push/pop on gcc) + #define BEGIN_STRUCTURE_PACKING_FOR_WIRE #pragma pack(1) - // for ntohl etc... - #include <netinet/in.h> + // Use default packing + #define END_STRUCTURE_PACKING_FOR_WIRE #pragma pack() +#else + #define STRUCTURE_PACKING_FOR_WIRE_USE_HEADERS +#endif - // types 'missing' +// Define missing types +#ifndef HAVE_UINT8_T typedef u_int8_t uint8_t; - typedef signed char int8_t; - typedef u_int32_t uint32_t; - typedef u_int16_t uint16_t; - typedef u_int64_t uint64_t; - - // not defined in Linux, a BSD thing - #define INFTIM -1 - - #define LLONG_MAX 9223372036854775807LL - #define LLONG_MIN (-LLONG_MAX - 1LL) - - #define PLATFORM_STATIC_TEMP_DIRECTORY_NAME "/tmp" - - #define PLATFORM_HAVE_getsockopt_SO_PEERCRED - - // load in installation specific linux configuration - #include "../../local/_linux_platform.h" - - #define PLATFORM_KQUEUE_NOT_SUPPORTED - #define PLATFORM_dirent_BROKEN_d_type - #define PLATFORM_stat_SHORT_mtime - #define PLATFORM_stat_NO_st_flags - #define PLATFORM_USES_MTAB_FILE_FOR_MOUNTS - #define PLATFORM_open_USE_flock - #define PLATFORM_sockaddr_NO_len - - #define PLATFORM_RANDOM_DEVICE "/dev/urandom" - - // If large file support is on, can't do the intercepts in the test/raidfile - #if _FILE_OFFSET_BITS == 64 - #define PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE - #endif - -#endif // PLATFORM_LINUX +#endif -#ifdef PLATFORM_SUNOS +#ifndef HAVE_UINT16_T + typedef u_int16_t uint16_t; +#endif - #include <sys/types.h> +#ifndef HAVE_UINT32_T + typedef u_int32_t uint32_t; +#endif - // for ntohl etc... - #include <netinet/in.h> +#ifndef HAVE_UINT64_T + typedef u_int64_t uint64_t; +#endif - // types 'missing' +#ifndef HAVE_U_INT8_T typedef uint8_t u_int8_t; -// typedef signed char int8_t; - typedef uint32_t u_int32_t; - typedef uint16_t u_int16_t; - typedef uint64_t u_int64_t; - - // not defined in Solaris, a BSD thing - #define INFTIM -1 - - //#define LLONG_MAX 9223372036854775807LL - //#define LLONG_MIN (-LLONG_MAX - 1LL) - - #define PLATFORM_STATIC_TEMP_DIRECTORY_NAME "/tmp" - - #define PLATFORM_BERKELEY_DB_NOT_SUPPORTED - #define PLATFORM_KQUEUE_NOT_SUPPORTED // This may be in Solaris 10 - #define PLATFORM_dirent_BROKEN_d_type // Well, no d_type at all actually - #define PLATFORM_stat_SHORT_mtime - #define PLATFORM_stat_NO_st_flags - #define PLATFORM_USES_MTAB_FILE_FOR_MOUNTS - #define PLATFORM_open_USE_fcntl - #define PLATFORM_sockaddr_NO_len - - #define PLATFORM_RANDOM_DEVICE "/dev/urandom" - -#endif // PLATFORM_SUNOS - -#ifdef PLATFORM_CYGWIN - - #define PLATFORM_BERKELEY_DB_NOT_SUPPORTED - - #define PLATFORM_KQUEUE_NOT_SUPPORTED - #define PLATFORM_dirent_BROKEN_d_type - #define PLATFORM_stat_SHORT_mtime - #define PLATFORM_stat_NO_st_flags - #define PLATFORM_USES_MTAB_FILE_FOR_MOUNTS - #define PLATFORM_open_USE_flock - #define PLATFORM_sockaddr_NO_len - #define PLATFORM_NO_BUILT_IN_SWAP64 - - #define PLATFORM_STATIC_TEMP_DIRECTORY_NAME "/tmp" - - #define PLATFORM_READLINE_NOT_SUPPORTED - - #define LLONG_MAX 9223372036854775807LL - #define LLONG_MIN (-LLONG_MAX - 1LL) - - #define INFTIM -1 - - // File listing canonical interesting mount points. - #define MNTTAB _PATH_MNTTAB - - // File listing currently active mount points. - #define MOUNTED _PATH_MOUNTED - - #define __need_FILE - - // Extra includes - #include <stdint.h> - #include <stdlib.h> - #include <netinet/in.h> - #include <sys/socket.h> - #include <sys/stat.h> - #include <sys/types.h> - #include <dirent.h> - #include <stdio.h> - #include <paths.h> - - // No easy random entropy source - #define PLATFORM_RANDOM_DEVICE_NONE - -#endif // PLATFORM_CYGWIN - - -// Check the processor type -#ifdef PLATFORM_SPARC - #define PLATFORM_ALIGN_INT #endif -#ifdef PLATFORM_ARM - #define PLATFORM_ALIGN_INT +#ifndef HAVE_U_INT16_T + typedef uint16_t u_int16_t; #endif - -// Find out if credentials on UNIX sockets can be obtained -#ifndef PLATFORM_HAVE_getpeereid - #ifndef PLATFORM_HAVE_getsockopt_SO_PEERCRED - #define PLATFORM_CANNOT_FIND_PEER_UID_OF_UNIX_SOCKET - #endif +#ifndef HAVE_U_INT32_T + typedef uint32_t u_int32_t; #endif - -// Compiler issues -#ifdef __GNUC__ - - #ifdef PLATFORM_GCC3 - - // GCC v3 doesn't like pragmas in #defines - #define STRUCTURE_PATCKING_FOR_WIRE_USE_HEADERS - - // But fortunately, the STL allocations are much better behaved. - - #else - - // Force STL to use malloc() for memory allocation - // -- slower, but doesn't gradually use more and more memory - // HOWEVER -- this 'fix' is broken on some platforms. Lots of fun! - #ifndef PLATFORM_STL_USE_MALLOC_BROKEN - #define __USE_MALLOC - #endif - - // set packing to one bytes (can't use push/pop on gcc) - #define BEGIN_STRUCTURE_PACKING_FOR_WIRE #pragma pack(1) - - // Use default packing - #define END_STRUCTURE_PACKING_FOR_WIRE #pragma pack() - - #endif - -#else - compiler not supported! +#ifndef HAVE_U_INT64_T + typedef uint64_t u_int64_t; #endif +#if !HAVE_DECL_INFTIM + #define INFTIM -1 +#endif #endif // BOXPLATFORM__H - diff --git a/lib/common/EndStructPackForWire.h b/lib/common/EndStructPackForWire.h index c9655cd7..82637f33 100644 --- a/lib/common/EndStructPackForWire.h +++ b/lib/common/EndStructPackForWire.h @@ -9,7 +9,7 @@ // No header guard -- this is intentional -#ifdef STRUCTURE_PATCKING_FOR_WIRE_USE_HEADERS +#ifdef STRUCTURE_PACKING_FOR_WIRE_USE_HEADERS #pragma pack() diff --git a/lib/common/EventWatchFilesystemObject.cpp b/lib/common/EventWatchFilesystemObject.cpp index 1611d5bd..c3fe11f8 100644 --- a/lib/common/EventWatchFilesystemObject.cpp +++ b/lib/common/EventWatchFilesystemObject.cpp @@ -27,11 +27,11 @@ // // -------------------------------------------------------------------------- EventWatchFilesystemObject::EventWatchFilesystemObject(const char *Filename) -#ifndef PLATFORM_KQUEUE_NOT_SUPPORTED +#ifdef HAVE_KQUEUE : mDescriptor(::open(Filename, O_RDONLY /*O_EVTONLY*/, 0)) #endif { -#ifndef PLATFORM_KQUEUE_NOT_SUPPORTED +#ifdef HAVE_KQUEUE if(mDescriptor == -1) { THROW_EXCEPTION(CommonException, OSFileOpenError) @@ -77,7 +77,7 @@ EventWatchFilesystemObject::EventWatchFilesystemObject(const EventWatchFilesyste } -#ifndef PLATFORM_KQUEUE_NOT_SUPPORTED +#ifdef HAVE_KQUEUE // -------------------------------------------------------------------------- // // Function diff --git a/lib/common/EventWatchFilesystemObject.h b/lib/common/EventWatchFilesystemObject.h index d8a7245b..f9175a49 100644 --- a/lib/common/EventWatchFilesystemObject.h +++ b/lib/common/EventWatchFilesystemObject.h @@ -10,7 +10,7 @@ #ifndef EVENTWATCHFILESYSTEMOBJECT__H #define EVENTWATCHFILESYSTEMOBJECT__H -#ifndef PLATFORM_KQUEUE_NOT_SUPPORTED +#ifdef HAVE_KQUEUE #include <sys/event.h> #endif @@ -34,7 +34,7 @@ private: EventWatchFilesystemObject &operator=(const EventWatchFilesystemObject &); public: -#ifndef PLATFORM_KQUEUE_NOT_SUPPORTED +#ifdef HAVE_KQUEUE void FillInKEvent(struct kevent &rEvent, int Flags = 0) const; #else void FillInPoll(int &fd, short &events, int Flags = 0) const; diff --git a/lib/common/ExcludeList.cpp b/lib/common/ExcludeList.cpp index 6350869d..556a2079 100755 --- a/lib/common/ExcludeList.cpp +++ b/lib/common/ExcludeList.cpp @@ -9,7 +9,7 @@ #include "Box.h" -#ifndef PLATFORM_REGEX_NOT_SUPPORTED +#ifdef HAVE_REGEX_H #include <regex.h> #define EXCLUDELIST_IMPLEMENTATION_REGEX_T_DEFINED #endif @@ -44,7 +44,7 @@ ExcludeList::ExcludeList() // -------------------------------------------------------------------------- ExcludeList::~ExcludeList() { -#ifndef PLATFORM_REGEX_NOT_SUPPORTED +#ifdef HAVE_REGEX_H // free regex memory while(mRegex.size() > 0) { @@ -106,7 +106,7 @@ void ExcludeList::AddDefiniteEntries(const std::string &rEntries) // -------------------------------------------------------------------------- void ExcludeList::AddRegexEntries(const std::string &rEntries) { -#ifndef PLATFORM_REGEX_NOT_SUPPORTED +#ifdef HAVE_REGEX_H // Split strings up std::vector<std::string> ens; @@ -173,7 +173,7 @@ bool ExcludeList::IsExcluded(const std::string &rTest) const } // Check against regular expressions -#ifndef PLATFORM_REGEX_NOT_SUPPORTED +#ifdef HAVE_REGEX_H for(std::vector<regex_t *>::const_iterator i(mRegex.begin()); i != mRegex.end(); ++i) { // Test against this expression diff --git a/lib/common/ExcludeList.h b/lib/common/ExcludeList.h index a1954044..5324d226 100755 --- a/lib/common/ExcludeList.h +++ b/lib/common/ExcludeList.h @@ -45,7 +45,7 @@ public: // Mainly for tests unsigned int SizeOfDefiniteList() const {return mDefinite.size();} unsigned int SizeOfRegexList() const -#ifndef PLATFORM_REGEX_NOT_SUPPORTED +#ifdef HAVE_REGEX_H {return mRegex.size();} #else {return 0;} @@ -53,7 +53,7 @@ public: private: std::set<std::string> mDefinite; -#ifndef PLATFORM_REGEX_NOT_SUPPORTED +#ifdef HAVE_REGEX_H std::vector<regex_t *> mRegex; #endif diff --git a/lib/common/FileModificationTime.h b/lib/common/FileModificationTime.h index 78f5c115..a84df579 100755 --- a/lib/common/FileModificationTime.h +++ b/lib/common/FileModificationTime.h @@ -16,7 +16,7 @@ inline box_time_t FileModificationTime(struct stat &st) { -#ifdef PLATFORM_stat_SHORT_mtime +#ifndef HAVE_STRUCT_STAT_ST_MTIMESPEC box_time_t datamodified = ((int64_t)st.st_mtime) * (MICRO_SEC_IN_SEC_LL); #else box_time_t datamodified = (((int64_t)st.st_mtimespec.tv_nsec) / NANO_SEC_IN_USEC_LL) @@ -28,7 +28,7 @@ inline box_time_t FileModificationTime(struct stat &st) inline box_time_t FileAttrModificationTime(struct stat &st) { -#ifdef PLATFORM_stat_SHORT_mtime +#ifndef HAVE_STRUCT_STAT_ST_MTIMESPEC box_time_t statusmodified = ((int64_t)st.st_ctime) * (MICRO_SEC_IN_SEC_LL); #else box_time_t statusmodified = (((int64_t)st.st_ctimespec.tv_nsec) / NANO_SEC_IN_USEC_LL) @@ -40,7 +40,7 @@ inline box_time_t FileAttrModificationTime(struct stat &st) inline box_time_t FileModificationTimeMaxModAndAttr(struct stat &st) { -#ifdef PLATFORM_stat_SHORT_mtime +#ifndef HAVE_STRUCT_STAT_ST_MTIMESPEC box_time_t datamodified = ((int64_t)st.st_mtime) * (MICRO_SEC_IN_SEC_LL); box_time_t statusmodified = ((int64_t)st.st_ctime) * (MICRO_SEC_IN_SEC_LL); #else diff --git a/lib/common/LinuxWorkaround.cpp b/lib/common/LinuxWorkaround.cpp deleted file mode 100755 index 7900fa6e..00000000 --- a/lib/common/LinuxWorkaround.cpp +++ /dev/null @@ -1,73 +0,0 @@ -// -------------------------------------------------------------------------- -// -// File -// Name: LinuxWorkaround.cpp -// Purpose: Workarounds for Linux -// Created: 2003/10/31 -// -// -------------------------------------------------------------------------- - -#include "Box.h" - -#include <sys/stat.h> -#include <unistd.h> -#include <dirent.h> - -#include <string> - -#include "LinuxWorkaround.h" -#include "CommonException.h" - -#include "MemLeakFindOn.h" - -#ifdef PLATFORM_LINUX - -// -------------------------------------------------------------------------- -// -// Function -// Name: LinuxWorkaround_FinishDirentStruct(struct dirent *, const char *) -// Purpose: Finishes off filling in a dirent structure, which Linux leaves incomplete. -// Created: 2003/10/31 -// -// -------------------------------------------------------------------------- -void LinuxWorkaround_FinishDirentStruct(struct dirent *entry, const char *DirectoryName) -{ - // From man readdir under Linux: - // - // BUGS - // Field d_type is not implemented as of libc6 2.1 and will always return - // DT_UNKNOWN (0). - // - // What kind of an OS is this? - - - // Build filename of this entry - std::string fn(DirectoryName); - fn += '/'; - fn += entry->d_name; - - // Do a stat on it - struct stat st; - if(::lstat(fn.c_str(), &st) != 0) - { - THROW_EXCEPTION(CommonException, OSFileError) - } - - // Fill in the d_type field. - if(S_ISREG(st.st_mode)) - { - entry->d_type = DT_REG; - } - else if(S_ISDIR(st.st_mode)) - { - entry->d_type = DT_DIR; - } - else if(S_ISLNK(st.st_mode)) - { - entry->d_type = DT_LNK; - } - // otherwise leave it as we found it -} - -#endif // PLATFORM_LINUX - diff --git a/lib/common/LinuxWorkaround.h b/lib/common/LinuxWorkaround.h deleted file mode 100755 index bcd27495..00000000 --- a/lib/common/LinuxWorkaround.h +++ /dev/null @@ -1,20 +0,0 @@ -// -------------------------------------------------------------------------- -// -// File -// Name: LinuxWorkaround.h -// Purpose: Workarounds for Linux -// Created: 2003/10/31 -// -// -------------------------------------------------------------------------- - -#ifndef LINUXWORKAROUND__H -#define LINUXWORKAROUND__H - -#ifdef PLATFORM_LINUX - -void LinuxWorkaround_FinishDirentStruct(struct dirent *entry, const char *DirectoryName); - -#endif // PLATFORM_LINUX - -#endif // LINUXWORKAROUND__H - diff --git a/lib/common/NamedLock.cpp b/lib/common/NamedLock.cpp index 8953db89..b9aeb768 100755 --- a/lib/common/NamedLock.cpp +++ b/lib/common/NamedLock.cpp @@ -12,9 +12,9 @@ #include <fcntl.h> #include <errno.h> #include <unistd.h> -#ifdef PLATFORM_open_USE_flock +#ifdef HAVE_FLOCK #include <sys/file.h> -#endif // PLATFORM_open_USE_flock +#endif #include "NamedLock.h" #include "CommonException.h" @@ -68,14 +68,31 @@ bool NamedLock::TryAndGetLock(const char *Filename, int mode) } // See if the lock can be got -#if defined(PLATFORM_open_USE_flock) || defined(PLATFORM_open_USE_fcntl) +#if HAVE_DECL_O_EXLOCK + int fd = ::open(Filename, O_WRONLY | O_NONBLOCK | O_CREAT | O_TRUNC | O_EXLOCK, mode); + if(fd != -1) + { + // Got a lock, lovely + mFileDescriptor = fd; + return true; + } + + // Failed. Why? + if(errno != EWOULDBLOCK) + { + // Not the expected error + THROW_EXCEPTION(CommonException, OSFileError) + } + + return false; +#else int fd = ::open(Filename, O_WRONLY | O_CREAT | O_TRUNC, mode); if(fd == -1) { THROW_EXCEPTION(CommonException, OSFileError) } -#ifdef PLATFORM_open_USE_flock +#ifdef HAVE_FLOCK if(::flock(fd, LOCK_EX | LOCK_NB) != 0) { ::close(fd); @@ -112,23 +129,6 @@ bool NamedLock::TryAndGetLock(const char *Filename, int mode) mFileDescriptor = fd; return true; -#else - int fd = ::open(Filename, O_WRONLY | O_NONBLOCK | O_CREAT | O_TRUNC | O_EXLOCK, mode); - if(fd != -1) - { - // Got a lock, lovely - mFileDescriptor = fd; - return true; - } - - // Failed. Why? - if(errno != EWOULDBLOCK) - { - // Not the expected error - THROW_EXCEPTION(CommonException, OSFileError) - } - - return false; #endif } diff --git a/lib/common/TemporaryDirectory.h b/lib/common/TemporaryDirectory.h index 62010f79..e683863b 100755 --- a/lib/common/TemporaryDirectory.h +++ b/lib/common/TemporaryDirectory.h @@ -12,11 +12,11 @@ #include <string> -#ifdef PLATFORM_STATIC_TEMP_DIRECTORY_NAME +#ifdef TEMP_DIRECTORY_NAME // Prefix name with Box to avoid clashing with OS API names inline std::string BoxGetTemporaryDirectoryName() { - return std::string(PLATFORM_STATIC_TEMP_DIRECTORY_NAME); + return std::string(TEMP_DIRECTORY_NAME); } #else non-static temporary directory names not supported yet diff --git a/lib/common/WaitForEvent.cpp b/lib/common/WaitForEvent.cpp index e9ee58d2..c552bb12 100644 --- a/lib/common/WaitForEvent.cpp +++ b/lib/common/WaitForEvent.cpp @@ -25,7 +25,7 @@ // Created: 9/3/04 // // -------------------------------------------------------------------------- -#ifndef PLATFORM_KQUEUE_NOT_SUPPORTED +#ifdef HAVE_KQUEUE WaitForEvent::WaitForEvent(int Timeout) : mKQueue(::kqueue()), mpTimeout(0) @@ -56,7 +56,7 @@ WaitForEvent::WaitForEvent(int Timeout) // -------------------------------------------------------------------------- WaitForEvent::~WaitForEvent() { -#ifndef PLATFORM_KQUEUE_NOT_SUPPORTED +#ifdef HAVE_KQUEUE ::close(mKQueue); mKQueue = -1; #else @@ -79,7 +79,7 @@ WaitForEvent::~WaitForEvent() // -------------------------------------------------------------------------- void WaitForEvent::SetTimeout(int Timeout) { -#ifndef PLATFORM_KQUEUE_NOT_SUPPORTED +#ifdef HAVE_KQUEUE // Generate timeout if(Timeout != TimeoutInfinite) { @@ -106,7 +106,7 @@ void WaitForEvent::SetTimeout(int Timeout) // -------------------------------------------------------------------------- void *WaitForEvent::Wait() { -#ifndef PLATFORM_KQUEUE_NOT_SUPPORTED +#ifdef HAVE_KQUEUE // Event return structure struct kevent e; ::memset(&e, 0, sizeof(e)); diff --git a/lib/common/WaitForEvent.h b/lib/common/WaitForEvent.h index b8f79da6..46f152c5 100644 --- a/lib/common/WaitForEvent.h +++ b/lib/common/WaitForEvent.h @@ -10,7 +10,7 @@ #ifndef WAITFOREVENT__H #define WAITFOREVENT__H -#ifndef PLATFORM_KQUEUE_NOT_SUPPORTED +#ifdef HAVE_KQUEUE #include <sys/event.h> #include <sys/time.h> #else @@ -42,7 +42,7 @@ public: void *Wait(); -#ifdef PLATFORM_KQUEUE_NOT_SUPPORTED +#ifndef HAVE_KQUEUE typedef struct { int fd; @@ -63,7 +63,7 @@ public: void Add(const T *pItem, int Flags = 0) { ASSERT(pItem != 0); -#ifndef PLATFORM_KQUEUE_NOT_SUPPORTED +#ifdef HAVE_KQUEUE struct kevent e; pItem->FillInKEvent(e, Flags); // Fill in extra flags to say what to do @@ -100,7 +100,7 @@ public: void Remove(const T *pItem, int Flags = 0) { ASSERT(pItem != 0); -#ifndef PLATFORM_KQUEUE_NOT_SUPPORTED +#ifdef HAVE_KQUEUE struct kevent e; pItem->FillInKEvent(e, Flags); // Fill in extra flags to say what to do @@ -128,7 +128,7 @@ public: } private: -#ifndef PLATFORM_KQUEUE_NOT_SUPPORTED +#ifdef HAVE_KQUEUE int mKQueue; struct timespec mTimeout; struct timespec *mpTimeout; diff --git a/lib/crypto/CipherAES.cpp b/lib/crypto/CipherAES.cpp index b4de6048..fad8b968 100644 --- a/lib/crypto/CipherAES.cpp +++ b/lib/crypto/CipherAES.cpp @@ -10,7 +10,7 @@ #include "Box.h" // Only available in new versions of openssl -#ifndef PLATFORM_OLD_OPENSSL +#ifndef HAVE_OLD_SSL #include <openssl/evp.h> @@ -159,5 +159,5 @@ void CipherAES::SetupParameters(EVP_CIPHER_CTX *pCipherContext) const -#endif // n PLATFORM_OLD_OPENSSL +#endif // n HAVE_OLD_SSL diff --git a/lib/crypto/CipherAES.h b/lib/crypto/CipherAES.h index 51fb146a..50b96dc3 100644 --- a/lib/crypto/CipherAES.h +++ b/lib/crypto/CipherAES.h @@ -11,7 +11,7 @@ #define CIPHERAES__H // Only available in new versions of openssl -#ifndef PLATFORM_OLD_OPENSSL +#ifndef HAVE_OLD_SSL #include "CipherDescription.h" @@ -44,7 +44,7 @@ private: const void *mpInitialisationVector; }; -#endif // n PLATFORM_OLD_OPENSSL +#endif // n HAVE_OLD_SSL #endif // CIPHERAES__H diff --git a/lib/crypto/CipherBlowfish.cpp b/lib/crypto/CipherBlowfish.cpp index e27e3b0a..e16cc6ed 100755 --- a/lib/crypto/CipherBlowfish.cpp +++ b/lib/crypto/CipherBlowfish.cpp @@ -11,7 +11,7 @@ #include <openssl/evp.h> -#ifdef PLATFORM_OLD_OPENSSL +#ifdef HAVE_OLD_SSL #include <string.h> #include <strings.h> #endif @@ -34,7 +34,7 @@ CipherBlowfish::CipherBlowfish(CipherDescription::CipherMode Mode, const void *pKey, unsigned int KeyLength, const void *pInitialisationVector) : CipherDescription(), mMode(Mode) -#ifndef PLATFORM_OLD_OPENSSL +#ifndef HAVE_OLD_SSL , mpKey(pKey), mKeyLength(KeyLength), mpInitialisationVector(pInitialisationVector) @@ -66,7 +66,7 @@ CipherBlowfish::CipherBlowfish(CipherDescription::CipherMode Mode, const void *p CipherBlowfish::CipherBlowfish(const CipherBlowfish &rToCopy) : CipherDescription(rToCopy), mMode(rToCopy.mMode), -#ifndef PLATFORM_OLD_OPENSSL +#ifndef HAVE_OLD_SSL mpKey(rToCopy.mpKey), mKeyLength(rToCopy.mKeyLength), mpInitialisationVector(rToCopy.mpInitialisationVector) @@ -80,7 +80,7 @@ CipherBlowfish::CipherBlowfish(const CipherBlowfish &rToCopy) #endif -#ifdef PLATFORM_OLD_OPENSSL +#ifdef HAVE_OLD_SSL // Hack functions to support old OpenSSL API CipherDescription *CipherBlowfish::Clone() const { @@ -110,7 +110,7 @@ void CipherBlowfish::SetIV(const void *pIV) // -------------------------------------------------------------------------- CipherBlowfish::~CipherBlowfish() { -#ifdef PLATFORM_OLD_OPENSSL +#ifdef HAVE_OLD_SSL // Zero copy of key for(unsigned int l = 0; l < mKey.size(); ++l) { @@ -134,7 +134,7 @@ CipherBlowfish &CipherBlowfish::operator=(const CipherBlowfish &rToCopy) CipherDescription::operator=(rToCopy); mMode = rToCopy.mMode; -#ifndef PLATFORM_OLD_OPENSSL +#ifndef HAVE_OLD_SSL mpKey = rToCopy.mpKey; mKeyLength = rToCopy.mKeyLength; mpInitialisationVector = rToCopy.mpInitialisationVector; @@ -196,7 +196,7 @@ void CipherBlowfish::SetupParameters(EVP_CIPHER_CTX *pCipherContext) const ASSERT(pCipherContext != 0); // Set key length -#ifndef PLATFORM_OLD_OPENSSL +#ifndef HAVE_OLD_SSL if(EVP_CIPHER_CTX_set_key_length(pCipherContext, mKeyLength) != 1) #else if(EVP_CIPHER_CTX_set_key_length(pCipherContext, mKey.size()) != 1) @@ -205,7 +205,7 @@ void CipherBlowfish::SetupParameters(EVP_CIPHER_CTX *pCipherContext) const THROW_EXCEPTION(CipherException, EVPBadKeyLength) } // Set key -#ifndef PLATFORM_OLD_OPENSSL +#ifndef HAVE_OLD_SSL if(EVP_CipherInit_ex(pCipherContext, NULL, NULL, (unsigned char*)mpKey, (unsigned char*)mpInitialisationVector, -1) != 1) #else if(EVP_CipherInit(pCipherContext, NULL, (unsigned char*)mKey.c_str(), (unsigned char*)mInitialisationVector, -1) != 1) diff --git a/lib/crypto/CipherBlowfish.h b/lib/crypto/CipherBlowfish.h index 92db1d85..b3bcf028 100755 --- a/lib/crypto/CipherBlowfish.h +++ b/lib/crypto/CipherBlowfish.h @@ -10,7 +10,7 @@ #ifndef CIPHERBLOWFISH__H #define CIPHERBLOWFISH__H -#ifdef PLATFORM_OLD_OPENSSL +#ifdef HAVE_OLD_SSL #include <string> #endif @@ -38,14 +38,14 @@ public: // Setup any other parameters virtual void SetupParameters(EVP_CIPHER_CTX *pCipherContext) const; -#ifdef PLATFORM_OLD_OPENSSL +#ifdef HAVE_OLD_SSL CipherDescription *Clone() const; void SetIV(const void *pIV); #endif private: CipherDescription::CipherMode mMode; -#ifndef PLATFORM_OLD_OPENSSL +#ifndef HAVE_OLD_SSL const void *mpKey; unsigned int mKeyLength; const void *mpInitialisationVector; diff --git a/lib/crypto/CipherContext.cpp b/lib/crypto/CipherContext.cpp index 42707497..8c3b25b2 100755 --- a/lib/crypto/CipherContext.cpp +++ b/lib/crypto/CipherContext.cpp @@ -29,7 +29,7 @@ CipherContext::CipherContext() : mInitialised(false), mWithinTransform(false), mPaddingOn(true) -#ifdef PLATFORM_OLD_OPENSSL +#ifdef HAVE_OLD_SSL , mFunction(Decrypt), mpDescription(0) #endif @@ -52,7 +52,7 @@ CipherContext::~CipherContext() EVP_CIPHER_CTX_cleanup(&ctx); mInitialised = false; } -#ifdef PLATFORM_OLD_OPENSSL +#ifdef HAVE_OLD_SSL if(mpDescription != 0) { delete mpDescription; @@ -83,7 +83,7 @@ void CipherContext::Init(CipherContext::CipherFunction Function, const CipherDes } // Initialise the cipher -#ifndef PLATFORM_OLD_OPENSSL +#ifndef HAVE_OLD_SSL EVP_CIPHER_CTX_init(&ctx); // no error return code, even though the docs says it does if(EVP_CipherInit_ex(&ctx, rDescription.GetCipher(), NULL, NULL, NULL, Function) != 1) @@ -100,7 +100,7 @@ void CipherContext::Init(CipherContext::CipherFunction Function, const CipherDes try { -#ifndef PLATFORM_OLD_OPENSSL +#ifndef HAVE_OLD_SSL // Let the description set up everything else rDescription.SetupParameters(&ctx); #else @@ -137,7 +137,7 @@ void CipherContext::Reset() EVP_CIPHER_CTX_cleanup(&ctx); mInitialised = false; } -#ifdef PLATFORM_OLD_OPENSSL +#ifdef HAVE_OLD_SSL if(mpDescription != 0) { delete mpDescription; @@ -270,7 +270,7 @@ int CipherContext::Final(void *pOutBuffer, int OutLength) // Do the transform int outLength = OutLength; -#ifndef PLATFORM_OLD_OPENSSL +#ifndef HAVE_OLD_SSL if(EVP_CipherFinal_ex(&ctx, (unsigned char*)pOutBuffer, &outLength) != 1) { THROW_EXCEPTION(CipherException, EVPFinalFailure) @@ -285,7 +285,7 @@ int CipherContext::Final(void *pOutBuffer, int OutLength) } -#ifdef PLATFORM_OLD_OPENSSL +#ifdef HAVE_OLD_SSL // -------------------------------------------------------------------------- // // Function @@ -458,7 +458,7 @@ int CipherContext::TransformBlock(void *pOutBuffer, int OutLength, const void *p } // Finalise int outLength2 = OutLength - outLength; -#ifndef PLATFORM_OLD_OPENSSL +#ifndef HAVE_OLD_SSL if(EVP_CipherFinal_ex(&ctx, ((unsigned char*)pOutBuffer) + outLength, &outLength2) != 1) { THROW_EXCEPTION(CipherException, EVPFinalFailure) @@ -472,7 +472,7 @@ int CipherContext::TransformBlock(void *pOutBuffer, int OutLength, const void *p { // Finalise the context, so definately ready for the next caller int outs = OutLength; -#ifndef PLATFORM_OLD_OPENSSL +#ifndef HAVE_OLD_SSL EVP_CipherFinal_ex(&ctx, (unsigned char*)pOutBuffer, &outs); #else OldOpenSSLFinal((unsigned char*)pOutBuffer, outs); @@ -530,7 +530,7 @@ void CipherContext::SetIV(const void *pIV) THROW_EXCEPTION(CipherException, EVPInitFailure) } -#ifdef PLATFORM_OLD_OPENSSL +#ifdef HAVE_OLD_SSL // Update description if(mpDescription != 0) { @@ -578,7 +578,7 @@ const void *CipherContext::SetRandomIV(int &rLengthOut) THROW_EXCEPTION(CipherException, EVPInitFailure) } -#ifdef PLATFORM_OLD_OPENSSL +#ifdef HAVE_OLD_SSL // Update description if(mpDescription != 0) { @@ -602,7 +602,7 @@ const void *CipherContext::SetRandomIV(int &rLengthOut) // -------------------------------------------------------------------------- void CipherContext::UsePadding(bool Padding) { -#ifndef PLATFORM_OLD_OPENSSL +#ifndef HAVE_OLD_SSL if(EVP_CIPHER_CTX_set_padding(&ctx, Padding) != 1) { THROW_EXCEPTION(CipherException, EVPSetPaddingFailure) diff --git a/lib/crypto/CipherContext.h b/lib/crypto/CipherContext.h index f9dcd022..64ce52d8 100755 --- a/lib/crypto/CipherContext.h +++ b/lib/crypto/CipherContext.h @@ -62,7 +62,7 @@ public: void UsePadding(bool Padding = true); -#ifdef PLATFORM_OLD_OPENSSL +#ifdef HAVE_OLD_SSL void OldOpenSSLFinal(unsigned char *Buffer, int &rOutLengthOut); #endif @@ -72,7 +72,7 @@ private: bool mWithinTransform; bool mPaddingOn; uint8_t mGeneratedIV[CIPHERCONTEXT_MAX_GENERATED_IV_LENGTH]; -#ifdef PLATFORM_OLD_OPENSSL +#ifdef HAVE_OLD_SSL CipherFunction mFunction; CipherDescription *mpDescription; #endif diff --git a/lib/crypto/CipherDescription.h b/lib/crypto/CipherDescription.h index 2977f7da..f825eefa 100755 --- a/lib/crypto/CipherDescription.h +++ b/lib/crypto/CipherDescription.h @@ -47,7 +47,7 @@ public: Mode_OFB = 3 } CipherMode; -#ifdef PLATFORM_OLD_OPENSSL +#ifdef HAVE_OLD_SSL // For the old version of OpenSSL, we need to be able to store cipher descriptions. virtual CipherDescription *Clone() const = 0; // And to be able to store new IVs diff --git a/lib/crypto/Random.cpp b/lib/crypto/Random.cpp index 3df5fc5e..c64e7d50 100755 --- a/lib/crypto/Random.cpp +++ b/lib/crypto/Random.cpp @@ -28,8 +28,8 @@ // -------------------------------------------------------------------------- void Random::Initialise() { -#ifndef PLATFORM_RANDOM_DEVICE_NONE - if(::RAND_load_file(PLATFORM_RANDOM_DEVICE, 1024) != 1024) +#ifdef HAVE_RANDOM_DEVICE + if(::RAND_load_file(RANDOM_DEVICE, 1024) != 1024) { THROW_EXCEPTION(CipherException, RandomInitFailed) } diff --git a/lib/raidfile/RaidFileRead.cpp b/lib/raidfile/RaidFileRead.cpp index 6314ba90..d60936fc 100755 --- a/lib/raidfile/RaidFileRead.cpp +++ b/lib/raidfile/RaidFileRead.cpp @@ -29,10 +29,6 @@ #include "RaidFileController.h" #include "RaidFileUtil.h" -#ifdef PLATFORM_LINUX - #include "LinuxWorkaround.h" -#endif - #include "MemLeakFindOn.h" #define READ_NUMBER_DISCS_REQUIRED 3 @@ -715,7 +711,7 @@ int RaidFileRead_Raid::ReadRecovered(void *pBuffer, int NBytes) if(mLastBlockHasSize) { int sizeXorOffset = (mBlockSize - sizeof(FileSizeType)) + ((mStripe1Handle != -1)?mBlockSize:0); - *((FileSizeType*)(mRecoveryBuffer + sizeXorOffset)) ^= ntoh64(mFileSize); + *((FileSizeType*)(mRecoveryBuffer + sizeXorOffset)) ^= box_ntoh64(mFileSize); } } else @@ -1233,7 +1229,7 @@ std::auto_ptr<RaidFileRead> RaidFileRead::Open(int SetNumber, const std::string if(parityIntegralPlusOffT) { // Wonderful! Have the value - length = ntoh64(parityLastData); + length = box_ntoh64(parityLastData); } else { @@ -1298,7 +1294,7 @@ std::auto_ptr<RaidFileRead> RaidFileRead::Open(int SetNumber, const std::string // Lovely! length = stripe1LastData ^ parityLastData; // Convert to host byte order - length = ntoh64(length); + length = box_ntoh64(length); ASSERT(length <= (paritySize + stripe1Size)); // Mark is as having this to aid code later lastBlockHasSize = true; @@ -1531,10 +1527,6 @@ bool RaidFileRead::ReadDirectoryContents(int SetNumber, const std::string &rDirN struct dirent *en = 0; while((en = ::readdir(dirHandle)) != 0) { -#ifdef PLATFORM_LINUX - LinuxWorkaround_FinishDirentStruct(en, dn.c_str()); -#endif - if(en->d_name[0] == '.' && (en->d_name[1] == '\0' || (en->d_name[1] == '.' && en->d_name[2] == '\0'))) { @@ -1547,7 +1539,9 @@ bool RaidFileRead::ReadDirectoryContents(int SetNumber, const std::string &rDirN unsigned int countToAdd = 1; // stat the file to find out what type it is -#ifdef PLATFORM_SUNOS +#ifdef HAVE_VALID_DIRENT_D_TYPE + if(DirReadType == DirReadType_FilesOnly && en->d_type == DT_REG) +#else struct stat st; std::string fullName(dn + DIRECTORY_SEPARATOR + en->d_name); if(::lstat(fullName.c_str(), &st) != 0) @@ -1555,8 +1549,6 @@ bool RaidFileRead::ReadDirectoryContents(int SetNumber, const std::string &rDirN THROW_EXCEPTION(RaidFileException, OSError) } if(DirReadType == DirReadType_FilesOnly && (st.st_mode & S_IFDIR) == 0) -#else - if(DirReadType == DirReadType_FilesOnly && en->d_type == DT_REG) #endif { // File. Complex, need to check the extension @@ -1585,10 +1577,10 @@ bool RaidFileRead::ReadDirectoryContents(int SetNumber, const std::string &rDirN } } } -#ifdef PLATFORM_SUNOS - if(DirReadType == DirReadType_DirsOnly && (st.st_mode & S_IFDIR)) -#else +#ifdef HAVE_VALID_DIRENT_D_TYPE if(DirReadType == DirReadType_DirsOnly && en->d_type == DT_DIR) +#else + if(DirReadType == DirReadType_DirsOnly && (st.st_mode & S_IFDIR)) #endif { // Directory, and we want directories diff --git a/lib/raidfile/RaidFileUtil.cpp b/lib/raidfile/RaidFileUtil.cpp index c71bb2df..da23cef5 100755 --- a/lib/raidfile/RaidFileUtil.cpp +++ b/lib/raidfile/RaidFileUtil.cpp @@ -54,7 +54,7 @@ RaidFileUtil::ExistType RaidFileUtil::RaidFileExists(RaidFileDiscSet &rDiscSet, if(pRevisionID != 0) { (*pRevisionID) = FileModificationTime(st); -#ifdef PLATFORM_stat_SHORT_mtime +#ifndef HAVE_STRUCT_STAT_ST_MTIMESPEC // On linux, the time resolution is very low for modification times. // So add the size to it to give a bit more chance of it changing. // TODO: Make this better. @@ -71,7 +71,7 @@ RaidFileUtil::ExistType RaidFileUtil::RaidFileExists(RaidFileDiscSet &rDiscSet, int64_t revisionID = 0; int setSize = rDiscSet.size(); int rfCount = 0; -#ifdef PLATFORM_stat_SHORT_mtime +#ifndef HAVE_STRUCT_STAT_ST_MTIMESPEC // TODO: replace this with better linux revision ID detection int64_t revisionIDplus = 0; #endif @@ -92,7 +92,7 @@ RaidFileUtil::ExistType RaidFileUtil::RaidFileExists(RaidFileDiscSet &rDiscSet, { int64_t rid = FileModificationTime(st); if(rid > revisionID) revisionID = rid; -#ifdef PLATFORM_stat_SHORT_mtime +#ifndef HAVE_STRUCT_STAT_ST_MTIMESPEC revisionIDplus += st.st_size; #endif } @@ -101,7 +101,7 @@ RaidFileUtil::ExistType RaidFileUtil::RaidFileExists(RaidFileDiscSet &rDiscSet, if(pRevisionID != 0) { (*pRevisionID) = revisionID; -#ifdef PLATFORM_stat_SHORT_mtime +#ifndef HAVE_STRUCT_STAT_ST_MTIMESPEC (*pRevisionID) += revisionIDplus; #endif } diff --git a/lib/raidfile/RaidFileWrite.cpp b/lib/raidfile/RaidFileWrite.cpp index 987aa22c..8341943d 100755 --- a/lib/raidfile/RaidFileWrite.cpp +++ b/lib/raidfile/RaidFileWrite.cpp @@ -112,7 +112,10 @@ void RaidFileWrite::Open(bool AllowOverwrite) } // Get a lock on the write file -#ifdef PLATFORM_open_USE_fcntl +#ifdef HAVE_FLOCK + int errnoBlock = EWOULDBLOCK; + if(::flock(mOSFileHandle, LOCK_EX | LOCK_NB) != 0) +#else int errnoBlock = EAGAIN; struct flock desc; desc.l_type = F_WRLCK; @@ -120,9 +123,6 @@ void RaidFileWrite::Open(bool AllowOverwrite) desc.l_start = 0; desc.l_len = 0; if(::fcntl(mOSFileHandle, F_SETLK, &desc) != 0) -#else - int errnoBlock = EWOULDBLOCK; - if(::flock(mOSFileHandle, LOCK_EX | LOCK_NB) != 0) #endif { // Lock was not obtained. @@ -387,14 +387,14 @@ void RaidFileWrite::TransformToRaidStorage() // Then open them all for writing (in strict order) try { -#if defined(PLATFORM_open_USE_flock) || defined(PLATFORM_open_USE_fcntl) - FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL)> stripe1(stripe1FilenameW.c_str()); - FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL)> stripe2(stripe2FilenameW.c_str()); - FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL)> parity(parityFilenameW.c_str()); -#else +#if HAVE_DECL_O_EXLOCK FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK)> stripe1(stripe1FilenameW.c_str()); FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK)> stripe2(stripe2FilenameW.c_str()); FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK)> parity(parityFilenameW.c_str()); +#else + FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL)> stripe1(stripe1FilenameW.c_str()); + FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL)> stripe2(stripe2FilenameW.c_str()); + FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL)> parity(parityFilenameW.c_str()); #endif // Then... read in data... @@ -461,7 +461,7 @@ void RaidFileWrite::TransformToRaidStorage() ASSERT(sizeof(RaidFileRead::FileSizeType) == (2*sizeof(unsigned int))); ASSERT(sizeof(RaidFileRead::FileSizeType) >= sizeof(off_t)); int sizePos = (blockSize/sizeof(unsigned int)) - 2; - RaidFileRead::FileSizeType sw = hton64(writeFileStat.st_size); + RaidFileRead::FileSizeType sw = box_hton64(writeFileStat.st_size); unsigned int *psize = (unsigned int *)(&sw); pparity[sizePos+0] = pstripe1[sizePos+0] ^ psize[0]; pparity[sizePos+1] = pstripe1[sizePos+1] ^ psize[1]; @@ -517,7 +517,7 @@ void RaidFileWrite::TransformToRaidStorage() if(sizeRecordRequired) { ASSERT(sizeof(writeFileStat.st_size) <= sizeof(RaidFileRead::FileSizeType)); - RaidFileRead::FileSizeType sw = hton64(writeFileStat.st_size); + RaidFileRead::FileSizeType sw = box_hton64(writeFileStat.st_size); ASSERT((::lseek(parity, 0, SEEK_CUR) % blockSize) == 0); if(::write(parity, &sw, sizeof(sw)) != sizeof(sw)) { diff --git a/lib/server/Daemon.cpp b/lib/server/Daemon.cpp index bb4ecd7c..ca2df62f 100755 --- a/lib/server/Daemon.cpp +++ b/lib/server/Daemon.cpp @@ -520,7 +520,7 @@ void Daemon::SetProcessTitle(const char *format, ...) // -- make sure other platforms include the image name somewhere so ps listings give // useful information. -#ifdef PLATFORM_HAVE_setproctitle +#ifdef HAVE_SETPROCTITLE // optional arguments va_list args; va_start(args, format); @@ -532,7 +532,7 @@ void Daemon::SetProcessTitle(const char *format, ...) // Set process title ::setproctitle("%s", title); -#endif // PLATFORM_HAVE_setproctitle +#endif // HAVE_SETPROCTITLE } diff --git a/lib/server/Protocol.cpp b/lib/server/Protocol.cpp index 690c2ec0..988d44c8 100755 --- a/lib/server/Protocol.cpp +++ b/lib/server/Protocol.cpp @@ -423,13 +423,13 @@ void Protocol::Read(int64_t &rOut) READ_START_CHECK READ_CHECK_BYTES_AVAILABLE(sizeof(int64_t)) -#ifdef PLATFORM_ALIGN_INT +#ifdef HAVE_ALIGNED_ONLY_INT64 int64_t nvalue; memcpy(&nvalue, mpBuffer + mReadOffset, sizeof(int64_t)); #else int64_t nvalue = *((int64_t*)(mpBuffer + mReadOffset)); #endif - rOut = ntoh64(nvalue); + rOut = box_ntoh64(nvalue); mReadOffset += sizeof(int64_t); } @@ -447,7 +447,7 @@ void Protocol::Read(int32_t &rOut) READ_START_CHECK READ_CHECK_BYTES_AVAILABLE(sizeof(int32_t)) -#ifdef PLATFORM_ALIGN_INT +#ifdef HAVE_ALIGNED_ONLY_INT32 int32_t nvalue; memcpy(&nvalue, mpBuffer + mReadOffset, sizeof(int32_t)); #else @@ -558,8 +558,8 @@ void Protocol::Write(int64_t Value) WRITE_START_CHECK WRITE_ENSURE_BYTES_AVAILABLE(sizeof(int64_t)) - int64_t nvalue = hton64(Value); -#ifdef PLATFORM_ALIGN_INT + int64_t nvalue = box_hton64(Value); +#ifdef HAVE_ALIGNED_ONLY_INT64 memcpy(mpBuffer + mWriteOffset, &nvalue, sizeof(int64_t)); #else *((int64_t*)(mpBuffer + mWriteOffset)) = nvalue; @@ -582,7 +582,7 @@ void Protocol::Write(int32_t Value) WRITE_ENSURE_BYTES_AVAILABLE(sizeof(int32_t)) int32_t nvalue = htonl(Value); -#ifdef PLATFORM_ALIGN_INT +#ifdef HAVE_ALIGNED_ONLY_INT32 memcpy(mpBuffer + mWriteOffset, &nvalue, sizeof(int32_t)); #else *((int32_t*)(mpBuffer + mWriteOffset)) = nvalue; diff --git a/lib/server/ProtocolWire.h b/lib/server/ProtocolWire.h index b6d3bd37..ff62b66e 100755 --- a/lib/server/ProtocolWire.h +++ b/lib/server/ProtocolWire.h @@ -13,7 +13,7 @@ #include <sys/types.h> // set packing to one byte -#ifdef STRUCTURE_PATCKING_FOR_WIRE_USE_HEADERS +#ifdef STRUCTURE_PACKING_FOR_WIRE_USE_HEADERS #include "BeginStructPackForWire.h" #else BEGIN_STRUCTURE_PACKING_FOR_WIRE @@ -33,7 +33,7 @@ typedef struct #define SPECIAL_STREAM_OBJECT_TYPE 0xffffffff // Use default packing -#ifdef STRUCTURE_PATCKING_FOR_WIRE_USE_HEADERS +#ifdef STRUCTURE_PACKING_FOR_WIRE_USE_HEADERS #include "EndStructPackForWire.h" #else END_STRUCTURE_PACKING_FOR_WIRE diff --git a/lib/server/SSLLib.cpp b/lib/server/SSLLib.cpp index e9f3a59d..9e98550a 100755 --- a/lib/server/SSLLib.cpp +++ b/lib/server/SSLLib.cpp @@ -45,8 +45,8 @@ void SSLLib::Initialise() ::SSL_load_error_strings(); // Extra seeding over and above what's already done by the library -#ifndef PLATFORM_RANDOM_DEVICE_NONE - if(::RAND_load_file(PLATFORM_RANDOM_DEVICE, 1024) != 1024) +#ifdef HAVE_RANDOM_DEVICE + if(::RAND_load_file(RANDOM_DEVICE, 1024) != 1024) { THROW_EXCEPTION(ServerException, SSLRandomInitFailed) } diff --git a/lib/server/Socket.cpp b/lib/server/Socket.cpp index 52eb79e3..b2d32345 100755 --- a/lib/server/Socket.cpp +++ b/lib/server/Socket.cpp @@ -49,7 +49,7 @@ void Socket::NameLookupToSockAddr(SocketAllAddr &addr, int &sockDomain, int Type if(phost->h_addr_list[0] != 0) { sockAddrLen = sizeof(addr.sa_inet); -#ifndef PLATFORM_sockaddr_NO_len +#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN addr.sa_inet.sin_len = sizeof(addr.sa_inet); #endif addr.sa_inet.sin_family = PF_INET; @@ -82,7 +82,7 @@ void Socket::NameLookupToSockAddr(SocketAllAddr &addr, int &sockDomain, int Type THROW_EXCEPTION(ServerException, SocketNameUNIXPathTooLong); } sockAddrLen = nameLen + (((char*)(&(addr.sa_unix.sun_path[0]))) - ((char*)(&addr.sa_unix))); -#ifndef PLATFORM_sockaddr_NO_len +#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN addr.sa_unix.sun_len = sockAddrLen; #endif addr.sa_unix.sun_family = PF_UNIX; diff --git a/lib/server/SocketListen.h b/lib/server/SocketListen.h index f1f5e377..7042011c 100755 --- a/lib/server/SocketListen.h +++ b/lib/server/SocketListen.h @@ -16,7 +16,7 @@ #include <poll.h> #include <memory> #include <string> -#ifndef PLATFORM_KQUEUE_NOT_SUPPORTED +#ifdef HAVE_KQUEUE #include <sys/event.h> #include <sys/time.h> #endif @@ -226,7 +226,7 @@ public: // Functions to allow adding to WaitForEvent class, for efficient waiting // on multiple sockets. -#ifndef PLATFORM_KQUEUE_NOT_SUPPORTED +#ifdef HAVE_KQUEUE // -------------------------------------------------------------------------- // // Function diff --git a/lib/server/SocketStream.cpp b/lib/server/SocketStream.cpp index 3c8bf453..53865ee3 100755 --- a/lib/server/SocketStream.cpp +++ b/lib/server/SocketStream.cpp @@ -372,7 +372,7 @@ int SocketStream::GetSocketHandle() // -------------------------------------------------------------------------- bool SocketStream::GetPeerCredentials(uid_t &rUidOut, gid_t &rGidOut) { -#ifdef PLATFORM_HAVE_getpeereid +#ifdef HAVE_GETPEEREID uid_t remoteEUID = 0xffff; gid_t remoteEGID = 0xffff; @@ -382,9 +382,9 @@ bool SocketStream::GetPeerCredentials(uid_t &rUidOut, gid_t &rGidOut) rGidOut = remoteEGID; return true; } -#endif // PLATFORM_HAVE_getpeereid +#endif -#ifdef PLATFORM_HAVE_getsockopt_SO_PEERCRED +#if HAVE_DECL_SO_PEERCRED struct ucred cred; socklen_t credLen = sizeof(cred); @@ -394,7 +394,7 @@ bool SocketStream::GetPeerCredentials(uid_t &rUidOut, gid_t &rGidOut) rGidOut = cred.gid; return true; } -#endif // PLATFORM_HAVE_getsockopt_SO_PEERCRED +#endif // Not available return false; |