mirror of https://github.com/aria2/aria2
2009-05-08 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added addTorrentFile xml-rpc command which receives uploaded torrent file and add download for it. * src/RequestGroupMan.cc * src/XmlRpcMethodFactory.cc * src/XmlRpcMethodImpl.cc * src/XmlRpcMethodImpl.h * src/download_helper.cc * src/download_helper.hpull/1/head
parent
c659b07b86
commit
c45ff588d1
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2009-05-08 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Added addTorrentFile xml-rpc command which receives uploaded
|
||||
torrent file and add download for it.
|
||||
* src/RequestGroupMan.cc
|
||||
* src/XmlRpcMethodFactory.cc
|
||||
* src/XmlRpcMethodImpl.cc
|
||||
* src/XmlRpcMethodImpl.h
|
||||
* src/download_helper.cc
|
||||
* src/download_helper.h
|
||||
|
||||
2009-05-08 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Added remove xml-rpc command which removes specified download.
|
||||
|
|
|
@ -346,6 +346,7 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
|
|||
e->addCommand(commands);
|
||||
} catch(RecoverableException& ex) {
|
||||
_logger->error(EX_EXCEPTION_CAUGHT, ex);
|
||||
groupToAdd->releaseRuntimeResource(e);
|
||||
_downloadResults.push_back(groupToAdd->createDownloadResult());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,8 @@ XmlRpcMethodFactory::create(const std::string& methodName)
|
|||
{
|
||||
if(methodName == "aria2.addURI") {
|
||||
return SharedHandle<XmlRpcMethod>(new AddURIXmlRpcMethod());
|
||||
} else if(methodName == "aria2.addTorrent") {
|
||||
return SharedHandle<XmlRpcMethod>(new AddTorrentFileXmlRpcMethod());
|
||||
} else if(methodName == "aria2.remove") {
|
||||
return SharedHandle<XmlRpcMethod>(new RemoveXmlRpcMethod());
|
||||
} else {
|
||||
|
|
|
@ -54,6 +54,14 @@ namespace aria2 {
|
|||
|
||||
namespace xmlrpc {
|
||||
|
||||
static BDE createGIDResponse(int32_t gid)
|
||||
{
|
||||
BDE resParams = BDE::list();
|
||||
resParams << BDE("OK");
|
||||
resParams << BDE(Util::itos(gid));
|
||||
return resParams;
|
||||
}
|
||||
|
||||
BDE AddURIXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
|
||||
{
|
||||
const BDE& params = req._params;
|
||||
|
@ -80,15 +88,35 @@ BDE AddURIXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
|
|||
|
||||
if(!result.empty()) {
|
||||
e->_requestGroupMan->addReservedGroup(result.front());
|
||||
BDE resParams = BDE::list();
|
||||
resParams << BDE("OK");
|
||||
resParams << BDE(Util::itos(result.front()->getGID()));
|
||||
return resParams;
|
||||
return createGIDResponse(result.front()->getGID());
|
||||
} else {
|
||||
throw DlAbortEx("No URI to download.");
|
||||
}
|
||||
}
|
||||
|
||||
BDE AddTorrentFileXmlRpcMethod::process
|
||||
(const XmlRpcRequest& req, DownloadEngine* e)
|
||||
{
|
||||
const BDE& params = req._params;
|
||||
assert(params.isList());
|
||||
if(params.empty() || !params[0].isString()) {
|
||||
throw DlAbortEx("Torrent data is not provided.");
|
||||
}
|
||||
|
||||
// TODO should accect uris from xml rpc request
|
||||
std::deque<SharedHandle<RequestGroup> > result;
|
||||
createRequestGroupForBitTorrent(result, *e->option,
|
||||
std::deque<std::string>(),
|
||||
params[0].s());
|
||||
|
||||
if(!result.empty()) {
|
||||
e->_requestGroupMan->addReservedGroup(result.front());
|
||||
return createGIDResponse(result.front()->getGID());
|
||||
} else {
|
||||
throw DlAbortEx("No Torrent to download.");
|
||||
}
|
||||
}
|
||||
|
||||
BDE RemoveXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
|
||||
{
|
||||
const BDE& params = req._params;
|
||||
|
|
|
@ -51,6 +51,11 @@ protected:
|
|||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
||||
};
|
||||
|
||||
class AddTorrentFileXmlRpcMethod:public XmlRpcMethod {
|
||||
protected:
|
||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
||||
};
|
||||
|
||||
class FailXmlRpcMethod:public XmlRpcMethod {
|
||||
protected:
|
||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
||||
|
|
|
@ -132,12 +132,17 @@ SharedHandle<RequestGroup>
|
|||
createBtRequestGroup(const std::string& torrentFilePath,
|
||||
const Option& op,
|
||||
const std::deque<std::string>& auxUris,
|
||||
const Option& requestOption)
|
||||
const Option& requestOption,
|
||||
const std::string& torrentData = "")
|
||||
{
|
||||
SharedHandle<RequestGroup> rg(new RequestGroup(&op, auxUris));
|
||||
SharedHandle<DefaultBtContext> btContext(new DefaultBtContext());
|
||||
btContext->setDir(requestOption.get(PREF_DIR));
|
||||
btContext->load(torrentFilePath);// may throw exception
|
||||
if(torrentData.empty()) {
|
||||
btContext->load(torrentFilePath);// may throw exception
|
||||
} else {
|
||||
btContext->loadFromMemory(torrentData, "default"); // may throw exception
|
||||
}
|
||||
if(op.defined(PREF_PEER_ID_PREFIX)) {
|
||||
btContext->setPeerIdPrefix(op.get(PREF_PEER_ID_PREFIX));
|
||||
}
|
||||
|
@ -158,7 +163,8 @@ createBtRequestGroup(const std::string& torrentFilePath,
|
|||
|
||||
void createRequestGroupForBitTorrent
|
||||
(std::deque<SharedHandle<RequestGroup> >& result, const Option& op,
|
||||
const std::deque<std::string>& uris)
|
||||
const std::deque<std::string>& uris,
|
||||
const std::string& torrentData)
|
||||
{
|
||||
std::deque<std::string> nargs;
|
||||
if(op.get(PREF_PARAMETERIZED_URI) == V_TRUE) {
|
||||
|
@ -171,7 +177,8 @@ void createRequestGroupForBitTorrent
|
|||
std::deque<std::string> auxUris;
|
||||
splitURI(auxUris, nargs.begin(), nargs.end(), numSplit);
|
||||
SharedHandle<RequestGroup> rg =
|
||||
createBtRequestGroup(op.get(PREF_TORRENT_FILE), op, auxUris, op);
|
||||
createBtRequestGroup(op.get(PREF_TORRENT_FILE), op, auxUris, op,
|
||||
torrentData);
|
||||
rg->setNumConcurrentCommand(numSplit);
|
||||
result.push_back(rg);
|
||||
}
|
||||
|
|
|
@ -51,11 +51,14 @@ class Option;
|
|||
const std::vector<std::string>& listRequestOptions();
|
||||
|
||||
#ifdef ENABLE_BITTORRENT
|
||||
// Create RequestGroup object using torrent file specified by torrent-file
|
||||
// option. In this function, force-sequential is ignored.
|
||||
// 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,
|
||||
// force-sequential is ignored.
|
||||
void createRequestGroupForBitTorrent
|
||||
(std::deque<SharedHandle<RequestGroup> >& result, const Option& op,
|
||||
const std::deque<std::string>& uris);
|
||||
const std::deque<std::string>& uris,
|
||||
const std::string& torrentData = "");
|
||||
#endif // ENABLE_BITTORRENT
|
||||
|
||||
#ifdef ENABLE_METALINK
|
||||
|
|
Loading…
Reference in New Issue