فهرست منبع

2007-11-13 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Now --metalink-location accepts a comma-deliminated list of 
locations.
	* src/MetalinkEntry.{h, cc}
	* test/MetalinkEntryTest.cc
	* src/version_usage.cc
	* src/Metalink2RequestGroup.cc
	* src/Xml2MetalinkProcessor.cc
	* test/Xml2MetalinkProcessorTest.cc
	* doc/aria2c.1.txt
	* doc/aria2c.1

	* src/Util.cc (toUpper)(toLower): Rewritten.
Tatsuhiro Tsujikawa 18 سال پیش
والد
کامیت
8cba9bc24c
12فایلهای تغییر یافته به همراه83 افزوده شده و 46 حذف شده
  1. 14 0
      ChangeLog
  2. 4 2
      TODO
  3. 4 4
      doc/aria2c.1
  4. 4 3
      doc/aria2c.1.txt
  5. 3 1
      src/Metalink2RequestGroup.cc
  6. 14 8
      src/MetalinkEntry.cc
  7. 1 1
      src/MetalinkEntry.h
  8. 2 16
      src/Util.cc
  9. 1 1
      src/Xml2MetalinkProcessor.cc
  10. 3 1
      src/version_usage.cc
  11. 31 7
      test/MetalinkEntryTest.cc
  12. 2 2
      test/Xml2MetalinkProcessorTest.cc

+ 14 - 0
ChangeLog

@@ -1,3 +1,17 @@
+2007-11-13  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Now --metalink-location accepts a comma-deliminated list of locations.
+	* src/MetalinkEntry.{h, cc}
+	* test/MetalinkEntryTest.cc
+	* src/version_usage.cc
+	* src/Metalink2RequestGroup.cc
+	* src/Xml2MetalinkProcessor.cc
+	* test/Xml2MetalinkProcessorTest.cc
+	* doc/aria2c.1.txt
+	* doc/aria2c.1
+
+	* src/Util.cc (toUpper)(toLower): Rewritten.
+
 2007-11-13  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Added the ability to detect duplicate download entry which is about to

+ 4 - 2
TODO

@@ -55,5 +55,7 @@
     DownloadFailureException .... RequestGroup should halt.
   FatalException .... Program should abort.
 
--- remaining features to be implemented for 0.12.0 release
-* improve --metalink-location field
+-- remaining issues to be implemented for 0.12.0 release
+* Update man page
+* Update translation
+* Test configuration(without torrent/messagedigest/ssh etc)

+ 4 - 4
doc/aria2c.1

@@ -1,11 +1,11 @@
 .\"     Title: aria2c
 .\"    Author: 
 .\" Generator: DocBook XSL Stylesheets v1.73.1 <http://docbook.sf.net/>
-.\"      Date: 10/29/2007
+.\"      Date: 11/13/2007
 .\"    Manual: 
 .\"    Source: 
 .\"
-.TH "ARIA2C" "1" "10/29/2007" "" ""
+.TH "ARIA2C" "1" "11/13/2007" "" ""
 .\" disable hyphenation
 .nh
 .\" disable justification (adjust text to left margin only)
@@ -382,9 +382,9 @@ The language of the file to download\.
 The operating system of the file to download\.
 .RE
 .PP
-\-\-metalink\-location=LOCATION
+\-\-metalink\-location=LOCATION[,\&...]
 .RS 4
-The location of the prefered server\.
+The location of the preferred server\. A comma\-deliminated list of locations is acceptable\.
 .RE
 .PP
 \-\-follow\-metalink=true|false

+ 4 - 3
doc/aria2c.1.txt

@@ -292,9 +292,10 @@ http://host/image[000-100:2].img
  --metalink-os=OS::
    The operating system of the file to download.
 
- --metalink-location=LOCATION::
- The location of the prefered server.
-
+ --metalink-location=LOCATION[,...]::
+    The location of the preferred server.
+    A comma-deliminated list of locations is acceptable.
+ 
  --follow-metalink=true|false::
    Set to false to prevent aria2 from
                               entering Metalink mode even if the filename of

+ 3 - 1
src/Metalink2RequestGroup.cc

