Просмотр исходного кода

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.
Tatsuhiro Tsujikawa 18 лет назад
Родитель
Сommit
ba7f9f7657
9 измененных файлов с 62 добавлено и 5 удалено
  1. 15 0
      src/BitfieldMan.cc
  2. 2 0
      src/BitfieldMan.h
  3. 2 1
      src/HttpConnection.cc
  4. 2 0
      src/HttpConnection.h
  5. 20 0
      src/HttpHeader.cc
  6. 17 3
      src/HttpHeader.h
  7. 1 0
      src/Request.h
  8. 2 0
      src/Segment.h
  9. 1 1
      src/main.cc

+ 15 - 0
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;
+}

+ 2 - 0
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_

+ 2 - 1
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 {

+ 2 - 0
src/HttpConnection.h

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

+ 20 - 0
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<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;
+}

+ 17 - 3
src/HttpHeader.h

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

+ 1 - 0
src/Request.h

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

+ 2 - 0
src/Segment.h

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

+ 1 - 1
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"