mirror of https://github.com/aria2/aria2
2009-05-31 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added 'position' parameter to addUri, addTorrent and addMetalink xml-rpc method. * src/RequestGroupMan.cc * src/RequestGroupMan.h * src/XmlRpcMethodImpl.cc * test/XmlRpcMethodTest.ccpull/1/head
parent
918c6bf38d
commit
960bab86c7
|
@ -1,3 +1,12 @@
|
|||
2009-05-31 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Added 'position' parameter to addUri, addTorrent and addMetalink
|
||||
xml-rpc method.
|
||||
* src/RequestGroupMan.cc
|
||||
* src/RequestGroupMan.h
|
||||
* src/XmlRpcMethodImpl.cc
|
||||
* test/XmlRpcMethodTest.cc
|
||||
|
||||
2009-05-29 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Removed Peer.cc from compile source list when --disable-bittorrent
|
||||
|
|
|
@ -112,11 +112,26 @@ void RequestGroupMan::addReservedGroup(const RequestGroups& groups)
|
|||
_reservedGroups.insert(_reservedGroups.end(), groups.begin(), groups.end());
|
||||
}
|
||||
|
||||
void RequestGroupMan::addReservedGroup(const RequestGroupHandle& group)
|
||||
void RequestGroupMan::addReservedGroup(const SharedHandle<RequestGroup>& group)
|
||||
{
|
||||
_reservedGroups.push_back(group);
|
||||
}
|
||||
|
||||
void RequestGroupMan::insertReservedGroup
|
||||
(size_t pos, const std::deque<SharedHandle<RequestGroup> >& groups)
|
||||
{
|
||||
_reservedGroups.insert
|
||||
(_reservedGroups.begin()+std::min(_reservedGroups.size(), pos),
|
||||
groups.begin(), groups.end());
|
||||
}
|
||||
|
||||
void RequestGroupMan::insertReservedGroup
|
||||
(size_t pos, const SharedHandle<RequestGroup>& group)
|
||||
{
|
||||
_reservedGroups.insert
|
||||
(_reservedGroups.begin()+std::min(_reservedGroups.size(), pos), group);
|
||||
}
|
||||
|
||||
size_t RequestGroupMan::countRequestGroup() const
|
||||
{
|
||||
return _requestGroups.size();
|
||||
|
|
|
@ -106,6 +106,11 @@ public:
|
|||
|
||||
void addReservedGroup(const SharedHandle<RequestGroup>& group);
|
||||
|
||||
void insertReservedGroup
|
||||
(size_t pos, const std::deque<SharedHandle<RequestGroup> >& groups);
|
||||
|
||||
void insertReservedGroup(size_t pos, const SharedHandle<RequestGroup>& group);
|
||||
|
||||
size_t countRequestGroup() const;
|
||||
|
||||
SharedHandle<RequestGroup> getRequestGroup(size_t index) const;
|
||||
|
|
|
@ -81,6 +81,34 @@ static BDE createGIDResponse(int32_t gid)
|
|||
return BDE(Util::itos(gid));
|
||||
}
|
||||
|
||||
static BDE addRequestGroup(const SharedHandle<RequestGroup>& group,
|
||||
DownloadEngine* e,
|
||||
bool posGiven, int pos)
|
||||
{
|
||||
if(posGiven) {
|
||||
e->_requestGroupMan->insertReservedGroup(pos, group);
|
||||
} else {
|
||||
e->_requestGroupMan->addReservedGroup(group);
|
||||
}
|
||||
return createGIDResponse(group->getGID());
|
||||
}
|
||||
|
||||
static bool hasDictParam(const BDE& params, size_t index)
|
||||
{
|
||||
return params.size() > index && params[index].isDict();
|
||||
}
|
||||
|
||||
static void getPosParam(const BDE& params, size_t posParamIndex,
|
||||
bool& posGiven, size_t& pos)
|
||||
{
|
||||
if(params.size() > posParamIndex && params[posParamIndex].isInteger()) {
|
||||
pos = params[posParamIndex].i();
|
||||
posGiven = true;
|
||||
} else {
|
||||
posGiven = false;
|
||||
}
|
||||
}
|
||||
|
||||
BDE AddUriXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
|
||||
{
|
||||
const BDE& params = req._params;
|
||||
|
@ -97,17 +125,20 @@ BDE AddUriXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
|
|||
}
|
||||
|
||||
SharedHandle<Option> requestOption(new Option(*e->option));
|
||||
if(params.size() > 1 && params[1].isDict()) {
|
||||
if(hasDictParam(params, 1)) {
|
||||
gatherRequestOption(requestOption, params[1]);
|
||||
}
|
||||
size_t pos = 0;
|
||||
bool posGiven = false;
|
||||
getPosParam(params, 2, posGiven, pos);
|
||||
|
||||
std::deque<SharedHandle<RequestGroup> > result;
|
||||
createRequestGroupForUri(result, requestOption, uris,
|
||||
/* ignoreForceSeq = */ true,
|
||||
/* ignoreNonURI = */ true);
|
||||
|
||||
if(!result.empty()) {
|
||||
e->_requestGroupMan->addReservedGroup(result.front());
|
||||
return createGIDResponse(result.front()->getGID());
|
||||
return addRequestGroup(result.front(), e, posGiven, pos);
|
||||
} else {
|
||||
throw DL_ABORT_EX("No URI to download.");
|
||||
}
|
||||
|
@ -132,19 +163,21 @@ BDE AddTorrentXmlRpcMethod::process
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
SharedHandle<Option> requestOption(new Option(*e->option));
|
||||
if(params.size() > 2 && params[2].isDict()) {
|
||||
if(hasDictParam(params, 2)) {
|
||||
gatherRequestOption(requestOption, params[2]);
|
||||
}
|
||||
size_t pos = 0;
|
||||
bool posGiven = false;
|
||||
getPosParam(params, 3, posGiven, pos);
|
||||
|
||||
std::deque<SharedHandle<RequestGroup> > result;
|
||||
createRequestGroupForBitTorrent(result, requestOption,
|
||||
uris,
|
||||
params[0].s());
|
||||
|
||||
if(!result.empty()) {
|
||||
e->_requestGroupMan->addReservedGroup(result.front());
|
||||
return createGIDResponse(result.front()->getGID());
|
||||
return addRequestGroup(result.front(), e, posGiven, pos);
|
||||
} else {
|
||||
throw DL_ABORT_EX("No Torrent to download.");
|
||||
}
|
||||
|
@ -162,13 +195,21 @@ BDE AddMetalinkXmlRpcMethod::process
|
|||
}
|
||||
|
||||
SharedHandle<Option> requestOption(new Option(*e->option));
|
||||
if(params.size() > 1 && params[1].isDict()) {
|
||||
if(hasDictParam(params, 1)) {
|
||||
gatherRequestOption(requestOption, params[1]);
|
||||
}
|
||||
};
|
||||
size_t pos = 0;
|
||||
bool posGiven = false;
|
||||
getPosParam(params, 2, posGiven, pos);
|
||||
|
||||
std::deque<SharedHandle<RequestGroup> > result;
|
||||
createRequestGroupForMetalink(result, requestOption, params[0].s());
|
||||
if(!result.empty()) {
|
||||
if(posGiven) {
|
||||
e->_requestGroupMan->insertReservedGroup(pos, result);
|
||||
} else {
|
||||
e->_requestGroupMan->addReservedGroup(result);
|
||||
}
|
||||
BDE gids = BDE::list();
|
||||
for(std::deque<SharedHandle<RequestGroup> >::const_iterator i =
|
||||
result.begin(); i != result.end(); ++i) {
|
||||
|
|
|
@ -29,15 +29,18 @@ class XmlRpcMethodTest:public CppUnit::TestFixture {
|
|||
CPPUNIT_TEST(testAddUri_withoutUri);
|
||||
CPPUNIT_TEST(testAddUri_notUri);
|
||||
CPPUNIT_TEST(testAddUri_withBadOption);
|
||||
CPPUNIT_TEST(testAddUri_withPosition);
|
||||
#ifdef ENABLE_BITTORRENT
|
||||
CPPUNIT_TEST(testAddTorrent);
|
||||
CPPUNIT_TEST(testAddTorrent_withoutTorrent);
|
||||
CPPUNIT_TEST(testAddTorrent_notBase64Torrent);
|
||||
CPPUNIT_TEST(testAddTorrent_withPosition);
|
||||
#endif // ENABLE_BITTORRENT
|
||||
#ifdef ENABLE_METALINK
|
||||
CPPUNIT_TEST(testAddMetalink);
|
||||
CPPUNIT_TEST(testAddMetalink_withoutMetalink);
|
||||
CPPUNIT_TEST(testAddMetalink_notBase64Metalink);
|
||||
CPPUNIT_TEST(testAddMetalink_withPosition);
|
||||
#endif // ENABLE_METALINK
|
||||
CPPUNIT_TEST(testChangeOption);
|
||||
CPPUNIT_TEST(testChangeOption_withBadOption);
|
||||
|
@ -69,15 +72,18 @@ public:
|
|||
void testAddUri_withoutUri();
|
||||
void testAddUri_notUri();
|
||||
void testAddUri_withBadOption();
|
||||
void testAddUri_withPosition();
|
||||
#ifdef ENABLE_BITTORRENT
|
||||
void testAddTorrent();
|
||||
void testAddTorrent_withoutTorrent();
|
||||
void testAddTorrent_notBase64Torrent();
|
||||
void testAddTorrent_withPosition();
|
||||
#endif // ENABLE_BITTORRENT
|
||||
#ifdef ENABLE_METALINK
|
||||
void testAddMetalink();
|
||||
void testAddMetalink_withoutMetalink();
|
||||
void testAddMetalink_notBase64Metalink();
|
||||
void testAddMetalink_withPosition();
|
||||
#endif // ENABLE_METALINK
|
||||
void testChangeOption();
|
||||
void testChangeOption_withBadOption();
|
||||
|
@ -150,6 +156,28 @@ void XmlRpcMethodTest::testAddUri_withBadOption()
|
|||
CPPUNIT_ASSERT_EQUAL(1, res._code);
|
||||
}
|
||||
|
||||
void XmlRpcMethodTest::testAddUri_withPosition()
|
||||
{
|
||||
AddUriXmlRpcMethod m;
|
||||
XmlRpcRequest req1("aria2.addUri", BDE::list());
|
||||
req1._params << BDE::list();
|
||||
req1._params[0] << BDE("http://uri1");
|
||||
XmlRpcResponse res1 = m.execute(req1, _e.get());
|
||||
CPPUNIT_ASSERT_EQUAL(0, res1._code);
|
||||
|
||||
XmlRpcRequest req2("aria2.addUri", BDE::list());
|
||||
req2._params << BDE::list();
|
||||
req2._params[0] << BDE("http://uri2");
|
||||
req2._params << BDE::dict();
|
||||
req2._params << BDE((int64_t)0);
|
||||
m.execute(req2, _e.get());
|
||||
|
||||
std::string uri =
|
||||
_e->_requestGroupMan->getReservedGroups()[0]->getRemainingUris()[0];
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://uri2"), uri);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_BITTORRENT
|
||||
void XmlRpcMethodTest::testAddTorrent()
|
||||
{
|
||||
|
@ -200,6 +228,29 @@ void XmlRpcMethodTest::testAddTorrent_notBase64Torrent()
|
|||
XmlRpcResponse res = m.execute(req, _e.get());
|
||||
CPPUNIT_ASSERT_EQUAL(1, res._code);
|
||||
}
|
||||
|
||||
void XmlRpcMethodTest::testAddTorrent_withPosition()
|
||||
{
|
||||
AddTorrentXmlRpcMethod m;
|
||||
XmlRpcRequest req1("aria2.addTorrent", BDE::list());
|
||||
req1._params << BDE(readFile("test.torrent"));
|
||||
req1._params << BDE::list();
|
||||
req1._params << BDE::dict();
|
||||
XmlRpcResponse res1 = m.execute(req1, _e.get());
|
||||
CPPUNIT_ASSERT_EQUAL(0, res1._code);
|
||||
|
||||
XmlRpcRequest req2("aria2.addTorrent", BDE::list());
|
||||
req2._params << BDE(readFile("single.torrent"));
|
||||
req2._params << BDE::list();
|
||||
req2._params << BDE::dict();
|
||||
req2._params << BDE((int64_t)0);
|
||||
m.execute(req2, _e.get());
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1,
|
||||
_e->_requestGroupMan->getReservedGroups()[0]->
|
||||
getDownloadContext()->getFileEntries().size());
|
||||
}
|
||||
|
||||
#endif // ENABLE_BITTORRENT
|
||||
|
||||
#ifdef ENABLE_METALINK
|
||||
|
@ -252,6 +303,29 @@ void XmlRpcMethodTest::testAddMetalink_notBase64Metalink()
|
|||
XmlRpcResponse res = m.execute(req, _e.get());
|
||||
CPPUNIT_ASSERT_EQUAL(1, res._code);
|
||||
}
|
||||
|
||||
void XmlRpcMethodTest::testAddMetalink_withPosition()
|
||||
{
|
||||
AddUriXmlRpcMethod m1;
|
||||
XmlRpcRequest req1("aria2.addUri", BDE::list());
|
||||
req1._params << BDE::list();
|
||||
req1._params[0] << BDE("http://uri");
|
||||
XmlRpcResponse res1 = m1.execute(req1, _e.get());
|
||||
CPPUNIT_ASSERT_EQUAL(0, res1._code);
|
||||
|
||||
AddMetalinkXmlRpcMethod m2;
|
||||
XmlRpcRequest req2("ari2.addMetalink", BDE::list());
|
||||
req2._params << BDE(readFile("2files.metalink"));
|
||||
req2._params << BDE::dict();
|
||||
req2._params << BDE((int64_t)0);
|
||||
XmlRpcResponse res2 = m2.execute(req2, _e.get());
|
||||
CPPUNIT_ASSERT_EQUAL(0, res2._code);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/aria2-5.0.0.tar.bz2"),
|
||||
_e->_requestGroupMan->getReservedGroups()[0]->
|
||||
getFilePath());
|
||||
}
|
||||
|
||||
#endif // ENABLE_METALINK
|
||||
|
||||
void XmlRpcMethodTest::testChangeOption()
|
||||
|
|
Loading…
Reference in New Issue