Renamed classes in abstract layer of RPC service from XmlRpc* to Rpc*.

Now JSON-RPC is available by default regardless of XML library.
XML-RPC becomes available when XML library is available.
pull/1/head
Tatsuhiro Tsujikawa 2011-03-14 16:38:54 +09:00
parent 5a1fb3875f
commit f0cfbb21c1
37 changed files with 715 additions and 711 deletions

View File

@ -72,9 +72,7 @@
#include "SelectEventPoll.h"
#include "DlAbortEx.h"
#include "FileAllocationEntry.h"
#ifdef ENABLE_XML_RPC
# include "HttpListenCommand.h"
#endif // ENABLE_XML_RPC
#include "HttpListenCommand.h"
namespace aria2 {
@ -165,7 +163,6 @@ DownloadEngineFactory::newDownloadEngine
stopSec));
}
}
#ifdef ENABLE_XML_RPC
if(op->getAsBool(PREF_ENABLE_XML_RPC)) {
static int families[] = { AF_INET, AF_INET6 };
size_t familiesLength = op->getAsBool(PREF_DISABLE_IPV6)?1:2;
@ -179,7 +176,6 @@ DownloadEngineFactory::newDownloadEngine
}
}
}
#endif // ENABLE_XML_RPC
return e;
}

View File

@ -45,7 +45,7 @@
namespace aria2 {
namespace xmlrpc {
namespace rpc {
namespace {
struct SessionData {
@ -104,7 +104,7 @@ void mlCharacters(void* userData, const char* ch, int len)
}
} // namespace
XmlRpcRequest
RpcRequest
XmlRpcRequestProcessor::parseMemory(const std::string& xml)
{
stm_.reset(new XmlRpcRequestParserStateMachine());
@ -125,10 +125,10 @@ XmlRpcRequestProcessor::parseMemory(const std::string& xml)
if(!asList(stm_->getCurrentFrameValue())) {
throw DL_ABORT_EX("Bad XML-RPC parameter list");
}
return XmlRpcRequest(stm_->getMethodName(),
return RpcRequest(stm_->getMethodName(),
static_pointer_cast<List>(stm_->getCurrentFrameValue()));
}
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2

View File

@ -40,11 +40,11 @@
#include <string>
#include "SharedHandle.h"
#include "XmlRpcRequest.h"
#include "RpcRequest.h"
namespace aria2 {
namespace xmlrpc {
namespace rpc {
class XmlRpcRequestParserStateMachine;
@ -52,10 +52,10 @@ class XmlRpcRequestProcessor {
private:
SharedHandle<XmlRpcRequestParserStateMachine> stm_;
public:
XmlRpcRequest parseMemory(const std::string& xml);
RpcRequest parseMemory(const std::string& xml);
};
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2

View File

@ -45,11 +45,6 @@
#include "HttpServerResponseCommand.h"
#include "OptionParser.h"
#include "OptionHandler.h"
#include "XmlRpcRequestProcessor.h"
#include "XmlRpcRequestParserStateMachine.h"
#include "XmlRpcMethod.h"
#include "XmlRpcMethodFactory.h"
#include "XmlRpcResponse.h"
#include "wallclock.h"
#include "util.h"
#include "fmt.h"
@ -57,6 +52,14 @@
#include "json.h"
#include "DlAbortEx.h"
#include "message.h"
#include "RpcMethod.h"
#include "RpcMethodFactory.h"
#include "RpcRequest.h"
#include "RpcResponse.h"
#ifdef ENABLE_XML_RPC
# include "XmlRpcRequestProcessor.h"
# include "XmlRpcRequestParserStateMachine.h"
#endif // ENABLE_XML_RPC
namespace aria2 {
@ -84,7 +87,7 @@ HttpServerBodyCommand::~HttpServerBodyCommand()
}
namespace {
xmlrpc::XmlRpcResponse
rpc::RpcResponse
createJsonRpcErrorResponse
(int code,
const std::string& msg,
@ -93,13 +96,13 @@ createJsonRpcErrorResponse
SharedHandle<Dict> params = Dict::g();
params->put("code", Integer::g(code));
params->put("message", msg);
xmlrpc::XmlRpcResponse res(code, params, id);
rpc::RpcResponse res(code, params, id);
return res;
}
} // namespace
void HttpServerBodyCommand::sendJsonRpcResponse
(const xmlrpc::XmlRpcResponse& res,
(const rpc::RpcResponse& res,
const std::string& callback)
{
bool gzip = httpServer_->supportsGZip();
@ -126,11 +129,11 @@ void HttpServerBodyCommand::sendJsonRpcResponse
}
void HttpServerBodyCommand::sendJsonRpcBatchResponse
(const std::vector<xmlrpc::XmlRpcResponse>& results,
(const std::vector<rpc::RpcResponse>& results,
const std::string& callback)
{
bool gzip = httpServer_->supportsGZip();
std::string responseData = xmlrpc::toJsonBatch(results, callback, gzip);
std::string responseData = rpc::toJsonBatch(results, callback, gzip);
httpServer_->feedResponse(responseData, "application/json-rpc");
addHttpServerResponseCommand();
}
@ -143,7 +146,7 @@ void HttpServerBodyCommand::addHttpServerResponseCommand()
e_->setNoWait(true);
}
xmlrpc::XmlRpcResponse
rpc::RpcResponse
HttpServerBodyCommand::processJsonRpcRequest(const Dict* jsondict)
{
@ -165,16 +168,16 @@ HttpServerBodyCommand::processJsonRpcRequest(const Dict* jsondict)
// TODO No support for Named params
return createJsonRpcErrorResponse(-32602, "Invalid params.", id);
}
xmlrpc::XmlRpcRequest req(methodName->s(), params, id);
SharedHandle<xmlrpc::XmlRpcMethod> method;
rpc::RpcRequest req(methodName->s(), params, id);
SharedHandle<rpc::RpcMethod> method;
try {
method = xmlrpc::XmlRpcMethodFactory::create(req.methodName);
method = rpc::RpcMethodFactory::create(req.methodName);
} catch(RecoverableException& e) {
A2_LOG_INFO_EX(EX_EXCEPTION_CAUGHT, e);
return createJsonRpcErrorResponse(-32601, "Method not found.", id);
}
method->setJsonRpc(true);
xmlrpc::XmlRpcResponse res = method->execute(req, e_);
rpc::RpcResponse res = method->execute(req, e_);
return res;
}
@ -200,16 +203,17 @@ bool HttpServerBodyCommand::execute()
reqPath.erase(reqPath.size()-query.size(), query.size());
// Do something for requestpath and body
if(reqPath == "/rpc") {
xmlrpc::XmlRpcRequest req =
xmlrpc::XmlRpcRequestProcessor().parseMemory(httpServer_->getBody());
SharedHandle<xmlrpc::XmlRpcMethod> method =
xmlrpc::XmlRpcMethodFactory::create(req.methodName);
xmlrpc::XmlRpcResponse res = method->execute(req, e_);
#ifdef ENABLE_XML_RPC
rpc::RpcRequest req =
rpc::XmlRpcRequestProcessor().parseMemory(httpServer_->getBody());
SharedHandle<rpc::RpcMethod> method =
rpc::RpcMethodFactory::create(req.methodName);
rpc::RpcResponse res = method->execute(req, e_);
bool gzip = httpServer_->supportsGZip();
std::string responseData = res.toXml(gzip);
httpServer_->feedResponse(responseData, "text/xml");
addHttpServerResponseCommand();
#endif // ENABLE_XML_RPC
return true;
} else if(reqPath == "/jsonrpc") {
std::string callback;
@ -227,7 +231,7 @@ bool HttpServerBodyCommand::execute()
(fmt("CUID#%lld - Failed to parse JSON-RPC request",
getCuid()),
e);
xmlrpc::XmlRpcResponse res
rpc::RpcResponse res
(createJsonRpcErrorResponse
(-32700, "Parse error.", SharedHandle<ValueBase>()));
sendJsonRpcResponse(res, callback);
@ -235,24 +239,24 @@ bool HttpServerBodyCommand::execute()
}
const Dict* jsondict = asDict(json);
if(jsondict) {
xmlrpc::XmlRpcResponse res = processJsonRpcRequest(jsondict);
rpc::RpcResponse res = processJsonRpcRequest(jsondict);
sendJsonRpcResponse(res, callback);
} else {
const List* jsonlist = asList(json);
if(jsonlist) {
// This is batch call
std::vector<xmlrpc::XmlRpcResponse> results;
std::vector<rpc::RpcResponse> results;
for(List::ValueType::const_iterator i = jsonlist->begin(),
eoi = jsonlist->end(); i != eoi; ++i) {
const Dict* jsondict = asDict(*i);
if(jsondict) {
xmlrpc::XmlRpcResponse r = processJsonRpcRequest(jsondict);
rpc::RpcResponse r = processJsonRpcRequest(jsondict);
results.push_back(r);
}
}
sendJsonRpcBatchResponse(results, callback);
} else {
xmlrpc::XmlRpcResponse res
rpc::RpcResponse res
(createJsonRpcErrorResponse
(-32600, "Invalid Request.", SharedHandle<ValueBase>()));
sendJsonRpcResponse(res, callback);

View File

@ -39,7 +39,7 @@
#include "SharedHandle.h"
#include "TimerA2.h"
#include "ValueBase.h"
#include "XmlRpcResponse.h"
#include "RpcResponse.h"
namespace aria2 {
@ -60,12 +60,12 @@ private:
const SharedHandle<ValueBase>& id,
const std::string& callback);
void sendJsonRpcResponse
(const xmlrpc::XmlRpcResponse& res,
(const rpc::RpcResponse& res,
const std::string& callback);
void sendJsonRpcBatchResponse
(const std::vector<xmlrpc::XmlRpcResponse>& results,
(const std::vector<rpc::RpcResponse>& results,
const std::string& callback);
xmlrpc::XmlRpcResponse processJsonRpcRequest(const Dict* jsondict);
rpc::RpcResponse processJsonRpcRequest(const Dict* jsondict);
void addHttpServerResponseCommand();
public:
HttpServerBodyCommand(cuid_t cuid,

View File

@ -211,7 +211,17 @@ SRCS = Socket.h\
uri.cc uri.h\
Triplet.h\
cookie_helper.cc cookie_helper.h\
json.cc json.h
json.cc json.h\
HttpServerBodyCommand.cc HttpServerBodyCommand.h\
RpcRequest.cc RpcRequest.h\
RpcMethod.cc RpcMethod.h\
RpcMethodImpl.cc RpcMethodImpl.h\
RpcMethodFactory.cc RpcMethodFactory.h\
RpcResponse.cc RpcResponse.h\
HttpListenCommand.cc HttpListenCommand.h\
HttpServerCommand.cc HttpServerCommand.h\
HttpServerResponseCommand.cc HttpServerResponseCommand.h\
HttpServer.cc HttpServer.h
if ENABLE_XML_RPC
SRCS += XmlRpcRequestParserController.cc XmlRpcRequestParserController.h\
@ -219,17 +229,7 @@ SRCS += XmlRpcRequestParserController.cc XmlRpcRequestParserController.h\
XmlRpcRequestParserState.h\
XmlRpcRequestParserStateImpl.cc XmlRpcRequestParserStateImpl.h\
XmlRpcElements.cc XmlRpcElements.h\
XmlRpcRequest.cc XmlRpcRequest.h\
XmlRpcRequestProcessor.h\
HttpServerBodyCommand.cc HttpServerBodyCommand.h\
XmlRpcMethod.cc XmlRpcMethod.h\
XmlRpcMethodImpl.cc XmlRpcMethodImpl.h\
XmlRpcMethodFactory.cc XmlRpcMethodFactory.h\
XmlRpcResponse.cc XmlRpcResponse.h\
HttpListenCommand.cc HttpListenCommand.h\
HttpServerCommand.cc HttpServerCommand.h\
HttpServerResponseCommand.cc HttpServerResponseCommand.h\
HttpServer.cc HttpServer.h
XmlRpcRequestProcessor.h
if HAVE_LIBXML2
SRCS += Xml2XmlRpcRequestProcessor.cc Xml2XmlRpcRequestProcessor.h

View File

@ -228,7 +228,6 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
handlers.push_back(op);
}
#endif // ENABLE_DIRECT_IO
#ifdef ENABLE_XML_RPC
{
SharedHandle<OptionHandler> op(new BooleanOptionHandler
(PREF_ENABLE_XML_RPC,
@ -238,7 +237,6 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
op->addTag(TAG_XML_RPC);
handlers.push_back(op);
}
#endif // ENABLE_XML_RPC
{
std::string params[] = {
#ifdef HAVE_EPOLL
@ -568,7 +566,6 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
op->addTag(TAG_ADVANCED);
handlers.push_back(op);
}
#ifdef ENABLE_XML_RPC
{
SharedHandle<OptionHandler> op(new BooleanOptionHandler
(PREF_XML_RPC_LISTEN_ALL,
@ -610,7 +607,6 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
op->addTag(TAG_XML_RPC);
handlers.push_back(op);
}
#endif // ENABLE_XML_RPC
// HTTP/FTP options
{
SharedHandle<OptionHandler> op(new NumberOptionHandler

View File

@ -100,11 +100,9 @@ RequestGroupMan::~RequestGroupMan() {}
bool RequestGroupMan::downloadFinished()
{
#ifdef ENABLE_XML_RPC
if(xmlRpc_) {
return false;
}
#endif // ENABLE_XML_RPC
return requestGroups_.empty() && reservedGroups_.empty();
}

View File

@ -32,7 +32,7 @@
* files in the program, then also delete it here.
*/
/* copyright --> */
#include "XmlRpcMethod.h"
#include "RpcMethod.h"
#include "DownloadEngine.h"
#include "LogFactory.h"
#include "RecoverableException.h"
@ -42,24 +42,24 @@
#include "Option.h"
#include "array_fun.h"
#include "download_helper.h"
#include "XmlRpcRequest.h"
#include "XmlRpcResponse.h"
#include "RpcRequest.h"
#include "RpcResponse.h"
#include "prefs.h"
#include "fmt.h"
#include "DlAbortEx.h"
namespace aria2 {
namespace xmlrpc {
namespace rpc {
XmlRpcMethod::XmlRpcMethod()
RpcMethod::RpcMethod()
: optionParser_(OptionParser::getInstance()),
jsonRpc_(false)
{}
XmlRpcMethod::~XmlRpcMethod() {}
RpcMethod::~RpcMethod() {}
SharedHandle<ValueBase> XmlRpcMethod::createErrorResponse
SharedHandle<ValueBase> RpcMethod::createErrorResponse
(const Exception& e)
{
SharedHandle<Dict> params = Dict::g();
@ -68,14 +68,14 @@ SharedHandle<ValueBase> XmlRpcMethod::createErrorResponse
return params;
}
XmlRpcResponse XmlRpcMethod::execute
(const XmlRpcRequest& req, DownloadEngine* e)
RpcResponse RpcMethod::execute
(const RpcRequest& req, DownloadEngine* e)
{
try {
return XmlRpcResponse(0, process(req, e), req.id);
return RpcResponse(0, process(req, e), req.id);
} catch(RecoverableException& e) {
A2_LOG_DEBUG_EX(EX_EXCEPTION_CAUGHT, e);
return XmlRpcResponse(1, createErrorResponse(e), req.id);
return RpcResponse(1, createErrorResponse(e), req.id);
}
}
@ -123,7 +123,7 @@ void gatherOption
}
} // namespace
void XmlRpcMethod::gatherRequestOption
void RpcMethod::gatherRequestOption
(const SharedHandle<Option>& option, const Dict* optionsDict)
{
if(optionsDict) {
@ -162,7 +162,7 @@ const std::set<std::string>& listChangeableOptions()
return options;
}
void XmlRpcMethod::gatherChangeableOption
void RpcMethod::gatherChangeableOption
(const SharedHandle<Option>& option, const Dict* optionsDict)
{
if(optionsDict) {
@ -172,7 +172,7 @@ void XmlRpcMethod::gatherChangeableOption
}
}
void XmlRpcMethod::applyChangeableOption(Option* dest, Option* src) const
void RpcMethod::applyChangeableOption(Option* dest, Option* src) const
{
applyOption(listChangeableOptions().begin(), listChangeableOptions().end(),
dest, src);
@ -191,7 +191,7 @@ const std::set<std::string>& listChangeableGlobalOptions()
return options;
}
void XmlRpcMethod::gatherChangeableGlobalOption
void RpcMethod::gatherChangeableGlobalOption
(const SharedHandle<Option>& option, const Dict* optionsDict)
{
if(optionsDict) {
@ -201,13 +201,13 @@ void XmlRpcMethod::gatherChangeableGlobalOption
}
}
void XmlRpcMethod::applyChangeableGlobalOption(Option* dest, Option* src) const
void RpcMethod::applyChangeableGlobalOption(Option* dest, Option* src) const
{
applyOption(listChangeableGlobalOptions().begin(),
listChangeableGlobalOptions().end(),
dest, src);
}
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2

View File

@ -32,8 +32,8 @@
* files in the program, then also delete it here.
*/
/* copyright --> */
#ifndef D_XML_RPC_METHOD_H
#define D_XML_RPC_METHOD_H
#ifndef D_RPC_METHOD_H
#define D_RPC_METHOD_H
#include "common.h"
@ -49,28 +49,28 @@ class OptionParser;
class Option;
class Exception;
namespace xmlrpc {
namespace rpc {
struct XmlRpcRequest;
struct XmlRpcResponse;
struct RpcRequest;
struct RpcResponse;
// This class offers abstract implementation of processing XML-RPC
// This class offers abstract implementation of processing RPC
// request. You have to inherit this class and implement process()
// method to add new XML-RPC API.
// method to add new RPC API.
//
// There is XmlRpcMethodFactory class which instantiates XmlRpcMethod
// subclass. If you add new XmlRpcMethod subclass, don't forget to add
// it to XmlRpcMethodFactory.
class XmlRpcMethod {
// There is RpcMethodFactory class which instantiates RpcMethod
// subclass. If you add new RpcMethod subclass, don't forget to add it
// to RpcMethodFactory.
class RpcMethod {
private:
SharedHandle<OptionParser> optionParser_;
bool jsonRpc_;
protected:
// Subclass must implement this function to fulfil XmlRpcRequest
// req. The return value of this method is used as a return value
// of XML-RPC request.
// Subclass must implement this function to fulfil RpcRequest req.
// The return value of this method is used as a return value of RPC
// request.
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e) = 0;
(const RpcRequest& req, DownloadEngine* e) = 0;
void gatherRequestOption
(const SharedHandle<Option>& option, const Dict* optionsDict);
@ -78,14 +78,14 @@ protected:
void gatherChangeableOption
(const SharedHandle<Option>& option, const Dict* optionDict);
// Copy options which is changeable in XML-RPC changeOption command
// to dest.
// Copy options which is changeable in RPC changeOption command to
// dest.
void applyChangeableOption(Option* dest, Option* src) const;
void gatherChangeableGlobalOption(const SharedHandle<Option>& option,
const Dict* optionDict);
// Copy options which is changeable in XML-RPC changeGlobalOption
// Copy options which is changeable in RPC changeGlobalOption
// command to dest.
void applyChangeableGlobalOption(Option* dest, Option* src) const;
@ -96,13 +96,13 @@ protected:
return optionParser_;
}
public:
XmlRpcMethod();
RpcMethod();
virtual ~XmlRpcMethod();
virtual ~RpcMethod();
// Do work to fulfill XmlRpcRequest req and returns its result as
// XmlRpcResponse. This method delegates to process() method.
XmlRpcResponse execute(const XmlRpcRequest& req, DownloadEngine* e);
// Do work to fulfill RpcRequest req and returns its result as
// RpcResponse. This method delegates to process() method.
RpcResponse execute(const RpcRequest& req, DownloadEngine* e);
// Set whether JSON-RPC style parameter handling.
void setJsonRpc(bool f)
{
@ -114,8 +114,8 @@ public:
}
};
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2
#endif // D_XML_RPC_METHOD_H
#endif // D_RPC_METHOD_H

127
src/RpcMethodFactory.cc Normal file
View File

@ -0,0 +1,127 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2009 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/
/* copyright --> */
#include "RpcMethodFactory.h"
#include "RpcMethodImpl.h"
#include "OptionParser.h"
#include "OptionHandler.h"
namespace aria2 {
namespace rpc {
SharedHandle<RpcMethod>
RpcMethodFactory::create(const std::string& methodName)
{
if(methodName == AddUriRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new AddUriRpcMethod());
#ifdef ENABLE_BITTORRENT
} else if(methodName == AddTorrentRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new AddTorrentRpcMethod());
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
}
else if(methodName == AddMetalinkRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new AddMetalinkRpcMethod());
#endif // ENABLE_METALINK
}
else if(methodName == RemoveRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new RemoveRpcMethod());
} else if(methodName == PauseRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new PauseRpcMethod());
} else if(methodName == ForcePauseRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new ForcePauseRpcMethod());
} else if(methodName == PauseAllRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new PauseAllRpcMethod());
} else if(methodName == ForcePauseAllRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new ForcePauseAllRpcMethod());
} else if(methodName == UnpauseRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new UnpauseRpcMethod());
} else if(methodName == UnpauseAllRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new UnpauseAllRpcMethod());
} else if(methodName == ForceRemoveRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new ForceRemoveRpcMethod());
} else if(methodName == ChangePositionRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new ChangePositionRpcMethod());
} else if(methodName == TellStatusRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new TellStatusRpcMethod());
} else if(methodName == GetUrisRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new GetUrisRpcMethod());
} else if(methodName == GetFilesRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new GetFilesRpcMethod());
#ifdef ENABLE_BITTORRENT
}
else if(methodName == GetPeersRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new GetPeersRpcMethod());
#endif // ENABLE_BITTORRENT
} else if(methodName == GetServersRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new GetServersRpcMethod());
} else if(methodName == TellActiveRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new TellActiveRpcMethod());
} else if(methodName == TellWaitingRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new TellWaitingRpcMethod());
} else if(methodName == TellStoppedRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new TellStoppedRpcMethod());
} else if(methodName == GetOptionRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new GetOptionRpcMethod());
} else if(methodName == ChangeUriRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new ChangeUriRpcMethod());
} else if(methodName == ChangeOptionRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new ChangeOptionRpcMethod());
} else if(methodName == GetGlobalOptionRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new GetGlobalOptionRpcMethod());
} else if(methodName == ChangeGlobalOptionRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new ChangeGlobalOptionRpcMethod());
} else if(methodName == PurgeDownloadResultRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new PurgeDownloadResultRpcMethod());
} else if(methodName == RemoveDownloadResultRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new RemoveDownloadResultRpcMethod());
} else if(methodName == GetVersionRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new GetVersionRpcMethod());
} else if(methodName == GetSessionInfoRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new GetSessionInfoRpcMethod());
} else if(methodName == ShutdownRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new ShutdownRpcMethod());
} else if(methodName == ForceShutdownRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new ForceShutdownRpcMethod());
} else if(methodName == SystemMulticallRpcMethod::getMethodName()) {
return SharedHandle<RpcMethod>(new SystemMulticallRpcMethod());
} else {
return SharedHandle<RpcMethod>(new NoSuchMethodRpcMethod());
}
}
} // namespace rpc
} // namespace aria2

