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.
pull/1/head
Tatsuhiro Tsujikawa 2007-11-13 13:49:10 +00:00
parent 74b4d8c5a4
commit 8cba9bc24c
12 changed files with 83 additions and 46 deletions

View File

@ -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> 2007-11-13 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added the ability to detect duplicate download entry which is about to Added the ability to detect duplicate download entry which is about to

6
TODO
View File

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

View File

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

View File

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

View File

@ -113,7 +113,9 @@ RequestGroups Metalink2RequestGroup::generate(const string& metalinkFile)
itr++, ++count) { itr++, ++count) {
MetalinkEntryHandle& entry = *itr; MetalinkEntryHandle& entry = *itr;
if(_option->defined(PREF_METALINK_LOCATION)) { 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(useIndex) {
if(find(selectIndexes.begin(), selectIndexes.end(), count+1) == selectIndexes.end()) { if(find(selectIndexes.begin(), selectIndexes.end(), count+1) == selectIndexes.end()) {

View File

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

View File

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

View File

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

View File

@ -224,7 +224,7 @@ MetalinkResourceHandle Xml2MetalinkProcessor::getResource(const string& xpath) {
} else { } else {
resource->preference = STRTOLL(pref.c_str()); 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)); resource->url = Util::trim(xmlContent(node));

View File

@ -256,7 +256,9 @@ void showUsage() {
cout << _(" --metalink-version=VERSION The version of the file to download.") << endl; 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-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-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" cout << _(" --follow-metalink=true|false Set to false to prevent aria2 from\n"
" entering Metalink mode even if the filename of\n" " entering Metalink mode even if the filename of\n"
" the downloaded file ends with .metalink.\n" " the downloaded file ends with .metalink.\n"

View File

@ -8,6 +8,7 @@ class MetalinkEntryTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(MetalinkEntryTest); CPPUNIT_TEST_SUITE(MetalinkEntryTest);
CPPUNIT_TEST(testDropUnsupportedResource); CPPUNIT_TEST(testDropUnsupportedResource);
CPPUNIT_TEST(testReorderResourcesByPreference); CPPUNIT_TEST(testReorderResourcesByPreference);
CPPUNIT_TEST(testSetLocationPreference);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
@ -19,13 +20,14 @@ public:
void testDropUnsupportedResource(); void testDropUnsupportedResource();
void testReorderResourcesByPreference(); void testReorderResourcesByPreference();
void testSetLocationPreference();
}; };
CPPUNIT_TEST_SUITE_REGISTRATION( MetalinkEntryTest ); CPPUNIT_TEST_SUITE_REGISTRATION( MetalinkEntryTest );
MetalinkEntry* createTestEntry() { MetalinkEntryHandle createTestEntry() {
MetalinkEntry* entry = new MetalinkEntry(); MetalinkEntryHandle entry = new MetalinkEntry();
MetalinkResource* res1 = new MetalinkResource(); MetalinkResource* res1 = new MetalinkResource();
res1->url = "ftp://myhost/aria2.tar.bz2"; res1->url = "ftp://myhost/aria2.tar.bz2";
res1->type = MetalinkResource::TYPE_FTP; res1->type = MetalinkResource::TYPE_FTP;
@ -39,17 +41,17 @@ MetalinkEntry* createTestEntry() {
MetalinkResource* res3 = new MetalinkResource(); MetalinkResource* res3 = new MetalinkResource();
res3->url = "http://myhost/aria2.torrent"; res3->url = "http://myhost/aria2.torrent";
res3->type = MetalinkResource::TYPE_BITTORRENT; res3->type = MetalinkResource::TYPE_BITTORRENT;
res3->location = "al"; res3->location = "AL";
res3->preference = 60; res3->preference = 60;
MetalinkResource* res4 = new MetalinkResource(); MetalinkResource* res4 = new MetalinkResource();
res4->url = "http://myhost/aria2.ext"; res4->url = "http://myhost/aria2.ext";
res4->type = MetalinkResource::TYPE_NOT_SUPPORTED; res4->type = MetalinkResource::TYPE_NOT_SUPPORTED;
res4->location = "ad"; res4->location = "AD";
res4->preference = 10; res4->preference = 10;
MetalinkResource* res5 = new MetalinkResource(); MetalinkResource* res5 = new MetalinkResource();
res5->url = "https://myhost/aria2.tar.bz2"; res5->url = "https://myhost/aria2.tar.bz2";
res5->type = MetalinkResource::TYPE_HTTPS; res5->type = MetalinkResource::TYPE_HTTPS;
res5->location = "jp"; res5->location = "JP";
res5->preference = 90; res5->preference = 90;
entry->resources.push_back(res1); entry->resources.push_back(res1);
@ -61,7 +63,7 @@ MetalinkEntry* createTestEntry() {
} }
void MetalinkEntryTest::testDropUnsupportedResource() { void MetalinkEntryTest::testDropUnsupportedResource() {
MetalinkEntry* entry = createTestEntry(); MetalinkEntryHandle entry = createTestEntry();
entry->dropUnsupportedResource(); entry->dropUnsupportedResource();
#if defined ENABLE_SSL && ENABLE_BITTORRENT #if defined ENABLE_SSL && ENABLE_BITTORRENT
@ -88,7 +90,7 @@ void MetalinkEntryTest::testDropUnsupportedResource() {
} }
void MetalinkEntryTest::testReorderResourcesByPreference() { void MetalinkEntryTest::testReorderResourcesByPreference() {
MetalinkEntry* entry = createTestEntry(); MetalinkEntryHandle entry = createTestEntry();
entry->reorderResourcesByPreference(); 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)50, entry->resources.at(3)->preference);
CPPUNIT_ASSERT_EQUAL((int32_t)10, entry->resources.at(4)->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);
}

View File

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