Przeglądaj źródła

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

	Print URL List in -S option for torrent.
	* src/bittorrent_helper.cc
	* src/bittorrent_helper.h
Tatsuhiro Tsujikawa 16 lat temu
rodzic
commit
5da696fb29
3 zmienionych plików z 27 dodań i 2 usunięć
  1. 6 0
      ChangeLog
  2. 19 2
      src/bittorrent_helper.cc
  3. 2 0
      src/bittorrent_helper.h

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+2009-07-05  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Print URL List in -S option for torrent.
+	* src/bittorrent_helper.cc
+	* src/bittorrent_helper.h
+
 2009-07-05  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Allocate buffer in ctor of DownloadCommand.

+ 19 - 2
src/bittorrent_helper.cc

@@ -100,6 +100,8 @@ const std::string PORT("port");
 
 const std::string NAME("name");
 
+const std::string URL_LIST("urlList");
+
 const std::string BITTORRENT("bittorrent");
 
 const std::string MULTI("multi");
@@ -121,7 +123,8 @@ static void extractPieceHash(const SharedHandle<DownloadContext>& ctx,
   ctx->setPieceHashAlgo(MessageDigestContext::SHA1);
 }
 
-static void extractUrlList(std::vector<std::string>& uris, const BDE& bde)
+static void extractUrlList
+(BDE& torrent, std::vector<std::string>& uris, const BDE& bde)
 {
   if(bde.isList()) {
     for(BDE::List::const_iterator itr = bde.listBegin();
@@ -130,8 +133,14 @@ static void extractUrlList(std::vector<std::string>& uris, const BDE& bde)
 	uris.push_back((*itr).s());
       }
     }
+    torrent[URL_LIST] = bde;
   } else if(bde.isString()) {
     uris.push_back(bde.s());
+    BDE urlList = BDE::list();
+    urlList << bde;
+    torrent[URL_LIST] = urlList;
+  } else {
+    torrent[URL_LIST] = BDE::list();
   }
 }
 
@@ -377,7 +386,7 @@ static void processRootDictionary
   // This implemantation obeys HTTP-Seeding specification:
   // see http://www.getright.com/seedtorrent.html
   std::vector<std::string> urlList;
-  extractUrlList(urlList, rootDict[C_URL_LIST]);
+  extractUrlList(torrent, urlList, rootDict[C_URL_LIST]);
   urlList.insert(urlList.end(), uris.begin(), uris.end());
   std::sort(urlList.begin(), urlList.end());
   urlList.erase(std::unique(urlList.begin(), urlList.end()), urlList.end());
@@ -506,6 +515,14 @@ void print(std::ostream& o, const SharedHandle<DownloadContext>& dctx)
   o << "Piece Length: " << Util::abbrevSize(dctx->getPieceLength()) << "B\n";
   o << "The Number of Pieces: " << dctx->getNumPieces() << "\n";
   o << "Total Length: " << Util::abbrevSize(dctx->getTotalLength()) << "B\n";
+  if(!torrentAttrs[URL_LIST].empty()) {
+    const BDE& urlList = torrentAttrs[URL_LIST];
+    o << "URL List: " << "\n";
+    for(BDE::List::const_iterator i = urlList.listBegin();
+	i != urlList.listEnd(); ++i) {
+      o << " " << (*i).s() << "\n";
+    }
+  }
   o << "Name: " << torrentAttrs[NAME].s() << "\n";
   Util::toStream(dctx->getFileEntries().begin(), dctx->getFileEntries().end(), o);
 }

+ 2 - 0
src/bittorrent_helper.h

@@ -69,6 +69,8 @@ extern const std::string PORT;
 
 extern const std::string NAME;
 
+extern const std::string URL_LIST;
+
 extern const std::string SINGLE;
 
 extern const std::string MULTI;