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

Added addMetalink XML-RPC command.
	* src/XmlRpcMethodFactory.cc
	* src/XmlRpcMethodImpl.cc
	* src/XmlRpcMethodImpl.h
	* src/download_helper.cc
	* src/download_helper.h
pull/1/head
Tatsuhiro Tsujikawa 2009-05-13 14:13:36 +00:00
parent eb0cb42c72
commit cbaf0619d9
6 changed files with 66 additions and 9 deletions

View File

@ -1,3 +1,12 @@
2009-05-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added addMetalink XML-RPC command.
* src/XmlRpcMethodFactory.cc
* src/XmlRpcMethodImpl.cc
* src/XmlRpcMethodImpl.h
* src/download_helper.cc
* src/download_helper.h
2009-05-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed the bug that POU peers are never choked in seeding.

View File

@ -48,6 +48,8 @@ XmlRpcMethodFactory::create(const std::string& methodName)
return SharedHandle<XmlRpcMethod>(new AddUriXmlRpcMethod());
} else if(methodName == "aria2.addTorrent") {
return SharedHandle<XmlRpcMethod>(new AddTorrentXmlRpcMethod());
} else if(methodName == "aria2.addMetalink") {
return SharedHandle<XmlRpcMethod>(new AddMetalinkXmlRpcMethod());
} else if(methodName == "aria2.remove") {
return SharedHandle<XmlRpcMethod>(new RemoveXmlRpcMethod());
} else if(methodName == "aria2.tellStatus") {

View File

@ -140,6 +140,37 @@ BDE AddTorrentXmlRpcMethod::process
}
}
BDE AddMetalinkXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
{
const BDE& params = req._params;
assert(params.isList());
if(params.empty() || !params[0].isString()) {
throw DlAbortEx("Metalink data is not provided.");
}
SharedHandle<Option> requestOption(new Option(*e->option));
if(params.size() > 1 && params[1].isDict()) {
gatherRequestOption(requestOption, params[1]);
}
std::deque<SharedHandle<RequestGroup> > result;
createRequestGroupForMetalink(result, requestOption, params[0].s());
if(!result.empty()) {
e->_requestGroupMan->addReservedGroup(result);
BDE resParams = BDE::list();
BDE gids = BDE::list();
for(std::deque<SharedHandle<RequestGroup> >::const_iterator i =
result.begin(); i != result.end(); ++i) {
gids << BDE(Util::itos((*i)->getGID()));
}
resParams << gids;
return resParams;
} else {
throw DlAbortEx("No files to download.");
}
}
BDE RemoveXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
{
const BDE& params = req._params;

View File

@ -56,6 +56,11 @@ protected:
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
};
class AddMetalinkXmlRpcMethod:public XmlRpcMethod {
protected:
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
};
class GetUrisXmlRpcMethod:public XmlRpcMethod {
protected:
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);

View File

@ -60,6 +60,7 @@
#include "Util.h"
#include "array_fun.h"
#include "OptionHandler.h"
#include "ByteArrayDiskWriter.h"
namespace aria2 {
@ -252,11 +253,18 @@ void createRequestGroupForBitTorrent
#ifdef ENABLE_METALINK
void createRequestGroupForMetalink
(std::deque<SharedHandle<RequestGroup> >& result,
const SharedHandle<Option>& option)
const SharedHandle<Option>& option,
const std::string& metalinkData)
{
Metalink2RequestGroup().generate(result,
option->get(PREF_METALINK_FILE),
option);
if(metalinkData.empty()) {
Metalink2RequestGroup().generate(result,
option->get(PREF_METALINK_FILE),
option);
} else {
SharedHandle<ByteArrayDiskWriter> dw(new ByteArrayDiskWriter());
dw->setString(metalinkData);
Metalink2RequestGroup().generate(result, dw, option);
}
if(result.empty()) {
throw DlAbortEx(MSG_NO_FILES_TO_DOWNLOAD);
}

View File

@ -52,8 +52,8 @@ const std::vector<std::string>& listRequestOptions();
#ifdef ENABLE_BITTORRENT
// Create RequestGroup object using torrent file specified by
// torrent-file option. If torrentData is specified, then it is used
// as a content of torrent file in stead. In this function,
// torrent-file option. If non-empty torrentData is specified, then
// it is used as a content of torrent file instead. In this function,
// force-sequential is ignored.
void createRequestGroupForBitTorrent
(std::deque<SharedHandle<RequestGroup> >& result,
@ -63,11 +63,13 @@ void createRequestGroupForBitTorrent
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
// Create RequestGroup objects using Metalink file specified by metalink-file
// option.
// Create RequestGroup objects using Metalink file specified by
// metalink-file option. If non-empty metalinkData is specified, it is
// used as a content of metalink file instead.
void createRequestGroupForMetalink
(std::deque<SharedHandle<RequestGroup> >& result,
const SharedHandle<Option>& option);
const SharedHandle<Option>& option,
const std::string& metalinkData = "");
#endif // ENABLE_METALINK
// Create RequestGroup objects from reading file specified by input-file option.