FeatureConfig.cc 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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 <sstream>
  37. #include <cstring>
  38. #ifdef HAVE_ZLIB
  39. # include <zlib.h>
  40. #endif // HAVE_ZLIB
  41. #ifdef HAVE_LIBXML2
  42. # include <libxml/xmlversion.h>
  43. #endif // HAVE_LIBXML2
  44. #ifdef HAVE_LIBEXPAT
  45. # include <expat.h>
  46. #endif // HAVE_LIBEXPAT
  47. #ifdef HAVE_SQLITE3
  48. # include <sqlite3.h>
  49. #endif // HAVE_SQLITE3
  50. #ifdef HAVE_LIBGNUTLS
  51. # include <gnutls/gnutls.h>
  52. #endif // HAVE_LIBGNUTLS
  53. #ifdef HAVE_OPENSSL
  54. # include <openssl/opensslv.h>
  55. #endif // HAVE_OPENSSL
  56. #ifdef HAVE_LIBGMP
  57. # include <gmp.h>
  58. #endif // HAVE_LIBGMP
  59. #ifdef HAVE_LIBGCRYPT
  60. # include <gcrypt.h>
  61. #endif // HAVE_LIBGCRYPT
  62. #ifdef HAVE_LIBCARES
  63. # include <ares.h>
  64. #endif // HAVE_LIBCARES
  65. #ifdef HAVE_SYS_UTSNAME_H
  66. # include <sys/utsname.h>
  67. #endif // HAVE_SYS_UTSNAME_H
  68. #ifdef HAVE_LIBSSH2
  69. # include <libssh2.h>
  70. #endif // HAVE_LIBSSH2
  71. #include "util.h"
  72. namespace aria2 {
  73. uint16_t getDefaultPort(const std::string& protocol)
  74. {
  75. if (protocol == "http") {
  76. return 80;
  77. }
  78. else if (protocol == "https") {
  79. return 443;
  80. }
  81. else if (protocol == "ftp") {
  82. return 21;
  83. }
  84. else if (protocol == "sftp") {
  85. return 22;
  86. }
  87. else {
  88. return 0;
  89. }
  90. }
  91. std::string featureSummary()
  92. {
  93. std::string s;
  94. int first;
  95. for (first = 0; first < MAX_FEATURE && !strSupportedFeature(first); ++first)
  96. ;
  97. if (first < MAX_FEATURE) {
  98. s += strSupportedFeature(first);
  99. for (int i = first + 1; i < MAX_FEATURE; ++i) {
  100. const char* name = strSupportedFeature(i);
  101. if (name) {
  102. s += ", ";
  103. s += name;
  104. }
  105. }
  106. }
  107. return s;
  108. }
  109. const char* strSupportedFeature(int feature)
  110. {
  111. switch (feature) {
  112. case (FEATURE_ASYNC_DNS):
  113. #ifdef ENABLE_ASYNC_DNS
  114. return "Async DNS";
  115. #else // !ENABLE_ASYNC_DNS
  116. return nullptr;
  117. #endif // !ENABLE_ASYNC_DNS
  118. break;
  119. case (FEATURE_BITTORRENT):
  120. #ifdef ENABLE_BITTORRENT
  121. return "BitTorrent";
  122. #else // !ENABLE_BITTORRENT
  123. return nullptr;
  124. #endif // !ENABLE_BITTORRENT
  125. break;
  126. case (FEATURE_FF3_COOKIE):
  127. #ifdef HAVE_SQLITE3
  128. return "Firefox3 Cookie";
  129. #else // !HAVE_SQLITE3
  130. return nullptr;
  131. #endif // !HAVE_SQLITE3
  132. break;
  133. case (FEATURE_GZIP):
  134. #ifdef HAVE_ZLIB
  135. return "GZip";
  136. #else // !HAVE_ZLIB
  137. return nullptr;
  138. #endif // !HAVE_ZLIB
  139. break;
  140. case (FEATURE_HTTPS):
  141. #ifdef ENABLE_SSL
  142. return "HTTPS";
  143. #else // !ENABLE_SSL
  144. return nullptr;
  145. #endif // !ENABLE_SSL
  146. break;
  147. case (FEATURE_MESSAGE_DIGEST):
  148. return "Message Digest";
  149. break;
  150. case (FEATURE_METALINK):
  151. #ifdef ENABLE_METALINK
  152. return "Metalink";
  153. #else // !ENABLE_METALINK
  154. return nullptr;
  155. #endif // !ENABLE_METALINK
  156. break;
  157. case (FEATURE_XML_RPC):
  158. #ifdef ENABLE_XML_RPC
  159. return "XML-RPC";
  160. #else // !ENABLE_XML_RPC
  161. return nullptr;
  162. #endif // !ENABLE_XML_RPC
  163. break;
  164. case (FEATURE_SFTP):
  165. #ifdef HAVE_LIBSSH2
  166. return "SFTP";
  167. #else // !HAVE_LIBSSH2
  168. return nullptr;
  169. #endif // !HAVE_LIBSSH2
  170. break;
  171. default:
  172. return nullptr;
  173. }
  174. }
  175. std::string usedLibs()
  176. {
  177. std::string res;
  178. #ifdef HAVE_ZLIB
  179. res += "zlib/" ZLIB_VERSION " ";
  180. #endif // HAVE_ZLIB
  181. #ifdef HAVE_LIBXML2
  182. res += "libxml2/" LIBXML_DOTTED_VERSION " ";
  183. #endif // HAVE_LIBXML2
  184. #ifdef HAVE_LIBEXPAT
  185. res += fmt("expat/%d.%d.%d ", XML_MAJOR_VERSION, XML_MINOR_VERSION,
  186. XML_MICRO_VERSION);
  187. #endif // HAVE_LIBEXPAT
  188. #ifdef HAVE_SQLITE3
  189. res += "sqlite3/" SQLITE_VERSION " ";
  190. #endif // HAVE_SQLITE3
  191. #ifdef HAVE_APPLETLS
  192. res += "AppleTLS ";
  193. #endif // HAVE_APPLETLS
  194. #ifdef HAVE_WINTLS
  195. res += "WinTLS ";
  196. #endif // HAVE_WINTLS
  197. #ifdef HAVE_LIBGNUTLS
  198. res += "GnuTLS/" GNUTLS_VERSION " ";
  199. #endif // HAVE_LIBGNUTLS
  200. #ifdef HAVE_OPENSSL
  201. res += fmt("OpenSSL/%ld.%ld.%ld", OPENSSL_VERSION_NUMBER >> 28,
  202. (OPENSSL_VERSION_NUMBER >> 20) & 0xff,
  203. (OPENSSL_VERSION_NUMBER >> 12) & 0xff);
  204. if ((OPENSSL_VERSION_NUMBER >> 4) & 0xff) {
  205. res += 'a' + ((OPENSSL_VERSION_NUMBER >> 4) & 0xff) - 1;
  206. }
  207. res += " ";
  208. #endif // HAVE_OPENSSL
  209. #ifdef HAVE_LIBNETTLE
  210. // No library version in header files.
  211. res += "nettle ";
  212. #endif // HAVE_LIBNETTLE
  213. #ifdef HAVE_LIBGMP
  214. res += fmt("GMP/%d.%d.%d ", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR,
  215. __GNU_MP_VERSION_PATCHLEVEL);
  216. #endif // HAVE_LIBGMP
  217. #ifdef HAVE_LIBGCRYPT
  218. res += "libgcrypt/" GCRYPT_VERSION " ";
  219. #endif // HAVE_LIBGCRYPT
  220. #ifdef HAVE_LIBCARES
  221. res += "c-ares/" ARES_VERSION_STR " ";
  222. #endif // HAVE_LIBCARES
  223. #ifdef HAVE_LIBSSH2
  224. res += "libssh2/" LIBSSH2_VERSION " ";
  225. #endif // HAVE_LIBSSH2
  226. if (!res.empty()) {
  227. res.erase(res.length() - 1);
  228. }
  229. return res;
  230. }
  231. std::string usedCompilerAndPlatform()
  232. {
  233. std::stringstream rv;
  234. #if defined(__clang_version__)
  235. # ifdef __apple_build_version__
  236. rv << "Apple LLVM ";
  237. # else // !__apple_build_version__
  238. rv << "clang ";
  239. # endif // !__apple_build_version__
  240. rv << __clang_version__;
  241. #elif defined(__INTEL_COMPILER)
  242. rv << "Intel ICC " << __VERSION__;
  243. #elif defined(__MINGW64_VERSION_STR)
  244. rv << "mingw-w64 " << __MINGW64_VERSION_STR;
  245. # ifdef __MINGW64_VERSION_STATE
  246. rv << " (" << __MINGW64_VERSION_STATE << ")";
  247. # endif // __MINGW64_VERSION_STATE
  248. rv << " / gcc " << __VERSION__;
  249. #elif defined(__GNUG__)
  250. # ifdef __MINGW32__
  251. rv << "mingw ";
  252. # ifdef __MINGW32_MAJOR_VERSION
  253. rv << (int)__MINGW32_MAJOR_VERSION;
  254. # endif // __MINGW32_MAJOR_VERSION
  255. # ifdef __MINGW32_MINOR_VERSION
  256. rv << "." << (int)__MINGW32_MINOR_VERSION;
  257. # endif // __MINGW32_MINOR_VERSION
  258. rv << " / ";
  259. # endif // __MINGW32__
  260. rv << "gcc " << __VERSION__;
  261. #else // !defined(__GNUG__)
  262. rv << "Unknown compiler/platform";
  263. #endif // !defined(__GNUG__)
  264. rv << "\n built by " << BUILD;
  265. if (strcmp(BUILD, TARGET)) {
  266. rv << "\n targeting " << TARGET;
  267. }
  268. rv << "\n on " << __DATE__ << " " << __TIME__;
  269. return rv.str();
  270. }
  271. std::string getOperatingSystemInfo()
  272. {
  273. #ifdef _WIN32
  274. std::stringstream rv;
  275. rv << "Windows ";
  276. OSVERSIONINFOEX ovi = {sizeof(OSVERSIONINFOEX)};
  277. if (!GetVersionEx((LPOSVERSIONINFO)&ovi)) {
  278. rv << "Unknown";
  279. return rv.str();
  280. }
  281. if (ovi.dwMajorVersion < 6) {
  282. rv << "Legacy, probably XP";
  283. return rv.str();
  284. }
  285. switch (ovi.dwMinorVersion) {
  286. case 0:
  287. if (ovi.wProductType == VER_NT_WORKSTATION) {
  288. rv << "Vista";
  289. }
  290. else {
  291. rv << "Server 2008";
  292. }
  293. break;
  294. case 1:
  295. if (ovi.wProductType == VER_NT_WORKSTATION) {
  296. rv << "7";
  297. }
  298. else {
  299. rv << "Server 2008 R2";
  300. }
  301. break;
  302. default:
  303. // Windows above 6.2 does not actually say so. :p
  304. rv << ovi.dwMajorVersion;
  305. if (ovi.dwMinorVersion) {
  306. rv << "." << ovi.dwMinorVersion;
  307. }
  308. if (ovi.wProductType != VER_NT_WORKSTATION) {
  309. rv << " Server";
  310. }
  311. break;
  312. }
  313. if (ovi.szCSDVersion[0]) {
  314. rv << " (" << ovi.szCSDVersion << ")";
  315. }
  316. # ifdef _WIN64
  317. rv << " (x86_64)";
  318. # endif // _WIN64
  319. rv << " (" << ovi.dwMajorVersion << "." << ovi.dwMinorVersion << ")";
  320. return rv.str();
  321. #else //! _WIN32
  322. # ifdef HAVE_SYS_UTSNAME_H
  323. struct utsname name;
  324. if (!uname(&name)) {
  325. if (!strstr(name.version, name.sysname) ||
  326. !strstr(name.version, name.release) ||
  327. !strstr(name.version, name.machine)) {
  328. std::stringstream ss;
  329. ss << name.sysname << " " << name.release << " " << name.version << " "
  330. << name.machine;
  331. return ss.str();
  332. }
  333. return name.version;
  334. }
  335. # endif // HAVE_SYS_UTSNAME_H
  336. return "Unknown system";
  337. #endif // !_WIN32
  338. }
  339. } // namespace aria2