Jelajahi Sumber

2009-05-28 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Fixed compile error without BitTorrent and Metalink support.
	* src/XmlRpcMethod.cc
	* src/XmlRpcMethodFactory.cc
	* src/XmlRpcMethodImpl.cc
	* src/XmlRpcMethodImpl.h
	* test/XmlRpcMethodTest.cc
Tatsuhiro Tsujikawa 16 tahun lalu
induk
melakukan
30f362319e

+ 9 - 0
ChangeLog

@@ -1,3 +1,12 @@
+2009-05-28  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Fixed compile error without BitTorrent and Metalink support.
+	* src/XmlRpcMethod.cc
+	* src/XmlRpcMethodFactory.cc
+	* src/XmlRpcMethodImpl.cc
+	* src/XmlRpcMethodImpl.h
+	* test/XmlRpcMethodTest.cc
+
 2009-05-27  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Rewritten the help message for --allow-overwrite option.

+ 3 - 0
src/XmlRpcMethod.cc

@@ -86,6 +86,9 @@ static void gatherOption
       const BDE& value = optionsDict[*first];
       SharedHandle<OptionHandler> optionHandler =
 	optionParser->findByName(*first);
+      if(optionHandler.isNull()) {
+	continue;
+      }
       // header and index-out option can take array as value
       if((*first == PREF_HEADER || *first == PREF_INDEX_OUT) && value.isList()){
 	for(BDE::List::const_iterator argiter = value.listBegin();

+ 12 - 3
src/XmlRpcMethodFactory.cc

@@ -46,11 +46,17 @@ XmlRpcMethodFactory::create(const std::string& methodName)
 {
   if(methodName == "aria2.addUri") {
     return SharedHandle<XmlRpcMethod>(new AddUriXmlRpcMethod());
+#ifdef ENABLE_BITTORRENT
   } else if(methodName == "aria2.addTorrent") {
     return SharedHandle<XmlRpcMethod>(new AddTorrentXmlRpcMethod());
-  } else if(methodName == "aria2.addMetalink") {
+#endif // ENABLE_BITTORRENT
+#ifdef ENABLE_METALINK
+  }
+  else if(methodName == "aria2.addMetalink") {
     return SharedHandle<XmlRpcMethod>(new AddMetalinkXmlRpcMethod());
-  } else if(methodName == "aria2.remove") {
+#endif // ENABLE_METALINK
+  }
+  else if(methodName == "aria2.remove") {
     return SharedHandle<XmlRpcMethod>(new RemoveXmlRpcMethod());
   } else if(methodName == "aria2.tellStatus") {
     return SharedHandle<XmlRpcMethod>(new TellStatusXmlRpcMethod());
@@ -58,8 +64,11 @@ XmlRpcMethodFactory::create(const std::string& methodName)
     return SharedHandle<XmlRpcMethod>(new GetUrisXmlRpcMethod());
   } else if(methodName == "aria2.getFiles") {
     return SharedHandle<XmlRpcMethod>(new GetFilesXmlRpcMethod());
-  } else if(methodName == "aria2.getPeers") {
+#ifdef ENABLE_BITTORRENT
+  }
+  else if(methodName == "aria2.getPeers") {
     return SharedHandle<XmlRpcMethod>(new GetPeersXmlRpcMethod());
+#endif // ENABLE_BITTORRENT
   } else if(methodName == "aria2.tellActive") {
     return SharedHandle<XmlRpcMethod>(new TellActiveXmlRpcMethod());
   } else if(methodName == "aria2.changeOption") {

+ 11 - 2
src/XmlRpcMethodImpl.cc

@@ -113,6 +113,7 @@ BDE AddUriXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
   }
 }
 
+#ifdef ENABLE_BITTORRENT
 BDE AddTorrentXmlRpcMethod::process
 (const XmlRpcRequest& req, DownloadEngine* e)
 {
@@ -147,8 +148,10 @@ BDE AddTorrentXmlRpcMethod::process
   } else {
     throw DL_ABORT_EX("No Torrent to download.");
   }
-} 
+}
+#endif // ENABLE_BITTORRENT
 
