Browse Source

2008-05-19 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Defined option name and possible values as std::string to reduce
	temporary string object creation in runtime.
	* src/HelpItemFactory.cc
	* src/LogFactory.cc
	* src/Option.cc
	* src/OptionHandlerFactory.cc
	* src/option_processing.cc
	* src/prefs.cc
	* src/prefs.h
Tatsuhiro Tsujikawa 17 years ago
parent
commit
0189bbc6bc
10 changed files with 513 additions and 224 deletions
  1. 12 0
      ChangeLog
  2. 3 1
      src/HelpItemFactory.cc
  3. 5 5
      src/LogFactory.cc
  4. 1 1
      src/Makefile.am
  5. 8 6
      src/Makefile.in
  6. 1 6
      src/Option.cc
  7. 3 3
      src/OptionHandlerFactory.cc
  8. 78 78
      src/option_processing.cc
  9. 276 0
      src/prefs.cc
  10. 126 124
      src/prefs.h

+ 12 - 0
ChangeLog

@@ -1,3 +1,15 @@
+2008-05-19  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Defined option name and possible values as std::string to reduce
+	temporary string object creation in runtime.
+	* src/HelpItemFactory.cc
+	* src/LogFactory.cc
+	* src/Option.cc
+	* src/OptionHandlerFactory.cc
+	* src/option_processing.cc
+	* src/prefs.cc
+	* src/prefs.h
+
 2008-05-18  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Return const reference.

+ 3 - 1
src/HelpItemFactory.cc

@@ -483,7 +483,9 @@ TagContainerHandle HelpItemFactory::createHelpItems(const Option* op)
 				     op->get(PREF_LOG_LEVEL)));
     item->addTag(TAG_ADVANCED);
     item->setAvailableValues
-      (StringFormat("%s,%s,%s,%s,%s", V_DEBUG, V_INFO, V_NOTICE, V_WARN, V_ERROR).str());
+      (StringFormat("%s,%s,%s,%s,%s",
+		    V_DEBUG.c_str(), V_INFO.c_str(), V_NOTICE.c_str(),
+		    V_WARN.c_str(), V_ERROR.c_str()).str());
     tc->addItem(item);
   }
   {

+ 5 - 5
src/LogFactory.cc

@@ -67,15 +67,15 @@ void LogFactory::setLogLevel(Logger::LEVEL level)
 
 void LogFactory::setLogLevel(const std::string& level)
 {
-  if(strcmp(level.c_str(), V_DEBUG) == 0) {
+  if(level == V_DEBUG) {
     _logLevel = Logger::DEBUG;
-  } else if(strcmp(level.c_str(), V_INFO) == 0) {
+  } else if(level == V_INFO) {
     _logLevel = Logger::INFO;
-  } else if(strcmp(level.c_str(), V_NOTICE) == 0) {
+  } else if(level == V_NOTICE) {
     _logLevel = Logger::NOTICE;
-  } else if(strcmp(level.c_str(), V_WARN) == 0) {
+  } else if(level == V_WARN) {
     _logLevel = Logger::WARN;
-  } else if(strcmp(level.c_str(), V_ERROR) == 0) {
+  } else if(level == V_ERROR) {
     _logLevel = Logger::ERROR;
   }
 }

+ 1 - 1
src/Makefile.am

@@ -179,7 +179,7 @@ SRCS =  Socket.h\
 	a2time.h\
 	array_fun.h\
 	help_tags.h\
-	prefs.h\
+	prefs.cc prefs.h\
 	usage_text.h\
 	ProtocolDetector.cc ProtocolDetector.h\
 	NullStatCalc.h\

+ 8 - 6
src/Makefile.in

@@ -403,8 +403,8 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
 	DNSCache.h DownloadResult.h Sequence.h IntSequence.h \
 	PostDownloadHandler.h PreDownloadHandler.h SingletonHolder.h \
 	TrueRequestGroupCriteria.h a2algo.h a2functional.h a2io.h \
-	a2netcompat.h a2time.h array_fun.h help_tags.h prefs.h \
-	usage_text.h ProtocolDetector.cc ProtocolDetector.h \
+	a2netcompat.h a2time.h array_fun.h help_tags.h prefs.cc \
+	prefs.h usage_text.h ProtocolDetector.cc ProtocolDetector.h \
 	NullStatCalc.h StringFormat.cc StringFormat.h \
 	HttpSkipResponseCommand.cc HttpSkipResponseCommand.h \
 	InitiateConnectionCommand.cc InitiateConnectionCommand.h \
@@ -790,8 +790,9 @@ am__objects_15 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
 	ByteArrayDiskWriterFactory.$(OBJEXT) ServerHost.$(OBJEXT) \
 	HelpItem.$(OBJEXT) TaggedItem.$(OBJEXT) TagContainer.$(OBJEXT) \
 	HelpItemFactory.$(OBJEXT) SingleFileDownloadContext.$(OBJEXT) \
-	TimedHaltCommand.$(OBJEXT) ProtocolDetector.$(OBJEXT) \
-	StringFormat.$(OBJEXT) HttpSkipResponseCommand.$(OBJEXT) \
+	TimedHaltCommand.$(OBJEXT) prefs.$(OBJEXT) \
+	ProtocolDetector.$(OBJEXT) StringFormat.$(OBJEXT) \
+	HttpSkipResponseCommand.$(OBJEXT) \
 	InitiateConnectionCommand.$(OBJEXT) \
 	FtpFinishDownloadCommand.$(OBJEXT) A2STR.$(OBJEXT) \
 	RarestPieceSelector.$(OBJEXT) $(am__objects_1) \
@@ -1132,8 +1133,8 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \
 	DNSCache.h DownloadResult.h Sequence.h IntSequence.h \
 	PostDownloadHandler.h PreDownloadHandler.h SingletonHolder.h \
 	TrueRequestGroupCriteria.h a2algo.h a2functional.h a2io.h \
-	a2netcompat.h a2time.h array_fun.h help_tags.h prefs.h \
-	usage_text.h ProtocolDetector.cc ProtocolDetector.h \
+	a2netcompat.h a2time.h array_fun.h help_tags.h prefs.cc \
+	prefs.h usage_text.h ProtocolDetector.cc ProtocolDetector.h \
 	NullStatCalc.h StringFormat.cc StringFormat.h \
 	HttpSkipResponseCommand.cc HttpSkipResponseCommand.h \
 	InitiateConnectionCommand.cc InitiateConnectionCommand.h \
@@ -1512,6 +1513,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/messageDigest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/option_processing.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/prefs.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strptime.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timegm.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/version_usage.Po@am__quote@

+ 1 - 6
src/Option.cc

@@ -80,12 +80,7 @@ int64_t Option::getAsLLInt(const std::string& name) const {
 }
 
 bool Option::getAsBool(const std::string& name) const {
-  const std::string& value = get(name);
-  if(strcmp(value.c_str(), V_TRUE) == 0) {
-    return true;
-  } else {
-    return false;
-  }
+  return get(name) == V_TRUE;
 }
 
 double Option::getAsDouble(const std::string& name) const {

+ 3 - 3
src/OptionHandlerFactory.cc

@@ -112,9 +112,9 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
   handlers.push_back(SH(new BooleanOptionHandler(PREF_ENABLE_DIRECT_IO)));
   handlers.push_back(SH(new BooleanOptionHandler(PREF_ALLOW_PIECE_LENGTH_CHANGE)));
   {
-    const char* params[] = { V_HTTP, V_HTTPS, V_FTP, V_NONE };
+    const std::string params[] = { V_HTTP, V_HTTPS, V_FTP, V_NONE };
     handlers.push_back(SH(new ParameterOptionHandler(PREF_METALINK_PREFERRED_PROTOCOL,
-						  std::deque<std::string>(&params[0], &params[arrayLength(params)]))));
+						     std::deque<std::string>(&params[0], &params[arrayLength(params)]))));
   }
   handlers.push_back(SH(new BooleanOptionHandler(PREF_METALINK_ENABLE_UNIQUE_PROTOCOL)));
   handlers.push_back(SH(new BooleanOptionHandler(PREF_ENABLE_PEER_EXCHANGE)));
