FeatureConfig.cc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2012 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 "FeatureConfig.h"
  36. #include "util.h"
  37. namespace aria2 {
  38. uint16_t getDefaultPort(const std::string& protocol)
  39. {
  40. if(protocol == "http") {
  41. return 80;
  42. } else if(protocol == "https") {
  43. return 443;
  44. } else if(protocol == "ftp") {
  45. return 21;
  46. } else {
  47. return 0;
  48. }
  49. }
  50. std::string featureSummary()
  51. {
  52. std::string s;
  53. int first;
  54. for(first = 0; first < MAX_FEATURE && !strSupportedFeature(first); ++first);
  55. if(first < MAX_FEATURE) {
  56. s += strSupportedFeature(first);
  57. for(int i = first+1; i < MAX_FEATURE; ++i) {
  58. const char* name = strSupportedFeature(i);
  59. if(name) {
  60. s += ", ";
  61. s += name;
  62. }
  63. }
  64. }
  65. return s;
  66. }
  67. const char* strSupportedFeature(int feature)
  68. {
  69. switch(feature) {
  70. case(FEATURE_ASYNC_DNS):
  71. #ifdef ENABLE_ASYNC_DNS
  72. return "Async DNS";
  73. #else // !ENABLE_ASYNC_DNS
  74. return 0;
  75. #endif // !ENABLE_ASYNC_DNS
  76. break;
  77. case(FEATURE_BITTORRENT):
  78. #ifdef ENABLE_BITTORRENT
  79. return "BitTorrent";
  80. #else // !ENABLE_BITTORRENT
  81. return 0;
  82. #endif // !ENABLE_BITTORRENT
  83. break;
  84. case(FEATURE_FF3_COOKIE):
  85. #ifdef HAVE_SQLITE3
  86. return "Firefox3 Cookie";
  87. #else // !HAVE_SQLITE3
  88. return 0;
  89. #endif // !HAVE_SQLITE3
  90. break;
  91. case(FEATURE_GZIP):
  92. #ifdef HAVE_ZLIB
  93. return "GZip";
  94. #else // !HAVE_ZLIB
  95. return 0;
  96. #endif // !HAVE_ZLIB
  97. break;
  98. case(FEATURE_HTTPS):
  99. #ifdef ENABLE_SSL
  100. return "HTTPS";
  101. #else // !ENABLE_SSL
  102. return 0;
  103. #endif // !ENABLE_SSL
  104. break;
  105. case(FEATURE_MESSAGE_DIGEST):
  106. #ifdef ENABLE_MESSAGE_DIGEST
  107. return "Message Digest";
  108. #else // !ENABLE_MESSAGE_DIGEST
  109. return 0;
  110. #endif // !ENABLE_MESSAGE_DIGEST
  111. break;
  112. case(FEATURE_METALINK):
  113. #ifdef ENABLE_METALINK
  114. return "Metalink";
  115. #else // !ENABLE_METALINK
  116. return 0;
  117. #endif // !ENABLE_METALINK
  118. break;
  119. case(FEATURE_XML_RPC):
  120. #ifdef ENABLE_XML_RPC
  121. return "XML-RPC";
  122. #else // !ENABLE_XML_RPC
  123. return 0;
  124. #endif // !ENABLE_XML_RPC
  125. break;
  126. default:
  127. return 0;
  128. }
  129. }
  130. } // namespace aria2