+#ifdef ENABLE_METALINK
 BDE AddMetalinkXmlRpcMethod::process
 (const XmlRpcRequest& req, DownloadEngine* e)
 {
@@ -176,7 +179,7 @@ BDE AddMetalinkXmlRpcMethod::process
     throw DL_ABORT_EX("No files to download.");
   }
 } 
-
+#endif // ENABLE_METALINK
 
 BDE RemoveXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
 {
@@ -235,6 +238,7 @@ static void gatherProgressCommon
     Util::uitos(group->getDownloadContext()->getNumPieces());
 }
 
+#ifdef ENABLE_BITTORRENT
 static void gatherProgressBitTorrent
 (BDE& entryDict, const SharedHandle<BtContext>& btctx)
 {
@@ -263,16 +267,19 @@ static void gatherPeer(BDE& peers, const SharedHandle<PeerStorage>& ps)
     peers << peerEntry;
   }
 }
+#endif // ENABLE_BITTORRENT
 
 static void gatherProgress
 (BDE& entryDict, const SharedHandle<RequestGroup>& group, DownloadEngine* e)
 {
   gatherProgressCommon(entryDict, group);
+#ifdef ENABLE_BITTORRENT
   SharedHandle<BtContext> btctx =
     dynamic_pointer_cast<BtContext>(group->getDownloadContext());
   if(!btctx.isNull()) {
     gatherProgressBitTorrent(entryDict, btctx);
   }
+#endif // ENABLE_BITTORRENT
 }
 
 static void gatherStoppedDownload
@@ -373,6 +380,7 @@ BDE GetUrisXmlRpcMethod::process
   return uriList;
 }
 
+#ifdef ENABLE_BITTORRENT
 BDE GetPeersXmlRpcMethod::process
 (const XmlRpcRequest& req, DownloadEngine* e)
 {
@@ -404,6 +412,7 @@ BDE GetPeersXmlRpcMethod::process
   }
   return peers;
 }
+#endif // ENABLE_BITTORRENT
 
 BDE TellStatusXmlRpcMethod::process
 (const XmlRpcRequest& req, DownloadEngine* e)

+ 6 - 0
src/XmlRpcMethodImpl.h

@@ -51,15 +51,19 @@ protected:
   virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
 };
 
+#ifdef ENABLE_BITTORRENT
 class AddTorrentXmlRpcMethod:public XmlRpcMethod {
 protected:
   virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
 };
+#endif // ENABLE_BITTORRENT
 
+#ifdef ENABLE_METALINK
 class AddMetalinkXmlRpcMethod:public XmlRpcMethod {
 protected:
   virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
 };
+#endif // ENABLE_METALINK
 
 class PurgeDownloadResultXmlRpcMethod:public XmlRpcMethod {
 protected:
@@ -76,10 +80,12 @@ protected:
   virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
 };
 
+#ifdef ENABLE_BITTORRENT
 class GetPeersXmlRpcMethod:public XmlRpcMethod {
 protected:
   virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
 };