View File

@ -32,8 +32,8 @@
* files in the program, then also delete it here.
*/
/* copyright --> */
#ifndef D_XML_RPC_METHOD_FACTORY_H
#define D_XML_RPC_METHOD_FACTORY_H
#ifndef D_RPC_METHOD_FACTORY_H
#define D_RPC_METHOD_FACTORY_H
#include "common.h"
@ -43,17 +43,17 @@
namespace aria2 {
namespace xmlrpc {
namespace rpc {
class XmlRpcMethod;
class RpcMethod;
class XmlRpcMethodFactory {
class RpcMethodFactory {
public:
static SharedHandle<XmlRpcMethod> create(const std::string& methodName);
static SharedHandle<RpcMethod> create(const std::string& methodName);
};
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2
#endif // D_XML_RPC_METHOD_FACTORY_H
#endif // D_RPC_METHOD_FACTORY_H

View File

@ -32,7 +32,7 @@
* files in the program, then also delete it here.
*/
/* copyright --> */
#include "XmlRpcMethodImpl.h"
#include "RpcMethodImpl.h"
#include <cassert>
#include <algorithm>
@ -49,7 +49,7 @@
#include "util.h"
#include "RequestGroupMan.h"
#include "fmt.h"
#include "XmlRpcRequest.h"
#include "RpcRequest.h"
#include "PieceStorage.h"
#include "DownloadContext.h"
#include "DiskAdaptor.h"
@ -58,8 +58,8 @@
#include "message.h"
#include "FeatureConfig.h"
#include "array_fun.h"
#include "XmlRpcMethodFactory.h"
#include "XmlRpcResponse.h"
#include "RpcMethodFactory.h"
#include "RpcResponse.h"
#include "SegmentMan.h"
#include "TimedHaltCommand.h"
#include "PeerStat.h"
@ -77,7 +77,7 @@
namespace aria2 {
namespace xmlrpc {
namespace rpc {
namespace {
const SharedHandle<String> VLB_TRUE = String::g("true");
@ -173,7 +173,7 @@ findRequestGroup(const SharedHandle<RequestGroupMan>& rgman, gid_t gid)
} // namespace
namespace {
void getPosParam(const XmlRpcRequest& req, size_t posParamIndex,
void getPosParam(const RpcRequest& req, size_t posParamIndex,
bool& posGiven, size_t& pos)
{
const Integer* p = req.getIntegerParam(posParamIndex);
@ -192,7 +192,7 @@ void getPosParam(const XmlRpcRequest& req, size_t posParamIndex,
namespace {
gid_t getRequiredGidParam
(const XmlRpcRequest& req, size_t posParamIndex)
(const RpcRequest& req, size_t posParamIndex)
{
const String* gidParam = req.getStringParam(posParamIndex);
if(gidParam) {
@ -219,8 +219,8 @@ void extractUris(OutputIterator out, const List* src)
}
} // namespace
SharedHandle<ValueBase> AddUriXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> AddUriRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
std::vector<std::string> uris;
extractUris(std::back_inserter(uris), req.getListParam(0));
@ -260,8 +260,8 @@ std::string getHexSha1(const std::string& s)
} // namespace
#ifdef ENABLE_BITTORRENT
SharedHandle<ValueBase> AddTorrentXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> AddTorrentRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const String* torrentParam = req.getStringParam(0);
if(!torrentParam) {
@ -307,8 +307,8 @@ SharedHandle<ValueBase> AddTorrentXmlRpcMethod::process
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
SharedHandle<ValueBase> AddMetalinkXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> AddMetalinkRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const String* metalinkParam = req.getStringParam(0);
if(!metalinkParam) {
@ -362,7 +362,7 @@ SharedHandle<ValueBase> AddMetalinkXmlRpcMethod::process
namespace {
SharedHandle<ValueBase> removeDownload
(const XmlRpcRequest& req, DownloadEngine* e, bool forceRemove)
(const RpcRequest& req, DownloadEngine* e, bool forceRemove)
{
gid_t gid = getRequiredGidParam(req, 0);
@ -393,14 +393,14 @@ SharedHandle<ValueBase> removeDownload
}
} // namespace
SharedHandle<ValueBase> RemoveXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> RemoveRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
return removeDownload(req, e, false);
}
SharedHandle<ValueBase> ForceRemoveXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> ForceRemoveRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
return removeDownload(req, e, true);
}
@ -433,7 +433,7 @@ bool pauseRequestGroup
namespace {
SharedHandle<ValueBase> pauseDownload
(const XmlRpcRequest& req, DownloadEngine* e, bool forcePause)
(const RpcRequest& req, DownloadEngine* e, bool forcePause)
{
gid_t gid = getRequiredGidParam(req, 0);
@ -454,14 +454,14 @@ SharedHandle<ValueBase> pauseDownload
}
} // namespace
SharedHandle<ValueBase> PauseXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> PauseRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
return pauseDownload(req, e, false);
}
SharedHandle<ValueBase> ForcePauseXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> ForcePauseRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
return pauseDownload(req, e, true);
}
@ -479,7 +479,7 @@ void pauseRequestGroups
namespace {
SharedHandle<ValueBase> pauseAllDownloads
(const XmlRpcRequest& req, DownloadEngine* e, bool forcePause)
(const RpcRequest& req, DownloadEngine* e, bool forcePause)
{
const std::deque<SharedHandle<RequestGroup> >& groups =
e->getRequestGroupMan()->getRequestGroups();
@ -492,20 +492,20 @@ SharedHandle<ValueBase> pauseAllDownloads
}
} // namespace
SharedHandle<ValueBase> PauseAllXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> PauseAllRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
return pauseAllDownloads(req, e, false);
}
SharedHandle<ValueBase> ForcePauseAllXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> ForcePauseAllRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
return pauseAllDownloads(req, e, true);
}
SharedHandle<ValueBase> UnpauseXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> UnpauseRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
gid_t gid = getRequiredGidParam(req, 0);
SharedHandle<RequestGroup> group =
@ -521,8 +521,8 @@ SharedHandle<ValueBase> UnpauseXmlRpcMethod::process
return createGIDResponse(gid);
}
SharedHandle<ValueBase> UnpauseAllXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> UnpauseAllRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const std::deque<SharedHandle<RequestGroup> >& groups =
e->getRequestGroupMan()->getReservedGroups();
@ -862,8 +862,8 @@ void gatherStoppedDownload
}
}
SharedHandle<ValueBase> GetFilesXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> GetFilesRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
gid_t gid = getRequiredGidParam(req, 0);
SharedHandle<List> files = List::g();
@ -887,8 +887,8 @@ SharedHandle<ValueBase> GetFilesXmlRpcMethod::process
return files;
}
SharedHandle<ValueBase> GetUrisXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> GetUrisRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
gid_t gid = getRequiredGidParam(req, 0);
SharedHandle<RequestGroup> group =
@ -907,8 +907,8 @@ SharedHandle<ValueBase> GetUrisXmlRpcMethod::process
}
#ifdef ENABLE_BITTORRENT
SharedHandle<ValueBase> GetPeersXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> GetPeersRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
gid_t gid = getRequiredGidParam(req, 0);
@ -929,8 +929,8 @@ SharedHandle<ValueBase> GetPeersXmlRpcMethod::process
}
#endif // ENABLE_BITTORRENT
SharedHandle<ValueBase> TellStatusXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> TellStatusRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
gid_t gid = getRequiredGidParam(req, 0);
@ -972,8 +972,8 @@ SharedHandle<ValueBase> TellStatusXmlRpcMethod::process
return entryDict;
}
SharedHandle<ValueBase> TellActiveXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> TellActiveRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const List* keysParam = req.getListParam(0);
std::vector<std::string> keys;
@ -994,12 +994,12 @@ SharedHandle<ValueBase> TellActiveXmlRpcMethod::process
}
const std::deque<SharedHandle<RequestGroup> >&
TellWaitingXmlRpcMethod::getItems(DownloadEngine* e) const
TellWaitingRpcMethod::getItems(DownloadEngine* e) const
{
return e->getRequestGroupMan()->getReservedGroups();
}
void TellWaitingXmlRpcMethod::createEntry
void TellWaitingRpcMethod::createEntry
(const SharedHandle<Dict>& entryDict,
const SharedHandle<RequestGroup>& item,
DownloadEngine* e,
@ -1016,12 +1016,12 @@ void TellWaitingXmlRpcMethod::createEntry
}
const std::deque<SharedHandle<DownloadResult> >&
TellStoppedXmlRpcMethod::getItems(DownloadEngine* e) const
TellStoppedRpcMethod::getItems(DownloadEngine* e) const
{
return e->getRequestGroupMan()->getDownloadResults();
}
void TellStoppedXmlRpcMethod::createEntry
void TellStoppedRpcMethod::createEntry
(const SharedHandle<Dict>& entryDict,
const SharedHandle<DownloadResult>& item,
DownloadEngine* e,
@ -1030,15 +1030,15 @@ void TellStoppedXmlRpcMethod::createEntry
gatherStoppedDownload(entryDict, item, keys);
}
SharedHandle<ValueBase> PurgeDownloadResultXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> PurgeDownloadResultRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
e->getRequestGroupMan()->purgeDownloadResult();
return VLB_OK;
}
SharedHandle<ValueBase> RemoveDownloadResultXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> RemoveDownloadResultRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
gid_t gid = getRequiredGidParam(req, 0);
if(!e->getRequestGroupMan()->removeDownloadResult(gid)) {
@ -1049,8 +1049,8 @@ SharedHandle<ValueBase> RemoveDownloadResultXmlRpcMethod::process
return VLB_OK;
}
SharedHandle<ValueBase> ChangeOptionXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> ChangeOptionRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
gid_t gid = getRequiredGidParam(req, 0);
@ -1085,8 +1085,8 @@ SharedHandle<ValueBase> ChangeOptionXmlRpcMethod::process
return VLB_OK;
}
SharedHandle<ValueBase> ChangeGlobalOptionXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> ChangeGlobalOptionRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const Dict* optionsParam = req.getDictParam(0);
if(!optionsParam) {
@ -1124,8 +1124,8 @@ SharedHandle<ValueBase> ChangeGlobalOptionXmlRpcMethod::process
return VLB_OK;
}
SharedHandle<ValueBase> GetVersionXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> GetVersionRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
SharedHandle<Dict> result = Dict::g();
result->put(KEY_VERSION, PACKAGE_VERSION);
@ -1156,8 +1156,8 @@ void pushRequestOption
}
} // namespace
SharedHandle<ValueBase> GetOptionXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> GetOptionRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
gid_t gid = getRequiredGidParam(req, 0);
@ -1174,8 +1174,8 @@ SharedHandle<ValueBase> GetOptionXmlRpcMethod::process
return result;
}
SharedHandle<ValueBase> GetGlobalOptionXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> GetGlobalOptionRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
SharedHandle<Dict> result = Dict::g();
for(std::map<std::string, std::string>::const_iterator i =
@ -1188,8 +1188,8 @@ SharedHandle<ValueBase> GetGlobalOptionXmlRpcMethod::process
return result;
}
SharedHandle<ValueBase> ChangePositionXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> ChangePositionRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
gid_t gid = getRequiredGidParam(req, 0);
const Integer* posParam = req.getIntegerParam(1);
@ -1216,16 +1216,16 @@ SharedHandle<ValueBase> ChangePositionXmlRpcMethod::process
return result;
}
SharedHandle<ValueBase> GetSessionInfoXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> GetSessionInfoRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
SharedHandle<Dict> result = Dict::g();
result->put(KEY_SESSION_ID, util::toHex(e->getSessionId()));
return result;
}
SharedHandle<ValueBase> GetServersXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> GetServersRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
gid_t gid = getRequiredGidParam(req, 0);
SharedHandle<RequestGroup> group =
@ -1263,8 +1263,8 @@ SharedHandle<ValueBase> GetServersXmlRpcMethod::process
return result;
}
SharedHandle<ValueBase> ChangeUriXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> ChangeUriRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
gid_t gid = getRequiredGidParam(req, 0);
const Integer* indexParam = req.getIntegerParam(1);
@ -1332,30 +1332,30 @@ SharedHandle<ValueBase> ChangeUriXmlRpcMethod::process
namespace {
SharedHandle<ValueBase> goingShutdown
(const XmlRpcRequest& req, DownloadEngine* e, bool forceHalt)
(const RpcRequest& req, DownloadEngine* e, bool forceHalt)
{
// Schedule shutdown after 3seconds to give time to client to
// receive XML-RPC response.
// receive RPC response.
e->addRoutineCommand(new TimedHaltCommand(e->newCUID(), e, 3, forceHalt));
A2_LOG_INFO("Scheduled shutdown in 3 seconds.");
return VLB_OK;
}
} // namespace
SharedHandle<ValueBase> ShutdownXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> ShutdownRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
return goingShutdown(req, e, false);
}
SharedHandle<ValueBase> ForceShutdownXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> ForceShutdownRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
return goingShutdown(req, e, true);
}
SharedHandle<ValueBase> SystemMulticallXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> SystemMulticallRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
const List* methodSpecs = req.getListParam(0);
if(!methodSpecs) {
@ -1383,11 +1383,11 @@ SharedHandle<ValueBase> SystemMulticallXmlRpcMethod::process
(DL_ABORT_EX("Recursive system.multicall forbidden.")));
continue;
}
SharedHandle<XmlRpcMethod> method =
XmlRpcMethodFactory::create(methodName->s());
XmlRpcRequest innerReq
SharedHandle<RpcMethod> method =
RpcMethodFactory::create(methodName->s());
RpcRequest innerReq
(methodName->s(), static_pointer_cast<List>(methodDict->get(KEY_PARAMS)));
XmlRpcResponse res = method->execute(innerReq, e);
RpcResponse res = method->execute(innerReq, e);
if(res.code == 0) {
SharedHandle<List> l = List::g();
l->append(res.param);
@ -1399,12 +1399,12 @@ SharedHandle<ValueBase> SystemMulticallXmlRpcMethod::process
return list;
}
SharedHandle<ValueBase> NoSuchMethodXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
SharedHandle<ValueBase> NoSuchMethodRpcMethod::process
(const RpcRequest& req, DownloadEngine* e)
{
throw DL_ABORT_EX(fmt("No such method: %s", req.methodName.c_str()));
}
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2

