diff --git a/src/AbstractDiskWriter.cc b/src/AbstractDiskWriter.cc index b50a9b8e..e209018a 100644 --- a/src/AbstractDiskWriter.cc +++ b/src/AbstractDiskWriter.cc @@ -62,7 +62,7 @@ AbstractDiskWriter::~AbstractDiskWriter() closeFile(); } -void AbstractDiskWriter::openFile(uint64_t totalLength) +void AbstractDiskWriter::openFile(off_t totalLength) { try { openExistingFile(totalLength); @@ -83,7 +83,7 @@ void AbstractDiskWriter::closeFile() } } -void AbstractDiskWriter::openExistingFile(uint64_t totalLength) +void AbstractDiskWriter::openExistingFile(off_t totalLength) { int flags = O_BINARY; if(readOnly_) { @@ -197,7 +197,7 @@ ssize_t AbstractDiskWriter::readData(unsigned char* data, size_t len, off_t offs return ret; } -void AbstractDiskWriter::truncate(uint64_t length) +void AbstractDiskWriter::truncate(off_t length) { if(fd_ == -1) { throw DL_ABORT_EX("File not opened."); @@ -223,7 +223,7 @@ void AbstractDiskWriter::truncate(uint64_t length) #endif } -void AbstractDiskWriter::allocate(off_t offset, uint64_t length) +void AbstractDiskWriter::allocate(off_t offset, off_t length) { #ifdef HAVE_SOME_FALLOCATE if(fd_ == -1) { @@ -272,7 +272,7 @@ void AbstractDiskWriter::allocate(off_t offset, uint64_t length) #endif // HAVE_SOME_FALLOCATE } -uint64_t AbstractDiskWriter::size() +off_t AbstractDiskWriter::size() { return File(filename_).size(); } diff --git a/src/AbstractDiskWriter.h b/src/AbstractDiskWriter.h index 297c3b26..9176dfef 100644 --- a/src/AbstractDiskWriter.h +++ b/src/AbstractDiskWriter.h @@ -57,22 +57,22 @@ public: AbstractDiskWriter(const std::string& filename); virtual ~AbstractDiskWriter(); - virtual void openFile(uint64_t totalLength = 0); + virtual void openFile(off_t totalLength = 0); virtual void closeFile(); - virtual void openExistingFile(uint64_t totalLength = 0); + virtual void openExistingFile(off_t totalLength = 0); virtual void writeData(const unsigned char* data, size_t len, off_t offset); virtual ssize_t readData(unsigned char* data, size_t len, off_t offset); - virtual void truncate(uint64_t length); + virtual void truncate(off_t length); // File must be opened before calling this function. - virtual void allocate(off_t offset, uint64_t length); + virtual void allocate(off_t offset, off_t length); - virtual uint64_t size(); + virtual off_t size(); virtual void enableReadOnly(); diff --git a/src/AbstractSingleDiskAdaptor.cc b/src/AbstractSingleDiskAdaptor.cc index ddf59059..95ef1606 100644 --- a/src/AbstractSingleDiskAdaptor.cc +++ b/src/AbstractSingleDiskAdaptor.cc @@ -85,12 +85,12 @@ bool AbstractSingleDiskAdaptor::fileExists() return File(getFilePath()).exists(); } -uint64_t AbstractSingleDiskAdaptor::size() +off_t AbstractSingleDiskAdaptor::size() { return File(getFilePath()).size(); } -void AbstractSingleDiskAdaptor::truncate(uint64_t length) +void AbstractSingleDiskAdaptor::truncate(off_t length) { diskWriter_->truncate(length); } @@ -139,7 +139,7 @@ void AbstractSingleDiskAdaptor::setDiskWriter diskWriter_ = diskWriter; } -void AbstractSingleDiskAdaptor::setTotalLength(const uint64_t& totalLength) +void AbstractSingleDiskAdaptor::setTotalLength(const off_t& totalLength) { totalLength_ = totalLength; } diff --git a/src/AbstractSingleDiskAdaptor.h b/src/AbstractSingleDiskAdaptor.h index 47563d95..a5f78aa1 100644 --- a/src/AbstractSingleDiskAdaptor.h +++ b/src/AbstractSingleDiskAdaptor.h @@ -45,7 +45,7 @@ class FileAllocationIterator; class AbstractSingleDiskAdaptor : public DiskAdaptor { private: SharedHandle diskWriter_; - uint64_t totalLength_; + off_t totalLength_; bool readOnly_; public: AbstractSingleDiskAdaptor(); @@ -67,9 +67,9 @@ public: virtual bool fileExists(); - virtual uint64_t size(); + virtual off_t size(); - virtual void truncate(uint64_t length); + virtual void truncate(off_t length); virtual SharedHandle fileAllocationIterator(); @@ -92,9 +92,9 @@ public: return diskWriter_; } - void setTotalLength(const uint64_t& totalLength); + void setTotalLength(const off_t& totalLength); - uint64_t getTotalLength() const + off_t getTotalLength() const { return totalLength_; } diff --git a/src/AdaptiveFileAllocationIterator.cc b/src/AdaptiveFileAllocationIterator.cc index 8eeb5f99..a96c9f4a 100644 --- a/src/AdaptiveFileAllocationIterator.cc +++ b/src/AdaptiveFileAllocationIterator.cc @@ -45,7 +45,7 @@ namespace aria2 { AdaptiveFileAllocationIterator::AdaptiveFileAllocationIterator -(BinaryStream* stream, off_t offset, uint64_t totalLength) +(BinaryStream* stream, off_t offset, off_t totalLength) : stream_(stream), offset_(offset), totalLength_(totalLength) @@ -59,8 +59,8 @@ void AdaptiveFileAllocationIterator::allocateChunk() #ifdef HAVE_FALLOCATE try { A2_LOG_DEBUG("Testing file system supports fallocate."); - if(static_cast(offset_) < totalLength_) { - off_t len = std::min(totalLength_-offset_, static_cast(4096)); + if(offset_ < totalLength_) { + off_t len = std::min(totalLength_-offset_, static_cast(4096)); stream_->allocate(offset_, len); offset_ += len; } @@ -89,7 +89,7 @@ void AdaptiveFileAllocationIterator::allocateChunk() bool AdaptiveFileAllocationIterator::finished() { if(!allocator_) { - return (uint64_t)offset_ == totalLength_; + return offset_ == totalLength_; } else { return allocator_->finished(); } @@ -104,7 +104,7 @@ off_t AdaptiveFileAllocationIterator::getCurrentLength() } } -uint64_t AdaptiveFileAllocationIterator::getTotalLength() +off_t AdaptiveFileAllocationIterator::getTotalLength() { return totalLength_; } diff --git a/src/AdaptiveFileAllocationIterator.h b/src/AdaptiveFileAllocationIterator.h index 8a3f2e3b..36217e6f 100644 --- a/src/AdaptiveFileAllocationIterator.h +++ b/src/AdaptiveFileAllocationIterator.h @@ -50,10 +50,10 @@ private: off_t offset_; - uint64_t totalLength_; + off_t totalLength_; public: AdaptiveFileAllocationIterator - (BinaryStream* stream, off_t offset, uint64_t totalLength); + (BinaryStream* stream, off_t offset, off_t totalLength); virtual ~AdaptiveFileAllocationIterator(); @@ -63,7 +63,7 @@ public: virtual off_t getCurrentLength(); - virtual uint64_t getTotalLength(); + virtual off_t getTotalLength(); }; } // namespace aria2 diff --git a/src/BinaryStream.h b/src/BinaryStream.h index 4dee179b..bb7853a5 100644 --- a/src/BinaryStream.h +++ b/src/BinaryStream.h @@ -53,11 +53,11 @@ public: // Truncates a file to given length. The default implementation does // nothing. - virtual void truncate(uint64_t length) {} + virtual void truncate(off_t length) {} // Allocates given length bytes of disk space from given offset. The // default implementation does nothing. - virtual void allocate(off_t offset, uint64_t length) {} + virtual void allocate(off_t offset, off_t length) {} }; typedef SharedHandle BinaryStreamHandle; diff --git a/src/BitfieldMan.cc b/src/BitfieldMan.cc index 2d50dab6..19a6d0c9 100644 --- a/src/BitfieldMan.cc +++ b/src/BitfieldMan.cc @@ -44,7 +44,7 @@ using namespace aria2::expr; namespace aria2 { -BitfieldMan::BitfieldMan(size_t blockLength, uint64_t totalLength) +BitfieldMan::BitfieldMan(size_t blockLength, off_t totalLength) :blockLength_(blockLength), totalLength_(totalLength), bitfieldLength_(0), @@ -275,8 +275,8 @@ bool getSparseMissingUnusedIndex } else { if((!bitfield::test(useBitfield, blocks, maxRange.startIndex-1) && bitfield::test(bitfield, blocks, maxRange.startIndex-1)) || - ((uint64_t)(maxRange.endIndex-maxRange.startIndex)*blockLength_ - >= minSplitSize)) { + (static_cast(maxRange.endIndex-maxRange.startIndex)* + blockLength_ >= minSplitSize)) { index = maxRange.startIndex; return true; } else { @@ -663,7 +663,7 @@ void BitfieldMan::ensureFilterBitfield() } } -void BitfieldMan::addFilter(uint64_t offset, uint64_t length) { +void BitfieldMan::addFilter(off_t offset, off_t length) { ensureFilterBitfield(); if(length > 0) { size_t startBlock = offset/blockLength_; @@ -675,7 +675,7 @@ void BitfieldMan::addFilter(uint64_t offset, uint64_t length) { updateCache(); } -void BitfieldMan::removeFilter(uint64_t offset, uint64_t length) { +void BitfieldMan::removeFilter(off_t offset, off_t length) { ensureFilterBitfield(); if(length > 0) { size_t startBlock = offset/blockLength_; @@ -687,7 +687,7 @@ void BitfieldMan::removeFilter(uint64_t offset, uint64_t length) { updateCache(); } -void BitfieldMan::addNotFilter(uint64_t offset, uint64_t length) +void BitfieldMan::addNotFilter(off_t offset, off_t length) { ensureFilterBitfield(); if(length > 0 && blocks_ > 0) { @@ -726,7 +726,7 @@ void BitfieldMan::clearFilter() { updateCache(); } -uint64_t BitfieldMan::getFilteredTotalLengthNow() const { +off_t BitfieldMan::getFilteredTotalLengthNow() const { if(!filterBitfield_) { return 0; } @@ -735,13 +735,13 @@ uint64_t BitfieldMan::getFilteredTotalLengthNow() const { return 0; } if(bitfield::test(filterBitfield_, blocks_, blocks_-1)) { - return ((uint64_t)filteredBlocks-1)*blockLength_+getLastBlockLength(); + return ((off_t)filteredBlocks-1)*blockLength_+getLastBlockLength(); } else { - return ((uint64_t)filteredBlocks)*blockLength_; + return ((off_t)filteredBlocks)*blockLength_; } } -uint64_t BitfieldMan::getCompletedLength(bool useFilter) const { +off_t BitfieldMan::getCompletedLength(bool useFilter) const { unsigned char* temp; if(useFilter) { temp = new unsigned char[bitfieldLength_]; @@ -755,14 +755,15 @@ uint64_t BitfieldMan::getCompletedLength(bool useFilter) const { temp = bitfield_; } size_t completedBlocks = bitfield::countSetBit(temp, blocks_); - uint64_t completedLength = 0; + off_t completedLength = 0; if(completedBlocks == 0) { completedLength = 0; } else { if(bitfield::test(temp, blocks_, blocks_-1)) { - completedLength = ((uint64_t)completedBlocks-1)*blockLength_+getLastBlockLength(); + completedLength = + ((off_t)completedBlocks-1)*blockLength_+getLastBlockLength(); } else { - completedLength = ((uint64_t)completedBlocks)*blockLength_; + completedLength = ((off_t)completedBlocks)*blockLength_; } } if(useFilter) { @@ -771,11 +772,11 @@ uint64_t BitfieldMan::getCompletedLength(bool useFilter) const { return completedLength; } -uint64_t BitfieldMan::getCompletedLengthNow() const { +off_t BitfieldMan::getCompletedLengthNow() const { return getCompletedLength(false); } -uint64_t BitfieldMan::getFilteredCompletedLengthNow() const { +off_t BitfieldMan::getFilteredCompletedLengthNow() const { return getCompletedLength(true); } @@ -814,7 +815,7 @@ void BitfieldMan::setBitRange(size_t startIndex, size_t endIndex) updateCache(); } -bool BitfieldMan::isBitSetOffsetRange(uint64_t offset, uint64_t length) const +bool BitfieldMan::isBitSetOffsetRange(off_t offset, off_t length) const { if(length <= 0) { return false; @@ -835,11 +836,11 @@ bool BitfieldMan::isBitSetOffsetRange(uint64_t offset, uint64_t length) const return true; } -uint64_t BitfieldMan::getOffsetCompletedLength -(uint64_t offset, - uint64_t length) const +off_t BitfieldMan::getOffsetCompletedLength +(off_t offset, + off_t length) const { - uint64_t res = 0; + off_t res = 0; if(length == 0 || totalLength_ <= offset) { return 0; } @@ -868,12 +869,12 @@ uint64_t BitfieldMan::getOffsetCompletedLength return res; } -uint64_t BitfieldMan::getMissingUnusedLength(size_t startingIndex) const +off_t BitfieldMan::getMissingUnusedLength(size_t startingIndex) const { if(startingIndex < 0 || blocks_ <= startingIndex) { return 0; } - uint64_t length = 0; + off_t length = 0; for(size_t i = startingIndex; i < blocks_; ++i) { if(isBitSet(i) || isUseBitSet(i)) { break; diff --git a/src/BitfieldMan.h b/src/BitfieldMan.h index d99235bf..b2ea7da4 100644 --- a/src/BitfieldMan.h +++ b/src/BitfieldMan.h @@ -46,7 +46,7 @@ namespace aria2 { class BitfieldMan { private: size_t blockLength_; - uint64_t totalLength_; + off_t totalLength_; size_t bitfieldLength_; size_t blocks_; bool filterEnabled_; @@ -57,9 +57,9 @@ private: // for caching size_t cachedNumMissingBlock_; size_t cachedNumFilteredBlock_; - uint64_t cachedCompletedLength_; - uint64_t cachedFilteredCompletedLength_; - uint64_t cachedFilteredTotalLength_; + off_t cachedCompletedLength_; + off_t cachedFilteredCompletedLength_; + off_t cachedFilteredTotalLength_; bool setBitInternal(unsigned char* bitfield, size_t index, bool on); bool setFilterBit(size_t index); @@ -67,7 +67,7 @@ private: size_t getStartIndex(size_t index) const; size_t getEndIndex(size_t index) const; - uint64_t getCompletedLength(bool useFilter) const; + off_t getCompletedLength(bool useFilter) const; // If filterBitfield_ is 0, allocate bitfieldLength_ bytes to it and // set 0 to all bytes. @@ -84,7 +84,7 @@ public: bool operator==(const Range& range) const; }; public: - BitfieldMan(size_t blockLength, uint64_t totalLength); + BitfieldMan(size_t blockLength, off_t totalLength); BitfieldMan(const BitfieldMan& bitfieldMan); ~BitfieldMan(); @@ -99,7 +99,7 @@ public: size_t getBlockLength(size_t index) const; - uint64_t getTotalLength() const { return totalLength_; } + off_t getTotalLength() const { return totalLength_; } // Returns true iff there is a bit index which is set in bitfield_, // but not set in this object. @@ -238,10 +238,10 @@ public: void clearAllUseBit(); void setAllUseBit(); - void addFilter(uint64_t offset, uint64_t length); - void removeFilter(uint64_t offset, uint64_t length); + void addFilter(off_t offset, off_t length); + void removeFilter(off_t offset, off_t length); // Add filter not in the range of [offset, offset+length) bytes - void addNotFilter(uint64_t offset, uint64_t length); + void addNotFilter(off_t offset, off_t length); // Clears filter and disables filter void clearFilter(); @@ -254,29 +254,29 @@ public: } // affected by filter - uint64_t getFilteredTotalLength() const + off_t getFilteredTotalLength() const { return cachedFilteredTotalLength_; } // affected by filter - uint64_t getFilteredTotalLengthNow() const; + off_t getFilteredTotalLengthNow() const; - uint64_t getCompletedLength() const + off_t getCompletedLength() const { return cachedCompletedLength_; } - uint64_t getCompletedLengthNow() const; + off_t getCompletedLengthNow() const; // affected by filter - uint64_t getFilteredCompletedLength() const + off_t getFilteredCompletedLength() const { return cachedFilteredCompletedLength_; } // affected by filter - uint64_t getFilteredCompletedLengthNow() const; + off_t getFilteredCompletedLengthNow() const; void updateCache(); @@ -286,13 +286,13 @@ public: void setBitRange(size_t startIndex, size_t endIndex); - bool isBitSetOffsetRange(uint64_t offset, uint64_t length) const; + bool isBitSetOffsetRange(off_t offset, off_t length) const; // Returns completed length in bytes in range [offset, // offset+length). This function will not affected by filter. - uint64_t getOffsetCompletedLength(uint64_t offset, uint64_t length) const; + off_t getOffsetCompletedLength(off_t offset, off_t length) const; - uint64_t getMissingUnusedLength(size_t startingIndex) const; + off_t getMissingUnusedLength(size_t startingIndex) const; const unsigned char* getFilterBitfield() const { diff --git a/src/BtRuntime.h b/src/BtRuntime.h index 7ceeac65..90859f41 100644 --- a/src/BtRuntime.h +++ b/src/BtRuntime.h @@ -42,7 +42,7 @@ namespace aria2 { class BtRuntime { private: - uint64_t uploadLengthAtStartup_; + off_t uploadLengthAtStartup_; bool halt_; unsigned int connections_; bool ready_; @@ -60,11 +60,11 @@ public: ~BtRuntime(); - uint64_t getUploadLengthAtStartup() const { + off_t getUploadLengthAtStartup() const { return uploadLengthAtStartup_; } - void setUploadLengthAtStartup(uint64_t length) { + void setUploadLengthAtStartup(off_t length) { uploadLengthAtStartup_ = length; } diff --git a/src/ByteArrayDiskWriter.cc b/src/ByteArrayDiskWriter.cc index bb81dcd1..e83a573a 100644 --- a/src/ByteArrayDiskWriter.cc +++ b/src/ByteArrayDiskWriter.cc @@ -50,16 +50,16 @@ void ByteArrayDiskWriter::clear() buf_.str(A2STR::NIL); } -void ByteArrayDiskWriter::initAndOpenFile(uint64_t totalLength) +void ByteArrayDiskWriter::initAndOpenFile(off_t totalLength) { clear(); } -void ByteArrayDiskWriter::openFile(uint64_t totalLength) {} +void ByteArrayDiskWriter::openFile(off_t totalLength) {} void ByteArrayDiskWriter::closeFile() {} -void ByteArrayDiskWriter::openExistingFile(uint64_t totalLength) +void ByteArrayDiskWriter::openExistingFile(off_t totalLength) { openFile(); } @@ -70,10 +70,10 @@ void ByteArrayDiskWriter::writeData(const unsigned char* data, size_t dataLength throw DL_ABORT_EX(fmt("Maximum length(%lu) exceeded.", static_cast(maxLength_))); } - uint64_t length = size(); - if(length < (uint64_t)position) { + off_t length = size(); + if(length < position) { buf_.seekp(length, std::ios::beg); - for(uint64_t i = length; i < (uint64_t)position; ++i) { + for(off_t i = length; i < position; ++i) { buf_.put('\0'); } } else { @@ -90,7 +90,7 @@ ssize_t ByteArrayDiskWriter::readData(unsigned char* data, size_t len, off_t pos return buf_.gcount(); } -uint64_t ByteArrayDiskWriter::size() +off_t ByteArrayDiskWriter::size() { buf_.seekg(0, std::ios::end); buf_.clear(); diff --git a/src/ByteArrayDiskWriter.h b/src/ByteArrayDiskWriter.h index c51d8200..6899d63f 100644 --- a/src/ByteArrayDiskWriter.h +++ b/src/ByteArrayDiskWriter.h @@ -49,18 +49,18 @@ public: ByteArrayDiskWriter(size_t maxLength = 5*1024*1024); virtual ~ByteArrayDiskWriter(); - virtual void initAndOpenFile(uint64_t totalLength = 0); + virtual void initAndOpenFile(off_t totalLength = 0); - virtual void openFile(uint64_t totalLength = 0); + virtual void openFile(off_t totalLength = 0); virtual void closeFile(); - virtual void openExistingFile(uint64_t totalLength = 0); + virtual void openExistingFile(off_t totalLength = 0); virtual void writeData(const unsigned char* data, size_t len, off_t position); virtual ssize_t readData(unsigned char* data, size_t len, off_t position); - virtual uint64_t size(); + virtual off_t size(); void setString(const std::string& s); diff --git a/src/CheckIntegrityEntry.cc b/src/CheckIntegrityEntry.cc index eda0b2ab..c635a540 100644 --- a/src/CheckIntegrityEntry.cc +++ b/src/CheckIntegrityEntry.cc @@ -56,7 +56,7 @@ void CheckIntegrityEntry::validateChunk() validator_->validateChunk(); } -uint64_t CheckIntegrityEntry::getTotalLength() +off_t CheckIntegrityEntry::getTotalLength() { if(!validator_) { return 0; diff --git a/src/CheckIntegrityEntry.h b/src/CheckIntegrityEntry.h index a2fb7da7..5f5dcd58 100644 --- a/src/CheckIntegrityEntry.h +++ b/src/CheckIntegrityEntry.h @@ -61,7 +61,7 @@ public: virtual ~CheckIntegrityEntry(); - virtual uint64_t getTotalLength(); + virtual off_t getTotalLength(); virtual off_t getCurrentLength(); diff --git a/src/ChunkChecksum.cc b/src/ChunkChecksum.cc index 4d120afa..2a561819 100644 --- a/src/ChunkChecksum.cc +++ b/src/ChunkChecksum.cc @@ -56,9 +56,9 @@ bool ChunkChecksum::validateChunk return !digest.empty() && actualDigest == digest; } -uint64_t ChunkChecksum::getEstimatedDataLength() const +off_t ChunkChecksum::getEstimatedDataLength() const { - return static_cast(pieceLength_)*pieceHashes_.size(); + return static_cast(pieceLength_)*pieceHashes_.size(); } size_t ChunkChecksum::countPieceHash() const diff --git a/src/ChunkChecksum.h b/src/ChunkChecksum.h index c28364d0..126bd82f 100644 --- a/src/ChunkChecksum.h +++ b/src/ChunkChecksum.h @@ -60,7 +60,7 @@ public: bool validateChunk(const std::string& actualDigest, size_t index) const; - uint64_t getEstimatedDataLength() const; + off_t getEstimatedDataLength() const; size_t countPieceHash() const; diff --git a/src/ChunkedDecodingStreamFilter.cc b/src/ChunkedDecodingStreamFilter.cc index b1f98bdf..87140e9e 100644 --- a/src/ChunkedDecodingStreamFilter.cc +++ b/src/ChunkedDecodingStreamFilter.cc @@ -96,8 +96,11 @@ bool ChunkedDecodingStreamFilter::readChunkSize if(extPos == std::string::npos || crlfPos < extPos) { extPos = crlfPos; } - chunkSize_ = util::parseULLInt + chunkSize_ = util::parseLLInt (std::string(buf_.begin(), buf_.begin()+extPos), 16); + if(chunkSize_ < 0) { + throw DL_ABORT_EX("Chunk size must be positive"); + } assert(crlfPos+2 > pbufSize); inbufOffset += crlfPos+2-pbufSize; buf_.clear(); @@ -155,8 +158,8 @@ bool ChunkedDecodingStreamFilter::readData const SharedHandle& out, const SharedHandle& segment) { - uint64_t readlen = - std::min(chunkSize_, static_cast(inlen-inbufOffset)); + off_t readlen = + std::min(chunkSize_, static_cast(inlen-inbufOffset)); outlen += getDelegate()->transform(out, segment, inbuf+inbufOffset, readlen); chunkSize_ -= readlen; inbufOffset += readlen; diff --git a/src/ChunkedDecodingStreamFilter.h b/src/ChunkedDecodingStreamFilter.h index 6909e33e..902d3fb5 100644 --- a/src/ChunkedDecodingStreamFilter.h +++ b/src/ChunkedDecodingStreamFilter.h @@ -59,7 +59,7 @@ private: std::string buf_; - uint64_t chunkSize_; + off_t chunkSize_; size_t bytesProcessed_; diff --git a/src/DefaultBtAnnounce.cc b/src/DefaultBtAnnounce.cc index 23be204c..049f3bcd 100644 --- a/src/DefaultBtAnnounce.cc +++ b/src/DefaultBtAnnounce.cc @@ -142,7 +142,7 @@ std::string DefaultBtAnnounce::getAnnounceUrl() { numWant = 0; } TransferStat stat = peerStorage_->calculateStat(); - uint64_t left = + off_t left = pieceStorage_->getTotalLength()-pieceStorage_->getCompletedLength(); // Use last 8 bytes of peer ID as a key const size_t keyLen = 8; diff --git a/src/DefaultBtProgressInfoFile.cc b/src/DefaultBtProgressInfoFile.cc index 84627d60..9fa32b1c 100644 --- a/src/DefaultBtProgressInfoFile.cc +++ b/src/DefaultBtProgressInfoFile.cc @@ -275,7 +275,7 @@ void DefaultBtProgressInfoFile::load() if(version >= 1) { totalLength = ntoh64(totalLength); } - if(totalLength != dctx_->getTotalLength()) { + if(totalLength != static_cast(dctx_->getTotalLength())) { throw DL_ABORT_EX (fmt("total length mismatch. expected: %lld, actual: %lld", static_cast(dctx_->getTotalLength()), diff --git a/src/DefaultDiskWriter.cc b/src/DefaultDiskWriter.cc index 7b475d8f..afa02072 100644 --- a/src/DefaultDiskWriter.cc +++ b/src/DefaultDiskWriter.cc @@ -41,7 +41,7 @@ DefaultDiskWriter::DefaultDiskWriter(const std::string& filename): DefaultDiskWriter::~DefaultDiskWriter() {} -void DefaultDiskWriter::initAndOpenFile(uint64_t totalLength) +void DefaultDiskWriter::initAndOpenFile(off_t totalLength) { createFile(); } diff --git a/src/DefaultDiskWriter.h b/src/DefaultDiskWriter.h index 339e0edd..2bc5a488 100644 --- a/src/DefaultDiskWriter.h +++ b/src/DefaultDiskWriter.h @@ -45,7 +45,7 @@ public: virtual ~DefaultDiskWriter(); - virtual void initAndOpenFile(uint64_t totalLength = 0); + virtual void initAndOpenFile(off_t totalLength = 0); }; typedef SharedHandle DefaultDiskWriterHandle; diff --git a/src/DefaultPeerStorage.cc b/src/DefaultPeerStorage.cc index af68de2a..dec61d6f 100644 --- a/src/DefaultPeerStorage.cc +++ b/src/DefaultPeerStorage.cc @@ -60,8 +60,8 @@ const size_t MAX_PEER_LIST_UPDATE = 100; DefaultPeerStorage::DefaultPeerStorage() : maxPeerListSize_(MAX_PEER_LIST_SIZE), - removedPeerSessionDownloadLength_(0), - removedPeerSessionUploadLength_(0), + removedPeerSessionDownloadLength_(0LL), + removedPeerSessionUploadLength_(0LL), seederStateChoke_(new BtSeederStateChoke()), leecherStateChoke_(new BtLeecherStateChoke()), lastTransferStatMapUpdated_(0) diff --git a/src/DefaultPeerStorage.h b/src/DefaultPeerStorage.h index 5411eac7..8722e63b 100644 --- a/src/DefaultPeerStorage.h +++ b/src/DefaultPeerStorage.h @@ -56,8 +56,8 @@ private: size_t maxPeerListSize_; std::deque > peers_; std::deque > droppedPeers_; - uint64_t removedPeerSessionDownloadLength_; - uint64_t removedPeerSessionUploadLength_; + int64_t removedPeerSessionDownloadLength_; + int64_t removedPeerSessionUploadLength_; BtSeederStateChoke* seederStateChoke_; BtLeecherStateChoke* leecherStateChoke_; diff --git a/src/DefaultPieceStorage.cc b/src/DefaultPieceStorage.cc index 7268bcf8..0b32761b 100644 --- a/src/DefaultPieceStorage.cc +++ b/src/DefaultPieceStorage.cc @@ -518,28 +518,28 @@ bool DefaultPieceStorage::isPieceUsed(size_t index) return bitfieldMan_->isUseBitSet(index); } -uint64_t DefaultPieceStorage::getTotalLength() +off_t DefaultPieceStorage::getTotalLength() { return bitfieldMan_->getTotalLength(); } -uint64_t DefaultPieceStorage::getFilteredTotalLength() +off_t DefaultPieceStorage::getFilteredTotalLength() { return bitfieldMan_->getFilteredTotalLength(); } -uint64_t DefaultPieceStorage::getCompletedLength() +off_t DefaultPieceStorage::getCompletedLength() { - uint64_t completedLength = + off_t completedLength = bitfieldMan_->getCompletedLength()+getInFlightPieceCompletedLength(); - uint64_t totalLength = getTotalLength(); + off_t totalLength = getTotalLength(); if(completedLength > totalLength) { completedLength = totalLength; } return completedLength; } -uint64_t DefaultPieceStorage::getFilteredCompletedLength() +off_t DefaultPieceStorage::getFilteredCompletedLength() { return bitfieldMan_->getFilteredCompletedLength()+ getInFlightPieceCompletedLength(); @@ -712,7 +712,7 @@ void DefaultPieceStorage::markAllPiecesDone() bitfieldMan_->setAllBit(); } -void DefaultPieceStorage::markPiecesDone(uint64_t length) +void DefaultPieceStorage::markPiecesDone(off_t length) { if(length == bitfieldMan_->getTotalLength()) { bitfieldMan_->setAllBit(); diff --git a/src/DefaultPieceStorage.h b/src/DefaultPieceStorage.h index 30f0ecf9..21b57fcb 100644 --- a/src/DefaultPieceStorage.h +++ b/src/DefaultPieceStorage.h @@ -187,13 +187,13 @@ public: virtual bool isPieceUsed(size_t index); - virtual uint64_t getTotalLength(); + virtual off_t getTotalLength(); - virtual uint64_t getFilteredTotalLength(); + virtual off_t getFilteredTotalLength(); - virtual uint64_t getCompletedLength(); + virtual off_t getCompletedLength(); - virtual uint64_t getFilteredCompletedLength(); + virtual off_t getFilteredCompletedLength(); virtual void initStorage(); @@ -246,7 +246,7 @@ public: virtual void markAllPiecesDone(); - virtual void markPiecesDone(uint64_t length); + virtual void markPiecesDone(off_t length); virtual void markPieceMissing(size_t index); diff --git a/src/DiskAdaptor.h b/src/DiskAdaptor.h index d7c06b90..6a94def0 100644 --- a/src/DiskAdaptor.h +++ b/src/DiskAdaptor.h @@ -66,7 +66,7 @@ public: virtual bool fileExists() = 0; - virtual uint64_t size() = 0; + virtual off_t size() = 0; template void setFileEntries(InputIterator first, InputIterator last) diff --git a/src/DiskWriter.h b/src/DiskWriter.h index 427380d4..d7c2c8b4 100644 --- a/src/DiskWriter.h +++ b/src/DiskWriter.h @@ -51,9 +51,9 @@ public: /** * Opens file. If the file exists, then it is truncated to 0 length. */ - virtual void initAndOpenFile(uint64_t totalLength = 0) = 0; + virtual void initAndOpenFile(off_t totalLength = 0) = 0; - virtual void openFile(uint64_t totalLength = 0) = 0; + virtual void openFile(off_t totalLength = 0) = 0; /** * Closes this output stream. @@ -65,10 +65,10 @@ public: * Opens a file. If the file doesnot exists, an exception may be * thrown. */ - virtual void openExistingFile(uint64_t totalLength = 0) = 0; + virtual void openExistingFile(off_t totalLength = 0) = 0; // Returns file length - virtual uint64_t size() = 0; + virtual off_t size() = 0; // Enables read-only mode. After this call, openExistingFile() opens // file in read-only mode. This is an optional functionality. The diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc index 37da0cbb..2862d3d3 100644 --- a/src/DownloadCommand.cc +++ b/src/DownloadCommand.cc @@ -146,8 +146,8 @@ bool DownloadCommand::executeInternal() { size_t bufSize; if(sinkFilterOnly_) { if(segment->getLength() > 0) { - if(static_cast(segment->getPosition()+segment->getLength()) <= - static_cast(getFileEntry()->getLastOffset())) { + if(static_cast(segment->getPosition()+segment->getLength()) <= + getFileEntry()->getLastOffset()) { bufSize = std::min(segment->getLength()-segment->getWrittenLength(), getSocketRecvBuffer()->getBufferLength()); } else { diff --git a/src/DownloadContext.cc b/src/DownloadContext.cc index 7f90627c..4a9e8e7a 100644 --- a/src/DownloadContext.cc +++ b/src/DownloadContext.cc @@ -57,7 +57,7 @@ DownloadContext::DownloadContext(): metalinkServerContacted_(false) {} DownloadContext::DownloadContext(size_t pieceLength, - uint64_t totalLength, + off_t totalLength, const std::string& path): pieceLength_(pieceLength), checksumVerified_(false), @@ -98,9 +98,7 @@ SharedHandle DownloadContext::findFileEntryByOffset(off_t offset) const { if(fileEntries_.empty() || - (offset > 0 && - fileEntries_.back()->getOffset()+fileEntries_.back()->getLength() <= - static_cast(offset))){ + (offset > 0 && fileEntries_.back()->getLastOffset() <= offset)) { return SharedHandle(); } @@ -200,7 +198,7 @@ size_t DownloadContext::getNumPieces() const } } -uint64_t DownloadContext::getTotalLength() const +off_t DownloadContext::getTotalLength() const { if(fileEntries_.empty()) { return 0; diff --git a/src/DownloadContext.h b/src/DownloadContext.h index 46c69e69..7eee1f84 100644 --- a/src/DownloadContext.h +++ b/src/DownloadContext.h @@ -93,7 +93,7 @@ public: // Convenient constructor that creates single file download. path // should be escaped with util::escapePath(...). DownloadContext(size_t pieceLength, - uint64_t totalLength, + off_t totalLength, const std::string& path = A2STR::NIL); ~DownloadContext(); @@ -114,7 +114,7 @@ public: pieceHashes_.assign(first, last); } - uint64_t getTotalLength() const; + off_t getTotalLength() const; bool knowsTotalLength() const { return knowsTotalLength_; } diff --git a/src/DownloadResult.h b/src/DownloadResult.h index 6c80ad29..5c920510 100644 --- a/src/DownloadResult.h +++ b/src/DownloadResult.h @@ -79,11 +79,11 @@ struct DownloadResult SharedHandle metadataInfo; - uint64_t totalLength; + off_t totalLength; - uint64_t completedLength; + off_t completedLength; - uint64_t uploadLength; + off_t uploadLength; std::string bitfield; diff --git a/src/FallocFileAllocationIterator.cc b/src/FallocFileAllocationIterator.cc index 3e4e24d1..f337bf7a 100644 --- a/src/FallocFileAllocationIterator.cc +++ b/src/FallocFileAllocationIterator.cc @@ -38,12 +38,12 @@ namespace aria2 { FallocFileAllocationIterator::FallocFileAllocationIterator -(BinaryStream* stream, off_t offset, uint64_t totalLength): +(BinaryStream* stream, off_t offset, off_t totalLength): stream_(stream), offset_(offset), totalLength_(totalLength) {} void FallocFileAllocationIterator::allocateChunk() { - if(static_cast(offset_) < totalLength_) { + if(offset_ < totalLength_) { stream_->allocate(offset_, totalLength_-offset_); offset_ = totalLength_; } else { @@ -54,7 +54,7 @@ void FallocFileAllocationIterator::allocateChunk() bool FallocFileAllocationIterator::finished() { - return static_cast(offset_) == totalLength_; + return offset_ == totalLength_; } off_t FallocFileAllocationIterator::getCurrentLength() @@ -62,7 +62,7 @@ off_t FallocFileAllocationIterator::getCurrentLength() return offset_; } -uint64_t FallocFileAllocationIterator::getTotalLength() +off_t FallocFileAllocationIterator::getTotalLength() { return totalLength_; } diff --git a/src/FallocFileAllocationIterator.h b/src/FallocFileAllocationIterator.h index e7e6fbc1..d43db3a6 100644 --- a/src/FallocFileAllocationIterator.h +++ b/src/FallocFileAllocationIterator.h @@ -45,10 +45,10 @@ class FallocFileAllocationIterator:public FileAllocationIterator { private: BinaryStream* stream_; off_t offset_; - uint64_t totalLength_; + off_t totalLength_; public: FallocFileAllocationIterator(BinaryStream* stream, off_t offset, - uint64_t totalLength); + off_t totalLength); virtual void allocateChunk(); @@ -56,7 +56,7 @@ public: virtual off_t getCurrentLength(); - virtual uint64_t getTotalLength(); + virtual off_t getTotalLength(); }; } // namespace aria2 diff --git a/src/File.cc b/src/File.cc index f47b78c7..87b95486 100644 --- a/src/File.cc +++ b/src/File.cc @@ -103,7 +103,7 @@ bool File::remove() { } } -uint64_t File::size() { +off_t File::size() { a2_struct_stat fstat; if(fillStat(fstat) < 0) { return 0; diff --git a/src/File.h b/src/File.h index 37b1ba49..8290cd4e 100644 --- a/src/File.h +++ b/src/File.h @@ -94,7 +94,7 @@ public: */ bool mkdirs(); - uint64_t size(); + off_t size(); mode_t mode(); diff --git a/src/FileAllocationEntry.cc b/src/FileAllocationEntry.cc index 2d96f756..ff4e0f29 100644 --- a/src/FileAllocationEntry.cc +++ b/src/FileAllocationEntry.cc @@ -54,7 +54,7 @@ off_t FileAllocationEntry::getCurrentLength() return fileAllocationIterator_->getCurrentLength(); } -uint64_t FileAllocationEntry::getTotalLength() +off_t FileAllocationEntry::getTotalLength() { return fileAllocationIterator_->getTotalLength(); } diff --git a/src/FileAllocationEntry.h b/src/FileAllocationEntry.h index 509a8a04..4d47123f 100644 --- a/src/FileAllocationEntry.h +++ b/src/FileAllocationEntry.h @@ -56,7 +56,7 @@ public: virtual off_t getCurrentLength(); - virtual uint64_t getTotalLength(); + virtual off_t getTotalLength(); virtual bool finished(); diff --git a/src/FileAllocationIterator.h b/src/FileAllocationIterator.h index a57d4277..57f4e294 100644 --- a/src/FileAllocationIterator.h +++ b/src/FileAllocationIterator.h @@ -52,7 +52,7 @@ public: virtual off_t getCurrentLength() = 0; - virtual uint64_t getTotalLength() = 0; + virtual off_t getTotalLength() = 0; }; } // namespace aria2 diff --git a/src/FileEntry.cc b/src/FileEntry.cc index 23721e7a..1af951da 100644 --- a/src/FileEntry.cc +++ b/src/FileEntry.cc @@ -53,7 +53,7 @@ namespace aria2 { FileEntry::FileEntry (const std::string& path, - uint64_t length, + off_t length, off_t offset, const std::vector& uris) : path_(path), diff --git a/src/FileEntry.h b/src/FileEntry.h index c77ca47a..1f3385ba 100644 --- a/src/FileEntry.h +++ b/src/FileEntry.h @@ -61,7 +61,7 @@ private: std::string path_; std::deque uris_; std::deque spentUris_; - uint64_t length_; + off_t length_; off_t offset_; bool requested_; std::deque > requestPool_; @@ -79,7 +79,7 @@ private: public: FileEntry(); - FileEntry(const std::string& path, uint64_t length, off_t offset, + FileEntry(const std::string& path, off_t length, off_t offset, const std::vector& uris = std::vector()); ~FileEntry(); @@ -94,9 +94,9 @@ public: void setPath(const std::string& path); - uint64_t getLength() const { return length_; } + off_t getLength() const { return length_; } - void setLength(uint64_t length) { length_ = length; } + void setLength(off_t length) { length_ = length; } off_t getOffset() const { return offset_; } diff --git a/src/FtpConnection.cc b/src/FtpConnection.cc index 90e430c4..4436d7c0 100644 --- a/src/FtpConnection.cc +++ b/src/FtpConnection.cc @@ -400,14 +400,17 @@ unsigned int FtpConnection::receiveResponse() # define ULONGLONG_SCANF "%Lu" #endif // __MINGW32__ -unsigned int FtpConnection::receiveSizeResponse(uint64_t& size) +unsigned int FtpConnection::receiveSizeResponse(off_t& size) { std::pair response; if(bulkReceiveResponse(response)) { if(response.first == 213) { std::pair rp; util::divide(rp, response.second.begin(), response.second.end(), ' '); - size = util::parseULLInt(std::string(rp.second.first, rp.second.second)); + size = util::parseLLInt(std::string(rp.second.first, rp.second.second)); + if(size < 0) { + throw DL_ABORT_EX("Size must be positive"); + } } return response.first; } else { diff --git a/src/FtpConnection.h b/src/FtpConnection.h index 6a33a33b..1abb9683 100644 --- a/src/FtpConnection.h +++ b/src/FtpConnection.h @@ -102,7 +102,7 @@ public: bool sendRetr(); unsigned int receiveResponse(); - unsigned int receiveSizeResponse(uint64_t& size); + unsigned int receiveSizeResponse(off_t& size); // Returns status code of MDTM reply. If the status code is 213, parses // time-val and store it in time. // If a code other than 213 is returned, time is not touched. diff --git a/src/FtpNegotiationCommand.cc b/src/FtpNegotiationCommand.cc index 7033715d..6412c7ac 100644 --- a/src/FtpNegotiationCommand.cc +++ b/src/FtpNegotiationCommand.cc @@ -364,7 +364,7 @@ bool FtpNegotiationCommand::sendSize() { return false; } -bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength) +bool FtpNegotiationCommand::onFileSizeDetermined(off_t totalLength) { getFileEntry()->setLength(totalLength); if(getFileEntry()->getPath().empty()) { @@ -464,7 +464,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength) } bool FtpNegotiationCommand::recvSize() { - uint64_t size = 0; + off_t size = 0; unsigned int status = ftp_->receiveSizeResponse(size); if(status == 0) { return false; diff --git a/src/FtpNegotiationCommand.h b/src/FtpNegotiationCommand.h index b155595b..a22e6853 100644 --- a/src/FtpNegotiationCommand.h +++ b/src/FtpNegotiationCommand.h @@ -137,7 +137,7 @@ private: void poolConnection() const; - bool onFileSizeDetermined(uint64_t totalLength); + bool onFileSizeDetermined(off_t totalLength); void onDryRunFileFound(); diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index ad926cc0..ff6aa8d9 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -108,16 +108,23 @@ HttpHeader::equalRange(const std::string& name) const return table_.equal_range(name); } -unsigned int HttpHeader::findAsUInt(const std::string& name) const { - return findAsULLInt(name); -} - -uint64_t HttpHeader::findAsULLInt(const std::string& name) const { +int32_t HttpHeader::findAsInt(const std::string& name) const +{ const std::string& value = find(name); if(value.empty()) { return 0; } else { - return util::parseULLInt(value); + return util::parseInt(value); + } +} + +int64_t HttpHeader::findAsLLInt(const std::string& name) const +{ + const std::string& value = find(name); + if(value.empty()) { + return 0; + } else { + return util::parseLLInt(value); } } @@ -129,7 +136,10 @@ RangeHandle HttpHeader::getRange() const if(clenStr.empty()) { return SharedHandle(new Range()); } else { - uint64_t contentLength = util::parseULLInt(clenStr); + off_t contentLength = util::parseLLInt(clenStr); + if(contentLength < 0) { + throw DL_ABORT_EX("Content-Length must be positive"); + } if(contentLength == 0) { return SharedHandle(new Range()); } else { @@ -168,8 +178,11 @@ RangeHandle HttpHeader::getRange() const } off_t startByte = util::parseLLInt(std::string(byteRangeSpec, minus)); off_t endByte = util::parseLLInt(std::string(minus+1, slash)); - uint64_t entityLength = - util::parseULLInt(std::string(slash+1, rangeStr.end())); + off_t entityLength = + util::parseLLInt(std::string(slash+1, rangeStr.end())); + if(startByte < 0 || endByte < 0 || entityLength < 0) { + throw DL_ABORT_EX("byte-range-spec must be positive"); + } return SharedHandle(new Range(startByte, endByte, entityLength)); } diff --git a/src/HttpHeader.h b/src/HttpHeader.h index 547a7615..b337e089 100644 --- a/src/HttpHeader.h +++ b/src/HttpHeader.h @@ -73,8 +73,8 @@ public: std::pair::const_iterator, std::multimap::const_iterator> equalRange(const std::string& name) const; - unsigned int findAsUInt(const std::string& name) const; - uint64_t findAsULLInt(const std::string& name) const; + int32_t findAsInt(const std::string& name) const; + int64_t findAsLLInt(const std::string& name) const; SharedHandle getRange() const; diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index fa99b583..50404956 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -368,7 +368,7 @@ const SharedHandle& HttpRequest::getAuthConfig() const return authConfig_; } -uint64_t HttpRequest::getEntityLength() const +off_t HttpRequest::getEntityLength() const { assert(fileEntry_); return fileEntry_->getLength(); diff --git a/src/HttpRequest.h b/src/HttpRequest.h index 11d6642b..1e72f754 100644 --- a/src/HttpRequest.h +++ b/src/HttpRequest.h @@ -105,7 +105,7 @@ public: void setRequest(const SharedHandle& request); - uint64_t getEntityLength() const; + off_t getEntityLength() const; const std::string& getHost() const; diff --git a/src/HttpRequestCommand.cc b/src/HttpRequestCommand.cc index 74ba8e10..a52ce99e 100644 --- a/src/HttpRequestCommand.cc +++ b/src/HttpRequestCommand.cc @@ -86,7 +86,7 @@ SharedHandle createHttpRequest(const SharedHandle& req, const SharedHandle& fileEntry, const SharedHandle& segment, - uint64_t totalLength, + off_t totalLength, const SharedHandle