فهرست منبع

2010-11-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Added .cc file for classes/structs that only provided by header
	file. Defined non-POD classes' ctor, dtor in .cc file.  Moved
	implementation code in header file to .cc file for major
	classes/strucsts.
Tatsuhiro Tsujikawa 15 سال پیش
والد
کامیت
1372ac51ad
100فایلهای تغییر یافته به همراه1688 افزوده شده و 674 حذف شده
  1. 7 0
      ChangeLog
  2. 34 5
      src/AbstractCommand.cc
  3. 16 29
      src/AbstractCommand.h
  4. 0 7
      src/AbstractProxyRequestCommand.cc
  5. 0 4
      src/AbstractProxyResponseCommand.cc
  6. 2 2
      src/AbstractSingleDiskAdaptor.cc
  7. 0 4
      src/ActivePeerConnectionCommand.cc
  8. 17 3
      src/AdaptiveFileAllocationIterator.cc
  9. 2 12
      src/AdaptiveFileAllocationIterator.h
  10. 82 0
      src/AlphaNumberDecorator.cc
  11. 6 37
      src/AlphaNumberDecorator.h
  12. 9 1
      src/AnnounceList.cc
  13. 7 4
      src/AnnounceList.h
  14. 79 0
      src/AnnounceTier.cc
  15. 12 33
      src/AnnounceTier.h
  16. 17 0
      src/AuthConfig.cc
  17. 7 8
      src/AuthConfig.h
  18. 4 6
      src/AutoSaveCommand.cc
  19. 31 1
      src/BitfieldMan.cc
  20. 7 25
      src/BitfieldMan.h
  21. 47 0
      src/BtAbortOutstandingRequestEvent.cc
  22. 4 3
      src/BtAbortOutstandingRequestEvent.h
  23. 3 1
      src/BtAnnounce.h
  24. 56 0
      src/BtBitfieldMessageValidator.cc
  25. 5 11
      src/BtBitfieldMessageValidator.h
  26. 0 3
      src/BtCheckIntegrityEntry.cc
  27. 1 0
      src/BtDependency.cc
  28. 2 0
      src/BtExtendedMessage.cc
  29. 1 0
      src/BtExtendedMessage.h
  30. 1 3
      src/BtFileAllocationEntry.cc
  31. 76 0
      src/BtHandshakeMessageValidator.cc
  32. 6 28
      src/BtHandshakeMessageValidator.h
  33. 2 0
      src/BtInterestedMessage.cc
  34. 1 0
      src/BtInterestedMessage.h
  35. 19 0
      src/BtLeecherStateChoke.cc
  36. 4 0
      src/BtLeecherStateChoke.h
  37. 2 0
      src/BtNotInterestedMessage.cc
  38. 1 0
      src/BtNotInterestedMessage.h
  39. 56 0
      src/BtPieceMessageValidator.cc
  40. 6 11
      src/BtPieceMessageValidator.h
  41. 51 0
      src/BtRegistry.cc
  42. 9 17
      src/BtRegistry.h
  43. 61 0
      src/BtRuntime.cc
  44. 5 20
      src/BtRuntime.h
  45. 23 0
      src/BtSeederStateChoke.cc
  46. 4 0
      src/BtSeederStateChoke.h
  47. 3 4
      src/BtSetup.cc
  48. 0 2
      src/BtStopDownloadCommand.cc
  49. 10 1
      src/ByteArrayDiskWriter.cc
  50. 3 9
      src/ByteArrayDiskWriter.h
  51. 51 0
      src/CUIDCounter.cc
  52. 4 12
      src/CUIDCounter.h
  53. 0 3
      src/CheckIntegrityCommand.cc
  54. 0 3
      src/CheckIntegrityDispatcherCommand.cc
  55. 0 3
      src/CheckIntegrityEntry.cc
  56. 65 0
      src/Checksum.cc
  57. 10 18
      src/Checksum.h
  58. 0 2
      src/ChecksumCheckIntegrityEntry.cc
  59. 91 0
      src/ChunkChecksum.cc
  60. 8 40
      src/ChunkChecksum.h
  61. 0 1
      src/Command.h
  62. 26 6
      src/ConsoleStatCalc.cc
  63. 4 21
      src/ConsoleStatCalc.h
  64. 4 0
      src/ContextAttribute.h
  65. 52 0
      src/Cookie.cc
  66. 8 16
      src/Cookie.h
  67. 32 2
      src/CookieStorage.cc
  68. 6 8
      src/CookieStorage.h
  69. 1 3
      src/CreateRequestCommand.cc
  70. 0 4
      src/DHTAutoSaveCommand.cc
  71. 0 4
      src/DHTBucketRefreshCommand.cc
  72. 3 7
      src/DHTEntryPointNameResolveCommand.cc
  73. 0 4
      src/DHTGetPeersCommand.cc
  74. 0 4
      src/DHTInteractionCommand.cc
  75. 7 0
      src/DHTMessageTrackerEntry.cc
  76. 3 4
      src/DHTMessageTrackerEntry.h
  77. 7 0
      src/DHTNode.cc
  78. 6 5
      src/DHTNode.h
  79. 0 4
      src/DHTPeerAnnounceCommand.cc
  80. 0 4
      src/DHTTokenUpdateCommand.cc
  81. 209 0
      src/DNSCache.cc
  82. 28 105
      src/DNSCache.h
  83. 2 0
      src/DiskAdaptor.cc
  84. 1 1
      src/DiskAdaptor.h
  85. 1 2
      src/DownloadCommand.cc
  86. 2 0
      src/DownloadCommand.h
  87. 43 0
      src/DownloadContext.cc
  88. 12 29
      src/DownloadContext.h
  89. 28 4
      src/DownloadEngine.cc
  90. 8 23
      src/DownloadEngine.h
  91. 46 0
      src/DownloadResult.cc
  92. 9 2
      src/DownloadResult.h
  93. 5 0
      src/Exception.cc
  94. 1 4
      src/Exception.h
  95. 78 0
      src/ExtensionMessageRegistry.cc
  96. 6 31
      src/ExtensionMessageRegistry.h
  97. 2 0
      src/FeatureConfig.cc
  98. 2 0
      src/FeatureConfig.h
  99. 11 1
      src/File.cc
  100. 5 0
      src/File.h

+ 7 - 0
ChangeLog

@@ -1,3 +1,10 @@
+2010-11-14  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Added .cc file for classes/structs that only provided by header
+	file. Defined non-POD classes' ctor, dtor in .cc file.  Moved
+	implementation code in header file to .cc file for major
+	classes/strucsts.
+
 2010-11-12  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Removed SharedHandle::isNull(). Instead we added operator* and

+ 34 - 5
src/AbstractCommand.cc

@@ -49,9 +49,6 @@
 #include "CreateRequestCommand.h"
 #include "InitiateConnectionCommandFactory.h"
 #include "SleepCommand.h"
-#ifdef ENABLE_ASYNC_DNS
-#include "AsyncNameResolver.h"
-#endif // ENABLE_ASYNC_DNS
 #include "StreamCheckIntegrityEntry.h"
 #include "PieceStorage.h"
 #include "Socket.h"
@@ -66,9 +63,11 @@
 #include "DownloadContext.h"
 #include "wallclock.h"
 #include "NameResolver.h"
-#include "ServerStatMan.h"
-#include "FileAllocationEntry.h"
 #include "uri.h"
+#include "FileEntry.h"
+#ifdef ENABLE_ASYNC_DNS
+#include "AsyncNameResolver.h"
+#endif // ENABLE_ASYNC_DNS
 #ifdef ENABLE_MESSAGE_DIGEST
 # include "ChecksumCheckIntegrityEntry.h"
 #endif // ENABLE_MESSAGE_DIGEST
@@ -861,4 +860,34 @@ size_t AbstractCommand::calculateMinSplitSize() const
   }
 }
 
+void AbstractCommand::setRequest(const SharedHandle<Request>& request)
+{
+  req_ = request;
+}
+
+void AbstractCommand::setFileEntry(const SharedHandle<FileEntry>& fileEntry)
+{
+  fileEntry_ = fileEntry;
+}
+
+void AbstractCommand::setSocket(const SharedHandle<SocketCore>& s)
+{
+  socket_ = s;
+}
+
+const SharedHandle<DownloadContext>& AbstractCommand::getDownloadContext() const
+{
+  return requestGroup_->getDownloadContext();
+}
+
+const SharedHandle<SegmentMan>& AbstractCommand::getSegmentMan() const
+{
+  return requestGroup_->getSegmentMan();
+}
+
+const SharedHandle<PieceStorage>& AbstractCommand::getPieceStorage() const
+{
+  return requestGroup_->getPieceStorage();
+}
+
 } // namespace aria2

+ 16 - 29
src/AbstractCommand.h

@@ -36,17 +36,24 @@
 #define D_ABSTRACT_COMMAND_H
 
 #include "Command.h"
+
+#include <vector>
+#include <string>
+
 #include "SharedHandle.h"
 #include "TimerA2.h"
-#include "FileEntry.h"
-#include "RequestGroup.h"
 
 namespace aria2 {
 
+class FileEntry;
+class RequestGroup;
+class CheckIntegrityEntry;
+class DownloadContext;
+class SegmentMan;
+class PieceStorage;
 class Request;
 class DownloadEngine;
 class Segment;
-class Exception;
 class SocketCore;
 class Option;
 #ifdef ENABLE_ASYNC_DNS
@@ -98,20 +105,14 @@ protected:
     return req_;
   }
 
-  void setRequest(const SharedHandle<Request>& request)
-  {
-    req_ = request;
-  }
+  void setRequest(const SharedHandle<Request>& request);
 
   const SharedHandle<FileEntry>& getFileEntry() const
   {
     return fileEntry_;
   }
 
-  void setFileEntry(const SharedHandle<FileEntry>& fileEntry)
-  {
-    fileEntry_ = fileEntry;
-  }
+  void setFileEntry(const SharedHandle<FileEntry>& fileEntry);
 
   DownloadEngine* getDownloadEngine() const
   {
@@ -123,10 +124,7 @@ protected:
     return socket_;
   }
 
-  void setSocket(const SharedHandle<SocketCore>& s)
-  {
-    socket_ = s;
-  }
+  void setSocket(const SharedHandle<SocketCore>& s);
 
   void createSocket();
 
@@ -213,20 +211,9 @@ protected:
 
   const SharedHandle<Option>& getOption() const;
 