+#endif // ENABLE_BITTORRENT
 
 class TellStatusXmlRpcMethod:public XmlRpcMethod {
 protected:

+ 21 - 1
test/XmlRpcMethodTest.cc

@@ -29,12 +29,16 @@ class XmlRpcMethodTest:public CppUnit::TestFixture {
   CPPUNIT_TEST(testAddUri_withoutUri);
   CPPUNIT_TEST(testAddUri_notUri);
   CPPUNIT_TEST(testAddUri_withBadOption);
+#ifdef ENABLE_BITTORRENT
   CPPUNIT_TEST(testAddTorrent);
   CPPUNIT_TEST(testAddTorrent_withoutTorrent);
   CPPUNIT_TEST(testAddTorrent_notBase64Torrent);
+#endif // ENABLE_BITTORRENT
+#ifdef ENABLE_METALINK
   CPPUNIT_TEST(testAddMetalink);
   CPPUNIT_TEST(testAddMetalink_withoutMetalink);
   CPPUNIT_TEST(testAddMetalink_notBase64Metalink);
+#endif // ENABLE_METALINK
   CPPUNIT_TEST(testChangeOption);
   CPPUNIT_TEST(testChangeOption_withBadOption);
   CPPUNIT_TEST(testChangeOption_withoutGid);
@@ -65,12 +69,16 @@ public:
   void testAddUri_withoutUri();
   void testAddUri_notUri();
   void testAddUri_withBadOption();
+#ifdef ENABLE_BITTORRENT
   void testAddTorrent();
   void testAddTorrent_withoutTorrent();
   void testAddTorrent_notBase64Torrent();
+#endif // ENABLE_BITTORRENT
+#ifdef ENABLE_METALINK
   void testAddMetalink();
   void testAddMetalink_withoutMetalink();
   void testAddMetalink_notBase64Metalink();
+#endif // ENABLE_METALINK
   void testChangeOption();
   void testChangeOption_withBadOption();
   void testChangeOption_withoutGid();
@@ -142,6 +150,7 @@ void XmlRpcMethodTest::testAddUri_withBadOption()
   CPPUNIT_ASSERT_EQUAL(1, res._code);
 }
 
+#ifdef ENABLE_BITTORRENT
 void XmlRpcMethodTest::testAddTorrent()
 {
   AddTorrentXmlRpcMethod m;
@@ -191,7 +200,9 @@ void XmlRpcMethodTest::testAddTorrent_notBase64Torrent()
   XmlRpcResponse res = m.execute(req, _e.get());
   CPPUNIT_ASSERT_EQUAL(1, res._code);
 }
+#endif // ENABLE_BITTORRENT
 
+#ifdef ENABLE_METALINK
 void XmlRpcMethodTest::testAddMetalink()
 {
   AddMetalinkXmlRpcMethod m;
@@ -241,6 +252,7 @@ void XmlRpcMethodTest::testAddMetalink_notBase64Metalink()
   XmlRpcResponse res = m.execute(req, _e.get());
   CPPUNIT_ASSERT_EQUAL(1, res._code);
 }
+#endif // ENABLE_METALINK
 
 void XmlRpcMethodTest::testChangeOption()
 {
@@ -253,14 +265,18 @@ void XmlRpcMethodTest::testChangeOption()
   req._params << BDE("1");
   BDE opt = BDE::dict();
   opt[PREF_MAX_DOWNLOAD_LIMIT] = BDE("100K");
+#ifdef ENABLE_BITTORRENT
   opt[PREF_MAX_UPLOAD_LIMIT] = BDE("50K");
+#endif // ENABLE_BITTORRENT
   req._params << opt;
   XmlRpcResponse res = m.execute(req, _e.get());
 
   CPPUNIT_ASSERT_EQUAL(0, res._code);
   CPPUNIT_ASSERT_EQUAL((unsigned int)100*1024,
 		       group->getMaxDownloadSpeedLimit());
-  CPPUNIT_ASSERT_EQUAL((unsigned int)50*1024, group->getMaxUploadSpeedLimit());
+#ifdef ENABLE_BITTORRENT
+   CPPUNIT_ASSERT_EQUAL((unsigned int)50*1024, group->getMaxUploadSpeedLimit());
+#endif // ENABLE_BITTORRENT
 }
 
 void XmlRpcMethodTest::testChangeOption_withBadOption()
@@ -293,15 +309,19 @@ void XmlRpcMethodTest::testChangeGlobalOption()
   XmlRpcRequest req("aria2.changeGlobalOption", BDE::list());
   BDE opt = BDE::dict();
   opt[PREF_MAX_OVERALL_DOWNLOAD_LIMIT] = BDE("100K");
+#ifdef ENABLE_BITTORRENT
   opt[PREF_MAX_OVERALL_UPLOAD_LIMIT] = BDE("50K");
+#endif // ENABLE_BITTORRENT
   req._params << opt;
   XmlRpcResponse res = m.execute(req, _e.get());
 
   CPPUNIT_ASSERT_EQUAL(0, res._code);
   CPPUNIT_ASSERT_EQUAL((unsigned int)100*1024,
 		       _e->_requestGroupMan->getMaxOverallDownloadSpeedLimit());
+#ifdef ENABLE_BITTORRENT
   CPPUNIT_ASSERT_EQUAL((unsigned int)50*1024,
 		       _e->_requestGroupMan->getMaxOverallUploadSpeedLimit());
+#endif // ENABLE_BITTORRENT
 }
 
 void XmlRpcMethodTest::testChangeGlobalOption_withBadOption()