aria2/src/OptionHandlerImpl.h

298 lines
12 KiB
C
Raw Normal View History

/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2006 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/
/* copyright --> */
#ifndef D_OPTION_HANDLER_IMPL_H
#define D_OPTION_HANDLER_IMPL_H
#include "OptionHandler.h"
#include <vector>
#include "NameMatchOptionHandler.h"
namespace aria2 {
class Option;
class NullOptionHandler : public OptionHandler {
private:
int id_;
public:
virtual ~NullOptionHandler();
virtual bool canHandle(const std::string& optName);
virtual void parse(Option& option, const std::string& arg);
virtual bool hasTag(const std::string& tag) const;
virtual void addTag(const std::string& tag);
virtual std::string toTagString() const;
virtual const std::string& getName() const;
virtual const std::string& getDescription() const;
virtual const std::string& getDefaultValue() const;
virtual std::string createPossibleValuesString() const;
virtual bool isHidden() const;
virtual void hide();
virtual OptionHandler::ARG_TYPE getArgType() const;
virtual int getOptionID() const;
virtual void setOptionID(int id);
virtual char getShortName() const;
};
class BooleanOptionHandler : public NameMatchOptionHandler {
public:
BooleanOptionHandler(const std::string& optName,
const std::string& description = NO_DESCRIPTION,
const std::string& defaultValue = NO_DEFAULT_VALUE,
OptionHandler::ARG_TYPE argType = OptionHandler::REQ_ARG,
char shortName = 0);
virtual ~BooleanOptionHandler();
virtual void parseArg(Option& option, const std::string& optarg);
virtual std::string createPossibleValuesString() const;
};
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
class IntegerRangeOptionHandler : public NameMatchOptionHandler {
private:
int32_t min_;
int32_t max_;
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
public:
IntegerRangeOptionHandler(const std::string& optName,
const std::string& description,
const std::string& defaultValue,
int32_t min, int32_t max,
char shortName = 0);
virtual ~IntegerRangeOptionHandler();
virtual void parseArg(Option& option, const std::string& optarg);
virtual std::string createPossibleValuesString() const;
2007-11-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Preallocate non-requested file which is adjacent forward to requested file('requested' files means the files given in --select-file option) if they share a same piece. This fixes long pause in the file system which doesn't support sparse files like FAT32 while downloading. * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/FileEntry.{h, cc} Removed unused _option. * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc * src/DefaultPieceStorage.cc Set the default value of --seed-ratio to 1.0. If 0.0 is given, then seeding continues regardless of share ratio. * src/version_usage.cc * src/option_processing.cc * src/BtSetup.cc * doc/aria2c.1.txt * doc/aria2c.1 Fixed: Selective download is not working in BitTorrent * src/RequestGroup.cc Introduced Sequence class. Use this instead of Util::unfoldRange() * src/PieceStorage.h * test/MockPieceStorage.h * src/UnknownLengthPieceStorage.h * src/DefaultPieceStorage.{h, cc} * src/Metalink2RequestGroup.cc * src/RequestGroup.cc * src/Sequence.h * test/SequenceTest.cc * src/IntSequence.h * src/message.h * src/Util.{h, cc} * test/UtilTest.cc Added new function 'parse' to catch exception thrown by subclass's parseArg * src/OptionHandler.h * src/OptionParser.cc * src/NameMatchOptionHandler.h * src/OptionHandlerImpl.h * test/OptionHandlerTest.cc Added IntegerRangeOptionHandler. Used for --listen-port and --select-file. Now --listen-port accepts range of port. * src/OptionHandlerFactory.cc * src/version_usage.cc * src/OptionHandlerImpl.h * src/option_processing.cc * src/BtSetup.cc * src/PeerListenCommand.{h, cc} * doc/aria2c.1.txt * doc/aria2c.1 Implemented operator< for Exception class to provide easy way to print exception stack trace. * src/Exception.{h, cc} * src/main.cc * src/option_processing.cc
2007-11-21 16:14:40 +00:00
};
class NumberOptionHandler : public NameMatchOptionHandler {
private:
int64_t min_;
int64_t max_;
public:
NumberOptionHandler(const std::string& optName,
const std::string& description = NO_DESCRIPTION,
const std::string& defaultValue = NO_DEFAULT_VALUE,
int64_t min = -1,
int64_t max = -1,
char shortName = 0);
virtual ~NumberOptionHandler();
virtual void parseArg(Option& option, const std::string& optarg);
void parseArg(Option& option, int64_t number);
virtual std::string createPossibleValuesString() const;
};
class UnitNumberOptionHandler : public NumberOptionHandler {
public:
UnitNumberOptionHandler(const std::string& optName,
const std::string& description = NO_DESCRIPTION,
const std::string& defaultValue = NO_DEFAULT_VALUE,
int64_t min = -1,
int64_t max = -1,
char shortName = 0);
virtual ~UnitNumberOptionHandler();
virtual void parseArg(Option& option, const std::string& optarg);
};
class FloatNumberOptionHandler : public NameMatchOptionHandler {
private:
double min_;
double max_;
public:
FloatNumberOptionHandler(const std::string& optName,
const std::string& description = NO_DESCRIPTION,
const std::string& defaultValue = NO_DEFAULT_VALUE,
double min = -1, double max = -1,
char shortName = 0);
virtual ~FloatNumberOptionHandler();
virtual void parseArg(Option& option, const std::string& optarg);
virtual std::string createPossibleValuesString() const;
};
class DefaultOptionHandler : public NameMatchOptionHandler {
private:
std::string possibleValuesString_;
public:
DefaultOptionHandler(const std::string& optName,
const std::string& description = NO_DESCRIPTION,
const std::string& defaultValue = NO_DEFAULT_VALUE,
const std::string& possibleValuesString = A2STR::NIL,
OptionHandler::ARG_TYPE argType = OptionHandler::REQ_ARG,
char shortName = 0);
virtual ~DefaultOptionHandler();
virtual void parseArg(Option& option, const std::string& optarg);
virtual std::string createPossibleValuesString() const;
};
class CumulativeOptionHandler : public NameMatchOptionHandler {
private:
std::string delim_;
std::string possibleValuesString_;
public:
CumulativeOptionHandler(const std::string& optName,
const std::string& description,
const std::string& defaultValue,
const std::string& delim,
const std::string& possibleValuesString = A2STR::NIL,
OptionHandler::ARG_TYPE argType =
OptionHandler::REQ_ARG,
char shortName = 0);
virtual ~CumulativeOptionHandler();
virtual void parseArg(Option& option, const std::string& optarg);
virtual std::string createPossibleValuesString() const;
};
class IndexOutOptionHandler : public NameMatchOptionHandler {
private:
public:
IndexOutOptionHandler(const std::string& optName,
const std::string& description,
char shortName = 0);
virtual ~IndexOutOptionHandler();
virtual void parseArg(Option& option, const std::string& optarg);
virtual std::string createPossibleValuesString() const;
};
class ParameterOptionHandler : public NameMatchOptionHandler {
private:
std::vector<std::string> validParamValues_;
public:
ParameterOptionHandler(const std::string& optName,
const std::string& description,
const std::string& defaultValue,
const std::vector<std::string>& validParamValues,
char shortName = 0);
ParameterOptionHandler(const std::string& optName,
const std::string& description,
const std::string& defaultValue,
const std::string& validParamValue,
char shortName = 0);
ParameterOptionHandler(const std::string& optName,
const std::string& description,
const std::string& defaultValue,
const std::string& validParamValue1,
const std::string& validParamValue2,
char shortName = 0);
ParameterOptionHandler(const std::string& optName,
const std::string& description,
const std::string& defaultValue,
const std::string& validParamValue1,
const std::string& validParamValue2,
const std::string& validParamValue3,
char shortName = 0);
virtual ~ParameterOptionHandler();
virtual void parseArg(Option& option, const std::string& optarg);
virtual std::string createPossibleValuesString() const;
};
class HostPortOptionHandler : public NameMatchOptionHandler {
private:
std::string hostOptionName_;
std::string portOptionName_;
public:
HostPortOptionHandler(const std::string& optName,
const std::string& description,
const std::string& defaultValue,
const std::string& hostOptionName,
const std::string& portOptionName,
char shortName = 0);
virtual ~HostPortOptionHandler();
virtual void parseArg(Option& option, const std::string& optarg);
2010-08-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> Added IPv6 DHT. Added --dht-entry-porint6, --dht-file-path6, --dht-listen-addr6 and --enable-dht6 option. IPv6 DHT is disabled by default. To use IPv6 DHT, you need to use --enable-dht6 and specify a global unicast address to --dht-listen-addr6. IPv6 DHT is highly experimental. * src/BtSetup.cc * src/DHTAutoSaveCommand.cc * src/DHTAutoSaveCommand.h * src/DHTConnectionImpl.cc * src/DHTConnectionImpl.h * src/DHTEntryPointNameResolveCommand.cc * src/DHTFindNodeReplyMessage.cc * src/DHTFindNodeReplyMessage.h * src/DHTGetPeersMessage.cc * src/DHTGetPeersReplyMessage.cc * src/DHTGetPeersReplyMessage.h * src/DHTMessageFactory.h * src/DHTMessageFactoryImpl.cc * src/DHTMessageFactoryImpl.h * src/DHTMessageTracker.cc * src/DHTRegistry.cc * src/DHTRegistry.h * src/DHTRoutingTableDeserializer.cc * src/DHTRoutingTableDeserializer.h * src/DHTRoutingTableSerializer.cc * src/DHTRoutingTableSerializer.h * src/DHTSetup.cc * src/DHTSetup.h * src/FtpConnection.cc * src/LpdMessageReceiver.cc * src/OptionHandlerFactory.cc * src/OptionHandlerImpl.h * src/PeerInteractionCommand.cc * src/RequestGroup.cc * src/SocketCore.cc * src/SocketCore.h * src/bittorrent_helper.cc * src/bittorrent_helper.h * src/prefs.cc * src/prefs.h * src/usage_text.h * test/DHTConnectionImplTest.cc * test/DHTFindNodeReplyMessageTest.cc * test/DHTGetPeersMessageTest.cc * test/DHTGetPeersReplyMessageTest.cc * test/DHTMessageFactoryImplTest.cc * test/DHTRoutingTableDeserializerTest.cc * test/DHTRoutingTableSerializerTest.cc * test/LpdMessageDispatcherTest.cc * test/MockDHTMessageFactory.h
2010-08-07 14:15:21 +00:00
void setHostAndPort
(Option& option, const std::string& hostname, uint16_t port);
virtual std::string createPossibleValuesString() const;
};
class HttpProxyUserOptionHandler:public NameMatchOptionHandler {
public:
HttpProxyUserOptionHandler(const std::string& optName,
const std::string& description,
const std::string& defaultValue,
char shortName = 0);
virtual void parseArg(Option& option, const std::string& optarg);
virtual std::string createPossibleValuesString() const;
};
class HttpProxyPasswdOptionHandler:public NameMatchOptionHandler {
public:
HttpProxyPasswdOptionHandler(const std::string& optName,
const std::string& description,
const std::string& defaultValue,
char shortName = 0);
virtual void parseArg(Option& option, const std::string& optarg);
virtual std::string createPossibleValuesString() const;
};
class HttpProxyOptionHandler : public NameMatchOptionHandler {
private:
std::string proxyUserPref_;
std::string proxyPasswdPref_;
public:
HttpProxyOptionHandler(const std::string& optName,
const std::string& description,
const std::string& defaultValue,
char shortName = 0);
virtual ~HttpProxyOptionHandler();
virtual void parseArg(Option& option, const std::string& optarg);
virtual std::string createPossibleValuesString() const;
};
class LocalFilePathOptionHandler : public NameMatchOptionHandler {
private:
bool acceptStdin_;
public:
LocalFilePathOptionHandler
(const std::string& optName,
const std::string& description = NO_DESCRIPTION,
const std::string& defaultValue = NO_DEFAULT_VALUE,
bool acceptStdin = false,
char shortName = 0);
virtual void parseArg(Option& option, const std::string& optarg);
virtual std::string createPossibleValuesString() const;
};
class PrioritizePieceOptionHandler:public NameMatchOptionHandler {
public:
PrioritizePieceOptionHandler
(const std::string& optName,
const std::string& description = NO_DESCRIPTION,
const std::string& defaultValue = NO_DEFAULT_VALUE,
char shortName = 0);
virtual void parseArg(Option& option, const std::string& optarg);
virtual std::string createPossibleValuesString() const;
};
} // namespace aria2
#endif // D_OPTION_HANDLER_IMPL_H