mirror of https://github.com/aria2/aria2
2008-05-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Changed method sinature: MetalinkEntry::toFileEntry, MetalinkHelper::query, MetalinkHelper::parseAndQuery, Metalinker::queryEntry * src/Metalink2RequestGroup.cc * src/MetalinkEntry.cc * src/MetalinkEntry.h * src/MetalinkHelper.cc * src/MetalinkHelper.h * src/Metalinker.cc * src/Metalinker.h * src/main.cc * test/MetalinkHelperTest.cc * test/MetalinkerTest.ccpull/1/head
parent
f84eac327f
commit
3da60af41e
17
ChangeLog
17
ChangeLog
|
@ -1,3 +1,20 @@
|
||||||
|
2008-05-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
|
Changed method sinature:
|
||||||
|
MetalinkEntry::toFileEntry,
|
||||||
|
MetalinkHelper::query, MetalinkHelper::parseAndQuery,
|
||||||
|
Metalinker::queryEntry
|
||||||
|
* src/Metalink2RequestGroup.cc
|
||||||
|
* src/MetalinkEntry.cc
|
||||||
|
* src/MetalinkEntry.h
|
||||||
|
* src/MetalinkHelper.cc
|
||||||
|
* src/MetalinkHelper.h
|
||||||
|
* src/Metalinker.cc
|
||||||
|
* src/Metalinker.h
|
||||||
|
* src/main.cc
|
||||||
|
* test/MetalinkHelperTest.cc
|
||||||
|
* test/MetalinkerTest.cc
|
||||||
|
|
||||||
2008-05-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
2008-05-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
Changed method sinature:
|
Changed method sinature:
|
||||||
|
|
|
@ -102,8 +102,8 @@ void
|
||||||
Metalink2RequestGroup::generate(std::deque<SharedHandle<RequestGroup> >& groups,
|
Metalink2RequestGroup::generate(std::deque<SharedHandle<RequestGroup> >& groups,
|
||||||
const std::string& metalinkFile)
|
const std::string& metalinkFile)
|
||||||
{
|
{
|
||||||
std::deque<SharedHandle<MetalinkEntry> > entries = MetalinkHelper::parseAndQuery(metalinkFile,
|
std::deque<SharedHandle<MetalinkEntry> > entries;
|
||||||
_option);
|
MetalinkHelper::parseAndQuery(entries, metalinkFile, _option);
|
||||||
createRequestGroup(groups, entries);
|
createRequestGroup(groups, entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,8 +111,8 @@ void
|
||||||
Metalink2RequestGroup::generate(std::deque<SharedHandle<RequestGroup> >& groups,
|
Metalink2RequestGroup::generate(std::deque<SharedHandle<RequestGroup> >& groups,
|
||||||
const SharedHandle<BinaryStream>& binaryStream)
|
const SharedHandle<BinaryStream>& binaryStream)
|
||||||
{
|
{
|
||||||
std::deque<SharedHandle<MetalinkEntry> > entries = MetalinkHelper::parseAndQuery(binaryStream,
|
std::deque<SharedHandle<MetalinkEntry> > entries;
|
||||||
_option);
|
MetalinkHelper::parseAndQuery(entries, binaryStream, _option);
|
||||||
createRequestGroup(groups, entries);
|
createRequestGroup(groups, entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -166,13 +166,13 @@ void MetalinkEntry::dropUnsupportedResource() {
|
||||||
resources.end());
|
resources.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::deque<SharedHandle<FileEntry> >
|
void MetalinkEntry::toFileEntry
|
||||||
MetalinkEntry::toFileEntry(const std::deque<SharedHandle<MetalinkEntry> >& metalinkEntries)
|
(std::deque<SharedHandle<FileEntry> >& fileEntries,
|
||||||
|
const std::deque<SharedHandle<MetalinkEntry> >& metalinkEntries)
|
||||||
{
|
{
|
||||||
std::deque<SharedHandle<FileEntry> > entries;
|
std::transform(metalinkEntries.begin(), metalinkEntries.end(),
|
||||||
std::transform(metalinkEntries.begin(), metalinkEntries.end(), std::back_inserter(entries),
|
std::back_inserter(fileEntries),
|
||||||
mem_fun_sh(&MetalinkEntry::getFile));
|
mem_fun_sh(&MetalinkEntry::getFile));
|
||||||
return entries;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedHandle<FileEntry> MetalinkEntry::getFile() const
|
SharedHandle<FileEntry> MetalinkEntry::getFile() const
|
||||||
|
|
|
@ -81,8 +81,9 @@ public:
|
||||||
void setLocationPreference(const std::deque<std::string>& locations, int preferenceToAdd);
|
void setLocationPreference(const std::deque<std::string>& locations, int preferenceToAdd);
|
||||||
void setProtocolPreference(const std::string& protocol, int preferenceToAdd);
|
void setProtocolPreference(const std::string& protocol, int preferenceToAdd);
|
||||||
|
|
||||||
static std::deque<SharedHandle<FileEntry> >
|
static void toFileEntry
|
||||||
toFileEntry(const std::deque<SharedHandle<MetalinkEntry> >& metalinkEntries);
|
(std::deque<SharedHandle<FileEntry> >& fileEntries,
|
||||||
|
const std::deque<SharedHandle<MetalinkEntry> >& metalinkEntries);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -50,35 +50,37 @@ MetalinkHelper::MetalinkHelper() {}
|
||||||
|
|
||||||
MetalinkHelper::~MetalinkHelper() {}
|
MetalinkHelper::~MetalinkHelper() {}
|
||||||
|
|
||||||
std::deque<SharedHandle<MetalinkEntry> >
|
void MetalinkHelper::parseAndQuery
|
||||||
MetalinkHelper::parseAndQuery(const std::string& filename, const Option* option)
|
(std::deque<SharedHandle<MetalinkEntry> >& result,
|
||||||
|
const std::string& filename, const Option* option)
|
||||||
{
|
{
|
||||||
SharedHandle<MetalinkProcessor> proc = MetalinkProcessorFactory::newInstance();
|
SharedHandle<MetalinkProcessor> proc = MetalinkProcessorFactory::newInstance();
|
||||||
|
|
||||||
SharedHandle<Metalinker> metalinker = proc->parseFile(filename);
|
SharedHandle<Metalinker> metalinker = proc->parseFile(filename);
|
||||||
return query(metalinker, option);
|
query(result, metalinker, option);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::deque<SharedHandle<MetalinkEntry> >
|
void MetalinkHelper::parseAndQuery
|
||||||
MetalinkHelper::parseAndQuery(const SharedHandle<BinaryStream>& binaryStream, const Option* option)
|
(std::deque<SharedHandle<MetalinkEntry> >& result,
|
||||||
|
const SharedHandle<BinaryStream>& binaryStream, const Option* option)
|
||||||
{
|
{
|
||||||
SharedHandle<MetalinkProcessor> proc = MetalinkProcessorFactory::newInstance();
|
SharedHandle<MetalinkProcessor> proc = MetalinkProcessorFactory::newInstance();
|
||||||
|
|
||||||
SharedHandle<Metalinker> metalinker = proc->parseFromBinaryStream(binaryStream);
|
SharedHandle<Metalinker> metalinker = proc->parseFromBinaryStream(binaryStream);
|
||||||
return query(metalinker, option);
|
query(result, metalinker, option);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::deque<SharedHandle<MetalinkEntry> >
|
void MetalinkHelper::query
|
||||||
MetalinkHelper::query(const SharedHandle<Metalinker>& metalinker, const Option* option)
|
(std::deque<SharedHandle<MetalinkEntry> >& result,
|
||||||
|
const SharedHandle<Metalinker>& metalinker, const Option* option)
|
||||||
{
|
{
|
||||||
if(metalinker->entries.empty()) {
|
if(metalinker->entries.empty()) {
|
||||||
throw DlAbortEx("No file entry found. Probably, the metalink file is not configured properly or broken.");
|
throw DlAbortEx("No file entry found. Probably, the metalink file is not configured properly or broken.");
|
||||||
}
|
}
|
||||||
std::deque<SharedHandle<MetalinkEntry> > entries =
|
metalinker->queryEntry(result,
|
||||||
metalinker->queryEntry(option->get(PREF_METALINK_VERSION),
|
option->get(PREF_METALINK_VERSION),
|
||||||
option->get(PREF_METALINK_LANGUAGE),
|
option->get(PREF_METALINK_LANGUAGE),
|
||||||
option->get(PREF_METALINK_OS));
|
option->get(PREF_METALINK_OS));
|
||||||
return entries;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -53,15 +53,18 @@ private:
|
||||||
|
|
||||||
~MetalinkHelper();
|
~MetalinkHelper();
|
||||||
|
|
||||||
static std::deque<SharedHandle<MetalinkEntry> >
|
static void query
|
||||||
query(const SharedHandle<Metalinker>& metalinker, const Option* option);
|
(std::deque<SharedHandle<MetalinkEntry> >& result,
|
||||||
|
const SharedHandle<Metalinker>& metalinker, const Option* option);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static std::deque<SharedHandle<MetalinkEntry> >
|
static void parseAndQuery
|
||||||
parseAndQuery(const std::string& filename, const Option* option);
|
(std::deque<SharedHandle<MetalinkEntry> >& result,
|
||||||
|
const std::string& filename, const Option* option);
|
||||||
|
|
||||||
static std::deque<SharedHandle<MetalinkEntry> >
|
static void parseAndQuery
|
||||||
parseAndQuery(const SharedHandle<BinaryStream>& binaryStream, const Option* option);
|
(std::deque<SharedHandle<MetalinkEntry> >& result,
|
||||||
|
const SharedHandle<BinaryStream>& binaryStream, const Option* option);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -75,17 +75,15 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::deque<SharedHandle<MetalinkEntry> >
|
void Metalinker::queryEntry
|
||||||
Metalinker::queryEntry(const std::string& version,
|
(std::deque<SharedHandle<MetalinkEntry> >& queryResult,
|
||||||
|
const std::string& version,
|
||||||
const std::string& language,
|
const std::string& language,
|
||||||
const std::string& os) const
|
const std::string& os) const
|
||||||
{
|
{
|
||||||
std::deque<SharedHandle<MetalinkEntry> > resultEntries(entries);
|
std::remove_copy_if(entries.begin(), entries.end(),
|
||||||
resultEntries.erase(std::remove_if(resultEntries.begin(),
|
std::back_inserter(queryResult),
|
||||||
resultEntries.end(),
|
std::not1(EntryQuery(version, language, os)));
|
||||||
std::not1(EntryQuery(version, language, os))),
|
|
||||||
resultEntries.end());
|
|
||||||
return resultEntries;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -58,8 +58,10 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::deque<SharedHandle<MetalinkEntry> >
|
void queryEntry
|
||||||
queryEntry(const std::string& version, const std::string& language,
|
(std::deque<SharedHandle<MetalinkEntry> >& queryResult,
|
||||||
|
const std::string& version,
|
||||||
|
const std::string& language,
|
||||||
const std::string& os) const;
|
const std::string& os) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -400,7 +400,12 @@ int main(int argc, char* argv[])
|
||||||
#ifdef ENABLE_METALINK
|
#ifdef ENABLE_METALINK
|
||||||
if(op->defined(PREF_METALINK_FILE)) {
|
if(op->defined(PREF_METALINK_FILE)) {
|
||||||
if(op->get(PREF_SHOW_FILES) == V_TRUE) {
|
if(op->get(PREF_SHOW_FILES) == V_TRUE) {
|
||||||
Util::toStream(std::cout, MetalinkEntry::toFileEntry(MetalinkHelper::parseAndQuery(op->get(PREF_METALINK_FILE), op)));
|
std::deque<SharedHandle<MetalinkEntry> > metalinkEntries;
|
||||||
|
MetalinkHelper::parseAndQuery(metalinkEntries,
|
||||||
|
op->get(PREF_METALINK_FILE), op);
|
||||||
|
std::deque<SharedHandle<FileEntry> > fileEntries;
|
||||||
|
MetalinkEntry::toFileEntry(fileEntries, metalinkEntries);
|
||||||
|
Util::toStream(std::cout, fileEntries);
|
||||||
} else {
|
} else {
|
||||||
returnValue = downloadMetalink(op);
|
returnValue = downloadMetalink(op);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,19 +29,19 @@ CPPUNIT_TEST_SUITE_REGISTRATION( MetalinkHelperTest );
|
||||||
void MetalinkHelperTest::testParseAndQuery()
|
void MetalinkHelperTest::testParseAndQuery()
|
||||||
{
|
{
|
||||||
Option option;
|
Option option;
|
||||||
std::deque<SharedHandle<MetalinkEntry> > entries =
|
std::deque<SharedHandle<MetalinkEntry> > result;
|
||||||
MetalinkHelper::parseAndQuery("test.xml", &option);
|
MetalinkHelper::parseAndQuery(result, "test.xml", &option);
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)5, entries.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)5, result.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetalinkHelperTest::testParseAndQuery_version()
|
void MetalinkHelperTest::testParseAndQuery_version()
|
||||||
{
|
{
|
||||||
Option option;
|
Option option;
|
||||||
option.put(PREF_METALINK_VERSION, "0.5.1");
|
option.put(PREF_METALINK_VERSION, "0.5.1");
|
||||||
std::deque<SharedHandle<MetalinkEntry> > entries =
|
std::deque<SharedHandle<MetalinkEntry> > result;
|
||||||
MetalinkHelper::parseAndQuery("test.xml", &option);
|
MetalinkHelper::parseAndQuery(result, "test.xml", &option);
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, entries.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
|
||||||
SharedHandle<MetalinkEntry> entry = entries.front();
|
SharedHandle<MetalinkEntry> entry = result.front();
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2-0.5.1.tar.bz2"), entry->getPath());
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2-0.5.1.tar.bz2"), entry->getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,27 +43,34 @@ void MetalinkerTest::testQueryEntry() {
|
||||||
version = "0.5.1";
|
version = "0.5.1";
|
||||||
language = "ja-JP";
|
language = "ja-JP";
|
||||||
os = "Linux-m68k";
|
os = "Linux-m68k";
|
||||||
std::deque<SharedHandle<MetalinkEntry> > entries =
|
{
|
||||||
metalinker->queryEntry(version, language, os);
|
std::deque<SharedHandle<MetalinkEntry> > result;
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, entries.size());
|
metalinker->queryEntry(result, version, language, os);
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("0.5.1"), entries.at(0)->version);
|
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("ja-JP"), entries.at(0)->language);
|
CPPUNIT_ASSERT_EQUAL(std::string("0.5.1"), result.at(0)->version);
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("Linux-m68k"), entries.at(0)->os);
|
CPPUNIT_ASSERT_EQUAL(std::string("ja-JP"), result.at(0)->language);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("Linux-m68k"), result.at(0)->os);
|
||||||
|
}
|
||||||
version = "0.6.0";
|
version = "0.6.0";
|
||||||
language = "";
|
language = "";
|
||||||
os = "";
|
os = "";
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)0,
|
{
|
||||||
metalinker->queryEntry(version, language, os).size());
|
std::deque<SharedHandle<MetalinkEntry> > result;
|
||||||
|
metalinker->queryEntry(result, version, language, os);
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)0, result.size());
|
||||||
|
}
|
||||||
|
|
||||||
version = "0.5.2";
|
version = "0.5.2";
|
||||||
language = "";
|
language = "";
|
||||||
os = "";
|
os = "";
|
||||||
entries = metalinker->queryEntry(version, language, os);
|
{
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, entries.size());
|
std::deque<SharedHandle<MetalinkEntry> > result;
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("0.5.2"), entries.at(0)->version);
|
metalinker->queryEntry(result, version, language, os);
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("en-US"), entries.at(0)->language);
|
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("Linux-x86"), entries.at(0)->os);
|
CPPUNIT_ASSERT_EQUAL(std::string("0.5.2"), result.at(0)->version);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("en-US"), result.at(0)->language);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("Linux-x86"), result.at(0)->os);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
Loading…
Reference in New Issue