View File

@ -32,16 +32,16 @@
* files in the program, then also delete it here.
*/
/* copyright --> */
#ifndef D_XML_RPC_METHOD_IMPL_H
#define D_XML_RPC_METHOD_IMPL_H
#ifndef D_RPC_METHOD_IMPL_H
#define D_RPC_METHOD_IMPL_H
#include "XmlRpcMethod.h"
#include "RpcMethod.h"
#include <cassert>
#include <deque>
#include <algorithm>
#include "XmlRpcRequest.h"
#include "RpcRequest.h"
#include "ValueBase.h"
#include "TorrentAttribute.h"
#include "DlAbortEx.h"
@ -51,7 +51,7 @@ namespace aria2 {
struct DownloadResult;
class RequestGroup;
namespace xmlrpc {
namespace rpc {
template<typename OutputIterator>
void toStringList(OutputIterator out, const List* src)
@ -68,10 +68,10 @@ void toStringList(OutputIterator out, const List* src)
}
}
class AddUriXmlRpcMethod:public XmlRpcMethod {
class AddUriRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -80,10 +80,10 @@ public:
}
};
class RemoveXmlRpcMethod:public XmlRpcMethod {
class RemoveRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -92,10 +92,10 @@ public:
}
};
class ForceRemoveXmlRpcMethod:public XmlRpcMethod {
class ForceRemoveRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -104,10 +104,10 @@ public:
}
};
class PauseXmlRpcMethod:public XmlRpcMethod {
class PauseRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -116,10 +116,10 @@ public:
}
};
class ForcePauseXmlRpcMethod:public XmlRpcMethod {
class ForcePauseRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -128,10 +128,10 @@ public:
}
};
class PauseAllXmlRpcMethod:public XmlRpcMethod {
class PauseAllRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -140,10 +140,10 @@ public:
}
};
class ForcePauseAllXmlRpcMethod:public XmlRpcMethod {
class ForcePauseAllRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -152,10 +152,10 @@ public:
}
};
class UnpauseXmlRpcMethod:public XmlRpcMethod {
class UnpauseRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -164,10 +164,10 @@ public:
}
};
class UnpauseAllXmlRpcMethod:public XmlRpcMethod {
class UnpauseAllRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -177,10 +177,10 @@ public:
};
#ifdef ENABLE_BITTORRENT
class AddTorrentXmlRpcMethod:public XmlRpcMethod {
class AddTorrentRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -191,10 +191,10 @@ public:
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
class AddMetalinkXmlRpcMethod:public XmlRpcMethod {
class AddMetalinkRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -204,10 +204,10 @@ public:
};
#endif // ENABLE_METALINK
class PurgeDownloadResultXmlRpcMethod:public XmlRpcMethod {
class PurgeDownloadResultRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -216,10 +216,10 @@ public:
}
};
class RemoveDownloadResultXmlRpcMethod:public XmlRpcMethod {
class RemoveDownloadResultRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -228,10 +228,10 @@ public:
}
};
class GetUrisXmlRpcMethod:public XmlRpcMethod {
class GetUrisRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -240,10 +240,10 @@ public:
}
};
class GetFilesXmlRpcMethod:public XmlRpcMethod {
class GetFilesRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -253,10 +253,10 @@ public:
};
#ifdef ENABLE_BITTORRENT
class GetPeersXmlRpcMethod:public XmlRpcMethod {
class GetPeersRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -266,10 +266,10 @@ public:
};
#endif // ENABLE_BITTORRENT
class GetServersXmlRpcMethod:public XmlRpcMethod {
class GetServersRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -278,10 +278,10 @@ public:
}
};
class TellStatusXmlRpcMethod:public XmlRpcMethod {
class TellStatusRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -290,10 +290,10 @@ public:
}
};
class TellActiveXmlRpcMethod:public XmlRpcMethod {
class TellActiveRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -303,7 +303,7 @@ public:
};
template<typename T>
class AbstractPaginationXmlRpcMethod:public XmlRpcMethod {
class AbstractPaginationRpcMethod:public RpcMethod {
private:
template<typename InputIterator>
std::pair<InputIterator, InputIterator>
@ -349,7 +349,7 @@ private:
}
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e)
(const RpcRequest& req, DownloadEngine* e)
{
const SharedHandle<List>& params = req.params;
checkPaginationParams(params);
@ -384,8 +384,8 @@ protected:
const std::vector<std::string>& keys) const = 0;
};
class TellWaitingXmlRpcMethod:
public AbstractPaginationXmlRpcMethod<RequestGroup> {
class TellWaitingRpcMethod:
public AbstractPaginationRpcMethod<RequestGroup> {
protected:
virtual const std::deque<SharedHandle<RequestGroup> >&
getItems(DownloadEngine* e) const;
@ -403,8 +403,8 @@ public:
}
};
class TellStoppedXmlRpcMethod:
public AbstractPaginationXmlRpcMethod<DownloadResult> {
class TellStoppedRpcMethod:
public AbstractPaginationRpcMethod<DownloadResult> {
protected:
virtual const std::deque<SharedHandle<DownloadResult> >&
getItems(DownloadEngine* e) const;
@ -422,10 +422,10 @@ public:
}
};
class ChangeOptionXmlRpcMethod:public XmlRpcMethod {
class ChangeOptionRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -434,10 +434,10 @@ public:
}
};
class ChangeGlobalOptionXmlRpcMethod:public XmlRpcMethod {
class ChangeGlobalOptionRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -446,10 +446,10 @@ public:
}
};
class GetVersionXmlRpcMethod:public XmlRpcMethod {
class GetVersionRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -458,10 +458,10 @@ public:
}
};
class GetOptionXmlRpcMethod:public XmlRpcMethod {
class GetOptionRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -470,10 +470,10 @@ public:
}
};
class GetGlobalOptionXmlRpcMethod:public XmlRpcMethod {
class GetGlobalOptionRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -482,10 +482,10 @@ public:
}
};
class ChangePositionXmlRpcMethod:public XmlRpcMethod {
class ChangePositionRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -494,10 +494,10 @@ public:
}
};
class ChangeUriXmlRpcMethod:public XmlRpcMethod {
class ChangeUriRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -506,10 +506,10 @@ public:
}
};
class GetSessionInfoXmlRpcMethod:public XmlRpcMethod {
class GetSessionInfoRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -518,10 +518,10 @@ public:
}
};
class ShutdownXmlRpcMethod:public XmlRpcMethod {
class ShutdownRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -530,10 +530,10 @@ public:
}
};
class ForceShutdownXmlRpcMethod:public XmlRpcMethod {
class ForceShutdownRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -542,10 +542,10 @@ public:
}
};
class SystemMulticallXmlRpcMethod:public XmlRpcMethod {
class SystemMulticallRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
@ -554,10 +554,10 @@ public:
}
};
class NoSuchMethodXmlRpcMethod:public XmlRpcMethod {
class NoSuchMethodRpcMethod:public RpcMethod {
protected:
virtual SharedHandle<ValueBase> process
(const XmlRpcRequest& req, DownloadEngine* e);
(const RpcRequest& req, DownloadEngine* e);
};
// Helper function to store data to entryDict from ds. This function
@ -579,8 +579,8 @@ void gatherBitTorrentMetadata
const SharedHandle<TorrentAttribute>& torrentAttrs);
#endif // ENABLE_BITTORRENT
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2
#endif // D_XML_RPC_METHOD_IMPL_H
#endif // D_RPC_METHOD_IMPL_H