@@ -134,7 +134,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
   handlers.push_back(SH(new BooleanOptionHandler(PREF_FTP_REUSE_CONNECTION)));
   handlers.push_back(SH(new NumberOptionHandler(PREF_SUMMARY_INTERVAL, 0, INT32_MAX)));
   {
-    const char* params[] = { V_DEBUG, V_INFO, V_NOTICE, V_WARN, V_ERROR };
+    const std::string params[] = { V_DEBUG, V_INFO, V_NOTICE, V_WARN, V_ERROR };
     handlers.push_back(SH(new ParameterOptionHandler
 			  (PREF_LOG_LEVEL,
 			   std::deque<std::string>(&params[0],

+ 78 - 78
src/option_processing.cc

@@ -172,97 +172,97 @@ Option* option_processing(int argc, char* const argv[])
     int lopt;
     static struct option longOpts[] = {
 #ifdef HAVE_DAEMON
-      { PREF_DAEMON, no_argument, NULL, 'D' },
+      { PREF_DAEMON.c_str(), no_argument, NULL, 'D' },
 #endif // HAVE_DAEMON
-      { PREF_DIR, required_argument, NULL, 'd' },
-      { PREF_OUT, required_argument, NULL, 'o' },
-      { PREF_LOG, required_argument, NULL, 'l' },
-      { PREF_SPLIT, required_argument, NULL, 's' },
-      { PREF_TIMEOUT, required_argument, NULL, 't' },
-      { PREF_MAX_TRIES, required_argument, NULL, 'm' },
-      { PREF_HTTP_PROXY, required_argument, &lopt, 1 },
-      { PREF_HTTP_USER, required_argument, &lopt, 2 },
-      { PREF_HTTP_PASSWD, required_argument, &lopt, 3 },
-      { PREF_HTTP_PROXY_USER, required_argument, &lopt, 4 },
-      { PREF_HTTP_PROXY_PASSWD, required_argument, &lopt, 5 },
-      { PREF_HTTP_AUTH_SCHEME, required_argument, &lopt, 6 },
-      { PREF_REFERER, required_argument, &lopt, 7 },
-      { PREF_RETRY_WAIT, required_argument, &lopt, 8 },
-      { PREF_FTP_USER, required_argument, &lopt, 9 },
-      { PREF_FTP_PASSWD, required_argument, &lopt, 10 },
-      { PREF_FTP_TYPE, required_argument, &lopt, 11 },
-      { PREF_FTP_PASV, no_argument, NULL, 'p' },
-      { PREF_FTP_VIA_HTTP_PROXY, required_argument, &lopt, 12 },
-      //{ PREF_MIN_SEGMENT_SIZE, required_argument, &lopt, 13 },
-      { PREF_HTTP_PROXY_METHOD, required_argument, &lopt, 14 },
-      { PREF_LOWEST_SPEED_LIMIT, required_argument, &lopt, 200 },
-      { PREF_MAX_DOWNLOAD_LIMIT, required_argument, &lopt, 201 },
-      { PREF_FILE_ALLOCATION, required_argument, 0, 'a' },
-      { PREF_ALLOW_OVERWRITE, required_argument, &lopt, 202 },
+      { 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, required_argument, &lopt, 203 },
-      { PREF_REALTIME_CHUNK_CHECKSUM, required_argument, &lopt, 204 },
+      { 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, no_argument, 0, 'c' },
-      { PREF_USER_AGENT, required_argument, 0, 'U' },
-      { PREF_NO_NETRC, no_argument, 0, 'n' },
-      { PREF_INPUT_FILE, required_argument, 0, 'i' },
-      { PREF_MAX_CONCURRENT_DOWNLOADS, required_argument, 0, 'j' },
-      { PREF_LOAD_COOKIES, required_argument, &lopt, 205 },
-      { PREF_FORCE_SEQUENTIAL, optional_argument, 0, 'Z' },
-      { PREF_AUTO_FILE_RENAMING, optional_argument, &lopt, 206 },
-      { PREF_PARAMETERIZED_URI, optional_argument, 0, 'P' },
-      { PREF_ENABLE_HTTP_KEEP_ALIVE, optional_argument, &lopt, 207 },
-      { PREF_ENABLE_HTTP_PIPELINING, optional_argument, &lopt, 208 },
-      { PREF_NO_FILE_ALLOCATION_LIMIT, required_argument, &lopt, 209 },
+      { 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, optional_argument, &lopt, 210 },
+      { PREF_ENABLE_DIRECT_IO.c_str(), optional_argument, &lopt, 210 },
 #endif // ENABLE_DIRECT_IO
-      { PREF_ALLOW_PIECE_LENGTH_CHANGE, required_argument, &lopt, 211 },
-      { PREF_NO_CONF, no_argument, &lopt, 212 },
-      { PREF_CONF_PATH, required_argument, &lopt, 213 },
-      { PREF_STOP, required_argument, &lopt, 214 },
-      { PREF_HEADER, required_argument, &lopt, 215 },
-      { PREF_QUIET, optional_argument, 0, 'q' },
+      { 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, optional_argument, &lopt, 216 },
+      { PREF_ASYNC_DNS.c_str(), optional_argument, &lopt, 216 },
 #endif // ENABLE_ASYNC_DNS
-      { PREF_FTP_REUSE_CONNECTION, optional_argument, &lopt, 217 },
-      { PREF_SUMMARY_INTERVAL, required_argument, &lopt, 218 },
-      { PREF_LOG_LEVEL, required_argument, &lopt, 219 },
+      { 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 },
 #if defined ENABLE_BITTORRENT || ENABLE_METALINK
-      { PREF_SHOW_FILES, no_argument, NULL, 'S' },
-      { PREF_SELECT_FILE, required_argument, &lopt, 21 },
+      { 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, required_argument, NULL, 'T' },
-      { PREF_LISTEN_PORT, required_argument, &lopt, 15 },
-      { PREF_FOLLOW_TORRENT, required_argument, &lopt, 16 },
-      { PREF_NO_PREALLOCATION, no_argument, &lopt, 18 },
-      { PREF_DIRECT_FILE_MAPPING, required_argument, &lopt, 19 },
+      { 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", required_argument, &lopt, 20 },
-      { PREF_SEED_TIME, required_argument, &lopt, 22 },
-      { PREF_SEED_RATIO, required_argument, &lopt, 23 },
-      { PREF_MAX_UPLOAD_LIMIT, required_argument, &lopt, 24 },
-      { PREF_PEER_ID_PREFIX, required_argument, &lopt, 25 },
-      { PREF_ENABLE_PEER_EXCHANGE, optional_argument, &lopt, 26 },
-      { PREF_ENABLE_DHT, optional_argument, &lopt, 27 },
-      { PREF_DHT_LISTEN_PORT, required_argument, &lopt, 28 },
-      { PREF_DHT_ENTRY_POINT, required_argument, &lopt, 29 },
-      { PREF_BT_MIN_CRYPTO_LEVEL, required_argument, &lopt, 30 },
-      { PREF_BT_REQUIRE_CRYPTO, required_argument, &lopt, 31 },
+      //{ "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 },
 #endif // ENABLE_BITTORRENT
 #ifdef ENABLE_METALINK
-      { PREF_METALINK_FILE, required_argument, NULL, 'M' },
-      { PREF_METALINK_SERVERS, required_argument, NULL, 'C' },
-      { PREF_METALINK_VERSION, required_argument, &lopt, 100 },
-      { PREF_METALINK_LANGUAGE, required_argument, &lopt, 101 },
-      { PREF_METALINK_OS, required_argument, &lopt, 102 },
-      { PREF_FOLLOW_METALINK, required_argument, &lopt, 103 },
-      { PREF_METALINK_LOCATION, required_argument, &lopt, 104 },
-      { PREF_METALINK_PREFERRED_PROTOCOL, required_argument, &lopt, 105 },
-      { PREF_METALINK_ENABLE_UNIQUE_PROTOCOL, optional_argument, &lopt, 106 },
+      { 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' },

+ 276 - 0
src/prefs.cc

@@ -0,0 +1,276 @@
+/* <!-- 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 "prefs.h"
+
+namespace aria2 {
+
+/**
+ * Constants
+ */
+const std::string V_TRUE("true");
+const std::string V_FALSE("false");
+const std::string V_NONE("none");
+const std::string V_MEM("mem");
+const std::string V_ALL("all");
+/**
+ * General preferences
+ */
+// values: 1*digit
+const std::string PREF_RETRY_WAIT("retry-wait");
+// 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_MAX_TRIES("max-tries");
+// values: 1*digit
+const std::string PREF_MIN_SEGMENT_SIZE("min-segment-size");
+// values: 1*digit
+const std::string PREF_AUTO_SAVE_INTERVAL("auto-save-interval");
+// values: true | false
+const std::string PREF_STDOUT_LOG("stdout-log");
+// 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_SEGMENT_SIZE("segment-size");
+// 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 | none
+const std::string PREF_FILE_ALLOCATION("file-allocation");
+const std::string V_PREALLOC("prealloc");
+#// 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: 1*digit
+const std::string PREF_DIRECT_DOWNLOAD_TIMEOUT("direct-download-timeout");
+// 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_INFO("info");
+const std::string V_NOTICE("notice");
+const std::string V_WARN("warn");
+const std::string V_ERROR("error");
+
+/**
+ * FTP related preferences
+ */
+const std::string PREF_FTP_USER("ftp-user");
+const std::string PREF_FTP_PASSWD("ftp-passwd");
+// values: binary | ascii
+const std::string PREF_FTP_TYPE("ftp-type");
+const std::string V_BINARY("binary");
+const std::string V_ASCII("ascii");
+// values: get | tunnel
+const std::string PREF_FTP_VIA_HTTP_PROXY("ftp-via-http-proxy");
+const std::string V_GET("get");
+const std::string V_TUNNEL("tunnel");
+// values: true | false
+const std::string PREF_FTP_PASV("ftp-pasv");
+// values: true | false
+const std::string PREF_FTP_REUSE_CONNECTION("ftp-reuse-connection");
+
+/**
+ * HTTP related preferences
+ */
+const std::string PREF_HTTP_USER("http-user");
+const std::string PREF_HTTP_PASSWD("http-passwd");
+// values: basic
+const std::string PREF_HTTP_AUTH_SCHEME("http-auth-scheme");
+const std::string V_BASIC("basic");
+// values: true | false
+const std::string PREF_HTTP_AUTH_ENABLED("http-auth-enabled");
+// values: string
+const std::string PREF_USER_AGENT("user-agent");
+// value: string that your file system recognizes as a file name.
+const std::string PREF_LOAD_COOKIES("load-cookies");
+// values: true | false
+const std::string PREF_ENABLE_HTTP_KEEP_ALIVE("enable-http-keep-alive");
+// values: true | false
+const std::string PREF_ENABLE_HTTP_PIPELINING("enable-http-pipelining");
+// value: 1*digit
+const std::string PREF_MAX_HTTP_PIPELINING("max-http-pipelining");
+// value: string
+const std::string PREF_HEADER("header");
+
+/** 
+ * HTTP proxy related preferences
+ */
+const std::string PREF_HTTP_PROXY("http-proxy");
+const std::string PREF_HTTP_PROXY_USER("http-proxy-user");
+const std::string PREF_HTTP_PROXY_PASSWD("http-proxy-passwd");
+const std::string PREF_HTTP_PROXY_HOST("http-proxy-host");
+const std::string PREF_HTTP_PROXY_PORT("http-proxy-port");
+// values: get | tunnel
+const std::string PREF_HTTP_PROXY_METHOD("http-proxy-method");
+// values: true | false
+const std::string PREF_HTTP_PROXY_ENABLED("http-proxy-enabled");
+// values: true | false
+const std::string PREF_HTTP_PROXY_AUTH_ENABLED("http-proxy-auth-enabled");
+
+/**
+ * BitTorrent related preferences
+ */
+// values: 1*digit
+const std::string PREF_PEER_CONNECTION_TIMEOUT("peer-connection-timeout");
+// values: 1*digit
+const std::string PREF_BT_TIMEOUT("bt-timeout");
+// values: 1*digit
+const std::string PREF_BT_REQUEST_TIMEOUT("bt-request-timeout");
+// values: true | false
+const std::string PREF_SHOW_FILES("show-files");
+// values: true | false
+const std::string PREF_NO_PREALLOCATION("no-preallocation");
+// values: true | false
+const std::string PREF_DIRECT_FILE_MAPPING("direct-file-mapping");
+// values: 1*digit
+const std::string PREF_MAX_UPLOAD_LIMIT("max-upload-limit");
+// values: a string that your file system recognizes as a file name.
+const std::string PREF_TORRENT_FILE("torrent-file");
+// values: 1*digit
+const std::string PREF_LISTEN_PORT("listen-port");
+// values: true | false | mem
+const std::string PREF_FOLLOW_TORRENT("follow-torrent");
+// values: 1*digit *( (,|-) 1*digit);
+const std::string PREF_SELECT_FILE("select-file");
+// values: 1*digit
+const std::string PREF_SEED_TIME("seed-time");
+// values: 1*digit ['.' [ 1*digit ] ]
+const std::string PREF_SEED_RATIO("seed-ratio");
+// values: 1*digit
+const std::string PREF_TRACKER_MAX_TRIES("tracker-max-tries");
+// values: 1*digit
+const std::string PREF_BT_KEEP_ALIVE_INTERVAL("bt-keep-alive-interval");
+// values: a string, less than or equals to 20 bytes length
+const std::string PREF_PEER_ID_PREFIX("peer-id-prefix");
+// values: true | false
+const std::string PREF_ENABLE_PEER_EXCHANGE("enable-peer-exchange");
+// values: true | false
+const std::string PREF_ENABLE_DHT("enable-dht");
+// values: 1*digit
+const std::string PREF_DHT_LISTEN_PORT("dht-listen-port");
+// values: a string
+const std::string PREF_DHT_ENTRY_POINT_HOST("dht-entry-point-host");
+// values: 1*digit
+const std::string PREF_DHT_ENTRY_POINT_PORT("dht-entry-point-port");
+// values: a string (hostname:port);
+const std::string PREF_DHT_ENTRY_POINT("dht-entry-point");
+// values: a string
+const std::string PREF_DHT_FILE_PATH("dht-file-path");
+// values: plain | arc4
+const std::string PREF_BT_MIN_CRYPTO_LEVEL("bt-min-crypto-level");
+const std::string V_PLAIN("plain");
+const std::string V_ARC4("arc4");
+// values:: true | false
+const std::string PREF_BT_REQUIRE_CRYPTO("bt-require-crypto");
+
+/**
+ * Metalink related preferences
+ */
+// values: a string that your file system recognizes as a file name.
+const std::string PREF_METALINK_FILE("metalink-file");
+// values: a string
+const std::string PREF_METALINK_VERSION("metalink-version");
+// values: a string
+const std::string PREF_METALINK_LANGUAGE("metalink-language");
+// values: a string
+const std::string PREF_METALINK_OS("metalink-os");
+// values: a string
+const std::string PREF_METALINK_LOCATION("metalink-location");
+// values: 1*digit
+const std::string PREF_METALINK_SERVERS("metalink-servers");
+// values: true | false | mem
+const std::string PREF_FOLLOW_METALINK("follow-metalink");
+// values: http | https | ftp | none
+const std::string PREF_METALINK_PREFERRED_PROTOCOL("metalink-preferred-protocol");
+const std::string V_HTTP("http");
+const std::string V_HTTPS("https");
+const std::string V_FTP("ftp");
+// values: true | false
+const std::string PREF_METALINK_ENABLE_UNIQUE_PROTOCOL("metalink-enable-unique-protocol");
+
+} // namespace aria2

+ 126 - 124
src/prefs.h

@@ -36,245 +36,247 @@
 #define _D_PREFS_H_
 
 #include "common.h"
+#include <string>
+
+namespace aria2 {
 
 /**
  * Constants
  */
-#undef V_TRUE
-#define V_TRUE "true"
-#undef V_FALSE
-#define V_FALSE "false"
-#undef V_NONE
-#define V_NONE "none"
-#define V_MEM "mem"
-#define V_ALL "all"
+extern const std::string V_TRUE;
+extern const std::string V_FALSE;
+extern const std::string V_NONE;
+extern const std::string V_MEM;
+extern const std::string V_ALL;
 /**
  * General preferences
  */
 // values: 1*digit
-#define PREF_RETRY_WAIT "retry-wait"
+extern const std::string PREF_RETRY_WAIT;
 // values: 1*digit
-#define PREF_TIMEOUT "timeout"
+extern const std::string PREF_TIMEOUT;
 // values: 1*digit
-#define PREF_DNS_TIMEOUT "dns-timeout"
+extern const std::string PREF_DNS_TIMEOUT;
 // values: 1*digit
-#define PREF_MAX_TRIES "max-tries"
+extern const std::string PREF_MAX_TRIES;
 // values: 1*digit
-#define PREF_MIN_SEGMENT_SIZE "min-segment-size"
+extern const std::string PREF_MIN_SEGMENT_SIZE;
 // values: 1*digit
-#define PREF_AUTO_SAVE_INTERVAL "auto-save-interval"
+extern const std::string PREF_AUTO_SAVE_INTERVAL;
 // values: true | false
-#define PREF_STDOUT_LOG "stdout-log"
+extern const std::string PREF_STDOUT_LOG;
 // values: a string that your file system recognizes as a file name.
-#define PREF_LOG "log"
+extern const std::string PREF_LOG;
 // values: a string that your file system recognizes as a directory.
-#define PREF_DIR "dir"
+extern const std::string PREF_DIR;
 // values: a string that your file system recognizes as a file name.
-#define PREF_OUT "out"
+extern const std::string PREF_OUT;
 // values: 1*digit
-#define PREF_SPLIT "split"
+extern const std::string PREF_SPLIT;
 // value: true | false
-#define PREF_DAEMON "daemon"
+extern const std::string PREF_DAEMON;
 // value: a string
-#define PREF_REFERER "referer"
+extern const std::string PREF_REFERER;
 // value: 1*digit
-#define PREF_LOWEST_SPEED_LIMIT "lowest-speed-limit"
+extern const std::string PREF_LOWEST_SPEED_LIMIT;
 // value: 1*digit
-#define PREF_SEGMENT_SIZE "segment-size"
+extern const std::string PREF_SEGMENT_SIZE;
 // value: 1*digit
-#define PREF_MAX_DOWNLOAD_LIMIT "max-download-limit"
+extern const std::string PREF_MAX_DOWNLOAD_LIMIT;
 // value: 1*digit
-#define PREF_STARTUP_IDLE_TIME "startup-idle-time"
+extern const std::string PREF_STARTUP_IDLE_TIME;
 // value: prealloc | none
-#define PREF_FILE_ALLOCATION "file-allocation"
-#  define V_PREALLOC "prealloc"
+extern const std::string PREF_FILE_ALLOCATION;
+extern const std::string V_PREALLOC;
 #// value: 1*digit
-#define PREF_NO_FILE_ALLOCATION_LIMIT "no-file-allocation-limit"
+extern const std::string PREF_NO_FILE_ALLOCATION_LIMIT;
 // value: true | false
-#define PREF_ALLOW_OVERWRITE "allow-overwrite"
+extern const std::string PREF_ALLOW_OVERWRITE;
 // value: true | false
-#define PREF_REALTIME_CHUNK_CHECKSUM "realtime-chunk-checksum"
+extern const std::string PREF_REALTIME_CHUNK_CHECKSUM;
 // value: true | false
-#define PREF_CHECK_INTEGRITY "check-integrity"
+extern const std::string PREF_CHECK_INTEGRITY;
 // value: string that your file system recognizes as a file name.
-#define PREF_NETRC_PATH "netrc-path"
+extern const std::string PREF_NETRC_PATH;
 // value:
-#define PREF_CONTINUE "continue"
+extern const std::string PREF_CONTINUE;
 // value:
-#define PREF_NO_NETRC "no-netrc"
+extern const std::string PREF_NO_NETRC;
 // value: 1*digit
-#define PREF_MAX_DOWNLOADS "max-downloads"
+extern const std::string PREF_MAX_DOWNLOADS;
 // value: string that your file system recognizes as a file name.
-#define PREF_INPUT_FILE "input-file"
+extern const std::string PREF_INPUT_FILE;
 // value: 1*digit
-#define PREF_MAX_CONCURRENT_DOWNLOADS "max-concurrent-downloads"
+extern const std::string PREF_MAX_CONCURRENT_DOWNLOADS;
 // value: 1*digit
-#define PREF_DIRECT_DOWNLOAD_TIMEOUT "direct-download-timeout"
+extern const std::string PREF_DIRECT_DOWNLOAD_TIMEOUT;
 // value: true | false
-#define PREF_FORCE_SEQUENTIAL "force-sequential"
+extern const std::string PREF_FORCE_SEQUENTIAL;
 // value: true | false
-#define PREF_AUTO_FILE_RENAMING "auto-file-renaming"
+extern const std::string PREF_AUTO_FILE_RENAMING;
 // value: true | false
-#define PREF_PARAMETERIZED_URI "parameterized-uri"
+extern const std::string PREF_PARAMETERIZED_URI;
 // value: true | false
-#define PREF_ENABLE_DIRECT_IO "enable-direct-io"
+extern const std::string PREF_ENABLE_DIRECT_IO;
 // value: true | false
-#define PREF_ALLOW_PIECE_LENGTH_CHANGE "allow-piece-length-change"
+extern const std::string PREF_ALLOW_PIECE_LENGTH_CHANGE;
 // value: true | false
-#define PREF_NO_CONF "no-conf"
+extern const std::string PREF_NO_CONF;
 // value: string
-#define PREF_CONF_PATH "conf-path"
+extern const std::string PREF_CONF_PATH;
 // value: 1*digit
-#define PREF_STOP "stop"
+extern const std::string PREF_STOP;
 // value: true | false
-#define PREF_QUIET "quiet"
+extern const std::string PREF_QUIET;
 // value: true | false
-#define PREF_ASYNC_DNS "async-dns"
+extern const std::string PREF_ASYNC_DNS;
 // value: 1*digit
-#define PREF_SUMMARY_INTERVAL "summary-interval"
+extern const std::string PREF_SUMMARY_INTERVAL;
 // value: debug, info, notice, warn, error
-#define PREF_LOG_LEVEL "log-level"
-#  define V_DEBUG "debug"
-#  define V_INFO "info"
-#  define V_NOTICE "notice"
-#  define V_WARN "warn"
-#  define V_ERROR "error"
+extern const std::string PREF_LOG_LEVEL;
+extern const std::string V_DEBUG;
+extern const std::string V_INFO;
+extern const std::string V_NOTICE;
+extern const std::string V_WARN;
+extern const std::string V_ERROR;
 
 /**
  * FTP related preferences
  */
-#define PREF_FTP_USER "ftp-user"
-#define PREF_FTP_PASSWD "ftp-passwd"
+extern const std::string PREF_FTP_USER;
+extern const std::string PREF_FTP_PASSWD;
 // values: binary | ascii
-#define PREF_FTP_TYPE "ftp-type"
-#  define V_BINARY "binary"
-#  define V_ASCII "ascii"
+extern const std::string PREF_FTP_TYPE;
+extern const std::string V_BINARY;
+extern const std::string V_ASCII;
 // values: get | tunnel
-#define PREF_FTP_VIA_HTTP_PROXY "ftp-via-http-proxy"
-#  define V_GET "get"
-#  define V_TUNNEL "tunnel"
+extern const std::string PREF_FTP_VIA_HTTP_PROXY;
+extern const std::string V_GET;
+extern const std::string V_TUNNEL;
 // values: true | false
-#define PREF_FTP_PASV "ftp-pasv"
+extern const std::string PREF_FTP_PASV;
 // values: true | false
-#define PREF_FTP_REUSE_CONNECTION "ftp-reuse-connection"
+extern const std::string PREF_FTP_REUSE_CONNECTION;
 
 /**
  * HTTP related preferences
  */
-#define PREF_HTTP_USER "http-user"
-#define PREF_HTTP_PASSWD "http-passwd"
+extern const std::string PREF_HTTP_USER;
+extern const std::string PREF_HTTP_PASSWD;
 // values: basic
-#define PREF_HTTP_AUTH_SCHEME "http-auth-scheme"
-#  define V_BASIC "basic"
+extern const std::string PREF_HTTP_AUTH_SCHEME;
+extern const std::string V_BASIC;
 // values: true | false
-#define PREF_HTTP_AUTH_ENABLED "http-auth-enabled"
+extern const std::string PREF_HTTP_AUTH_ENABLED;
 // values: string
-#define PREF_USER_AGENT "user-agent"
+extern const std::string PREF_USER_AGENT;
 // value: string that your file system recognizes as a file name.
-#define PREF_LOAD_COOKIES "load-cookies"
+extern const std::string PREF_LOAD_COOKIES;
 // values: true | false
-#define PREF_ENABLE_HTTP_KEEP_ALIVE "enable-http-keep-alive"
+extern const std::string PREF_ENABLE_HTTP_KEEP_ALIVE;
 // values: true | false
-#define PREF_ENABLE_HTTP_PIPELINING "enable-http-pipelining"
+extern const std::string PREF_ENABLE_HTTP_PIPELINING;
 // value: 1*digit
-#define PREF_MAX_HTTP_PIPELINING "max-http-pipelining"
+extern const std::string PREF_MAX_HTTP_PIPELINING;
 // value: string
-#define PREF_HEADER "header"
+extern const std::string PREF_HEADER;
 
-/** 
+/**;
  * HTTP proxy related preferences
  */
-#define PREF_HTTP_PROXY "http-proxy"
-#define PREF_HTTP_PROXY_USER "http-proxy-user"
-#define PREF_HTTP_PROXY_PASSWD "http-proxy-passwd"
-#define PREF_HTTP_PROXY_HOST "http-proxy-host"
-#define PREF_HTTP_PROXY_PORT "http-proxy-port"
+extern const std::string PREF_HTTP_PROXY;
+extern const std::string PREF_HTTP_PROXY_USER;
+extern const std::string PREF_HTTP_PROXY_PASSWD;
+extern const std::string PREF_HTTP_PROXY_HOST;
+extern const std::string PREF_HTTP_PROXY_PORT;
 // values: get | tunnel
-#define PREF_HTTP_PROXY_METHOD "http-proxy-method"
+extern const std::string PREF_HTTP_PROXY_METHOD;
 // values: true | false
-#define PREF_HTTP_PROXY_ENABLED "http-proxy-enabled"
+extern const std::string PREF_HTTP_PROXY_ENABLED;
 // values: true | false
-#define PREF_HTTP_PROXY_AUTH_ENABLED "http-proxy-auth-enabled"
+extern const std::string PREF_HTTP_PROXY_AUTH_ENABLED;
 
 /**
  * BitTorrent related preferences
  */
 // values: 1*digit
-#define PREF_PEER_CONNECTION_TIMEOUT "peer-connection-timeout"
+extern const std::string PREF_PEER_CONNECTION_TIMEOUT;
 // values: 1*digit
-#define PREF_BT_TIMEOUT "bt-timeout"
+extern const std::string PREF_BT_TIMEOUT;
 // values: 1*digit
-#define PREF_BT_REQUEST_TIMEOUT "bt-request-timeout"
+extern const std::string PREF_BT_REQUEST_TIMEOUT;
 // values: true | false
-#define PREF_SHOW_FILES "show-files"
+extern const std::string PREF_SHOW_FILES;
 // values: true | false
-#define PREF_NO_PREALLOCATION "no-preallocation"
+extern const std::string PREF_NO_PREALLOCATION;
 // values: true | false
-#define PREF_DIRECT_FILE_MAPPING "direct-file-mapping"
+extern const std::string PREF_DIRECT_FILE_MAPPING;
 // values: 1*digit
-#define PREF_MAX_UPLOAD_LIMIT "max-upload-limit"
+extern const std::string PREF_MAX_UPLOAD_LIMIT;
 // values: a string that your file system recognizes as a file name.
-#define PREF_TORRENT_FILE "torrent-file"
+extern const std::string PREF_TORRENT_FILE;
 // values: 1*digit
-#define PREF_LISTEN_PORT "listen-port"
+extern const std::string PREF_LISTEN_PORT;
 // values: true | false | mem
-#define PREF_FOLLOW_TORRENT "follow-torrent"
+extern const std::string PREF_FOLLOW_TORRENT;
 // values: 1*digit *( (,|-) 1*digit)
-#define PREF_SELECT_FILE "select-file"
+extern const std::string PREF_SELECT_FILE;
 // values: 1*digit
-#define PREF_SEED_TIME "seed-time"
+extern const std::string PREF_SEED_TIME;
 // values: 1*digit ['.' [ 1*digit ] ]
-#define PREF_SEED_RATIO "seed-ratio"
+extern const std::string PREF_SEED_RATIO;
 // values: 1*digit
-#define PREF_TRACKER_MAX_TRIES "tracker-max-tries"
+extern const std::string PREF_TRACKER_MAX_TRIES;
 // values: 1*digit
-#define PREF_BT_KEEP_ALIVE_INTERVAL "bt-keep-alive-interval"
+extern const std::string PREF_BT_KEEP_ALIVE_INTERVAL;
 // values: a string, less than or equals to 20 bytes length
-#define PREF_PEER_ID_PREFIX "peer-id-prefix"
+extern const std::string PREF_PEER_ID_PREFIX;
 // values: true | false
-#define PREF_ENABLE_PEER_EXCHANGE "enable-peer-exchange"
+extern const std::string PREF_ENABLE_PEER_EXCHANGE;
 // values: true | false
-#define PREF_ENABLE_DHT "enable-dht"
+extern const std::string PREF_ENABLE_DHT;
 // values: 1*digit
-#define PREF_DHT_LISTEN_PORT "dht-listen-port"
+extern const std::string PREF_DHT_LISTEN_PORT;
 // values: a string
-#define PREF_DHT_ENTRY_POINT_HOST "dht-entry-point-host"
+extern const std::string PREF_DHT_ENTRY_POINT_HOST;
 // values: 1*digit
-#define PREF_DHT_ENTRY_POINT_PORT "dht-entry-point-port"
+extern const std::string PREF_DHT_ENTRY_POINT_PORT;
 // values: a string (hostname:port)
-#define PREF_DHT_ENTRY_POINT "dht-entry-point"
+extern const std::string PREF_DHT_ENTRY_POINT;
 // values: a string
-#define PREF_DHT_FILE_PATH "dht-file-path"
+extern const std::string PREF_DHT_FILE_PATH;
 // values: plain | arc4
-#define PREF_BT_MIN_CRYPTO_LEVEL "bt-min-crypto-level"
-#  define V_PLAIN "plain"
-#  define V_ARC4 "arc4"
+extern const std::string PREF_BT_MIN_CRYPTO_LEVEL;
+extern const std::string V_PLAIN;
+extern const std::string V_ARC4;
 // values:: true | false
-#define PREF_BT_REQUIRE_CRYPTO "bt-require-crypto"
+extern const std::string PREF_BT_REQUIRE_CRYPTO;
 
 /**
  * Metalink related preferences
  */
 // values: a string that your file system recognizes as a file name.
-#define PREF_METALINK_FILE "metalink-file"
+extern const std::string PREF_METALINK_FILE;
 // values: a string
-#define PREF_METALINK_VERSION "metalink-version"
+extern const std::string PREF_METALINK_VERSION;
 // values: a string
-#define PREF_METALINK_LANGUAGE "metalink-language"
+extern const std::string PREF_METALINK_LANGUAGE;
 // values: a string
-#define PREF_METALINK_OS "metalink-os"
+extern const std::string PREF_METALINK_OS;
 // values: a string
-#define PREF_METALINK_LOCATION "metalink-location"
+extern const std::string PREF_METALINK_LOCATION;
 // values: 1*digit
-#define PREF_METALINK_SERVERS "metalink-servers"
+extern const std::string PREF_METALINK_SERVERS;
 // values: true | false | mem
-#define PREF_FOLLOW_METALINK "follow-metalink"
+extern const std::string PREF_FOLLOW_METALINK;
 // values: http | https | ftp | none
-#define PREF_METALINK_PREFERRED_PROTOCOL "metalink-preferred-protocol"
-#  define V_HTTP "http"
-#  define V_HTTPS "https"
-#  define V_FTP "ftp"
+extern const std::string 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
-#define PREF_METALINK_ENABLE_UNIQUE_PROTOCOL "metalink-enable-unique-protocol"
+extern const std::string PREF_METALINK_ENABLE_UNIQUE_PROTOCOL;
+
+} // namespace aria2
 
 #endif // _D_PREFS_H_