Deprecated --enable-xml-rpc and --xml-rpc-* option. Introduced

--enable-rpc and --rpc-* option instead.

--enable-xml-rpc and --xml-rpc-* option can be used but warning
message will be shown. The help tag #xml-rpc was replaced with #rpc.
pull/1/head
Tatsuhiro Tsujikawa 2011-03-14 21:02:25 +09:00
parent f0cfbb21c1
commit 3ddb68f340
14 changed files with 289 additions and 67 deletions

View File

@ -163,13 +163,13 @@ DownloadEngineFactory::newDownloadEngine
stopSec));
}
}
if(op->getAsBool(PREF_ENABLE_XML_RPC)) {
if(op->getAsBool(PREF_ENABLE_RPC)) {
static int families[] = { AF_INET, AF_INET6 };
size_t familiesLength = op->getAsBool(PREF_DISABLE_IPV6)?1:2;
for(size_t i = 0; i < familiesLength; ++i) {
HttpListenCommand* httpListenCommand =
new HttpListenCommand(e->newCUID(), e.get(), families[i]);
if(httpListenCommand->bindPort(op->getAsInt(PREF_XML_RPC_LISTEN_PORT))){
if(httpListenCommand->bindPort(op->getAsInt(PREF_RPC_LISTEN_PORT))){
e->addRoutineCommand(httpListenCommand);
} else {
delete httpListenCommand;

View File

@ -102,7 +102,7 @@ bool HttpListenCommand::bindPort(uint16_t port)
family_ == AF_INET?4:6));
try {
int flags = 0;
if(e_->getOption()->getAsBool(PREF_XML_RPC_LISTEN_ALL)) {
if(e_->getOption()->getAsBool(PREF_RPC_LISTEN_ALL)) {
flags = AI_PASSIVE;
}
serverSocket_->bind(A2STR::NIL, port, family_, flags);

View File

@ -64,8 +64,8 @@ HttpServerCommand::HttpServerCommand
{
setStatus(Command::STATUS_ONESHOT_REALTIME);
e_->addSocketForReadCheck(socket_, this);
httpServer_->setUsernamePassword(e_->getOption()->get(PREF_XML_RPC_USER),
e_->getOption()->get(PREF_XML_RPC_PASSWD));
httpServer_->setUsernamePassword(e_->getOption()->get(PREF_RPC_USER),
e_->getOption()->get(PREF_RPC_PASSWD));
#ifdef HAVE_ZLIB
httpServer_->enableGZip();
#else // !HAVE_ZLIB
@ -130,7 +130,7 @@ bool HttpServerCommand::execute()
return true;
}
if(static_cast<uint64_t>
(e_->getOption()->getAsInt(PREF_XML_RPC_MAX_REQUEST_SIZE)) <
(e_->getOption()->getAsInt(PREF_RPC_MAX_REQUEST_SIZE)) <
httpServer_->getContentLength()) {
A2_LOG_INFO(fmt("Request too long. ContentLength=%s."
" See --xml-rpc-max-request-size option to loose"

View File

@ -230,11 +230,24 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
#endif // ENABLE_DIRECT_IO
{
SharedHandle<OptionHandler> op(new BooleanOptionHandler
(PREF_ENABLE_XML_RPC,
TEXT_ENABLE_XML_RPC,
(PREF_ENABLE_RPC,
TEXT_ENABLE_RPC,
A2_V_FALSE,
OptionHandler::OPT_ARG));
op->addTag(TAG_XML_RPC);
op->addTag(TAG_RPC);
handlers.push_back(op);
}
{
// TODO Deprecated
SharedHandle<OptionHandler> op
(new DeprecatedOptionHandler
(SharedHandle<OptionHandler>(new BooleanOptionHandler
(PREF_ENABLE_XML_RPC,
TEXT_ENABLE_XML_RPC,
NO_DEFAULT_VALUE,
OptionHandler::OPT_ARG)),
PREF_ENABLE_RPC));
op->addTag(TAG_RPC);
handlers.push_back(op);
}
{
@ -568,43 +581,104 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
}
{
SharedHandle<OptionHandler> op(new BooleanOptionHandler
(PREF_XML_RPC_LISTEN_ALL,
TEXT_XML_RPC_LISTEN_ALL,
(PREF_RPC_LISTEN_ALL,
TEXT_RPC_LISTEN_ALL,
A2_V_FALSE,
OptionHandler::OPT_ARG));
op->addTag(TAG_XML_RPC);
op->addTag(TAG_RPC);
handlers.push_back(op);
}
{
SharedHandle<OptionHandler> op(new NumberOptionHandler
(PREF_XML_RPC_LISTEN_PORT,
TEXT_XML_RPC_LISTEN_PORT,
(PREF_RPC_LISTEN_PORT,
TEXT_RPC_LISTEN_PORT,
"6800",
1024, UINT16_MAX));
op->addTag(TAG_XML_RPC);
op->addTag(TAG_RPC);
handlers.push_back(op);
}
{
SharedHandle<OptionHandler> op(new UnitNumberOptionHandler
(PREF_XML_RPC_MAX_REQUEST_SIZE,
TEXT_XML_RPC_MAX_REQUEST_SIZE,
(PREF_RPC_MAX_REQUEST_SIZE,
TEXT_RPC_MAX_REQUEST_SIZE,
"2M",
0));
op->addTag(TAG_XML_RPC);
op->addTag(TAG_RPC);
handlers.push_back(op);
}
{
SharedHandle<OptionHandler> op(new DefaultOptionHandler
(PREF_XML_RPC_USER,
TEXT_XML_RPC_USER));
op->addTag(TAG_XML_RPC);
(PREF_RPC_USER,
TEXT_RPC_USER));
op->addTag(TAG_RPC);
handlers.push_back(op);
}
{
SharedHandle<OptionHandler> op(new DefaultOptionHandler
(PREF_XML_RPC_PASSWD,
TEXT_XML_RPC_PASSWD));
op->addTag(TAG_XML_RPC);
(PREF_RPC_PASSWD,
TEXT_RPC_PASSWD));
op->addTag(TAG_RPC);
handlers.push_back(op);
}
{
// TODO Deprecated
SharedHandle<OptionHandler> op
(new DeprecatedOptionHandler
(SharedHandle<OptionHandler>(new BooleanOptionHandler
(PREF_XML_RPC_LISTEN_ALL,
TEXT_XML_RPC_LISTEN_ALL,
NO_DEFAULT_VALUE,
OptionHandler::OPT_ARG)),
PREF_RPC_LISTEN_ALL));
op->addTag(TAG_RPC);
handlers.push_back(op);
}
{
// TODO Deprecated
SharedHandle<OptionHandler> op
(new DeprecatedOptionHandler
(SharedHandle<OptionHandler>(new NumberOptionHandler
(PREF_XML_RPC_LISTEN_PORT,
TEXT_XML_RPC_LISTEN_PORT,
NO_DEFAULT_VALUE,
1024, UINT16_MAX)),
PREF_RPC_LISTEN_PORT));
op->addTag(TAG_RPC);
handlers.push_back(op);
}
{
// TODO Deprecated
SharedHandle<OptionHandler> op
(new DeprecatedOptionHandler
(SharedHandle<OptionHandler>(new UnitNumberOptionHandler
(PREF_XML_RPC_MAX_REQUEST_SIZE,
TEXT_XML_RPC_MAX_REQUEST_SIZE,
NO_DEFAULT_VALUE,
0)),
PREF_RPC_MAX_REQUEST_SIZE));
op->addTag(TAG_RPC);
handlers.push_back(op);
}
{
// TODO Deprecated
SharedHandle<OptionHandler> op
(new DeprecatedOptionHandler
(SharedHandle<OptionHandler>(new DefaultOptionHandler
(PREF_XML_RPC_USER,
TEXT_XML_RPC_USER)),
PREF_RPC_USER));
op->addTag(TAG_RPC);
handlers.push_back(op);
}
{
// TODO Deprecated
SharedHandle<OptionHandler> op
(new DeprecatedOptionHandler
(SharedHandle<OptionHandler>(new DefaultOptionHandler
(PREF_XML_RPC_PASSWD,
TEXT_XML_RPC_PASSWD)),
PREF_RPC_PASSWD));
op->addTag(TAG_RPC);
handlers.push_back(op);
}
// HTTP/FTP options
@ -1689,7 +1763,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
TAG_COOKIE,
TAG_HOOK,
TAG_FILE,
TAG_XML_RPC,
TAG_RPC,
TAG_EXPERIMENTAL,
TAG_HELP,
TAG_ALL

View File

@ -55,6 +55,7 @@
#include "File.h"
#include "FileEntry.h"
#include "a2io.h"
#include "LogFactory.h"
namespace aria2 {
@ -728,4 +729,89 @@ std::string PrioritizePieceOptionHandler::createPossibleValuesString() const
return "head[=SIZE], tail[=SIZE]";
}
DeprecatedOptionHandler::DeprecatedOptionHandler
(const SharedHandle<OptionHandler>& depOptHandler,
const std::string& repOptName)
: depOptHandler_(depOptHandler), repOptName_(repOptName)
{}
bool DeprecatedOptionHandler::canHandle(const std::string& optName)
{
return depOptHandler_->canHandle(optName);
}
void DeprecatedOptionHandler::parse(Option& option, const std::string& arg)
{
A2_LOG_WARN(fmt("--%s option is deprecated. Use --%s option instead.",
depOptHandler_->getName().c_str(),
repOptName_.c_str()));
depOptHandler_->parse(option, arg);
option.put(repOptName_, option.get(depOptHandler_->getName()));
}
std::string DeprecatedOptionHandler::createPossibleValuesString() const
{
return depOptHandler_->createPossibleValuesString();
}
bool DeprecatedOptionHandler::hasTag(const std::string& tag) const
{
return depOptHandler_->hasTag(tag);
}
void DeprecatedOptionHandler::addTag(const std::string& tag)
{
depOptHandler_->addTag(tag);
}
std::string DeprecatedOptionHandler::toTagString() const
{
return depOptHandler_->toTagString();
}
const std::string& DeprecatedOptionHandler::getName() const
{
return depOptHandler_->getName();
}
const std::string& DeprecatedOptionHandler::getDescription() const
{
return depOptHandler_->getDescription();
}
const std::string& DeprecatedOptionHandler::getDefaultValue() const
{
return depOptHandler_->getDefaultValue();
}
bool DeprecatedOptionHandler::isHidden() const
{
return depOptHandler_->isHidden();
}
void DeprecatedOptionHandler::hide()
{
depOptHandler_->hide();
}
OptionHandler::ARG_TYPE DeprecatedOptionHandler::getArgType() const
{
return depOptHandler_->getArgType();
}
char DeprecatedOptionHandler::getShortName() const
{
return depOptHandler_->getShortName();
}
int DeprecatedOptionHandler::getOptionID() const
{
return depOptHandler_->getOptionID();
}
void DeprecatedOptionHandler::setOptionID(int id)
{
depOptHandler_->setOptionID(id);
}
} // namespace aria2

View File

@ -292,6 +292,31 @@ public:
virtual std::string createPossibleValuesString() const;
};
class DeprecatedOptionHandler:public OptionHandler {
private:
SharedHandle<OptionHandler> depOptHandler_;
std::string repOptName_;
public:
DeprecatedOptionHandler
(const SharedHandle<OptionHandler>& depOptHandler,
const std::string& repOptName);
virtual bool canHandle(const std::string& optName);
virtual void parse(Option& option, const std::string& arg);
virtual std::string createPossibleValuesString() const;
virtual bool hasTag(const std::string& tag) const;
virtual void addTag(const std::string& tag);
virtual std::string toTagString() const;
virtual const std::string& getName() const;
virtual const std::string& getDescription() const;
virtual const std::string& getDefaultValue() const;
virtual bool isHidden() const;
virtual void hide();
virtual ARG_TYPE getArgType() const;
virtual char getShortName() const;
virtual int getOptionID() const;
virtual void setOptionID(int id);
};
} // namespace aria2
#endif // D_OPTION_HANDLER_IMPL_H

View File

@ -89,7 +89,7 @@ RequestGroupMan::RequestGroupMan
(option->getAsInt(PREF_MAX_OVERALL_DOWNLOAD_LIMIT)),
maxOverallUploadSpeedLimit_(option->getAsInt
(PREF_MAX_OVERALL_UPLOAD_LIMIT)),
xmlRpc_(option->getAsBool(PREF_ENABLE_XML_RPC)),
rpc_(option->getAsBool(PREF_ENABLE_RPC)),
queueCheck_(true),
removedErrorResult_(0),
removedLastErrorResult_(error_code::FINISHED),
@ -100,7 +100,7 @@ RequestGroupMan::~RequestGroupMan() {}
bool RequestGroupMan::downloadFinished()
{
if(xmlRpc_) {
if(rpc_) {
return false;
}
return requestGroups_.empty() && reservedGroups_.empty();

View File

@ -71,8 +71,8 @@ private:
unsigned int maxOverallUploadSpeedLimit_;
// truf if XML-RPC is enabled.
bool xmlRpc_;
// true if JSON-RPC/XML-RPC is enabled.
bool rpc_;
bool queueCheck_;

View File

@ -45,7 +45,7 @@
#define TAG_COOKIE "#cookie"
#define TAG_HOOK "#hook"
#define TAG_FILE "#file"
#define TAG_XML_RPC "#xml-rpc"
#define TAG_RPC "#rpc"
#define TAG_EXPERIMENTAL "#experimental"
#define TAG_HELP "#help"
#define TAG_ALL "#all"

View File

@ -262,7 +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(!op->getAsBool(PREF_ENABLE_XML_RPC) && requestGroups.empty()) {
if(!op->getAsBool(PREF_ENABLE_RPC) && requestGroups.empty()) {
std::cout << MSG_NO_FILES_TO_DOWNLOAD << std::endl;
} else {
exitStatus = MultiUrlRequestInfo(requestGroups, op, getStatCalc(op),

View File

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

View File

@ -154,28 +154,40 @@ const std::string V_KQUEUE("kqueue");
const std::string V_PORT("port");
const std::string V_POLL("poll");
const std::string V_SELECT("select");
// value: true | false
const std::string PREF_ENABLE_RPC("enable-rpc");
// value: 1*digit
const std::string PREF_XML_RPC_LISTEN_PORT("xml-rpc-listen-port");
const std::string PREF_RPC_LISTEN_PORT("rpc-listen-port");
// value: string
const std::string PREF_RPC_USER("rpc-user");
// value: string
const std::string PREF_RPC_PASSWD("rpc-passwd");
// value: 1*digit
const std::string PREF_RPC_MAX_REQUEST_SIZE("rpc-max-request-size");
// value: true | false
const std::string PREF_RPC_LISTEN_ALL("rpc-listen-all");
// value: true | false
const std::string PREF_ENABLE_XML_RPC("enable-xml-rpc");
// value: true | false
const std::string PREF_DRY_RUN("dry-run");
// value: true | false
const std::string PREF_REUSE_URI("reuse-uri");
// value: 1*digit
const std::string PREF_XML_RPC_LISTEN_PORT("xml-rpc-listen-port");
// value: string
const std::string PREF_XML_RPC_USER("xml-rpc-user");
// value: string
const std::string PREF_XML_RPC_PASSWD("xml-rpc-passwd");
// value: 1*digit
const std::string PREF_XML_RPC_MAX_REQUEST_SIZE("xml-rpc-max-request-size");
// value: true | false
const std::string PREF_XML_RPC_LISTEN_ALL("xml-rpc-listen-all");
// value: true | false
const std::string PREF_DRY_RUN("dry-run");
// value: true | false
const std::string PREF_REUSE_URI("reuse-uri");
// value: string
const std::string PREF_ON_DOWNLOAD_START("on-download-start");
const std::string PREF_ON_DOWNLOAD_PAUSE("on-download-pause");
const std::string PREF_ON_DOWNLOAD_STOP("on-download-stop");
const std::string PREF_ON_DOWNLOAD_COMPLETE("on-download-complete");
const std::string PREF_ON_DOWNLOAD_ERROR("on-download-error");
// value: true | false
const std::string PREF_XML_RPC_LISTEN_ALL("xml-rpc-listen-all");
// value: string
const std::string PREF_INTERFACE("interface");
// value: true | false

View File

@ -158,28 +158,40 @@ extern const std::string V_KQUEUE;
extern const std::string V_PORT;
extern const std::string V_POLL;
extern const std::string V_SELECT;
// value: true | false
extern const std::string PREF_ENABLE_RPC;
// value: 1*digit
extern const std::string PREF_XML_RPC_LISTEN_PORT;
extern const std::string PREF_RPC_LISTEN_PORT;
// value: string
extern const std::string PREF_RPC_USER;
// value: string
extern const std::string PREF_RPC_PASSWD;
// value: 1*digit
extern const std::string PREF_RPC_MAX_REQUEST_SIZE;
// value: true | false
extern const std::string PREF_RPC_LISTEN_ALL;
// value: true | false
extern const std::string PREF_ENABLE_XML_RPC;
// value: true | false
extern const std::string PREF_DRY_RUN;
// value: true | false
extern const std::string PREF_REUSE_URI;
// value: 1*digit
extern const std::string PREF_XML_RPC_LISTEN_PORT;
// value: string
extern const std::string PREF_XML_RPC_USER;
// value: string
extern const std::string PREF_XML_RPC_PASSWD;
// value: 1*digit
extern const std::string PREF_XML_RPC_MAX_REQUEST_SIZE;
// value: true | false
extern const std::string PREF_XML_RPC_LISTEN_ALL;
// value: true | false
extern const std::string PREF_DRY_RUN;
// value: true | false
extern const std::string PREF_REUSE_URI;
// value: string
extern const std::string PREF_ON_DOWNLOAD_START;
extern const std::string PREF_ON_DOWNLOAD_PAUSE;
extern const std::string PREF_ON_DOWNLOAD_STOP;
extern const std::string PREF_ON_DOWNLOAD_COMPLETE;
extern const std::string PREF_ON_DOWNLOAD_ERROR;
// value: true | false
extern const std::string PREF_XML_RPC_LISTEN_ALL;
// value: string
extern const std::string PREF_INTERFACE;
// value: true | false

View File

@ -490,22 +490,6 @@
" server.")
#define TEXT_EVENT_POLL \
_(" --event-poll=POLL Specify the method for polling events.")
#define TEXT_XML_RPC_LISTEN_PORT \
_(" --xml-rpc-listen-port=PORT Specify a port number for XML-RPC server to listen\n" \
" to.")
#define TEXT_ENABLE_XML_RPC \
_(" --enable-xml-rpc[=true|false] Enable XML-RPC server.\n" \
" It is strongly recommended to set username and\n" \
" password using --xml-rpc-user and --xml-rpc-passwd\n" \
" option. See also --xml-rpc-listen-port option.")
#define TEXT_XML_RPC_MAX_REQUEST_SIZE \
_(" --xml-rpc-max-request-size=SIZE Set max size of XML-RPC request. If aria2\n" \
" detects the request is more than SIZE bytes, it\n" \
" drops connection.")
#define TEXT_XML_RPC_USER \
_(" --xml-rpc-user=USER Set XML-RPC user.")
#define TEXT_XML_RPC_PASSWD \
_(" --xml-rpc-passwd=PASSWD Set XML-RPC password.")
#define TEXT_BT_EXTERNAL_IP \
_(" --bt-external-ip=IPADDRESS Specify the external IP address to report to a\n" \
" BitTorrent tracker. Although this function is\n" \
@ -574,10 +558,6 @@
_(" --bt-stop-timeout=SEC Stop BitTorrent download if download speed is 0 in\n" \
" consecutive SEC seconds. If 0 is given, this\n" \
" feature is disabled.")
#define TEXT_XML_RPC_LISTEN_ALL \
_(" --xml-rpc-listen-all[=true|false] Listen incoming XML-RPC requests on all\n" \
" network interfaces. If false is given, listen only\n" \
" on local loopback interface.")
#define TEXT_BT_PRIORITIZE_PIECE \
_(" --bt-prioritize-piece=head[=SIZE],tail[=SIZE] Try to download first and last\n" \
" pieces of each file first. This is useful for\n" \
@ -685,7 +665,7 @@
" You can pass this output file to aria2c with -i\n" \
" option on restart. Please note that downloads\n" \
" added by aria2.addTorrent and aria2.addMetalink\n" \
" XML-RPC method are not saved.")
" RPC method are not saved.")
#define TEXT_MAX_CONNECTION_PER_SERVER \
_(" -x, --max-connection-per-server=NUM The maximum number of connections to one\n" \
" server for each download.")
@ -764,3 +744,36 @@
" option is useful when the system does not have\n" \
" /etc/resolv.conf and user does not have the\n" \
" permission to create it.")
#define TEXT_ENABLE_RPC \
_(" --enable-rpc[=true|false] Enable JSON-RPC/XML-RPC server.\n" \
" It is strongly recommended to set username and\n" \
" password using --rpc-user and --rpc-passwd\n" \
" option. See also --rpc-listen-port option.")
#define TEXT_RPC_MAX_REQUEST_SIZE \
_(" --rpc-max-request-size=SIZE Set max size of JSON-RPC/XML-RPC request. If aria2\n" \
" detects the request is more than SIZE bytes, it\n" \
" drops connection.")
#define TEXT_RPC_USER \
_(" --rpc-user=USER Set JSON-RPC/XML-RPC user.")
#define TEXT_RPC_PASSWD \
_(" --rpc-passwd=PASSWD Set JSON-RPC/XML-RPC password.")
#define TEXT_RPC_LISTEN_ALL \
_(" --rpc-listen-all[=true|false] Listen incoming JSON-RPC/XML-RPC requests on all\n" \
" network interfaces. If false is given, listen only\n" \
" on local loopback interface.")
#define TEXT_RPC_LISTEN_PORT \
_(" --rpc-listen-port=PORT Specify a port number for JSON-RPC/XML-RPC server\n" \
" to listen to.")
#define TEXT_ENABLE_XML_RPC \
_(" --enable-xml-rpc[=true|false] Deprecated. Use --enable-rpc instead.")
#define TEXT_XML_RPC_MAX_REQUEST_SIZE \
_(" --xml-rpc-max-request-size=SIZE Deprecated. Use --rpc-max-request-size\n" \
" instead.")
#define TEXT_XML_RPC_USER \
_(" --xml-rpc-user=USER Deprecated. Use --rpc-user instead.")
#define TEXT_XML_RPC_PASSWD \
_(" --xml-rpc-passwd=PASSWD Deprecated. Use --rpc-passwd instead.")
#define TEXT_XML_RPC_LISTEN_ALL \
_(" --xml-rpc-listen-all[=true|false] Deprecated. Use --rpc-listen-all instead.")
#define TEXT_XML_RPC_LISTEN_PORT \
_(" --xml-rpc-listen-port=PORT Deprecated. Use --rpc-listen-port instead.")