mirror of https://github.com/aria2/aria2
2009-12-20 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added getOption and getGlobalOption XML-RPC method. getOption takes GID as a parameter and returns its options as struct. getGlobalOption takes no parameter and returns global options. Because global option is used as a template for the option of newly added downloads, it includes options returned by getOption. * src/Option.h * src/XmlRpcMethodFactory.cc * src/XmlRpcMethodImpl.cc * src/XmlRpcMethodImpl.hpull/1/head
parent
e77e1ec24d
commit
26e319df43
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
||||||
|
2009-12-20 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Added getOption and getGlobalOption XML-RPC method. getOption
|
||||||
|
takes GID as a parameter and returns its options as struct.
|
||||||
|
getGlobalOption takes no parameter and returns global
|
||||||
|
options. Because global option is used as a template for the
|
||||||
|
option of newly added downloads, it includes options returned by
|
||||||
|
getOption.
|
||||||
|
* src/Option.h
|
||||||
|
* src/XmlRpcMethodFactory.cc
|
||||||
|
* src/XmlRpcMethodImpl.cc
|
||||||
|
* src/XmlRpcMethodImpl.h
|
||||||
|
|
||||||
2009-12-20 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2009-12-20 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Sort _optionHandlers in OptionParser by name in ascending order.
|
Sort _optionHandlers in OptionParser by name in ascending order.
|
||||||
|
|
10
src/Option.h
10
src/Option.h
|
@ -64,6 +64,16 @@ public:
|
||||||
void remove(const std::string& name);
|
void remove(const std::string& name);
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
std::map<std::string, std::string>::const_iterator begin() const
|
||||||
|
{
|
||||||
|
return table.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, std::string>::const_iterator end() const
|
||||||
|
{
|
||||||
|
return table.end();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -73,8 +73,12 @@ XmlRpcMethodFactory::create(const std::string& methodName)
|
||||||
return SharedHandle<XmlRpcMethod>(new TellActiveXmlRpcMethod());
|
return SharedHandle<XmlRpcMethod>(new TellActiveXmlRpcMethod());
|
||||||
} else if(methodName == "aria2.tellWaiting") {
|
} else if(methodName == "aria2.tellWaiting") {
|
||||||
return SharedHandle<XmlRpcMethod>(new TellWaitingXmlRpcMethod());
|
return SharedHandle<XmlRpcMethod>(new TellWaitingXmlRpcMethod());
|
||||||
|
} else if(methodName == "aria2.getOption") {
|
||||||
|
return SharedHandle<XmlRpcMethod>(new GetOptionXmlRpcMethod());
|
||||||
} else if(methodName == "aria2.changeOption") {
|
} else if(methodName == "aria2.changeOption") {
|
||||||
return SharedHandle<XmlRpcMethod>(new ChangeOptionXmlRpcMethod());
|
return SharedHandle<XmlRpcMethod>(new ChangeOptionXmlRpcMethod());
|
||||||
|
} else if(methodName == "aria2.getGlobalOption") {
|
||||||
|
return SharedHandle<XmlRpcMethod>(new GetGlobalOptionXmlRpcMethod());
|
||||||
} else if(methodName == "aria2.changeGlobalOption") {
|
} else if(methodName == "aria2.changeGlobalOption") {
|
||||||
return SharedHandle<XmlRpcMethod>(new ChangeGlobalOptionXmlRpcMethod());
|
return SharedHandle<XmlRpcMethod>(new ChangeGlobalOptionXmlRpcMethod());
|
||||||
} else if(methodName == "aria2.purgeDownloadResult") {
|
} else if(methodName == "aria2.purgeDownloadResult") {
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "FeatureConfig.h"
|
#include "FeatureConfig.h"
|
||||||
|
#include "array_fun.h"
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
# include "bittorrent_helper.h"
|
# include "bittorrent_helper.h"
|
||||||
# include "BtRegistry.h"
|
# include "BtRegistry.h"
|
||||||
|
@ -679,6 +680,53 @@ BDE GetVersionXmlRpcMethod::process
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename InputIterator>
|
||||||
|
static void pushRequestOption
|
||||||
|
(BDE& dict, InputIterator optionFirst, InputIterator optionLast)
|
||||||
|
{
|
||||||
|
const std::set<std::string>& requestOptions = listRequestOptions();
|
||||||
|
for(; optionFirst != optionLast; ++optionFirst) {
|
||||||
|
if(requestOptions.count((*optionFirst).first)) {
|
||||||
|
dict[(*optionFirst).first] = (*optionFirst).second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BDE GetOptionXmlRpcMethod::process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e)
|
||||||
|
{
|
||||||
|
const BDE& params = req._params;
|
||||||
|
assert(params.isList());
|
||||||
|
if(params.empty() || !params[0].isString()) {
|
||||||
|
throw DL_ABORT_EX(MSG_GID_NOT_PROVIDED);
|
||||||
|
}
|
||||||
|
int32_t gid = util::parseInt(params[0].s());
|
||||||
|
|
||||||
|
SharedHandle<RequestGroup> group = findRequestGroup(e->_requestGroupMan, gid);
|
||||||
|
if(group.isNull()) {
|
||||||
|
throw DL_ABORT_EX
|
||||||
|
(StringFormat("Cannot get option for GID#%d", gid).str());
|
||||||
|
}
|
||||||
|
BDE result = BDE::dict();
|
||||||
|
SharedHandle<Option> option = group->getOption();
|
||||||
|
pushRequestOption(result, option->begin(), option->end());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
BDE GetGlobalOptionXmlRpcMethod::process
|
||||||
|
(const XmlRpcRequest& req, DownloadEngine* e)
|
||||||
|
{
|
||||||
|
BDE result = BDE::dict();
|
||||||
|
for(std::map<std::string, std::string>::const_iterator i = e->option->begin();
|
||||||
|
i != e->option->end(); ++i) {
|
||||||
|
SharedHandle<OptionHandler> h = _optionParser->findByName((*i).first);
|
||||||
|
if(!h.isNull() && !h->isHidden()) {
|
||||||
|
result[(*i).first] = (*i).second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
BDE NoSuchMethodXmlRpcMethod::process
|
BDE NoSuchMethodXmlRpcMethod::process
|
||||||
(const XmlRpcRequest& req, DownloadEngine* e)
|
(const XmlRpcRequest& req, DownloadEngine* e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -120,6 +120,16 @@ protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class GetOptionXmlRpcMethod:public XmlRpcMethod {
|
||||||
|
protected:
|
||||||
|
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
|
};
|
||||||
|
|
||||||
|
class GetGlobalOptionXmlRpcMethod:public XmlRpcMethod {
|
||||||
|
protected:
|
||||||
|
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
|
};
|
||||||
|
|
||||||
class NoSuchMethodXmlRpcMethod:public XmlRpcMethod {
|
class NoSuchMethodXmlRpcMethod:public XmlRpcMethod {
|
||||||
protected:
|
protected:
|
||||||
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
|
||||||
|
|
Loading…
Reference in New Issue