View File

@ -32,30 +32,30 @@
* files in the program, then also delete it here.
*/
/* copyright --> */
#include "XmlRpcRequest.h"
#include "RpcRequest.h"
namespace aria2 {
namespace xmlrpc {
namespace rpc {
XmlRpcRequest::XmlRpcRequest(const std::string& methodName,
RpcRequest::RpcRequest(const std::string& methodName,
const SharedHandle<List>& params)
: methodName(methodName), params(params)
{}
XmlRpcRequest::XmlRpcRequest(const std::string& methodName,
RpcRequest::RpcRequest(const std::string& methodName,
const SharedHandle<List>& params,
const SharedHandle<ValueBase>& id)
: methodName(methodName), params(params), id(id)
{}
XmlRpcRequest::XmlRpcRequest(const XmlRpcRequest& c)
RpcRequest::RpcRequest(const RpcRequest& c)
: methodName(c.methodName), params(c.params), id(c.id)
{}
XmlRpcRequest::~XmlRpcRequest() {}
RpcRequest::~RpcRequest() {}
XmlRpcRequest& XmlRpcRequest::operator=(const XmlRpcRequest& c)
RpcRequest& RpcRequest::operator=(const RpcRequest& c)
{
if(this != &c) {
methodName = c.methodName;
@ -64,7 +64,7 @@ XmlRpcRequest& XmlRpcRequest::operator=(const XmlRpcRequest& c)
return *this;
}
const String* XmlRpcRequest::getStringParam(size_t index) const
const String* RpcRequest::getStringParam(size_t index) const
{
const String* stringParam = 0;
if(params->size() > index) {
@ -73,7 +73,7 @@ const String* XmlRpcRequest::getStringParam(size_t index) const
return stringParam;
}
const Integer* XmlRpcRequest::getIntegerParam(size_t index) const
const Integer* RpcRequest::getIntegerParam(size_t index) const
{
const Integer* integerParam = 0;
if(params->size() > index) {
@ -82,7 +82,7 @@ const Integer* XmlRpcRequest::getIntegerParam(size_t index) const
return integerParam;
}
const List* XmlRpcRequest::getListParam(size_t index) const
const List* RpcRequest::getListParam(size_t index) const
{
const List* listParam = 0;
if(params->size() > index) {
@ -91,7 +91,7 @@ const List* XmlRpcRequest::getListParam(size_t index) const
return listParam;
}
const Dict* XmlRpcRequest::getDictParam(size_t index) const
const Dict* RpcRequest::getDictParam(size_t index) const
{
const Dict* dictParam = 0;
if(params->size() > index) {
@ -100,6 +100,6 @@ const Dict* XmlRpcRequest::getDictParam(size_t index) const
return dictParam;
}
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2

View File

@ -32,8 +32,8 @@
* files in the program, then also delete it here.
*/
/* copyright --> */
#ifndef D_XML_RPC_REQUEST_H
#define D_XML_RPC_REQUEST_H
#ifndef D_RPC_REQUEST_H
#define D_RPC_REQUEST_H
#include "common.h"
@ -43,25 +43,25 @@
namespace aria2 {
namespace xmlrpc {
namespace rpc {
struct XmlRpcRequest {
struct RpcRequest {
std::string methodName;
SharedHandle<List> params;
SharedHandle<ValueBase> id;
XmlRpcRequest(const std::string& methodName,
RpcRequest(const std::string& methodName,
const SharedHandle<List>& params);
XmlRpcRequest(const std::string& methodName,
RpcRequest(const std::string& methodName,
const SharedHandle<List>& params,
const SharedHandle<ValueBase>& id);
~XmlRpcRequest();
~RpcRequest();
XmlRpcRequest(const XmlRpcRequest& c);
RpcRequest(const RpcRequest& c);
XmlRpcRequest& operator=(const XmlRpcRequest& c);
RpcRequest& operator=(const RpcRequest& c);
const String* getStringParam(size_t index) const;
@ -72,8 +72,8 @@ struct XmlRpcRequest {
const Dict* getDictParam(size_t index) const;
};
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2
#endif // D_XML_RPC_REQUEST_H
#endif // D_RPC_REQUEST_H

View File

@ -32,7 +32,7 @@
* files in the program, then also delete it here.
*/
/* copyright --> */
#include "XmlRpcResponse.h"
#include "RpcResponse.h"
#include <cassert>
#include <sstream>
@ -45,7 +45,7 @@
namespace aria2 {
namespace xmlrpc {
namespace rpc {
namespace {
template<typename OutputStream>
@ -121,22 +121,22 @@ std::string encodeAll
}
} // namespace
XmlRpcResponse::XmlRpcResponse
RpcResponse::RpcResponse
(int code,
const SharedHandle<ValueBase>& param,
const SharedHandle<ValueBase>& id)
: code(code), param(param), id(id)
{}
XmlRpcResponse::XmlRpcResponse(const XmlRpcResponse& c)
RpcResponse::RpcResponse(const RpcResponse& c)
: code(c.code),
param(c.param),
id(c.id)
{}
XmlRpcResponse::~XmlRpcResponse() {}
RpcResponse::~RpcResponse() {}
XmlRpcResponse& XmlRpcResponse::operator=(const XmlRpcResponse& c)
RpcResponse& RpcResponse::operator=(const RpcResponse& c)
{
if(this != &c) {
code = c.code;
@ -145,7 +145,7 @@ XmlRpcResponse& XmlRpcResponse::operator=(const XmlRpcResponse& c)
return *this;
}
std::string XmlRpcResponse::toXml(bool gzip) const
std::string RpcResponse::toXml(bool gzip) const
{
if(gzip) {
#ifdef HAVE_ZLIB
@ -189,7 +189,7 @@ OutputStream& encodeJsonAll
}
} // namespace
std::string XmlRpcResponse::toJson(const std::string& callback, bool gzip) const
std::string RpcResponse::toJson(const std::string& callback, bool gzip) const
{
if(gzip) {
#ifdef HAVE_ZLIB
@ -209,14 +209,14 @@ namespace {
template<typename OutputStream>
OutputStream& encodeJsonBatchAll
(OutputStream& o,
const std::vector<XmlRpcResponse>& results,
const std::vector<RpcResponse>& results,
const std::string& callback)
{
o << "[";
if(!results.empty()) {
encodeJsonAll(o, results[0].code, results[0].param, results[0].id,callback);
}
for(std::vector<XmlRpcResponse>::const_iterator i = results.begin()+1,
for(std::vector<RpcResponse>::const_iterator i = results.begin()+1,
eoi = results.end(); i != eoi; ++i) {
o << ",";
encodeJsonAll(o, (*i).code, (*i).param, (*i).id, callback);
@ -227,7 +227,7 @@ OutputStream& encodeJsonBatchAll
} // namespace
std::string toJsonBatch
(const std::vector<XmlRpcResponse>& results,
(const std::vector<RpcResponse>& results,
const std::string& callback,
bool gzip)
{
@ -245,6 +245,6 @@ std::string toJsonBatch
}
}
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2

View File

@ -32,8 +32,8 @@
* files in the program, then also delete it here.
*/
/* copyright --> */
#ifndef D_XML_RPC_RESPONSE_H
#define D_XML_RPC_RESPONSE_H
#ifndef D_RPC_RESPONSE_H
#define D_RPC_RESPONSE_H
#include "common.h"
@ -44,9 +44,9 @@
namespace aria2 {
namespace xmlrpc {
namespace rpc {
struct XmlRpcResponse {
struct RpcResponse {
// 0 for success, non-zero for error
int code;
@ -54,16 +54,16 @@ struct XmlRpcResponse {
SharedHandle<ValueBase> id;
XmlRpcResponse
RpcResponse
(int code,
const SharedHandle<ValueBase>& param,
const SharedHandle<ValueBase>& id);
XmlRpcResponse(const XmlRpcResponse& c);
RpcResponse(const RpcResponse& c);
~XmlRpcResponse();
~RpcResponse();
XmlRpcResponse& operator=(const XmlRpcResponse& c);
RpcResponse& operator=(const RpcResponse& c);
std::string toXml(bool gzip = false) const;
@ -73,12 +73,12 @@ struct XmlRpcResponse {
};
std::string toJsonBatch
(const std::vector<XmlRpcResponse>& results,
(const std::vector<RpcResponse>& results,
const std::string& callback,
bool gzip = false);
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2
#endif // D_XML_RPC_RESPONSE_H
#endif // D_RPC_RESPONSE_H

View File

@ -45,7 +45,7 @@
namespace aria2 {
namespace xmlrpc {
namespace rpc {
namespace {
struct SessionData {
@ -148,7 +148,7 @@ XmlRpcRequestProcessor::XmlRpcRequestProcessor() {}
XmlRpcRequestProcessor::~XmlRpcRequestProcessor() {}
XmlRpcRequest
RpcRequest
XmlRpcRequestProcessor::parseMemory(const std::string& xml)
{
stm_.reset(new XmlRpcRequestParserStateMachine());
@ -162,10 +162,10 @@ XmlRpcRequestProcessor::parseMemory(const std::string& xml)
if(!asList(stm_->getCurrentFrameValue())) {
throw DL_ABORT_EX("Bad XML-RPC parameter list");
}
return XmlRpcRequest(stm_->getMethodName(),
return RpcRequest(stm_->getMethodName(),
static_pointer_cast<List>(stm_->getCurrentFrameValue()));
}
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2

View File

@ -40,11 +40,11 @@
#include <string>
#include "SharedHandle.h"
#include "XmlRpcRequest.h"
#include "RpcRequest.h"
namespace aria2 {
namespace xmlrpc {
namespace rpc {
class XmlRpcRequestParserStateMachine;
@ -56,10 +56,10 @@ public:
~XmlRpcRequestProcessor();
XmlRpcRequest parseMemory(const std::string& xml);
RpcRequest parseMemory(const std::string& xml);
};
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2

View File

@ -35,7 +35,7 @@
#include "XmlRpcElements.h"
namespace aria2 {
namespace xmlrpc {
namespace rpc {
namespace elements {
const std::string METHOD_CALL("methodCall");
@ -57,5 +57,5 @@ const std::string ARRAY("array");
const std::string DATA("data");
} // namespace elements
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2

View File

@ -40,7 +40,7 @@
#include <string>
namespace aria2 {
namespace xmlrpc {
namespace rpc {
namespace elements {
extern const std::string METHOD_CALL;
@ -62,7 +62,7 @@ extern const std::string ARRAY;
extern const std::string DATA;
} // namespace elements
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2
#endif // D_XML_RPC_ELEMENTS_H

View File

@ -1,127 +0,0 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2009 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/
/* copyright --> */
#include "XmlRpcMethodFactory.h"
#include "XmlRpcMethodImpl.h"
#include "OptionParser.h"
#include "OptionHandler.h"
namespace aria2 {
namespace xmlrpc {
SharedHandle<XmlRpcMethod>
XmlRpcMethodFactory::create(const std::string& methodName)
{
if(methodName == AddUriXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new AddUriXmlRpcMethod());
#ifdef ENABLE_BITTORRENT
} else if(methodName == AddTorrentXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new AddTorrentXmlRpcMethod());
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
}
else if(methodName == AddMetalinkXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new AddMetalinkXmlRpcMethod());
#endif // ENABLE_METALINK
}
else if(methodName == RemoveXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new RemoveXmlRpcMethod());
} else if(methodName == PauseXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new PauseXmlRpcMethod());
} else if(methodName == ForcePauseXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new ForcePauseXmlRpcMethod());
} else if(methodName == PauseAllXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new PauseAllXmlRpcMethod());
} else if(methodName == ForcePauseAllXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new ForcePauseAllXmlRpcMethod());
} else if(methodName == UnpauseXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new UnpauseXmlRpcMethod());
} else if(methodName == UnpauseAllXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new UnpauseAllXmlRpcMethod());
} else if(methodName == ForceRemoveXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new ForceRemoveXmlRpcMethod());
} else if(methodName == ChangePositionXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new ChangePositionXmlRpcMethod());
} else if(methodName == TellStatusXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new TellStatusXmlRpcMethod());
} else if(methodName == GetUrisXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new GetUrisXmlRpcMethod());
} else if(methodName == GetFilesXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new GetFilesXmlRpcMethod());
#ifdef ENABLE_BITTORRENT
}
else if(methodName == GetPeersXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new GetPeersXmlRpcMethod());
#endif // ENABLE_BITTORRENT
} else if(methodName == GetServersXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new GetServersXmlRpcMethod());
} else if(methodName == TellActiveXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new TellActiveXmlRpcMethod());
} else if(methodName == TellWaitingXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new TellWaitingXmlRpcMethod());
} else if(methodName == TellStoppedXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new TellStoppedXmlRpcMethod());
} else if(methodName == GetOptionXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new GetOptionXmlRpcMethod());
} else if(methodName == ChangeUriXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new ChangeUriXmlRpcMethod());
} else if(methodName == ChangeOptionXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new ChangeOptionXmlRpcMethod());
} else if(methodName == GetGlobalOptionXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new GetGlobalOptionXmlRpcMethod());
} else if(methodName == ChangeGlobalOptionXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new ChangeGlobalOptionXmlRpcMethod());
} else if(methodName == PurgeDownloadResultXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new PurgeDownloadResultXmlRpcMethod());
} else if(methodName == RemoveDownloadResultXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new RemoveDownloadResultXmlRpcMethod());
} else if(methodName == GetVersionXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new GetVersionXmlRpcMethod());
} else if(methodName == GetSessionInfoXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new GetSessionInfoXmlRpcMethod());
} else if(methodName == ShutdownXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new ShutdownXmlRpcMethod());
} else if(methodName == ForceShutdownXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new ForceShutdownXmlRpcMethod());
} else if(methodName == SystemMulticallXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new SystemMulticallXmlRpcMethod());
} else {
return SharedHandle<XmlRpcMethod>(new NoSuchMethodXmlRpcMethod());
}
}
} // namespace xmlrpc
} // namespace aria2

View File

@ -38,7 +38,7 @@
namespace aria2 {
namespace xmlrpc {
namespace rpc {
void XmlRpcRequestParserController::pushFrame()
{
@ -92,6 +92,6 @@ XmlRpcRequestParserController::getCurrentFrameValue() const
return currentFrame_.value_;
}
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2

View File

@ -44,7 +44,7 @@
namespace aria2 {
namespace xmlrpc {
namespace rpc {
class XmlRpcRequestParserController {
private:
@ -89,7 +89,7 @@ public:
const std::string& getMethodName() const { return methodName_; }
};
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2

View File

@ -42,7 +42,7 @@
namespace aria2 {
namespace xmlrpc {
namespace rpc {
class XmlRpcRequestParserStateMachine;
@ -61,7 +61,7 @@ public:
virtual bool needsCharactersBuffering() const = 0;
};
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2

View File

@ -41,7 +41,7 @@
namespace aria2 {
namespace xmlrpc {
namespace rpc {
// InitialXmlRpcRequestParserState
@ -324,6 +324,6 @@ void ArrayValueXmlRpcRequestParserState::endElement
stm->popArrayFrame();
}
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2

View File

@ -39,7 +39,7 @@
namespace aria2 {
namespace xmlrpc {
namespace rpc {
class InitialXmlRpcRequestParserState:public XmlRpcRequestParserState {
public:
@ -231,7 +231,7 @@ class ArrayValueXmlRpcRequestParserState:public ValueXmlRpcRequestParserState {
const std::string& characters);
};
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2

View File

@ -36,7 +36,7 @@
namespace aria2 {
namespace xmlrpc {
namespace rpc {
InitialXmlRpcRequestParserState*
XmlRpcRequestParserStateMachine::initialState_ =
@ -113,6 +113,6 @@ XmlRpcRequestParserStateMachine::~XmlRpcRequestParserStateMachine()
delete controller_;
}
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2

View File

@ -47,7 +47,7 @@
namespace aria2 {
namespace xmlrpc {
namespace rpc {
class XmlRpcRequestParserStateMachine {
private:
@ -165,7 +165,7 @@ public:
void pushArrayValueState() { stateStack_.push(arrayValueState_); }
};
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2

View File

@ -262,11 +262,7 @@ error_code::Value main(int argc, char* argv[])
op->remove(PREF_INPUT_FILE);
op->remove(PREF_INDEX_OUT);
op->remove(PREF_SELECT_FILE);
if(
#ifdef ENABLE_XML_RPC
!op->getAsBool(PREF_ENABLE_XML_RPC) &&
#endif // ENABLE_XML_RPC
requestGroups.empty()) {
if(!op->getAsBool(PREF_ENABLE_XML_RPC) && requestGroups.empty()) {
std::cout << MSG_NO_FILES_TO_DOWNLOAD << std::endl;
} else {
exitStatus = MultiUrlRequestInfo(requestGroups, op, getStatCalc(op),

View File

@ -184,10 +184,7 @@ void option_processing(Option& op, std::vector<std::string>& uris,
showUsage(TAG_HELP, oparser);
exit(e.getErrorCode());
}
if(
#ifdef ENABLE_XML_RPC
!op.getAsBool(PREF_ENABLE_XML_RPC) &&
#endif // ENABLE_XML_RPC
if(!op.getAsBool(PREF_ENABLE_XML_RPC) &&
#ifdef ENABLE_BITTORRENT
op.blank(PREF_TORRENT_FILE) &&
#endif // ENABLE_BITTORRENT

View File

@ -78,12 +78,12 @@ aria2c_SOURCES = AllTest.cc\
TripletTest.cc\
CookieHelperTest.cc\
JsonTest.cc\
XmlRpcResponseTest.cc
RpcResponseTest.cc\
RpcMethodTest.cc
if ENABLE_XML_RPC
aria2c_SOURCES += XmlRpcRequestParserControllerTest.cc\
XmlRpcRequestProcessorTest.cc\
XmlRpcMethodTest.cc
XmlRpcRequestProcessorTest.cc
endif # ENABLE_XML_RPC
if HAVE_SOME_FALLOCATE

View File

@ -1,4 +1,4 @@
#include "XmlRpcMethod.h"
#include "RpcMethod.h"
#include <cppunit/extensions/HelperMacros.h>
@ -7,11 +7,11 @@
#include "Option.h"
#include "RequestGroupMan.h"
#include "RequestGroup.h"
#include "XmlRpcMethodImpl.h"
#include "RpcMethodImpl.h"
#include "OptionParser.h"
#include "OptionHandler.h"
#include "XmlRpcRequest.h"
#include "XmlRpcResponse.h"
#include "RpcRequest.h"
#include "RpcResponse.h"
#include "prefs.h"
#include "TestUtil.h"
#include "DownloadContext.h"
@ -28,11 +28,11 @@
namespace aria2 {
namespace xmlrpc {
namespace rpc {
class XmlRpcMethodTest:public CppUnit::TestFixture {
class RpcMethodTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(XmlRpcMethodTest);
CPPUNIT_TEST_SUITE(RpcMethodTest);
CPPUNIT_TEST(testAddUri);
CPPUNIT_TEST(testAddUri_withoutUri);
CPPUNIT_TEST(testAddUri_notUri);
@ -85,7 +85,7 @@ public:
{
RequestGroup::resetGIDCounter();
option_.reset(new Option());
option_->put(PREF_DIR, A2_TEST_OUT_DIR"/aria2_XmlRpcMethodTest");
option_->put(PREF_DIR, A2_TEST_OUT_DIR"/aria2_RpcMethodTest");
option_->put(PREF_SEGMENT_SIZE, "1048576");
File(option_->get(PREF_DIR)).mkdirs();
e_.reset
@ -143,7 +143,7 @@ public:
};
CPPUNIT_TEST_SUITE_REGISTRATION(XmlRpcMethodTest);
CPPUNIT_TEST_SUITE_REGISTRATION(RpcMethodTest);
namespace {
std::string getString(const Dict* dict, const std::string& key)
@ -152,15 +152,15 @@ std::string getString(const Dict* dict, const std::string& key)
}
} // namespace
void XmlRpcMethodTest::testAddUri()
void RpcMethodTest::testAddUri()
{
AddUriXmlRpcMethod m;
XmlRpcRequest req(AddUriXmlRpcMethod::getMethodName(), List::g());
AddUriRpcMethod m;
RpcRequest req(AddUriRpcMethod::getMethodName(), List::g());
SharedHandle<List> urisParam = List::g();
urisParam->append("http://localhost/");
req.params->append(urisParam);
{
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res.code);
const std::deque<SharedHandle<RequestGroup> > rgs =
e_->getRequestGroupMan()->getReservedGroups();
@ -174,7 +174,7 @@ void XmlRpcMethodTest::testAddUri()
opt->put(PREF_DIR, "/sink");
req.params->append(opt);
{
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res.code);
CPPUNIT_ASSERT_EQUAL(std::string("/sink"),
e_->getRequestGroupMan()->findReservedGroup(2)->
@ -182,50 +182,50 @@ void XmlRpcMethodTest::testAddUri()
}
}
void XmlRpcMethodTest::testAddUri_withoutUri()
void RpcMethodTest::testAddUri_withoutUri()
{
AddUriXmlRpcMethod m;
XmlRpcRequest req(AddUriXmlRpcMethod::getMethodName(), List::g());
XmlRpcResponse res = m.execute(req, e_.get());
AddUriRpcMethod m;
RpcRequest req(AddUriRpcMethod::getMethodName(), List::g());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code);
}
void XmlRpcMethodTest::testAddUri_notUri()
void RpcMethodTest::testAddUri_notUri()
{
AddUriXmlRpcMethod m;
XmlRpcRequest req(AddUriXmlRpcMethod::getMethodName(), List::g());
AddUriRpcMethod m;
RpcRequest req(AddUriRpcMethod::getMethodName(), List::g());
SharedHandle<List> urisParam = List::g();
urisParam->append("not uri");
req.params->append(urisParam);
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code);
}
void XmlRpcMethodTest::testAddUri_withBadOption()
void RpcMethodTest::testAddUri_withBadOption()
{
AddUriXmlRpcMethod m;
XmlRpcRequest req(AddUriXmlRpcMethod::getMethodName(), List::g());
AddUriRpcMethod m;
RpcRequest req(AddUriRpcMethod::getMethodName(), List::g());
SharedHandle<List> urisParam = List::g();
urisParam->append("http://localhost");
req.params->append(urisParam);
SharedHandle<Dict> opt = Dict::g();
opt->put(PREF_FILE_ALLOCATION, "badvalue");
req.params->append(opt);
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code);
}
void XmlRpcMethodTest::testAddUri_withPosition()
void RpcMethodTest::testAddUri_withPosition()
{
AddUriXmlRpcMethod m;
XmlRpcRequest req1(AddUriXmlRpcMethod::getMethodName(), List::g());
AddUriRpcMethod m;
RpcRequest req1(AddUriRpcMethod::getMethodName(), List::g());
SharedHandle<List> urisParam1 = List::g();
urisParam1->append("http://uri1");
req1.params->append(urisParam1);
XmlRpcResponse res1 = m.execute(req1, e_.get());
RpcResponse res1 = m.execute(req1, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res1.code);
XmlRpcRequest req2(AddUriXmlRpcMethod::getMethodName(), List::g());
RpcRequest req2(AddUriRpcMethod::getMethodName(), List::g());
SharedHandle<List> urisParam2 = List::g();
urisParam2->append("http://uri2");
req2.params->append(urisParam2);
@ -240,32 +240,32 @@ void XmlRpcMethodTest::testAddUri_withPosition()
CPPUNIT_ASSERT_EQUAL(std::string("http://uri2"), uri);
}
void XmlRpcMethodTest::testAddUri_withBadPosition()
void RpcMethodTest::testAddUri_withBadPosition()
{
AddUriXmlRpcMethod m;
XmlRpcRequest req(AddUriXmlRpcMethod::getMethodName(), List::g());
AddUriRpcMethod m;
RpcRequest req(AddUriRpcMethod::getMethodName(), List::g());
SharedHandle<List> urisParam = List::g();
urisParam->append("http://localhost/");
req.params->append(urisParam);
req.params->append(Dict::g());
req.params->append(Integer::g(-1));
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code);
}
#ifdef ENABLE_BITTORRENT
void XmlRpcMethodTest::testAddTorrent()
void RpcMethodTest::testAddTorrent()
{
File(e_->getOption()->get(PREF_DIR)+
"/0a3893293e27ac0490424c06de4d09242215f0a6.torrent").remove();
AddTorrentXmlRpcMethod m;
XmlRpcRequest req(AddTorrentXmlRpcMethod::getMethodName(), List::g());
AddTorrentRpcMethod m;
RpcRequest req(AddTorrentRpcMethod::getMethodName(), List::g());
req.params->append(readFile(A2_TEST_DIR"/single.torrent"));
SharedHandle<List> uris = List::g();
uris->append("http://localhost/aria2-0.8.2.tar.bz2");
req.params->append(uris);
{
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT
(File(e_->getOption()->get(PREF_DIR)+
"/0a3893293e27ac0490424c06de4d09242215f0a6.torrent").exists());
@ -285,14 +285,14 @@ void XmlRpcMethodTest::testAddTorrent()
getRemainingUris()[0]);
}
// with options
std::string dir = A2_TEST_OUT_DIR"/aria2_XmlRpcMethodTest_testAddTorrent";
std::string dir = A2_TEST_OUT_DIR"/aria2_RpcMethodTest_testAddTorrent";
File(dir).mkdirs();
SharedHandle<Dict> opt = Dict::g();
opt->put(PREF_DIR, dir);
File(dir+"/0a3893293e27ac0490424c06de4d09242215f0a6.torrent").remove();
req.params->append(opt);
{
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res.code);
CPPUNIT_ASSERT_EQUAL
(dir+"/aria2-0.8.2.tar.bz2",
@ -302,34 +302,34 @@ void XmlRpcMethodTest::testAddTorrent()
}
}
void XmlRpcMethodTest::testAddTorrent_withoutTorrent()
void RpcMethodTest::testAddTorrent_withoutTorrent()
{
AddTorrentXmlRpcMethod m;
XmlRpcRequest req(AddTorrentXmlRpcMethod::getMethodName(), List::g());
XmlRpcResponse res = m.execute(req, e_.get());
AddTorrentRpcMethod m;
RpcRequest req(AddTorrentRpcMethod::getMethodName(), List::g());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code);
}
void XmlRpcMethodTest::testAddTorrent_notBase64Torrent()
void RpcMethodTest::testAddTorrent_notBase64Torrent()
{
AddTorrentXmlRpcMethod m;
XmlRpcRequest req(AddTorrentXmlRpcMethod::getMethodName(), List::g());
AddTorrentRpcMethod m;
RpcRequest req(AddTorrentRpcMethod::getMethodName(), List::g());
req.params->append("not torrent");
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code);
}
void XmlRpcMethodTest::testAddTorrent_withPosition()
void RpcMethodTest::testAddTorrent_withPosition()
{
AddTorrentXmlRpcMethod m;
XmlRpcRequest req1(AddTorrentXmlRpcMethod::getMethodName(), List::g());
AddTorrentRpcMethod m;
RpcRequest req1(AddTorrentRpcMethod::getMethodName(), List::g());
req1.params->append(readFile(A2_TEST_DIR"/test.torrent"));
req1.params->append(List::g());
req1.params->append(Dict::g());
XmlRpcResponse res1 = m.execute(req1, e_.get());
RpcResponse res1 = m.execute(req1, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res1.code);
XmlRpcRequest req2(AddTorrentXmlRpcMethod::getMethodName(), List::g());
RpcRequest req2(AddTorrentRpcMethod::getMethodName(), List::g());
req2.params->append(readFile(A2_TEST_DIR"/single.torrent"));
req2.params->append(List::g());
req2.params->append(Dict::g());
@ -344,15 +344,15 @@ void XmlRpcMethodTest::testAddTorrent_withPosition()
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
void XmlRpcMethodTest::testAddMetalink()
void RpcMethodTest::testAddMetalink()
{
File(e_->getOption()->get(PREF_DIR)+
"/c908634fbc257fd56f0114912c2772aeeb4064f4.metalink").remove();
AddMetalinkXmlRpcMethod m;
XmlRpcRequest req(AddMetalinkXmlRpcMethod::getMethodName(), List::g());
AddMetalinkRpcMethod m;
RpcRequest req(AddMetalinkRpcMethod::getMethodName(), List::g());
req.params->append(readFile(A2_TEST_DIR"/2files.metalink"));
{
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res.code);
const List* resParams = asList(res.param);
CPPUNIT_ASSERT_EQUAL((size_t)2, resParams->size());
@ -374,14 +374,14 @@ void XmlRpcMethodTest::testAddMetalink()
deb->getFirstFilePath());
}
// with options
std::string dir = A2_TEST_OUT_DIR"/aria2_XmlRpcMethodTest_testAddMetalink";
std::string dir = A2_TEST_OUT_DIR"/aria2_RpcMethodTest_testAddMetalink";
File(dir).mkdirs();
SharedHandle<Dict> opt = Dict::g();
opt->put(PREF_DIR, dir);
File(dir+"/c908634fbc257fd56f0114912c2772aeeb4064f4.metalink").remove();
req.params->append(opt);
{
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res.code);
CPPUNIT_ASSERT_EQUAL(dir+"/aria2-5.0.0.tar.bz2",
e_->getRequestGroupMan()->findReservedGroup(3)->
@ -391,39 +391,39 @@ void XmlRpcMethodTest::testAddMetalink()
}
}
void XmlRpcMethodTest::testAddMetalink_withoutMetalink()
void RpcMethodTest::testAddMetalink_withoutMetalink()
{
AddMetalinkXmlRpcMethod m;
XmlRpcRequest req(AddMetalinkXmlRpcMethod::getMethodName(), List::g());
XmlRpcResponse res = m.execute(req, e_.get());
AddMetalinkRpcMethod m;
RpcRequest req(AddMetalinkRpcMethod::getMethodName(), List::g());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code);
}
void XmlRpcMethodTest::testAddMetalink_notBase64Metalink()
void RpcMethodTest::testAddMetalink_notBase64Metalink()
{
AddMetalinkXmlRpcMethod m;
XmlRpcRequest req(AddMetalinkXmlRpcMethod::getMethodName(), List::g());
AddMetalinkRpcMethod m;
RpcRequest req(AddMetalinkRpcMethod::getMethodName(), List::g());
req.params->append("not metalink");
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code);
}
void XmlRpcMethodTest::testAddMetalink_withPosition()
void RpcMethodTest::testAddMetalink_withPosition()
{
AddUriXmlRpcMethod m1;
XmlRpcRequest req1(AddUriXmlRpcMethod::getMethodName(), List::g());
AddUriRpcMethod m1;
RpcRequest req1(AddUriRpcMethod::getMethodName(), List::g());
SharedHandle<List> urisParam1 = List::g();
urisParam1->append("http://uri");
req1.params->append(urisParam1);
XmlRpcResponse res1 = m1.execute(req1, e_.get());
RpcResponse res1 = m1.execute(req1, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res1.code);
AddMetalinkXmlRpcMethod m2;
XmlRpcRequest req2("ari2.addMetalink", List::g());
AddMetalinkRpcMethod m2;
RpcRequest req2("ari2.addMetalink", List::g());
req2.params->append(readFile(A2_TEST_DIR"/2files.metalink"));
req2.params->append(Dict::g());
req2.params->append(Integer::g(0));
XmlRpcResponse res2 = m2.execute(req2, e_.get());
RpcResponse res2 = m2.execute(req2, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res2.code);
CPPUNIT_ASSERT_EQUAL(e_->getOption()->get(PREF_DIR)+"/aria2-5.0.0.tar.bz2",
@ -433,13 +433,13 @@ void XmlRpcMethodTest::testAddMetalink_withPosition()
#endif // ENABLE_METALINK
void XmlRpcMethodTest::testChangeOption()
void RpcMethodTest::testChangeOption()
{
SharedHandle<RequestGroup> group(new RequestGroup(option_));
e_->getRequestGroupMan()->addReservedGroup(group);
ChangeOptionXmlRpcMethod m;
XmlRpcRequest req(ChangeOptionXmlRpcMethod::getMethodName(), List::g());
ChangeOptionRpcMethod m;
RpcRequest req(ChangeOptionRpcMethod::getMethodName(), List::g());
req.params->append("1");
SharedHandle<Dict> opt = Dict::g();
opt->put(PREF_MAX_DOWNLOAD_LIMIT, "100K");
@ -453,7 +453,7 @@ void XmlRpcMethodTest::testChangeOption()
e_->getBtRegistry()->put(group->getGID(), btObject);
#endif // ENABLE_BITTORRENT
req.params->append(opt);
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
SharedHandle<Option> option = group->getOption();
@ -476,56 +476,56 @@ void XmlRpcMethodTest::testChangeOption()
#endif // ENABLE_BITTORRENT
}
void XmlRpcMethodTest::testChangeOption_withBadOption()
void RpcMethodTest::testChangeOption_withBadOption()
{
SharedHandle<RequestGroup> group(new RequestGroup(option_));
e_->getRequestGroupMan()->addReservedGroup(group);
ChangeOptionXmlRpcMethod m;
XmlRpcRequest req(ChangeOptionXmlRpcMethod::getMethodName(), List::g());
ChangeOptionRpcMethod m;
RpcRequest req(ChangeOptionRpcMethod::getMethodName(), List::g());
req.params->append("1");
SharedHandle<Dict> opt = Dict::g();
opt->put(PREF_MAX_DOWNLOAD_LIMIT, "badvalue");
req.params->append(opt);
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code);
}
void XmlRpcMethodTest::testChangeOption_withNotAllowedOption()
void RpcMethodTest::testChangeOption_withNotAllowedOption()
{
SharedHandle<RequestGroup> group(new RequestGroup(option_));
e_->getRequestGroupMan()->addReservedGroup(group);
ChangeOptionXmlRpcMethod m;
XmlRpcRequest req(ChangeOptionXmlRpcMethod::getMethodName(), List::g());
ChangeOptionRpcMethod m;
RpcRequest req(ChangeOptionRpcMethod::getMethodName(), List::g());
req.params->append("1");
SharedHandle<Dict> opt = Dict::g();
opt->put(PREF_MAX_OVERALL_DOWNLOAD_LIMIT, "100K");
req.params->append(opt);
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code);
}
void XmlRpcMethodTest::testChangeOption_withoutGid()
void RpcMethodTest::testChangeOption_withoutGid()
{
ChangeOptionXmlRpcMethod m;
XmlRpcRequest req(ChangeOptionXmlRpcMethod::getMethodName(), List::g());
XmlRpcResponse res = m.execute(req, e_.get());
ChangeOptionRpcMethod m;
RpcRequest req(ChangeOptionRpcMethod::getMethodName(), List::g());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code);
}
void XmlRpcMethodTest::testChangeGlobalOption()
void RpcMethodTest::testChangeGlobalOption()
{
ChangeGlobalOptionXmlRpcMethod m;
XmlRpcRequest req
(ChangeGlobalOptionXmlRpcMethod::getMethodName(), List::g());
ChangeGlobalOptionRpcMethod m;
RpcRequest req
(ChangeGlobalOptionRpcMethod::getMethodName(), List::g());
SharedHandle<Dict> opt = Dict::g();
opt->put(PREF_MAX_OVERALL_DOWNLOAD_LIMIT, "100K");
#ifdef ENABLE_BITTORRENT
opt->put(PREF_MAX_OVERALL_UPLOAD_LIMIT, "50K");
#endif // ENABLE_BITTORRENT
req.params->append(opt);
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res.code);
CPPUNIT_ASSERT_EQUAL
@ -542,73 +542,53 @@ void XmlRpcMethodTest::testChangeGlobalOption()
#endif // ENABLE_BITTORRENT
}
void XmlRpcMethodTest::testChangeGlobalOption_withBadOption()
void RpcMethodTest::testChangeGlobalOption_withBadOption()
{
ChangeGlobalOptionXmlRpcMethod m;
XmlRpcRequest req
(ChangeGlobalOptionXmlRpcMethod::getMethodName(), List::g());
ChangeGlobalOptionRpcMethod m;
RpcRequest req
(ChangeGlobalOptionRpcMethod::getMethodName(), List::g());
SharedHandle<Dict> opt = Dict::g();
opt->put(PREF_MAX_OVERALL_DOWNLOAD_LIMIT, "badvalue");
req.params->append(opt);
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code);
}
void XmlRpcMethodTest::testChangeGlobalOption_withNotAllowedOption()
void RpcMethodTest::testChangeGlobalOption_withNotAllowedOption()
{
ChangeGlobalOptionXmlRpcMethod m;
XmlRpcRequest req
(ChangeGlobalOptionXmlRpcMethod::getMethodName(), List::g());
ChangeGlobalOptionRpcMethod m;
RpcRequest req
(ChangeGlobalOptionRpcMethod::getMethodName(), List::g());
SharedHandle<Dict> opt = Dict::g();
opt->put(PREF_MAX_DOWNLOAD_LIMIT, "100K");
req.params->append(opt);
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code);
}
void XmlRpcMethodTest::testNoSuchMethod()
void RpcMethodTest::testNoSuchMethod()
{
NoSuchMethodXmlRpcMethod m;
XmlRpcRequest req("make.hamburger", List::g());
XmlRpcResponse res = m.execute(req, 0);
NoSuchMethodRpcMethod m;
RpcRequest req("make.hamburger", List::g());
RpcResponse res = m.execute(req, 0);
CPPUNIT_ASSERT_EQUAL(1, res.code);
CPPUNIT_ASSERT_EQUAL(std::string("No such method: make.hamburger"),
getString(asDict(res.param), "faultString"));
CPPUNIT_ASSERT_EQUAL
(std::string("<?xml version=\"1.0\"?>"
"<methodResponse>"
"<fault>"
"<value>"
"<struct>"
"<member>"
"<name>faultCode</name><value><int>1</int></value>"
"</member>"
"<member>"
"<name>faultString</name>"
"<value>"
"<string>No such method: make.hamburger</string>"
"</value>"
"</member>"
"</struct>"
"</value>"
"</fault>"
"</methodResponse>"),
res.toXml());
}
void XmlRpcMethodTest::testTellStatus_withoutGid()
void RpcMethodTest::testTellStatus_withoutGid()
{
TellStatusXmlRpcMethod m;
XmlRpcRequest req(TellStatusXmlRpcMethod::getMethodName(), List::g());
XmlRpcResponse res = m.execute(req, e_.get());
TellStatusRpcMethod m;
RpcRequest req(TellStatusRpcMethod::getMethodName(), List::g());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code);
}
namespace {
void addUri(const std::string& uri, const SharedHandle<DownloadEngine>& e)
{
AddUriXmlRpcMethod m;
XmlRpcRequest req(AddUriXmlRpcMethod::getMethodName(), List::g());
AddUriRpcMethod m;
RpcRequest req(AddUriRpcMethod::getMethodName(), List::g());
SharedHandle<List> urisParam = List::g();
urisParam->append(uri);
req.params->append(urisParam);
@ -621,15 +601,15 @@ namespace {
void addTorrent
(const std::string& torrentFile, const SharedHandle<DownloadEngine>& e)
{
AddTorrentXmlRpcMethod m;
XmlRpcRequest req(AddTorrentXmlRpcMethod::getMethodName(), List::g());
AddTorrentRpcMethod m;
RpcRequest req(AddTorrentRpcMethod::getMethodName(), List::g());
req.params->append(readFile(torrentFile));
XmlRpcResponse res = m.execute(req, e.get());
RpcResponse res = m.execute(req, e.get());
}
} // namespace
#endif // ENABLE_BITTORRENT
void XmlRpcMethodTest::testTellWaiting()
void RpcMethodTest::testTellWaiting()
{
addUri("http://1/", e_);
addUri("http://2/", e_);
@ -640,11 +620,11 @@ void XmlRpcMethodTest::testTellWaiting()
addUri("http://4/", e_);
#endif // !ENABLE_BITTORRENT
TellWaitingXmlRpcMethod m;
XmlRpcRequest req(TellWaitingXmlRpcMethod::getMethodName(), List::g());
TellWaitingRpcMethod m;
RpcRequest req(TellWaitingRpcMethod::getMethodName(), List::g());
req.params->append(Integer::g(1));
req.params->append(Integer::g(2));
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res.code);
const List* resParams = asList(res.param);
CPPUNIT_ASSERT_EQUAL((size_t)2, resParams->size());
@ -653,7 +633,7 @@ void XmlRpcMethodTest::testTellWaiting()
CPPUNIT_ASSERT_EQUAL(std::string("3"),
getString(asDict(resParams->get(1)), "gid"));
// waiting.size() == offset+num
req = XmlRpcRequest(TellWaitingXmlRpcMethod::getMethodName(), List::g());
req = RpcRequest(TellWaitingRpcMethod::getMethodName(), List::g());
req.params->append(Integer::g(1));
req.params->append(Integer::g(3));
res = m.execute(req, e_.get());
@ -661,7 +641,7 @@ void XmlRpcMethodTest::testTellWaiting()
resParams = asList(res.param);
CPPUNIT_ASSERT_EQUAL((size_t)3, resParams->size());
// waiting.size() < offset+num
req = XmlRpcRequest(TellWaitingXmlRpcMethod::getMethodName(), List::g());
req = RpcRequest(TellWaitingRpcMethod::getMethodName(), List::g());
req.params->append(Integer::g(1));
req.params->append(Integer::g(4));
res = m.execute(req, e_.get());
@ -669,7 +649,7 @@ void XmlRpcMethodTest::testTellWaiting()
resParams = asList(res.param);
CPPUNIT_ASSERT_EQUAL((size_t)3, resParams->size());
// negative offset
req = XmlRpcRequest(TellWaitingXmlRpcMethod::getMethodName(), List::g());
req = RpcRequest(TellWaitingRpcMethod::getMethodName(), List::g());
req.params->append(Integer::g(-1));
req.params->append(Integer::g(2));
res = m.execute(req, e_.get());
@ -700,19 +680,19 @@ void XmlRpcMethodTest::testTellWaiting()
CPPUNIT_ASSERT_EQUAL((size_t)1, resParams->size());
}
void XmlRpcMethodTest::testTellWaiting_fail()
void RpcMethodTest::testTellWaiting_fail()
{
TellWaitingXmlRpcMethod m;
XmlRpcRequest req(TellWaitingXmlRpcMethod::getMethodName(), List::g());
XmlRpcResponse res = m.execute(req, e_.get());
TellWaitingRpcMethod m;
RpcRequest req(TellWaitingRpcMethod::getMethodName(), List::g());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code);
}
void XmlRpcMethodTest::testGetVersion()
void RpcMethodTest::testGetVersion()
{
GetVersionXmlRpcMethod m;
XmlRpcRequest req(GetVersionXmlRpcMethod::getMethodName(), List::g());
XmlRpcResponse res = m.execute(req, e_.get());
GetVersionRpcMethod m;
RpcRequest req(GetVersionRpcMethod::getMethodName(), List::g());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res.code);
const Dict* resParams = asDict(res.param);
CPPUNIT_ASSERT_EQUAL(std::string(PACKAGE_VERSION),
@ -730,7 +710,7 @@ void XmlRpcMethodTest::testGetVersion()
features);
}
void XmlRpcMethodTest::testGatherStoppedDownload()
void RpcMethodTest::testGatherStoppedDownload()
{
std::vector<SharedHandle<FileEntry> > fileEntries;
std::vector<gid_t> followedBy;
@ -763,7 +743,7 @@ void XmlRpcMethodTest::testGatherStoppedDownload()
CPPUNIT_ASSERT(entry->containsKey("gid"));
}
void XmlRpcMethodTest::testGatherProgressCommon()
void RpcMethodTest::testGatherProgressCommon()
{
SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0,"aria2.tar.bz2"));
std::string uris[] = { "http://localhost/aria2.tar.bz2" };
@ -813,7 +793,7 @@ void XmlRpcMethodTest::testGatherProgressCommon()
}
#ifdef ENABLE_BITTORRENT
void XmlRpcMethodTest::testGatherBitTorrentMetadata()
void RpcMethodTest::testGatherBitTorrentMetadata()
{
SharedHandle<Option> option(new Option());
option->put(PREF_DIR, ".");
@ -857,30 +837,30 @@ void XmlRpcMethodTest::testGatherBitTorrentMetadata()
}
#endif // ENABLE_BITTORRENT
void XmlRpcMethodTest::testChangePosition()
void RpcMethodTest::testChangePosition()
{
e_->getRequestGroupMan()->addReservedGroup
(SharedHandle<RequestGroup>(new RequestGroup(option_)));
e_->getRequestGroupMan()->addReservedGroup
(SharedHandle<RequestGroup>(new RequestGroup(option_)));
ChangePositionXmlRpcMethod m;
XmlRpcRequest req(ChangePositionXmlRpcMethod::getMethodName(), List::g());
ChangePositionRpcMethod m;
RpcRequest req(ChangePositionRpcMethod::getMethodName(), List::g());
req.params->append("1");
req.params->append(Integer::g(1));
req.params->append("POS_SET");
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res.code);
CPPUNIT_ASSERT_EQUAL((int64_t)1, asInteger(res.param)->i());
CPPUNIT_ASSERT_EQUAL
((gid_t)1, e_->getRequestGroupMan()->getReservedGroups()[1]->getGID());
}
void XmlRpcMethodTest::testChangePosition_fail()
void RpcMethodTest::testChangePosition_fail()
{
ChangePositionXmlRpcMethod m;
XmlRpcRequest req(ChangePositionXmlRpcMethod::getMethodName(), List::g());
XmlRpcResponse res = m.execute(req, e_.get());
ChangePositionRpcMethod m;
RpcRequest req(ChangePositionRpcMethod::getMethodName(), List::g());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code);
req.params->append("1");
@ -889,7 +869,7 @@ void XmlRpcMethodTest::testChangePosition_fail()
CPPUNIT_ASSERT_EQUAL(1, res.code);
}
void XmlRpcMethodTest::testChangeUri()
void RpcMethodTest::testChangeUri()
{
SharedHandle<FileEntry> files[3];
for(int i = 0; i < 3; ++i) {
@ -904,8 +884,8 @@ void XmlRpcMethodTest::testChangeUri()
group->setDownloadContext(dctx);
e_->getRequestGroupMan()->addReservedGroup(group);
ChangeUriXmlRpcMethod m;
XmlRpcRequest req(ChangeUriXmlRpcMethod::getMethodName(), List::g());
ChangeUriRpcMethod m;
RpcRequest req(ChangeUriRpcMethod::getMethodName(), List::g());
req.params->append("1"); // GID
req.params->append(Integer::g(2)); // index of FileEntry
SharedHandle<List> removeuris = List::g();
@ -919,7 +899,7 @@ void XmlRpcMethodTest::testChangeUri()
adduris->append("baduri");
adduris->append("http://example.org/added3");
req.params->append(adduris);
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res.code);
CPPUNIT_ASSERT_EQUAL((int64_t)2, asInteger(asList(res.param)->get(0))->i());
CPPUNIT_ASSERT_EQUAL((int64_t)3, asInteger(asList(res.param)->get(1))->i());
@ -962,7 +942,7 @@ void XmlRpcMethodTest::testChangeUri()
CPPUNIT_ASSERT_EQUAL(std::string("http://example.org/added1-2"), uris[1]);
}
void XmlRpcMethodTest::testChangeUri_fail()
void RpcMethodTest::testChangeUri_fail()
{
SharedHandle<FileEntry> files[3];
for(int i = 0; i < 3; ++i) {
@ -974,15 +954,15 @@ void XmlRpcMethodTest::testChangeUri_fail()
group->setDownloadContext(dctx);
e_->getRequestGroupMan()->addReservedGroup(group);
ChangeUriXmlRpcMethod m;
XmlRpcRequest req(ChangeUriXmlRpcMethod::getMethodName(), List::g());
ChangeUriRpcMethod m;
RpcRequest req(ChangeUriRpcMethod::getMethodName(), List::g());
req.params->append("1"); // GID
req.params->append(Integer::g(1)); // index of FileEntry
SharedHandle<List> removeuris = List::g();
req.params->append(removeuris);
SharedHandle<List> adduris = List::g();
req.params->append(adduris);
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res.code);
req.params->set(0, String::g("2"));
@ -1014,17 +994,17 @@ void XmlRpcMethodTest::testChangeUri_fail()
CPPUNIT_ASSERT_EQUAL(1, res.code);
}
void XmlRpcMethodTest::testGetSessionInfo()
void RpcMethodTest::testGetSessionInfo()
{
GetSessionInfoXmlRpcMethod m;
XmlRpcRequest req(GetSessionInfoXmlRpcMethod::getMethodName(), List::g());
XmlRpcResponse res = m.execute(req, e_.get());
GetSessionInfoRpcMethod m;
RpcRequest req(GetSessionInfoRpcMethod::getMethodName(), List::g());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res.code);
CPPUNIT_ASSERT_EQUAL(util::toHex(e_->getSessionId()),
getString(asDict(res.param), "sessionId"));
}
void XmlRpcMethodTest::testPause()
void RpcMethodTest::testPause()
{
const std::string URIS[] = {
"http://url1",
@ -1038,43 +1018,43 @@ void XmlRpcMethodTest::testPause()
CPPUNIT_ASSERT_EQUAL((size_t)3, groups.size());
e_->getRequestGroupMan()->addReservedGroup(groups);
{
PauseXmlRpcMethod m;
XmlRpcRequest req(PauseXmlRpcMethod::getMethodName(), List::g());
PauseRpcMethod m;
RpcRequest req(PauseRpcMethod::getMethodName(), List::g());
req.params->append("1");
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res.code);
}
CPPUNIT_ASSERT(groups[0]->isPauseRequested());
{
UnpauseXmlRpcMethod m;
XmlRpcRequest req(UnpauseXmlRpcMethod::getMethodName(), List::g());
UnpauseRpcMethod m;
RpcRequest req(UnpauseRpcMethod::getMethodName(), List::g());
req.params->append("1");
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res.code);
}
CPPUNIT_ASSERT(!groups[0]->isPauseRequested());
{
PauseAllXmlRpcMethod m;
XmlRpcRequest req(PauseAllXmlRpcMethod::getMethodName(), List::g());
XmlRpcResponse res = m.execute(req, e_.get());
PauseAllRpcMethod m;
RpcRequest req(PauseAllRpcMethod::getMethodName(), List::g());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res.code);
}
for(size_t i = 0; i < groups.size(); ++i) {
CPPUNIT_ASSERT(groups[i]->isPauseRequested());
}
{
UnpauseAllXmlRpcMethod m;
XmlRpcRequest req(UnpauseAllXmlRpcMethod::getMethodName(), List::g());
XmlRpcResponse res = m.execute(req, e_.get());
UnpauseAllRpcMethod m;
RpcRequest req(UnpauseAllRpcMethod::getMethodName(), List::g());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res.code);
}
for(size_t i = 0; i < groups.size(); ++i) {
CPPUNIT_ASSERT(!groups[i]->isPauseRequested());
}
{
ForcePauseAllXmlRpcMethod m;
XmlRpcRequest req(ForcePauseAllXmlRpcMethod::getMethodName(), List::g());
XmlRpcResponse res = m.execute(req, e_.get());
ForcePauseAllRpcMethod m;
RpcRequest req(ForcePauseAllRpcMethod::getMethodName(), List::g());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res.code);
}
for(size_t i = 0; i < groups.size(); ++i) {
@ -1082,15 +1062,15 @@ void XmlRpcMethodTest::testPause()
}
}
void XmlRpcMethodTest::testSystemMulticall()
void RpcMethodTest::testSystemMulticall()
{
SystemMulticallXmlRpcMethod m;
XmlRpcRequest req("system.multicall", List::g());
SystemMulticallRpcMethod m;
RpcRequest req("system.multicall", List::g());
SharedHandle<List> reqparams = List::g();
req.params->append(reqparams);
for(int i = 0; i < 2; ++i) {
SharedHandle<Dict> dict = Dict::g();
dict->put("methodName", AddUriXmlRpcMethod::getMethodName());
dict->put("methodName", AddUriRpcMethod::getMethodName());
SharedHandle<List> params = List::g();
SharedHandle<List> urisParam = List::g();
urisParam->append("http://localhost/"+util::itos(i));
@ -1116,16 +1096,16 @@ void XmlRpcMethodTest::testSystemMulticall()
{
// missing params
SharedHandle<Dict> dict = Dict::g();
dict->put("methodName", GetVersionXmlRpcMethod::getMethodName());
dict->put("methodName", GetVersionRpcMethod::getMethodName());
reqparams->append(dict);
}
{
SharedHandle<Dict> dict = Dict::g();
dict->put("methodName", GetVersionXmlRpcMethod::getMethodName());
dict->put("methodName", GetVersionRpcMethod::getMethodName());
dict->put("params", List::g());
reqparams->append(dict);
}
XmlRpcResponse res = m.execute(req, e_.get());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(0, res.code);
const List* resParams = asList(res.param);
CPPUNIT_ASSERT_EQUAL((size_t)7, resParams->size());
@ -1152,14 +1132,14 @@ void XmlRpcMethodTest::testSystemMulticall()
CPPUNIT_ASSERT(asList(resParams->get(6)));
}
void XmlRpcMethodTest::testSystemMulticall_fail()
void RpcMethodTest::testSystemMulticall_fail()
{
SystemMulticallXmlRpcMethod m;
XmlRpcRequest req("system.multicall", List::g());
XmlRpcResponse res = m.execute(req, e_.get());
SystemMulticallRpcMethod m;
RpcRequest req("system.multicall", List::g());
RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code);
}
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2

View File

@ -1,29 +1,35 @@
#include "XmlRpcResponse.h"
#include "RpcResponse.h"
#include <cppunit/extensions/HelperMacros.h>
namespace aria2 {
namespace xmlrpc {
namespace rpc {
class XmlRpcResponseTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(XmlRpcResponseTest);
class RpcResponseTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(RpcResponseTest);
CPPUNIT_TEST(testToJson);
#ifdef ENABLE_XML_RPC
CPPUNIT_TEST(testToXml);
#endif // ENABLE_XML_RPC
CPPUNIT_TEST_SUITE_END();
public:
void testToJson();
#ifdef ENABLE_XML_RPC
void testToXml();
#endif // ENABLE_XML_RPC
};
CPPUNIT_TEST_SUITE_REGISTRATION(XmlRpcResponseTest);
CPPUNIT_TEST_SUITE_REGISTRATION(RpcResponseTest);
void XmlRpcResponseTest::testToJson()
void RpcResponseTest::testToJson()
{
std::vector<XmlRpcResponse> results;
std::vector<RpcResponse> results;
{
SharedHandle<List> param = List::g();
param->append(Integer::g(1));
SharedHandle<String> id = String::g("9");
XmlRpcResponse res(0, param, id);
RpcResponse res(0, param, id);
results.push_back(res);
std::string s = res.toJson("", false);
CPPUNIT_ASSERT_EQUAL(std::string("{\"id\":\"9\","
@ -36,7 +42,7 @@ void XmlRpcResponseTest::testToJson()
SharedHandle<Dict> param = Dict::g();
param->put("code", Integer::g(1));
param->put("message", "HELLO ERROR");
XmlRpcResponse res(1, param, Null::g());
RpcResponse res(1, param, Null::g());
results.push_back(res);
std::string s = res.toJson("", false);
CPPUNIT_ASSERT_EQUAL(std::string("{\"error\":{\"code\":1,"
@ -63,6 +69,37 @@ void XmlRpcResponseTest::testToJson()
}
}
} // namespace xmlrpc
#ifdef ENABLE_XML_RPC
void RpcResponseTest::testToXml()
{
SharedHandle<Dict> param = Dict::g();
param->put("faultCode", Integer::g(1));
param->put("faultString", "No such method: make.hamburger");
RpcResponse res(1, param, Null::g());
std::string s = res.toXml(false);
CPPUNIT_ASSERT_EQUAL
(std::string("<?xml version=\"1.0\"?>"
"<methodResponse>"
"<fault>"
"<value>"
"<struct>"
"<member>"
"<name>faultCode</name><value><int>1</int></value>"
"</member>"
"<member>"
"<name>faultString</name>"
"<value>"
"<string>No such method: make.hamburger</string>"
"</value>"
"</member>"
"</struct>"
"</value>"
"</fault>"
"</methodResponse>"),
s);
}
#endif // ENABLE_XML_RPC
} // namespace rpc
} // namespace aria2

View File

@ -4,7 +4,7 @@
namespace aria2 {
namespace xmlrpc {
namespace rpc {
class XmlRpcRequestParserControllerTest:public CppUnit::TestFixture {
@ -157,6 +157,6 @@ void XmlRpcRequestParserControllerTest::testPopArrayFrame_compound()
CPPUNIT_ASSERT_EQUAL(std::string("jp"), asString(countryList->get(0))->s());
}
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2

View File

@ -7,7 +7,7 @@
namespace aria2 {
namespace xmlrpc {
namespace rpc {
class XmlRpcRequestProcessorTest:public CppUnit::TestFixture {
@ -30,7 +30,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(XmlRpcRequestProcessorTest);
void XmlRpcRequestProcessorTest::testParseMemory()
{
XmlRpcRequestProcessor proc;
XmlRpcRequest req =
RpcRequest req =
proc.parseMemory("<?xml version=\"1.0\"?>"
"<methodCall>"
" <methodName>aria2.addURI</methodName>"
@ -95,7 +95,7 @@ void XmlRpcRequestProcessorTest::testParseMemory_shouldFail()
// success
}
{
XmlRpcRequest req =
RpcRequest req =
proc.parseMemory("<methodCall>"
" <methodName>aria2.addURI</methodName>"
" <params>"
@ -104,7 +104,7 @@ void XmlRpcRequestProcessorTest::testParseMemory_shouldFail()
CPPUNIT_ASSERT(req.params);
}
try {
XmlRpcRequest req =
RpcRequest req =
proc.parseMemory("<methodCall>"
" <methodName>aria2.addURI</methodName>"
"</methodCall>");
@ -114,6 +114,6 @@ void XmlRpcRequestProcessorTest::testParseMemory_shouldFail()
}
}
} // namespace xmlrpc
} // namespace rpc
} // namespace aria2