From ba7f9f765794bc197750253f07211c66afdd69e5 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 5 Mar 2007 12:31:57 +0000 Subject: [PATCH] 2007-03-05 Tatsuhiro Tsujikawa * src/HttpHeader.h (Range.h): New include. (status): New variable. (HttpHeader): Initialized status with 0. (getStatus): New function. (setStatus): New function. (getRange): New function. (HttpHeaderHandle): New function. * src/HttpHeader.cc (getRange): New function. * src/Request.h (RequestWeakHandle): New definition. * src/HttpConnection.h (HttpConnectionHandle): New type definition. * src/HttpConnection.cc (receiveResponse): Set HTTP status to headers. * src/main.cc (showUsage): Fixed typo. * src/Segment.h (SegmentHandle): New type definition. * src/BitfieldMan.h (getMissingUnusedLength): New function. * src/BitfieldMan.cc (getMissingUnusedLength): New function. --- src/BitfieldMan.cc | 15 +++++++++++++++ src/BitfieldMan.h | 2 ++ src/HttpConnection.cc | 3 ++- src/HttpConnection.h | 2 ++ src/HttpHeader.cc | 20 ++++++++++++++++++++ src/HttpHeader.h | 20 +++++++++++++++++--- src/Request.h | 1 + src/Segment.h | 2 ++ src/main.cc | 2 +- 9 files changed, 62 insertions(+), 5 deletions(-) diff --git a/src/BitfieldMan.cc b/src/BitfieldMan.cc index f142e00a..ef9a4cbe 100644 --- a/src/BitfieldMan.cc +++ b/src/BitfieldMan.cc @@ -665,3 +665,18 @@ bool BitfieldMan::isBitSetOffsetRange(int64_t offset, int64_t length) const } return true; } + +int64_t BitfieldMan::getMissingUnusedLength(int32_t startingIndex) const +{ + if(startingIndex < 0 || blocks <= startingIndex) { + return 0; + } + int64_t length = 0; + for(int32_t i = startingIndex; i < blocks; ++i) { + if(isBitSet(i) || isUseBitSet(i)) { + break; + } + length += getBlockLength(i); + } + return length; +} diff --git a/src/BitfieldMan.h b/src/BitfieldMan.h index 663ae62c..cfca8e4d 100644 --- a/src/BitfieldMan.h +++ b/src/BitfieldMan.h @@ -257,6 +257,8 @@ public: bool isBitSetOffsetRange(int64_t offset, int64_t length) const; + int64_t getMissingUnusedLength(int32_t startingIndex) const; + }; #endif // _D_BITFIELD_MAN_H_ diff --git a/src/HttpConnection.cc b/src/HttpConnection.cc index 7c080864..095fae5c 100644 --- a/src/HttpConnection.cc +++ b/src/HttpConnection.cc @@ -202,7 +202,8 @@ int HttpConnection::receiveResponse(HttpHeader& headers) { Util::split(hp, line, ':'); headers.put(hp.first, hp.second); } - return (int)strtol(status.c_str(), NULL, 10); + headers.setStatus(strtol(status.c_str(), 0, 10)); + return headers.getStatus(); } bool HttpConnection::useProxy() const { diff --git a/src/HttpConnection.h b/src/HttpConnection.h index e01f6b22..1c60f95c 100644 --- a/src/HttpConnection.h +++ b/src/HttpConnection.h @@ -97,4 +97,6 @@ public: int receiveResponse(HttpHeader& headers); }; +typedef SharedHandle HttpConnectionHandle; + #endif // _D_HTTP_CONNECTION_H_ diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index b9f97f16..adf74ae3 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -73,3 +73,23 @@ long long int HttpHeader::getFirstAsLLInt(const string& name) const { return strtoll(value.c_str(), NULL, 10); } } + +RangeHandle HttpHeader::getRange() const +{ + string rangeStr = getFirst("Range"); + if(rangeStr == "") { + return 0; + } + pair rangePair; + Util::split(rangePair, rangeStr, '/'); + pair startEndBytePair; + Util::split(startEndBytePair, rangePair.first, '-'); + + int64_t startByte = STRTOLL(startEndBytePair.first.c_str()); + int64_t endByte = STRTOLL(startEndBytePair.second.c_str()); + int64_t contentLength = STRTOLL(rangePair.second.c_str()); + + RangeHandle range = new Range(startByte, endByte, contentLength); + + return range; +} diff --git a/src/HttpHeader.h b/src/HttpHeader.h index 568bc1b4..363f207d 100644 --- a/src/HttpHeader.h +++ b/src/HttpHeader.h @@ -36,17 +36,17 @@ #define _D_HTTP_HEADER_H_ #include "common.h" +#include "Range.h" #include #include #include -using namespace std; - class HttpHeader { private: + int32_t status; multimap table; public: - HttpHeader() {} + HttpHeader():status(0) {} ~HttpHeader() {} void put(const string& name, const string& value); @@ -55,6 +55,20 @@ public: Strings get(const string& name) const; int getFirstAsInt(const string& name) const; long long int getFirstAsLLInt(const string& name) const; + + RangeHandle getRange() const; + + int32_t getStatus() const + { + return status; + } + + void setStatus(int32_t status) + { + this->status = status; + } }; +typedef SharedHandle HttpHeaderHandle; + #endif // _D_HTTP_HEADER_H_ diff --git a/src/Request.h b/src/Request.h index c62c5c7d..04f8aad7 100644 --- a/src/Request.h +++ b/src/Request.h @@ -135,5 +135,6 @@ public: typedef SharedHandle RequestHandle; typedef deque Requests; +typedef WeakHandle RequestWeakHandle; #endif // _D_REQUEST_H_ diff --git a/src/Segment.h b/src/Segment.h index 96972ae0..eed5cf0e 100644 --- a/src/Segment.h +++ b/src/Segment.h @@ -81,5 +81,7 @@ public: ostream& operator<<(ostream& o, const Segment& segment); +typedef SharedHandle SegmentHandle; + #endif // _D_SEGMENT_H_ diff --git a/src/main.cc b/src/main.cc index d7891f42..b6533ed5 100644 --- a/src/main.cc +++ b/src/main.cc @@ -181,7 +181,7 @@ void showUsage() { " system but its corresponding .aria2 file doesn't\n" " exist.\n" " Default: false") << endl; - cout << _(" --check-integiry=true|false Check file integiry by validating piece hash.\n" + cout << _(" --check-integriy=true|false Check file integriy by validating piece hash.\n" " This option makes effect in BitTorrent download\n" " and Metalink with chunk checksums.\n" " Use this option to redownload a damaged portion of\n"