OptionHandlerFactory.cc 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * In addition, as a special exception, the copyright holders give
  22. * permission to link the code of portions of this program with the
  23. * OpenSSL library under certain conditions as described in each
  24. * individual source file, and distribute linked combinations
  25. * including the two.
  26. * You must obey the GNU General Public License in all respects
  27. * for all of the code used other than OpenSSL. If you modify
  28. * file(s) with this exception, you may extend this exception to your
  29. * version of the file(s), but you are not obligated to do so. If you
  30. * do not wish to do so, delete this exception statement from your
  31. * version. If you delete this exception statement from all source
  32. * files in the program, then also delete it here.
  33. */
  34. /* copyright --> */
  35. #include "OptionHandlerFactory.h"
  36. #include "prefs.h"
  37. #include "OptionHandlerImpl.h"
  38. #include "array_fun.h"
  39. #define SH(X) SharedHandle<OptionHandler>(X)
  40. namespace aria2 {
  41. OptionHandlers OptionHandlerFactory::createOptionHandlers()
  42. {
  43. OptionHandlers handlers;
  44. handlers.push_back(SH(new HttpProxyOptionHandler(PREF_HTTP_PROXY,
  45. PREF_HTTP_PROXY_HOST,
  46. PREF_HTTP_PROXY_PORT)));
  47. handlers.push_back(SH(new DefaultOptionHandler(PREF_HTTP_USER)));
  48. handlers.push_back(SH(new DefaultOptionHandler(PREF_HTTP_PASSWD)));
  49. handlers.push_back(SH(new DefaultOptionHandler(PREF_HTTP_PROXY_USER)));
  50. handlers.push_back(SH(new DefaultOptionHandler(PREF_HTTP_PROXY_PASSWD)));
  51. handlers.push_back(SH(new ParameterOptionHandler(PREF_HTTP_AUTH_SCHEME, V_BASIC)));
  52. handlers.push_back(SH(new DefaultOptionHandler(PREF_REFERER)));
  53. handlers.push_back(SH(new NumberOptionHandler(PREF_RETRY_WAIT, 0, 60)));
  54. handlers.push_back(SH(new DefaultOptionHandler(PREF_FTP_USER)));
  55. handlers.push_back(SH(new DefaultOptionHandler(PREF_FTP_PASSWD)));
  56. handlers.push_back(SH(new ParameterOptionHandler(PREF_FTP_TYPE, V_BINARY, V_ASCII)));
  57. handlers.push_back(SH(new ParameterOptionHandler(PREF_FTP_VIA_HTTP_PROXY,
  58. V_GET, V_TUNNEL)));
  59. handlers.push_back(SH(new UnitNumberOptionHandler(PREF_MIN_SEGMENT_SIZE, 1024)));
  60. handlers.push_back(SH(new ParameterOptionHandler(PREF_HTTP_PROXY_METHOD,
  61. V_GET, V_TUNNEL)));
  62. handlers.push_back(SH(new IntegerRangeOptionHandler(PREF_LISTEN_PORT, 1024, UINT16_MAX)));
  63. handlers.push_back(SH(new ParameterOptionHandler(PREF_FOLLOW_TORRENT, V_TRUE, V_MEM, V_FALSE)));
  64. handlers.push_back(SH(new BooleanOptionHandler(PREF_NO_PREALLOCATION)));
  65. handlers.push_back(SH(new BooleanOptionHandler(PREF_DIRECT_FILE_MAPPING)));
  66. handlers.push_back(SH(new IntegerRangeOptionHandler(PREF_SELECT_FILE, 1, INT32_MAX)));
  67. handlers.push_back(SH(new NumberOptionHandler(PREF_SEED_TIME, 0)));
  68. handlers.push_back(SH(new FloatNumberOptionHandler(PREF_SEED_RATIO, 0.0)));
  69. handlers.push_back(SH(new UnitNumberOptionHandler(PREF_MAX_UPLOAD_LIMIT, 0)));
  70. handlers.push_back(SH(new DefaultOptionHandler(PREF_METALINK_VERSION)));
  71. handlers.push_back(SH(new DefaultOptionHandler(PREF_METALINK_LANGUAGE)));
  72. handlers.push_back(SH(new DefaultOptionHandler(PREF_METALINK_OS)));
  73. handlers.push_back(SH(new ParameterOptionHandler(PREF_FOLLOW_METALINK, V_TRUE, V_MEM, V_FALSE)));
  74. handlers.push_back(SH(new DefaultOptionHandler(PREF_METALINK_LOCATION)));
  75. handlers.push_back(SH(new UnitNumberOptionHandler(PREF_LOWEST_SPEED_LIMIT, 0)));
  76. handlers.push_back(SH(new UnitNumberOptionHandler(PREF_MAX_DOWNLOAD_LIMIT, 0)));
  77. handlers.push_back(SH(new BooleanOptionHandler(PREF_ALLOW_OVERWRITE)));
  78. handlers.push_back(SH(new BooleanOptionHandler(PREF_CHECK_INTEGRITY)));
  79. handlers.push_back(SH(new BooleanOptionHandler(PREF_REALTIME_CHUNK_CHECKSUM)));
  80. handlers.push_back(SH(new BooleanOptionHandler(PREF_DAEMON)));
  81. handlers.push_back(SH(new DefaultOptionHandler(PREF_DIR)));
  82. handlers.push_back(SH(new DefaultOptionHandler(PREF_OUT)));
  83. handlers.push_back(SH(new LogOptionHandler(PREF_LOG)));
  84. handlers.push_back(SH(new NumberOptionHandler(PREF_SPLIT, 1, 5)));
  85. handlers.push_back(SH(new NumberOptionHandler(PREF_TIMEOUT, 1, 600)));
  86. handlers.push_back(SH(new NumberOptionHandler(PREF_MAX_TRIES, 0)));
  87. handlers.push_back(SH(new BooleanOptionHandler(PREF_FTP_PASV)));
  88. handlers.push_back(SH(new BooleanOptionHandler(PREF_SHOW_FILES)));
  89. handlers.push_back(SH(new DefaultOptionHandler(PREF_TORRENT_FILE)));
  90. handlers.push_back(SH(new DefaultOptionHandler(PREF_METALINK_FILE)));
  91. handlers.push_back(SH(new NumberOptionHandler(PREF_METALINK_SERVERS, 1)));
  92. handlers.push_back(SH(new ParameterOptionHandler(PREF_FILE_ALLOCATION,
  93. V_NONE, V_PREALLOC)));
  94. handlers.push_back(SH(new BooleanOptionHandler(PREF_CONTINUE)));
  95. handlers.push_back(SH(new DefaultOptionHandler(PREF_USER_AGENT)));
  96. handlers.push_back(SH(new BooleanOptionHandler(PREF_NO_NETRC)));
  97. handlers.push_back(SH(new DefaultOptionHandler(PREF_INPUT_FILE)));
  98. handlers.push_back(SH(new NumberOptionHandler(PREF_MAX_CONCURRENT_DOWNLOADS, 1, 45)));
  99. handlers.push_back(SH(new DefaultOptionHandler(PREF_LOAD_COOKIES)));
  100. handlers.push_back(SH(new DefaultOptionHandler(PREF_PEER_ID_PREFIX)));
  101. handlers.push_back(SH(new BooleanOptionHandler(PREF_FORCE_SEQUENTIAL)));
  102. handlers.push_back(SH(new BooleanOptionHandler(PREF_AUTO_FILE_RENAMING)));
  103. handlers.push_back(SH(new BooleanOptionHandler(PREF_PARAMETERIZED_URI)));
  104. handlers.push_back(SH(new BooleanOptionHandler(PREF_ENABLE_HTTP_KEEP_ALIVE)));
  105. handlers.push_back(SH(new BooleanOptionHandler(PREF_ENABLE_HTTP_PIPELINING)));
  106. handlers.push_back(SH(new UnitNumberOptionHandler(PREF_NO_FILE_ALLOCATION_LIMIT, 0)));
  107. handlers.push_back(SH(new BooleanOptionHandler(PREF_ENABLE_DIRECT_IO)));
  108. handlers.push_back(SH(new BooleanOptionHandler(PREF_ALLOW_PIECE_LENGTH_CHANGE)));
  109. {
  110. const std::string params[] = { V_HTTP, V_HTTPS, V_FTP, V_NONE };
  111. handlers.push_back(SH(new ParameterOptionHandler(PREF_METALINK_PREFERRED_PROTOCOL,
  112. std::deque<std::string>(&params[0], &params[arrayLength(params)]))));
  113. }
  114. handlers.push_back(SH(new BooleanOptionHandler(PREF_METALINK_ENABLE_UNIQUE_PROTOCOL)));
  115. handlers.push_back(SH(new BooleanOptionHandler(PREF_ENABLE_PEER_EXCHANGE)));
  116. handlers.push_back(SH(new BooleanOptionHandler(PREF_ENABLE_DHT)));
  117. handlers.push_back(SH(new IntegerRangeOptionHandler(PREF_DHT_LISTEN_PORT, 1024, UINT16_MAX)));
  118. handlers.push_back(SH(new HostPortOptionHandler(PREF_DHT_ENTRY_POINT,
  119. PREF_DHT_ENTRY_POINT_HOST,
  120. PREF_DHT_ENTRY_POINT_PORT)));
  121. handlers.push_back(SH(new NumberOptionHandler(PREF_STOP, 0, INT32_MAX)));
  122. handlers.push_back(SH(new ParameterOptionHandler(PREF_BT_MIN_CRYPTO_LEVEL, V_PLAIN, V_ARC4)));
  123. handlers.push_back(SH(new BooleanOptionHandler(PREF_BT_REQUIRE_CRYPTO)));
  124. handlers.push_back(SH(new NumberOptionHandler(PREF_BT_REQUEST_PEER_SPEED_LIMIT, 0)));
  125. handlers.push_back(SH(new CumulativeOptionHandler(PREF_HEADER, "\n")));
  126. handlers.push_back(SH(new BooleanOptionHandler(PREF_QUIET)));
  127. #ifdef ENABLE_ASYNC_DNS
  128. handlers.push_back(SH(new BooleanOptionHandler(PREF_ASYNC_DNS)));
  129. #endif // ENABLE_ASYNC_DNS
  130. handlers.push_back(SH(new BooleanOptionHandler(PREF_FTP_REUSE_CONNECTION)));
  131. handlers.push_back(SH(new NumberOptionHandler(PREF_SUMMARY_INTERVAL, 0, INT32_MAX)));
  132. {
  133. const std::string params[] = { V_DEBUG, V_INFO, V_NOTICE, V_WARN, V_ERROR };
  134. handlers.push_back(SH(new ParameterOptionHandler
  135. (PREF_LOG_LEVEL,
  136. std::deque<std::string>(&params[0],
  137. &params[arrayLength(params)]))));
  138. }
  139. return handlers;
  140. }
  141. } // namespace aria2