2007-03-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

* 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.
pull/1/head
Tatsuhiro Tsujikawa 2007-03-05 12:31:57 +00:00
parent cc24f7cdf8
commit ba7f9f7657
9 changed files with 62 additions and 5 deletions

View File

@ -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;
}

View File

@ -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_

View File

@ -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 {

View File

@ -97,4 +97,6 @@ public:
int receiveResponse(HttpHeader& headers);
};
typedef SharedHandle<HttpConnection> HttpConnectionHandle;
#endif // _D_HTTP_CONNECTION_H_

View File

@ -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<string, string> rangePair;
Util::split(rangePair, rangeStr, '/');
pair<string, string> 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;
}

View File

@ -36,17 +36,17 @@
#define _D_HTTP_HEADER_H_
#include "common.h"
#include "Range.h"
#include <map>
#include <deque>
#include <string>
using namespace std;
class HttpHeader {
private:
int32_t status;
multimap<string, string> 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<HttpHeader> HttpHeaderHandle;
#endif // _D_HTTP_HEADER_H_

View File

@ -135,5 +135,6 @@ public:
typedef SharedHandle<Request> RequestHandle;
typedef deque<RequestHandle> Requests;
typedef WeakHandle<Request> RequestWeakHandle;
#endif // _D_REQUEST_H_

View File

@ -81,5 +81,7 @@ public:
ostream& operator<<(ostream& o, const Segment& segment);
typedef SharedHandle<Segment> SegmentHandle;
#endif // _D_SEGMENT_H_

View File

@ -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"