version.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, 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 "ssh.h"
  28. #include "quic.h"
  29. #include "curl_printf.h"
  30. #ifdef USE_ARES
  31. # if defined(CURL_STATICLIB) && !defined(CARES_STATICLIB) && \
  32. (defined(WIN32) || defined(__SYMBIAN32__))
  33. # define CARES_STATICLIB
  34. # endif
  35. # include <ares.h>
  36. #endif
  37. #ifdef USE_LIBIDN2
  38. #include <idn2.h>
  39. #endif
  40. #ifdef USE_LIBPSL
  41. #include <libpsl.h>
  42. #endif
  43. #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
  44. #include <iconv.h>
  45. #endif
  46. #ifdef USE_LIBRTMP
  47. #include <librtmp/rtmp.h>
  48. #endif
  49. #ifdef HAVE_ZLIB_H
  50. #include <zlib.h>
  51. #ifdef __SYMBIAN32__
  52. /* zlib pollutes the namespace with this definition */
  53. #undef WIN32
  54. #endif
  55. #endif
  56. #ifdef HAVE_BROTLI
  57. #include <brotli/decode.h>
  58. #endif
  59. void Curl_version_init(void);
  60. /* For thread safety purposes this function is called by global_init so that
  61. the static data in both version functions is initialized. */
  62. void Curl_version_init(void)
  63. {
  64. curl_version();
  65. curl_version_info(CURLVERSION_NOW);
  66. }
  67. #ifdef HAVE_BROTLI
  68. static size_t brotli_version(char *buf, size_t bufsz)
  69. {
  70. uint32_t brotli_version = BrotliDecoderVersion();
  71. unsigned int major = brotli_version >> 24;
  72. unsigned int minor = (brotli_version & 0x00FFFFFF) >> 12;
  73. unsigned int patch = brotli_version & 0x00000FFF;
  74. return msnprintf(buf, bufsz, "%u.%u.%u", major, minor, patch);
  75. }
  76. #endif
  77. char *curl_version(void)
  78. {
  79. static bool initialized;
  80. static char version[250];
  81. char *ptr = version;
  82. size_t len;
  83. size_t left = sizeof(version);
  84. if(initialized)
  85. return version;
  86. strcpy(ptr, LIBCURL_NAME "/" LIBCURL_VERSION);
  87. len = strlen(ptr);
  88. left -= len;
  89. ptr += len;
  90. if(left > 1) {
  91. len = Curl_ssl_version(ptr + 1, left - 1);
  92. if(len > 0) {
  93. *ptr = ' ';
  94. left -= ++len;
  95. ptr += len;
  96. }
  97. }
  98. #ifdef HAVE_LIBZ
  99. len = msnprintf(ptr, left, " zlib/%s", zlibVersion());
  100. left -= len;
  101. ptr += len;
  102. #endif
  103. #ifdef HAVE_BROTLI
  104. len = msnprintf(ptr, left, "%s", " brotli/");
  105. left -= len;
  106. ptr += len;
  107. len = brotli_version(ptr, left);
  108. left -= len;
  109. ptr += len;
  110. #endif
  111. #ifdef USE_ARES
  112. /* this function is only present in c-ares, not in the original ares */
  113. len = msnprintf(ptr, left, " c-ares/%s", ares_version(NULL));
  114. left -= len;
  115. ptr += len;
  116. #endif
  117. #ifdef USE_LIBIDN2
  118. if(idn2_check_version(IDN2_VERSION)) {
  119. len = msnprintf(ptr, left, " libidn2/%s", idn2_check_version(NULL));
  120. left -= len;
  121. ptr += len;
  122. }
  123. #endif
  124. #ifdef USE_LIBPSL
  125. len = msnprintf(ptr, left, " libpsl/%s", psl_get_version());
  126. left -= len;
  127. ptr += len;
  128. #endif
  129. #ifdef USE_WIN32_IDN
  130. len = msnprintf(ptr, left, " WinIDN");
  131. left -= len;
  132. ptr += len;
  133. #endif
  134. #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
  135. #ifdef _LIBICONV_VERSION
  136. len = msnprintf(ptr, left, " iconv/%d.%d",
  137. _LIBICONV_VERSION >> 8, _LIBICONV_VERSION & 255);
  138. #else
  139. /* version unknown */
  140. len = msnprintf(ptr, left, " iconv");
  141. #endif /* _LIBICONV_VERSION */
  142. left -= len;
  143. ptr += len;
  144. #endif
  145. #ifdef USE_SSH
  146. if(left) {
  147. *ptr++=' ';
  148. left--;
  149. }
  150. len = Curl_ssh_version(ptr, left);
  151. left -= len;
  152. ptr += len;
  153. #endif
  154. #ifdef USE_NGHTTP2
  155. len = Curl_http2_ver(ptr, left);
  156. left -= len;
  157. ptr += len;
  158. #endif
  159. #ifdef ENABLE_QUIC
  160. len = Curl_quic_ver(ptr, left);
  161. left -= len;
  162. ptr += len;
  163. #endif
  164. #ifdef USE_LIBRTMP
  165. {
  166. char suff[2];
  167. if(RTMP_LIB_VERSION & 0xff) {
  168. suff[0] = (RTMP_LIB_VERSION & 0xff) + 'a' - 1;
  169. suff[1] = '\0';
  170. }
  171. else
  172. suff[0] = '\0';
  173. msnprintf(ptr, left, " librtmp/%d.%d%s",
  174. RTMP_LIB_VERSION >> 16, (RTMP_LIB_VERSION >> 8) & 0xff,
  175. suff);
  176. /*
  177. If another lib version is added below this one, this code would
  178. also have to do:
  179. len = what msnprintf() returned
  180. left -= len;
  181. ptr += len;
  182. */
  183. }
  184. #endif
  185. /* Silent scan-build even if librtmp is not enabled. */
  186. (void) left;
  187. (void) ptr;
  188. initialized = true;
  189. return version;
  190. }
  191. /* data for curl_version_info
  192. Keep the list sorted alphabetically. It is also written so that each
  193. protocol line has its own #if line to make things easier on the eye.
  194. */
  195. static const char * const protocols[] = {
  196. #ifndef CURL_DISABLE_DICT
  197. "dict",
  198. #endif
  199. #ifndef CURL_DISABLE_FILE
  200. "file",
  201. #endif
  202. #ifndef CURL_DISABLE_FTP
  203. "ftp",
  204. #endif
  205. #if defined(USE_SSL) && !defined(CURL_DISABLE_FTP)
  206. "ftps",
  207. #endif
  208. #ifndef CURL_DISABLE_GOPHER
  209. "gopher",
  210. #endif
  211. #ifndef CURL_DISABLE_HTTP
  212. "http",
  213. #endif
  214. #if defined(USE_SSL) && !defined(CURL_DISABLE_HTTP)
  215. "https",
  216. #endif
  217. #ifndef CURL_DISABLE_IMAP
  218. "imap",
  219. #endif
  220. #if defined(USE_SSL) && !defined(CURL_DISABLE_IMAP)
  221. "imaps",
  222. #endif
  223. #ifndef CURL_DISABLE_LDAP
  224. "ldap",
  225. #if !defined(CURL_DISABLE_LDAPS) && \
  226. ((defined(USE_OPENLDAP) && defined(USE_SSL)) || \
  227. (!defined(USE_OPENLDAP) && defined(HAVE_LDAP_SSL)))
  228. "ldaps",
  229. #endif
  230. #endif
  231. #ifndef CURL_DISABLE_POP3
  232. "pop3",
  233. #endif
  234. #if defined(USE_SSL) && !defined(CURL_DISABLE_POP3)
  235. "pop3s",
  236. #endif
  237. #ifdef USE_LIBRTMP
  238. "rtmp",
  239. #endif
  240. #ifndef CURL_DISABLE_RTSP
  241. "rtsp",
  242. #endif
  243. #if defined(USE_SSH)
  244. "scp",
  245. "sftp",
  246. #endif
  247. #if !defined(CURL_DISABLE_SMB) && defined(USE_NTLM) && \
  248. (CURL_SIZEOF_CURL_OFF_T > 4) && \
  249. (!defined(USE_WINDOWS_SSPI) || defined(USE_WIN32_CRYPTO))
  250. "smb",
  251. # ifdef USE_SSL
  252. "smbs",
  253. # endif
  254. #endif
  255. #ifndef CURL_DISABLE_SMTP
  256. "smtp",
  257. #endif
  258. #if defined(USE_SSL) && !defined(CURL_DISABLE_SMTP)
  259. "smtps",
  260. #endif
  261. #ifndef CURL_DISABLE_TELNET
  262. "telnet",
  263. #endif
  264. #ifndef CURL_DISABLE_TFTP
  265. "tftp",
  266. #endif
  267. NULL
  268. };
  269. static curl_version_info_data version_info = {
  270. CURLVERSION_NOW,
  271. LIBCURL_VERSION,
  272. LIBCURL_VERSION_NUM,
  273. OS, /* as found by configure or set by hand at build-time */
  274. 0 /* features is 0 by default */
  275. #ifdef ENABLE_IPV6
  276. | CURL_VERSION_IPV6
  277. #endif
  278. #ifdef USE_SSL
  279. | CURL_VERSION_SSL
  280. #endif
  281. #ifdef USE_NTLM
  282. | CURL_VERSION_NTLM
  283. #endif
  284. #if !defined(CURL_DISABLE_HTTP) && defined(USE_NTLM) && \
  285. defined(NTLM_WB_ENABLED)
  286. | CURL_VERSION_NTLM_WB
  287. #endif
  288. #ifdef USE_SPNEGO
  289. | CURL_VERSION_SPNEGO
  290. #endif
  291. #ifdef USE_KERBEROS5
  292. | CURL_VERSION_KERBEROS5
  293. #endif
  294. #ifdef HAVE_GSSAPI
  295. | CURL_VERSION_GSSAPI
  296. #endif
  297. #ifdef USE_WINDOWS_SSPI
  298. | CURL_VERSION_SSPI
  299. #endif
  300. #ifdef HAVE_LIBZ
  301. | CURL_VERSION_LIBZ
  302. #endif
  303. #ifdef DEBUGBUILD
  304. | CURL_VERSION_DEBUG
  305. #endif
  306. #ifdef CURLDEBUG
  307. | CURL_VERSION_CURLDEBUG
  308. #endif
  309. #ifdef CURLRES_ASYNCH
  310. | CURL_VERSION_ASYNCHDNS
  311. #endif
  312. #if (CURL_SIZEOF_CURL_OFF_T > 4) && \
  313. ( (SIZEOF_OFF_T > 4) || defined(USE_WIN32_LARGE_FILES) )
  314. | CURL_VERSION_LARGEFILE
  315. #endif
  316. #if defined(CURL_DOES_CONVERSIONS)
  317. | CURL_VERSION_CONV
  318. #endif
  319. #if defined(USE_TLS_SRP)
  320. | CURL_VERSION_TLSAUTH_SRP
  321. #endif
  322. #if defined(USE_NGHTTP2)
  323. | CURL_VERSION_HTTP2
  324. #endif
  325. #if defined(ENABLE_QUIC)
  326. | CURL_VERSION_HTTP3
  327. #endif
  328. #if defined(USE_UNIX_SOCKETS)
  329. | CURL_VERSION_UNIX_SOCKETS
  330. #endif
  331. #if defined(USE_LIBPSL)
  332. | CURL_VERSION_PSL
  333. #endif
  334. #if defined(CURL_WITH_MULTI_SSL)
  335. | CURL_VERSION_MULTI_SSL
  336. #endif
  337. #if defined(HAVE_BROTLI)
  338. | CURL_VERSION_BROTLI
  339. #endif
  340. #if defined(USE_ALTSVC)
  341. | CURL_VERSION_ALTSVC
  342. #endif
  343. ,
  344. NULL, /* ssl_version */
  345. 0, /* ssl_version_num, this is kept at zero */
  346. NULL, /* zlib_version */
  347. protocols,
  348. NULL, /* c-ares version */
  349. 0, /* c-ares version numerical */
  350. NULL, /* libidn version */
  351. 0, /* iconv version */
  352. NULL, /* ssh lib version */
  353. 0, /* brotli_ver_num */
  354. NULL, /* brotli version */
  355. 0, /* nghttp2 version number */
  356. NULL, /* nghttp2 version string */
  357. NULL /* quic library string */
  358. };
  359. curl_version_info_data *curl_version_info(CURLversion stamp)
  360. {
  361. static bool initialized;
  362. #if defined(USE_SSH)
  363. static char ssh_buffer[80];
  364. #endif
  365. #ifdef USE_SSL
  366. #ifdef CURL_WITH_MULTI_SSL
  367. static char ssl_buffer[200];
  368. #else
  369. static char ssl_buffer[80];
  370. #endif
  371. #endif
  372. #ifdef HAVE_BROTLI
  373. static char brotli_buffer[80];
  374. #endif
  375. if(initialized)
  376. return &version_info;
  377. #ifdef USE_SSL
  378. Curl_ssl_version(ssl_buffer, sizeof(ssl_buffer));
  379. version_info.ssl_version = ssl_buffer;
  380. if(Curl_ssl->supports & SSLSUPP_HTTPS_PROXY)
  381. version_info.features |= CURL_VERSION_HTTPS_PROXY;
  382. else
  383. version_info.features &= ~CURL_VERSION_HTTPS_PROXY;
  384. #endif
  385. #ifdef HAVE_LIBZ
  386. version_info.libz_version = zlibVersion();
  387. /* libz left NULL if non-existing */
  388. #endif
  389. #ifdef USE_ARES
  390. {
  391. int aresnum;
  392. version_info.ares = ares_version(&aresnum);
  393. version_info.ares_num = aresnum;
  394. }
  395. #endif
  396. #ifdef USE_LIBIDN2
  397. /* This returns a version string if we use the given version or later,
  398. otherwise it returns NULL */
  399. version_info.libidn = idn2_check_version(IDN2_VERSION);
  400. if(version_info.libidn)
  401. version_info.features |= CURL_VERSION_IDN;
  402. #elif defined(USE_WIN32_IDN)
  403. version_info.features |= CURL_VERSION_IDN;
  404. #endif
  405. #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
  406. #ifdef _LIBICONV_VERSION
  407. version_info.iconv_ver_num = _LIBICONV_VERSION;
  408. #else
  409. /* version unknown */
  410. version_info.iconv_ver_num = -1;
  411. #endif /* _LIBICONV_VERSION */
  412. #endif
  413. #if defined(USE_SSH)
  414. Curl_ssh_version(ssh_buffer, sizeof(ssh_buffer));
  415. version_info.libssh_version = ssh_buffer;
  416. #endif
  417. #ifdef HAVE_BROTLI
  418. version_info.brotli_ver_num = BrotliDecoderVersion();
  419. brotli_version(brotli_buffer, sizeof(brotli_buffer));
  420. version_info.brotli_version = brotli_buffer;
  421. #endif
  422. #ifdef USE_NGHTTP2
  423. {
  424. nghttp2_info *h2 = nghttp2_version(0);
  425. version_info.nghttp2_ver_num = h2->version_num;
  426. version_info.nghttp2_version = h2->version_str;
  427. }
  428. #endif
  429. #ifdef ENABLE_QUIC
  430. {
  431. static char quicbuffer[80];
  432. Curl_quic_ver(quicbuffer, sizeof(quicbuffer));
  433. version_info.quic_version = quicbuffer;
  434. }
  435. #endif
  436. (void)stamp; /* avoid compiler warnings, we don't use this */
  437. initialized = true;
  438. return &version_info;
  439. }