diff --git a/src/DownloadEngineFactory.cc b/src/DownloadEngineFactory.cc index 5b793cad..e976913c 100644 --- a/src/DownloadEngineFactory.cc +++ b/src/DownloadEngineFactory.cc @@ -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; } diff --git a/src/ExpatXmlRpcRequestProcessor.cc b/src/ExpatXmlRpcRequestProcessor.cc index b353abac..46bd6214 100644 --- a/src/ExpatXmlRpcRequestProcessor.cc +++ b/src/ExpatXmlRpcRequestProcessor.cc @@ -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(), - static_pointer_cast(stm_->getCurrentFrameValue())); + return RpcRequest(stm_->getMethodName(), + static_pointer_cast(stm_->getCurrentFrameValue())); } -} // namespace xmlrpc +} // namespace rpc } // namespace aria2 diff --git a/src/ExpatXmlRpcRequestProcessor.h b/src/ExpatXmlRpcRequestProcessor.h index 6959c013..e61f1d3d 100644 --- a/src/ExpatXmlRpcRequestProcessor.h +++ b/src/ExpatXmlRpcRequestProcessor.h @@ -40,11 +40,11 @@ #include #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 stm_; public: - XmlRpcRequest parseMemory(const std::string& xml); + RpcRequest parseMemory(const std::string& xml); }; -} // namespace xmlrpc +} // namespace rpc } // namespace aria2 diff --git a/src/HttpServerBodyCommand.cc b/src/HttpServerBodyCommand.cc index 44eaa2f0..a545b1f6 100644 --- a/src/HttpServerBodyCommand.cc +++ b/src/HttpServerBodyCommand.cc @@ -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 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& results, +(const std::vector& 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 method; + rpc::RpcRequest req(methodName->s(), params, id); + SharedHandle 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 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 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())); 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 results; + std::vector 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())); sendJsonRpcResponse(res, callback); diff --git a/src/HttpServerBodyCommand.h b/src/HttpServerBodyCommand.h index b4503a8c..f8fcc881 100644 --- a/src/HttpServerBodyCommand.h +++ b/src/HttpServerBodyCommand.h @@ -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& id, const std::string& callback); void sendJsonRpcResponse - (const xmlrpc::XmlRpcResponse& res, + (const rpc::RpcResponse& res, const std::string& callback); void sendJsonRpcBatchResponse - (const std::vector& results, + (const std::vector& results, const std::string& callback); - xmlrpc::XmlRpcResponse processJsonRpcRequest(const Dict* jsondict); + rpc::RpcResponse processJsonRpcRequest(const Dict* jsondict); void addHttpServerResponseCommand(); public: HttpServerBodyCommand(cuid_t cuid, diff --git a/src/Makefile.am b/src/Makefile.am index 8a3b3d79..97e0ded3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index 65f92992..2e72ee49 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -228,7 +228,6 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers() handlers.push_back(op); } #endif // ENABLE_DIRECT_IO -#ifdef ENABLE_XML_RPC { SharedHandle 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 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 op(new NumberOptionHandler diff --git a/src/RequestGroupMan.cc b/src/RequestGroupMan.cc index 85063637..536543c8 100644 --- a/src/RequestGroupMan.cc +++ b/src/RequestGroupMan.cc @@ -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(); } diff --git a/src/XmlRpcMethod.cc b/src/RpcMethod.cc similarity index 88% rename from src/XmlRpcMethod.cc rename to src/RpcMethod.cc index 7621b0f2..96d05461 100644 --- a/src/XmlRpcMethod.cc +++ b/src/RpcMethod.cc @@ -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 XmlRpcMethod::createErrorResponse +SharedHandle RpcMethod::createErrorResponse (const Exception& e) { SharedHandle params = Dict::g(); @@ -68,14 +68,14 @@ SharedHandle 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