FeatureConfig.cc 8.3 KB

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