Rewritten Option. Introduced Pref.

Now preference key is Pref instead of just string.  It has Option
ID. Now option lookup and setting takes O(1) using Pref object.
pull/2/head
Tatsuhiro Tsujikawa 2011-10-21 21:56:42 +09:00
parent 20e781c2df
commit 3832ed97c6
26 changed files with 1164 additions and 1008 deletions

View File

@ -545,7 +545,7 @@ void AbstractCommand::setWriteCheckSocketIf
namespace { namespace {
// Returns proxy option value for the given protocol. // Returns proxy option value for the given protocol.
const std::string& getProxyOptionFor const std::string& getProxyOptionFor
(const std::string& proxyPref, const SharedHandle<Option>& option) (const Pref* proxyPref, const SharedHandle<Option>& option)
{ {
if(option->defined(proxyPref)) { if(option->defined(proxyPref)) {
return option->get(proxyPref); return option->get(proxyPref);

View File

@ -212,11 +212,11 @@ void DHTSetup::setup
taskQueue->addPeriodicTask1(task); taskQueue->addPeriodicTask1(task);
} }
const std::string& prefEntryPointHost = const Pref* prefEntryPointHost =
family == AF_INET?PREF_DHT_ENTRY_POINT_HOST:PREF_DHT_ENTRY_POINT_HOST6; family == AF_INET?PREF_DHT_ENTRY_POINT_HOST:PREF_DHT_ENTRY_POINT_HOST6;
if(!e->getOption()->get(prefEntryPointHost).empty()) { if(!e->getOption()->get(prefEntryPointHost).empty()) {
{ {
const std::string& prefEntryPointPort = const Pref* prefEntryPointPort =
family == AF_INET?PREF_DHT_ENTRY_POINT_PORT: family == AF_INET?PREF_DHT_ENTRY_POINT_PORT:
PREF_DHT_ENTRY_POINT_PORT6; PREF_DHT_ENTRY_POINT_PORT6;
std::pair<std::string, uint16_t> addr std::pair<std::string, uint16_t> addr

View File

@ -39,16 +39,17 @@
#include "OptionHandlerException.h" #include "OptionHandlerException.h"
#include "a2functional.h" #include "a2functional.h"
#include "Option.h" #include "Option.h"
#include "prefs.h"
namespace aria2 { namespace aria2 {
NameMatchOptionHandler::NameMatchOptionHandler NameMatchOptionHandler::NameMatchOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
ARG_TYPE argType, ARG_TYPE argType,
char shortName) char shortName)
: optName_(optName), : pref_(pref),
description_(description), description_(description),
defaultValue_(defaultValue), defaultValue_(defaultValue),
id_(0), id_(0),
@ -62,7 +63,7 @@ NameMatchOptionHandler::~NameMatchOptionHandler() {}
bool NameMatchOptionHandler::canHandle(const std::string& optName) bool NameMatchOptionHandler::canHandle(const std::string& optName)
{ {
return optName_ == optName; return pref_->k == optName;
} }
void NameMatchOptionHandler::parse(Option& option, const std::string& arg) void NameMatchOptionHandler::parse(Option& option, const std::string& arg)
@ -70,7 +71,7 @@ void NameMatchOptionHandler::parse(Option& option, const std::string& arg)
try { try {
parseArg(option, arg); parseArg(option, arg);
} catch(Exception& e) { } catch(Exception& e) {
throw OPTION_HANDLER_EXCEPTION2(optName_, e); throw OPTION_HANDLER_EXCEPTION2(pref_, e);
} }
} }
@ -89,4 +90,9 @@ std::string NameMatchOptionHandler::toTagString() const
return strjoin(tags_.begin(), tags_.end(), ", "); return strjoin(tags_.begin(), tags_.end(), ", ");
} }
const std::string& NameMatchOptionHandler::getName() const
{
return pref_->k;
}
} // namespace aria2 } // namespace aria2

View File

@ -44,10 +44,11 @@
namespace aria2 { namespace aria2 {
class Option; class Option;
class Pref;
class NameMatchOptionHandler : public OptionHandler { class NameMatchOptionHandler : public OptionHandler {
protected: protected:
std::string optName_; const Pref* pref_;
std::string description_; std::string description_;
@ -67,7 +68,7 @@ protected:
virtual void parseArg(Option& option, const std::string& arg) = 0; virtual void parseArg(Option& option, const std::string& arg) = 0;
public: public:
NameMatchOptionHandler(const std::string& optName, NameMatchOptionHandler(const Pref* pref,
const std::string& description = NO_DESCRIPTION, const std::string& description = NO_DESCRIPTION,
const std::string& defaultValue = NO_DEFAULT_VALUE, const std::string& defaultValue = NO_DEFAULT_VALUE,
ARG_TYPE argType = REQ_ARG, ARG_TYPE argType = REQ_ARG,
@ -85,10 +86,7 @@ public:
virtual std::string toTagString() const; virtual std::string toTagString() const;
virtual const std::string& getName() const virtual const std::string& getName() const;
{
return optName_;
}
virtual const std::string& getDescription() const virtual const std::string& getDescription() const
{ {

View File

@ -33,43 +33,74 @@
*/ */
/* copyright --> */ /* copyright --> */
#include "Option.h" #include "Option.h"
#include "prefs.h"
#include "A2STR.h"
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include "prefs.h"
#include "bitfield.h"
namespace aria2 { namespace aria2 {
Option::Option() {} Option::Option()
: table_(option::countOption()),
use_((option::countOption()+7)/8)
{}
Option::~Option() {} Option::~Option() {}
void Option::put(const std::string& name, const std::string& value) { Option::Option(const Option& option)
table_[name] = value; : table_(option.table_),
} use_(option.use_)
{}
bool Option::defined(const std::string& name) const Option& Option::operator=(const Option& option)
{ {
return table_.count(name) == 1; if(this != &option) {
table_ = option.table_;
use_ = option.use_;
}
return *this;
} }
bool Option::blank(const std::string& name) const namespace {
template<typename V>
void setBit(V& b, const Pref* pref)
{ {
std::map<std::string, std::string>::const_iterator i = table_.find(name); b[pref->i/8] |= 128 >> (pref->i%8);
return i == table_.end() || (*i).second.empty();
} }
const std::string& Option::get(const std::string& name) const { template<typename V>
std::map<std::string, std::string>::const_iterator itr = table_.find(name); void unsetBit(V& b, const Pref* pref)
if(itr == table_.end()) { {
return A2STR::NIL; b[pref->i/8] &= ~(128 >> (pref->i%8));
} else {
return (*itr).second;
}
} }
int32_t Option::getAsInt(const std::string& name) const { } // namespace
const std::string& value = get(name);
void Option::put(const Pref* pref, const std::string& value) {
setBit(use_, pref);
table_[pref->i] = value;
}
bool Option::defined(const Pref* pref) const
{
return bitfield::test(use_, use_.size()*8, pref->i);
}
bool Option::blank(const Pref* pref) const
{
return !defined(pref) || table_[pref->i].empty();
}
const std::string& Option::get(const Pref* pref) const
{
return table_[pref->i];
}
int32_t Option::getAsInt(const Pref* pref) const {
const std::string& value = get(pref);
if(value.empty()) { if(value.empty()) {
return 0; return 0;
} else { } else {
@ -77,8 +108,8 @@ int32_t Option::getAsInt(const std::string& name) const {
} }
} }
int64_t Option::getAsLLInt(const std::string& name) const { int64_t Option::getAsLLInt(const Pref* pref) const {
const std::string& value = get(name); const std::string& value = get(pref);
if(value.empty()) { if(value.empty()) {
return 0; return 0;
} else { } else {
@ -86,12 +117,12 @@ int64_t Option::getAsLLInt(const std::string& name) const {
} }
} }
bool Option::getAsBool(const std::string& name) const { bool Option::getAsBool(const Pref* pref) const {
return get(name) == A2_V_TRUE; return get(pref) == A2_V_TRUE;
} }
double Option::getAsDouble(const std::string& name) const { double Option::getAsDouble(const Pref* pref) const {
const std::string& value = get(name); const std::string& value = get(pref);
if(value.empty()) { if(value.empty()) {
return 0.0; return 0.0;
} else { } else {
@ -99,37 +130,16 @@ double Option::getAsDouble(const std::string& name) const {
} }
} }
void Option::remove(const std::string& name) void Option::remove(const Pref* pref)
{ {
std::map<std::string, std::string>::iterator i = table_.find(name); unsetBit(use_, pref);
if(i != table_.end()) { table_[pref->i].clear();
table_.erase(i);
}
} }
void Option::clear() void Option::clear()
{ {
table_.clear(); std::fill(use_.begin(), use_.end(), 0);
} std::fill(table_.begin(), table_.end(), "");
std::map<std::string, std::string>::const_iterator Option::begin() const
{
return table_.begin();
}
std::map<std::string, std::string>::const_iterator Option::end() const
{
return table_.end();
}
std::map<std::string, std::string>::iterator Option::begin()
{
return table_.begin();
}
std::map<std::string, std::string>::iterator Option::end()
{
return table_.end();
} }
} // namespace aria2 } // namespace aria2

View File

@ -36,42 +36,45 @@
#define D_OPTION_H #define D_OPTION_H
#include "common.h" #include "common.h"
#include <string> #include <string>
#include <map> #include <vector>
namespace aria2 { namespace aria2 {
class Pref;
class Option { class Option {
private: private:
std::map<std::string, std::string> table_; std::vector<std::string> table_;
std::vector<unsigned char> use_;
public: public:
Option(); Option();
~Option(); ~Option();
Option(const Option& option);
Option& operator=(const Option& option);
void put(const std::string& name, const std::string& value); void put(const Pref* pref, const std::string& value);
// Returns true if name is defined. Otherwise returns false. // Returns true if name is defined. Otherwise returns false.
// Note that even if the value is a empty string, this method returns true. // Note that even if the value is a empty string, this method returns true.
bool defined(const std::string& name) const; bool defined(const Pref* pref) const;
// Returns true if name is not defined or the value is a empty string. // Returns true if name is not defined or the value is a empty string.
// Otherwise returns false. // Otherwise returns false.
bool blank(const std::string& name) const; bool blank(const Pref* pref) const;
const std::string& get(const std::string& name) const; const std::string& get(const Pref* pref) const;
int32_t getAsInt(const std::string& name) const; int32_t getAsInt(const Pref* pref) const;
int64_t getAsLLInt(const std::string& name) const; int64_t getAsLLInt(const Pref* pref) const;
bool getAsBool(const std::string& name) const; bool getAsBool(const Pref* pref) const;
double getAsDouble(const std::string& name) const; double getAsDouble(const Pref* pref) const;
void remove(const std::string& name); void remove(const Pref* pref);
void clear(); void clear();
std::map<std::string, std::string>::const_iterator begin() const; const std::vector<std::string>& getTable()
{
std::map<std::string, std::string>::const_iterator end() const; return table_;
}
std::map<std::string, std::string>::iterator begin();
std::map<std::string, std::string>::iterator end();
}; };
} // namespace aria2 } // namespace aria2

View File

@ -34,31 +34,38 @@
/* copyright --> */ /* copyright --> */
#include "OptionHandlerException.h" #include "OptionHandlerException.h"
#include "fmt.h" #include "fmt.h"
#include "prefs.h"
namespace aria2 { namespace aria2 {
const std::string OptionHandlerException::MESSAGE const std::string OptionHandlerException::MESSAGE
("We encountered a problem while processing the option '--%s'."); ("We encountered a problem while processing the option '--%s'.");
OptionHandlerException::OptionHandlerException(const char* file, int line, OptionHandlerException::OptionHandlerException
const std::string& optName): (const char* file, int line,
RecoverableException const Pref* pref)
(file, line, fmt(MESSAGE.c_str(), optName.c_str()), error_code::OPTION_ERROR), : RecoverableException
optName_(optName) {} (file, line, fmt(MESSAGE.c_str(), pref->k.c_str()),
error_code::OPTION_ERROR),
pref_(pref)
{}
OptionHandlerException::OptionHandlerException(const char* file, int line, OptionHandlerException::OptionHandlerException
const std::string& optName, (const char* file, int line,
const Exception& cause): const Pref* pref,
RecoverableException const Exception& cause)
(file, line, fmt(MESSAGE.c_str(), optName.c_str()), error_code::OPTION_ERROR, : RecoverableException
(file, line, fmt(MESSAGE.c_str(), pref->k.c_str()),
error_code::OPTION_ERROR,
cause), cause),
optName_(optName) {} pref_(pref)
{}
OptionHandlerException::~OptionHandlerException() throw() {} OptionHandlerException::~OptionHandlerException() throw() {}
const std::string& OptionHandlerException::getOptionName() const throw() const std::string& OptionHandlerException::getOptionName() const throw()
{ {
return optName_; return pref_->k;
} }
SharedHandle<Exception> OptionHandlerException::copy() const SharedHandle<Exception> OptionHandlerException::copy() const

View File

@ -38,18 +38,21 @@
namespace aria2 { namespace aria2 {
class Pref;
class OptionHandlerException:public RecoverableException { class OptionHandlerException:public RecoverableException {
private: private:
std::string optName_; const Pref* pref_;
static const std::string MESSAGE; static const std::string MESSAGE;
protected: protected:
virtual SharedHandle<Exception> copy() const; virtual SharedHandle<Exception> copy() const;
public: public:
OptionHandlerException(const char* file, int line, OptionHandlerException(const char* file, int line,
const std::string& optName); const Pref* pref);
OptionHandlerException(const char* file, int line, const std::string& optName, OptionHandlerException(const char* file, int line,
const Pref* pref,
const Exception& cause); const Exception& cause);
virtual ~OptionHandlerException() throw(); virtual ~OptionHandlerException() throw();

View File

@ -1781,7 +1781,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
// Version Option // Version Option
{ {
SharedHandle<OptionHandler> op(new DefaultOptionHandler SharedHandle<OptionHandler> op(new DefaultOptionHandler
("version", (PREF_VERSION,
TEXT_VERSION, TEXT_VERSION,
NO_DEFAULT_VALUE, NO_DEFAULT_VALUE,
A2STR::NIL, A2STR::NIL,
@ -1812,7 +1812,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
}; };
static std::string tagsStr = strjoin(vbegin(tags), vend(tags), ", "); static std::string tagsStr = strjoin(vbegin(tags), vend(tags), ", ");
SharedHandle<OptionHandler> op(new DefaultOptionHandler SharedHandle<OptionHandler> op(new DefaultOptionHandler
("help", (PREF_HELP,
TEXT_HELP, TEXT_HELP,
TAG_BASIC, TAG_BASIC,
tagsStr, tagsStr,

View File

@ -127,12 +127,12 @@ bool NullOptionHandler::getEraseAfterParse() const
void NullOptionHandler::setEraseAfterParse(bool eraseAfterParse) {} void NullOptionHandler::setEraseAfterParse(bool eraseAfterParse) {}
BooleanOptionHandler::BooleanOptionHandler BooleanOptionHandler::BooleanOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
OptionHandler::ARG_TYPE argType, OptionHandler::ARG_TYPE argType,
char shortName) char shortName)
: NameMatchOptionHandler(optName, description, defaultValue, : NameMatchOptionHandler(pref, description, defaultValue,
argType, shortName) argType, shortName)
{} {}
@ -144,11 +144,11 @@ void BooleanOptionHandler::parseArg(Option& option, const std::string& optarg)
((argType_ == OptionHandler::OPT_ARG || ((argType_ == OptionHandler::OPT_ARG ||
argType_ == OptionHandler::NO_ARG) argType_ == OptionHandler::NO_ARG)
&& optarg.empty())) { && optarg.empty())) {
option.put(optName_, A2_V_TRUE); option.put(pref_, A2_V_TRUE);
} else if(optarg == "false") { } else if(optarg == "false") {
option.put(optName_, A2_V_FALSE); option.put(pref_, A2_V_FALSE);
} else { } else {
std::string msg = optName_; std::string msg = pref_->k;
strappend(msg, " ", _("must be either 'true' or 'false'.")); strappend(msg, " ", _("must be either 'true' or 'false'."));
throw DL_ABORT_EX(msg); throw DL_ABORT_EX(msg);
} }
@ -160,12 +160,12 @@ std::string BooleanOptionHandler::createPossibleValuesString() const
} }
IntegerRangeOptionHandler::IntegerRangeOptionHandler IntegerRangeOptionHandler::IntegerRangeOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
int32_t min, int32_t max, int32_t min, int32_t max,
char shortName) char shortName)
: NameMatchOptionHandler(optName, description, defaultValue, : NameMatchOptionHandler(pref, description, defaultValue,
OptionHandler::REQ_ARG, shortName), OptionHandler::REQ_ARG, shortName),
min_(min), min_(min),
max_(max) max_(max)
@ -180,13 +180,13 @@ void IntegerRangeOptionHandler::parseArg
while(seq.hasNext()) { while(seq.hasNext()) {
int32_t v = seq.next(); int32_t v = seq.next();
if(v < min_ || max_ < v) { if(v < min_ || max_ < v) {
std::string msg = optName_; std::string msg = pref_->k;
strappend(msg, " ", _("must be between %s and %s.")); strappend(msg, " ", _("must be between %s and %s."));
throw DL_ABORT_EX throw DL_ABORT_EX
(fmt(msg.c_str(), util::itos(min_).c_str(), (fmt(msg.c_str(), util::itos(min_).c_str(),
util::itos(max_).c_str())); util::itos(max_).c_str()));
} }
option.put(optName_, optarg); option.put(pref_, optarg);
} }
} }
@ -196,13 +196,13 @@ std::string IntegerRangeOptionHandler::createPossibleValuesString() const
} }
NumberOptionHandler::NumberOptionHandler NumberOptionHandler::NumberOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
int64_t min, int64_t min,
int64_t max, int64_t max,
char shortName) char shortName)
: NameMatchOptionHandler(optName, description, defaultValue, : NameMatchOptionHandler(pref, description, defaultValue,
OptionHandler::REQ_ARG, shortName), OptionHandler::REQ_ARG, shortName),
min_(min), min_(min),
max_(max) max_(max)
@ -219,9 +219,9 @@ void NumberOptionHandler::parseArg(Option& option, const std::string& optarg)
void NumberOptionHandler::parseArg(Option& option, int64_t number) void NumberOptionHandler::parseArg(Option& option, int64_t number)
{ {
if((min_ == -1 || min_ <= number) && (max_ == -1 || number <= max_)) { if((min_ == -1 || min_ <= number) && (max_ == -1 || number <= max_)) {
option.put(optName_, util::itos(number)); option.put(pref_, util::itos(number));
} else { } else {
std::string msg = optName_; std::string msg = pref_->k;
msg += " "; msg += " ";
if(min_ == -1 && max_ != -1) { if(min_ == -1 && max_ != -1) {
msg += fmt(_("must be smaller than or equal to %s."), msg += fmt(_("must be smaller than or equal to %s."),
@ -258,13 +258,13 @@ std::string NumberOptionHandler::createPossibleValuesString() const
} }
UnitNumberOptionHandler::UnitNumberOptionHandler UnitNumberOptionHandler::UnitNumberOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
int64_t min, int64_t min,
int64_t max, int64_t max,
char shortName) char shortName)
: NumberOptionHandler(optName, description, defaultValue, min, max, : NumberOptionHandler(pref, description, defaultValue, min, max,
shortName) shortName)
{} {}
@ -278,13 +278,13 @@ void UnitNumberOptionHandler::parseArg
} }
FloatNumberOptionHandler::FloatNumberOptionHandler FloatNumberOptionHandler::FloatNumberOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
double min, double min,
double max, double max,
char shortName) char shortName)
: NameMatchOptionHandler(optName, description, defaultValue, : NameMatchOptionHandler(pref, description, defaultValue,
OptionHandler::REQ_ARG, shortName), OptionHandler::REQ_ARG, shortName),
min_(min), min_(min),
max_(max) max_(max)
@ -297,9 +297,9 @@ void FloatNumberOptionHandler::parseArg
{ {
double number = strtod(optarg.c_str(), 0); double number = strtod(optarg.c_str(), 0);
if((min_ < 0 || min_ <= number) && (max_ < 0 || number <= max_)) { if((min_ < 0 || min_ <= number) && (max_ < 0 || number <= max_)) {
option.put(optName_, optarg); option.put(pref_, optarg);
} else { } else {
std::string msg = optName_; std::string msg = pref_->k;
msg += " "; msg += " ";
if(min_ < 0 && max_ >= 0) { if(min_ < 0 && max_ >= 0) {
msg += fmt(_("must be smaller than or equal to %.1f."), max_); msg += fmt(_("must be smaller than or equal to %.1f."), max_);
@ -336,13 +336,13 @@ std::string FloatNumberOptionHandler::createPossibleValuesString() const
} }
DefaultOptionHandler::DefaultOptionHandler DefaultOptionHandler::DefaultOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
const std::string& possibleValuesString, const std::string& possibleValuesString,
OptionHandler::ARG_TYPE argType, OptionHandler::ARG_TYPE argType,
char shortName) char shortName)
: NameMatchOptionHandler(optName, description, defaultValue, argType, : NameMatchOptionHandler(pref, description, defaultValue, argType,
shortName), shortName),
possibleValuesString_(possibleValuesString) possibleValuesString_(possibleValuesString)
{} {}
@ -351,7 +351,7 @@ DefaultOptionHandler::~DefaultOptionHandler() {}
void DefaultOptionHandler::parseArg(Option& option, const std::string& optarg) void DefaultOptionHandler::parseArg(Option& option, const std::string& optarg)
{ {
option.put(optName_, optarg); option.put(pref_, optarg);
} }
std::string DefaultOptionHandler::createPossibleValuesString() const std::string DefaultOptionHandler::createPossibleValuesString() const
@ -360,14 +360,14 @@ std::string DefaultOptionHandler::createPossibleValuesString() const
} }
CumulativeOptionHandler::CumulativeOptionHandler CumulativeOptionHandler::CumulativeOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
const std::string& delim, const std::string& delim,
const std::string& possibleValuesString, const std::string& possibleValuesString,
OptionHandler::ARG_TYPE argType, OptionHandler::ARG_TYPE argType,
char shortName) char shortName)
: NameMatchOptionHandler(optName, description, defaultValue, argType, : NameMatchOptionHandler(pref, description, defaultValue, argType,
shortName), shortName),
delim_(delim), delim_(delim),
possibleValuesString_(possibleValuesString) possibleValuesString_(possibleValuesString)
@ -378,9 +378,9 @@ CumulativeOptionHandler::~CumulativeOptionHandler() {}
void CumulativeOptionHandler::parseArg void CumulativeOptionHandler::parseArg
(Option& option, const std::string& optarg) (Option& option, const std::string& optarg)
{ {
std::string value = option.get(optName_); std::string value = option.get(pref_);
strappend(value, optarg, delim_); strappend(value, optarg, delim_);
option.put(optName_, value); option.put(pref_, value);
} }
std::string CumulativeOptionHandler::createPossibleValuesString() const std::string CumulativeOptionHandler::createPossibleValuesString() const
@ -389,10 +389,10 @@ std::string CumulativeOptionHandler::createPossibleValuesString() const
} }
IndexOutOptionHandler::IndexOutOptionHandler IndexOutOptionHandler::IndexOutOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description, const std::string& description,
char shortName) char shortName)
: NameMatchOptionHandler(optName, description, NO_DEFAULT_VALUE, : NameMatchOptionHandler(pref, description, NO_DEFAULT_VALUE,
OptionHandler::REQ_ARG, shortName) OptionHandler::REQ_ARG, shortName)
{} {}
@ -402,9 +402,9 @@ void IndexOutOptionHandler::parseArg(Option& option, const std::string& optarg)
{ {
// See optarg is in the fomrat of "INDEX=PATH" // See optarg is in the fomrat of "INDEX=PATH"
util::parseIndexPath(optarg); util::parseIndexPath(optarg);
std::string value = option.get(optName_); std::string value = option.get(pref_);
strappend(value, optarg, "\n"); strappend(value, optarg, "\n");
option.put(optName_, value); option.put(pref_, value);
} }
std::string IndexOutOptionHandler::createPossibleValuesString() const std::string IndexOutOptionHandler::createPossibleValuesString() const
@ -413,10 +413,10 @@ std::string IndexOutOptionHandler::createPossibleValuesString() const
} }
ChecksumOptionHandler::ChecksumOptionHandler ChecksumOptionHandler::ChecksumOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description, const std::string& description,
char shortName) char shortName)
: NameMatchOptionHandler(optName, description, NO_DEFAULT_VALUE, : NameMatchOptionHandler(pref, description, NO_DEFAULT_VALUE,
OptionHandler::REQ_ARG, shortName) OptionHandler::REQ_ARG, shortName)
{} {}
@ -431,7 +431,7 @@ void ChecksumOptionHandler::parseArg(Option& option, const std::string& optarg)
if(!MessageDigest::isValidHash(p.first, p.second)) { if(!MessageDigest::isValidHash(p.first, p.second)) {
throw DL_ABORT_EX(_("Unrecognized checksum")); throw DL_ABORT_EX(_("Unrecognized checksum"));
} }
option.put(optName_, optarg); option.put(pref_, optarg);
} }
std::string ChecksumOptionHandler::createPossibleValuesString() const std::string ChecksumOptionHandler::createPossibleValuesString() const
@ -440,36 +440,36 @@ std::string ChecksumOptionHandler::createPossibleValuesString() const
} }
ParameterOptionHandler::ParameterOptionHandler ParameterOptionHandler::ParameterOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
const std::vector<std::string>& validParamValues, const std::vector<std::string>& validParamValues,
char shortName) char shortName)
: NameMatchOptionHandler(optName, description, defaultValue, : NameMatchOptionHandler(pref, description, defaultValue,
OptionHandler::REQ_ARG, shortName), OptionHandler::REQ_ARG, shortName),
validParamValues_(validParamValues) validParamValues_(validParamValues)
{} {}
ParameterOptionHandler::ParameterOptionHandler ParameterOptionHandler::ParameterOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
const std::string& validParamValue, const std::string& validParamValue,
char shortName) char shortName)
: NameMatchOptionHandler(optName, description, defaultValue, : NameMatchOptionHandler(pref, description, defaultValue,
OptionHandler::REQ_ARG, shortName) OptionHandler::REQ_ARG, shortName)
{ {
validParamValues_.push_back(validParamValue); validParamValues_.push_back(validParamValue);
} }
ParameterOptionHandler::ParameterOptionHandler ParameterOptionHandler::ParameterOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
const std::string& validParamValue1, const std::string& validParamValue1,
const std::string& validParamValue2, const std::string& validParamValue2,
char shortName) char shortName)
: NameMatchOptionHandler(optName, description, defaultValue, : NameMatchOptionHandler(pref, description, defaultValue,
OptionHandler::REQ_ARG, shortName) OptionHandler::REQ_ARG, shortName)
{ {
validParamValues_.push_back(validParamValue1); validParamValues_.push_back(validParamValue1);
@ -477,14 +477,14 @@ ParameterOptionHandler::ParameterOptionHandler
} }
ParameterOptionHandler::ParameterOptionHandler ParameterOptionHandler::ParameterOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
const std::string& validParamValue1, const std::string& validParamValue1,
const std::string& validParamValue2, const std::string& validParamValue2,
const std::string& validParamValue3, const std::string& validParamValue3,
char shortName) char shortName)
: NameMatchOptionHandler(optName, description, defaultValue, : NameMatchOptionHandler(pref, description, defaultValue,
OptionHandler::REQ_ARG, shortName) OptionHandler::REQ_ARG, shortName)
{ {
validParamValues_.push_back(validParamValue1); validParamValues_.push_back(validParamValue1);
@ -499,7 +499,7 @@ void ParameterOptionHandler::parseArg(Option& option, const std::string& optarg)
std::vector<std::string>::const_iterator itr = std::vector<std::string>::const_iterator itr =
std::find(validParamValues_.begin(), validParamValues_.end(), optarg); std::find(validParamValues_.begin(), validParamValues_.end(), optarg);
if(itr == validParamValues_.end()) { if(itr == validParamValues_.end()) {
std::string msg = optName_; std::string msg = pref_->k;
strappend(msg, " ", _("must be one of the following:")); strappend(msg, " ", _("must be one of the following:"));
if(validParamValues_.size() == 0) { if(validParamValues_.size() == 0) {
msg += "''"; msg += "''";
@ -512,7 +512,7 @@ void ParameterOptionHandler::parseArg(Option& option, const std::string& optarg)
} }
throw DL_ABORT_EX(msg); throw DL_ABORT_EX(msg);
} else { } else {
option.put(optName_, optarg); option.put(pref_, optarg);
} }
} }
@ -525,13 +525,13 @@ std::string ParameterOptionHandler::createPossibleValuesString() const
} }
HostPortOptionHandler::HostPortOptionHandler HostPortOptionHandler::HostPortOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
const std::string& hostOptionName, const Pref* hostOptionName,
const std::string& portOptionName, const Pref* portOptionName,
char shortName) char shortName)
: NameMatchOptionHandler(optName, description, defaultValue, : NameMatchOptionHandler(pref, description, defaultValue,
OptionHandler::REQ_ARG, shortName), OptionHandler::REQ_ARG, shortName),
hostOptionName_(hostOptionName), hostOptionName_(hostOptionName),
portOptionName_(portOptionName) portOptionName_(portOptionName)
@ -547,7 +547,7 @@ void HostPortOptionHandler::parseArg(Option& option, const std::string& optarg)
if(!req.setUri(uri)) { if(!req.setUri(uri)) {
throw DL_ABORT_EX(_("Unrecognized format")); throw DL_ABORT_EX(_("Unrecognized format"));
} }
option.put(optName_, optarg); option.put(pref_, optarg);
setHostAndPort(option, req.getHost(), req.getPort()); setHostAndPort(option, req.getHost(), req.getPort());
} }
@ -564,19 +564,19 @@ std::string HostPortOptionHandler::createPossibleValuesString() const
} }
HttpProxyUserOptionHandler::HttpProxyUserOptionHandler HttpProxyUserOptionHandler::HttpProxyUserOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
char shortName) char shortName)
: NameMatchOptionHandler(optName, description, defaultValue, : NameMatchOptionHandler(pref, description, defaultValue,
OptionHandler::REQ_ARG, shortName) OptionHandler::REQ_ARG, shortName)
{} {}
void HttpProxyUserOptionHandler::parseArg void HttpProxyUserOptionHandler::parseArg
(Option& option, const std::string& optarg) (Option& option, const std::string& optarg)
{ {
if(util::endsWith(optName_, "-user")) { if(util::endsWith(pref_->k, "-user")) {
const std::string proxyPref = optName_.substr(0, optName_.size()-5); const Pref* proxyPref = option::k2p(pref_->k.substr(0, pref_->k.size()-5));
const std::string& olduri = option.get(proxyPref); const std::string& olduri = option.get(proxyPref);
if(!olduri.empty()) { if(!olduri.empty()) {
Request req; Request req;
@ -597,7 +597,7 @@ void HttpProxyUserOptionHandler::parseArg
option.put(proxyPref, uri); option.put(proxyPref, uri);
} }
} }
option.put(optName_, optarg); option.put(pref_, optarg);
} }
std::string HttpProxyUserOptionHandler::createPossibleValuesString() const std::string HttpProxyUserOptionHandler::createPossibleValuesString() const
@ -606,19 +606,19 @@ std::string HttpProxyUserOptionHandler::createPossibleValuesString() const
} }
HttpProxyPasswdOptionHandler::HttpProxyPasswdOptionHandler HttpProxyPasswdOptionHandler::HttpProxyPasswdOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
char shortName) char shortName)
: NameMatchOptionHandler(optName, description, defaultValue, : NameMatchOptionHandler(pref, description, defaultValue,
OptionHandler::REQ_ARG, shortName) OptionHandler::REQ_ARG, shortName)
{} {}
void HttpProxyPasswdOptionHandler::parseArg void HttpProxyPasswdOptionHandler::parseArg
(Option& option, const std::string& optarg) (Option& option, const std::string& optarg)
{ {
if(util::endsWith(optName_, "-passwd")) { if(util::endsWith(pref_->k, "-passwd")) {
const std::string proxyPref = optName_.substr(0, optName_.size()-7); const Pref* proxyPref = option::k2p(pref_->k.substr(0, pref_->k.size()-7));
const std::string& olduri = option.get(proxyPref); const std::string& olduri = option.get(proxyPref);
if(!olduri.empty()) { if(!olduri.empty()) {
Request req; Request req;
@ -639,7 +639,7 @@ void HttpProxyPasswdOptionHandler::parseArg
option.put(proxyPref, uri); option.put(proxyPref, uri);
} }
} }
option.put(optName_, optarg); option.put(pref_, optarg);
} }
std::string HttpProxyPasswdOptionHandler::createPossibleValuesString() const std::string HttpProxyPasswdOptionHandler::createPossibleValuesString() const
@ -648,14 +648,14 @@ std::string HttpProxyPasswdOptionHandler::createPossibleValuesString() const
} }
HttpProxyOptionHandler::HttpProxyOptionHandler HttpProxyOptionHandler::HttpProxyOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
char shortName) char shortName)
: NameMatchOptionHandler(optName, description, defaultValue, : NameMatchOptionHandler(pref, description, defaultValue,
OptionHandler::REQ_ARG, shortName), OptionHandler::REQ_ARG, shortName),
proxyUserPref_(optName_+"-user"), proxyUserPref_(option::k2p(pref->k+"-user")),
proxyPasswdPref_(optName_+"-passwd") proxyPasswdPref_(option::k2p(pref->k+"-passwd"))
{} {}
HttpProxyOptionHandler::~HttpProxyOptionHandler() {} HttpProxyOptionHandler::~HttpProxyOptionHandler() {}
@ -663,7 +663,7 @@ HttpProxyOptionHandler::~HttpProxyOptionHandler() {}
void HttpProxyOptionHandler::parseArg(Option& option, const std::string& optarg) void HttpProxyOptionHandler::parseArg(Option& option, const std::string& optarg)
{ {
if(optarg.empty()) { if(optarg.empty()) {
option.put(optName_, optarg); option.put(pref_, optarg);
} else { } else {
Request req; Request req;
std::string uri; std::string uri;
@ -691,7 +691,7 @@ void HttpProxyOptionHandler::parseArg(Option& option, const std::string& optarg)
us.hasPassword = true; us.hasPassword = true;
} }
} }
option.put(optName_, uri::construct(us)); option.put(pref_, uri::construct(us));
} }
} }
@ -701,12 +701,12 @@ std::string HttpProxyOptionHandler::createPossibleValuesString() const
} }
LocalFilePathOptionHandler::LocalFilePathOptionHandler LocalFilePathOptionHandler::LocalFilePathOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
bool acceptStdin, bool acceptStdin,
char shortName) char shortName)
: NameMatchOptionHandler(optName, description, defaultValue, : NameMatchOptionHandler(pref, description, defaultValue,
OptionHandler::REQ_ARG, shortName), OptionHandler::REQ_ARG, shortName),
acceptStdin_(acceptStdin) acceptStdin_(acceptStdin)
{} {}
@ -715,13 +715,13 @@ void LocalFilePathOptionHandler::parseArg
(Option& option, const std::string& optarg) (Option& option, const std::string& optarg)
{ {
if(acceptStdin_ && optarg == "-") { if(acceptStdin_ && optarg == "-") {
option.put(optName_, DEV_STDIN); option.put(pref_, DEV_STDIN);
} else { } else {
File f(optarg); File f(optarg);
if(!f.exists() || f.isDir()) { if(!f.exists() || f.isDir()) {
throw DL_ABORT_EX(fmt(MSG_NOT_FILE, optarg.c_str())); throw DL_ABORT_EX(fmt(MSG_NOT_FILE, optarg.c_str()));
} }
option.put(optName_, optarg); option.put(pref_, optarg);
} }
} }
@ -735,11 +735,11 @@ std::string LocalFilePathOptionHandler::createPossibleValuesString() const
} }
PrioritizePieceOptionHandler::PrioritizePieceOptionHandler PrioritizePieceOptionHandler::PrioritizePieceOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
char shortName) char shortName)
: NameMatchOptionHandler(optName, description, defaultValue, : NameMatchOptionHandler(pref, description, defaultValue,
OptionHandler::REQ_ARG, shortName) OptionHandler::REQ_ARG, shortName)
{} {}
@ -751,7 +751,7 @@ void PrioritizePieceOptionHandler::parseArg
std::vector<size_t> result; std::vector<size_t> result;
util::parsePrioritizePieceRange util::parsePrioritizePieceRange
(result, optarg, std::vector<SharedHandle<FileEntry> >(), 1024); (result, optarg, std::vector<SharedHandle<FileEntry> >(), 1024);
option.put(optName_, optarg); option.put(pref_, optarg);
} }
std::string PrioritizePieceOptionHandler::createPossibleValuesString() const std::string PrioritizePieceOptionHandler::createPossibleValuesString() const