-  const SharedHandle<DownloadContext>& getDownloadContext() const
-  {
-    return requestGroup_->getDownloadContext();
-  }
-
-  const SharedHandle<SegmentMan>& getSegmentMan() const
-  {
-    return requestGroup_->getSegmentMan();
-  }
-
-  const SharedHandle<PieceStorage>& getPieceStorage() const
-  {
-    return requestGroup_->getPieceStorage();
-  }
+  const SharedHandle<DownloadContext>& getDownloadContext() const;
+  const SharedHandle<SegmentMan>& getSegmentMan() const;
+  const SharedHandle<PieceStorage>& getPieceStorage() const;
 
   Timer& getCheckPoint()
   {

+ 0 - 7
src/AbstractProxyRequestCommand.cc

@@ -42,14 +42,7 @@
 #include "Option.h"
 #include "prefs.h"
 #include "Socket.h"
-#include "CookieStorage.h"
-#include "AuthConfigFactory.h"
-#include "AuthConfig.h"
 #include "DownloadContext.h"
-#include "RequestGroupMan.h"
-#include "ServerStatMan.h"
-#include "FileAllocationEntry.h"
-#include "CheckIntegrityEntry.h"
 
 namespace aria2 {
 

+ 0 - 4
src/AbstractProxyResponseCommand.cc

@@ -46,10 +46,6 @@
 #include "message.h"
 #include "HttpHeader.h"
 #include "DownloadContext.h"
-#include "RequestGroupMan.h"
-#include "FileAllocationEntry.h"
-#include "CheckIntegrityEntry.h"
-#include "ServerStatMan.h"
 
 namespace aria2 {
 

+ 2 - 2
src/AbstractSingleDiskAdaptor.cc

@@ -35,11 +35,11 @@
 #include "AbstractSingleDiskAdaptor.h"
 #include "File.h"
 #include "AdaptiveFileAllocationIterator.h"
+#include "DiskWriter.h"
+#include "FileEntry.h"
 #ifdef HAVE_SOME_FALLOCATE
 # include "FallocFileAllocationIterator.h"
 #endif // HAVE_SOME_FALLOCATE
-#include "DiskWriter.h"
-#include "FileEntry.h"
 
 namespace aria2 {
 

+ 0 - 4
src/ActivePeerConnectionCommand.cc

@@ -51,10 +51,6 @@
 #include "bittorrent_helper.h"
 #include "wallclock.h"
 #include "util.h"
-#include "RequestGroupMan.h"
-#include "FileAllocationEntry.h"
-#include "CheckIntegrityEntry.h"
-#include "ServerStatMan.h"
 
 namespace aria2 {
 

+ 17 - 3
src/AdaptiveFileAllocationIterator.cc

@@ -34,13 +34,13 @@
 /* copyright --> */
 #include "AdaptiveFileAllocationIterator.h"
 #include "BinaryStream.h"
-#ifdef HAVE_FALLOCATE
-# include "FallocFileAllocationIterator.h"
-#endif // HAVE_FALLOCATE
 #include "SingleFileAllocationIterator.h"
 #include "RecoverableException.h"
 #include "LogFactory.h"
 #include "Logger.h"
+#ifdef HAVE_FALLOCATE
+# include "FallocFileAllocationIterator.h"
+#endif // HAVE_FALLOCATE
 
 namespace aria2 {
 
@@ -99,4 +99,18 @@ bool AdaptiveFileAllocationIterator::finished()
   }
 }
 
+off_t AdaptiveFileAllocationIterator::getCurrentLength()
+{
+  if(!allocator_) {
+    return offset_;
+  } else {
+    return allocator_->getCurrentLength();
+  }
+}
+
+uint64_t AdaptiveFileAllocationIterator::getTotalLength()
+{
+  return totalLength_;
+}
+
 } // namespace aria2

+ 2 - 12
src/AdaptiveFileAllocationIterator.h

@@ -64,19 +64,9 @@ public:
   
   virtual bool finished();
 
-  virtual off_t getCurrentLength()
-  {
-    if(!allocator_) {
-      return offset_;
-    } else {
-      return allocator_->getCurrentLength();
-    }
-  }
+  virtual off_t getCurrentLength();
 
-  virtual uint64_t getTotalLength()
-  {
-    return totalLength_;
-  }
+  virtual uint64_t getTotalLength();
 };
 
 } // namespace aria2

+ 82 - 0
src/AlphaNumberDecorator.cc

@@ -0,0 +1,82 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#include "AlphaNumberDecorator.h"
+
+#include <algorithm>
+
+namespace aria2 {
+
+namespace {
+std::string widen(const std::string& s, size_t width, char zeroChar)
+{
+  std::string t = s;
+  std::string zero(1, zeroChar);
+  while(t.size() < width) {
+    t.insert(0, zero);
+  }
+  return t;
+}
+} // namespace
+
+AlphaNumberDecorator::AlphaNumberDecorator(size_t width, bool uppercase)
+  : width_(width),
+    zero_(uppercase?'A':'a')
+{}
+
+AlphaNumberDecorator::~AlphaNumberDecorator() {}
+
+std::string AlphaNumberDecorator::decorate(unsigned int number)
+{
+  if(number == 0) {
+    return widen(std::string(1, zero_), width_, zero_);
+  }
+
+  int base = 26;
+  char u[14]; // because if unsigned int is 64bit, which is the
+              // biggest integer for the time being and number is
+              // UINT64_MAX, you get "HLHXCZMXSYUMQP"
+  size_t index = 0;
+  do {
+    unsigned int quot = number/base;
+    unsigned int rem = number%base;
+    u[index++] = zero_+rem;
+    number = quot;
+  } while(number);
+  std::reverse(&u[0], &u[index]);
+
+  return widen(std::string(&u[0], &u[index]), width_, zero_);
+}
+
+} // namespace aria2

+ 6 - 37
src/AlphaNumberDecorator.h

@@ -36,54 +36,23 @@
 #define D_ALPHA_NUMBER_DECORATOR_H
 
 #include "NumberDecorator.h"
-#include "DlAbortEx.h"
-#include <algorithm>
 
 namespace aria2 {
 
 class AlphaNumberDecorator : public NumberDecorator
 {
 private:
-
   size_t width_;
-
   char zero_;
-
-  std::string widen(const std::string& s, size_t width)
-  {
-    std::string t = s;
-    std::string zero(1, zero_);
-    while(t.size() < width) {
-      t.insert(0, zero);
-    }
-    return t;
-  }
-
 public:
-  AlphaNumberDecorator(size_t width, bool uppercase = false):
-    width_(width), zero_(uppercase?'A':'a') {}
-
-  virtual ~AlphaNumberDecorator() {}
-
-  virtual std::string decorate(unsigned int number)
-  {
-    if(number == 0) {
-      return widen(std::string(1, zero_), width_);
-    }
+  AlphaNumberDecorator(size_t width, bool uppercase = false);
+  virtual ~AlphaNumberDecorator();
 
-    int base = 26;
-    char u[14]; // because if unsigned int is 64bit, which is the biggest integer for the time being and number is UINT64_MAX, you get "HLHXCZMXSYUMQP"
-    size_t index = 0;
-    do {
-      unsigned int quot = number/base;
-      unsigned int rem = number%base;
-      u[index++] = zero_+rem;
-      number = quot;
-    } while(number);
-    std::reverse(&u[0], &u[index]);
+  // Don't allow copying
+  AlphaNumberDecorator(const AlphaNumberDecorator& c);
+  AlphaNumberDecorator& operator=(const AlphaNumberDecorator& c);
 
-    return widen(std::string(&u[0], &u[index]), width_);
-  }
+  virtual std::string decorate(unsigned int number);
 };
 
 } // namespace aria2

+ 9 - 1
src/AnnounceList.cc

@@ -38,7 +38,6 @@
 
 #include "A2STR.h"
 #include "SimpleRandomizer.h"
-#include "util.h"
 #include "a2algo.h"
 
 namespace aria2 {
@@ -49,6 +48,8 @@ const std::string AnnounceList::STOPPED("stopped");
 
 const std::string AnnounceList::COMPLETED("completed");
 
+AnnounceList::AnnounceList():currentTrackerInitialized_(false) {}
+
 AnnounceList::AnnounceList
 (const std::vector<std::vector<std::string> >& announceList):
   currentTrackerInitialized_(false) {
@@ -61,6 +62,8 @@ AnnounceList::AnnounceList
   resetIterator();
 }
 
+AnnounceList::~AnnounceList() {}
+
 void AnnounceList::reconfigure
 (const std::vector<std::vector<std::string> >& announceList)
 {
@@ -262,4 +265,9 @@ bool AnnounceList::currentTierAcceptsCompletedEvent() const
   }
 }
 
+size_t AnnounceList::countTier() const
+{
+  return tiers_.size();
+}
+
 } // namespace aria2

+ 7 - 4
src/AnnounceList.h

@@ -54,16 +54,19 @@ private:
   void setCurrentTier
   (const std::deque<SharedHandle<AnnounceTier> >::iterator& itr);
 public:
-  AnnounceList():currentTrackerInitialized_(false) {}
+  AnnounceList();
   AnnounceList(const std::vector<std::vector<std::string> >& announceList);
   AnnounceList(const std::deque<SharedHandle<AnnounceTier> >& tiers);
+  ~AnnounceList();
+
+  // Don't allow copying
+  AnnounceList(const AnnounceList&);
+  AnnounceList& operator=(const AnnounceList&);
 
   void reconfigure(const std::vector<std::vector<std::string> >& announceList);
   void reconfigure(const std::string& url);
 
-  size_t countTier() const {
-    return tiers_.size();
-  }
+  size_t countTier() const;
 
   /**
    * Shuffles all the URLs in each group.

+ 79 - 0
src/AnnounceTier.cc

@@ -0,0 +1,79 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#include "AnnounceTier.h"
+
+namespace aria2 {
+
+AnnounceTier::AnnounceTier(const std::deque<std::string>& urls)
+  : event(STARTED), urls(urls)
+{}
+
+AnnounceTier::~AnnounceTier() {}
+
+void AnnounceTier::nextEvent()
+{
+  switch(event) {
+  case STARTED:
+    event = DOWNLOADING;
+    break;
+  case STARTED_AFTER_COMPLETION:
+    event = SEEDING;
+    break;
+  case STOPPED:
+    event = HALTED;
+    break;
+  case COMPLETED:
+    event = SEEDING;
+    break;
+  default:
+    break;
+  }
+}
+
+void AnnounceTier::nextEventIfAfterStarted()
+{
+  switch(event) {
+  case STOPPED:
+    event = HALTED;
+    break;
+  case COMPLETED:
+    event = SEEDING;
+    break;
+  default:
+    break;
+  }
+}
+
+} // namespace aria2

+ 12 - 33
src/AnnounceTier.h

@@ -36,10 +36,12 @@
 #define D_ANNOUNCE_TIER_H
 
 #include "common.h"
-#include "SharedHandle.h"
+
 #include <string>
 #include <deque>
 
+#include "SharedHandle.h"
+
 namespace aria2 {
 
 class AnnounceTier {
@@ -57,40 +59,17 @@ public:
   AnnounceEvent event;
   std::deque<std::string> urls;
 
-  AnnounceTier(const std::deque<std::string>& urls):event(STARTED), urls(urls) {}
+  AnnounceTier(const std::deque<std::string>& urls);
+
+  ~AnnounceTier();
+
+  // Don't allow copying
+  AnnounceTier(const AnnounceTier&);
+  AnnounceTier& operator=(const AnnounceTier&);
 
-  void nextEvent() {
-    switch(event) {
-    case STARTED:
-      event = DOWNLOADING;
-      break;
-    case STARTED_AFTER_COMPLETION:
-      event = SEEDING;
-      break;
-    case STOPPED:
-      event = HALTED;
-      break;
-    case COMPLETED:
-      event = SEEDING;
-      break;
-    default:
-      break;
-    }
-  }
+  void nextEvent();
 
-  void nextEventIfAfterStarted()
-  {
-    switch(event) {
-    case STOPPED:
-      event = HALTED;
-      break;
-    case COMPLETED:
-      event = SEEDING;
-      break;
-    default:
-      break;
-    }
-  }
+  void nextEventIfAfterStarted();
 };
 
 } // namespace aria2

+ 17 - 0
src/AuthConfig.cc

@@ -33,10 +33,27 @@
  */
 /* copyright --> */
 #include "AuthConfig.h"
+
 #include <ostream>
 
