aria2/src/option_processing.cc

651 lines
22 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 --> */
#include "common.h"
#include "Option.h"
#include "prefs.h"
#include "OptionParser.h"
#include "OptionHandlerFactory.h"
#include "OptionHandler.h"
#include "Util.h"
#include "message.h"
2007-11-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Don't connect server before checking file integrity at startup, if filesize and output file path are known. * src/AbstractCommand.cc * src/StreamFileAllocationEntry.cc * src/Metalink2RequestGroup.cc * src/RequestGroup.{h, cc} * src/HttpResponseCommand.cc * src/FtpNegotiationCommand.cc Added DownloadFailureException. If it is thrown, RequestGroup should halt. * src/AbstractCommand.cc * src/DownloadFailureException.h * src/RequestGroup.cc Catch RecoverableException, instead of DlAbortEx. * src/RequestGroupMan.cc * src/FillRequestGroupCommand.cc * src/MetaFileUtil.cc * src/IteratableChunkChecksumValidator.cc Now first parameter of MSG_DOWNLOAD_ABORTED is gid(RequestGroup:: getGID()) * src/CheckIntegrityCommand.cc * src/message.h Print gid instead of idx. * src/RequestGroupMan.cc Removed exception throwers declaration. * src/DirectDiskAdaptor.{h, cc} * src/SocketCore.{h, cc} * src/MultiDiskAdaptor.{h, cc} * src/HttpConnection.{h, cc} * src/HttpResponse.{h, cc} * src/DiskAdaptor.{h, cc} * src/CopyDiskAdaptor.{h, cc} * src/MultiDiskAdaptor.{h, cc} * src/HttpHeaderProcessor.{h, cc} * src/AbstractSingleDiskAdaptor.{h, cc} * src/Util.{h, cc} * test/UtilTest.cc * src/DefaultDiskWriter.{h, cc} * src/FtpConnection.{h, cc} * src/AbstractDiskWriter.{h, cc} Removed duplicate code. * src/StreamCheckIntegrityEntry.cc Removed unnecessary include. * src/DiskWriter.h Included Exception.h * src/option_processing.cc Included 2 files and added doc * src/TrackerWatcherCommand.cc * src/SocketCore.cc (writeData): Fixed send error with GnuTLS.
2007-11-09 18:01:12 +00:00
#include "Exception.h"
#include "a2io.h"
#include "help_tags.h"
#include "File.h"
#include "StringFormat.h"
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <sstream>
#include <iostream>
extern char* optarg;
extern int optind, opterr, optopt;
#include <getopt.h>
namespace aria2 {
extern void showVersion();
extern void showUsage(const std::string& category, const Option* option);
static std::string toBoolArg(const char* optarg)
{
std::string arg;
if(!optarg || strlen(optarg) == 0) {
arg = V_TRUE;
} else {
arg = optarg;
}
return arg;
}
Option* createDefaultOption()
{
Option* op = new Option();
op->put(PREF_STDOUT_LOG, V_FALSE);
op->put(PREF_DIR, ".");
op->put(PREF_SPLIT, "5");
op->put(PREF_DAEMON, V_FALSE);
op->put(PREF_SEGMENT_SIZE, Util::itos((int32_t)(1024*1024)));
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
op->put(PREF_LISTEN_PORT, "6881-6999");
op->put(PREF_METALINK_SERVERS, "5");
op->put(PREF_FOLLOW_TORRENT,
#ifdef ENABLE_BITTORRENT
V_TRUE
#else
V_FALSE
#endif // ENABLE_BITTORRENT
);
op->put(PREF_FOLLOW_METALINK,
#ifdef ENABLE_METALINK
V_TRUE
#else
V_FALSE
#endif // ENABLE_METALINK
);
op->put(PREF_RETRY_WAIT, "5");
op->put(PREF_TIMEOUT, "60");
op->put(PREF_DNS_TIMEOUT, "30");
op->put(PREF_CONNECT_TIMEOUT, "60");
op->put(PREF_PEER_CONNECTION_TIMEOUT, "20");
op->put(PREF_BT_TIMEOUT, "180");
op->put(PREF_BT_REQUEST_TIMEOUT, "60");
op->put(PREF_BT_KEEP_ALIVE_INTERVAL, "120");
op->put(PREF_MIN_SEGMENT_SIZE, "1048576");// 1M
op->put(PREF_MAX_TRIES, "5");
op->put(PREF_HTTP_AUTH_SCHEME, V_BASIC);
op->put(PREF_HTTP_PROXY_METHOD, V_TUNNEL);
op->put(PREF_FTP_TYPE, V_BINARY);
op->put(PREF_FTP_VIA_HTTP_PROXY, V_TUNNEL);
op->put(PREF_AUTO_SAVE_INTERVAL, "60");
op->put(PREF_DIRECT_FILE_MAPPING, V_TRUE);
op->put(PREF_LOWEST_SPEED_LIMIT, "0");
op->put(PREF_MAX_DOWNLOAD_LIMIT, "0");
op->put(PREF_MAX_UPLOAD_LIMIT, "0");
op->put(PREF_STARTUP_IDLE_TIME, "10");
op->put(PREF_TRACKER_MAX_TRIES, "10");
op->put(PREF_FILE_ALLOCATION, V_PREALLOC);
op->put(PREF_NO_FILE_ALLOCATION_LIMIT, "5242880"); // 5MiB
op->put(PREF_ALLOW_OVERWRITE, V_FALSE);
op->put(PREF_REALTIME_CHUNK_CHECKSUM, V_TRUE);
op->put(PREF_CHECK_INTEGRITY, V_FALSE);
op->put(PREF_NETRC_PATH, Util::getHomeDir()+"/.netrc");
op->put(PREF_CONTINUE, V_FALSE);
op->put(PREF_USER_AGENT, "aria2");
op->put(PREF_NO_NETRC, V_FALSE);
op->put(PREF_MAX_CONCURRENT_DOWNLOADS, "5");
op->put(PREF_DIRECT_DOWNLOAD_TIMEOUT, "300");
op->put(PREF_FORCE_SEQUENTIAL, V_FALSE);
op->put(PREF_AUTO_FILE_RENAMING, V_TRUE);
op->put(PREF_PARAMETERIZED_URI, V_FALSE);
op->put(PREF_ENABLE_HTTP_KEEP_ALIVE, V_TRUE);
op->put(PREF_ENABLE_HTTP_PIPELINING, V_FALSE);
op->put(PREF_MAX_HTTP_PIPELINING, "2");
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
op->put(PREF_SEED_RATIO, "1.0");
op->put(PREF_ENABLE_DIRECT_IO, V_FALSE);
op->put(PREF_ALLOW_PIECE_LENGTH_CHANGE, V_FALSE);
op->put(PREF_METALINK_PREFERRED_PROTOCOL, V_NONE);
op->put(PREF_METALINK_ENABLE_UNIQUE_PROTOCOL, V_TRUE);
op->put(PREF_ENABLE_PEER_EXCHANGE, V_TRUE);
op->put(PREF_ENABLE_DHT, V_FALSE);
op->put(PREF_DHT_LISTEN_PORT, "6881-6999");
op->put(PREF_DHT_FILE_PATH, Util::getHomeDir()+"/.aria2/dht.dat");
op->put(PREF_BT_MIN_CRYPTO_LEVEL, V_PLAIN);
op->put(PREF_BT_REQUIRE_CRYPTO, V_FALSE);
op->put(PREF_BT_REQUEST_PEER_SPEED_LIMIT, "51200");
op->put(PREF_BT_MAX_OPEN_FILES, "100");
op->put(PREF_BT_SEED_UNVERIFIED, V_FALSE);
op->put(PREF_QUIET, V_FALSE);
op->put(PREF_STOP, "0");
#ifdef ENABLE_ASYNC_DNS
op->put(PREF_ASYNC_DNS, V_TRUE);
#else
op->put(PREF_ASYNC_DNS, V_FALSE);
#endif // ENABLE_ASYNC_DNS
op->put(PREF_FTP_REUSE_CONNECTION, V_TRUE);
op->put(PREF_SUMMARY_INTERVAL, "60");
op->put(PREF_LOG_LEVEL, V_DEBUG);
op->put(PREF_URI_SELECTOR, V_INORDER);
op->put(PREF_SERVER_STAT_TIMEOUT, "86400");// 1day
op->put(PREF_REMOTE_TIME, V_FALSE);
op->put(PREF_MAX_FILE_NOT_FOUND, "0");
return op;
}
Option* option_processing(int argc, char* const argv[])
{
std::stringstream cmdstream;
int32_t c;
Option* op = createDefaultOption();
// following options are not parsed by OptionHandler and not stored in Option.
bool noConf = false;
std::string defaultCfname = Util::getHomeDir()+"/.aria2/aria2.conf";
std::string ucfname;
while(1) {
int optIndex = 0;
int lopt;
static struct option longOpts[] = {
#ifdef HAVE_DAEMON
{ PREF_DAEMON.c_str(), no_argument, NULL, 'D' },
#endif // HAVE_DAEMON
{ PREF_DIR.c_str(), required_argument, NULL, 'd' },
{ PREF_OUT.c_str(), required_argument, NULL, 'o' },
{ PREF_LOG.c_str(), required_argument, NULL, 'l' },
{ PREF_SPLIT.c_str(), required_argument, NULL, 's' },
{ PREF_TIMEOUT.c_str(), required_argument, NULL, 't' },
{ PREF_MAX_TRIES.c_str(), required_argument, NULL, 'm' },
{ PREF_HTTP_PROXY.c_str(), required_argument, &lopt, 1 },
{ PREF_HTTP_USER.c_str(), required_argument, &lopt, 2 },
{ PREF_HTTP_PASSWD.c_str(), required_argument, &lopt, 3 },
{ PREF_HTTP_PROXY_USER.c_str(), required_argument, &lopt, 4 },
{ PREF_HTTP_PROXY_PASSWD.c_str(), required_argument, &lopt, 5 },
{ PREF_HTTP_AUTH_SCHEME.c_str(), required_argument, &lopt, 6 },
{ PREF_REFERER.c_str(), required_argument, &lopt, 7 },
{ PREF_RETRY_WAIT.c_str(), required_argument, &lopt, 8 },
{ PREF_FTP_USER.c_str(), required_argument, &lopt, 9 },
{ PREF_FTP_PASSWD.c_str(), required_argument, &lopt, 10 },
{ PREF_FTP_TYPE.c_str(), required_argument, &lopt, 11 },
{ PREF_FTP_PASV.c_str(), no_argument, NULL, 'p' },
{ PREF_FTP_VIA_HTTP_PROXY.c_str(), required_argument, &lopt, 12 },
//{ PREF_MIN_SEGMENT_SIZE.c_str(), required_argument, &lopt, 13 },
{ PREF_HTTP_PROXY_METHOD.c_str(), required_argument, &lopt, 14 },
{ PREF_LOWEST_SPEED_LIMIT.c_str(), required_argument, &lopt, 200 },
{ PREF_MAX_DOWNLOAD_LIMIT.c_str(), required_argument, &lopt, 201 },
{ PREF_FILE_ALLOCATION.c_str(), required_argument, 0, 'a' },
{ PREF_ALLOW_OVERWRITE.c_str(), required_argument, &lopt, 202 },
#ifdef ENABLE_MESSAGE_DIGEST
{ PREF_CHECK_INTEGRITY.c_str(), required_argument, &lopt, 203 },
{ PREF_REALTIME_CHUNK_CHECKSUM.c_str(), required_argument, &lopt, 204 },
#endif // ENABLE_MESSAGE_DIGEST
{ PREF_CONTINUE.c_str(), no_argument, 0, 'c' },
{ PREF_USER_AGENT.c_str(), required_argument, 0, 'U' },
{ PREF_NO_NETRC.c_str(), no_argument, 0, 'n' },
{ PREF_INPUT_FILE.c_str(), required_argument, 0, 'i' },
{ PREF_MAX_CONCURRENT_DOWNLOADS.c_str(), required_argument, 0, 'j' },
{ PREF_LOAD_COOKIES.c_str(), required_argument, &lopt, 205 },
{ PREF_FORCE_SEQUENTIAL.c_str(), optional_argument, 0, 'Z' },
{ PREF_AUTO_FILE_RENAMING.c_str(), optional_argument, &lopt, 206 },
{ PREF_PARAMETERIZED_URI.c_str(), optional_argument, 0, 'P' },
{ PREF_ENABLE_HTTP_KEEP_ALIVE.c_str(), optional_argument, &lopt, 207 },
{ PREF_ENABLE_HTTP_PIPELINING.c_str(), optional_argument, &lopt, 208 },
{ PREF_NO_FILE_ALLOCATION_LIMIT.c_str(), required_argument, &lopt, 209 },
#ifdef ENABLE_DIRECT_IO
{ PREF_ENABLE_DIRECT_IO.c_str(), optional_argument, &lopt, 210 },
#endif // ENABLE_DIRECT_IO
{ PREF_ALLOW_PIECE_LENGTH_CHANGE.c_str(), required_argument, &lopt, 211 },
{ PREF_NO_CONF.c_str(), no_argument, &lopt, 212 },
{ PREF_CONF_PATH.c_str(), required_argument, &lopt, 213 },
{ PREF_STOP.c_str(), required_argument, &lopt, 214 },
{ PREF_HEADER.c_str(), required_argument, &lopt, 215 },
{ PREF_QUIET.c_str(), optional_argument, 0, 'q' },
#ifdef ENABLE_ASYNC_DNS
{ PREF_ASYNC_DNS.c_str(), optional_argument, &lopt, 216 },
#endif // ENABLE_ASYNC_DNS
{ PREF_FTP_REUSE_CONNECTION.c_str(), optional_argument, &lopt, 217 },
{ PREF_SUMMARY_INTERVAL.c_str(), required_argument, &lopt, 218 },
{ PREF_LOG_LEVEL.c_str(), required_argument, &lopt, 219 },
{ PREF_URI_SELECTOR.c_str(), required_argument, &lopt, 220 },
{ PREF_SERVER_STAT_IF.c_str(), required_argument, &lopt, 221 },
{ PREF_SERVER_STAT_OF.c_str(), required_argument, &lopt, 222 },
{ PREF_SERVER_STAT_TIMEOUT.c_str(), required_argument, &lopt, 223 },
{ PREF_REMOTE_TIME.c_str(), optional_argument, 0, 'R' },
{ PREF_CONNECT_TIMEOUT.c_str(), required_argument, &lopt, 224 },
{ PREF_MAX_FILE_NOT_FOUND.c_str(), required_argument, &lopt, 225 },
#if defined ENABLE_BITTORRENT || defined ENABLE_METALINK
{ PREF_SHOW_FILES.c_str(), no_argument, NULL, 'S' },
{ PREF_SELECT_FILE.c_str(), required_argument, &lopt, 21 },
#endif // ENABLE_BITTORRENT || ENABLE_METALINK
#ifdef ENABLE_BITTORRENT
{ PREF_TORRENT_FILE.c_str(), required_argument, NULL, 'T' },
{ PREF_LISTEN_PORT.c_str(), required_argument, &lopt, 15 },
{ PREF_FOLLOW_TORRENT.c_str(), required_argument, &lopt, 16 },
{ PREF_NO_PREALLOCATION.c_str(), no_argument, &lopt, 18 },
{ PREF_DIRECT_FILE_MAPPING.c_str(), required_argument, &lopt, 19 },
// TODO remove upload-limit.
//{ "upload-limit".c_str(), required_argument, &lopt, 20 },
{ PREF_SEED_TIME.c_str(), required_argument, &lopt, 22 },
{ PREF_SEED_RATIO.c_str(), required_argument, &lopt, 23 },
{ PREF_MAX_UPLOAD_LIMIT.c_str(), required_argument, &lopt, 24 },
{ PREF_PEER_ID_PREFIX.c_str(), required_argument, &lopt, 25 },
{ PREF_ENABLE_PEER_EXCHANGE.c_str(), optional_argument, &lopt, 26 },
{ PREF_ENABLE_DHT.c_str(), optional_argument, &lopt, 27 },
{ PREF_DHT_LISTEN_PORT.c_str(), required_argument, &lopt, 28 },
{ PREF_DHT_ENTRY_POINT.c_str(), required_argument, &lopt, 29 },
{ PREF_BT_MIN_CRYPTO_LEVEL.c_str(), required_argument, &lopt, 30 },
{ PREF_BT_REQUIRE_CRYPTO.c_str(), required_argument, &lopt, 31 },
{ PREF_BT_REQUEST_PEER_SPEED_LIMIT.c_str(), required_argument, &lopt, 32 },
{ PREF_BT_MAX_OPEN_FILES.c_str(), required_argument, &lopt, 33 },
{ PREF_BT_SEED_UNVERIFIED.c_str(), optional_argument, &lopt, 34 },
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
{ PREF_METALINK_FILE.c_str(), required_argument, NULL, 'M' },
{ PREF_METALINK_SERVERS.c_str(), required_argument, NULL, 'C' },
{ PREF_METALINK_VERSION.c_str(), required_argument, &lopt, 100 },
{ PREF_METALINK_LANGUAGE.c_str(), required_argument, &lopt, 101 },
{ PREF_METALINK_OS.c_str(), required_argument, &lopt, 102 },
{ PREF_FOLLOW_METALINK.c_str(), required_argument, &lopt, 103 },
{ PREF_METALINK_LOCATION.c_str(), required_argument, &lopt, 104 },
{ PREF_METALINK_PREFERRED_PROTOCOL.c_str(), required_argument, &lopt, 105 },
{ PREF_METALINK_ENABLE_UNIQUE_PROTOCOL.c_str(), optional_argument, &lopt, 106 },
#endif // ENABLE_METALINK
{ "version", no_argument, NULL, 'v' },
{ "help", optional_argument, NULL, 'h' },
{ 0, 0, 0, 0 }
};
c = getopt_long(argc, argv,
"Dd:o:l:s:pt:m:vh::ST:M:C:a:cU:ni:j:Z::P::q::R::",
longOpts, &optIndex);
if(c == -1) {
break;
}
switch(c) {
case 0:{
switch(lopt) {
case 1:
cmdstream << PREF_HTTP_PROXY << "=" << optarg << "\n";
break;
case 2:
cmdstream << PREF_HTTP_USER << "=" << optarg << "\n";
break;
case 3:
cmdstream << PREF_HTTP_PASSWD << "=" << optarg << "\n";
break;
case 4:
cmdstream << PREF_HTTP_PROXY_USER << "=" << optarg << "\n";
break;
case 5:
cmdstream << PREF_HTTP_PROXY_PASSWD << "=" << optarg << "\n";
break;
case 6:
cmdstream << PREF_HTTP_AUTH_SCHEME << "=" << optarg << "\n";
break;
case 7:
cmdstream << PREF_REFERER << "=" << optarg << "\n";
break;
case 8:
cmdstream << PREF_RETRY_WAIT << "=" << optarg << "\n";
break;
case 9:
cmdstream << PREF_FTP_USER << "=" << optarg << "\n";
break;
case 10:
cmdstream << PREF_FTP_PASSWD << "=" << optarg << "\n";
break;
case 11:
cmdstream << PREF_FTP_TYPE << "=" << optarg << "\n";
break;
case 12:
cmdstream << PREF_FTP_VIA_HTTP_PROXY << "=" << optarg << "\n";
break;
case 13:
cmdstream << PREF_MIN_SEGMENT_SIZE << "=" << optarg << "\n";
break;
case 14:
cmdstream << PREF_HTTP_PROXY_METHOD << "=" << optarg << "\n";
break;
case 15:
cmdstream << PREF_LISTEN_PORT << "=" << optarg << "\n";
break;
case 16:
cmdstream << PREF_FOLLOW_TORRENT << "=" << optarg << "\n";
break;
case 18:
cmdstream << PREF_NO_PREALLOCATION << "=" << V_TRUE << "\n";
break;
case 19:
cmdstream << PREF_DIRECT_FILE_MAPPING << "=" << optarg << "\n";
break;
case 21:
cmdstream << PREF_SELECT_FILE << "=" << optarg << "\n";
break;
case 22:
cmdstream << PREF_SEED_TIME << "=" << optarg << "\n";
break;
case 23:
cmdstream << PREF_SEED_RATIO << "=" << optarg << "\n";
break;
case 24:
cmdstream << PREF_MAX_UPLOAD_LIMIT << "=" << optarg << "\n";
break;
case 25:
cmdstream << PREF_PEER_ID_PREFIX << "=" << optarg << "\n";
break;
case 26:
cmdstream << PREF_ENABLE_PEER_EXCHANGE << "=" << toBoolArg(optarg) << "\n";
break;
case 27:
cmdstream << PREF_ENABLE_DHT << "=" << toBoolArg(optarg) << "\n";
break;
case 28:
cmdstream << PREF_DHT_LISTEN_PORT << "=" << optarg << "\n";
break;
case 29:
cmdstream << PREF_DHT_ENTRY_POINT << "=" << optarg << "\n";
break;
case 30:
cmdstream << PREF_BT_MIN_CRYPTO_LEVEL << "=" << optarg << "\n";
break;
case 31:
cmdstream << PREF_BT_REQUIRE_CRYPTO << "=" << optarg << "\n";
break;
case 32:
cmdstream << PREF_BT_REQUEST_PEER_SPEED_LIMIT << "=" << optarg << "\n";
break;
case 33:
cmdstream << PREF_BT_MAX_OPEN_FILES << "=" << optarg << "\n";
break;
case 34:
cmdstream << PREF_BT_SEED_UNVERIFIED << "=" << toBoolArg(optarg)
<< "\n";
break;
case 100:
cmdstream << PREF_METALINK_VERSION << "=" << optarg << "\n";
break;
case 101:
cmdstream << PREF_METALINK_LANGUAGE << "=" << optarg << "\n";
break;
case 102:
cmdstream << PREF_METALINK_OS << "=" << optarg << "\n";
break;
case 103:
cmdstream << PREF_FOLLOW_METALINK << "=" << optarg << "\n";
break;
case 104:
cmdstream << PREF_METALINK_LOCATION << "=" << optarg << "\n";
break;
case 105:
cmdstream << PREF_METALINK_PREFERRED_PROTOCOL << "=" << optarg << "\n";
break;
case 106:
cmdstream << PREF_METALINK_ENABLE_UNIQUE_PROTOCOL << "=" << toBoolArg(optarg) << "\n";
break;
case 200:
cmdstream << PREF_LOWEST_SPEED_LIMIT << "=" << optarg << "\n";
break;
case 201:
cmdstream << PREF_MAX_DOWNLOAD_LIMIT << "=" << optarg << "\n";
break;
case 202:
cmdstream << PREF_ALLOW_OVERWRITE << "=" << optarg << "\n";
break;
case 203:
cmdstream << PREF_CHECK_INTEGRITY << "=" << optarg << "\n";
break;
case 204:
cmdstream << PREF_REALTIME_CHUNK_CHECKSUM << "=" << optarg << "\n";
break;
case 205:
cmdstream << PREF_LOAD_COOKIES << "=" << optarg << "\n";
break;
case 206:
cmdstream << PREF_AUTO_FILE_RENAMING << "=" << toBoolArg(optarg) << "\n";
break;
case 207:
cmdstream << PREF_ENABLE_HTTP_KEEP_ALIVE << "=" << toBoolArg(optarg) << "\n";
break;
case 208:
cmdstream << PREF_ENABLE_HTTP_PIPELINING << "=" << toBoolArg(optarg) << "\n";
break;
case 209:
cmdstream << PREF_NO_FILE_ALLOCATION_LIMIT << "=" << optarg << "\n";
break;
case 210:
cmdstream << PREF_ENABLE_DIRECT_IO << "=" << toBoolArg(optarg) << "\n";
break;
case 211:
cmdstream << PREF_ALLOW_PIECE_LENGTH_CHANGE << "=" << optarg << "\n";
break;
case 212:
noConf = true;
break;
case 213:
ucfname = optarg;
break;
case 214:
cmdstream << PREF_STOP << "=" << optarg << "\n";
break;
case 215:
cmdstream << PREF_HEADER << "=" << optarg << "\n";
break;
#ifdef ENABLE_ASYNC_DNS
case 216:
cmdstream << PREF_ASYNC_DNS << "=" << toBoolArg(optarg) << "\n";
break;
#endif // ENABLE_ASYNC_DNS
case 217:
cmdstream << PREF_FTP_REUSE_CONNECTION << "=" << toBoolArg(optarg) << "\n";
break;
case 218:
cmdstream << PREF_SUMMARY_INTERVAL << "=" << optarg << "\n";
break;
case 219:
cmdstream << PREF_LOG_LEVEL << "=" << optarg << "\n";
break;
case 220:
cmdstream << PREF_URI_SELECTOR << "=" << optarg << "\n";
break;
case 221:
cmdstream << PREF_SERVER_STAT_IF << "=" << optarg << "\n";
break;
case 222:
cmdstream << PREF_SERVER_STAT_OF << "=" << optarg << "\n";
break;
case 223:
cmdstream << PREF_SERVER_STAT_TIMEOUT << "=" << optarg << "\n";
break;
case 224:
cmdstream << PREF_CONNECT_TIMEOUT << "=" << optarg << "\n";
break;
case 225:
cmdstream << PREF_MAX_FILE_NOT_FOUND << "=" << optarg << "\n";
break;
}
break;
}
#ifdef HAVE_DAEMON
case 'D':
cmdstream << PREF_DAEMON << "=" << V_TRUE << "\n";
break;
#endif // HAVE_DAEMON
case 'd':
cmdstream << PREF_DIR << "=" << optarg << "\n";
break;
case 'o':
cmdstream << PREF_OUT << "=" << optarg << "\n";
break;
case 'l':
cmdstream << PREF_LOG << "=" << optarg << "\n";
break;
case 's':
cmdstream << PREF_SPLIT << "=" << optarg << "\n";
break;
case 't':
cmdstream << PREF_TIMEOUT << "=" << optarg << "\n";
break;
case 'm':
cmdstream << PREF_MAX_TRIES << "=" << optarg << "\n";
break;
case 'p':
cmdstream << PREF_FTP_PASV << "=" << V_TRUE << "\n";
break;
case 'S':
cmdstream << PREF_SHOW_FILES << "=" << V_TRUE << "\n";
break;
case 'T':
cmdstream << PREF_TORRENT_FILE << "=" << optarg << "\n";
break;
case 'M':
cmdstream << PREF_METALINK_FILE << "=" << optarg << "\n";
break;
case 'C':
cmdstream << PREF_METALINK_SERVERS << "=" << optarg << "\n";
break;
case 'a':
cmdstream << PREF_FILE_ALLOCATION << "=" << optarg << "\n";
break;
case 'c':
cmdstream << PREF_CONTINUE << "=" << V_TRUE << "\n";
break;
case 'U':
cmdstream << PREF_USER_AGENT << "=" << optarg << "\n";
break;
case 'n':
cmdstream << PREF_NO_NETRC << "=" << V_TRUE << "\n";
break;
case 'i':
cmdstream << PREF_INPUT_FILE << "=" << optarg << "\n";
break;
case 'j':
cmdstream << PREF_MAX_CONCURRENT_DOWNLOADS << "=" << optarg << "\n";
break;
case 'Z':
cmdstream << PREF_FORCE_SEQUENTIAL << "=" << toBoolArg(optarg) << "\n";
break;
case 'P':
cmdstream << PREF_PARAMETERIZED_URI << "=" << toBoolArg(optarg) << "\n";
break;
case 'q':
cmdstream << PREF_QUIET << "=" << toBoolArg(optarg) << "\n";
break;
case 'R':
cmdstream << PREF_REMOTE_TIME << "=" << toBoolArg(optarg) << "\n";
break;
case 'v':
showVersion();
exit(EXIT_SUCCESS);
case 'h':
{
std::string category;
if(optarg == 0 || strlen(optarg) == 0) {
category = TAG_BASIC;
} else {
category = optarg;
}
showUsage(category, createDefaultOption());
exit(EXIT_SUCCESS);
}
default:
showUsage(TAG_HELP, op);
exit(EXIT_FAILURE);
}
}
{
OptionParser oparser;
oparser.setOptionHandlers(OptionHandlerFactory::createOptionHandlers());
if(!noConf) {
std::string cfname;
if(ucfname.size()) {
cfname = ucfname;
} else {
cfname = defaultCfname;
}
if(File(cfname).isFile()) {
std::ifstream cfstream(cfname.c_str());
try {
oparser.parse(op, cfstream);
} catch(Exception& e) {
std::cerr << "Parse error in " << cfname << "\n"
<< e.stackTrace() << std::endl;
exit(EXIT_FAILURE);
}
} else if(ucfname.size()) {
std::cout << StringFormat("Configuration file %s is not found.", cfname.c_str())
<< "\n";
}
}
try {
oparser.parse(op, cmdstream);
} catch(Exception& e) {
std::cerr << e.stackTrace() << std::endl;
showUsage(TAG_HELP, op);
exit(EXIT_FAILURE);
}
}
if(op->defined(PREF_HTTP_USER)) {
op->put(PREF_HTTP_AUTH_ENABLED, V_TRUE);
}
if(op->defined(PREF_HTTP_PROXY_USER)) {
op->put(PREF_HTTP_PROXY_AUTH_ENABLED, V_TRUE);
}
if(
#ifdef ENABLE_BITTORRENT
!op->defined(PREF_TORRENT_FILE) &&
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
!op->defined(PREF_METALINK_FILE) &&
#endif // ENABLE_METALINK
!op->defined(PREF_INPUT_FILE)) {
if(optind == argc) {
std::cerr << MSG_URI_REQUIRED << std::endl;
showUsage(TAG_HELP, op);
exit(EXIT_FAILURE);
}
}
#ifdef HAVE_DAEMON
if(op->getAsBool(PREF_DAEMON)) {
if(daemon(1, 1) < 0) {
perror(MSG_DAEMON_FAILED);
exit(EXIT_FAILURE);
}
}
#endif // HAVE_DAEMON
return op;
}
} // namespace aria2