View File

@ -44,6 +44,7 @@
namespace aria2 { namespace aria2 {
class Option; class Option;
class Pref;
class NullOptionHandler : public OptionHandler { class NullOptionHandler : public OptionHandler {
private: private:
@ -71,7 +72,7 @@ public:
class BooleanOptionHandler : public NameMatchOptionHandler { class BooleanOptionHandler : public NameMatchOptionHandler {
public: public:
BooleanOptionHandler(const std::string& optName, BooleanOptionHandler(const Pref* pref,
const std::string& description = NO_DESCRIPTION, const std::string& description = NO_DESCRIPTION,
const std::string& defaultValue = NO_DEFAULT_VALUE, const std::string& defaultValue = NO_DEFAULT_VALUE,
OptionHandler::ARG_TYPE argType = OptionHandler::REQ_ARG, OptionHandler::ARG_TYPE argType = OptionHandler::REQ_ARG,
@ -86,7 +87,7 @@ private:
int32_t min_; int32_t min_;
int32_t max_; int32_t max_;
public: public:
IntegerRangeOptionHandler(const std::string& optName, IntegerRangeOptionHandler(const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
int32_t min, int32_t max, int32_t min, int32_t max,
@ -101,7 +102,7 @@ private:
int64_t min_; int64_t min_;
int64_t max_; int64_t max_;
public: public:
NumberOptionHandler(const std::string& optName, NumberOptionHandler(const Pref* pref,
const std::string& description = NO_DESCRIPTION, const std::string& description = NO_DESCRIPTION,
const std::string& defaultValue = NO_DEFAULT_VALUE, const std::string& defaultValue = NO_DEFAULT_VALUE,
int64_t min = -1, int64_t min = -1,
@ -116,7 +117,7 @@ public:
class UnitNumberOptionHandler : public NumberOptionHandler { class UnitNumberOptionHandler : public NumberOptionHandler {
public: public:
UnitNumberOptionHandler(const std::string& optName, UnitNumberOptionHandler(const Pref* pref,
const std::string& description = NO_DESCRIPTION, const std::string& description = NO_DESCRIPTION,
const std::string& defaultValue = NO_DEFAULT_VALUE, const std::string& defaultValue = NO_DEFAULT_VALUE,
int64_t min = -1, int64_t min = -1,
@ -131,7 +132,7 @@ private:
double min_; double min_;
double max_; double max_;
public: public:
FloatNumberOptionHandler(const std::string& optName, FloatNumberOptionHandler(const Pref* pref,
const std::string& description = NO_DESCRIPTION, const std::string& description = NO_DESCRIPTION,
const std::string& defaultValue = NO_DEFAULT_VALUE, const std::string& defaultValue = NO_DEFAULT_VALUE,
double min = -1, double max = -1, double min = -1, double max = -1,
@ -145,7 +146,7 @@ class DefaultOptionHandler : public NameMatchOptionHandler {
private: private:
std::string possibleValuesString_; std::string possibleValuesString_;
public: public:
DefaultOptionHandler(const std::string& optName, DefaultOptionHandler(const Pref* pref,
const std::string& description = NO_DESCRIPTION, const std::string& description = NO_DESCRIPTION,
const std::string& defaultValue = NO_DEFAULT_VALUE, const std::string& defaultValue = NO_DEFAULT_VALUE,
const std::string& possibleValuesString = A2STR::NIL, const std::string& possibleValuesString = A2STR::NIL,
@ -161,7 +162,7 @@ private:
std::string delim_; std::string delim_;
std::string possibleValuesString_; std::string possibleValuesString_;
public: public:
CumulativeOptionHandler(const std::string& optName, CumulativeOptionHandler(const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
const std::string& delim, const std::string& delim,
@ -175,9 +176,8 @@ public:
}; };
class IndexOutOptionHandler : public NameMatchOptionHandler { class IndexOutOptionHandler : public NameMatchOptionHandler {
private:
public: public:
IndexOutOptionHandler(const std::string& optName, IndexOutOptionHandler(const Pref* pref,
const std::string& description, const std::string& description,
char shortName = 0); char shortName = 0);
virtual ~IndexOutOptionHandler(); virtual ~IndexOutOptionHandler();
@ -186,9 +186,8 @@ public:
}; };
class ChecksumOptionHandler : public NameMatchOptionHandler { class ChecksumOptionHandler : public NameMatchOptionHandler {
private:
public: public:
ChecksumOptionHandler(const std::string& optName, ChecksumOptionHandler(const Pref* pref,
const std::string& description, const std::string& description,
char shortName = 0); char shortName = 0);
virtual ~ChecksumOptionHandler(); virtual ~ChecksumOptionHandler();
@ -200,23 +199,23 @@ class ParameterOptionHandler : public NameMatchOptionHandler {
private: private:
std::vector<std::string> validParamValues_; std::vector<std::string> validParamValues_;
public: public:
ParameterOptionHandler(const std::string& optName, ParameterOptionHandler(const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
const std::vector<std::string>& validParamValues, const std::vector<std::string>& validParamValues,
char shortName = 0); char shortName = 0);
ParameterOptionHandler(const std::string& optName, ParameterOptionHandler(const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
const std::string& validParamValue, const std::string& validParamValue,
char shortName = 0); char shortName = 0);
ParameterOptionHandler(const std::string& optName, ParameterOptionHandler(const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
const std::string& validParamValue1, const std::string& validParamValue1,
const std::string& validParamValue2, const std::string& validParamValue2,
char shortName = 0); char shortName = 0);
ParameterOptionHandler(const std::string& optName, ParameterOptionHandler(const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
const std::string& validParamValue1, const std::string& validParamValue1,
@ -230,14 +229,14 @@ public:
class HostPortOptionHandler : public NameMatchOptionHandler { class HostPortOptionHandler : public NameMatchOptionHandler {
private: private:
std::string hostOptionName_; const Pref* hostOptionName_;
std::string portOptionName_; const Pref* portOptionName_;
public: public:
HostPortOptionHandler(const std::string& optName, HostPortOptionHandler(const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
const std::string& hostOptionName, const Pref* hostOptionName,
const std::string& portOptionName, const Pref* portOptionName,
char shortName = 0); char shortName = 0);
virtual ~HostPortOptionHandler(); virtual ~HostPortOptionHandler();
virtual void parseArg(Option& option, const std::string& optarg); virtual void parseArg(Option& option, const std::string& optarg);
@ -248,7 +247,7 @@ public:
class HttpProxyUserOptionHandler:public NameMatchOptionHandler { class HttpProxyUserOptionHandler:public NameMatchOptionHandler {
public: public:
HttpProxyUserOptionHandler(const std::string& optName, HttpProxyUserOptionHandler(const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
char shortName = 0); char shortName = 0);
@ -258,7 +257,7 @@ public:
class HttpProxyPasswdOptionHandler:public NameMatchOptionHandler { class HttpProxyPasswdOptionHandler:public NameMatchOptionHandler {
public: public:
HttpProxyPasswdOptionHandler(const std::string& optName, HttpProxyPasswdOptionHandler(const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
char shortName = 0); char shortName = 0);
@ -268,10 +267,10 @@ public:
class HttpProxyOptionHandler : public NameMatchOptionHandler { class HttpProxyOptionHandler : public NameMatchOptionHandler {
private: private:
std::string proxyUserPref_; const Pref* proxyUserPref_;
std::string proxyPasswdPref_; const Pref* proxyPasswdPref_;
public: public:
HttpProxyOptionHandler(const std::string& optName, HttpProxyOptionHandler(const Pref* pref,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue,
char shortName = 0); char shortName = 0);
@ -285,7 +284,7 @@ private:
bool acceptStdin_; bool acceptStdin_;
public: public:
LocalFilePathOptionHandler LocalFilePathOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description = NO_DESCRIPTION, const std::string& description = NO_DESCRIPTION,
const std::string& defaultValue = NO_DEFAULT_VALUE, const std::string& defaultValue = NO_DEFAULT_VALUE,
bool acceptStdin = false, bool acceptStdin = false,
@ -297,7 +296,7 @@ public:
class PrioritizePieceOptionHandler:public NameMatchOptionHandler { class PrioritizePieceOptionHandler:public NameMatchOptionHandler {
public: public:
PrioritizePieceOptionHandler PrioritizePieceOptionHandler
(const std::string& optName, (const Pref* pref,
const std::string& description = NO_DESCRIPTION, const std::string& description = NO_DESCRIPTION,
const std::string& defaultValue = NO_DEFAULT_VALUE, const std::string& defaultValue = NO_DEFAULT_VALUE,
char shortName = 0); char shortName = 0);

View File

@ -50,6 +50,7 @@
#include "OptionHandlerFactory.h" #include "OptionHandlerFactory.h"
#include "DlAbortEx.h" #include "DlAbortEx.h"
#include "error_code.h" #include "error_code.h"
#include "prefs.h"
namespace aria2 { namespace aria2 {
@ -196,16 +197,21 @@ void OptionParser::parse(Option& option, std::istream& is)
} }
namespace { namespace {
class DummyOptionHandler:public NameMatchOptionHandler { class DummyOptionHandler:public NullOptionHandler {
protected: protected:
virtual void parseArg(Option& option, const std::string& arg) {} virtual void parseArg(Option& option, const std::string& arg) {}
public: public:
DummyOptionHandler(const std::string& name):NameMatchOptionHandler(name) {} DummyOptionHandler(const std::string& optName)
: NullOptionHandler(),
optName_(optName)
{}
virtual std::string createPossibleValuesString() const virtual const std::string& getName() const
{ {
return A2STR::NIL; return optName_;
} }
private:
std::string optName_;
}; };
} // namespace } // namespace

View File

@ -107,7 +107,7 @@ void gatherOption
// header and index-out option can take array as value // header and index-out option can take array as value
const List* oplist = downcast<List>((*first).second); const List* oplist = downcast<List>((*first).second);
if(oplist && if(oplist &&
(optionName == PREF_HEADER || optionName == PREF_INDEX_OUT)) { (optionName == PREF_HEADER->k || optionName == PREF_INDEX_OUT->k)) {
for(List::ValueType::const_iterator argiter = oplist->begin(), for(List::ValueType::const_iterator argiter = oplist->begin(),
eoi = oplist->end(); argiter != eoi; ++argiter) { eoi = oplist->end(); argiter != eoi; ++argiter) {
const String* opval = downcast<String>(*argiter); const String* opval = downcast<String>(*argiter);
@ -142,8 +142,9 @@ void applyOption(InputIterator optNameFirst,
Option* src) Option* src)
{ {
for(; optNameFirst != optNameLast; ++optNameFirst) { for(; optNameFirst != optNameLast; ++optNameFirst) {
if(src->defined(*optNameFirst)) { const Pref* pref = option::k2p(*optNameFirst);
dest->put(*optNameFirst, src->get(*optNameFirst)); if(src->defined(pref)) {
dest->put(pref, src->get(pref));
} }
} }
} }
@ -152,10 +153,10 @@ void applyOption(InputIterator optNameFirst,
const std::set<std::string>& listChangeableOptions() const std::set<std::string>& listChangeableOptions()
{ {
static const std::string OPTIONS[] = { static const std::string OPTIONS[] = {
PREF_BT_MAX_PEERS, PREF_BT_MAX_PEERS->k,
PREF_BT_REQUEST_PEER_SPEED_LIMIT, PREF_BT_REQUEST_PEER_SPEED_LIMIT->k,
PREF_MAX_DOWNLOAD_LIMIT, PREF_MAX_DOWNLOAD_LIMIT->k,
PREF_MAX_UPLOAD_LIMIT PREF_MAX_UPLOAD_LIMIT->k
}; };
static std::set<std::string> options(vbegin(OPTIONS), vend(OPTIONS)); static std::set<std::string> options(vbegin(OPTIONS), vend(OPTIONS));
return options; return options;
@ -180,11 +181,11 @@ void RpcMethod::applyChangeableOption(Option* dest, Option* src) const
const std::set<std::string>& listChangeableGlobalOptions() const std::set<std::string>& listChangeableGlobalOptions()
{ {
static const std::string OPTIONS[] = { static const std::string OPTIONS[] = {
PREF_MAX_OVERALL_UPLOAD_LIMIT, PREF_MAX_OVERALL_UPLOAD_LIMIT->k,
PREF_MAX_OVERALL_DOWNLOAD_LIMIT, PREF_MAX_OVERALL_DOWNLOAD_LIMIT->k,
PREF_MAX_CONCURRENT_DOWNLOADS, PREF_MAX_CONCURRENT_DOWNLOADS->k,
PREF_LOG, PREF_LOG->k,
PREF_LOG_LEVEL PREF_LOG_LEVEL->k
}; };
static std::set<std::string> options(vbegin(OPTIONS), vend(OPTIONS)); static std::set<std::string> options(vbegin(OPTIONS), vend(OPTIONS));
return options; return options;

View File

@ -1203,15 +1203,14 @@ SharedHandle<ValueBase> GetVersionRpcMethod::process
} }
namespace { namespace {
template<typename InputIterator>
void pushRequestOption void pushRequestOption
(const SharedHandle<Dict>& dict, (const SharedHandle<Dict>& dict, const SharedHandle<Option>& option)
InputIterator optionFirst, InputIterator optionLast)
{ {
const std::set<std::string>& requestOptions = listRequestOptions(); const std::set<std::string>& requestOptions = listRequestOptions();
for(; optionFirst != optionLast; ++optionFirst) { for(size_t i = 0, len = option->getTable().size(); i < len; ++i) {
if(requestOptions.count((*optionFirst).first)) { const Pref* pref = option::i2p(i);
dict->put((*optionFirst).first, (*optionFirst).second); if(requestOptions.count(pref->k) && option->defined(pref)) {
dict->put(pref->k, option->get(pref));
} }
} }
} }
@ -1232,7 +1231,7 @@ SharedHandle<ValueBase> GetOptionRpcMethod::process
} }
SharedHandle<Dict> result = Dict::g(); SharedHandle<Dict> result = Dict::g();
SharedHandle<Option> option = group->getOption(); SharedHandle<Option> option = group->getOption();
pushRequestOption(result, option->begin(), option->end()); pushRequestOption(result, option);
return result; return result;
} }
@ -1240,11 +1239,14 @@ SharedHandle<ValueBase> GetGlobalOptionRpcMethod::process
(const RpcRequest& req, DownloadEngine* e) (const RpcRequest& req, DownloadEngine* e)
{ {
SharedHandle<Dict> result = Dict::g(); SharedHandle<Dict> result = Dict::g();
for(std::map<std::string, std::string>::const_iterator i = for(size_t i = 0, len = e->getOption()->getTable().size(); i < len; ++i) {
e->getOption()->begin(), eoi = e->getOption()->end(); i != eoi; ++i) { const Pref* pref = option::i2p(i);
SharedHandle<OptionHandler> h = getOptionParser()->findByName((*i).first); if(!e->getOption()->defined(pref)) {
continue;
}
SharedHandle<OptionHandler> h = getOptionParser()->findByName(pref->k);
if(h && !h->isHidden()) { if(h && !h->isHidden()) {
result->put((*i).first, (*i).second); result->put(pref->k, e->getOption()->get(pref));
} }
} }
return result; return result;

View File

@ -78,7 +78,7 @@ bool SessionSerializer::save(const std::string& filename) const
namespace { namespace {
const std::vector<std::string>& getCumulativeOpts() const std::vector<std::string>& getCumulativeOpts()
{ {
static std::string cumulativeOpts[] = { PREF_INDEX_OUT, PREF_HEADER }; static std::string cumulativeOpts[] = { PREF_INDEX_OUT->k, PREF_HEADER->k };
static std::vector<std::string> opts static std::vector<std::string> opts
(vbegin(cumulativeOpts), vend(cumulativeOpts)); (vbegin(cumulativeOpts), vend(cumulativeOpts));
return opts; return opts;
@ -108,8 +108,9 @@ bool writeOption(BufferedFile& fp, const SharedHandle<Option>& op)
if(inCumulativeOpts(*itr)) { if(inCumulativeOpts(*itr)) {
continue; continue;
} }
if(op->defined(*itr)) { const Pref* pref = option::k2p(*itr);
if(fp.printf(" %s=%s\n", (*itr).c_str(), op->get(*itr).c_str()) < 0) { if(op->defined(pref)) {
if(fp.printf(" %s=%s\n", (*itr).c_str(), op->get(pref).c_str()) < 0) {
return false; return false;
} }
} }
@ -117,9 +118,10 @@ bool writeOption(BufferedFile& fp, const SharedHandle<Option>& op)
const std::vector<std::string>& cumopts = getCumulativeOpts(); const std::vector<std::string>& cumopts = getCumulativeOpts();
for(std::vector<std::string>::const_iterator opitr = cumopts.begin(), for(std::vector<std::string>::const_iterator opitr = cumopts.begin(),
eoi = cumopts.end(); opitr != eoi; ++opitr) { eoi = cumopts.end(); opitr != eoi; ++opitr) {
if(op->defined(*opitr)) { const Pref* pref = option::k2p(*opitr);
if(op->defined(pref)) {
std::vector<std::string> v; std::vector<std::string> v;
util::split(op->get(*opitr), std::back_inserter(v), "\n", util::split(op->get(pref), std::back_inserter(v), "\n",
false, false); false, false);
for(std::vector<std::string>::const_iterator i = v.begin(), eoi = v.end(); for(std::vector<std::string>::const_iterator i = v.begin(), eoi = v.end();
i != eoi; ++i) { i != eoi; ++i) {
@ -213,7 +215,7 @@ bool SessionSerializer::save(BufferedFile& fp) const
// PREF_PAUSE was removed from option, so save it here looking // PREF_PAUSE was removed from option, so save it here looking
// property separately. // property separately.
if((*itr)->isPauseRequested()) { if((*itr)->isPauseRequested()) {
if(fp.printf(" %s=true\n", PREF_PAUSE.c_str()) < 0) { if(fp.printf(" %s=true\n", PREF_PAUSE->k.c_str()) < 0) {
return false; return false;
} }
} }

View File

@ -72,106 +72,106 @@ namespace aria2 {
const std::set<std::string>& listRequestOptions() const std::set<std::string>& listRequestOptions()
{ {
static const std::string REQUEST_OPTIONS[] = { static const std::string REQUEST_OPTIONS[] = {
PREF_DIR, PREF_DIR->k,
PREF_CHECK_INTEGRITY, PREF_CHECK_INTEGRITY->k,
PREF_CONTINUE, PREF_CONTINUE->k,
PREF_ALL_PROXY, PREF_ALL_PROXY->k,
PREF_ALL_PROXY_USER, PREF_ALL_PROXY_USER->k,
PREF_ALL_PROXY_PASSWD, PREF_ALL_PROXY_PASSWD->k,
PREF_CONNECT_TIMEOUT, PREF_CONNECT_TIMEOUT->k,
PREF_DRY_RUN, PREF_DRY_RUN->k,
PREF_LOWEST_SPEED_LIMIT, PREF_LOWEST_SPEED_LIMIT->k,
PREF_MAX_FILE_NOT_FOUND, PREF_MAX_FILE_NOT_FOUND->k,
PREF_MAX_TRIES, PREF_MAX_TRIES->k,
PREF_NO_PROXY, PREF_NO_PROXY->k,
PREF_OUT, PREF_OUT->k,
PREF_PROXY_METHOD, PREF_PROXY_METHOD->k,
PREF_REMOTE_TIME, PREF_REMOTE_TIME->k,
PREF_SPLIT, PREF_SPLIT->k,
PREF_TIMEOUT, PREF_TIMEOUT->k,
PREF_HTTP_AUTH_CHALLENGE, PREF_HTTP_AUTH_CHALLENGE->k,
PREF_HTTP_NO_CACHE, PREF_HTTP_NO_CACHE->k,
PREF_HTTP_USER, PREF_HTTP_USER->k,
PREF_HTTP_PASSWD, PREF_HTTP_PASSWD->k,
PREF_HTTP_PROXY, PREF_HTTP_PROXY->k,
PREF_HTTP_PROXY_USER, PREF_HTTP_PROXY_USER->k,
PREF_HTTP_PROXY_PASSWD, PREF_HTTP_PROXY_PASSWD->k,
PREF_HTTPS_PROXY, PREF_HTTPS_PROXY->k,
PREF_HTTPS_PROXY_USER, PREF_HTTPS_PROXY_USER->k,
PREF_HTTPS_PROXY_PASSWD, PREF_HTTPS_PROXY_PASSWD->k,
PREF_REFERER, PREF_REFERER->k,
PREF_ENABLE_HTTP_KEEP_ALIVE, PREF_ENABLE_HTTP_KEEP_ALIVE->k,
PREF_ENABLE_HTTP_PIPELINING, PREF_ENABLE_HTTP_PIPELINING->k,
PREF_HEADER, PREF_HEADER->k,
PREF_USE_HEAD, PREF_USE_HEAD->k,
PREF_USER_AGENT, PREF_USER_AGENT->k,
PREF_FTP_USER, PREF_FTP_USER->k,
PREF_FTP_PASSWD, PREF_FTP_PASSWD->k,
PREF_FTP_PASV, PREF_FTP_PASV->k,
PREF_FTP_PROXY, PREF_FTP_PROXY->k,
PREF_FTP_PROXY_USER, PREF_FTP_PROXY_USER->k,
PREF_FTP_PROXY_PASSWD, PREF_FTP_PROXY_PASSWD->k,
PREF_FTP_TYPE, PREF_FTP_TYPE->k,
PREF_FTP_REUSE_CONNECTION, PREF_FTP_REUSE_CONNECTION->k,
PREF_NO_NETRC, PREF_NO_NETRC->k,
PREF_REUSE_URI, PREF_REUSE_URI->k,
PREF_SELECT_FILE, PREF_SELECT_FILE->k,
PREF_BT_ENABLE_LPD, PREF_BT_ENABLE_LPD->k,
PREF_BT_EXTERNAL_IP, PREF_BT_EXTERNAL_IP->k,
PREF_BT_HASH_CHECK_SEED, PREF_BT_HASH_CHECK_SEED->k,
PREF_BT_MAX_OPEN_FILES, PREF_BT_MAX_OPEN_FILES->k,
PREF_BT_MAX_PEERS, PREF_BT_MAX_PEERS->k,
PREF_BT_METADATA_ONLY, PREF_BT_METADATA_ONLY->k,
PREF_BT_MIN_CRYPTO_LEVEL, PREF_BT_MIN_CRYPTO_LEVEL->k,
PREF_BT_PRIORITIZE_PIECE, PREF_BT_PRIORITIZE_PIECE->k,
PREF_BT_REQUIRE_CRYPTO, PREF_BT_REQUIRE_CRYPTO->k,
PREF_BT_REQUEST_PEER_SPEED_LIMIT, PREF_BT_REQUEST_PEER_SPEED_LIMIT->k,
PREF_BT_SAVE_METADATA, PREF_BT_SAVE_METADATA->k,
PREF_BT_SEED_UNVERIFIED, PREF_BT_SEED_UNVERIFIED->k,
PREF_BT_STOP_TIMEOUT, PREF_BT_STOP_TIMEOUT->k,
PREF_BT_TRACKER_INTERVAL, PREF_BT_TRACKER_INTERVAL->k,
PREF_BT_TRACKER_TIMEOUT, PREF_BT_TRACKER_TIMEOUT->k,
PREF_BT_TRACKER_CONNECT_TIMEOUT, PREF_BT_TRACKER_CONNECT_TIMEOUT->k,
PREF_ENABLE_PEER_EXCHANGE, PREF_ENABLE_PEER_EXCHANGE->k,
PREF_FOLLOW_TORRENT, PREF_FOLLOW_TORRENT->k,
PREF_INDEX_OUT, PREF_INDEX_OUT->k,
PREF_MAX_UPLOAD_LIMIT, PREF_MAX_UPLOAD_LIMIT->k,
PREF_SEED_RATIO, PREF_SEED_RATIO->k,
PREF_SEED_TIME, PREF_SEED_TIME->k,
PREF_FOLLOW_METALINK, PREF_FOLLOW_METALINK->k,
PREF_METALINK_SERVERS, PREF_METALINK_SERVERS->k,
PREF_METALINK_LANGUAGE, PREF_METALINK_LANGUAGE->k,
PREF_METALINK_LOCATION, PREF_METALINK_LOCATION->k,
PREF_METALINK_OS, PREF_METALINK_OS->k,
PREF_METALINK_VERSION, PREF_METALINK_VERSION->k,
PREF_METALINK_PREFERRED_PROTOCOL, PREF_METALINK_PREFERRED_PROTOCOL->k,
PREF_METALINK_ENABLE_UNIQUE_PROTOCOL, PREF_METALINK_ENABLE_UNIQUE_PROTOCOL->k,
PREF_ALLOW_OVERWRITE, PREF_ALLOW_OVERWRITE->k,
PREF_ALLOW_PIECE_LENGTH_CHANGE, PREF_ALLOW_PIECE_LENGTH_CHANGE->k,
PREF_ASYNC_DNS, PREF_ASYNC_DNS->k,
PREF_AUTO_FILE_RENAMING, PREF_AUTO_FILE_RENAMING->k,
PREF_FILE_ALLOCATION, PREF_FILE_ALLOCATION->k,
PREF_MAX_DOWNLOAD_LIMIT, PREF_MAX_DOWNLOAD_LIMIT->k,
PREF_NO_FILE_ALLOCATION_LIMIT, PREF_NO_FILE_ALLOCATION_LIMIT->k,
PREF_PARAMETERIZED_URI, PREF_PARAMETERIZED_URI->k,
PREF_REALTIME_CHUNK_CHECKSUM, PREF_REALTIME_CHUNK_CHECKSUM->k,
PREF_REMOVE_CONTROL_FILE, PREF_REMOVE_CONTROL_FILE->k,
PREF_ALWAYS_RESUME, PREF_ALWAYS_RESUME->k,
PREF_MAX_RESUME_FAILURE_TRIES, PREF_MAX_RESUME_FAILURE_TRIES->k,
PREF_HTTP_ACCEPT_GZIP, PREF_HTTP_ACCEPT_GZIP->k,
PREF_MAX_CONNECTION_PER_SERVER, PREF_MAX_CONNECTION_PER_SERVER->k,
PREF_MIN_SPLIT_SIZE, PREF_MIN_SPLIT_SIZE->k,
PREF_CONDITIONAL_GET, PREF_CONDITIONAL_GET->k,
PREF_ENABLE_ASYNC_DNS6, PREF_ENABLE_ASYNC_DNS6->k,
PREF_BT_TRACKER, PREF_BT_TRACKER->k,
PREF_BT_EXCLUDE_TRACKER, PREF_BT_EXCLUDE_TRACKER->k,
PREF_RETRY_WAIT, PREF_RETRY_WAIT->k,
PREF_METALINK_BASE_URI, PREF_METALINK_BASE_URI->k,
PREF_PAUSE, PREF_PAUSE->k,
PREF_STREAM_PIECE_SELECTOR, PREF_STREAM_PIECE_SELECTOR->k,
PREF_HASH_CHECK_ONLY, PREF_HASH_CHECK_ONLY->k,
PREF_CHECKSUM, PREF_CHECKSUM->k,
PREF_PIECE_LENGTH PREF_PIECE_LENGTH->k
}; };
static std::set<std::string> requestOptions static std::set<std::string> requestOptions
(vbegin(REQUEST_OPTIONS), vend(REQUEST_OPTIONS)); (vbegin(REQUEST_OPTIONS), vend(REQUEST_OPTIONS));
@ -534,8 +534,9 @@ void createRequestGroupForUriList
for(std::set<std::string>::const_iterator i = for(std::set<std::string>::const_iterator i =
listRequestOptions().begin(), eoi = listRequestOptions().end(); listRequestOptions().begin(), eoi = listRequestOptions().end();
i != eoi; ++i) { i != eoi; ++i) {
if(tempOption->defined(*i)) { const Pref* pref = option::k2p(*i);
requestOption->put(*i, tempOption->get(*i)); if(tempOption->defined(pref)) {
requestOption->put(pref, tempOption->get(pref));
} }
} }

View File

@ -68,13 +68,13 @@ extern void showUsage(const std::string& keyword, const OptionParser& oparser);
namespace { namespace {
void overrideWithEnv(Option& op, const OptionParser& optionParser, void overrideWithEnv(Option& op, const OptionParser& optionParser,
const std::string& pref, const Pref* pref,
const std::string& envName) const std::string& envName)
{ {
char* value = getenv(envName.c_str()); char* value = getenv(envName.c_str());
if(value) { if(value) {
try { try {
optionParser.findByName(pref)->parse(op, value); optionParser.findByName(pref->k)->parse(op, value);
} catch(Exception& e) { } catch(Exception& e) {
global::cerr()->printf global::cerr()->printf
("Caught Error while parsing environment variable '%s'\n%s\n", ("Caught Error while parsing environment variable '%s'\n%s\n",
@ -102,16 +102,16 @@ void option_processing(Option& op, std::vector<std::string>& uris,
noConf = op.getAsBool(PREF_NO_CONF); noConf = op.getAsBool(PREF_NO_CONF);
ucfname = op.get(PREF_CONF_PATH); ucfname = op.get(PREF_CONF_PATH);
if(op.defined("version")) { if(op.defined(PREF_VERSION)) {
showVersion(); showVersion();
exit(error_code::FINISHED); exit(error_code::FINISHED);
} }
if(op.defined("help")) { if(op.defined(PREF_HELP)) {
std::string keyword; std::string keyword;
if(op.get("help").empty()) { if(op.get(PREF_HELP).empty()) {
keyword = TAG_BASIC; keyword = TAG_BASIC;
} else { } else {
keyword = op.get("help"); keyword = op.get(PREF_HELP);
if(util::startsWith(keyword, "--")) { if(util::startsWith(keyword, "--")) {
keyword = keyword.substr(2); keyword = keyword.substr(2);
} }
@ -130,7 +130,7 @@ void option_processing(Option& op, std::vector<std::string>& uris,
if(!noConf) { if(!noConf) {
std::string cfname = std::string cfname =
ucfname.empty() ? ucfname.empty() ?
oparser.findByName(PREF_CONF_PATH)->getDefaultValue(): oparser.findByName(PREF_CONF_PATH->k)->getDefaultValue():
ucfname; ucfname;
if(File(cfname).isFile()) { if(File(cfname).isFile()) {

View File

@ -34,8 +34,91 @@
/* copyright --> */ /* copyright --> */
#include "prefs.h" #include "prefs.h"
#include <cassert>
#include <vector>
#include <map>
namespace aria2 { namespace aria2 {
Pref::Pref(const std::string& k, size_t i):k(k), i(i) {}
namespace {
class PrefFactory {
public:
PrefFactory():count_(0)
{
// We add special null pref whose ID is 0.
makePref("");
}
size_t nextId()
{
return count_++;
}
Pref* makePref(const std::string& key)
{
size_t id = nextId();
Pref* pref = new Pref(key, id);
i2p_.push_back(pref);
k2p_[key] = pref;
return pref;
}
size_t getCount() const
{
return count_;
}
const Pref* i2p(size_t id) const
{
assert(id < count_);
return i2p_[id];
}
const Pref* k2p(const std::string& k) const
{
std::map<std::string, const Pref*>::const_iterator i = k2p_.find(k);
if(i == k2p_.end()) {
return i2p_[0];
} else {
return (*i).second;
}
}
private:
size_t count_;
std::vector<const Pref*> i2p_;
std::map<std::string, const Pref*> k2p_;
};
PrefFactory* getPrefFactory()
{
static PrefFactory* pf = new PrefFactory();
return pf;
}
Pref* makePref(const std::string& key)
{
return getPrefFactory()->makePref(key);
}
} // namespace
namespace option {
size_t countOption()
{
return getPrefFactory()->getCount();
}
const Pref* i2p(size_t id)
{
return getPrefFactory()->i2p(id);
}
const Pref* k2p(const std::string& key)
{
return getPrefFactory()->k2p(key);
}
} // namespace option
/** /**
* Constants * Constants
*/ */
@ -47,388 +130,391 @@ const std::string V_MEM("mem");
const std::string V_ALL("all"); const std::string V_ALL("all");
const std::string A2_V_FULL("full"); const std::string A2_V_FULL("full");
const std::string A2_V_GEOM("geom"); const std::string A2_V_GEOM("geom");
/**
* General preferences
*/
// values: 1*digit
const std::string PREF_TIMEOUT("timeout");
// values: 1*digit
const std::string PREF_DNS_TIMEOUT("dns-timeout");
// values: 1*digit
const std::string PREF_CONNECT_TIMEOUT("connect-timeout");
// values: 1*digit
const std::string PREF_MAX_TRIES("max-tries");
// values: 1*digit
const std::string PREF_AUTO_SAVE_INTERVAL("auto-save-interval");
// values: a string that your file system recognizes as a file name.
const std::string PREF_LOG("log");
// values: a string that your file system recognizes as a directory.
const std::string PREF_DIR("dir");
// values: a string that your file system recognizes as a file name.
const std::string PREF_OUT("out");
// values: 1*digit
const std::string PREF_SPLIT("split");
// value: true | false
const std::string PREF_DAEMON("daemon");
// value: a string
const std::string PREF_REFERER("referer");
// value: 1*digit
const std::string PREF_LOWEST_SPEED_LIMIT("lowest-speed-limit");
// value: 1*digit
const std::string PREF_PIECE_LENGTH("piece-length");
// value: 1*digit
const std::string PREF_MAX_OVERALL_DOWNLOAD_LIMIT("max-overall-download-limit");
// value: 1*digit
const std::string PREF_MAX_DOWNLOAD_LIMIT("max-download-limit");
// value: 1*digit
const std::string PREF_STARTUP_IDLE_TIME("startup-idle-time");
// value: prealloc | fallc | none
const std::string PREF_FILE_ALLOCATION("file-allocation");
const std::string V_PREALLOC("prealloc"); const std::string V_PREALLOC("prealloc");
const std::string V_FALLOC("falloc"); const std::string V_FALLOC("falloc");
// value: 1*digit
const std::string PREF_NO_FILE_ALLOCATION_LIMIT("no-file-allocation-limit");
// value: true | false
const std::string PREF_ALLOW_OVERWRITE("allow-overwrite");
// value: true | false
const std::string PREF_REALTIME_CHUNK_CHECKSUM("realtime-chunk-checksum");
// value: true | false
const std::string PREF_CHECK_INTEGRITY("check-integrity");
// value: string that your file system recognizes as a file name.
const std::string PREF_NETRC_PATH("netrc-path");
// value:
const std::string PREF_CONTINUE("continue");
// value:
const std::string PREF_NO_NETRC("no-netrc");
// value: 1*digit
const std::string PREF_MAX_DOWNLOADS("max-downloads");
// value: string that your file system recognizes as a file name.
const std::string PREF_INPUT_FILE("input-file");
// value: 1*digit
const std::string PREF_MAX_CONCURRENT_DOWNLOADS("max-concurrent-downloads");
// value: true | false
const std::string PREF_FORCE_SEQUENTIAL("force-sequential");
// value: true | false
const std::string PREF_AUTO_FILE_RENAMING("auto-file-renaming");
// value: true | false
const std::string PREF_PARAMETERIZED_URI("parameterized-uri");
// value: true | false
const std::string PREF_ENABLE_DIRECT_IO("enable-direct-io");
// value: true | false
const std::string PREF_ALLOW_PIECE_LENGTH_CHANGE("allow-piece-length-change");
// value: true | false
const std::string PREF_NO_CONF("no-conf");
// value: string
const std::string PREF_CONF_PATH("conf-path");
// value: 1*digit
const std::string PREF_STOP("stop");
// value: true | false
const std::string PREF_QUIET("quiet");
// value: true | false
const std::string PREF_ASYNC_DNS("async-dns");
// value: 1*digit
const std::string PREF_SUMMARY_INTERVAL("summary-interval");
// value: debug, info, notice, warn, error
const std::string PREF_LOG_LEVEL("log-level");
const std::string V_DEBUG("debug"); const std::string V_DEBUG("debug");
const std::string V_INFO("info"); const std::string V_INFO("info");
const std::string V_NOTICE("notice"); const std::string V_NOTICE("notice");
const std::string V_WARN("warn"); const std::string V_WARN("warn");
const std::string V_ERROR("error"); const std::string V_ERROR("error");
// value: inorder | feedback | adaptive
const std::string PREF_URI_SELECTOR("uri-selector");
const std::string V_INORDER("inorder"); const std::string V_INORDER("inorder");
const std::string V_FEEDBACK("feedback"); const std::string V_FEEDBACK("feedback");
const std::string V_ADAPTIVE("adaptive"); const std::string V_ADAPTIVE("adaptive");
// value: 1*digit
const std::string PREF_SERVER_STAT_TIMEOUT("server-stat-timeout");
// value: string that your file system recognizes as a file name.
const std::string PREF_SERVER_STAT_IF("server-stat-if");
// value: string that your file system recognizes as a file name.
const std::string PREF_SERVER_STAT_OF("server-stat-of");
// value: true | false
const std::string PREF_REMOTE_TIME("remote-time");
// value: 1*digit
const std::string PREF_MAX_FILE_NOT_FOUND("max-file-not-found");
// value: epoll | select
const std::string PREF_EVENT_POLL("event-poll");
const std::string V_EPOLL("epoll"); const std::string V_EPOLL("epoll");
const std::string V_KQUEUE("kqueue"); const std::string V_KQUEUE("kqueue");
const std::string V_PORT("port"); const std::string V_PORT("port");
const std::string V_POLL("poll"); const std::string V_POLL("poll");
const std::string V_SELECT("select"); const std::string V_SELECT("select");
const std::string V_BINARY("binary");
const std::string V_ASCII("ascii");
const std::string V_GET("get");
const std::string V_TUNNEL("tunnel");
const std::string V_PLAIN("plain");
const std::string V_ARC4("arc4");
const std::string V_HTTP("http");
const std::string V_HTTPS("https");
const std::string V_FTP("ftp");
const Pref* PREF_VERSION = makePref("version");
const Pref* PREF_HELP = makePref("help");
/**
* General preferences
*/
// values: 1*digit
const Pref* PREF_TIMEOUT = makePref("timeout");
// values: 1*digit
const Pref* PREF_DNS_TIMEOUT = makePref("dns-timeout");
// values: 1*digit
const Pref* PREF_CONNECT_TIMEOUT = makePref("connect-timeout");
// values: 1*digit
const Pref* PREF_MAX_TRIES = makePref("max-tries");
// values: 1*digit
const Pref* PREF_AUTO_SAVE_INTERVAL = makePref("auto-save-interval");
// values: a string that your file system recognizes as a file name.
const Pref* PREF_LOG = makePref("log");
// values: a string that your file system recognizes as a directory.
const Pref* PREF_DIR = makePref("dir");
// values: a string that your file system recognizes as a file name.
const Pref* PREF_OUT = makePref("out");
// values: 1*digit
const Pref* PREF_SPLIT = makePref("split");
// value: true | false // value: true | false
const std::string PREF_ENABLE_RPC("enable-rpc"); const Pref* PREF_DAEMON = makePref("daemon");
// value: a string
const Pref* PREF_REFERER = makePref("referer");
// value: 1*digit // value: 1*digit
const std::string PREF_RPC_LISTEN_PORT("rpc-listen-port"); const Pref* PREF_LOWEST_SPEED_LIMIT = makePref("lowest-speed-limit");
// value: string
const std::string PREF_RPC_USER("rpc-user");
// value: string
const std::string PREF_RPC_PASSWD("rpc-passwd");
// value: 1*digit // value: 1*digit
const std::string PREF_RPC_MAX_REQUEST_SIZE("rpc-max-request-size"); const Pref* PREF_PIECE_LENGTH = makePref("piece-length");
// value: true | false
const std::string PREF_RPC_LISTEN_ALL("rpc-listen-all");
// value: true | false
const std::string PREF_RPC_ALLOW_ORIGIN_ALL("rpc-allow-origin-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: string
const std::string PREF_INTERFACE("interface");
// value: true | false
const std::string PREF_DISABLE_IPV6("disable-ipv6");
// value: true | false
const std::string PREF_HUMAN_READABLE("human-readable");
// value: true | false
const std::string PREF_REMOVE_CONTROL_FILE("remove-control-file");
// value: true | false
const std::string PREF_ALWAYS_RESUME("always-resume");
// value: 1*digit // value: 1*digit
const std::string PREF_MAX_RESUME_FAILURE_TRIES("max-resume-failure-tries"); const Pref* PREF_MAX_OVERALL_DOWNLOAD_LIMIT = makePref("max-overall-download-limit");
// value: 1*digit
const Pref* PREF_MAX_DOWNLOAD_LIMIT = makePref("max-download-limit");
// value: 1*digit
const Pref* PREF_STARTUP_IDLE_TIME = makePref("startup-idle-time");
// value: prealloc | fallc | none
const Pref* PREF_FILE_ALLOCATION = makePref("file-allocation");
// value: 1*digit
const Pref* PREF_NO_FILE_ALLOCATION_LIMIT = makePref("no-file-allocation-limit");
// value: true | false
const Pref* PREF_ALLOW_OVERWRITE = makePref("allow-overwrite");
// value: true | false
const Pref* PREF_REALTIME_CHUNK_CHECKSUM = makePref("realtime-chunk-checksum");
// value: true | false
const Pref* PREF_CHECK_INTEGRITY = makePref("check-integrity");
// value: string that your file system recognizes as a file name. // value: string that your file system recognizes as a file name.
const std::string PREF_SAVE_SESSION("save-session"); const Pref* PREF_NETRC_PATH = makePref("netrc-path");
// value:
const Pref* PREF_CONTINUE = makePref("continue");
// value:
const Pref* PREF_NO_NETRC = makePref("no-netrc");
// value: 1*digit // value: 1*digit
const std::string PREF_MAX_CONNECTION_PER_SERVER("max-connection-per-server"); const Pref* PREF_MAX_DOWNLOADS = makePref("max-downloads");
// value: string that your file system recognizes as a file name.
const Pref* PREF_INPUT_FILE = makePref("input-file");
// value: 1*digit // value: 1*digit
const std::string PREF_MIN_SPLIT_SIZE("min-split-size"); const Pref* PREF_MAX_CONCURRENT_DOWNLOADS = makePref("max-concurrent-downloads");
// value: true | false // value: true | false
const std::string PREF_CONDITIONAL_GET("conditional-get"); const Pref* PREF_FORCE_SEQUENTIAL = makePref("force-sequential");
// value: true | false // value: true | false
const std::string PREF_SELECT_LEAST_USED_HOST("select-least-used-host"); const Pref* PREF_AUTO_FILE_RENAMING = makePref("auto-file-renaming");
// value: true | false // value: true | false
const std::string PREF_ENABLE_ASYNC_DNS6("enable-async-dns6"); const Pref* PREF_PARAMETERIZED_URI = makePref("parameterized-uri");
// value: 1*digit // value: true | false
const std::string PREF_MAX_DOWNLOAD_RESULT("max-download-result"); const Pref* PREF_ENABLE_DIRECT_IO = makePref("enable-direct-io");
// value: 1*digit // value: true | false
const std::string PREF_RETRY_WAIT("retry-wait"); const Pref* PREF_ALLOW_PIECE_LENGTH_CHANGE = makePref("allow-piece-length-change");
// value: true | false
const Pref* PREF_NO_CONF = makePref("no-conf");
// value: string // value: string
const std::string PREF_ASYNC_DNS_SERVER("async-dns-server"); const Pref* PREF_CONF_PATH = makePref("conf-path");
// value: 1*digit
const Pref* PREF_STOP = makePref("stop");
// value: true | false // value: true | false
const std::string PREF_SHOW_CONSOLE_READOUT("show-console-readout"); const Pref* PREF_QUIET = makePref("quiet");
// value: true | false
const Pref* PREF_ASYNC_DNS = makePref("async-dns");
// value: 1*digit
const Pref* PREF_SUMMARY_INTERVAL = makePref("summary-interval");
// value: debug, info, notice, warn, error
const Pref* PREF_LOG_LEVEL = makePref("log-level");
// value: inorder | feedback | adaptive
const Pref* PREF_URI_SELECTOR = makePref("uri-selector");
// value: 1*digit
const Pref* PREF_SERVER_STAT_TIMEOUT = makePref("server-stat-timeout");
// value: string that your file system recognizes as a file name.
const Pref* PREF_SERVER_STAT_IF = makePref("server-stat-if");
// value: string that your file system recognizes as a file name.
const Pref* PREF_SERVER_STAT_OF = makePref("server-stat-of");
// value: true | false
const Pref* PREF_REMOTE_TIME = makePref("remote-time");
// value: 1*digit
const Pref* PREF_MAX_FILE_NOT_FOUND = makePref("max-file-not-found");
// value: epoll | select
const Pref* PREF_EVENT_POLL = makePref("event-poll");
// value: true | false
const Pref* PREF_ENABLE_RPC = makePref("enable-rpc");
// value: 1*digit
const Pref* PREF_RPC_LISTEN_PORT = makePref("rpc-listen-port");
// value: string
const Pref* PREF_RPC_USER = makePref("rpc-user");
// value: string
const Pref* PREF_RPC_PASSWD = makePref("rpc-passwd");
// value: 1*digit
const Pref* PREF_RPC_MAX_REQUEST_SIZE = makePref("rpc-max-request-size");
// value: true | false
const Pref* PREF_RPC_LISTEN_ALL = makePref("rpc-listen-all");
// value: true | false
const Pref* PREF_RPC_ALLOW_ORIGIN_ALL = makePref("rpc-allow-origin-all");
// value: true | false
const Pref* PREF_DRY_RUN = makePref("dry-run");
// value: true | false
const Pref* PREF_REUSE_URI = makePref("reuse-uri");
// value: string
const Pref* PREF_ON_DOWNLOAD_START = makePref("on-download-start");
const Pref* PREF_ON_DOWNLOAD_PAUSE = makePref("on-download-pause");
const Pref* PREF_ON_DOWNLOAD_STOP = makePref("on-download-stop");
const Pref* PREF_ON_DOWNLOAD_COMPLETE = makePref("on-download-complete");
const Pref* PREF_ON_DOWNLOAD_ERROR = makePref("on-download-error");
// value: string
const Pref* PREF_INTERFACE = makePref("interface");
// value: true | false
const Pref* PREF_DISABLE_IPV6 = makePref("disable-ipv6");
// value: true | false
const Pref* PREF_HUMAN_READABLE = makePref("human-readable");
// value: true | false
const Pref* PREF_REMOVE_CONTROL_FILE = makePref("remove-control-file");
// value: true | false
const Pref* PREF_ALWAYS_RESUME = makePref("always-resume");
// value: 1*digit
const Pref* PREF_MAX_RESUME_FAILURE_TRIES = makePref("max-resume-failure-tries");
// value: string that your file system recognizes as a file name.
const Pref* PREF_SAVE_SESSION = makePref("save-session");
// value: 1*digit
const Pref* PREF_MAX_CONNECTION_PER_SERVER = makePref("max-connection-per-server");
// value: 1*digit
const Pref* PREF_MIN_SPLIT_SIZE = makePref("min-split-size");
// value: true | false
const Pref* PREF_CONDITIONAL_GET = makePref("conditional-get");
// value: true | false
const Pref* PREF_SELECT_LEAST_USED_HOST = makePref("select-least-used-host");
// value: true | false
const Pref* PREF_ENABLE_ASYNC_DNS6 = makePref("enable-async-dns6");
// value: 1*digit
const Pref* PREF_MAX_DOWNLOAD_RESULT = makePref("max-download-result");
// value: 1*digit
const Pref* PREF_RETRY_WAIT = makePref("retry-wait");
// value: string
const Pref* PREF_ASYNC_DNS_SERVER = makePref("async-dns-server");
// value: true | false
const Pref* PREF_SHOW_CONSOLE_READOUT = makePref("show-console-readout");
// value: default | inorder // value: default | inorder
const std::string PREF_STREAM_PIECE_SELECTOR("stream-piece-selector"); const Pref* PREF_STREAM_PIECE_SELECTOR = makePref("stream-piece-selector");
// value: true | false // value: true | false
const std::string PREF_TRUNCATE_CONSOLE_READOUT("truncate-console-readout"); const Pref* PREF_TRUNCATE_CONSOLE_READOUT = makePref("truncate-console-readout");
// value: true | false // value: true | false
const std::string PREF_PAUSE("pause"); const Pref* PREF_PAUSE = makePref("pause");
// value: default | full // value: default | full
const std::string PREF_DOWNLOAD_RESULT("download-result"); const Pref* PREF_DOWNLOAD_RESULT = makePref("download-result");
// value: true | false // value: true | false
const std::string PREF_HASH_CHECK_ONLY("hash-check-only"); const Pref* PREF_HASH_CHECK_ONLY = makePref("hash-check-only");
// values: hashType=digest // values: hashType=digest
const std::string PREF_CHECKSUM("checksum"); const Pref* PREF_CHECKSUM = makePref("checksum");
/** /**
* FTP related preferences * FTP related preferences
*/ */
const std::string PREF_FTP_USER("ftp-user"); const Pref* PREF_FTP_USER = makePref("ftp-user");
const std::string PREF_FTP_PASSWD("ftp-passwd"); const Pref* PREF_FTP_PASSWD = makePref("ftp-passwd");
// values: binary | ascii // values: binary | ascii
const std::string PREF_FTP_TYPE("ftp-type"); const Pref* PREF_FTP_TYPE = makePref("ftp-type");
const std::string V_BINARY("binary");
const std::string V_ASCII("ascii");
// values: true | false // values: true | false
const std::string PREF_FTP_PASV("ftp-pasv"); const Pref* PREF_FTP_PASV = makePref("ftp-pasv");
// values: true | false // values: true | false
const std::string PREF_FTP_REUSE_CONNECTION("ftp-reuse-connection"); const Pref* PREF_FTP_REUSE_CONNECTION = makePref("ftp-reuse-connection");
/** /**
* HTTP related preferences * HTTP related preferences
*/ */
const std::string PREF_HTTP_USER("http-user"); const Pref* PREF_HTTP_USER = makePref("http-user");
const std::string PREF_HTTP_PASSWD("http-passwd"); const Pref* PREF_HTTP_PASSWD = makePref("http-passwd");
// values: string // values: string
const std::string PREF_USER_AGENT("user-agent"); const Pref* PREF_USER_AGENT = makePref("user-agent");
// value: string that your file system recognizes as a file name. // value: string that your file system recognizes as a file name.
const std::string PREF_LOAD_COOKIES("load-cookies"); const Pref* PREF_LOAD_COOKIES = makePref("load-cookies");
// value: string that your file system recognizes as a file name. // value: string that your file system recognizes as a file name.
const std::string PREF_SAVE_COOKIES("save-cookies"); const Pref* PREF_SAVE_COOKIES = makePref("save-cookies");
// values: true | false // values: true | false
const std::string PREF_ENABLE_HTTP_KEEP_ALIVE("enable-http-keep-alive"); const Pref* PREF_ENABLE_HTTP_KEEP_ALIVE = makePref("enable-http-keep-alive");
// values: true | false // values: true | false
const std::string PREF_ENABLE_HTTP_PIPELINING("enable-http-pipelining"); const Pref* PREF_ENABLE_HTTP_PIPELINING = makePref("enable-http-pipelining");
// value: 1*digit // value: 1*digit
const std::string PREF_MAX_HTTP_PIPELINING("max-http-pipelining"); const Pref* PREF_MAX_HTTP_PIPELINING = makePref("max-http-pipelining");
// value: string // value: string
const std::string PREF_HEADER("header"); const Pref* PREF_HEADER = makePref("header");
// value: string that your file system recognizes as a file name. // value: string that your file system recognizes as a file name.
const std::string PREF_CERTIFICATE("certificate"); const Pref* PREF_CERTIFICATE = makePref("certificate");
// value: string that your file system recognizes as a file name. // value: string that your file system recognizes as a file name.
const std::string PREF_PRIVATE_KEY("private-key"); const Pref* PREF_PRIVATE_KEY = makePref("private-key");
// value: string that your file system recognizes as a file name. // value: string that your file system recognizes as a file name.
const std::string PREF_CA_CERTIFICATE("ca-certificate"); const Pref* PREF_CA_CERTIFICATE = makePref("ca-certificate");
// value: true | false // value: true | false
const std::string PREF_CHECK_CERTIFICATE("check-certificate"); const Pref* PREF_CHECK_CERTIFICATE = makePref("check-certificate");
// value: true | false // value: true | false
const std::string PREF_USE_HEAD("use-head"); const Pref* PREF_USE_HEAD = makePref("use-head");
// value: true | false // value: true | false
const std::string PREF_HTTP_AUTH_CHALLENGE("http-auth-challenge"); const Pref* PREF_HTTP_AUTH_CHALLENGE = makePref("http-auth-challenge");
// value: true | false // value: true | false
const std::string PREF_HTTP_NO_CACHE("http-no-cache"); const Pref* PREF_HTTP_NO_CACHE = makePref("http-no-cache");
// value: true | false // value: true | false
const std::string PREF_HTTP_ACCEPT_GZIP("http-accept-gzip"); const Pref* PREF_HTTP_ACCEPT_GZIP = makePref("http-accept-gzip");
/** /**
* Proxy related preferences * Proxy related preferences
*/ */
const std::string PREF_HTTP_PROXY("http-proxy"); const Pref* PREF_HTTP_PROXY = makePref("http-proxy");
const std::string PREF_HTTPS_PROXY("https-proxy"); const Pref* PREF_HTTPS_PROXY = makePref("https-proxy");
const std::string PREF_FTP_PROXY("ftp-proxy"); const Pref* PREF_FTP_PROXY = makePref("ftp-proxy");
const std::string PREF_ALL_PROXY("all-proxy"); const Pref* PREF_ALL_PROXY = makePref("all-proxy");
// values: comma separeted hostname or domain // values: comma separeted hostname or domain
const std::string PREF_NO_PROXY("no-proxy"); const Pref* PREF_NO_PROXY = makePref("no-proxy");
// values: get | tunnel // values: get | tunnel
const std::string PREF_PROXY_METHOD("proxy-method"); const Pref* PREF_PROXY_METHOD = makePref("proxy-method");
const std::string V_GET("get"); const Pref* PREF_HTTP_PROXY_USER = makePref("http-proxy-user");
const std::string V_TUNNEL("tunnel"); const Pref* PREF_HTTP_PROXY_PASSWD = makePref("http-proxy-passwd");
const std::string PREF_HTTP_PROXY_USER("http-proxy-user"); const Pref* PREF_HTTPS_PROXY_USER = makePref("https-proxy-user");
const std::string PREF_HTTP_PROXY_PASSWD("http-proxy-passwd"); const Pref* PREF_HTTPS_PROXY_PASSWD = makePref("https-proxy-passwd");
const std::string PREF_HTTPS_PROXY_USER("https-proxy-user"); const Pref* PREF_FTP_PROXY_USER = makePref("ftp-proxy-user");
const std::string PREF_HTTPS_PROXY_PASSWD("https-proxy-passwd"); const Pref* PREF_FTP_PROXY_PASSWD = makePref("ftp-proxy-passwd");
const std::string PREF_FTP_PROXY_USER("ftp-proxy-user"); const Pref* PREF_ALL_PROXY_USER = makePref("all-proxy-user");
const std::string PREF_FTP_PROXY_PASSWD("ftp-proxy-passwd"); const Pref* PREF_ALL_PROXY_PASSWD = makePref("all-proxy-passwd");
const std::string PREF_ALL_PROXY_USER("all-proxy-user");
const std::string PREF_ALL_PROXY_PASSWD("all-proxy-passwd");
/** /**
* BitTorrent related preferences * BitTorrent related preferences
*/ */
// values: 1*digit // values: 1*digit
const std::string PREF_PEER_CONNECTION_TIMEOUT("peer-connection-timeout"); const Pref* PREF_PEER_CONNECTION_TIMEOUT = makePref("peer-connection-timeout");
// values: 1*digit // values: 1*digit
const std::string PREF_BT_TIMEOUT("bt-timeout"); const Pref* PREF_BT_TIMEOUT = makePref("bt-timeout");
// values: 1*digit // values: 1*digit
const std::string PREF_BT_REQUEST_TIMEOUT("bt-request-timeout"); const Pref* PREF_BT_REQUEST_TIMEOUT = makePref("bt-request-timeout");
// values: true | false // values: true | false
const std::string PREF_SHOW_FILES("show-files"); const Pref* PREF_SHOW_FILES = makePref("show-files");
// values: 1*digit // values: 1*digit
const std::string PREF_MAX_OVERALL_UPLOAD_LIMIT("max-overall-upload-limit"); const Pref* PREF_MAX_OVERALL_UPLOAD_LIMIT = makePref("max-overall-upload-limit");
// values: 1*digit // values: 1*digit
const std::string PREF_MAX_UPLOAD_LIMIT("max-upload-limit"); const Pref* PREF_MAX_UPLOAD_LIMIT = makePref("max-upload-limit");
// values: a string that your file system recognizes as a file name. // values: a string that your file system recognizes as a file name.
const std::string PREF_TORRENT_FILE("torrent-file"); const Pref* PREF_TORRENT_FILE = makePref("torrent-file");
// values: 1*digit // values: 1*digit
const std::string PREF_LISTEN_PORT("listen-port"); const Pref* PREF_LISTEN_PORT = makePref("listen-port");
// values: true | false | mem // values: true | false | mem
const std::string PREF_FOLLOW_TORRENT("follow-torrent"); const Pref* PREF_FOLLOW_TORRENT = makePref("follow-torrent");
// values: 1*digit *( (,|-) 1*digit); // values: 1*digit * = makePref( = makePref(,|-) 1*digit);
const std::string PREF_SELECT_FILE("select-file"); const Pref* PREF_SELECT_FILE = makePref("select-file");
// values: 1*digit // values: 1*digit
const std::string PREF_SEED_TIME("seed-time"); const Pref* PREF_SEED_TIME = makePref("seed-time");
// values: 1*digit ['.' [ 1*digit ] ] // values: 1*digit ['.' [ 1*digit ] ]
const std::string PREF_SEED_RATIO("seed-ratio"); const Pref* PREF_SEED_RATIO = makePref("seed-ratio");
// values: 1*digit // values: 1*digit
const std::string PREF_BT_KEEP_ALIVE_INTERVAL("bt-keep-alive-interval"); const Pref* PREF_BT_KEEP_ALIVE_INTERVAL = makePref("bt-keep-alive-interval");
// values: a string, less than or equals to 20 bytes length // values: a string, less than or equals to 20 bytes length
const std::string PREF_PEER_ID_PREFIX("peer-id-prefix"); const Pref* PREF_PEER_ID_PREFIX = makePref("peer-id-prefix");
// values: true | false // values: true | false
const std::string PREF_ENABLE_PEER_EXCHANGE("enable-peer-exchange"); const Pref* PREF_ENABLE_PEER_EXCHANGE = makePref("enable-peer-exchange");
// values: true | false // values: true | false
const std::string PREF_ENABLE_DHT("enable-dht"); const Pref* PREF_ENABLE_DHT = makePref("enable-dht");
// values: a string // values: a string
const std::string PREF_DHT_LISTEN_ADDR("dht-listen-addr"); const Pref* PREF_DHT_LISTEN_ADDR = makePref("dht-listen-addr");
// values: 1*digit // values: 1*digit
const std::string PREF_DHT_LISTEN_PORT("dht-listen-port"); const Pref* PREF_DHT_LISTEN_PORT = makePref("dht-listen-port");
// values: a string // values: a string
const std::string PREF_DHT_ENTRY_POINT_HOST("dht-entry-point-host"); const Pref* PREF_DHT_ENTRY_POINT_HOST = makePref("dht-entry-point-host");
// values: 1*digit // values: 1*digit
const std::string PREF_DHT_ENTRY_POINT_PORT("dht-entry-point-port"); const Pref* PREF_DHT_ENTRY_POINT_PORT = makePref("dht-entry-point-port");
// values: a string (hostname:port); // values: a string = makePref(hostname:port);
const std::string PREF_DHT_ENTRY_POINT("dht-entry-point"); const Pref* PREF_DHT_ENTRY_POINT = makePref("dht-entry-point");
// values: a string // values: a string
const std::string PREF_DHT_FILE_PATH("dht-file-path"); const Pref* PREF_DHT_FILE_PATH = makePref("dht-file-path");
// values: true | false // values: true | false
const std::string PREF_ENABLE_DHT6("enable-dht6"); const Pref* PREF_ENABLE_DHT6 = makePref("enable-dht6");
// values: a string // values: a string
const std::string PREF_DHT_LISTEN_ADDR6("dht-listen-addr6"); const Pref* PREF_DHT_LISTEN_ADDR6 = makePref("dht-listen-addr6");
// values: a string // values: a string
const std::string PREF_DHT_ENTRY_POINT_HOST6("dht-entry-point-host6"); const Pref* PREF_DHT_ENTRY_POINT_HOST6 = makePref("dht-entry-point-host6");
// values: 1*digit // values: 1*digit
const std::string PREF_DHT_ENTRY_POINT_PORT6("dht-entry-point-port6"); const Pref* PREF_DHT_ENTRY_POINT_PORT6 = makePref("dht-entry-point-port6");
// values: a string (hostname:port) // values: a string = makePref(hostname:port)
const std::string PREF_DHT_ENTRY_POINT6("dht-entry-point6"); const Pref* PREF_DHT_ENTRY_POINT6 = makePref("dht-entry-point6");
// values: a string // values: a string
const std::string PREF_DHT_FILE_PATH6("dht-file-path6"); const Pref* PREF_DHT_FILE_PATH6 = makePref("dht-file-path6");
// values: plain | arc4 // values: plain | arc4
const std::string PREF_BT_MIN_CRYPTO_LEVEL("bt-min-crypto-level"); const Pref* PREF_BT_MIN_CRYPTO_LEVEL = makePref("bt-min-crypto-level");
const std::string V_PLAIN("plain");
const std::string V_ARC4("arc4");
// values:: true | false // values:: true | false
const std::string PREF_BT_REQUIRE_CRYPTO("bt-require-crypto"); const Pref* PREF_BT_REQUIRE_CRYPTO = makePref("bt-require-crypto");
// values: 1*digit // values: 1*digit
const std::string PREF_BT_REQUEST_PEER_SPEED_LIMIT("bt-request-peer-speed-limit"); const Pref* PREF_BT_REQUEST_PEER_SPEED_LIMIT = makePref("bt-request-peer-speed-limit");
// values: 1*digit // values: 1*digit
const std::string PREF_BT_MAX_OPEN_FILES("bt-max-open-files"); const Pref* PREF_BT_MAX_OPEN_FILES = makePref("bt-max-open-files");
// values: true | false // values: true | false
const std::string PREF_BT_SEED_UNVERIFIED("bt-seed-unverified"); const Pref* PREF_BT_SEED_UNVERIFIED = makePref("bt-seed-unverified");
// values: true | false // values: true | false
const std::string PREF_BT_HASH_CHECK_SEED("bt-hash-check-seed"); const Pref* PREF_BT_HASH_CHECK_SEED = makePref("bt-hash-check-seed");
// values: 1*digit // values: 1*digit
const std::string PREF_BT_MAX_PEERS("bt-max-peers"); const Pref* PREF_BT_MAX_PEERS = makePref("bt-max-peers");
// values: a string (IP address) // values: a string = makePref(IP address)
const std::string PREF_BT_EXTERNAL_IP("bt-external-ip"); const Pref* PREF_BT_EXTERNAL_IP = makePref("bt-external-ip");
// values: 1*digit '=' a string that your file system recognizes as a file name. // values: 1*digit '=' a string that your file system recognizes as a file name.
const std::string PREF_INDEX_OUT("index-out"); const Pref* PREF_INDEX_OUT = makePref("index-out");
// values: 1*digit // values: 1*digit
const std::string PREF_BT_TRACKER_INTERVAL("bt-tracker-interval"); const Pref* PREF_BT_TRACKER_INTERVAL = makePref("bt-tracker-interval");
// values: 1*digit // values: 1*digit
const std::string PREF_BT_STOP_TIMEOUT("bt-stop-timeout"); const Pref* PREF_BT_STOP_TIMEOUT = makePref("bt-stop-timeout");
// values: head[=SIZE]|tail[=SIZE], ... // values: head[=SIZE]|tail[=SIZE], ...
const std::string PREF_BT_PRIORITIZE_PIECE("bt-prioritize-piece"); const Pref* PREF_BT_PRIORITIZE_PIECE = makePref("bt-prioritize-piece");
// values: true | false // values: true | false
const std::string PREF_BT_SAVE_METADATA("bt-save-metadata"); const Pref* PREF_BT_SAVE_METADATA = makePref("bt-save-metadata");
// values: true | false // values: true | false
const std::string PREF_BT_METADATA_ONLY("bt-metadata-only"); const Pref* PREF_BT_METADATA_ONLY = makePref("bt-metadata-only");
// values: true | false // values: true | false
const std::string PREF_BT_ENABLE_LPD("bt-enable-lpd"); const Pref* PREF_BT_ENABLE_LPD = makePref("bt-enable-lpd");
// values: string // values: string
const std::string PREF_BT_LPD_INTERFACE("bt-lpd-interface"); const Pref* PREF_BT_LPD_INTERFACE = makePref("bt-lpd-interface");
// values: 1*digit // values: 1*digit
const std::string PREF_BT_TRACKER_TIMEOUT("bt-tracker-timeout"); const Pref* PREF_BT_TRACKER_TIMEOUT = makePref("bt-tracker-timeout");
// values: 1*digit // values: 1*digit
const std::string PREF_BT_TRACKER_CONNECT_TIMEOUT("bt-tracker-connect-timeout"); const Pref* PREF_BT_TRACKER_CONNECT_TIMEOUT = makePref("bt-tracker-connect-timeout");
// values: 1*digit // values: 1*digit
const std::string PREF_DHT_MESSAGE_TIMEOUT("dht-message-timeout"); const Pref* PREF_DHT_MESSAGE_TIMEOUT = makePref("dht-message-timeout");
// values: string // values: string
const std::string PREF_ON_BT_DOWNLOAD_COMPLETE("on-bt-download-complete"); const Pref* PREF_ON_BT_DOWNLOAD_COMPLETE = makePref("on-bt-download-complete");
// values: string // values: string
const std::string PREF_BT_TRACKER("bt-tracker"); const Pref* PREF_BT_TRACKER = makePref("bt-tracker");
// values: string // values: string
const std::string PREF_BT_EXCLUDE_TRACKER("bt-exclude-tracker"); const Pref* PREF_BT_EXCLUDE_TRACKER = makePref("bt-exclude-tracker");
/** /**
* Metalink related preferences * Metalink related preferences
*/ */
// values: a string that your file system recognizes as a file name. // values: a string that your file system recognizes as a file name.
const std::string PREF_METALINK_FILE("metalink-file"); const Pref* PREF_METALINK_FILE = makePref("metalink-file");
// values: a string // values: a string
const std::string PREF_METALINK_VERSION("metalink-version"); const Pref* PREF_METALINK_VERSION = makePref("metalink-version");
// values: a string // values: a string
const std::string PREF_METALINK_LANGUAGE("metalink-language"); const Pref* PREF_METALINK_LANGUAGE = makePref("metalink-language");
// values: a string // values: a string
const std::string PREF_METALINK_OS("metalink-os"); const Pref* PREF_METALINK_OS = makePref("metalink-os");
// values: a string // values: a string
const std::string PREF_METALINK_LOCATION("metalink-location"); const Pref* PREF_METALINK_LOCATION = makePref("metalink-location");
// values: 1*digit // values: 1*digit
const std::string PREF_METALINK_SERVERS("metalink-servers"); const Pref* PREF_METALINK_SERVERS = makePref("metalink-servers");
// values: true | false | mem // values: true | false | mem
const std::string PREF_FOLLOW_METALINK("follow-metalink"); const Pref* PREF_FOLLOW_METALINK = makePref("follow-metalink");
// values: http | https | ftp | none // values: http | https | ftp | none
const std::string PREF_METALINK_PREFERRED_PROTOCOL("metalink-preferred-protocol"); const Pref* PREF_METALINK_PREFERRED_PROTOCOL = makePref("metalink-preferred-protocol");
const std::string V_HTTP("http");
const std::string V_HTTPS("https");
const std::string V_FTP("ftp");
// values: true | false // values: true | false
const std::string PREF_METALINK_ENABLE_UNIQUE_PROTOCOL("metalink-enable-unique-protocol"); const Pref* PREF_METALINK_ENABLE_UNIQUE_PROTOCOL = makePref("metalink-enable-unique-protocol");
const std::string PREF_METALINK_BASE_URI("metalink-base-uri"); const Pref* PREF_METALINK_BASE_URI = makePref("metalink-base-uri");
} // namespace aria2 } // namespace aria2

View File

@ -40,6 +40,28 @@
namespace aria2 { namespace aria2 {
struct Pref {
Pref(const std::string& k, size_t i);
// Keyword, aka Option Name
std::string k;
// Option ID
size_t i;
};
namespace option {
// Returns the number of options.
size_t countOption();
// Returns Pref whose ID is id. id must be less than countOption().
const Pref* i2p(size_t id);
// Returns Pref whose keyword is k. If no such Pref is found, returns
// special null Pref whose ID is 0.
const Pref* k2p(const std::string& k);
} // namespace option
/** /**
* Constants * Constants
*/ */
@ -51,390 +73,393 @@ extern const std::string V_MEM;
extern const std::string V_ALL; extern const std::string V_ALL;
extern const std::string A2_V_FULL; extern const std::string A2_V_FULL;
extern const std::string A2_V_GEOM; extern const std::string A2_V_GEOM;
/**
* General preferences
*/
// values: 1*digit
extern const std::string PREF_TIMEOUT;
// values: 1*digit
extern const std::string PREF_DNS_TIMEOUT;
// values: 1*digit
extern const std::string PREF_CONNECT_TIMEOUT;
// values: 1*digit
extern const std::string PREF_MAX_TRIES;
// values: 1*digit
extern const std::string PREF_AUTO_SAVE_INTERVAL;
// values: a string that your file system recognizes as a file name.
extern const std::string PREF_LOG;
// values: a string that your file system recognizes as a directory.
extern const std::string PREF_DIR;
// values: a string that your file system recognizes as a file name.
extern const std::string PREF_OUT;
// values: 1*digit
extern const std::string PREF_SPLIT;
// value: true | false
extern const std::string PREF_DAEMON;
// value: a string
extern const std::string PREF_REFERER;
// value: 1*digit
extern const std::string PREF_LOWEST_SPEED_LIMIT;
// value: 1*digit
extern const std::string PREF_PIECE_LENGTH;
// value: 1*digit
extern const std::string PREF_MAX_DOWNLOAD_LIMIT;
// value: 1*digit
extern const std::string PREF_STARTUP_IDLE_TIME;
// value: prealloc | falloc | none
extern const std::string PREF_FILE_ALLOCATION;
extern const std::string V_PREALLOC; extern const std::string V_PREALLOC;
extern const std::string V_FALLOC; extern const std::string V_FALLOC;
// value: 1*digit
extern const std::string PREF_NO_FILE_ALLOCATION_LIMIT;
// value: true | false
extern const std::string PREF_ALLOW_OVERWRITE;
// value: true | false
extern const std::string PREF_REALTIME_CHUNK_CHECKSUM;
// value: true | false
extern const std::string PREF_CHECK_INTEGRITY;
// value: string that your file system recognizes as a file name.
extern const std::string PREF_NETRC_PATH;
// value:
extern const std::string PREF_CONTINUE;
// value:
extern const std::string PREF_NO_NETRC;
// value: 1*digit
extern const std::string PREF_MAX_OVERALL_DOWNLOAD_LIMIT;
// value: 1*digit
extern const std::string PREF_MAX_DOWNLOADS;
// value: string that your file system recognizes as a file name.
extern const std::string PREF_INPUT_FILE;
// value: 1*digit
extern const std::string PREF_MAX_CONCURRENT_DOWNLOADS;
// value: true | false
extern const std::string PREF_FORCE_SEQUENTIAL;
// value: true | false
extern const std::string PREF_AUTO_FILE_RENAMING;
// value: true | false
extern const std::string PREF_PARAMETERIZED_URI;
// value: true | false
extern const std::string PREF_ENABLE_DIRECT_IO;
// value: true | false
extern const std::string PREF_ALLOW_PIECE_LENGTH_CHANGE;
// value: true | false
extern const std::string PREF_NO_CONF;
// value: string
extern const std::string PREF_CONF_PATH;
// value: 1*digit
extern const std::string PREF_STOP;
// value: true | false
extern const std::string PREF_QUIET;
// value: true | false
extern const std::string PREF_ASYNC_DNS;
// value: 1*digit
extern const std::string PREF_SUMMARY_INTERVAL;
// value: debug, info, notice, warn, error
extern const std::string PREF_LOG_LEVEL;
extern const std::string V_DEBUG; extern const std::string V_DEBUG;
extern const std::string V_INFO; extern const std::string V_INFO;
extern const std::string V_NOTICE; extern const std::string V_NOTICE;
extern const std::string V_WARN; extern const std::string V_WARN;
extern const std::string V_ERROR; extern const std::string V_ERROR;
// value: inorder | feedback | adaptive
extern const std::string PREF_URI_SELECTOR;
extern const std::string V_INORDER; extern const std::string V_INORDER;
extern const std::string V_FEEDBACK; extern const std::string V_FEEDBACK;
extern const std::string V_ADAPTIVE; extern const std::string V_ADAPTIVE;
// value: 1*digit
extern const std::string PREF_SERVER_STAT_TIMEOUT;
// value: string that your file system recognizes as a file name.
extern const std::string PREF_SERVER_STAT_IF;
// value: string that your file system recognizes as a file name.
extern const std::string PREF_SERVER_STAT_OF;
// value: true | false
extern const std::string PREF_REMOTE_TIME;
// value: 1*digit
extern const std::string PREF_MAX_FILE_NOT_FOUND;
// value: epoll | select
extern const std::string PREF_EVENT_POLL;
extern const std::string V_EPOLL; extern const std::string V_EPOLL;
extern const std::string V_KQUEUE; extern const std::string V_KQUEUE;
extern const std::string V_PORT; extern const std::string V_PORT;
extern const std::string V_POLL; extern const std::string V_POLL;
extern const std::string V_SELECT; extern const std::string V_SELECT;
extern const std::string V_BINARY;
extern const std::string V_ASCII;
extern const std::string V_GET;
extern const std::string V_TUNNEL;
extern const std::string V_PLAIN;
extern const std::string V_ARC4;
extern const std::string V_HTTP;
extern const std::string V_HTTPS;
extern const std::string V_FTP;
extern const Pref* PREF_VERSION;
extern const Pref* PREF_HELP;
/**
* General preferences
*/
// values: 1*digit
extern const Pref* PREF_TIMEOUT;
// values: 1*digit
extern const Pref* PREF_DNS_TIMEOUT;
// values: 1*digit
extern const Pref* PREF_CONNECT_TIMEOUT;
// values: 1*digit
extern const Pref* PREF_MAX_TRIES;
// values: 1*digit
extern const Pref* PREF_AUTO_SAVE_INTERVAL;
// values: a string that your file system recognizes as a file name.
extern const Pref* PREF_LOG;
// values: a string that your file system recognizes as a directory.
extern const Pref* PREF_DIR;
// values: a string that your file system recognizes as a file name.
extern const Pref* PREF_OUT;
// values: 1*digit
extern const Pref* PREF_SPLIT;
// value: true | false // value: true | false
extern const std::string PREF_ENABLE_RPC; extern const Pref* PREF_DAEMON;
// value: a string
extern const Pref* PREF_REFERER;
// value: 1*digit // value: 1*digit
extern const std::string PREF_RPC_LISTEN_PORT; extern const Pref* PREF_LOWEST_SPEED_LIMIT;
// value: string
extern const std::string PREF_RPC_USER;
// value: string
extern const std::string PREF_RPC_PASSWD;
// value: 1*digit // value: 1*digit
extern const std::string PREF_RPC_MAX_REQUEST_SIZE; extern const Pref* PREF_PIECE_LENGTH;
// value: true | false
extern const std::string PREF_RPC_LISTEN_ALL;
// value: true | false
extern const std::string PREF_RPC_ALLOW_ORIGIN_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: string
extern const std::string PREF_INTERFACE;
// value: true | false
extern const std::string PREF_DISABLE_IPV6;
// value: true | false
extern const std::string PREF_HUMAN_READABLE;
// value: true | false
extern const std::string PREF_REMOVE_CONTROL_FILE;
// value: true | false
extern const std::string PREF_ALWAYS_RESUME;
// value: 1*digit // value: 1*digit
extern const std::string PREF_MAX_RESUME_FAILURE_TRIES; extern const Pref* PREF_MAX_DOWNLOAD_LIMIT;
// value: 1*digit
extern const Pref* PREF_STARTUP_IDLE_TIME;
// value: prealloc | falloc | none
extern const Pref* PREF_FILE_ALLOCATION;
// value: 1*digit
extern const Pref* PREF_NO_FILE_ALLOCATION_LIMIT;
// value: true | false
extern const Pref* PREF_ALLOW_OVERWRITE;
// value: true | false
extern const Pref* PREF_REALTIME_CHUNK_CHECKSUM;
// value: true | false
extern const Pref* PREF_CHECK_INTEGRITY;
// value: string that your file system recognizes as a file name. // value: string that your file system recognizes as a file name.
extern const std::string PREF_SAVE_SESSION; extern const Pref* PREF_NETRC_PATH;
// value:
extern const Pref* PREF_CONTINUE;
// value:
extern const Pref* PREF_NO_NETRC;
// value: 1*digit // value: 1*digit
extern const std::string PREF_MAX_CONNECTION_PER_SERVER; extern const Pref* PREF_MAX_OVERALL_DOWNLOAD_LIMIT;
// value: 1*digit // value: 1*digit
extern const std::string PREF_MIN_SPLIT_SIZE; extern const Pref* PREF_MAX_DOWNLOADS;
// value: string that your file system recognizes as a file name.
extern const Pref* PREF_INPUT_FILE;
// value: 1*digit
extern const Pref* PREF_MAX_CONCURRENT_DOWNLOADS;
// value: true | false // value: true | false
extern const std::string PREF_CONDITIONAL_GET; extern const Pref* PREF_FORCE_SEQUENTIAL;
// value: true | false // value: true | false
extern const std::string PREF_SELECT_LEAST_USED_HOST; extern const Pref* PREF_AUTO_FILE_RENAMING;
// value: true | false // value: true | false
extern const std::string PREF_ENABLE_ASYNC_DNS6; extern const Pref* PREF_PARAMETERIZED_URI;
// value: 1*digit // value: true | false
extern const std::string PREF_MAX_DOWNLOAD_RESULT; extern const Pref* PREF_ENABLE_DIRECT_IO;
// value: 1*digit // value: true | false
extern const std::string PREF_RETRY_WAIT; extern const Pref* PREF_ALLOW_PIECE_LENGTH_CHANGE;
// value: true | false
extern const Pref* PREF_NO_CONF;
// value: string // value: string
extern const std::string PREF_ASYNC_DNS_SERVER; extern const Pref* PREF_CONF_PATH;
// value: 1*digit
extern const Pref* PREF_STOP;
// value: true | false // value: true | false
extern const std::string PREF_SHOW_CONSOLE_READOUT; extern const Pref* PREF_QUIET;
// value: true | false
extern const Pref* PREF_ASYNC_DNS;
// value: 1*digit
extern const Pref* PREF_SUMMARY_INTERVAL;
// value: debug, info, notice, warn, error
extern const Pref* PREF_LOG_LEVEL;
// value: inorder | feedback | adaptive
extern const Pref* PREF_URI_SELECTOR;
// value: 1*digit
extern const Pref* PREF_SERVER_STAT_TIMEOUT;
// value: string that your file system recognizes as a file name.
extern const Pref* PREF_SERVER_STAT_IF;
// value: string that your file system recognizes as a file name.
extern const Pref* PREF_SERVER_STAT_OF;
// value: true | false
extern const Pref* PREF_REMOTE_TIME;
// value: 1*digit
extern const Pref* PREF_MAX_FILE_NOT_FOUND;
// value: epoll | select
extern const Pref* PREF_EVENT_POLL;
// value: true | false
extern const Pref* PREF_ENABLE_RPC;
// value: 1*digit
extern const Pref* PREF_RPC_LISTEN_PORT;
// value: string
extern const Pref* PREF_RPC_USER;
// value: string
extern const Pref* PREF_RPC_PASSWD;
// value: 1*digit
extern const Pref* PREF_RPC_MAX_REQUEST_SIZE;
// value: true | false
extern const Pref* PREF_RPC_LISTEN_ALL;
// value: true | false
extern const Pref* PREF_RPC_ALLOW_ORIGIN_ALL;
// value: true | false
extern const Pref* PREF_DRY_RUN;
// value: true | false
extern const Pref* PREF_REUSE_URI;
// value: string
extern const Pref* PREF_ON_DOWNLOAD_START;
extern const Pref* PREF_ON_DOWNLOAD_PAUSE;
extern const Pref* PREF_ON_DOWNLOAD_STOP;
extern const Pref* PREF_ON_DOWNLOAD_COMPLETE;
extern const Pref* PREF_ON_DOWNLOAD_ERROR;
// value: string
extern const Pref* PREF_INTERFACE;
// value: true | false
extern const Pref* PREF_DISABLE_IPV6;
// value: true | false
extern const Pref* PREF_HUMAN_READABLE;
// value: true | false
extern const Pref* PREF_REMOVE_CONTROL_FILE;
// value: true | false
extern const Pref* PREF_ALWAYS_RESUME;
// value: 1*digit
extern const Pref* PREF_MAX_RESUME_FAILURE_TRIES;
// value: string that your file system recognizes as a file name.
extern const Pref* PREF_SAVE_SESSION;
// value: 1*digit
extern const Pref* PREF_MAX_CONNECTION_PER_SERVER;
// value: 1*digit
extern const Pref* PREF_MIN_SPLIT_SIZE;
// value: true | false
extern const Pref* PREF_CONDITIONAL_GET;
// value: true | false
extern const Pref* PREF_SELECT_LEAST_USED_HOST;
// value: true | false
extern const Pref* PREF_ENABLE_ASYNC_DNS6;
// value: 1*digit
extern const Pref* PREF_MAX_DOWNLOAD_RESULT;
// value: 1*digit
extern const Pref* PREF_RETRY_WAIT;
// value: string
extern const Pref* PREF_ASYNC_DNS_SERVER;
// value: true | false
extern const Pref* PREF_SHOW_CONSOLE_READOUT;
// value: default | inorder | geom // value: default | inorder | geom
extern const std::string PREF_STREAM_PIECE_SELECTOR; extern const Pref* PREF_STREAM_PIECE_SELECTOR;
// value: true | false // value: true | false
extern const std::string PREF_TRUNCATE_CONSOLE_READOUT; extern const Pref* PREF_TRUNCATE_CONSOLE_READOUT;
// value: true | false // value: true | false
extern const std::string PREF_PAUSE; extern const Pref* PREF_PAUSE;
// value: default | full // value: default | full
extern const std::string PREF_DOWNLOAD_RESULT; extern const Pref* PREF_DOWNLOAD_RESULT;
// value: true | false // value: true | false
extern const std::string PREF_HASH_CHECK_ONLY; extern const Pref* PREF_HASH_CHECK_ONLY;
/** /**
* FTP related preferences * FTP related preferences
*/ */
extern const std::string PREF_FTP_USER; extern const Pref* PREF_FTP_USER;
extern const std::string PREF_FTP_PASSWD; extern const Pref* PREF_FTP_PASSWD;
// values: binary | ascii // values: binary | ascii
extern const std::string PREF_FTP_TYPE; extern const Pref* PREF_FTP_TYPE;
extern const std::string V_BINARY;
extern const std::string V_ASCII;
// values: true | false // values: true | false
extern const std::string PREF_FTP_PASV; extern const Pref* PREF_FTP_PASV;
// values: true | false // values: true | false
extern const std::string PREF_FTP_REUSE_CONNECTION; extern const Pref* PREF_FTP_REUSE_CONNECTION;
// values: hashType=digest // values: hashType=digest
extern const std::string PREF_CHECKSUM; extern const Pref* PREF_CHECKSUM;
/** /**
* HTTP related preferences * HTTP related preferences
*/ */
extern const std::string PREF_HTTP_USER; extern const Pref* PREF_HTTP_USER;
extern const std::string PREF_HTTP_PASSWD; extern const Pref* PREF_HTTP_PASSWD;
// values: string // values: string
extern const std::string PREF_USER_AGENT; extern const Pref* PREF_USER_AGENT;
// value: string that your file system recognizes as a file name. // value: string that your file system recognizes as a file name.
extern const std::string PREF_LOAD_COOKIES; extern const Pref* PREF_LOAD_COOKIES;
// value: string that your file system recognizes as a file name. // value: string that your file system recognizes as a file name.
extern const std::string PREF_SAVE_COOKIES; extern const Pref* PREF_SAVE_COOKIES;
// values: true | false // values: true | false
extern const std::string PREF_ENABLE_HTTP_KEEP_ALIVE; extern const Pref* PREF_ENABLE_HTTP_KEEP_ALIVE;
// values: true | false // values: true | false
extern const std::string PREF_ENABLE_HTTP_PIPELINING; extern const Pref* PREF_ENABLE_HTTP_PIPELINING;
// value: 1*digit // value: 1*digit
extern const std::string PREF_MAX_HTTP_PIPELINING; extern const Pref* PREF_MAX_HTTP_PIPELINING;
// value: string // value: string
extern const std::string PREF_HEADER; extern const Pref* PREF_HEADER;
// value: string that your file system recognizes as a file name. // value: string that your file system recognizes as a file name.
extern const std::string PREF_CERTIFICATE; extern const Pref* PREF_CERTIFICATE;
// value: string that your file system recognizes as a file name. // value: string that your file system recognizes as a file name.
extern const std::string PREF_PRIVATE_KEY; extern const Pref* PREF_PRIVATE_KEY;
// value: string that your file system recognizes as a file name. // value: string that your file system recognizes as a file name.
extern const std::string PREF_CA_CERTIFICATE; extern const Pref* PREF_CA_CERTIFICATE;
// value: true | false // value: true | false
extern const std::string PREF_CHECK_CERTIFICATE; extern const Pref* PREF_CHECK_CERTIFICATE;
// value: true | false // value: true | false
extern const std::string PREF_USE_HEAD; extern const Pref* PREF_USE_HEAD;
// value: true | false // value: true | false
extern const std::string PREF_HTTP_AUTH_CHALLENGE; extern const Pref* PREF_HTTP_AUTH_CHALLENGE;
// value: true | false // value: true | false
extern const std::string PREF_HTTP_NO_CACHE; extern const Pref* PREF_HTTP_NO_CACHE;
// value: true | false // value: true | false
extern const std::string PREF_HTTP_ACCEPT_GZIP; extern const Pref* PREF_HTTP_ACCEPT_GZIP;
/**; /**;
* Proxy related preferences * Proxy related preferences
*/ */
extern const std::string PREF_HTTP_PROXY; extern const Pref* PREF_HTTP_PROXY;
extern const std::string PREF_HTTPS_PROXY; extern const Pref* PREF_HTTPS_PROXY;
extern const std::string PREF_FTP_PROXY; extern const Pref* PREF_FTP_PROXY;
extern const std::string PREF_ALL_PROXY; extern const Pref* PREF_ALL_PROXY;
// values: comma separeted hostname or domain // values: comma separeted hostname or domain
extern const std::string PREF_NO_PROXY; extern const Pref* PREF_NO_PROXY;
// values: get | tunnel // values: get | tunnel
extern const std::string PREF_PROXY_METHOD; extern const Pref* PREF_PROXY_METHOD;
extern const std::string V_GET; extern const Pref* PREF_HTTP_PROXY_USER;
extern const std::string V_TUNNEL; extern const Pref* PREF_HTTP_PROXY_PASSWD;
extern const std::string PREF_HTTP_PROXY_USER; extern const Pref* PREF_HTTPS_PROXY_USER;
extern const std::string PREF_HTTP_PROXY_PASSWD; extern const Pref* PREF_HTTPS_PROXY_PASSWD;
extern const std::string PREF_HTTPS_PROXY_USER; extern const Pref* PREF_FTP_PROXY_USER;
extern const std::string PREF_HTTPS_PROXY_PASSWD; extern const Pref* PREF_FTP_PROXY_PASSWD;
extern const std::string PREF_FTP_PROXY_USER; extern const Pref* PREF_ALL_PROXY_USER;
extern const std::string PREF_FTP_PROXY_PASSWD; extern const Pref* PREF_ALL_PROXY_PASSWD;
extern const std::string PREF_ALL_PROXY_USER;
extern const std::string PREF_ALL_PROXY_PASSWD;
/** /**
* BitTorrent related preferences * BitTorrent related preferences
*/ */
// values: 1*digit // values: 1*digit
extern const std::string PREF_PEER_CONNECTION_TIMEOUT; extern const Pref* PREF_PEER_CONNECTION_TIMEOUT;
// values: 1*digit // values: 1*digit
extern const std::string PREF_BT_TIMEOUT; extern const Pref* PREF_BT_TIMEOUT;
// values: 1*digit // values: 1*digit
extern const std::string PREF_BT_REQUEST_TIMEOUT; extern const Pref* PREF_BT_REQUEST_TIMEOUT;
// values: true | false // values: true | false
extern const std::string PREF_SHOW_FILES; extern const Pref* PREF_SHOW_FILES;
// values: 1*digit // values: 1*digit
extern const std::string PREF_MAX_OVERALL_UPLOAD_LIMIT; extern const Pref* PREF_MAX_OVERALL_UPLOAD_LIMIT;
// values: 1*digit // values: 1*digit
extern const std::string PREF_MAX_UPLOAD_LIMIT; extern const Pref* PREF_MAX_UPLOAD_LIMIT;
// values: a string that your file system recognizes as a file name. // values: a string that your file system recognizes as a file name.
extern const std::string PREF_TORRENT_FILE; extern const Pref* PREF_TORRENT_FILE;
// values: 1*digit // values: 1*digit
extern const std::string PREF_LISTEN_PORT; extern const Pref* PREF_LISTEN_PORT;
// values: true | false | mem // values: true | false | mem
extern const std::string PREF_FOLLOW_TORRENT; extern const Pref* PREF_FOLLOW_TORRENT;
// values: 1*digit *( (,|-) 1*digit) // values: 1*digit *( (,|-) 1*digit)
extern const std::string PREF_SELECT_FILE; extern const Pref* PREF_SELECT_FILE;
// values: 1*digit // values: 1*digit
extern const std::string PREF_SEED_TIME; extern const Pref* PREF_SEED_TIME;
// values: 1*digit ['.' [ 1*digit ] ] // values: 1*digit ['.' [ 1*digit ] ]
extern const std::string PREF_SEED_RATIO; extern const Pref* PREF_SEED_RATIO;
// values: 1*digit // values: 1*digit
extern const std::string PREF_BT_KEEP_ALIVE_INTERVAL; extern const Pref* PREF_BT_KEEP_ALIVE_INTERVAL;
// values: a string, less than or equals to 20 bytes length // values: a string, less than or equals to 20 bytes length
extern const std::string PREF_PEER_ID_PREFIX; extern const Pref* PREF_PEER_ID_PREFIX;
// values: true | false // values: true | false
extern const std::string PREF_ENABLE_PEER_EXCHANGE; extern const Pref* PREF_ENABLE_PEER_EXCHANGE;
// values: true | false // values: true | false
extern const std::string PREF_ENABLE_DHT; extern const Pref* PREF_ENABLE_DHT;
// values: a string // values: a string
extern const std::string PREF_DHT_LISTEN_ADDR; extern const Pref* PREF_DHT_LISTEN_ADDR;
// values: 1*digit // values: 1*digit
extern const std::string PREF_DHT_LISTEN_PORT; extern const Pref* PREF_DHT_LISTEN_PORT;
// values: a string // values: a string
extern const std::string PREF_DHT_ENTRY_POINT_HOST; extern const Pref* PREF_DHT_ENTRY_POINT_HOST;
// values: 1*digit // values: 1*digit
extern const std::string PREF_DHT_ENTRY_POINT_PORT; extern const Pref* PREF_DHT_ENTRY_POINT_PORT;
// values: a string (hostname:port) // values: a string (hostname:port)
extern const std::string PREF_DHT_ENTRY_POINT; extern const Pref* PREF_DHT_ENTRY_POINT;
// values: a string // values: a string
extern const std::string PREF_DHT_FILE_PATH; extern const Pref* PREF_DHT_FILE_PATH;
// values: true | false // values: true | false
extern const std::string PREF_ENABLE_DHT6; extern const Pref* PREF_ENABLE_DHT6;
// values: a string // values: a string
extern const std::string PREF_DHT_LISTEN_ADDR6; extern const Pref* PREF_DHT_LISTEN_ADDR6;
// values: a string // values: a string
extern const std::string PREF_DHT_ENTRY_POINT_HOST6; extern const Pref* PREF_DHT_ENTRY_POINT_HOST6;
// values: 1*digit // values: 1*digit
extern const std::string PREF_DHT_ENTRY_POINT_PORT6; extern const Pref* PREF_DHT_ENTRY_POINT_PORT6;
// values: a string (hostname:port) // values: a string (hostname:port)
extern const std::string PREF_DHT_ENTRY_POINT6; extern const Pref* PREF_DHT_ENTRY_POINT6;
// values: a string // values: a string
extern const std::string PREF_DHT_FILE_PATH6; extern const Pref* PREF_DHT_FILE_PATH6;
// values: plain | arc4 // values: plain | arc4
extern const std::string PREF_BT_MIN_CRYPTO_LEVEL; extern const Pref* PREF_BT_MIN_CRYPTO_LEVEL;
extern const std::string V_PLAIN;
extern const std::string V_ARC4;
// values:: true | false // values:: true | false
extern const std::string PREF_BT_REQUIRE_CRYPTO; extern const Pref* PREF_BT_REQUIRE_CRYPTO;
// values: 1*digit // values: 1*digit
extern const std::string PREF_BT_REQUEST_PEER_SPEED_LIMIT; extern const Pref* PREF_BT_REQUEST_PEER_SPEED_LIMIT;
// values: 1*digit // values: 1*digit
extern const std::string PREF_BT_MAX_OPEN_FILES; extern const Pref* PREF_BT_MAX_OPEN_FILES;
// values: true | false // values: true | false
extern const std::string PREF_BT_SEED_UNVERIFIED; extern const Pref* PREF_BT_SEED_UNVERIFIED;
// values: true | false // values: true | false
extern const std::string PREF_BT_HASH_CHECK_SEED; extern const Pref* PREF_BT_HASH_CHECK_SEED;
// values: 1*digit // values: 1*digit
extern const std::string PREF_BT_MAX_PEERS; extern const Pref* PREF_BT_MAX_PEERS;
// values: a string (IP address) // values: a string (IP address)
extern const std::string PREF_BT_EXTERNAL_IP; extern const Pref* PREF_BT_EXTERNAL_IP;
// values: 1*digit '=' a string that your file system recognizes as a file name. // values: 1*digit '=' a string that your file system recognizes as a file name.
extern const std::string PREF_INDEX_OUT; extern const Pref* PREF_INDEX_OUT;
// values: 1*digit // values: 1*digit
extern const std::string PREF_BT_TRACKER_INTERVAL; extern const Pref* PREF_BT_TRACKER_INTERVAL;
// values: 1*digit // values: 1*digit
extern const std::string PREF_BT_STOP_TIMEOUT; extern const Pref* PREF_BT_STOP_TIMEOUT;
// values: head[=SIZE]|tail[=SIZE], ... // values: head[=SIZE]|tail[=SIZE], ...
extern const std::string PREF_BT_PRIORITIZE_PIECE; extern const Pref* PREF_BT_PRIORITIZE_PIECE;
// values: true | false // values: true | false
extern const std::string PREF_BT_SAVE_METADATA; extern const Pref* PREF_BT_SAVE_METADATA;
// values: true | false // values: true | false
extern const std::string PREF_BT_METADATA_ONLY; extern const Pref* PREF_BT_METADATA_ONLY;
// values: true | false // values: true | false
extern const std::string PREF_BT_ENABLE_LPD; extern const Pref* PREF_BT_ENABLE_LPD;
// values: string // values: string
extern const std::string PREF_BT_LPD_INTERFACE; extern const Pref* PREF_BT_LPD_INTERFACE;
// values: 1*digit // values: 1*digit
extern const std::string PREF_BT_TRACKER_TIMEOUT; extern const Pref* PREF_BT_TRACKER_TIMEOUT;
// values: 1*digit // values: 1*digit
extern const std::string PREF_BT_TRACKER_CONNECT_TIMEOUT; extern const Pref* PREF_BT_TRACKER_CONNECT_TIMEOUT;
// values: 1*digit // values: 1*digit
extern const std::string PREF_DHT_MESSAGE_TIMEOUT; extern const Pref* PREF_DHT_MESSAGE_TIMEOUT;
// values: string // values: string
extern const std::string PREF_ON_BT_DOWNLOAD_COMPLETE; extern const Pref* PREF_ON_BT_DOWNLOAD_COMPLETE;
// values: string // values: string
extern const std::string PREF_BT_TRACKER; extern const Pref* PREF_BT_TRACKER;
// values: string // values: string
extern const std::string PREF_BT_EXCLUDE_TRACKER; extern const Pref* PREF_BT_EXCLUDE_TRACKER;
/** /**
* Metalink related preferences * Metalink related preferences
*/ */
// values: a string that your file system recognizes as a file name. // values: a string that your file system recognizes as a file name.
extern const std::string PREF_METALINK_FILE; extern const Pref* PREF_METALINK_FILE;
// values: a string // values: a string
extern const std::string PREF_METALINK_VERSION; extern const Pref* PREF_METALINK_VERSION;
// values: a string // values: a string
extern const std::string PREF_METALINK_LANGUAGE; extern const Pref* PREF_METALINK_LANGUAGE;
// values: a string // values: a string
extern const std::string PREF_METALINK_OS; extern const Pref* PREF_METALINK_OS;
// values: a string // values: a string
extern const std::string PREF_METALINK_LOCATION; extern const Pref* PREF_METALINK_LOCATION;
// values: 1*digit // values: 1*digit
extern const std::string PREF_METALINK_SERVERS; extern const Pref* PREF_METALINK_SERVERS;
// values: true | false | mem // values: true | false | mem
extern const std::string PREF_FOLLOW_METALINK; extern const Pref* PREF_FOLLOW_METALINK;
// values: http | https | ftp | none // values: http | https | ftp | none
extern const std::string PREF_METALINK_PREFERRED_PROTOCOL; extern const Pref* PREF_METALINK_PREFERRED_PROTOCOL;
extern const std::string V_HTTP;
extern const std::string V_HTTPS;
extern const std::string V_FTP;
// values: true | false // values: true | false
extern const std::string PREF_METALINK_ENABLE_UNIQUE_PROTOCOL; extern const Pref* PREF_METALINK_ENABLE_UNIQUE_PROTOCOL;
// values: a string // values: a string
extern const std::string PREF_METALINK_BASE_URI; extern const Pref* PREF_METALINK_BASE_URI;
} // namespace aria2 } // namespace aria2

View File

@ -71,6 +71,7 @@
#include "DownloadContext.h" #include "DownloadContext.h"
#include "BufferedFile.h" #include "BufferedFile.h"
#include "SocketCore.h" #include "SocketCore.h"
#include "prefs.h"
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
# include "MessageDigest.h" # include "MessageDigest.h"
@ -1698,15 +1699,16 @@ void executeHook
void executeHookByOptName void executeHookByOptName
(const SharedHandle<RequestGroup>& group, const Option* option, (const SharedHandle<RequestGroup>& group, const Option* option,
const std::string& opt) const Pref* pref)
{ {
executeHookByOptName(group.get(), option, opt); executeHookByOptName(group.get(), option, pref);
} }
void executeHookByOptName void executeHookByOptName
(const RequestGroup* group, const Option* option, const std::string& opt) (const RequestGroup* group, const Option* option, const Pref* pref)
{ {
if(!option->blank(opt)) { const std::string& cmd = option->get(pref);
if(!cmd.empty()) {
const SharedHandle<DownloadContext> dctx = group->getDownloadContext(); const SharedHandle<DownloadContext> dctx = group->getDownloadContext();
std::string firstFilename; std::string firstFilename;
size_t numFiles = 0; size_t numFiles = 0;
@ -1717,7 +1719,7 @@ void executeHookByOptName
} }
numFiles = dctx->countRequestedFileEntry(); numFiles = dctx->countRequestedFileEntry();
} }
executeHook(option->get(opt), group->getGID(), numFiles, firstFilename); executeHook(cmd, group->getGID(), numFiles, firstFilename);
} }
} }

View File

@ -64,6 +64,7 @@ class BinaryStream;
class FileEntry; class FileEntry;
class RequestGroup; class RequestGroup;
class Option; class Option;
class Pref;
#define STRTOLL(X) strtoll(X, reinterpret_cast<char**>(0), 10) #define STRTOLL(X) strtoll(X, reinterpret_cast<char**>(0), 10)
#define STRTOULL(X) strtoull(X, reinterpret_cast<char**>(0), 10) #define STRTOULL(X) strtoull(X, reinterpret_cast<char**>(0), 10)
@ -441,11 +442,11 @@ void removeMetalinkContentTypes(RequestGroup* group);
// No throw // No throw
void executeHookByOptName void executeHookByOptName
(const SharedHandle<RequestGroup>& group, const Option* option, (const SharedHandle<RequestGroup>& group, const Option* option,
const std::string& opt); const Pref* pref);
// No throw // No throw
void executeHookByOptName void executeHookByOptName
(const RequestGroup* group, const Option* option, const std::string& opt); (const RequestGroup* group, const Option* option, const Pref* pref);
std::string createSafePath(const std::string& dir, const std::string& filename); std::string createSafePath(const std::string& dir, const std::string& filename);

View File

@ -63,19 +63,19 @@ void OptionHandlerTest::testNullOptionHandler()
CPPUNIT_ASSERT(handler.canHandle("foo")); CPPUNIT_ASSERT(handler.canHandle("foo"));
Option option; Option option;
handler.parse(option, "bar"); handler.parse(option, "bar");
CPPUNIT_ASSERT(!option.defined("bar")); CPPUNIT_ASSERT(!option.defined(PREF_TIMEOUT));
} }
void OptionHandlerTest::testBooleanOptionHandler() void OptionHandlerTest::testBooleanOptionHandler()
{ {
BooleanOptionHandler handler("foo"); BooleanOptionHandler handler(PREF_DAEMON);
CPPUNIT_ASSERT(handler.canHandle("foo")); CPPUNIT_ASSERT(handler.canHandle(PREF_DAEMON->k));
CPPUNIT_ASSERT(!handler.canHandle("foobar")); CPPUNIT_ASSERT(!handler.canHandle(PREF_DIR->k));
Option option; Option option;
handler.parse(option, A2_V_TRUE); handler.parse(option, A2_V_TRUE);
CPPUNIT_ASSERT_EQUAL(std::string(A2_V_TRUE), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string(A2_V_TRUE), option.get(PREF_DAEMON));
handler.parse(option, A2_V_FALSE); handler.parse(option, A2_V_FALSE);
CPPUNIT_ASSERT_EQUAL(std::string(A2_V_FALSE), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string(A2_V_FALSE), option.get(PREF_DAEMON));
try { try {
handler.parse(option, "hello"); handler.parse(option, "hello");
CPPUNIT_FAIL("exception must be thrown."); CPPUNIT_FAIL("exception must be thrown.");
@ -86,22 +86,22 @@ void OptionHandlerTest::testBooleanOptionHandler()
void OptionHandlerTest::testNumberOptionHandler() void OptionHandlerTest::testNumberOptionHandler()
{ {
NumberOptionHandler handler("foo"); NumberOptionHandler handler(PREF_TIMEOUT);
CPPUNIT_ASSERT(handler.canHandle("foo")); CPPUNIT_ASSERT(handler.canHandle(PREF_TIMEOUT->k));
CPPUNIT_ASSERT(!handler.canHandle("foobar")); CPPUNIT_ASSERT(!handler.canHandle(PREF_DIR->k));
Option option; Option option;
handler.parse(option, "0"); handler.parse(option, "0");
CPPUNIT_ASSERT_EQUAL(std::string("0"), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string("0"), option.get(PREF_TIMEOUT));
CPPUNIT_ASSERT_EQUAL(std::string("*-*"), CPPUNIT_ASSERT_EQUAL(std::string("*-*"),
handler.createPossibleValuesString()); handler.createPossibleValuesString());
} }
void OptionHandlerTest::testNumberOptionHandler_min() void OptionHandlerTest::testNumberOptionHandler_min()
{ {
NumberOptionHandler handler("foo", "", "", 1); NumberOptionHandler handler(PREF_TIMEOUT, "", "", 1);
Option option; Option option;
handler.parse(option, "1"); handler.parse(option, "1");
CPPUNIT_ASSERT_EQUAL(std::string("1"), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string("1"), option.get(PREF_TIMEOUT));
try { try {
handler.parse(option, "0"); handler.parse(option, "0");
CPPUNIT_FAIL("exception must be thrown."); CPPUNIT_FAIL("exception must be thrown.");
@ -112,10 +112,10 @@ void OptionHandlerTest::testNumberOptionHandler_min()
void OptionHandlerTest::testNumberOptionHandler_max() void OptionHandlerTest::testNumberOptionHandler_max()
{ {
NumberOptionHandler handler("foo", "", "", -1, 100); NumberOptionHandler handler(PREF_TIMEOUT, "", "", -1, 100);
Option option; Option option;
handler.parse(option, "100"); handler.parse(option, "100");
CPPUNIT_ASSERT_EQUAL(std::string("100"), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string("100"), option.get(PREF_TIMEOUT));
try { try {
handler.parse(option, "101"); handler.parse(option, "101");
CPPUNIT_FAIL("exception must be thrown."); CPPUNIT_FAIL("exception must be thrown.");
@ -126,12 +126,12 @@ void OptionHandlerTest::testNumberOptionHandler_max()
void OptionHandlerTest::testNumberOptionHandler_min_max() void OptionHandlerTest::testNumberOptionHandler_min_max()
{ {
NumberOptionHandler handler("foo", "", "", 1, 100); NumberOptionHandler handler(PREF_TIMEOUT, "", "", 1, 100);
Option option; Option option;
handler.parse(option, "1"); handler.parse(option, "1");
CPPUNIT_ASSERT_EQUAL(std::string("1"), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string("1"), option.get(PREF_TIMEOUT));
handler.parse(option, "100"); handler.parse(option, "100");
CPPUNIT_ASSERT_EQUAL(std::string("100"), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string("100"), option.get(PREF_TIMEOUT));
try { try {
handler.parse(option, "0"); handler.parse(option, "0");
CPPUNIT_FAIL("exception must be thrown."); CPPUNIT_FAIL("exception must be thrown.");
@ -146,16 +146,16 @@ void OptionHandlerTest::testNumberOptionHandler_min_max()
void OptionHandlerTest::testUnitNumberOptionHandler() void OptionHandlerTest::testUnitNumberOptionHandler()
{ {
UnitNumberOptionHandler handler("foo"); UnitNumberOptionHandler handler(PREF_TIMEOUT);
CPPUNIT_ASSERT(handler.canHandle("foo")); CPPUNIT_ASSERT(handler.canHandle(PREF_TIMEOUT->k));
CPPUNIT_ASSERT(!handler.canHandle("foobar")); CPPUNIT_ASSERT(!handler.canHandle("foobar"));
Option option; Option option;
handler.parse(option, "4294967296"); handler.parse(option, "4294967296");
CPPUNIT_ASSERT_EQUAL(std::string("4294967296"), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string("4294967296"), option.get(PREF_TIMEOUT));
handler.parse(option, "4096M"); handler.parse(option, "4096M");
CPPUNIT_ASSERT_EQUAL(std::string("4294967296"), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string("4294967296"), option.get(PREF_TIMEOUT));
handler.parse(option, "4096K"); handler.parse(option, "4096K");
CPPUNIT_ASSERT_EQUAL(std::string("4194304"), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string("4194304"), option.get(PREF_TIMEOUT));
try { try {
handler.parse(option, "K"); handler.parse(option, "K");
CPPUNIT_FAIL("exception must be thrown."); CPPUNIT_FAIL("exception must be thrown.");
@ -171,12 +171,12 @@ void OptionHandlerTest::testUnitNumberOptionHandler()
void OptionHandlerTest::testParameterOptionHandler_1argInit() void OptionHandlerTest::testParameterOptionHandler_1argInit()
{ {
ParameterOptionHandler handler("foo", "", "", "value1"); ParameterOptionHandler handler(PREF_TIMEOUT, "", "", "value1");
CPPUNIT_ASSERT(handler.canHandle("foo")); CPPUNIT_ASSERT(handler.canHandle(PREF_TIMEOUT->k));
CPPUNIT_ASSERT(!handler.canHandle("foobar")); CPPUNIT_ASSERT(!handler.canHandle("foobar"));
Option option; Option option;
handler.parse(option, "value1"); handler.parse(option, "value1");
CPPUNIT_ASSERT_EQUAL(std::string("value1"), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string("value1"), option.get(PREF_TIMEOUT));
try { try {
handler.parse(option, "value3"); handler.parse(option, "value3");
CPPUNIT_FAIL("exception must be thrown."); CPPUNIT_FAIL("exception must be thrown.");
@ -187,14 +187,14 @@ void OptionHandlerTest::testParameterOptionHandler_1argInit()
void OptionHandlerTest::testParameterOptionHandler_2argsInit() void OptionHandlerTest::testParameterOptionHandler_2argsInit()
{ {
ParameterOptionHandler handler("foo", "", "", "value1", "value2"); ParameterOptionHandler handler(PREF_TIMEOUT, "", "", "value1", "value2");
CPPUNIT_ASSERT(handler.canHandle("foo")); CPPUNIT_ASSERT(handler.canHandle(PREF_TIMEOUT->k));
CPPUNIT_ASSERT(!handler.canHandle("foobar")); CPPUNIT_ASSERT(!handler.canHandle("foobar"));
Option option; Option option;
handler.parse(option, "value1"); handler.parse(option, "value1");
CPPUNIT_ASSERT_EQUAL(std::string("value1"), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string("value1"), option.get(PREF_TIMEOUT));
handler.parse(option, "value2"); handler.parse(option, "value2");
CPPUNIT_ASSERT_EQUAL(std::string("value2"), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string("value2"), option.get(PREF_TIMEOUT));
try { try {
handler.parse(option, "value3"); handler.parse(option, "value3");
CPPUNIT_FAIL("exception must be thrown."); CPPUNIT_FAIL("exception must be thrown.");
@ -209,14 +209,14 @@ void OptionHandlerTest::testParameterOptionHandler_listInit()
validValues.push_back("value1"); validValues.push_back("value1");
validValues.push_back("value2"); validValues.push_back("value2");
ParameterOptionHandler handler("foo", "", "", validValues); ParameterOptionHandler handler(PREF_TIMEOUT, "", "", validValues);
CPPUNIT_ASSERT(handler.canHandle("foo")); CPPUNIT_ASSERT(handler.canHandle(PREF_TIMEOUT->k));
CPPUNIT_ASSERT(!handler.canHandle("foobar")); CPPUNIT_ASSERT(!handler.canHandle("foobar"));
Option option; Option option;
handler.parse(option, "value1"); handler.parse(option, "value1");
CPPUNIT_ASSERT_EQUAL(std::string("value1"), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string("value1"), option.get(PREF_TIMEOUT));
handler.parse(option, "value2"); handler.parse(option, "value2");
CPPUNIT_ASSERT_EQUAL(std::string("value2"), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string("value2"), option.get(PREF_TIMEOUT));
try { try {
handler.parse(option, "value3"); handler.parse(option, "value3");
CPPUNIT_FAIL("exception must be thrown."); CPPUNIT_FAIL("exception must be thrown.");
@ -227,14 +227,14 @@ void OptionHandlerTest::testParameterOptionHandler_listInit()
void OptionHandlerTest::testDefaultOptionHandler() void OptionHandlerTest::testDefaultOptionHandler()
{ {
DefaultOptionHandler handler("foo"); DefaultOptionHandler handler(PREF_TIMEOUT);
CPPUNIT_ASSERT(handler.canHandle("foo")); CPPUNIT_ASSERT(handler.canHandle(PREF_TIMEOUT->k));
CPPUNIT_ASSERT(!handler.canHandle("foobar")); CPPUNIT_ASSERT(!handler.canHandle("foobar"));
Option option; Option option;
handler.parse(option, "bar"); handler.parse(option, "bar");
CPPUNIT_ASSERT_EQUAL(std::string("bar"), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string("bar"), option.get(PREF_TIMEOUT));
handler.parse(option, ""); handler.parse(option, "");
CPPUNIT_ASSERT_EQUAL(std::string(""), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string(""), option.get(PREF_TIMEOUT));
CPPUNIT_ASSERT_EQUAL(std::string(""), handler.createPossibleValuesString()); CPPUNIT_ASSERT_EQUAL(std::string(""), handler.createPossibleValuesString());
handler.addTag("apple"); handler.addTag("apple");
@ -248,22 +248,22 @@ void OptionHandlerTest::testDefaultOptionHandler()
void OptionHandlerTest::testFloatNumberOptionHandler() void OptionHandlerTest::testFloatNumberOptionHandler()
{ {
FloatNumberOptionHandler handler("foo"); FloatNumberOptionHandler handler(PREF_TIMEOUT);
CPPUNIT_ASSERT(handler.canHandle("foo")); CPPUNIT_ASSERT(handler.canHandle(PREF_TIMEOUT->k));
CPPUNIT_ASSERT(!handler.canHandle("foobar")); CPPUNIT_ASSERT(!handler.canHandle("foobar"));
Option option; Option option;
handler.parse(option, "1.0"); handler.parse(option, "1.0");
CPPUNIT_ASSERT_EQUAL(std::string("1.0"), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string("1.0"), option.get(PREF_TIMEOUT));
CPPUNIT_ASSERT_EQUAL(std::string("*-*"), CPPUNIT_ASSERT_EQUAL(std::string("*-*"),
handler.createPossibleValuesString()); handler.createPossibleValuesString());
} }
void OptionHandlerTest::testFloatNumberOptionHandler_min() void OptionHandlerTest::testFloatNumberOptionHandler_min()
{ {
FloatNumberOptionHandler handler("foo", "", "", 0.0); FloatNumberOptionHandler handler(PREF_TIMEOUT, "", "", 0.0);
Option option; Option option;
handler.parse(option, "0.0"); handler.parse(option, "0.0");
CPPUNIT_ASSERT_EQUAL(std::string("0.0"), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string("0.0"), option.get(PREF_TIMEOUT));
try { try {
handler.parse(option, "-0.1"); handler.parse(option, "-0.1");
CPPUNIT_FAIL("exception must be thrown."); CPPUNIT_FAIL("exception must be thrown.");
@ -274,10 +274,10 @@ void OptionHandlerTest::testFloatNumberOptionHandler_min()
void OptionHandlerTest::testFloatNumberOptionHandler_max() void OptionHandlerTest::testFloatNumberOptionHandler_max()
{ {
FloatNumberOptionHandler handler("foo", "", "", -1, 10.0); FloatNumberOptionHandler handler(PREF_TIMEOUT, "", "", -1, 10.0);
Option option; Option option;
handler.parse(option, "10.0"); handler.parse(option, "10.0");
CPPUNIT_ASSERT_EQUAL(std::string("10.0"), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string("10.0"), option.get(PREF_TIMEOUT));
try { try {
handler.parse(option, "10.1"); handler.parse(option, "10.1");
CPPUNIT_FAIL("exception must be thrown."); CPPUNIT_FAIL("exception must be thrown.");
@ -288,12 +288,12 @@ void OptionHandlerTest::testFloatNumberOptionHandler_max()
void OptionHandlerTest::testFloatNumberOptionHandler_min_max() void OptionHandlerTest::testFloatNumberOptionHandler_min_max()
{ {
FloatNumberOptionHandler handler("foo", "", "", 0.0, 10.0); FloatNumberOptionHandler handler(PREF_TIMEOUT, "", "", 0.0, 10.0);
Option option; Option option;
handler.parse(option, "0.0"); handler.parse(option, "0.0");
CPPUNIT_ASSERT_EQUAL(std::string("0.0"), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string("0.0"), option.get(PREF_TIMEOUT));
handler.parse(option, "10.0"); handler.parse(option, "10.0");
CPPUNIT_ASSERT_EQUAL(std::string("10.0"), option.get("foo")); CPPUNIT_ASSERT_EQUAL(std::string("10.0"), option.get(PREF_TIMEOUT));
try { try {
handler.parse(option, "-0.1"); handler.parse(option, "-0.1");
CPPUNIT_FAIL("exception must be thrown."); CPPUNIT_FAIL("exception must be thrown.");
@ -309,7 +309,7 @@ void OptionHandlerTest::testFloatNumberOptionHandler_min_max()
void OptionHandlerTest::testHttpProxyOptionHandler() void OptionHandlerTest::testHttpProxyOptionHandler()
{ {
HttpProxyOptionHandler handler(PREF_HTTP_PROXY, "", ""); HttpProxyOptionHandler handler(PREF_HTTP_PROXY, "", "");
CPPUNIT_ASSERT(handler.canHandle(PREF_HTTP_PROXY)); CPPUNIT_ASSERT(handler.canHandle(PREF_HTTP_PROXY->k));
CPPUNIT_ASSERT(!handler.canHandle("foobar")); CPPUNIT_ASSERT(!handler.canHandle("foobar"));
Option option; Option option;
handler.parse(option, "proxy:65535"); handler.parse(option, "proxy:65535");
@ -425,19 +425,19 @@ void OptionHandlerTest::testDeprecatedOptionHandler()
{ {
{ {
DeprecatedOptionHandler handler DeprecatedOptionHandler handler
(SharedHandle<OptionHandler>(new DefaultOptionHandler("dep"))); (SharedHandle<OptionHandler>(new DefaultOptionHandler(PREF_TIMEOUT)));
Option option; Option option;
handler.parse(option, "foo"); handler.parse(option, "foo");
CPPUNIT_ASSERT(!option.defined("dep")); CPPUNIT_ASSERT(!option.defined(PREF_TIMEOUT));
} }
{ {
DeprecatedOptionHandler handler DeprecatedOptionHandler handler
(SharedHandle<OptionHandler>(new DefaultOptionHandler("dep")), (SharedHandle<OptionHandler>(new DefaultOptionHandler(PREF_TIMEOUT)),
SharedHandle<OptionHandler>(new DefaultOptionHandler("rep"))); SharedHandle<OptionHandler>(new DefaultOptionHandler(PREF_DIR)));
Option option; Option option;
handler.parse(option, "foo"); handler.parse(option, "foo");
CPPUNIT_ASSERT(!option.defined("dep")); CPPUNIT_ASSERT(!option.defined(PREF_TIMEOUT));
CPPUNIT_ASSERT_EQUAL(std::string("foo"), option.get("rep")); CPPUNIT_ASSERT_EQUAL(std::string("foo"), option.get(PREF_DIR));
} }
} }

View File

@ -10,6 +10,7 @@
#include "util.h" #include "util.h"
#include "Option.h" #include "Option.h"
#include "array_fun.h" #include "array_fun.h"
#include "prefs.h"
namespace aria2 { namespace aria2 {
@ -33,30 +34,31 @@ public:
{ {
oparser_.reset(new OptionParser()); oparser_.reset(new OptionParser());
SharedHandle<OptionHandler> alpha SharedHandle<OptionHandler> timeout
(new DefaultOptionHandler("alpha", NO_DESCRIPTION, "ALPHA", "", (new DefaultOptionHandler(PREF_TIMEOUT, NO_DESCRIPTION, "ALPHA", "",
OptionHandler::REQ_ARG, 'A')); OptionHandler::REQ_ARG, 'A'));
alpha->addTag("apple"); timeout->addTag("apple");
alpha->setEraseAfterParse(true); timeout->setEraseAfterParse(true);
oparser_->addOptionHandler(alpha); oparser_->addOptionHandler(timeout);
SharedHandle<OptionHandler> bravo(new DefaultOptionHandler("bravo")); SharedHandle<OptionHandler> dir(new DefaultOptionHandler(PREF_DIR));
bravo->addTag("apple"); dir->addTag("apple");
bravo->addTag("orange"); dir->addTag("orange");
bravo->addTag("pineapple"); dir->addTag("pineapple");
oparser_->addOptionHandler(bravo); oparser_->addOptionHandler(dir);
SharedHandle<DefaultOptionHandler> charlie SharedHandle<DefaultOptionHandler> daemon
(new DefaultOptionHandler("charlie", NO_DESCRIPTION, "CHARLIE", "", (new DefaultOptionHandler(PREF_DAEMON, NO_DESCRIPTION, "CHARLIE", "",
OptionHandler::REQ_ARG, 'C')); OptionHandler::REQ_ARG, 'C'));
charlie->hide(); daemon->hide();
charlie->addTag("pineapple"); daemon->addTag("pineapple");
oparser_->addOptionHandler(charlie); oparser_->addOptionHandler(daemon);
SharedHandle<OptionHandler> delta SharedHandle<OptionHandler> out
(new UnitNumberOptionHandler("delta", NO_DESCRIPTION, "1M", -1, -1, 'D')); (new UnitNumberOptionHandler(PREF_OUT, NO_DESCRIPTION, "1M",
delta->addTag("pineapple"); -1, -1, 'D'));
oparser_->addOptionHandler(delta); out->addTag("pineapple");
oparser_->addOptionHandler(out);
} }
void tearDown() {} void tearDown() {}
@ -79,18 +81,18 @@ void OptionParserTest::testFindAll()
{ {
std::vector<SharedHandle<OptionHandler> > res = oparser_->findAll(); std::vector<SharedHandle<OptionHandler> > res = oparser_->findAll();
CPPUNIT_ASSERT_EQUAL((size_t)3, res.size()); CPPUNIT_ASSERT_EQUAL((size_t)3, res.size());
CPPUNIT_ASSERT_EQUAL(std::string("alpha"), res[0]->getName()); CPPUNIT_ASSERT_EQUAL(std::string("timeout"), res[0]->getName());
CPPUNIT_ASSERT_EQUAL(std::string("bravo"), res[1]->getName()); CPPUNIT_ASSERT_EQUAL(std::string("dir"), res[1]->getName());
CPPUNIT_ASSERT_EQUAL(std::string("delta"), res[2]->getName()); CPPUNIT_ASSERT_EQUAL(std::string("out"), res[2]->getName());
} }
void OptionParserTest::testFindByNameSubstring() void OptionParserTest::testFindByNameSubstring()
{ {
std::vector<SharedHandle<OptionHandler> > res = std::vector<SharedHandle<OptionHandler> > res =
oparser_->findByNameSubstring("l"); oparser_->findByNameSubstring("i");
CPPUNIT_ASSERT_EQUAL((size_t)2, res.size()); CPPUNIT_ASSERT_EQUAL((size_t)2, res.size());
CPPUNIT_ASSERT_EQUAL(std::string("alpha"), res[0]->getName()); CPPUNIT_ASSERT_EQUAL(std::string("timeout"), res[0]->getName());
CPPUNIT_ASSERT_EQUAL(std::string("delta"), res[1]->getName()); CPPUNIT_ASSERT_EQUAL(std::string("dir"), res[1]->getName());
} }
void OptionParserTest::testFindByTag() void OptionParserTest::testFindByTag()
@ -98,37 +100,37 @@ void OptionParserTest::testFindByTag()
std::vector<SharedHandle<OptionHandler> > res = std::vector<SharedHandle<OptionHandler> > res =
oparser_->findByTag("pineapple"); oparser_->findByTag("pineapple");
CPPUNIT_ASSERT_EQUAL((size_t)2, res.size()); CPPUNIT_ASSERT_EQUAL((size_t)2, res.size());
CPPUNIT_ASSERT_EQUAL(std::string("bravo"), res[0]->getName()); CPPUNIT_ASSERT_EQUAL(std::string("dir"), res[0]->getName());
CPPUNIT_ASSERT_EQUAL(std::string("delta"), res[1]->getName()); CPPUNIT_ASSERT_EQUAL(std::string("out"), res[1]->getName());
} }
void OptionParserTest::testFindByName() void OptionParserTest::testFindByName()
{ {
SharedHandle<OptionHandler> bravo = oparser_->findByName("bravo"); SharedHandle<OptionHandler> dir = oparser_->findByName("dir");
CPPUNIT_ASSERT(bravo); CPPUNIT_ASSERT(dir);
CPPUNIT_ASSERT_EQUAL(std::string("bravo"), bravo->getName()); CPPUNIT_ASSERT_EQUAL(std::string("dir"), dir->getName());
SharedHandle<OptionHandler> charlie = oparser_->findByName("charlie"); SharedHandle<OptionHandler> daemon = oparser_->findByName("daemon");
CPPUNIT_ASSERT(!charlie); CPPUNIT_ASSERT(!daemon);
SharedHandle<OptionHandler> alpha2 = oparser_->findByName("alpha2"); SharedHandle<OptionHandler> timeout2 = oparser_->findByName("timeout2");
CPPUNIT_ASSERT(!alpha2); CPPUNIT_ASSERT(!timeout2);
} }
void OptionParserTest::testFindByShortName() void OptionParserTest::testFindByShortName()
{ {
SharedHandle<OptionHandler> alpha = oparser_->findByShortName('A'); SharedHandle<OptionHandler> timeout = oparser_->findByShortName('A');
CPPUNIT_ASSERT(alpha); CPPUNIT_ASSERT(timeout);
CPPUNIT_ASSERT_EQUAL(std::string("alpha"), alpha->getName()); CPPUNIT_ASSERT_EQUAL(std::string("timeout"), timeout->getName());
CPPUNIT_ASSERT(!oparser_->findByShortName('C')); CPPUNIT_ASSERT(!oparser_->findByShortName('C'));
} }
void OptionParserTest::testFindByID() void OptionParserTest::testFindByID()
{ {
SharedHandle<OptionHandler> alpha = oparser_->findByID(1); SharedHandle<OptionHandler> timeout = oparser_->findByID(1);
CPPUNIT_ASSERT(alpha); CPPUNIT_ASSERT(timeout);
CPPUNIT_ASSERT_EQUAL(std::string("alpha"), alpha->getName()); CPPUNIT_ASSERT_EQUAL(std::string("timeout"), timeout->getName());
CPPUNIT_ASSERT(!oparser_->findByID(3)); CPPUNIT_ASSERT(!oparser_->findByID(3));
} }
@ -137,10 +139,10 @@ void OptionParserTest::testParseDefaultValues()
{ {
Option option; Option option;
oparser_->parseDefaultValues(option); oparser_->parseDefaultValues(option);
CPPUNIT_ASSERT_EQUAL(std::string("ALPHA"), option.get("alpha")); CPPUNIT_ASSERT_EQUAL(std::string("ALPHA"), option.get(PREF_TIMEOUT));
CPPUNIT_ASSERT_EQUAL(std::string("1048576"), option.get("delta")); CPPUNIT_ASSERT_EQUAL(std::string("1048576"), option.get(PREF_OUT));
CPPUNIT_ASSERT_EQUAL(std::string("CHARLIE"), option.get("charlie")); CPPUNIT_ASSERT_EQUAL(std::string("CHARLIE"), option.get(PREF_DAEMON));
CPPUNIT_ASSERT(!option.defined("bravo")); CPPUNIT_ASSERT(!option.defined(PREF_DIR));
} }
void OptionParserTest::testParseArg() void OptionParserTest::testParseArg()
@ -149,21 +151,21 @@ void OptionParserTest::testParseArg()
char prog[7]; char prog[7];
strncpy(prog, "aria2c", sizeof(prog)); strncpy(prog, "aria2c", sizeof(prog));
char optionAlpha[3]; char optionTimeout[3];
strncpy(optionAlpha, "-A", sizeof(optionAlpha)); strncpy(optionTimeout, "-A", sizeof(optionTimeout));
char argAlpha[6]; char argTimeout[6];
strncpy(argAlpha, "ALPHA", sizeof(argAlpha)); strncpy(argTimeout, "ALPHA", sizeof(argTimeout));
char optionBravo[8]; char optionDir[8];
strncpy(optionBravo, "--bravo", sizeof(optionBravo)); strncpy(optionDir, "--dir", sizeof(optionDir));
char argBravo[6]; char argDir[6];
strncpy(argBravo, "BRAVO", sizeof(argBravo)); strncpy(argDir, "BRAVO", sizeof(argDir));
char nonopt1[8]; char nonopt1[8];
strncpy(nonopt1, "nonopt1", sizeof(nonopt1)); strncpy(nonopt1, "nonopt1", sizeof(nonopt1));
char nonopt2[8]; char nonopt2[8];
strncpy(nonopt2, "nonopt2", sizeof(nonopt2)); strncpy(nonopt2, "nonopt2", sizeof(nonopt2));
char* argv[] = { prog, optionAlpha, argAlpha, optionBravo, argBravo, char* argv[] = { prog, optionTimeout, argTimeout, optionDir, argDir,
nonopt1, nonopt2 }; nonopt1, nonopt2 };
int argc = A2_ARRAY_LEN(argv); int argc = A2_ARRAY_LEN(argv);
@ -172,28 +174,26 @@ void OptionParserTest::testParseArg()
oparser_->parseArg(s, nonopts, argc, argv); oparser_->parseArg(s, nonopts, argc, argv);
CPPUNIT_ASSERT_EQUAL(std::string("alpha=ALPHA\n" CPPUNIT_ASSERT_EQUAL(std::string("timeout=ALPHA\n"
"bravo=BRAVO\n"), s.str()); "dir=BRAVO\n"), s.str());
CPPUNIT_ASSERT_EQUAL((size_t)2, nonopts.size()); CPPUNIT_ASSERT_EQUAL((size_t)2, nonopts.size());
CPPUNIT_ASSERT_EQUAL(std::string("nonopt1"), nonopts[0]); CPPUNIT_ASSERT_EQUAL(std::string("nonopt1"), nonopts[0]);
CPPUNIT_ASSERT_EQUAL(std::string("nonopt2"), nonopts[1]); CPPUNIT_ASSERT_EQUAL(std::string("nonopt2"), nonopts[1]);
CPPUNIT_ASSERT_EQUAL(std::string("*****"), std::string(argAlpha)); CPPUNIT_ASSERT_EQUAL(std::string("*****"), std::string(argTimeout));
} }
void OptionParserTest::testParse() void OptionParserTest::testParse()
{ {
Option option; Option option;
std::istringstream in("alpha=Hello\n" std::istringstream in("timeout=Hello\n"
"UNKNOWN=x\n" "UNKNOWN=x\n"
"\n" "\n"
"bravo=World"); "dir=World");
oparser_->parse(option, in); oparser_->parse(option, in);
CPPUNIT_ASSERT_EQUAL CPPUNIT_ASSERT_EQUAL(std::string("Hello"), option.get(PREF_TIMEOUT));
((std::ptrdiff_t)2, std::distance(option.begin(), option.end())); CPPUNIT_ASSERT_EQUAL(std::string("World"), option.get(PREF_DIR));
CPPUNIT_ASSERT_EQUAL(std::string("Hello"), option.get("alpha"));
CPPUNIT_ASSERT_EQUAL(std::string("World"), option.get("bravo"));
} }
} // namespace aria2 } // namespace aria2

View File

@ -1,7 +1,11 @@
#include "Option.h" #include "Option.h"
#include <string> #include <string>
#include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/HelperMacros.h>
#include "prefs.h"
namespace aria2 { namespace aria2 {
class OptionTest:public CppUnit::TestFixture { class OptionTest:public CppUnit::TestFixture {
@ -31,45 +35,45 @@ CPPUNIT_TEST_SUITE_REGISTRATION( OptionTest );
void OptionTest::testPutAndGet() { void OptionTest::testPutAndGet() {
Option op; Option op;
op.put("key", "value"); op.put(PREF_TIMEOUT, "value");
CPPUNIT_ASSERT(op.defined("key")); CPPUNIT_ASSERT(op.defined(PREF_TIMEOUT));
CPPUNIT_ASSERT_EQUAL(std::string("value"), op.get("key")); CPPUNIT_ASSERT_EQUAL(std::string("value"), op.get(PREF_TIMEOUT));
} }
void OptionTest::testPutAndGetAsInt() { void OptionTest::testPutAndGetAsInt() {
Option op; Option op;
op.put("key", "1000"); op.put(PREF_TIMEOUT, "1000");
CPPUNIT_ASSERT(op.defined("key")); CPPUNIT_ASSERT(op.defined(PREF_TIMEOUT));
CPPUNIT_ASSERT_EQUAL((int32_t)1000, op.getAsInt("key")); CPPUNIT_ASSERT_EQUAL((int32_t)1000, op.getAsInt(PREF_TIMEOUT));
} }
void OptionTest::testPutAndGetAsDouble() { void OptionTest::testPutAndGetAsDouble() {
Option op; Option op;
op.put("key", "10.0"); op.put(PREF_TIMEOUT, "10.0");
CPPUNIT_ASSERT_EQUAL(10.0, op.getAsDouble("key")); CPPUNIT_ASSERT_EQUAL(10.0, op.getAsDouble(PREF_TIMEOUT));
} }
void OptionTest::testDefined() void OptionTest::testDefined()
{ {
Option op; Option op;
op.put("k", "v"); op.put(PREF_TIMEOUT, "v");
op.put("k1", ""); op.put(PREF_DIR, "");
CPPUNIT_ASSERT(op.defined("k")); CPPUNIT_ASSERT(op.defined(PREF_TIMEOUT));
CPPUNIT_ASSERT(op.defined("k1")); CPPUNIT_ASSERT(op.defined(PREF_DIR));
CPPUNIT_ASSERT(!op.defined("undefined")); CPPUNIT_ASSERT(!op.defined(PREF_DAEMON));
} }
void OptionTest::testBlank() void OptionTest::testBlank()
{ {
Option op; Option op;
op.put("k", "v"); op.put(PREF_TIMEOUT, "v");
op.put("k1", ""); op.put(PREF_DIR, "");
CPPUNIT_ASSERT(!op.blank("k")); CPPUNIT_ASSERT(!op.blank(PREF_TIMEOUT));
CPPUNIT_ASSERT(op.blank("k1")); CPPUNIT_ASSERT(op.blank(PREF_DIR));
CPPUNIT_ASSERT(op.blank("undefined")); CPPUNIT_ASSERT(op.blank(PREF_DAEMON));
} }
} // namespace aria2 } // namespace aria2

View File

@ -171,7 +171,7 @@ void RpcMethodTest::testAddUri()
} }
// with options // with options
SharedHandle<Dict> opt = Dict::g(); SharedHandle<Dict> opt = Dict::g();
opt->put(PREF_DIR, "/sink"); opt->put(PREF_DIR->k, "/sink");
req.params->append(opt); req.params->append(opt);
{ {
RpcResponse res = m.execute(req, e_.get()); RpcResponse res = m.execute(req, e_.get());
@ -209,7 +209,7 @@ void RpcMethodTest::testAddUri_withBadOption()
urisParam->append("http://localhost"); urisParam->append("http://localhost");
req.params->append(urisParam); req.params->append(urisParam);
SharedHandle<Dict> opt = Dict::g(); SharedHandle<Dict> opt = Dict::g();
opt->put(PREF_FILE_ALLOCATION, "badvalue"); opt->put(PREF_FILE_ALLOCATION->k, "badvalue");
req.params->append(opt); req.params->append(opt);
RpcResponse res = m.execute(req, e_.get()); RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code); CPPUNIT_ASSERT_EQUAL(1, res.code);
@ -288,7 +288,7 @@ void RpcMethodTest::testAddTorrent()
std::string dir = A2_TEST_OUT_DIR"/aria2_RpcMethodTest_testAddTorrent"; std::string dir = A2_TEST_OUT_DIR"/aria2_RpcMethodTest_testAddTorrent";
File(dir).mkdirs(); File(dir).mkdirs();
SharedHandle<Dict> opt = Dict::g(); SharedHandle<Dict> opt = Dict::g();
opt->put(PREF_DIR, dir); opt->put(PREF_DIR->k, dir);
File(dir+"/0a3893293e27ac0490424c06de4d09242215f0a6.torrent").remove(); File(dir+"/0a3893293e27ac0490424c06de4d09242215f0a6.torrent").remove();
req.params->append(opt); req.params->append(opt);
{ {
@ -379,7 +379,7 @@ void RpcMethodTest::testAddMetalink()
std::string dir = A2_TEST_OUT_DIR"/aria2_RpcMethodTest_testAddMetalink"; std::string dir = A2_TEST_OUT_DIR"/aria2_RpcMethodTest_testAddMetalink";
File(dir).mkdirs(); File(dir).mkdirs();
SharedHandle<Dict> opt = Dict::g(); SharedHandle<Dict> opt = Dict::g();
opt->put(PREF_DIR, dir); opt->put(PREF_DIR->k, dir);
File(dir+"/c908634fbc257fd56f0114912c2772aeeb4064f4.meta4").remove(); File(dir+"/c908634fbc257fd56f0114912c2772aeeb4064f4.meta4").remove();
req.params->append(opt); req.params->append(opt);
{ {
@ -446,11 +446,11 @@ void RpcMethodTest::testChangeOption()
RpcRequest req(ChangeOptionRpcMethod::getMethodName(), List::g()); RpcRequest req(ChangeOptionRpcMethod::getMethodName(), List::g());
req.params->append("1"); req.params->append("1");
SharedHandle<Dict> opt = Dict::g(); SharedHandle<Dict> opt = Dict::g();
opt->put(PREF_MAX_DOWNLOAD_LIMIT, "100K"); opt->put(PREF_MAX_DOWNLOAD_LIMIT->k, "100K");
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
opt->put(PREF_BT_MAX_PEERS, "100"); opt->put(PREF_BT_MAX_PEERS->k, "100");
opt->put(PREF_BT_REQUEST_PEER_SPEED_LIMIT, "300K"); opt->put(PREF_BT_REQUEST_PEER_SPEED_LIMIT->k, "300K");
opt->put(PREF_MAX_UPLOAD_LIMIT, "50K"); opt->put(PREF_MAX_UPLOAD_LIMIT->k, "50K");
BtObject btObject; BtObject btObject;
btObject.btRuntime_ = SharedHandle<BtRuntime>(new BtRuntime()); btObject.btRuntime_ = SharedHandle<BtRuntime>(new BtRuntime());
@ -489,7 +489,7 @@ void RpcMethodTest::testChangeOption_withBadOption()
RpcRequest req(ChangeOptionRpcMethod::getMethodName(), List::g()); RpcRequest req(ChangeOptionRpcMethod::getMethodName(), List::g());
req.params->append("1"); req.params->append("1");
SharedHandle<Dict> opt = Dict::g(); SharedHandle<Dict> opt = Dict::g();
opt->put(PREF_MAX_DOWNLOAD_LIMIT, "badvalue"); opt->put(PREF_MAX_DOWNLOAD_LIMIT->k, "badvalue");
req.params->append(opt); req.params->append(opt);
RpcResponse res = m.execute(req, e_.get()); RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code); CPPUNIT_ASSERT_EQUAL(1, res.code);
@ -504,7 +504,7 @@ void RpcMethodTest::testChangeOption_withNotAllowedOption()
RpcRequest req(ChangeOptionRpcMethod::getMethodName(), List::g()); RpcRequest req(ChangeOptionRpcMethod::getMethodName(), List::g());
req.params->append("1"); req.params->append("1");
SharedHandle<Dict> opt = Dict::g(); SharedHandle<Dict> opt = Dict::g();
opt->put(PREF_MAX_OVERALL_DOWNLOAD_LIMIT, "100K"); opt->put(PREF_MAX_OVERALL_DOWNLOAD_LIMIT->k, "100K");
req.params->append(opt); req.params->append(opt);
RpcResponse res = m.execute(req, e_.get()); RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code); CPPUNIT_ASSERT_EQUAL(1, res.code);
@ -524,9 +524,9 @@ void RpcMethodTest::testChangeGlobalOption()
RpcRequest req RpcRequest req
(ChangeGlobalOptionRpcMethod::getMethodName(), List::g()); (ChangeGlobalOptionRpcMethod::getMethodName(), List::g());
SharedHandle<Dict> opt = Dict::g(); SharedHandle<Dict> opt = Dict::g();
opt->put(PREF_MAX_OVERALL_DOWNLOAD_LIMIT, "100K"); opt->put(PREF_MAX_OVERALL_DOWNLOAD_LIMIT->k, "100K");
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
opt->put(PREF_MAX_OVERALL_UPLOAD_LIMIT, "50K"); opt->put(PREF_MAX_OVERALL_UPLOAD_LIMIT->k, "50K");
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
req.params->append(opt); req.params->append(opt);
RpcResponse res = m.execute(req, e_.get()); RpcResponse res = m.execute(req, e_.get());
@ -552,7 +552,7 @@ void RpcMethodTest::testChangeGlobalOption_withBadOption()
RpcRequest req RpcRequest req
(ChangeGlobalOptionRpcMethod::getMethodName(), List::g()); (ChangeGlobalOptionRpcMethod::getMethodName(), List::g());
SharedHandle<Dict> opt = Dict::g(); SharedHandle<Dict> opt = Dict::g();
opt->put(PREF_MAX_OVERALL_DOWNLOAD_LIMIT, "badvalue"); opt->put(PREF_MAX_OVERALL_DOWNLOAD_LIMIT->k, "badvalue");
req.params->append(opt); req.params->append(opt);
RpcResponse res = m.execute(req, e_.get()); RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code); CPPUNIT_ASSERT_EQUAL(1, res.code);
@ -564,7 +564,7 @@ void RpcMethodTest::testChangeGlobalOption_withNotAllowedOption()
RpcRequest req RpcRequest req
(ChangeGlobalOptionRpcMethod::getMethodName(), List::g()); (ChangeGlobalOptionRpcMethod::getMethodName(), List::g());
SharedHandle<Dict> opt = Dict::g(); SharedHandle<Dict> opt = Dict::g();
opt->put(PREF_MAX_DOWNLOAD_LIMIT, "100K"); opt->put(PREF_MAX_DOWNLOAD_LIMIT->k, "100K");
req.params->append(opt); req.params->append(opt);
RpcResponse res = m.execute(req, e_.get()); RpcResponse res = m.execute(req, e_.get());
CPPUNIT_ASSERT_EQUAL(1, res.code); CPPUNIT_ASSERT_EQUAL(1, res.code);

View File

@ -107,8 +107,8 @@ void UTMetadataPostDownloadHandlerTest::testGetNextRequestGroups()
newAttrs->announceList; newAttrs->announceList;
CPPUNIT_ASSERT_EQUAL((size_t)1, newAnnounceList.size()); CPPUNIT_ASSERT_EQUAL((size_t)1, newAnnounceList.size());
CPPUNIT_ASSERT_EQUAL(std::string("http://tracker"), newAnnounceList[0][0]); CPPUNIT_ASSERT_EQUAL(std::string("http://tracker"), newAnnounceList[0][0]);
CPPUNIT_ASSERT_EQUAL(option_->get("Hello"), CPPUNIT_ASSERT_EQUAL(option_->get(PREF_DIR),
newRg->getOption()->get("Hello")); newRg->getOption()->get(PREF_DIR));
CPPUNIT_ASSERT CPPUNIT_ASSERT
(std::find(requestGroup_->followedBy().begin(), (std::find(requestGroup_->followedBy().begin(),
requestGroup_->followedBy().end(), requestGroup_->followedBy().end(),