From 7d1aa887ee5f00ecdfe8a7d8f71becf81018e55e Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 2 Feb 2014 17:58:56 +0900 Subject: [PATCH] Add future deprecation warning to --rpc-user and --rpc-passwd --- doc/manual-src/en/aria2c.rst | 12 ++++++++++++ src/OptionHandlerFactory.cc | 17 +++++++++++------ src/OptionHandlerImpl.cc | 25 +++++++++++++++++++------ src/OptionHandlerImpl.h | 11 ++++++++--- src/usage_text.h | 8 ++++++-- 5 files changed, 56 insertions(+), 17 deletions(-) diff --git a/doc/manual-src/en/aria2c.rst b/doc/manual-src/en/aria2c.rst index f45d6d17..45d43391 100644 --- a/doc/manual-src/en/aria2c.rst +++ b/doc/manual-src/en/aria2c.rst @@ -988,6 +988,12 @@ RPC Options Set JSON-RPC/XML-RPC password. + .. Warning:: + + :option:`--rpc-passwd` option will be deprecated in the future + release. Migrate to :option:`--rpc-secret` option as soon as + possible. + .. option:: --rpc-private-key= Use the private key in FILE for RPC server. The private key must be @@ -1021,6 +1027,12 @@ RPC Options Set JSON-RPC/XML-RPC user. + .. Warning:: + + :option:`--rpc-user` option will be deprecated in the future + release. Migrate to :option:`--rpc-secret` option as soon as + possible. + Advanced Options ~~~~~~~~~~~~~~~~ .. option:: --allow-overwrite[=true|false] diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index e709b67b..11f32620 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -883,17 +883,22 @@ std::vector OptionHandlerFactory::createOptionHandlers() handlers.push_back(op); } { - OptionHandler* op(new DefaultOptionHandler - (PREF_RPC_USER, - TEXT_RPC_USER)); + OptionHandler* op(new DeprecatedOptionHandler + (new DefaultOptionHandler + (PREF_RPC_USER, + TEXT_RPC_USER), + nullptr, true, + "Migrate to --rpc-secret option as soon as possible.")); op->addTag(TAG_RPC); op->setEraseAfterParse(true); handlers.push_back(op); } { - OptionHandler* op(new DefaultOptionHandler - (PREF_RPC_PASSWD, - TEXT_RPC_PASSWD)); + OptionHandler* op(new DeprecatedOptionHandler + (new DefaultOptionHandler + (PREF_RPC_PASSWD, + TEXT_RPC_PASSWD), + nullptr, true)); op->addTag(TAG_RPC); op->setEraseAfterParse(true); handlers.push_back(op); diff --git a/src/OptionHandlerImpl.cc b/src/OptionHandlerImpl.cc index 69a0d677..939625c2 100644 --- a/src/OptionHandlerImpl.cc +++ b/src/OptionHandlerImpl.cc @@ -578,8 +578,13 @@ std::string PrioritizePieceOptionHandler::createPossibleValuesString() const DeprecatedOptionHandler::DeprecatedOptionHandler (OptionHandler* depOptHandler, - const OptionHandler* repOptHandler) - : depOptHandler_(depOptHandler), repOptHandler_(repOptHandler) + const OptionHandler* repOptHandler, + bool stillWork, + std::string additionalMessage) + : depOptHandler_(depOptHandler), + repOptHandler_(repOptHandler), + stillWork_(stillWork), + additionalMessage_(std::move(additionalMessage)) { depOptHandler_->addTag(TAG_DEPRECATED); } @@ -594,13 +599,21 @@ void DeprecatedOptionHandler::parse(Option& option, const std::string& arg) const { if(repOptHandler_) { - A2_LOG_WARN(fmt(_("--%s option is deprecated. Use --%s option instead."), + A2_LOG_WARN(fmt(_("--%s option is deprecated. Use --%s option instead. %s"), depOptHandler_->getName(), - repOptHandler_->getName())); + repOptHandler_->getName(), + additionalMessage_.c_str())); repOptHandler_->parse(option, arg); + } else if(stillWork_) { + A2_LOG_WARN(fmt(_("--%s option will be deprecated in the future release. " + "%s"), + depOptHandler_->getName(), + additionalMessage_.c_str())); + depOptHandler_->parse(option, arg); } else { - A2_LOG_WARN(fmt(_("--%s option is deprecated."), - depOptHandler_->getName())); + A2_LOG_WARN(fmt(_("--%s option is deprecated. %s"), + depOptHandler_->getName(), + additionalMessage_.c_str())); } } diff --git a/src/OptionHandlerImpl.h b/src/OptionHandlerImpl.h index 47559f6e..16e23e0c 100644 --- a/src/OptionHandlerImpl.h +++ b/src/OptionHandlerImpl.h @@ -265,13 +265,18 @@ class DeprecatedOptionHandler:public OptionHandler { private: OptionHandler* depOptHandler_; const OptionHandler* repOptHandler_; + bool stillWork_; + std::string additionalMessage_; public: // depOptHandler is deprecated option and repOptHandler is replacing - // new option. If there is no replacing option, omit second - // argument. + // new option. If there is no replacing option, specify nullptr. If + // there is no replacing option, but the option still alives, give + // true to stillWork. Set additional message to additionalMessage. DeprecatedOptionHandler (OptionHandler* depOptHandler, - const OptionHandler* repOptHandler = nullptr); + const OptionHandler* repOptHandler = nullptr, + bool stillWork = false, + std::string additionalMessage = ""); virtual ~DeprecatedOptionHandler(); virtual void parse(Option& option, const std::string& arg) const CXX11_OVERRIDE; diff --git a/src/usage_text.h b/src/usage_text.h index b1c7fc7c..facba928 100644 --- a/src/usage_text.h +++ b/src/usage_text.h @@ -780,9 +780,13 @@ " 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.") + _(" --rpc-user=USER Set JSON-RPC/XML-RPC user. This option will be\n" \ + " deprecated in the future release. Migrate to\n" \ + " --rpc-secret option as soon as possible.") #define TEXT_RPC_PASSWD \ - _(" --rpc-passwd=PASSWD Set JSON-RPC/XML-RPC password.") + _(" --rpc-passwd=PASSWD Set JSON-RPC/XML-RPC password. This option will\n" \ + " be deprecated in the future release. Migrate to\n" \ + " --rpc-secret option as soon as possible.") #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" \