diff --git a/ChangeLog b/ChangeLog index fcf974ac..1aeaac51 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2009-05-08 Tatsuhiro Tsujikawa + + Added remove xml-rpc command which removes specified download. + There is a known issue: the removed unfinished downloads are + reported ERR when aria2 exits. They should be reported as INPR. + * src/RequestGroupMan.cc + * src/RequestGroupMan.h + * src/XmlRpcMethodFactory.cc + * src/XmlRpcMethodImpl.cc + * src/XmlRpcMethodImpl.h + 2009-05-08 Tatsuhiro Tsujikawa If --enable-http-server is enabled, don't stop aria2 when all diff --git a/src/RequestGroupMan.cc b/src/RequestGroupMan.cc index 714c1efd..4084bdbe 100644 --- a/src/RequestGroupMan.cc +++ b/src/RequestGroupMan.cc @@ -133,6 +133,18 @@ RequestGroupMan::getRequestGroups() const return _requestGroups; } +SharedHandle +RequestGroupMan::findRequestGroup(int32_t gid) const +{ + for(std::deque >::const_iterator i = + _requestGroups.begin(); i != _requestGroups.end(); ++i) { + if((*i)->getGID() == gid) { + return *i; + } + } + return SharedHandle(); +} + const std::deque >& RequestGroupMan::getReservedGroups() const { diff --git a/src/RequestGroupMan.h b/src/RequestGroupMan.h index e9d1b607..b9702fb0 100644 --- a/src/RequestGroupMan.h +++ b/src/RequestGroupMan.h @@ -112,6 +112,8 @@ public: const std::deque >& getRequestGroups() const; + SharedHandle findRequestGroup(int32_t gid) const; + const std::deque >& getReservedGroups() const; void showDownloadResults(std::ostream& o) const; diff --git a/src/XmlRpcMethodFactory.cc b/src/XmlRpcMethodFactory.cc index b1c19755..57e801a3 100644 --- a/src/XmlRpcMethodFactory.cc +++ b/src/XmlRpcMethodFactory.cc @@ -46,6 +46,8 @@ XmlRpcMethodFactory::create(const std::string& methodName) { if(methodName == "aria2.addURI") { return SharedHandle(new AddURIXmlRpcMethod()); + } else if(methodName == "aria2.remove") { + return SharedHandle(new RemoveXmlRpcMethod()); } else { return SharedHandle(new FailXmlRpcMethod()); } diff --git a/src/XmlRpcMethodImpl.cc b/src/XmlRpcMethodImpl.cc index ec4aa38a..c4c09d19 100644 --- a/src/XmlRpcMethodImpl.cc +++ b/src/XmlRpcMethodImpl.cc @@ -89,6 +89,32 @@ BDE AddURIXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e) } } +BDE RemoveXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e) +{ + const BDE& params = req._params; + assert(params.isList()); + + if(params.empty() || !params[0].isString()) { + throw DlAbortEx("GID is not provided."); + } + + int32_t gid = Util::parseInt(params[0].s()); + + SharedHandle group = e->_requestGroupMan->findRequestGroup(gid); + + if(group.isNull()) { + throw DlAbortEx + (StringFormat("Active Download not found for GID#%d", gid).str()); + } + + group->setHaltRequested(true); + + BDE resParams = BDE::list(); + resParams << BDE("OK"); + resParams << BDE(Util::itos(gid)); + return resParams; +} + BDE FailXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e) { throw DlAbortEx diff --git a/src/XmlRpcMethodImpl.h b/src/XmlRpcMethodImpl.h index dc9be756..ef9352a4 100644 --- a/src/XmlRpcMethodImpl.h +++ b/src/XmlRpcMethodImpl.h @@ -46,6 +46,11 @@ protected: virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e); }; +class RemoveXmlRpcMethod:public XmlRpcMethod { +protected: + virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e); +}; + class FailXmlRpcMethod:public XmlRpcMethod { protected: virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);