+#include "a2functional.h"
+
 namespace aria2 {
 
+AuthConfig::AuthConfig() {}
+
+AuthConfig::AuthConfig(const std::string& user, const std::string& password)
+    : user_(user),
+      password_(password)
+{}
+
+AuthConfig::~AuthConfig() {}
+
+std::string AuthConfig::getAuthText() const
+{
+  return strconcat(user_, ":", password_);
+}
+
 std::ostream& operator<<(std::ostream& o, const AuthConfigHandle& authConfig)
 {
   o << authConfig->getAuthText();

+ 7 - 8
src/AuthConfig.h

@@ -41,7 +41,6 @@
 #include <iosfwd>
 
 #include "SharedHandle.h"
-#include "a2functional.h"
 
 namespace aria2 {
 
@@ -51,15 +50,15 @@ private:
   std::string user_;
   std::string password_;
 public:
+  AuthConfig();
+  AuthConfig(const std::string& user, const std::string& password);
+  ~AuthConfig();
 
-  AuthConfig() {}
-  AuthConfig(const std::string& user, const std::string& password):
-    user_(user), password_(password) {}
+  // Don't allow copying
+  AuthConfig(const AuthConfig&);
+  AuthConfig& operator=(const AuthConfig&);
 
-  std::string getAuthText() const
-  {
-    return strconcat(user_, ":", password_);
-  }
+  std::string getAuthText() const;
 
   const std::string& getUser() const
   {

+ 4 - 6
src/AutoSaveCommand.cc

@@ -35,15 +35,13 @@
 #include "AutoSaveCommand.h"
 #include "DownloadEngine.h"
 #include "RequestGroupMan.h"
-#include "FileEntry.h"
-#include "ServerStatMan.h"
-#include "FileAllocationEntry.h"
-#include "CheckIntegrityEntry.h"
 
 namespace aria2 {
 
-AutoSaveCommand::AutoSaveCommand(cuid_t cuid, DownloadEngine* e, time_t interval):
-  TimeBasedCommand(cuid, e, interval, true) {}
+AutoSaveCommand::AutoSaveCommand
+(cuid_t cuid, DownloadEngine* e, time_t interval)
+  : TimeBasedCommand(cuid, e, interval, true)
+{}
 
 AutoSaveCommand::~AutoSaveCommand() {}
 

+ 31 - 1
src/BitfieldMan.cc

@@ -37,7 +37,6 @@
 #include <cassert>
 #include <cstring>
 
-#include "util.h"
 #include "array_fun.h"
 #include "bitfield.h"
 
@@ -131,6 +130,11 @@ BitfieldMan::~BitfieldMan() {
   delete [] filterBitfield_;
 }
 
+size_t BitfieldMan::getLastBlockLength() const
+{
+  return totalLength_-blockLength_*(blocks_-1);
+}
+
 size_t BitfieldMan::getBlockLength(size_t index) const
 {
   if(index == blocks_-1) {
@@ -716,4 +720,30 @@ uint64_t BitfieldMan::getMissingUnusedLength(size_t startingIndex) const
   return length;
 }
 
+BitfieldMan::Range::Range(size_t startIndex, size_t endIndex)
+ :
+  startIndex(startIndex),
+  endIndex(endIndex)
+{}
+  
+size_t BitfieldMan::Range::getSize() const
+{
+  return endIndex-startIndex;
+}
+
+size_t BitfieldMan::Range::getMidIndex() const
+{
+  return (endIndex-startIndex)/2+startIndex;
+}
+
+bool BitfieldMan::Range::operator<(const Range& range) const
+{
+  return getSize() < range.getSize();
+}
+    
+bool BitfieldMan::Range::operator==(const Range& range) const
+{
+  return getSize() == range.getSize();
+}
+
 } // namespace aria2

+ 7 - 25
src/BitfieldMan.h

@@ -74,29 +74,14 @@ private:
   void ensureFilterBitfield();
 public:
   // [startIndex, endIndex)
-  class Range {
-  public:
+  struct Range {
     size_t startIndex;
     size_t endIndex;
-    Range(size_t startIndex = 0, size_t endIndex = 0):startIndex(startIndex),
-                                                      endIndex(endIndex) {}
-  
-    size_t getSize() const {
-      return endIndex-startIndex;
-    }
-
-    size_t getMidIndex() const {
-      return (endIndex-startIndex)/2+startIndex;
-    }
-
-    bool operator<(const Range& range) const {
-      return getSize() < range.getSize();
-    }
-    
-    bool operator==(const Range& range) const
-    {
-      return getSize() == range.getSize();
-    }
+    Range(size_t startIndex = 0, size_t endIndex = 0);
+    size_t getSize() const;
+    size_t getMidIndex() const;
+    bool operator<(const Range& range) const;    
+    bool operator==(const Range& range) const;
   };
 public:
   BitfieldMan(size_t blockLength, uint64_t totalLength);
@@ -110,10 +95,7 @@ public:
     return blockLength_;
   }
 
-  size_t getLastBlockLength() const
-  {
-    return totalLength_-blockLength_*(blocks_-1);
-  }
+  size_t getLastBlockLength() const;
 
   size_t getBlockLength(size_t index) const;
 

+ 47 - 0
src/BtAbortOutstandingRequestEvent.cc

@@ -0,0 +1,47 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#include "BtAbortOutstandingRequestEvent.h"
+#include "Piece.h"
+
+namespace aria2 {
+
+BtAbortOutstandingRequestEvent::BtAbortOutstandingRequestEvent
+(const SharedHandle<Piece>& piece)
+  : piece_(piece)
+{}
+
+BtAbortOutstandingRequestEvent::~BtAbortOutstandingRequestEvent() {}
+
+} // namespace aria2

+ 4 - 3
src/BtAbortOutstandingRequestEvent.h

@@ -37,16 +37,17 @@
 
 #include "common.h"
 #include "SharedHandle.h"
-#include "Piece.h"
 
 namespace aria2 {
 
+class Piece;
+
 class BtAbortOutstandingRequestEvent {
 private:
   SharedHandle<Piece> piece_;
 public:
-  BtAbortOutstandingRequestEvent(const SharedHandle<Piece>& piece):
-    piece_(piece) {}
+  BtAbortOutstandingRequestEvent(const SharedHandle<Piece>& piece);
+  ~BtAbortOutstandingRequestEvent();
 
   const SharedHandle<Piece>& getPiece() const { return piece_; }
 };

+ 3 - 1
src/BtAnnounce.h

@@ -36,9 +36,11 @@
 #define D_BT_ANNOUNCE_H
 
 #include "common.h"
+
+#include <string>
+
 #include "SharedHandle.h"
 #include "a2time.h"
-#include <string>
 
 namespace aria2 {
 

+ 56 - 0
src/BtBitfieldMessageValidator.cc

@@ -0,0 +1,56 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#include "BtBitfieldMessageValidator.h"
+#include "BtBitfieldMessage.h"
+#include "bittorrent_helper.h"
+
+namespace aria2 {
+
+BtBitfieldMessageValidator::BtBitfieldMessageValidator
+(const BtBitfieldMessage* message, size_t numPiece)
+  : message_(message),
+    numPiece_(numPiece)
+{}
+
+BtBitfieldMessageValidator::~BtBitfieldMessageValidator() {}
+
+void BtBitfieldMessageValidator::validate()
+{
+  bittorrent::checkBitfield(message_->getBitfield(),
+                            message_->getBitfieldLength(),
+                            numPiece_);
+}
+
+} // namespace aria2

+ 5 - 11
src/BtBitfieldMessageValidator.h

@@ -36,27 +36,21 @@
 #define D_BT_BITFIELD_MESSAGE_VALIDATOR_H
 
 #include "BtMessageValidator.h"
-#include "BtBitfieldMessage.h"
-#include "bittorrent_helper.h"
 
 namespace aria2 {
 
+class BtBitfieldMessage;
+
 class BtBitfieldMessageValidator : public BtMessageValidator {
 private:
   const BtBitfieldMessage* message_;
   size_t numPiece_;
 public:
   BtBitfieldMessageValidator(const BtBitfieldMessage* message,
-                             size_t numPiece):
-    message_(message),
-    numPiece_(numPiece) {}
+                             size_t numPiece);
+  ~BtBitfieldMessageValidator();
 
-  virtual void validate()
-  {
-    bittorrent::checkBitfield(message_->getBitfield(),
-                              message_->getBitfieldLength(),
-                              numPiece_);
-  }
+  virtual void validate();
 };
 
 typedef SharedHandle<BtBitfieldMessageValidator> BtBitfieldMessageValidatorHandle;

+ 0 - 3
src/BtCheckIntegrityEntry.cc

@@ -40,9 +40,6 @@
 #include "DiskAdaptor.h"
 #include "prefs.h"
 #include "Option.h"
-#include "DownloadContext.h"
-#include "RequestGroupMan.h"
-#include "ServerStatMan.h"
 
 namespace aria2 {
 

+ 1 - 0
src/BtDependency.cc

@@ -48,6 +48,7 @@
 #include "bittorrent_helper.h"
 #include "DlAbortEx.h"
 #include "StringFormat.h"
+#include "FileEntry.h"
 
 namespace aria2 {
 

+ 2 - 0
src/BtExtendedMessage.cc

@@ -58,6 +58,8 @@ BtExtendedMessage::BtExtendedMessage
   msgLength_(0)
 {}
 
+BtExtendedMessage::~BtExtendedMessage() {}
+
 unsigned char* BtExtendedMessage::createMessage()
 {
   /**

+ 1 - 0
src/BtExtendedMessage.h

@@ -53,6 +53,7 @@ private:
 public:
   BtExtendedMessage(const SharedHandle<ExtensionMessage>& extensionMessage =
                     SharedHandle<ExtensionMessage>());
+  virtual ~BtExtendedMessage();
 
   static const uint8_t ID = 20;
 

+ 1 - 3
src/BtFileAllocationEntry.cc

@@ -41,9 +41,7 @@
 #include "Command.h"
 #include "DownloadEngine.h"
 #include "DownloadContext.h"
-#include "RequestGroupMan.h"
-#include "CheckIntegrityEntry.h"
-#include "ServerStatMan.h"
+#include "FileEntry.h"
 
 namespace aria2 {
 

+ 76 - 0
src/BtHandshakeMessageValidator.cc

@@ -0,0 +1,76 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#include "BtHandshakeMessageValidator.h"
+
+#include <cstring>
+
+#include "BtHandshakeMessage.h"
+#include "util.h"
+#include "StringFormat.h"
+#include "DlAbortEx.h"
+
+namespace aria2 {
+
+BtHandshakeMessageValidator::BtHandshakeMessageValidator
+(const BtHandshakeMessage* message, const unsigned char* infoHash)
+  : message_(message)
+{
+  memcpy(infoHash_, infoHash, sizeof(infoHash_));
+}
+
+BtHandshakeMessageValidator::~BtHandshakeMessageValidator() {}
+
+void BtHandshakeMessageValidator::validate()
+{
+  if(message_->getPstrlen() != 19) {
+    throw DL_ABORT_EX(StringFormat("invalid handshake pstrlen=%u",
+                                   message_->getPstrlen()).str());
+  }
+  if(memcmp(BtHandshakeMessage::BT_PSTR, message_->getPstr(), 19) != 0) {
+    throw DL_ABORT_EX
+      (StringFormat("invalid handshake pstr=%s",
+                    util::percentEncode
+                    (message_->getPstr(), 19).c_str()).str());
+  }
+  if(memcmp(infoHash_, message_->getInfoHash(), sizeof(infoHash_)) != 0) {
+    throw DL_ABORT_EX
+      (StringFormat("invalid handshake info hash: expected:%s, actual:%s",
+                    util::toHex(infoHash_, sizeof(infoHash_)).c_str(),
+                    util::toHex(message_->getInfoHash(),
+                                INFO_HASH_LENGTH).c_str()).str());
+  }
+}
+
+} // namespace aria2

+ 6 - 28
src/BtHandshakeMessageValidator.h

@@ -39,45 +39,23 @@
 
 #include <cstring>
 
-#include "BtHandshakeMessage.h"
-#include "util.h"
-#include "StringFormat.h"
 #include "BtConstants.h"
 
 namespace aria2 {
 
+class BtHandshakeMessage;
+
 class BtHandshakeMessageValidator : public BtMessageValidator {
 private:
   const BtHandshakeMessage* message_;
   unsigned char infoHash_[INFO_HASH_LENGTH];
 public:
   BtHandshakeMessageValidator(const BtHandshakeMessage* message,
-                              const unsigned char* infoHash):
-    message_(message)
-  {
-    memcpy(infoHash_, infoHash, sizeof(infoHash_));
-  }
+                              const unsigned char* infoHash);
+
+  ~BtHandshakeMessageValidator();
 
-  virtual void validate()
-  {
-    if(message_->getPstrlen() != 19) {
-      throw DL_ABORT_EX(StringFormat("invalid handshake pstrlen=%u",
-                                     message_->getPstrlen()).str());
-    }
-    if(memcmp(BtHandshakeMessage::BT_PSTR, message_->getPstr(), 19) != 0) {
-      throw DL_ABORT_EX
-        (StringFormat("invalid handshake pstr=%s",
-                      util::percentEncode
-                      (message_->getPstr(), 19).c_str()).str());
-    }
-    if(memcmp(infoHash_, message_->getInfoHash(), sizeof(infoHash_)) != 0) {
-      throw DL_ABORT_EX
-        (StringFormat("invalid handshake info hash: expected:%s, actual:%s",
-                      util::toHex(infoHash_, sizeof(infoHash_)).c_str(),
-                      util::toHex(message_->getInfoHash(),
-                                  INFO_HASH_LENGTH).c_str()).str());
-    }
-  }
+  virtual void validate();
 };
 
 typedef SharedHandle<BtHandshakeMessageValidator> BtHandshakeMessageValidatorHandle;

+ 2 - 0
src/BtInterestedMessage.cc

@@ -42,6 +42,8 @@ const std::string BtInterestedMessage::NAME("interested");
 
 BtInterestedMessage::BtInterestedMessage():ZeroBtMessage(ID, NAME) {}
 
+BtInterestedMessage::~BtInterestedMessage() {}
+
 SharedHandle<BtInterestedMessage> BtInterestedMessage::create
 (const unsigned char* data, size_t dataLength)
 {

+ 1 - 0
src/BtInterestedMessage.h

@@ -49,6 +49,7 @@ private:
   SharedHandle<PeerStorage> peerStorage_;
 public:
   BtInterestedMessage();
+  virtual ~BtInterestedMessage();
 
   static const uint8_t ID = 2;
 

+ 19 - 0
src/BtLeecherStateChoke.cc

@@ -58,6 +58,25 @@ BtLeecherStateChoke::PeerEntry::PeerEntry(const SharedHandle<Peer>& peer):
   (peer->peerInterested() &&
    peer->getLastDownloadUpdate().difference(global::wallclock) < 30) {}
 
+BtLeecherStateChoke::PeerEntry::PeerEntry(const PeerEntry& c)
+  : peer_(c.peer_),
+    downloadSpeed_(c.downloadSpeed_),
+    regularUnchoker_(c.regularUnchoker_)
+{}
+
+BtLeecherStateChoke::PeerEntry& BtLeecherStateChoke::PeerEntry::operator=
+(const PeerEntry& c)
+{
+  if(this != &c) {
+    peer_ = c.peer_;
+    downloadSpeed_ = c.downloadSpeed_;
+    regularUnchoker_ = c.regularUnchoker_;
+  }
+  return *this;
+}
+
+BtLeecherStateChoke::PeerEntry::~PeerEntry() {}
+
 const SharedHandle<Peer>& BtLeecherStateChoke::PeerEntry::getPeer() const
 {
   return peer_;

+ 4 - 0
src/BtLeecherStateChoke.h

@@ -62,6 +62,10 @@ private:
     bool regularUnchoker_;
   public:
     PeerEntry(const SharedHandle<Peer>& peer);
+    PeerEntry(const PeerEntry& c);
+    ~PeerEntry();
+
+    PeerEntry& operator=(const PeerEntry& c);
 
     bool operator<(const PeerEntry& rhs) const;
 

+ 2 - 0
src/BtNotInterestedMessage.cc

@@ -42,6 +42,8 @@ const std::string BtNotInterestedMessage::NAME("not interested");
 
 BtNotInterestedMessage::BtNotInterestedMessage():ZeroBtMessage(ID, NAME) {}
 
+BtNotInterestedMessage::~BtNotInterestedMessage() {}
+
 SharedHandle<BtNotInterestedMessage> BtNotInterestedMessage::create
 (const unsigned char* data, size_t dataLength)
 {

+ 1 - 0
src/BtNotInterestedMessage.h

@@ -49,6 +49,7 @@ private:
   SharedHandle<PeerStorage> peerStorage_;
 public:
   BtNotInterestedMessage();
+  virtual ~BtNotInterestedMessage();
 
   static const uint8_t ID = 3;
 

+ 56 - 0
src/BtPieceMessageValidator.cc

@@ -0,0 +1,56 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#include "BtPieceMessageValidator.h"
+#include "BtPieceMessage.h"
+#include "bittorrent_helper.h"
+
+namespace aria2 {
+
+BtPieceMessageValidator::BtPieceMessageValidator
+(const BtPieceMessage* message, size_t numPiece, size_t pieceLength)
+  : message_(message),
+    numPiece_(numPiece),
+    pieceLength_(pieceLength)
+{}
+
+BtPieceMessageValidator::~BtPieceMessageValidator() {}
+
+void BtPieceMessageValidator::validate()
+{
+  bittorrent::checkIndex(message_->getIndex(), numPiece_);
+  bittorrent::checkBegin(message_->getBegin(), pieceLength_);
+}
+
+} // namespace aria2

+ 6 - 11
src/BtPieceMessageValidator.h

@@ -36,11 +36,11 @@
 #define D_BT_PIECE_MESSAGE_VALIDATOR_H
 
 #include "BtMessageValidator.h"
-#include "BtPieceMessage.h"
-#include "bittorrent_helper.h"
 
 namespace aria2 {
 
+class BtPieceMessage;
+
 class BtPieceMessageValidator : public BtMessageValidator {
 private:
   const BtPieceMessage* message_;
@@ -49,16 +49,11 @@ private:
 public:
   BtPieceMessageValidator(const BtPieceMessage* message,
                           size_t numPiece,
-                          size_t pieceLength):
-    message_(message),
-    numPiece_(numPiece),
-    pieceLength_(pieceLength) {}
+                          size_t pieceLength);
+
+  ~BtPieceMessageValidator();
 
-  virtual void validate()
-  {
-    bittorrent::checkIndex(message_->getIndex(), numPiece_);
-    bittorrent::checkBegin(message_->getBegin(), pieceLength_);
-  }
+  virtual void validate();
 };
 
 typedef SharedHandle<BtPieceMessageValidator> BtPieceMessageValidatorHandle;

+ 51 - 0
src/BtRegistry.cc

@@ -89,4 +89,55 @@ void BtRegistry::removeAll() {
   pool_.clear();
 }
 
+BtObject::BtObject
+(const SharedHandle<DownloadContext>& downloadContext,
+ const SharedHandle<PieceStorage>& pieceStorage,
+ const SharedHandle<PeerStorage>& peerStorage,
+ const SharedHandle<BtAnnounce>& btAnnounce,
+ const SharedHandle<BtRuntime>& btRuntime,
+ const SharedHandle<BtProgressInfoFile>& btProgressInfoFile)
+  : downloadContext_(downloadContext),
+    pieceStorage_(pieceStorage),
+    peerStorage_(peerStorage),
+    btAnnounce_(btAnnounce),
+    btRuntime_(btRuntime),
+    btProgressInfoFile_(btProgressInfoFile)
+{}
+
+BtObject::BtObject() {}
+
+BtObject::BtObject(const BtObject& c)
+  : downloadContext_(c.downloadContext_),
+    pieceStorage_(c.pieceStorage_),
+    peerStorage_(c.peerStorage_),
+    btAnnounce_(c.btAnnounce_),
+    btRuntime_(c.btRuntime_),
+    btProgressInfoFile_(c.btProgressInfoFile_)
+{}
+
+BtObject::~BtObject() {}
+
+BtObject& BtObject::operator=(const BtObject& c)
+{
+  if(this != &c) {
+    downloadContext_ = c.downloadContext_;
+    pieceStorage_ = c.pieceStorage_;
+    peerStorage_ = c.peerStorage_;
+    btAnnounce_ = c.btAnnounce_;
+    btRuntime_ = c.btRuntime_;
+    btProgressInfoFile_ = c.btProgressInfoFile_;
+  }
+  return *this;
+}
+
+bool BtObject::isNull() const
+{
+  return !downloadContext_ &&
+    !pieceStorage_ &&
+    !peerStorage_ &&
+    !btAnnounce_ &&
+    !btRuntime_ &&
+    !btProgressInfoFile_;
+}
+
 } // namespace aria2

+ 9 - 17
src/BtRegistry.h

@@ -64,25 +64,17 @@ struct BtObject {
            const SharedHandle<PeerStorage>& peerStorage,
            const SharedHandle<BtAnnounce>& btAnnounce,
            const SharedHandle<BtRuntime>& btRuntime,
-           const SharedHandle<BtProgressInfoFile>& btProgressInfoFile):
-    downloadContext_(downloadContext),
-    pieceStorage_(pieceStorage),
-    peerStorage_(peerStorage),
-    btAnnounce_(btAnnounce),
-    btRuntime_(btRuntime),
-    btProgressInfoFile_(btProgressInfoFile) {}
+           const SharedHandle<BtProgressInfoFile>& btProgressInfoFile);
 
-  BtObject() {}
+  BtObject();
 
-  bool isNull() const
-  {
-    return !downloadContext_ &&
-      !pieceStorage_ &&
-      !peerStorage_ &&
-      !btAnnounce_ &&
-      !btRuntime_ &&
-      !btProgressInfoFile_;
-  }
+  BtObject(const BtObject& c);
+
+  ~BtObject();
+
+  BtObject& operator=(const BtObject& c);
+
+  bool isNull() const;
 };
 
 class BtRegistry {

+ 61 - 0
src/BtRuntime.cc

@@ -0,0 +1,61 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#include "BtRuntime.h"
+#include "BtConstants.h"
+
+namespace aria2 {
+
+BtRuntime::BtRuntime()
+  : uploadLengthAtStartup_(0),
+    port_(0),
+    halt_(false),
+    connections_(0),
+    ready_(false),
+    maxPeers_(DEFAULT_MAX_PEERS),
+    minPeers_(DEFAULT_MIN_PEERS)
+{}
+
+BtRuntime::~BtRuntime() {}
+
+void BtRuntime::setMaxPeers(unsigned int maxPeers)
+{
+  maxPeers_ = maxPeers;
+  minPeers_ = static_cast<unsigned int>(maxPeers*0.8);
+  if(minPeers_ == 0 && maxPeers != 0) {
+    minPeers_ = maxPeers;
+  }
+}
+
+} // namespace aria2

+ 5 - 20
src/BtRuntime.h

@@ -36,7 +36,7 @@
 #define D_BT_RUNTIME_H
 
 #include "common.h"
-#include "BtConstants.h"
+#include "SharedHandle.h"
 
 namespace aria2 {
 
@@ -57,17 +57,9 @@ private:
   static const unsigned int DEFAULT_MIN_PEERS = 40;
 
 public:
-  BtRuntime():
-    uploadLengthAtStartup_(0),
-    port_(0),
-    halt_(false),
-    connections_(0),
-    ready_(false),
-    maxPeers_(DEFAULT_MAX_PEERS),
-    minPeers_(DEFAULT_MIN_PEERS)
-  {}
-
-  ~BtRuntime() {}
+  BtRuntime();
+
+  ~BtRuntime();
 
   uint64_t getUploadLengthAtStartup() const {
     return uploadLengthAtStartup_;
@@ -114,14 +106,7 @@ public:
 
   void setReady(bool go) { ready_ = go; }
 
-  void setMaxPeers(unsigned int maxPeers)
-  {
-    maxPeers_ = maxPeers;
-    minPeers_ = static_cast<unsigned int>(maxPeers*0.8);
-    if(minPeers_ == 0 && maxPeers != 0) {
-      minPeers_ = maxPeers;
-    }
-  }
+  void setMaxPeers(unsigned int maxPeers);
 
   unsigned int getMaxPeers() const
   {

+ 23 - 0
src/BtSeederStateChoke.cc

@@ -60,6 +60,29 @@ BtSeederStateChoke::PeerEntry::PeerEntry
   uploadSpeed_(peer->calculateUploadSpeed())
 {}
 
+BtSeederStateChoke::PeerEntry::PeerEntry(const PeerEntry& c)
+  : peer_(c.peer_),
+    outstandingUpload_(c.outstandingUpload_),
+    lastAmUnchoking_(c.lastAmUnchoking_),
+    recentUnchoking_(c.recentUnchoking_),
+    uploadSpeed_(c.uploadSpeed_)
+{}
+
+BtSeederStateChoke::PeerEntry::~PeerEntry() {}
+
+BtSeederStateChoke::PeerEntry& BtSeederStateChoke::PeerEntry::operator=
+(const PeerEntry& c)
+{
+  if(this != &c) {
+    peer_ = c.peer_;
+    outstandingUpload_ = c.outstandingUpload_;
+    lastAmUnchoking_ = c.lastAmUnchoking_;
+    recentUnchoking_ = c.recentUnchoking_;
+    uploadSpeed_ = c.uploadSpeed_;
+  }
+  return *this;
+}
+
 bool
 BtSeederStateChoke::PeerEntry::operator<(const PeerEntry& rhs) const
 {

+ 4 - 0
src/BtSeederStateChoke.h

@@ -66,6 +66,10 @@ private:
     const static time_t TIME_FRAME = 20;
   public:
     PeerEntry(const SharedHandle<Peer>& peer);
+    PeerEntry(const PeerEntry& c);
+    ~PeerEntry();
+
+    PeerEntry& operator=(const PeerEntry& c);
 
     bool operator<(const PeerEntry& rhs) const;
 

+ 3 - 4
src/BtSetup.cc

@@ -78,12 +78,11 @@
 #include "LpdMessageDispatcher.h"
 #include "message.h"
 #include "SocketCore.h"
-#include "RequestGroupMan.h"
-#include "FileAllocationEntry.h"
-#include "CheckIntegrityEntry.h"
-#include "ServerStatMan.h"
 #include "DlAbortEx.h"
 #include "array_fun.h"
+#include "DownloadContext.h"
+#include "PieceStorage.h"
+#include "PeerStorage.h"
 
 namespace aria2 {
 

+ 0 - 2
src/BtStopDownloadCommand.cc

@@ -36,8 +36,6 @@
 #include "PieceStorage.h"
 #include "RequestGroup.h"
 #include "BtRuntime.h"
-#include "Peer.h"
-#include "DownloadContext.h"
 #include "Logger.h"
 #include "wallclock.h"
 #include "util.h"

+ 10 - 1
src/ByteArrayDiskWriter.cc

@@ -33,7 +33,6 @@
  */
 /* copyright --> */
 #include "ByteArrayDiskWriter.h"
-#include "util.h"
 #include "A2STR.h"
 
 namespace aria2 {
@@ -90,4 +89,14 @@ uint64_t ByteArrayDiskWriter::size()
   return buf_.tellg();
 }
 
+void ByteArrayDiskWriter::setString(const std::string& s)
+{
+  buf_.str(s);
+}
+
+std::string ByteArrayDiskWriter::getString() const
+{
+  return buf_.str();
+}
+
 } // namespace aria2

+ 3 - 9
src/ByteArrayDiskWriter.h

@@ -66,15 +66,9 @@ public:
 
   virtual void disableDirectIO() {}
 
-  void setString(const std::string& s)
-  {
-    buf_.str(s);
-  }
-
-  std::string getString() const
-  {
-    return buf_.str();
-  }
+  void setString(const std::string& s);
+
+  std::string getString() const;
 };
 
 typedef SharedHandle<ByteArrayDiskWriter> ByteArrayDiskWriterHandle;

+ 51 - 0
src/CUIDCounter.cc

@@ -0,0 +1,51 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#include "CUIDCounter.h"
+
+namespace aria2 {
+
+CUIDCounter::CUIDCounter():count_(0) {}
+
+CUIDCounter::~CUIDCounter() {}
+
+cuid_t CUIDCounter::newID()
+{
+  if(count_ == INT64_MAX) {
+    count_ = 0;
+  }
+  return ++count_;
+}
+
+} // namespace aria2

+ 4 - 12
src/CUIDCounter.h

@@ -44,19 +44,11 @@ class CUIDCounter {
 private:
   cuid_t count_;
 public:
-  CUIDCounter():count_(0) {}
-
-  ~CUIDCounter() {}
-
-  cuid_t newID()
-  {
-    if(count_ == INT64_MAX) {
-      count_ = 0;
-    }
-    return ++count_;
-  }
+  CUIDCounter();
+  ~CUIDCounter();
+  cuid_t newID();
 };
 
-}
+} // namespace aria2
 
 #endif // D_CUID_COUNTER_H

+ 0 - 3
src/CheckIntegrityCommand.cc

@@ -43,9 +43,6 @@
 #include "a2functional.h"
 #include "RecoverableException.h"
 #include "util.h"
-#include "RequestGroupMan.h"
-#include "FileAllocationEntry.h"
-#include "ServerStatMan.h"
 
 namespace aria2 {
 

+ 0 - 3
src/CheckIntegrityDispatcherCommand.cc

@@ -37,10 +37,7 @@
 #include "CheckIntegrityCommand.h"
 #include "message.h"
 #include "Logger.h"
-#include "FileEntry.h"
 #include "util.h"
-#include "ServerStatMan.h"
-#include "FileAllocationEntry.h"
 
 namespace aria2 {
 

+ 0 - 3
src/CheckIntegrityEntry.cc

@@ -41,9 +41,6 @@
 #include "FileAllocationEntry.h"
 #include "DownloadEngine.h"
 #include "Option.h"
-#include "DownloadContext.h"
-#include "RequestGroupMan.h"
-#include "ServerStatMan.h"
 
 namespace aria2 {
 

+ 65 - 0
src/Checksum.cc

@@ -0,0 +1,65 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#include "Checksum.h"
+
+namespace aria2 {
+
+Checksum::Checksum(const std::string& algo, const std::string& messageDigest)
+    : algo_(algo),
+      messageDigest_(messageDigest)
+{}
+
+Checksum::Checksum()
+    : algo_("sha-1")
+{}
+
+Checksum::~Checksum() {}
+
+bool Checksum::isEmpty() const
+{
+  return messageDigest_.empty();
+}
+
+void Checksum::setMessageDigest(const std::string& md)
+{
+  messageDigest_ = md;
+}
+  
+void Checksum::setAlgo(const std::string& algo)
+{
+  algo_ = algo;
+}
+
+} // namespace aria2

+ 10 - 18
src/Checksum.h

@@ -47,29 +47,21 @@ private:
   std::string messageDigest_;
 public:
   // messageDigest_ is ascii hexadecimal notation.
-  Checksum(const std::string& algo, const std::string& messageDigest):
-    algo_(algo), messageDigest_(messageDigest) {}
-  Checksum():
-    algo_("sha-1") {}
+  Checksum(const std::string& algo, const std::string& messageDigest);
+  Checksum();
+  ~Checksum();
 
-  ~Checksum() {}
+  bool isEmpty() const;
 
-  bool isEmpty() const {
-    return messageDigest_.empty();
-  }
-
-  void setMessageDigest(const std::string& md) {
-    this->messageDigest_ = md;
-  }
-  const std::string& getMessageDigest() const {
+  void setMessageDigest(const std::string& md);
+  const std::string& getMessageDigest() const
+  {
     return messageDigest_;
   }
   
-  void setAlgo(const std::string& algo) {
-    this->algo_ = algo;
-  }
-
-  const std::string& getAlgo() const {
+  void setAlgo(const std::string& algo);
+  const std::string& getAlgo() const
+  {
     return algo_;
   }
 };

+ 0 - 2
src/ChecksumCheckIntegrityEntry.cc

@@ -39,9 +39,7 @@
 #include "IteratableChecksumValidator.h"
 #include "DownloadEngine.h"
 #include "PieceStorage.h"
-#include "RequestGroupMan.h"
 #include "FileAllocationEntry.h"
-#include "ServerStatMan.h"
 #include "StreamFileAllocationEntry.h"
 
 namespace aria2 {

+ 91 - 0
src/ChunkChecksum.cc

@@ -0,0 +1,91 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#include "ChunkChecksum.h"
+#include "A2STR.h"
+
+namespace aria2 {
+
+ChunkChecksum::ChunkChecksum():checksumLength_(0) {}
+
+ChunkChecksum::ChunkChecksum
+(const std::string& algo,
+ const std::vector<std::string>& checksums,
+ size_t checksumLength)
+    : algo_(algo),
+      checksums_(checksums),
+      checksumLength_(checksumLength)
+{}
+
+bool ChunkChecksum::validateChunk
+(const std::string& actualChecksum,
+ size_t checksumIndex) const
+{
+  if(checksumIndex < checksums_.size()) {
+    return actualChecksum == getChecksum(checksumIndex);
+  } else {
+    return false;
+  }
+}
+
+uint64_t ChunkChecksum::getEstimatedDataLength() const
+{
+  return static_cast<uint64_t>(checksumLength_)*checksums_.size();
+}
+
+size_t ChunkChecksum::countChecksum() const
+{
+  return checksums_.size();
+}
+
+const std::string& ChunkChecksum::getChecksum(size_t index) const
+{
+  if(index < checksums_.size()) {
+    return checksums_[index];
+  } else {
+    return A2STR::NIL;
+  }
+}
+
+void ChunkChecksum::setAlgo(const std::string& algo)
+{
+  algo_ = algo;
+}
+
+void ChunkChecksum::setChecksums(const std::vector<std::string>& mds)
+{
+  checksums_ = mds;
+}
+
+} // namespace aria2

+ 8 - 40
src/ChunkChecksum.h

@@ -41,7 +41,6 @@
 #include <vector>
 
 #include "SharedHandle.h"
-#include "A2STR.h"
 
 namespace aria2 {
 
@@ -51,44 +50,22 @@ private:
   std::vector<std::string> checksums_;
   size_t checksumLength_;
 public:
-  ChunkChecksum():checksumLength_(0) {}    
+  ChunkChecksum();
 
   ChunkChecksum(const std::string& algo,
                 const std::vector<std::string>& checksums,
-                size_t checksumLength):
-    algo_(algo),
-    checksums_(checksums),
-    checksumLength_(checksumLength) {}
+                size_t checksumLength);
 
   bool validateChunk(const std::string& actualChecksum,
-                     size_t checksumIndex) const
-  {
-    if(checksumIndex < checksums_.size()) {
-      return actualChecksum == getChecksum(checksumIndex);
-    } else {
-      return false;
-    }
-  }
+                     size_t checksumIndex) const;
 
-  uint64_t getEstimatedDataLength() const
-  {
-    return ((uint64_t)checksumLength_)*checksums_.size();
-  }
+  uint64_t getEstimatedDataLength() const;
 
-  size_t countChecksum() const
-  {
-    return checksums_.size();
-  }
+  size_t countChecksum() const;
 
-  const std::string& getChecksum(size_t index) const
-  {
-    if(index < checksums_.size()) {
-      return checksums_[index];
-    } else {
-      return A2STR::NIL;
-    }
-  }
+  const std::string& getChecksum(size_t index) const;
   
+  void setChecksums(const std::vector<std::string>& mds);
   const std::vector<std::string>& getChecksums() const
   {
     return checksums_;
@@ -99,25 +76,16 @@ public:
     return checksumLength_;
   }
 
+  void setAlgo(const std::string& algo);
   const std::string& getAlgo() const
   {
     return algo_;
   }
 
-  void setAlgo(const std::string& algo)
-  {
-    algo_ = algo;
-  }
-
   void setChecksumLength(size_t length)
   {
     checksumLength_ = length;
   }
-
-  void setChecksums(const std::vector<std::string>& mds)
-  {
-    checksums_ = mds;
-  }
 };
 
 } // namespace aria2

+ 0 - 1
src/Command.h

@@ -36,7 +36,6 @@
 #define D_COMMAND_H
 
 #include "common.h"
-#include <stdint.h>
 
 namespace aria2 {
 

+ 26 - 6
src/ConsoleStatCalc.cc

@@ -60,20 +60,40 @@
 #include "util.h"
 #include "DownloadContext.h"
 #include "wallclock.h"
-#include "ServerStatMan.h"
+#include "FileEntry.h"
 #ifdef ENABLE_BITTORRENT
 # include "bittorrent_helper.h"
-# include "Peer.h"
 # include "PeerStorage.h"
 # include "BtRegistry.h"
-# include "BtProgressInfoFile.h"
-# include "BtRuntime.h"
-# include "BtAnnounce.h"
-# include "PieceStorage.h"
 #endif // ENABLE_BITTORRENT
 
 namespace aria2 {
 
+std::string SizeFormatter::operator()(int64_t size) const
+{
+  return format(size);
+}
+
+namespace {
+class AbbrevSizeFormatter:public SizeFormatter {
+protected:
+  virtual std::string format(int64_t size) const
+  {
+    return util::abbrevSize(size);
+  }
+};
+} // namespace
+
+namespace {
+class PlainSizeFormatter:public SizeFormatter {
+protected:
+  virtual std::string format(int64_t size) const
+  {
+    return util::itos(size);
+  }
+};
+} // namespace
+
 namespace {
 void printProgress
 (std::ostream& o, const SharedHandle<RequestGroup>& rg, const DownloadEngine* e,

+ 4 - 21
src/ConsoleStatCalc.h

@@ -36,8 +36,10 @@
 #define D_CONSOLE_STAT_CALC_H
 
 #include "StatCalc.h"
+
+#include <string>
+
 #include "TimerA2.h"
-#include "util.h"
 
 namespace aria2 {
 
@@ -47,26 +49,7 @@ protected:
 public:
   virtual ~SizeFormatter() {}
 
-  std::string operator()(int64_t size) const
-  {
-    return format(size);
-  }
-};
-
-class AbbrevSizeFormatter:public SizeFormatter {
-protected:
-  virtual std::string format(int64_t size) const
-  {
-    return util::abbrevSize(size);
-  }
-};
-
-class PlainSizeFormatter:public SizeFormatter {
-protected:
-  virtual std::string format(int64_t size) const
-  {
-    return util::itos(size);
-  }
+  std::string operator()(int64_t size) const;
 };
 
 class ConsoleStatCalc:public StatCalc

+ 4 - 0
src/ContextAttribute.h

@@ -37,8 +37,12 @@
 
 #include "common.h"
 
+namespace aria2 {
+
 struct ContextAttribute {
   virtual ~ContextAttribute() {}
 };
 
+} // namespace aria2
+
 #endif // D_CONTEXT_ATTRIBUTE_H

+ 52 - 0
src/Cookie.cc

@@ -74,8 +74,40 @@ Cookie::Cookie():
   creationTime_(0),
   lastAccessTime_(0) {}
 
+Cookie::Cookie(const Cookie& c)
+  : name_(c.name_),
+    value_(c.value_),
+    expiryTime_(c.expiryTime_),
+    persistent_(c.persistent_),
+    domain_(c.domain_),
+    hostOnly_(c.hostOnly_),
+    path_(c.path_),
+    secure_(c.secure_),
+    httpOnly_(c.httpOnly_),
+    creationTime_(c.creationTime_),
+    lastAccessTime_(c.lastAccessTime_)
+{}
+
 Cookie::~Cookie() {}
 
+Cookie& Cookie::operator=(const Cookie& c)
+{
+  if(this != &c) {
+    name_ = c.name_;
+    value_ = c.value_;
+    expiryTime_ = c.expiryTime_;
+    persistent_ = c.persistent_;
+    domain_ = c.domain_;
+    hostOnly_ = c.hostOnly_;
+    path_ = c.path_;
+    secure_ = c.secure_;
+    httpOnly_ = c.httpOnly_;
+    creationTime_ = c.creationTime_;
+    lastAccessTime_ = c.lastAccessTime_;
+  }
+  return *this;
+}
+
 std::string Cookie::toString() const
 {
   return strconcat(name_, '=', value_);
@@ -139,4 +171,24 @@ std::string Cookie::toNsCookieFormat() const
   return ss.str();
 }
 
+void Cookie::setName(const std::string& name)
+{
+  name_ = name;
+}
+
+void Cookie::setValue(const std::string& value)
+{
+  value_ = value;
+}
+
+void Cookie::setDomain(const std::string& domain)
+{
+  domain_ = domain;
+}
+
+void Cookie::setPath(const std::string& path)
+{
+  path_ = path;
+}
+
 } // namespace aria2

+ 8 - 16
src/Cookie.h

@@ -74,8 +74,12 @@ public:
    bool httpOnly,
    time_t creationTime);
 
+  Cookie(const Cookie& c);
+
   ~Cookie();
 
+  Cookie& operator=(const Cookie& c);
+
   std::string toString() const;
 
   bool match
@@ -91,20 +95,14 @@ public:
     return name_;
   }
 
-  void setName(const std::string& name)
-  {
-    name_ = name;
-  }
+  void setName(const std::string& name);
 
   const std::string& getValue() const
   {
     return value_;
   }
 
-  void setValue(const std::string& value)
-  {
-    value_ = value;
-  }
+  void setValue(const std::string& value);
 
   time_t getExpiryTime() const
   {
@@ -131,10 +129,7 @@ public:
     return domain_;
   }
 
-  void setDomain(const std::string& domain)
-  {
-    domain_ = domain;
-  }
+  void setDomain(const std::string& domain);
 
   bool getHostOnly() const
   {
@@ -151,10 +146,7 @@ public:
     return path_;
   }
 
-  void setPath(const std::string& path)
-  {
-    path_ = path;
-  }
+  void setPath(const std::string& path);
 
   bool getSecure() const
   {

+ 32 - 2
src/CookieStorage.cc

@@ -55,11 +55,30 @@
 
 namespace aria2 {
 
+CookieStorage::DomainEntry::DomainEntry(const std::string& domain)
+ : key_(util::isNumericHost(domain)?domain:cookie::reverseDomainLevel(domain))
+{}
+
 CookieStorage::DomainEntry::DomainEntry
-(const std::string& domain):
-  key_(util::isNumericHost(domain)?domain:cookie::reverseDomainLevel(domain))
+(const DomainEntry& c)
+  : key_(c.key_),
+    lastAccessTime_(c.lastAccessTime_),
+    cookies_(c.cookies_)
 {}
 
+CookieStorage::DomainEntry::~DomainEntry() {}
+
+CookieStorage::DomainEntry& CookieStorage::DomainEntry::operator=
+(const DomainEntry& c)
+{
+  if(this != &c) {
+    key_ = c.key_;
+    lastAccessTime_ = c.lastAccessTime_;
+    cookies_ = c.cookies_;
+  }
+  return *this;
+}
+
 bool CookieStorage::DomainEntry::addCookie(const Cookie& cookie, time_t now)
 {
   setLastAccessTime(now);
@@ -109,6 +128,17 @@ void CookieStorage::DomainEntry::writeCookie(std::ostream& o) const
   }
 }
 
+size_t CookieStorage::DomainEntry::countCookie() const
+{
+  return cookies_.size();
+}
+
+
+bool CookieStorage::DomainEntry::operator<(const DomainEntry& de) const
+{
+  return key_ < de.key_;
+}
+
 CookieStorage::CookieStorage():logger_(LogFactory::getInstance()) {}
 
 CookieStorage::~CookieStorage() {}

+ 6 - 8
src/CookieStorage.h

@@ -66,6 +66,10 @@ public:
     std::deque<Cookie> cookies_;
   public:
     DomainEntry(const std::string& domain);
+    DomainEntry(const DomainEntry& c);
+    ~DomainEntry();
+
+    DomainEntry& operator=(const DomainEntry& c);
 
     const std::string& getKey() const
     {
@@ -89,10 +93,7 @@ public:
       return out;
     }
 
-    size_t countCookie() const
-    {
-      return cookies_.size();
-    }
+    size_t countCookie() const;
 
     bool addCookie(const Cookie& cookie, time_t now);
 
@@ -116,10 +117,7 @@ public:
       return std::copy(cookies_.begin(), cookies_.end(), out);
     }
 
-    bool operator<(const DomainEntry& de) const
-    {
-      return key_ < de.key_;
-    }
+    bool operator<(const DomainEntry& de) const;
   };
 private:
   std::deque<DomainEntry> domains_;

+ 1 - 3
src/CreateRequestCommand.cc

@@ -44,9 +44,7 @@
 #include "prefs.h"
 #include "Option.h"
 #include "RequestGroupMan.h"
-#include "FileAllocationEntry.h"
-#include "CheckIntegrityEntry.h"
-#include "ServerStatMan.h"
+#include "FileEntry.h"
 
 namespace aria2 {
 

+ 0 - 4
src/DHTAutoSaveCommand.cc

@@ -43,7 +43,6 @@
 #include "DHTRoutingTableSerializer.h"
 #include "RecoverableException.h"
 #include "DownloadEngine.h"
-#include "util.h"
 #include "DHTBucket.h"
 #include "RequestGroupMan.h"
 #include "prefs.h"
@@ -54,9 +53,6 @@
 #include "FileEntry.h"
 #include "DlAbortEx.h"
 #include "StringFormat.h"
-#include "ServerStatMan.h"
-#include "FileAllocationEntry.h"
-#include "CheckIntegrityEntry.h"
 
 namespace aria2 {
 

+ 0 - 4
src/DHTBucketRefreshCommand.cc

@@ -39,10 +39,6 @@
 #include "DHTTask.h"
 #include "DownloadEngine.h"
 #include "RequestGroupMan.h"
-#include "FileEntry.h"
-#include "ServerStatMan.h"
-#include "FileAllocationEntry.h"
-#include "CheckIntegrityEntry.h"
 
 namespace aria2 {
 

+ 3 - 7
src/DHTEntryPointNameResolveCommand.cc

@@ -34,9 +34,6 @@
 /* copyright --> */
 #include "DHTEntryPointNameResolveCommand.h"
 #include "DownloadEngine.h"
-#ifdef ENABLE_ASYNC_DNS
-#include "AsyncNameResolver.h"
-#endif // ENABLE_ASYNC_DNS
 #include "NameResolver.h"
 #include "DlAbortEx.h"
 #include "prefs.h"
@@ -51,10 +48,9 @@
 #include "RequestGroupMan.h"
 #include "Logger.h"
 #include "StringFormat.h"
-#include "FileEntry.h"
-#include "ServerStatMan.h"
-#include "FileAllocationEntry.h"
-#include "CheckIntegrityEntry.h"
+#ifdef ENABLE_ASYNC_DNS
+#include "AsyncNameResolver.h"
+#endif // ENABLE_ASYNC_DNS
 
 namespace aria2 {
 

+ 0 - 4
src/DHTGetPeersCommand.cc

@@ -47,10 +47,6 @@
 #include "bittorrent_helper.h"
 #include "DownloadContext.h"
 #include "wallclock.h"
-#include "RequestGroupMan.h"
-#include "FileAllocationEntry.h"
-#include "CheckIntegrityEntry.h"
-#include "ServerStatMan.h"
 
 namespace aria2 {
 

+ 0 - 4
src/DHTInteractionCommand.cc

@@ -45,10 +45,6 @@
 #include "Logger.h"
 #include "DHTMessageCallback.h"
 #include "DHTNode.h"
-#include "FileEntry.h"
-#include "ServerStatMan.h"
-#include "FileAllocationEntry.h"
-#include "CheckIntegrityEntry.h"
 
 namespace aria2 {
 

+ 7 - 0
src/DHTMessageTrackerEntry.cc

@@ -53,6 +53,8 @@ DHTMessageTrackerEntry::DHTMessageTrackerEntry(const SharedHandle<DHTMessage>& s
   timeout_(timeout)
 {}
 
+DHTMessageTrackerEntry::~DHTMessageTrackerEntry() {}
+
 bool DHTMessageTrackerEntry::isTimeout() const
 {
   return dispatchedTime_.difference(global::wallclock) >= timeout_;
@@ -77,4 +79,9 @@ bool DHTMessageTrackerEntry::match(const std::string& transactionID, const std::
   return false;
 }
 
+int64_t DHTMessageTrackerEntry::getElapsedMillis() const
+{
+  return dispatchedTime_.differenceInMillis(global::wallclock);
+}
+
 } // namespace aria2

+ 3 - 4
src/DHTMessageTrackerEntry.h

@@ -69,6 +69,8 @@ public:
                          const SharedHandle<DHTMessageCallback>& callback =
                          SharedHandle<DHTMessageCallback>());
 
+  ~DHTMessageTrackerEntry();
+
   bool isTimeout() const;
 
   void extendTimeout();
@@ -90,10 +92,7 @@ public:
     return callback_;
   }  
 
-  int64_t getElapsedMillis() const
-  {
-    return dispatchedTime_.differenceInMillis(global::wallclock);
-  }
+  int64_t getElapsedMillis() const;
 };
 
 } // namespace aria2

+ 7 - 0
src/DHTNode.cc

@@ -53,6 +53,8 @@ DHTNode::DHTNode(const unsigned char* id):port_(0), rtt_(0), condition_(1), last
   memcpy(id_, id, DHT_ID_LENGTH);
 }
 
+DHTNode::~DHTNode() {}
+
 void DHTNode::generateID()
 {
   util::generateRandomKey(id_);
@@ -126,4 +128,9 @@ void DHTNode::setID(const unsigned char* id)
   memcpy(id_, id, DHT_ID_LENGTH);
 }
 
+void DHTNode::setIPAddress(const std::string& ipaddr)
+{
+  ipaddr_ = ipaddr;
+}
+
 } // namespace aria2

+ 6 - 5
src/DHTNode.h

@@ -36,10 +36,12 @@
 #define D_DHT_NODE_H
 
 #include "common.h"
+
+#include <string>
+
 #include "SharedHandle.h"
 #include "DHTConstants.h"
 #include "TimerA2.h"
-#include <string>
 
 namespace aria2 {
 
@@ -65,6 +67,8 @@ public:
    */
   DHTNode(const unsigned char* id);
 
+  ~DHTNode();
+  
   void generateID();
 
   const unsigned char* getID() const
@@ -82,10 +86,7 @@ public:
     return ipaddr_;
   }
 
-  void setIPAddress(const std::string& ipaddr)
-  {
-    ipaddr_ = ipaddr;
-  }
+  void setIPAddress(const std::string& ipaddr);
 
   void setID(const unsigned char* id);
 

+ 0 - 4
src/DHTPeerAnnounceCommand.cc

@@ -39,10 +39,6 @@
 #include "RecoverableException.h"
 #include "message.h"
 #include "Logger.h"
-#include "FileEntry.h"
-#include "ServerStatMan.h"
-#include "FileAllocationEntry.h"
-#include "CheckIntegrityEntry.h"
 
 namespace aria2 {
 

+ 0 - 4
src/DHTTokenUpdateCommand.cc

@@ -39,10 +39,6 @@
 #include "RecoverableException.h"
 #include "message.h"
 #include "Logger.h"
-#include "FileEntry.h"
-#include "ServerStatMan.h"
-#include "FileAllocationEntry.h"
-#include "CheckIntegrityEntry.h"
 
 namespace aria2 {
 

+ 209 - 0
src/DNSCache.cc

@@ -0,0 +1,209 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#include "DNSCache.h"
+#include "A2STR.h"
+
+namespace aria2 {
+
+DNSCache::AddrEntry::AddrEntry(const std::string& addr)
+  : addr_(addr), good_(true)
+{}
+
+DNSCache::AddrEntry::AddrEntry(const AddrEntry& c)
+  : addr_(c.addr_), good_(c.good_)
+{}
+
+DNSCache::AddrEntry::~AddrEntry() {}
+
+DNSCache::AddrEntry& DNSCache::AddrEntry::operator=(const AddrEntry& c)
+{
+  if(this != &c) {
+    addr_ = c.addr_;
+    good_ = c.good_;
+  }
+  return *this;
+}
+
+DNSCache::CacheEntry::CacheEntry(const std::string& hostname, uint16_t port)
+  : hostname_(hostname), port_(port)
+{}
+
+DNSCache::CacheEntry::CacheEntry(const CacheEntry& c)
+  : hostname_(c.hostname_), port_(c.port_), addrEntries_(c.addrEntries_)
+{}
+
+DNSCache::CacheEntry::~CacheEntry() {}
+
+DNSCache::CacheEntry& DNSCache::CacheEntry::operator=(const CacheEntry& c)
+{
+  if(this != &c) {
+    hostname_ = c.hostname_;
+    port_ = c.port_;
+    addrEntries_ = c.addrEntries_;
+  }
+  return *this;
+}
+
+void DNSCache::CacheEntry::add(const std::string& addr)
+{
+  addrEntries_.push_back(AddrEntry(addr));
+}
+
+std::vector<DNSCache::AddrEntry>::iterator DNSCache::CacheEntry::find
+(const std::string& addr)
+{
+  for(std::vector<AddrEntry>::iterator i = addrEntries_.begin(),
+        eoi = addrEntries_.end(); i != eoi; ++i) {
+    if((*i).addr_ == addr) {
+      return i;
+    }
+  }
+  return addrEntries_.end();
+}
+
+std::vector<DNSCache::AddrEntry>::const_iterator DNSCache::CacheEntry::find
+(const std::string& addr) const
+{
+  for(std::vector<AddrEntry>::const_iterator i = addrEntries_.begin(),
+        eoi = addrEntries_.end(); i != eoi; ++i) {
+    if((*i).addr_ == addr) {
+      return i;
+    }
+  }
+  return addrEntries_.end();
+}
+
+bool DNSCache::CacheEntry::contains(const std::string& addr) const
+{
+  return find(addr) != addrEntries_.end();
+}
+
+const std::string& DNSCache::CacheEntry::getGoodAddr() const
+{
+  for(std::vector<AddrEntry>::const_iterator i = addrEntries_.begin(),
+        eoi = addrEntries_.end(); i != eoi; ++i) {
+    if((*i).good_) {
+      return (*i).addr_;
+    }
+  }
+  return A2STR::NIL;
+}
+
+void DNSCache::CacheEntry::markBad(const std::string& addr)
+{
+  std::vector<AddrEntry>::iterator i = find(addr);
+  if(i != addrEntries_.end()) {
+    (*i).good_ = false;
+  }
+}
+
+bool DNSCache::CacheEntry::operator<(const CacheEntry& e) const
+{
+  int r = hostname_.compare(e.hostname_);
+  if(r != 0) {
+    return r < 0;
+  }
+  return port_ < e.port_;
+}
+
+bool DNSCache::CacheEntry::operator==(const CacheEntry& e) const
+{
+  return hostname_ == e.hostname_ && port_ == e.port_;
+}
+
+DNSCache::DNSCache() {}
+
+DNSCache::DNSCache(const DNSCache& c):entries_(c.entries_) {}
+
+DNSCache::~DNSCache() {}
+
+DNSCache& DNSCache::operator=(const DNSCache& c)
+{
+  if(this != &c) {
+    entries_ = c.entries_;
+  }
+  return *this;
+}
+
+const std::string& DNSCache::find
+(const std::string& hostname, uint16_t port) const
+{
+  CacheEntry target(hostname, port);
+  std::deque<CacheEntry>::const_iterator i =
+    std::lower_bound(entries_.begin(), entries_.end(), target);
+  if(i != entries_.end() && (*i) == target) {
+    return (*i).getGoodAddr();
+  }
+  return A2STR::NIL;
+}
+
+void DNSCache::put
+(const std::string& hostname, const std::string& ipaddr, uint16_t port)
+{
+  CacheEntry target(hostname, port);
+  std::deque<CacheEntry>::iterator i =
+    std::lower_bound(entries_.begin(), entries_.end(), target);
+  if(i == entries_.end() || !((*i) == target)) {
+    target.add(ipaddr);
+    entries_.insert(i, target);
+  } else {
+    if(!(*i).contains(ipaddr)) {
+      (*i).add(ipaddr);
+    }
+  }
+}
+
+void DNSCache::markBad
+(const std::string& hostname, const std::string& ipaddr, uint16_t port)
+{
+  CacheEntry target(hostname, port);
+  std::deque<CacheEntry>::iterator i =
+    std::lower_bound(entries_.begin(), entries_.end(), target);
+  if(i != entries_.end() && (*i) == target) {
+    (*i).markBad(ipaddr);
+  }
+}
+
+void DNSCache::remove(const std::string& hostname, uint16_t port)
+{
+  CacheEntry target(hostname, port);
+  std::deque<CacheEntry>::iterator i =
+    std::lower_bound(entries_.begin(), entries_.end(), target);
+  if(i != entries_.end() && (*i) == target) {
+    entries_.erase(i);
+  }
+}
+
+} // namespace aria2

+ 28 - 105
src/DNSCache.h

@@ -42,8 +42,6 @@
 #include <algorithm>
 #include <vector>
 
-#include "A2STR.h"
-
 namespace aria2 {
 
 class DNSCache {
@@ -52,7 +50,11 @@ private:
     std::string addr_;
     bool good_;
 
-    AddrEntry(const std::string& addr):addr_(addr), good_(true) {}
+    AddrEntry(const std::string& addr);
+    AddrEntry(const AddrEntry& c);
+    ~AddrEntry();
+
+    AddrEntry& operator=(const AddrEntry& c);
   };
 
   struct CacheEntry {
@@ -60,52 +62,21 @@ private:
     uint16_t port_;
     std::vector<AddrEntry> addrEntries_;
 
-    CacheEntry
-    (const std::string& hostname, uint16_t port):
-      hostname_(hostname), port_(port) {}
+    CacheEntry(const std::string& hostname, uint16_t port);
+    CacheEntry(const CacheEntry& c);
+    ~CacheEntry();
 
-    void add(const std::string& addr)
-    {
-      addrEntries_.push_back(AddrEntry(addr));
-    }
+    CacheEntry& operator=(const CacheEntry& c);
 
-    std::vector<AddrEntry>::iterator find(const std::string& addr)
-    {
-      for(std::vector<AddrEntry>::iterator i = addrEntries_.begin(),
-            eoi = addrEntries_.end(); i != eoi; ++i) {
-        if((*i).addr_ == addr) {
-          return i;
-        }
-      }
-      return addrEntries_.end();
-    }
+    void add(const std::string& addr);
 
-    std::vector<AddrEntry>::const_iterator find(const std::string& addr) const
-    {
-      for(std::vector<AddrEntry>::const_iterator i = addrEntries_.begin(),
-            eoi = addrEntries_.end(); i != eoi; ++i) {
-        if((*i).addr_ == addr) {
-          return i;
-        }
-      }
-      return addrEntries_.end();
-    }
+    std::vector<AddrEntry>::iterator find(const std::string& addr);
 
-    bool contains(const std::string& addr) const
-    {
-      return find(addr) != addrEntries_.end();
-    }
+    std::vector<AddrEntry>::const_iterator find(const std::string& addr) const;
 
-    const std::string& getGoodAddr() const
-    {
-      for(std::vector<AddrEntry>::const_iterator i = addrEntries_.begin(),
-            eoi = addrEntries_.end(); i != eoi; ++i) {
-        if((*i).good_) {
-          return (*i).addr_;
-        }
-      }
-      return A2STR::NIL;
-    }
+    bool contains(const std::string& addr) const;
+
+    const std::string& getGoodAddr() const;
 
     template<typename OutputIterator>
     void getAllGoodAddrs(OutputIterator out) const
@@ -118,42 +89,23 @@ private:
       }      
     }
 
-    void markBad(const std::string& addr)
-    {
-      std::vector<AddrEntry>::iterator i = find(addr);
-      if(i != addrEntries_.end()) {
-        (*i).good_ = false;
-      }
-    }
+    void markBad(const std::string& addr);
 
-    bool operator<(const CacheEntry& e) const
-    {
-      int r = hostname_.compare(e.hostname_);
-      if(r != 0) {
-        return r < 0;
-      }
-      return port_ < e.port_;
-    }
+    bool operator<(const CacheEntry& e) const;
 
-    bool operator==(const CacheEntry& e) const
-    {
-      return hostname_ == e.hostname_ && port_ == e.port_;
-    }
+    bool operator==(const CacheEntry& e) const;
   };
 
   std::deque<CacheEntry> entries_;
 
 public:
-  const std::string& find(const std::string& hostname, uint16_t port) const
-  {
-    CacheEntry target(hostname, port);
-    std::deque<CacheEntry>::const_iterator i =
-      std::lower_bound(entries_.begin(), entries_.end(), target);
-    if(i != entries_.end() && (*i) == target) {
-      return (*i).getGoodAddr();
-    }
-    return A2STR::NIL;
-  }
+  DNSCache();
+  DNSCache(const DNSCache& c);
+  ~DNSCache();
+
+  DNSCache& operator=(const DNSCache& c);
+
+  const std::string& find(const std::string& hostname, uint16_t port) const;
   
   template<typename OutputIterator>
   void findAll
@@ -168,41 +120,12 @@ public:
   }
 
   void put
-  (const std::string& hostname, const std::string& ipaddr, uint16_t port)
-  {
-    CacheEntry target(hostname, port);
-    std::deque<CacheEntry>::iterator i =
-      std::lower_bound(entries_.begin(), entries_.end(), target);
-    if(i == entries_.end() || !((*i) == target)) {
-      target.add(ipaddr);
-      entries_.insert(i, target);
-    } else {
-      if(!(*i).contains(ipaddr)) {
-        (*i).add(ipaddr);
-      }
-    }
-  }
+  (const std::string& hostname, const std::string& ipaddr, uint16_t port);
 
   void markBad
-  (const std::string& hostname, const std::string& ipaddr, uint16_t port)
-  {
-    CacheEntry target(hostname, port);
-    std::deque<CacheEntry>::iterator i =
-      std::lower_bound(entries_.begin(), entries_.end(), target);
-    if(i != entries_.end() && (*i) == target) {
-      (*i).markBad(ipaddr);
-    }
-  }
+  (const std::string& hostname, const std::string& ipaddr, uint16_t port);
 
-  void remove(const std::string& hostname, uint16_t port)
-  {
-    CacheEntry target(hostname, port);
-    std::deque<CacheEntry>::iterator i =
-      std::lower_bound(entries_.begin(), entries_.end(), target);
-    if(i != entries_.end() && (*i) == target) {
-      entries_.erase(i);
-    }
-  }
+  void remove(const std::string& hostname, uint16_t port);
 };
 
 } // namespace aria2

+ 2 - 0
src/DiskAdaptor.cc

@@ -43,4 +43,6 @@ DiskAdaptor::DiskAdaptor():
   fallocate_(false),
   logger_(LogFactory::getInstance()) {}
 
+DiskAdaptor::~DiskAdaptor() {}
+
 } // namespace aria2

+ 1 - 1
src/DiskAdaptor.h

@@ -62,7 +62,7 @@ protected:
   }
 public:
   DiskAdaptor();
-  virtual ~DiskAdaptor() {}
+  virtual ~DiskAdaptor();
 
   virtual void openFile() = 0;
 

+ 1 - 2
src/DownloadCommand.cc

@@ -58,9 +58,8 @@
 #include "StringFormat.h"
 #include "RequestGroupMan.h"
 #include "wallclock.h"
-#include "ServerStatMan.h"
-#include "FileAllocationEntry.h"
 #include "SinkStreamFilter.h"
+#include "FileEntry.h"
 #ifdef ENABLE_MESSAGE_DIGEST
 # include "MessageDigest.h"
 # include "MessageDigestHelper.h"

+ 2 - 0
src/DownloadCommand.h

@@ -37,6 +37,8 @@
 
 #include "AbstractCommand.h"
 
+#include <unistd.h>
+
 namespace aria2 {
 
 class PeerStat;

+ 43 - 0
src/DownloadContext.cc

@@ -42,6 +42,8 @@
 #include "wallclock.h"
 #include "DlAbortEx.h"
 #include "a2functional.h"
+#include "Signature.h"
+#include "ContextAttribute.h"
 
 namespace aria2 {
 
@@ -69,6 +71,8 @@ DownloadContext::DownloadContext(size_t pieceLength,
   fileEntries_.push_back(fileEntry);
 }
 
+DownloadContext::~DownloadContext() {}
+
 void DownloadContext::resetDownloadStartTime()
 {
   downloadStartTime_ = global::wallclock;
@@ -226,4 +230,43 @@ bool DownloadContext::isPieceHashVerificationAvailable() const
     pieceHashes_.size() > 0 && pieceHashes_.size() == getNumPieces();
 }
 
+const std::string& DownloadContext::getPieceHash(size_t index) const
+{
+  if(index < pieceHashes_.size()) {
+    return pieceHashes_[index];
+  } else {
+    return A2STR::NIL;
+  }
+}
+
+void DownloadContext::setPieceHashAlgo(const std::string& algo)
+{
+  pieceHashAlgo_ = algo;
+}
+
+void DownloadContext::setChecksum(const std::string& checksum)
+{
+  checksum_ = checksum;
+}
+
+void DownloadContext::setChecksumHashAlgo(const std::string& algo)
+{
+  checksumHashAlgo_ = algo;
+}
+
+void DownloadContext::setBasePath(const std::string& basePath)
+{
+  basePath_ = basePath;
+}
+
+void DownloadContext::setDir(const std::string& dir)
+{
+  dir_ = dir;
+}
+
+void DownloadContext::setSignature(const SharedHandle<Signature>& signature)
+{
+  signature_ = signature;
+}
+
 } // namespace aria2

+ 12 - 29
src/DownloadContext.h

@@ -42,17 +42,17 @@
 #include <vector>
 
 #include "SharedHandle.h"
-#include "Signature.h"
 #include "TimerA2.h"
 #include "A2STR.h"
 #include "ValueBase.h"
 #include "IntSequence.h"
-#include "FileEntry.h"
-#include "TorrentAttribute.h"
 
 namespace aria2 {
 
 class RequestGroup;
+class Signature;
+class FileEntry;
+class ContextAttribute;
 
 class DownloadContext
 {
@@ -95,14 +95,9 @@ public:
                   uint64_t totalLength,
                   const std::string& path = A2STR::NIL);
 
-  const std::string& getPieceHash(size_t index) const
-  {
-    if(index < pieceHashes_.size()) {
-      return pieceHashes_[index];
-    } else {
-      return A2STR::NIL;
-    }
-  }
+  ~DownloadContext();
+
+  const std::string& getPieceHash(size_t index) const;
   
   const std::vector<std::string>& getPieceHashes() const
   {
@@ -148,24 +143,15 @@ public:
 
   const std::string& getPieceHashAlgo() const { return pieceHashAlgo_; }
 
-  void setPieceHashAlgo(const std::string& algo)
-  {
-    pieceHashAlgo_ = algo;
-  }
+  void setPieceHashAlgo(const std::string& algo);
 
   const std::string& getChecksum() const { return checksum_; }
 
-  void setChecksum(const std::string& checksum)
-  {
-    checksum_ = checksum;
-  }
+  void setChecksum(const std::string& checksum);
 
   const std::string& getChecksumHashAlgo() const { return checksumHashAlgo_; }
 
-  void setChecksumHashAlgo(const std::string& algo)
-  {
-    checksumHashAlgo_ = algo;
-  }
+  void setChecksumHashAlgo(const std::string& algo);
 
   // The representative path name for this context. It is used as a
   // part of .aria2 control file. If basePath_ is set, returns
@@ -173,18 +159,15 @@ public:
   // returned.
   const std::string& getBasePath() const;
 
-  void setBasePath(const std::string& basePath) { basePath_ = basePath; }
+  void setBasePath(const std::string& basePath);
 
   const std::string& getDir() const { return dir_; }
 
-  void setDir(const std::string& dir) { dir_ = dir; }
+  void setDir(const std::string& dir);
 
   const SharedHandle<Signature>& getSignature() const { return signature_; }
 
-  void setSignature(const SharedHandle<Signature>& signature)
-  {
-    signature_ = signature;
-  }
+  void setSignature(const SharedHandle<Signature>& signature);
 
   RequestGroup* getOwnerRequestGroup() { return ownerRequestGroup_; }
 

+ 28 - 4
src/DownloadEngine.cc

@@ -66,10 +66,6 @@
 #include "DownloadContext.h"
 #ifdef ENABLE_BITTORRENT
 # include "BtRegistry.h"
-# include "PeerStorage.h"
-# include "PieceStorage.h"
-# include "BtAnnounce.h"
-# include "BtRuntime.h"
 #endif // ENABLE_BITTORRENT
 
 namespace aria2 {
@@ -540,4 +536,32 @@ void DownloadEngine::setRefreshInterval(int64_t interval)
   refreshInterval_ = interval;
 }
 
+void DownloadEngine::addCommand(const std::vector<Command*>& commands)
+{
+  commands_.insert(commands_.end(), commands.begin(), commands.end());
+}
+
+void DownloadEngine::addCommand(Command* command)
+{
+  commands_.push_back(command);
+}
+
+void DownloadEngine::setRequestGroupMan
+(const SharedHandle<RequestGroupMan>& rgman)
+{
+  requestGroupMan_ = rgman;
+}
+
+void DownloadEngine::setFileAllocationMan
+(const SharedHandle<FileAllocationMan>& faman)
+{
+  fileAllocationMan_ = faman;
+}
+
+void DownloadEngine::setCheckIntegrityMan
+(const SharedHandle<CheckIntegrityMan>& ciman)
+{
+  checkIntegrityMan_ = ciman;
+}
+
 } // namespace aria2

+ 8 - 23
src/DownloadEngine.h

@@ -46,13 +46,13 @@
 #include "a2netcompat.h"
 #include "TimerA2.h"
 #include "a2io.h"
-#ifdef ENABLE_ASYNC_DNS
-# include "AsyncNameResolver.h"
-#endif // ENABLE_ASYNC_DNS
 #include "CUIDCounter.h"
 #include "FileAllocationMan.h"
 #include "CheckIntegrityMan.h"
 #include "DNSCache.h"
+#ifdef ENABLE_ASYNC_DNS
+# include "AsyncNameResolver.h"
+#endif // ENABLE_ASYNC_DNS
 
 namespace aria2 {
 
@@ -187,45 +187,30 @@ public:
                                Command* command);
 #endif // ENABLE_ASYNC_DNS
 
-  void addCommand(const std::vector<Command*>& commands)
-  {
-    commands_.insert(commands_.end(), commands.begin(), commands.end());
-  }
+  void addCommand(const std::vector<Command*>& commands);
 
-  void addCommand(Command* command)
-  {
-    commands_.push_back(command);
-  }
+  void addCommand(Command* command);
 
   const SharedHandle<RequestGroupMan>& getRequestGroupMan() const
   {
     return requestGroupMan_;
   }
 
-  void setRequestGroupMan(const SharedHandle<RequestGroupMan>& rgman)
-  {
-    requestGroupMan_ = rgman;
-  }
+  void setRequestGroupMan(const SharedHandle<RequestGroupMan>& rgman);
 
   const SharedHandle<FileAllocationMan>& getFileAllocationMan() const
   {
     return fileAllocationMan_;
   }
 
-  void setFileAllocationMan(const SharedHandle<FileAllocationMan>& faman)
-  {
-    fileAllocationMan_ = faman;
-  }
+  void setFileAllocationMan(const SharedHandle<FileAllocationMan>& faman);
 
   const SharedHandle<CheckIntegrityMan>& getCheckIntegrityMan() const
   {
     return checkIntegrityMan_;
   }
 
-  void setCheckIntegrityMan(const SharedHandle<CheckIntegrityMan>& ciman)
-  {
-    checkIntegrityMan_ = ciman;
-  }
+  void setCheckIntegrityMan(const SharedHandle<CheckIntegrityMan>& ciman);
 
   Option* getOption() const
   {

+ 46 - 0
src/DownloadResult.cc

@@ -0,0 +1,46 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#include "DownloadResult.h"
+#include "FileEntry.h"
+#include "Option.h"
+#include "MetadataInfo.h"
+
+namespace aria2 {
+
+DownloadResult::DownloadResult() {}
+
+DownloadResult::~DownloadResult() {}
+
+} // namespace aria2

+ 9 - 2
src/DownloadResult.h

@@ -45,12 +45,12 @@
 #include "SharedHandle.h"
 #include "DownloadResultCode.h"
 #include "RequestGroup.h"
-#include "Option.h"
-#include "MetadataInfo.h"
 
 namespace aria2 {
 
+class Option;
 class FileEntry;
+class MetadataInfo;
 
 struct DownloadResult
 {
@@ -94,6 +94,13 @@ struct DownloadResult
   size_t numPieces;
 
   std::string dir;
+
+  DownloadResult();
+  ~DownloadResult();
+
+  // Don't allow copying
+  DownloadResult(const DownloadResult& c);
+  DownloadResult& operator=(const DownloadResult& c);
 };
 
 typedef SharedHandle<DownloadResult> DownloadResultHandle;

+ 5 - 0
src/Exception.cc

@@ -72,4 +72,9 @@ std::string Exception::stackTrace() const
   return s.str();
 }
 
+const char* Exception::what() const throw()
+{
+  return msg_.c_str();
+}
+
 } // namespace aria2

+ 1 - 4
src/Exception.h

@@ -71,10 +71,7 @@ public:
 
   virtual ~Exception() throw();
 
-  virtual const char* what() const throw()
-  {
-    return msg_.c_str();
-  }
+  virtual const char* what() const throw();
 
   std::string stackTrace() const;
 

+ 78 - 0
src/ExtensionMessageRegistry.cc

@@ -0,0 +1,78 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#include "ExtensionMessageRegistry.h"
+#include "BtConstants.h"
+#include "A2STR.h"
+
+namespace aria2 {
+
+ExtensionMessageRegistry::ExtensionMessageRegistry()
+{
+  extensions_["ut_pex"] = 8;
+  // http://www.bittorrent.org/beps/bep_0009.html
+  extensions_["ut_metadata"] = 9;
+}
+
+ExtensionMessageRegistry::~ExtensionMessageRegistry() {}
+
+uint8_t ExtensionMessageRegistry::getExtensionMessageID
+(const std::string& name) const
+{
+  Extensions::const_iterator itr = extensions_.find(name);
+  if(itr == extensions_.end()) {
+    return 0;
+  } else {
+    return (*itr).second;
+  }
+}
+
+const std::string& ExtensionMessageRegistry::getExtensionName(uint8_t id) const
+{
+  for(Extensions::const_iterator itr = extensions_.begin(),
+        eoi = extensions_.end(); itr != eoi; ++itr) {
+    const Extensions::value_type& p = *itr;
+    if(p.second == id) {
+      return p.first;
+    }
+  }
+  return A2STR::NIL;
+}
+
+void ExtensionMessageRegistry::removeExtension(const std::string& name)
+{
+  extensions_.erase(name);
+}
+
+} // namespace aria2

+ 6 - 31
src/ExtensionMessageRegistry.h

@@ -40,7 +40,6 @@
 #include <string>
 
 #include "BtConstants.h"
-#include "A2STR.h"
 
 namespace aria2 {
 
@@ -48,44 +47,20 @@ class ExtensionMessageRegistry {
 private:
   Extensions extensions_;
 public:
-  ExtensionMessageRegistry()
-  {
-    extensions_["ut_pex"] = 8;
-    // http://www.bittorrent.org/beps/bep_0009.html
-    extensions_["ut_metadata"] = 9;
-  }
+  ExtensionMessageRegistry();
+
+  ~ExtensionMessageRegistry();
 
   const Extensions& getExtensions() const
   {
     return extensions_;
   }
 
-  uint8_t getExtensionMessageID(const std::string& name) const
-  {
-    Extensions::const_iterator itr = extensions_.find(name);
-    if(itr == extensions_.end()) {
-      return 0;
-    } else {
-      return (*itr).second;
-    }
-  }
+  uint8_t getExtensionMessageID(const std::string& name) const;
 
-  const std::string& getExtensionName(uint8_t id) const
-  {
-    for(Extensions::const_iterator itr = extensions_.begin(),
-          eoi = extensions_.end(); itr != eoi; ++itr) {
-      const Extensions::value_type& p = *itr;
-      if(p.second == id) {
-        return p.first;
-      }
-    }
-    return A2STR::NIL;
-  }
+  const std::string& getExtensionName(uint8_t id) const;
 
-  void removeExtension(const std::string& name)
-  {
-    extensions_.erase(name);
-  }
+  void removeExtension(const std::string& name);
 };
 
 } // namespace aria2

+ 2 - 0
src/FeatureConfig.cc

@@ -120,6 +120,8 @@ FeatureConfig::FeatureConfig() {
   features_.insert(vbegin(featureArray), vend(featureArray));
 }
 
+FeatureConfig::~FeatureConfig() {}
+
 const SharedHandle<FeatureConfig>& FeatureConfig::getInstance()
 {
   if(!featureConfig_) {

+ 2 - 0
src/FeatureConfig.h

@@ -56,6 +56,8 @@ private:
 
   FeatureConfig();
 public:
+  ~FeatureConfig();
+
   static const SharedHandle<FeatureConfig>& getInstance();
 
   uint16_t getDefaultPort(const std::string& protocol) const;

+ 11 - 1
src/File.cc

@@ -54,10 +54,20 @@ namespace aria2 {
 # include <windows.h>
 #endif // __MINGW32__
 
-File::File(const std::string& name):name_(name) {}
+File::File(const std::string& name) : name_(name) {}
+
+File::File(const File& c) : name_(c.name_) {}
 
 File::~File() {}
 
+File& File::operator=(const File& c)
+{
+  if(this != &c) {
+    name_ = c.name_;
+  }
+  return *this;
+}
+
 int File::fillStat(a2_struct_stat& fstat) {
   return a2stat(name_.c_str(), &fstat);
 }

+ 5 - 0
src/File.h

@@ -57,8 +57,13 @@ private:
   int fillStat(a2_struct_stat& fstat);
 public:
   File(const std::string& name);
+
+  File(const File& c);
+
   ~File();
 
+  File& operator=(const File& c);
+
   /**
    * Tests whether the file or directory denoted by name exists.
    */

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است