FeatureConfig.cc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. #ifdef HAVE_ZLIB
  37. # include <zlib.h>
  38. #endif // HAVE_ZLIB
  39. #ifdef HAVE_LIBXML2
  40. # include <libxml/xmlversion.h>
  41. #endif // HAVE_LIBXML2
  42. #ifdef HAVE_LIBEXPAT
  43. # include <expat.h>
  44. #endif // HAVE_LIBEXPAT
  45. #ifdef HAVE_SQLITE3
  46. # include <sqlite3.h>
  47. #endif // HAVE_SQLITE3
  48. #ifdef HAVE_LIBGNUTLS
  49. # include <gnutls/gnutls.h>
  50. #endif // HAVE_LIBGNUTLS
  51. #ifdef HAVE_OPENSSL
  52. # include <openssl/opensslv.h>
  53. #endif // HAVE_OPENSSL
  54. #ifdef HAVE_LIBGMP
  55. # include <gmp.h>
  56. #endif // HAVE_LIBGMP
  57. #ifdef HAVE_LIBGCRYPT
  58. # include <gcrypt.h>
  59. #endif // HAVE_LIBGCRYPT
  60. #ifdef HAVE_LIBCARES
  61. # include <ares.h>
  62. #endif // HAVE_LIBCARES
  63. #include "util.h"
  64. namespace aria2 {
  65. uint16_t getDefaultPort(const std::string& protocol)
  66. {
  67. if(protocol == "http") {
  68. return 80;
  69. } else if(protocol == "https") {
  70. return 443;
  71. } else if(protocol == "ftp") {
  72. return 21;
  73. } else {
  74. return 0;
  75. }
  76. }
  77. std::string featureSummary()
  78. {
  79. std::string s;
  80. int first;
  81. for(first = 0; first < MAX_FEATURE && !strSupportedFeature(first); ++first);
  82. if(first < MAX_FEATURE) {
  83. s += strSupportedFeature(first);
  84. for(int i = first+1; i < MAX_FEATURE; ++i) {
  85. const char* name = strSupportedFeature(i);
  86. if(name) {
  87. s += ", ";
  88. s += name;
  89. }
  90. }
  91. }
  92. return s;
  93. }
  94. const char* strSupportedFeature(int feature)
  95. {
  96. switch(feature) {
  97. case(FEATURE_ASYNC_DNS):
  98. #ifdef ENABLE_ASYNC_DNS
  99. return "Async DNS";
  100. #else // !ENABLE_ASYNC_DNS
  101. return nullptr;
  102. #endif // !ENABLE_ASYNC_DNS
  103. break;
  104. case(FEATURE_BITTORRENT):
  105. #ifdef ENABLE_BITTORRENT
  106. return "BitTorrent";
  107. #else // !ENABLE_BITTORRENT
  108. return 0;
  109. #endif // !ENABLE_BITTORRENT
  110. break;
  111. case(FEATURE_FF3_COOKIE):
  112. #ifdef HAVE_SQLITE3
  113. return "Firefox3 Cookie";
  114. #else // !HAVE_SQLITE3
  115. return nullptr;
  116. #endif // !HAVE_SQLITE3
  117. break;
  118. case(FEATURE_GZIP):
  119. #ifdef HAVE_ZLIB
  120. return "GZip";
  121. #else // !HAVE_ZLIB
  122. return 0;
  123. #endif // !HAVE_ZLIB
  124. break;
  125. case(FEATURE_HTTPS):
  126. #ifdef ENABLE_SSL
  127. return "HTTPS";
  128. #else // !ENABLE_SSL
  129. return 0;
  130. #endif // !ENABLE_SSL
  131. break;
  132. case(FEATURE_MESSAGE_DIGEST):
  133. #ifdef ENABLE_MESSAGE_DIGEST
  134. return "Message Digest";
  135. #else // !ENABLE_MESSAGE_DIGEST
  136. return 0;
  137. #endif // !ENABLE_MESSAGE_DIGEST
  138. break;
  139. case(FEATURE_METALINK):
  140. #ifdef ENABLE_METALINK
  141. return "Metalink";
  142. #else // !ENABLE_METALINK
  143. return 0;
  144. #endif // !ENABLE_METALINK
  145. break;
  146. case(FEATURE_XML_RPC):
  147. #ifdef ENABLE_XML_RPC
  148. return "XML-RPC";
  149. #else // !ENABLE_XML_RPC
  150. return 0;
  151. #endif // !ENABLE_XML_RPC
  152. break;
  153. default:
  154. return nullptr;
  155. }
  156. }
  157. std::string usedLibs()
  158. {
  159. std::string res;
  160. #ifdef HAVE_ZLIB
  161. res += "zlib/" ZLIB_VERSION " ";
  162. #endif // HAVE_ZLIB
  163. #ifdef HAVE_LIBXML2
  164. res += "libxml2/" LIBXML_DOTTED_VERSION " ";
  165. #endif // HAVE_LIBXML2
  166. #ifdef HAVE_LIBEXPAT
  167. res += fmt("expat/%d.%d.%d ",
  168. XML_MAJOR_VERSION, XML_MINOR_VERSION, XML_MICRO_VERSION);
  169. #endif // HAVE_LIBEXPAT
  170. #ifdef HAVE_SQLITE3
  171. res += "sqlite3/" SQLITE_VERSION " ";
  172. #endif // HAVE_SQLITE3
  173. #ifdef HAVE_APPLETLS
  174. res += "AppleTLS ";
  175. #endif // HAVE_APPLETLS
  176. #ifdef HAVE_WINTLS
  177. res += "WinTLS ";
  178. #endif // HAVE_WINTLS
  179. #ifdef HAVE_LIBGNUTLS
  180. res += "GnuTLS/" GNUTLS_VERSION " ";
  181. #endif // HAVE_LIBGNUTLS
  182. #ifdef HAVE_OPENSSL
  183. res += fmt("OpenSSL/%ld.%ld.%ld",
  184. OPENSSL_VERSION_NUMBER >> 28,
  185. (OPENSSL_VERSION_NUMBER >> 20) & 0xff,
  186. (OPENSSL_VERSION_NUMBER >> 12) & 0xff);
  187. if((OPENSSL_VERSION_NUMBER >> 4) & 0xff) {
  188. res += 'a' + ((OPENSSL_VERSION_NUMBER >> 4) & 0xff) - 1;
  189. }
  190. res += " ";
  191. #endif // HAVE_OPENSSL
  192. #ifdef HAVE_LIBNETTLE
  193. // No library version in header files.
  194. res += "nettle ";
  195. #endif // HAVE_LIBNETTLE
  196. #ifdef HAVE_LIBGMP
  197. res += fmt("GMP/%d.%d.%d ",
  198. __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR,
  199. __GNU_MP_VERSION_PATCHLEVEL);
  200. #endif // HAVE_LIBGMP
  201. #ifdef HAVE_LIBGCRYPT
  202. res += "libgcrypt/" GCRYPT_VERSION " ";
  203. #endif // HAVE_LIBGCRYPT
  204. #ifdef HAVE_LIBCARES
  205. res += "c-ares/" ARES_VERSION_STR " ";
  206. #endif // HAVE_LIBCARES
  207. if(!res.empty()) {
  208. res.erase(res.length()-1);
  209. }
  210. return res;
  211. }
  212. } // namespace aria2