version.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2016, Daniel Stenberg, <[email protected]>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. #include "curl_setup.h"
  23. #include <curl/curl.h>
  24. #include "urldata.h"
  25. #include "vtls/vtls.h"
  26. #include "http2.h"
  27. #include "curl_printf.h"
  28. #ifdef USE_ARES
  29. # if defined(CURL_STATICLIB) && !defined(CARES_STATICLIB) && \
  30. (defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__))
  31. # define CARES_STATICLIB
  32. # endif
  33. # include <ares.h>
  34. #endif
  35. #ifdef USE_LIBIDN2
  36. #include <idn2.h>
  37. #endif
  38. #ifdef USE_LIBPSL
  39. #include <libpsl.h>
  40. #endif
  41. #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
  42. #include <iconv.h>
  43. #endif
  44. #ifdef USE_LIBRTMP
  45. #include <librtmp/rtmp.h>
  46. #endif
  47. #ifdef USE_LIBSSH2
  48. #include <libssh2.h>
  49. #endif
  50. #ifdef HAVE_LIBSSH2_VERSION
  51. /* get it run-time if possible */
  52. #define CURL_LIBSSH2_VERSION libssh2_version(0)
  53. #else
  54. /* use build-time if run-time not possible */
  55. #define CURL_LIBSSH2_VERSION LIBSSH2_VERSION
  56. #endif
  57. void Curl_version_init(void);
  58. /* For thread safety purposes this function is called by global_init so that
  59. the static data in both version functions is initialized. */
  60. void Curl_version_init(void)
  61. {
  62. curl_version();
  63. curl_version_info(CURLVERSION_NOW);
  64. }
  65. char *curl_version(void)
  66. {
  67. static bool initialized;
  68. static char version[200];
  69. char *ptr = version;
  70. size_t len;
  71. size_t left = sizeof(version);
  72. if(initialized)
  73. return version;
  74. strcpy(ptr, LIBCURL_NAME "/" LIBCURL_VERSION);
  75. len = strlen(ptr);
  76. left -= len;
  77. ptr += len;
  78. if(left > 1) {
  79. len = Curl_ssl_version(ptr + 1, left - 1);
  80. if(len > 0) {
  81. *ptr = ' ';
  82. left -= ++len;
  83. ptr += len;
  84. }
  85. }
  86. #ifdef HAVE_LIBZ
  87. len = snprintf(ptr, left, " zlib/%s", zlibVersion());
  88. left -= len;
  89. ptr += len;
  90. #endif
  91. #ifdef USE_ARES
  92. /* this function is only present in c-ares, not in the original ares */
  93. len = snprintf(ptr, left, " c-ares/%s", ares_version(NULL));
  94. left -= len;
  95. ptr += len;
  96. #endif
  97. #ifdef USE_LIBIDN2
  98. if(idn2_check_version(IDN2_VERSION)) {
  99. len = snprintf(ptr, left, " libidn2/%s", idn2_check_version(NULL));
  100. left -= len;
  101. ptr += len;
  102. }
  103. #endif
  104. #ifdef USE_LIBPSL
  105. len = snprintf(ptr, left, " libpsl/%s", psl_get_version());
  106. left -= len;
  107. ptr += len;
  108. #endif
  109. #ifdef USE_WIN32_IDN
  110. len = snprintf(ptr, left, " WinIDN");
  111. left -= len;
  112. ptr += len;
  113. #endif
  114. #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
  115. #ifdef _LIBICONV_VERSION
  116. len = snprintf(ptr, left, " iconv/%d.%d",
  117. _LIBICONV_VERSION >> 8, _LIBICONV_VERSION & 255);
  118. #else
  119. /* version unknown */
  120. len = snprintf(ptr, left, " iconv");
  121. #endif /* _LIBICONV_VERSION */
  122. left -= len;
  123. ptr += len;
  124. #endif
  125. #ifdef USE_LIBSSH2
  126. len = snprintf(ptr, left, " libssh2/%s", CURL_LIBSSH2_VERSION);
  127. left -= len;
  128. ptr += len;
  129. #endif
  130. #ifdef USE_NGHTTP2
  131. len = Curl_http2_ver(ptr, left);
  132. left -= len;
  133. ptr += len;
  134. #endif
  135. #ifdef USE_LIBRTMP
  136. {
  137. char suff[2];
  138. if(RTMP_LIB_VERSION & 0xff) {
  139. suff[0] = (RTMP_LIB_VERSION & 0xff) + 'a' - 1;
  140. suff[1] = '\0';
  141. }
  142. else
  143. suff[0] = '\0';
  144. snprintf(ptr, left, " librtmp/%d.%d%s",
  145. RTMP_LIB_VERSION >> 16, (RTMP_LIB_VERSION >> 8) & 0xff,
  146. suff);
  147. /*
  148. If another lib version is added below this one, this code would
  149. also have to do:
  150. len = what snprintf() returned
  151. left -= len;
  152. ptr += len;
  153. */
  154. }
  155. #endif
  156. initialized = true;
  157. return version;
  158. }
  159. /* data for curl_version_info
  160. Keep the list sorted alphabetically. It is also written so that each
  161. protocol line has its own #if line to make things easier on the eye.
  162. */
  163. static const char * const protocols[] = {
  164. #ifndef CURL_DISABLE_DICT
  165. "dict",
  166. #endif
  167. #ifndef CURL_DISABLE_FILE
  168. "file",
  169. #endif
  170. #ifndef CURL_DISABLE_FTP
  171. "ftp",
  172. #endif
  173. #if defined(USE_SSL) && !defined(CURL_DISABLE_FTP)
  174. "ftps",
  175. #endif
  176. #ifndef CURL_DISABLE_GOPHER
  177. "gopher",
  178. #endif
  179. #ifndef CURL_DISABLE_HTTP
  180. "http",
  181. #endif
  182. #if defined(USE_SSL) && !defined(CURL_DISABLE_HTTP)
  183. "https",
  184. #endif
  185. #ifndef CURL_DISABLE_IMAP
  186. "imap",
  187. #endif
  188. #if defined(USE_SSL) && !defined(CURL_DISABLE_IMAP)
  189. "imaps",
  190. #endif
  191. #ifndef CURL_DISABLE_LDAP
  192. "ldap",
  193. #if !defined(CURL_DISABLE_LDAPS) && \
  194. ((defined(USE_OPENLDAP) && defined(USE_SSL)) || \
  195. (!defined(USE_OPENLDAP) && defined(HAVE_LDAP_SSL)))
  196. "ldaps",
  197. #endif
  198. #endif
  199. #ifndef CURL_DISABLE_POP3
  200. "pop3",
  201. #endif
  202. #if defined(USE_SSL) && !defined(CURL_DISABLE_POP3)
  203. "pop3s",
  204. #endif
  205. #ifdef USE_LIBRTMP
  206. "rtmp",
  207. #endif
  208. #ifndef CURL_DISABLE_RTSP
  209. "rtsp",
  210. #endif
  211. #ifdef USE_LIBSSH2
  212. "scp",
  213. #endif
  214. #ifdef USE_LIBSSH2
  215. "sftp",
  216. #endif
  217. #if !defined(CURL_DISABLE_SMB) && defined(USE_NTLM) && \
  218. (CURL_SIZEOF_CURL_OFF_T > 4) && \
  219. (!defined(USE_WINDOWS_SSPI) || defined(USE_WIN32_CRYPTO))
  220. "smb",
  221. # ifdef USE_SSL
  222. "smbs",
  223. # endif
  224. #endif
  225. #ifndef CURL_DISABLE_SMTP
  226. "smtp",
  227. #endif
  228. #if defined(USE_SSL) && !defined(CURL_DISABLE_SMTP)
  229. "smtps",
  230. #endif
  231. #ifndef CURL_DISABLE_TELNET
  232. "telnet",
  233. #endif
  234. #ifndef CURL_DISABLE_TFTP
  235. "tftp",
  236. #endif
  237. NULL
  238. };
  239. static curl_version_info_data version_info = {
  240. CURLVERSION_NOW,
  241. LIBCURL_VERSION,
  242. LIBCURL_VERSION_NUM,
  243. OS, /* as found by configure or set by hand at build-time */
  244. 0 /* features is 0 by default */
  245. #ifdef ENABLE_IPV6
  246. | CURL_VERSION_IPV6
  247. #endif
  248. #ifdef USE_SSL
  249. | CURL_VERSION_SSL
  250. #endif
  251. #ifdef USE_NTLM
  252. | CURL_VERSION_NTLM
  253. #endif
  254. #if !defined(CURL_DISABLE_HTTP) && defined(USE_NTLM) && \
  255. defined(NTLM_WB_ENABLED)
  256. | CURL_VERSION_NTLM_WB
  257. #endif
  258. #ifdef USE_SPNEGO
  259. | CURL_VERSION_SPNEGO
  260. #endif
  261. #ifdef USE_KERBEROS5
  262. | CURL_VERSION_KERBEROS5
  263. #endif
  264. #ifdef HAVE_GSSAPI
  265. | CURL_VERSION_GSSAPI
  266. #endif
  267. #ifdef USE_WINDOWS_SSPI
  268. | CURL_VERSION_SSPI
  269. #endif
  270. #ifdef HAVE_LIBZ
  271. | CURL_VERSION_LIBZ
  272. #endif
  273. #ifdef DEBUGBUILD
  274. | CURL_VERSION_DEBUG
  275. #endif
  276. #ifdef CURLDEBUG
  277. | CURL_VERSION_CURLDEBUG
  278. #endif
  279. #ifdef CURLRES_ASYNCH
  280. | CURL_VERSION_ASYNCHDNS
  281. #endif
  282. #if (CURL_SIZEOF_CURL_OFF_T > 4) && \
  283. ( (SIZEOF_OFF_T > 4) || defined(USE_WIN32_LARGE_FILES) )
  284. | CURL_VERSION_LARGEFILE
  285. #endif
  286. #if defined(CURL_DOES_CONVERSIONS)
  287. | CURL_VERSION_CONV
  288. #endif
  289. #if defined(USE_TLS_SRP)
  290. | CURL_VERSION_TLSAUTH_SRP
  291. #endif
  292. #if defined(USE_NGHTTP2)
  293. | CURL_VERSION_HTTP2
  294. #endif
  295. #if defined(USE_UNIX_SOCKETS)
  296. | CURL_VERSION_UNIX_SOCKETS
  297. #endif
  298. #if defined(USE_LIBPSL)
  299. | CURL_VERSION_PSL
  300. #endif
  301. #if defined(HTTPS_PROXY_SUPPORT)
  302. | CURL_VERSION_HTTPS_PROXY
  303. #endif
  304. ,
  305. NULL, /* ssl_version */
  306. 0, /* ssl_version_num, this is kept at zero */
  307. NULL, /* zlib_version */
  308. protocols,
  309. NULL, /* c-ares version */
  310. 0, /* c-ares version numerical */
  311. NULL, /* libidn version */
  312. 0, /* iconv version */
  313. NULL, /* ssh lib version */
  314. };
  315. curl_version_info_data *curl_version_info(CURLversion stamp)
  316. {
  317. static bool initialized;
  318. #ifdef USE_LIBSSH2
  319. static char ssh_buffer[80];
  320. #endif
  321. #ifdef USE_SSL
  322. static char ssl_buffer[80];
  323. #endif
  324. if(initialized)
  325. return &version_info;
  326. #ifdef USE_SSL
  327. Curl_ssl_version(ssl_buffer, sizeof(ssl_buffer));
  328. version_info.ssl_version = ssl_buffer;
  329. #endif
  330. #ifdef HAVE_LIBZ
  331. version_info.libz_version = zlibVersion();
  332. /* libz left NULL if non-existing */
  333. #endif
  334. #ifdef USE_ARES
  335. {
  336. int aresnum;
  337. version_info.ares = ares_version(&aresnum);
  338. version_info.ares_num = aresnum;
  339. }
  340. #endif
  341. #ifdef USE_LIBIDN2
  342. /* This returns a version string if we use the given version or later,
  343. otherwise it returns NULL */
  344. version_info.libidn = idn2_check_version(IDN2_VERSION);
  345. if(version_info.libidn)
  346. version_info.features |= CURL_VERSION_IDN;
  347. #elif defined(USE_WIN32_IDN)
  348. version_info.features |= CURL_VERSION_IDN;
  349. #endif
  350. #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
  351. #ifdef _LIBICONV_VERSION
  352. version_info.iconv_ver_num = _LIBICONV_VERSION;
  353. #else
  354. /* version unknown */
  355. version_info.iconv_ver_num = -1;
  356. #endif /* _LIBICONV_VERSION */
  357. #endif
  358. #ifdef USE_LIBSSH2
  359. snprintf(ssh_buffer, sizeof(ssh_buffer), "libssh2/%s", LIBSSH2_VERSION);
  360. version_info.libssh_version = ssh_buffer;
  361. #endif
  362. (void)stamp; /* avoid compiler warnings, we don't use this */
  363. initialized = true;
  364. return &version_info;
  365. }