@@ -113,7 +113,9 @@ RequestGroups Metalink2RequestGroup::generate(const string& metalinkFile)
       itr++, ++count) {
     MetalinkEntryHandle& entry = *itr;
     if(_option->defined(PREF_METALINK_LOCATION)) {
-      entry->setLocationPreference(_option->get(PREF_METALINK_LOCATION), 100);
+      Strings locations;
+      Util::slice(locations, _option->get(PREF_METALINK_LOCATION), ',', true);
+      entry->setLocationPreference(locations, 100);
     }
     if(useIndex) {
       if(find(selectIndexes.begin(), selectIndexes.end(), count+1) == selectIndexes.end()) {

+ 14 - 8
src/MetalinkEntry.cc

@@ -49,22 +49,28 @@ MetalinkEntry::~MetalinkEntry() {}
 
 class AddLocationPreference {
 private:
-  string location;
-  int32_t preferenceToAdd;
+  Strings _locations;
+  int32_t _preferenceToAdd;
 public:
-  AddLocationPreference(const string& location, int32_t preferenceToAdd):
-    location(location), preferenceToAdd(preferenceToAdd) {}
+  AddLocationPreference(const Strings& locations, int32_t preferenceToAdd):
+    _locations(locations), _preferenceToAdd(preferenceToAdd)
+  {
+    transform(_locations.begin(), _locations.end(), _locations.begin(), Util::toUpper);
+    sort(_locations.begin(), _locations.end());
+  }
 
   void operator()(MetalinkResourceHandle& res) {
-    if(res->location == location) {
-      res->preference += preferenceToAdd;
+    if(binary_search(_locations.begin(), _locations.end(), res->location)) {
+      res->preference += _preferenceToAdd;
     }
   }
 };
 
-void MetalinkEntry::setLocationPreference(const string& location, int32_t preferenceToAdd) {
+void MetalinkEntry::setLocationPreference(const Strings& locations,
+					  int32_t preferenceToAdd)
+{
   for_each(resources.begin(), resources.end(),
-	   AddLocationPreference(location, preferenceToAdd));
+	   AddLocationPreference(locations, preferenceToAdd));
 }
 
 class PrefOrder {

+ 1 - 1
src/MetalinkEntry.h

@@ -95,7 +95,7 @@ public:
 
   void reorderResourcesByPreference();
   
-  void setLocationPreference(const string& location, int32_t preferenceToAdd);
+  void setLocationPreference(const Strings& locations, int32_t preferenceToAdd);
 
   static FileEntries toFileEntry(const MetalinkEntries& metalinkEntries);
 };

+ 2 - 16
src/Util.cc

@@ -541,29 +541,15 @@ string Util::randomAlpha(int32_t length, const RandomizerHandle& randomizer) {
   return str;
 }
 
-class UpperCase {
-public:
-  void operator()(char& ch) {
-    ch = toupper(ch);
-  }
-};
-
 string Util::toUpper(const string& src) {
   string temp = src;
-  for_each(temp.begin(), temp.end(), UpperCase());
+  transform(temp.begin(), temp.end(), temp.begin(), ::toupper);
   return temp;
 }
 
-class LowerCase {
-public:
-  void operator()(char& ch) {
-    ch = tolower(ch);
-  }
-};
-
 string Util::toLower(const string& src) {
   string temp = src;
-  for_each(temp.begin(), temp.end(), LowerCase());
+  transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
   return temp;
 }
 

+ 1 - 1
src/Xml2MetalinkProcessor.cc

@@ -224,7 +224,7 @@ MetalinkResourceHandle Xml2MetalinkProcessor::getResource(const string& xpath) {
   } else {
     resource->preference = STRTOLL(pref.c_str());
   }
-  resource->location = Util::trim(xmlAttribute(node, "location"));
+  resource->location = Util::toUpper(Util::trim(xmlAttribute(node, "location")));
 
   resource->url = Util::trim(xmlContent(node));
 

+ 3 - 1
src/version_usage.cc

@@ -256,7 +256,9 @@ void showUsage() {
   cout << _(" --metalink-version=VERSION   The version of the file to download.") << endl;
   cout << _(" --metalink-language=LANGUAGE The language of the file to download.") << endl;
   cout << _(" --metalink-os=OS             The operating system of the file to download.") << endl;
-  cout << _(" --metalink-location=LOCATION The location of the prefered server.") << endl;
+  cout << _(" --metalink-location=LOCATION[,...] The location of the preferred server.\n"
+	    "                              A comma-deliminated list of locations is\n"
+	    "                              acceptable.") << endl;
   cout << _(" --follow-metalink=true|false Set to false to prevent aria2 from\n"
 	    "                              entering Metalink mode even if the filename of\n"
 	    "                              the downloaded file ends with .metalink.\n"

+ 31 - 7
test/MetalinkEntryTest.cc

@@ -8,6 +8,7 @@ class MetalinkEntryTest:public CppUnit::TestFixture {
   CPPUNIT_TEST_SUITE(MetalinkEntryTest);
   CPPUNIT_TEST(testDropUnsupportedResource);
   CPPUNIT_TEST(testReorderResourcesByPreference);
+  CPPUNIT_TEST(testSetLocationPreference);
   CPPUNIT_TEST_SUITE_END();
 private:
 
@@ -19,13 +20,14 @@ public:
 
   void testDropUnsupportedResource();
   void testReorderResourcesByPreference();
+  void testSetLocationPreference();
 };
 
 
 CPPUNIT_TEST_SUITE_REGISTRATION( MetalinkEntryTest );
 
-MetalinkEntry* createTestEntry() {
-  MetalinkEntry* entry = new MetalinkEntry();
+MetalinkEntryHandle createTestEntry() {
+  MetalinkEntryHandle entry = new MetalinkEntry();
   MetalinkResource* res1 = new MetalinkResource();
   res1->url = "ftp://myhost/aria2.tar.bz2";
   res1->type = MetalinkResource::TYPE_FTP;
@@ -39,17 +41,17 @@ MetalinkEntry* createTestEntry() {
   MetalinkResource* res3 = new MetalinkResource();
   res3->url = "http://myhost/aria2.torrent";
   res3->type = MetalinkResource::TYPE_BITTORRENT;
-  res3->location = "al";
+  res3->location = "AL";
   res3->preference = 60;
   MetalinkResource* res4 = new MetalinkResource();
   res4->url = "http://myhost/aria2.ext";
   res4->type = MetalinkResource::TYPE_NOT_SUPPORTED;
-  res4->location = "ad";
+  res4->location = "AD";
   res4->preference = 10;
   MetalinkResource* res5 = new MetalinkResource();
   res5->url = "https://myhost/aria2.tar.bz2";
   res5->type = MetalinkResource::TYPE_HTTPS;
-  res5->location = "jp";
+  res5->location = "JP";
   res5->preference = 90;
 
   entry->resources.push_back(res1);
@@ -61,7 +63,7 @@ MetalinkEntry* createTestEntry() {
 }
 
 void MetalinkEntryTest::testDropUnsupportedResource() {
-  MetalinkEntry* entry = createTestEntry();
+  MetalinkEntryHandle entry = createTestEntry();
 
   entry->dropUnsupportedResource();
 #if defined ENABLE_SSL && ENABLE_BITTORRENT
@@ -88,7 +90,7 @@ void MetalinkEntryTest::testDropUnsupportedResource() {
 }
 
 void MetalinkEntryTest::testReorderResourcesByPreference() {
-  MetalinkEntry* entry = createTestEntry();
+  MetalinkEntryHandle entry = createTestEntry();
   
   entry->reorderResourcesByPreference();
 
@@ -98,3 +100,25 @@ void MetalinkEntryTest::testReorderResourcesByPreference() {
   CPPUNIT_ASSERT_EQUAL((int32_t)50, entry->resources.at(3)->preference);
   CPPUNIT_ASSERT_EQUAL((int32_t)10, entry->resources.at(4)->preference);
 }
+
+void MetalinkEntryTest::testSetLocationPreference()
+{
+  MetalinkEntryHandle entry = createTestEntry();
+
+  const char* locationsSrc[] = { "jp", "al", "RO" };
+
+  Strings locations(&locationsSrc[0], &locationsSrc[3]);
+
+  entry->setLocationPreference(locations, 100);
+
+  CPPUNIT_ASSERT_EQUAL(string("RO"), entry->resources[0]->location);
+  CPPUNIT_ASSERT_EQUAL((int32_t)150, entry->resources[0]->preference);
+  CPPUNIT_ASSERT_EQUAL(string("AT"), entry->resources[1]->location);
+  CPPUNIT_ASSERT_EQUAL((int32_t)100, entry->resources[1]->preference);
+  CPPUNIT_ASSERT_EQUAL(string("AL"), entry->resources[2]->location);
+  CPPUNIT_ASSERT_EQUAL((int32_t)160, entry->resources[2]->preference);
+  CPPUNIT_ASSERT_EQUAL(string("AD"), entry->resources[3]->location);
+  CPPUNIT_ASSERT_EQUAL((int32_t)10, entry->resources[3]->preference);
+  CPPUNIT_ASSERT_EQUAL(string("JP"), entry->resources[4]->location);
+  CPPUNIT_ASSERT_EQUAL((int32_t)190, entry->resources[4]->preference);
+}

+ 2 - 2
test/Xml2MetalinkProcessorTest.cc

@@ -46,7 +46,7 @@ void Xml2MetalinkProcessorTest::testParseFile() {
     MetalinkResources::iterator resourceItr1 = entry1->resources.begin();
     MetalinkResourceHandle resource1 = *resourceItr1;
     CPPUNIT_ASSERT_EQUAL(MetalinkResource::TYPE_FTP, resource1->type);
-    CPPUNIT_ASSERT_EQUAL(string("jp"), resource1->location);
+    CPPUNIT_ASSERT_EQUAL(string("JP"), resource1->location);
     CPPUNIT_ASSERT_EQUAL((int32_t)100, resource1->preference);
     CPPUNIT_ASSERT_EQUAL(string("ftp://ftphost/aria2-0.5.2.tar.bz2"),
 			 resource1->url);
@@ -55,7 +55,7 @@ void Xml2MetalinkProcessorTest::testParseFile() {
     resourceItr1++;
     MetalinkResourceHandle resource2 = *resourceItr1;
     CPPUNIT_ASSERT_EQUAL(MetalinkResource::TYPE_HTTP, resource2->type);
-    CPPUNIT_ASSERT_EQUAL(string("us"), resource2->location);
+    CPPUNIT_ASSERT_EQUAL(string("US"), resource2->location);
     CPPUNIT_ASSERT_EQUAL((int32_t)100, resource2->preference);
     CPPUNIT_ASSERT_EQUAL(string("http://httphost/aria2-0.5.2.tar.bz2"),
 			 resource2->url);