version.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 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.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. * SPDX-License-Identifier: curl
  22. *
  23. ***************************************************************************/
  24. #include "curl_setup.h"
  25. #ifdef USE_NGHTTP2
  26. #include <nghttp2/nghttp2.h>
  27. #endif
  28. #include <curl/curl.h>
  29. #include "urldata.h"
  30. #include "vtls/vtls.h"
  31. #include "http2.h"
  32. #include "vssh/ssh.h"
  33. #include "vquic/vquic.h"
  34. #include "easy_lock.h"
  35. #ifdef USE_ARES
  36. # include <ares.h>
  37. #endif
  38. #ifdef USE_LIBIDN2
  39. #include <idn2.h>
  40. #endif
  41. #ifdef USE_LIBPSL
  42. #include <libpsl.h>
  43. #endif
  44. #ifdef USE_LIBRTMP
  45. #include <librtmp/rtmp.h>
  46. #include "curl_rtmp.h"
  47. #endif
  48. #ifdef HAVE_LIBZ
  49. #include <cm3p/zlib.h>
  50. #endif
  51. #ifdef HAVE_BROTLI
  52. #if defined(__GNUC__) || defined(__clang__)
  53. /* Ignore -Wvla warnings in brotli headers */
  54. #pragma GCC diagnostic push
  55. #pragma GCC diagnostic ignored "-Wvla"
  56. #endif
  57. #include <brotli/decode.h>
  58. #if defined(__GNUC__) || defined(__clang__)
  59. #pragma GCC diagnostic pop
  60. #endif
  61. #endif
  62. #ifdef HAVE_ZSTD
  63. #include <zstd.h>
  64. #endif
  65. #ifdef USE_GSASL
  66. #include <gsasl.h>
  67. #endif
  68. #ifdef HAVE_GSSAPI
  69. # ifdef HAVE_GSSGNU
  70. # include <gss.h>
  71. # else
  72. # include <gssapi/gssapi.h>
  73. # endif
  74. #endif
  75. #ifdef USE_OPENLDAP
  76. #include <ldap.h>
  77. #endif
  78. #ifdef HAVE_BROTLI
  79. static void brotli_version(char *buf, size_t bufsz)
  80. {
  81. uint32_t brotli_version = BrotliDecoderVersion();
  82. unsigned int major = brotli_version >> 24;
  83. unsigned int minor = (brotli_version & 0x00FFFFFF) >> 12;
  84. unsigned int patch = brotli_version & 0x00000FFF;
  85. (void)curl_msnprintf(buf, bufsz, "brotli/%u.%u.%u", major, minor, patch);
  86. }
  87. #endif
  88. #ifdef HAVE_ZSTD
  89. static void zstd_version(char *buf, size_t bufsz)
  90. {
  91. unsigned int version = ZSTD_versionNumber();
  92. unsigned int major = version / (100 * 100);
  93. unsigned int minor = (version - (major * 100 * 100)) / 100;
  94. unsigned int patch = version - (major * 100 * 100) - (minor * 100);
  95. (void)curl_msnprintf(buf, bufsz, "zstd/%u.%u.%u", major, minor, patch);
  96. }
  97. #endif
  98. #ifdef USE_OPENLDAP
  99. static void oldap_version(char *buf, size_t bufsz)
  100. {
  101. LDAPAPIInfo api;
  102. api.ldapai_info_version = LDAP_API_INFO_VERSION;
  103. if(ldap_get_option(NULL, LDAP_OPT_API_INFO, &api) == LDAP_OPT_SUCCESS) {
  104. unsigned int patch = (unsigned int)(api.ldapai_vendor_version % 100);
  105. unsigned int major = (unsigned int)(api.ldapai_vendor_version / 10000);
  106. unsigned int minor =
  107. (((unsigned int)api.ldapai_vendor_version - major * 10000)
  108. - patch) / 100;
  109. curl_msnprintf(buf, bufsz, "%s/%u.%u.%u",
  110. api.ldapai_vendor_name, major, minor, patch);
  111. ldap_memfree(api.ldapai_vendor_name);
  112. ber_memvfree((void **)api.ldapai_extensions);
  113. }
  114. else
  115. curl_msnprintf(buf, bufsz, "OpenLDAP");
  116. }
  117. #endif
  118. #ifdef USE_LIBPSL
  119. static void psl_version(char *buf, size_t bufsz)
  120. {
  121. #if defined(PSL_VERSION_MAJOR) && (PSL_VERSION_MAJOR > 0 || \
  122. PSL_VERSION_MINOR >= 11)
  123. int num = psl_check_version_number(0);
  124. curl_msnprintf(buf, bufsz, "libpsl/%d.%d.%d",
  125. num >> 16, (num >> 8) & 0xff, num & 0xff);
  126. #else
  127. curl_msnprintf(buf, bufsz, "libpsl/%s", psl_get_version());
  128. #endif
  129. }
  130. #endif
  131. #if defined(USE_LIBIDN2) || defined(USE_WIN32_IDN) || defined(USE_APPLE_IDN)
  132. #define USE_IDN
  133. #endif
  134. #ifdef USE_IDN
  135. static void idn_version(char *buf, size_t bufsz)
  136. {
  137. #ifdef USE_LIBIDN2
  138. curl_msnprintf(buf, bufsz, "libidn2/%s", idn2_check_version(NULL));
  139. #elif defined(USE_WIN32_IDN)
  140. curl_msnprintf(buf, bufsz, "WinIDN");
  141. #elif defined(USE_APPLE_IDN)
  142. curl_msnprintf(buf, bufsz, "AppleIDN");
  143. #endif
  144. }
  145. #endif
  146. /*
  147. * curl_version() returns a pointer to a static buffer.
  148. *
  149. * It is implemented to work multi-threaded by making sure repeated invokes
  150. * generate the exact same string and never write any temporary data like
  151. * zeros in the data.
  152. */
  153. #define VERSION_PARTS 16 /* number of substrings we can concatenate */
  154. char *curl_version(void)
  155. {
  156. static char out[300];
  157. char *outp;
  158. size_t outlen;
  159. const char *src[VERSION_PARTS];
  160. #ifdef USE_SSL
  161. char ssl_version[200];
  162. #endif
  163. #ifdef HAVE_LIBZ
  164. char z_version[30];
  165. #endif
  166. #ifdef HAVE_BROTLI
  167. char br_version[30];
  168. #endif
  169. #ifdef HAVE_ZSTD
  170. char zstd_ver[30];
  171. #endif
  172. #ifdef USE_ARES
  173. char cares_version[30];
  174. #endif
  175. #ifdef USE_IDN
  176. char idn_ver[30];
  177. #endif
  178. #ifdef USE_LIBPSL
  179. char psl_ver[30];
  180. #endif
  181. #ifdef USE_SSH
  182. char ssh_version[30];
  183. #endif
  184. #if !defined(CURL_DISABLE_HTTP) && defined(USE_NGHTTP2)
  185. char h2_version[30];
  186. #endif
  187. #if !defined(CURL_DISABLE_HTTP) && defined(USE_HTTP3)
  188. char h3_version[30];
  189. #endif
  190. #ifdef USE_LIBRTMP
  191. char rtmp_version[30];
  192. #endif
  193. #ifdef USE_GSASL
  194. char gsasl_buf[30];
  195. #endif
  196. #ifdef HAVE_GSSAPI
  197. char gss_buf[40];
  198. #endif
  199. #ifdef USE_OPENLDAP
  200. char ldap_buf[30];
  201. #endif
  202. int i = 0;
  203. int j;
  204. #ifdef DEBUGBUILD
  205. /* Override version string when environment variable CURL_VERSION is set */
  206. const char *debugversion = getenv("CURL_VERSION");
  207. if(debugversion) {
  208. curl_msnprintf(out, sizeof(out), "%s", debugversion);
  209. return out;
  210. }
  211. #endif
  212. src[i++] = LIBCURL_NAME "/" LIBCURL_VERSION;
  213. #ifdef USE_SSL
  214. Curl_ssl_version(ssl_version, sizeof(ssl_version));
  215. src[i++] = ssl_version;
  216. #endif
  217. #ifdef HAVE_LIBZ
  218. curl_msnprintf(z_version, sizeof(z_version), "zlib/%s", zlibVersion());
  219. src[i++] = z_version;
  220. #endif
  221. #ifdef HAVE_BROTLI
  222. brotli_version(br_version, sizeof(br_version));
  223. src[i++] = br_version;
  224. #endif
  225. #ifdef HAVE_ZSTD
  226. zstd_version(zstd_ver, sizeof(zstd_ver));
  227. src[i++] = zstd_ver;
  228. #endif
  229. #ifdef USE_ARES
  230. curl_msnprintf(cares_version, sizeof(cares_version),
  231. "c-ares/%s", ares_version(NULL));
  232. src[i++] = cares_version;
  233. #endif
  234. #ifdef USE_IDN
  235. idn_version(idn_ver, sizeof(idn_ver));
  236. src[i++] = idn_ver;
  237. #endif
  238. #ifdef USE_LIBPSL
  239. psl_version(psl_ver, sizeof(psl_ver));
  240. src[i++] = psl_ver;
  241. #endif
  242. #ifdef USE_SSH
  243. Curl_ssh_version(ssh_version, sizeof(ssh_version));
  244. src[i++] = ssh_version;
  245. #endif
  246. #if !defined(CURL_DISABLE_HTTP) && defined(USE_NGHTTP2)
  247. Curl_http2_ver(h2_version, sizeof(h2_version));
  248. src[i++] = h2_version;
  249. #endif
  250. #if !defined(CURL_DISABLE_HTTP) && defined(USE_HTTP3)
  251. Curl_quic_ver(h3_version, sizeof(h3_version));
  252. src[i++] = h3_version;
  253. #endif
  254. #ifdef USE_LIBRTMP
  255. Curl_rtmp_version(rtmp_version, sizeof(rtmp_version));
  256. src[i++] = rtmp_version;
  257. #endif
  258. #ifdef USE_GSASL
  259. curl_msnprintf(gsasl_buf, sizeof(gsasl_buf), "libgsasl/%s",
  260. gsasl_check_version(NULL));
  261. src[i++] = gsasl_buf;
  262. #endif
  263. #ifdef HAVE_GSSAPI
  264. #ifdef HAVE_GSSGNU
  265. curl_msnprintf(gss_buf, sizeof(gss_buf), "libgss/%s",
  266. GSS_VERSION);
  267. #elif defined(CURL_KRB5_VERSION)
  268. curl_msnprintf(gss_buf, sizeof(gss_buf), "mit-krb5/%s",
  269. CURL_KRB5_VERSION);
  270. #else
  271. curl_msnprintf(gss_buf, sizeof(gss_buf), "mit-krb5");
  272. #endif
  273. src[i++] = gss_buf;
  274. #endif /* HAVE_GSSAPI */
  275. #ifdef USE_OPENLDAP
  276. oldap_version(ldap_buf, sizeof(ldap_buf));
  277. src[i++] = ldap_buf;
  278. #endif
  279. DEBUGASSERT(i <= VERSION_PARTS);
  280. outp = &out[0];
  281. outlen = sizeof(out);
  282. for(j = 0; j < i; j++) {
  283. size_t n = strlen(src[j]);
  284. /* we need room for a space, the string and the final zero */
  285. if(outlen <= (n + 2))
  286. break;
  287. if(j) {
  288. /* prepend a space if not the first */
  289. *outp++ = ' ';
  290. outlen--;
  291. }
  292. memcpy(outp, src[j], n);
  293. outp += n;
  294. outlen -= n;
  295. }
  296. *outp = 0;
  297. return out;
  298. }
  299. /* data for curl_version_info
  300. Keep the list sorted alphabetically. It is also written so that each
  301. protocol line has its own #if line to make things easier on the eye.
  302. */
  303. static const char * const supported_protocols[] = {
  304. #ifndef CURL_DISABLE_DICT
  305. "dict",
  306. #endif
  307. #ifndef CURL_DISABLE_FILE
  308. "file",
  309. #endif
  310. #ifndef CURL_DISABLE_FTP
  311. "ftp",
  312. #endif
  313. #if defined(USE_SSL) && !defined(CURL_DISABLE_FTP)
  314. "ftps",
  315. #endif
  316. #ifndef CURL_DISABLE_GOPHER
  317. "gopher",
  318. #endif
  319. #if defined(USE_SSL) && !defined(CURL_DISABLE_GOPHER)
  320. "gophers",
  321. #endif
  322. #ifndef CURL_DISABLE_HTTP
  323. "http",
  324. #endif
  325. #if defined(USE_SSL) && !defined(CURL_DISABLE_HTTP)
  326. "https",
  327. #endif
  328. #ifndef CURL_DISABLE_IMAP
  329. "imap",
  330. #endif
  331. #if defined(USE_SSL) && !defined(CURL_DISABLE_IMAP)
  332. "imaps",
  333. #endif
  334. #ifndef CURL_DISABLE_LDAP
  335. "ldap",
  336. #if !defined(CURL_DISABLE_LDAPS) && \
  337. ((defined(USE_OPENLDAP) && defined(USE_SSL)) || \
  338. (!defined(USE_OPENLDAP) && defined(HAVE_LDAP_SSL)))
  339. "ldaps",
  340. #endif
  341. #endif
  342. #ifndef CURL_DISABLE_MQTT
  343. "mqtt",
  344. #endif
  345. #ifndef CURL_DISABLE_POP3
  346. "pop3",
  347. #endif
  348. #if defined(USE_SSL) && !defined(CURL_DISABLE_POP3)
  349. "pop3s",
  350. #endif
  351. #ifdef USE_LIBRTMP
  352. "rtmp",
  353. "rtmpe",
  354. "rtmps",
  355. "rtmpt",
  356. "rtmpte",
  357. "rtmpts",
  358. #endif
  359. #ifndef CURL_DISABLE_RTSP
  360. "rtsp",
  361. #endif
  362. #ifdef USE_SSH
  363. "scp",
  364. "sftp",
  365. #endif
  366. #if !defined(CURL_DISABLE_SMB) && defined(USE_CURL_NTLM_CORE)
  367. "smb",
  368. # ifdef USE_SSL
  369. "smbs",
  370. # endif
  371. #endif
  372. #ifndef CURL_DISABLE_SMTP
  373. "smtp",
  374. #endif
  375. #if defined(USE_SSL) && !defined(CURL_DISABLE_SMTP)
  376. "smtps",
  377. #endif
  378. #ifndef CURL_DISABLE_TELNET
  379. "telnet",
  380. #endif
  381. #ifndef CURL_DISABLE_TFTP
  382. "tftp",
  383. #endif
  384. #ifndef CURL_DISABLE_HTTP
  385. /* WebSocket support relies on HTTP */
  386. #ifndef CURL_DISABLE_WEBSOCKETS
  387. "ws",
  388. #endif
  389. #if defined(USE_SSL) && !defined(CURL_DISABLE_WEBSOCKETS)
  390. "wss",
  391. #endif
  392. #endif
  393. NULL
  394. };
  395. /*
  396. * Feature presence runtime check functions.
  397. *
  398. * Warning: the value returned by these should not change between
  399. * curl_global_init() and curl_global_cleanup() calls.
  400. */
  401. #if defined(USE_LIBIDN2) || defined(USE_WIN32_IDN) || defined(USE_APPLE_IDN)
  402. static int idn_present(curl_version_info_data *info)
  403. {
  404. #if defined(USE_WIN32_IDN) || defined(USE_APPLE_IDN)
  405. (void)info;
  406. return TRUE;
  407. #else
  408. return info->libidn != NULL;
  409. #endif
  410. }
  411. #endif
  412. #if defined(USE_SSL) && !defined(CURL_DISABLE_PROXY) && \
  413. !defined(CURL_DISABLE_HTTP)
  414. static int https_proxy_present(curl_version_info_data *info)
  415. {
  416. (void)info;
  417. return Curl_ssl_supports(NULL, SSLSUPP_HTTPS_PROXY);
  418. }
  419. #endif
  420. #if defined(USE_SSL) && defined(USE_ECH)
  421. static int ech_present(curl_version_info_data *info)
  422. {
  423. (void)info;
  424. return Curl_ssl_supports(NULL, SSLSUPP_ECH);
  425. }
  426. #endif
  427. /*
  428. * Features table.
  429. *
  430. * Keep the features alphabetically sorted.
  431. * Use FEATURE() macro to define an entry: this allows documentation check.
  432. */
  433. #define FEATURE(name, present, bitmask) {(name), (present), (bitmask)}
  434. struct feat {
  435. const char *name;
  436. int (*present)(curl_version_info_data *info);
  437. int bitmask;
  438. };
  439. static const struct feat features_table[] = {
  440. #ifndef CURL_DISABLE_ALTSVC
  441. FEATURE("alt-svc", NULL, CURL_VERSION_ALTSVC),
  442. #endif
  443. #if defined(USE_ARES) && defined(CURLRES_THREADED) && defined(USE_HTTPSRR)
  444. FEATURE("asyn-rr", NULL, 0),
  445. #endif
  446. #ifdef CURLRES_ASYNCH
  447. FEATURE("AsynchDNS", NULL, CURL_VERSION_ASYNCHDNS),
  448. #endif
  449. #ifdef HAVE_BROTLI
  450. FEATURE("brotli", NULL, CURL_VERSION_BROTLI),
  451. #endif
  452. #ifdef DEBUGBUILD
  453. FEATURE("Debug", NULL, CURL_VERSION_DEBUG),
  454. #endif
  455. #if defined(USE_SSL) && defined(USE_ECH)
  456. FEATURE("ECH", ech_present, 0),
  457. #ifndef USE_HTTPSRR
  458. #error "ECH enabled but not HTTPSRR, must be a config error"
  459. #endif
  460. #endif
  461. #ifdef USE_GSASL
  462. FEATURE("gsasl", NULL, CURL_VERSION_GSASL),
  463. #endif
  464. #ifdef HAVE_GSSAPI
  465. FEATURE("GSS-API", NULL, CURL_VERSION_GSSAPI),
  466. #endif
  467. #ifndef CURL_DISABLE_HSTS
  468. FEATURE("HSTS", NULL, CURL_VERSION_HSTS),
  469. #endif
  470. #if !defined(CURL_DISABLE_HTTP) && defined(USE_NGHTTP2)
  471. FEATURE("HTTP2", NULL, CURL_VERSION_HTTP2),
  472. #endif
  473. #if !defined(CURL_DISABLE_HTTP) && defined(USE_HTTP3)
  474. FEATURE("HTTP3", NULL, CURL_VERSION_HTTP3),
  475. #endif
  476. #if defined(USE_SSL) && !defined(CURL_DISABLE_PROXY) && \
  477. !defined(CURL_DISABLE_HTTP)
  478. FEATURE("HTTPS-proxy", https_proxy_present, CURL_VERSION_HTTPS_PROXY),
  479. #endif
  480. #ifdef USE_HTTPSRR
  481. FEATURE("HTTPSRR", NULL, 0),
  482. #endif
  483. #if defined(USE_LIBIDN2) || defined(USE_WIN32_IDN) || defined(USE_APPLE_IDN)
  484. FEATURE("IDN", idn_present, CURL_VERSION_IDN),
  485. #endif
  486. #ifdef USE_IPV6
  487. FEATURE("IPv6", NULL, CURL_VERSION_IPV6),
  488. #endif
  489. #ifdef USE_KERBEROS5
  490. FEATURE("Kerberos", NULL, CURL_VERSION_KERBEROS5),
  491. #endif
  492. #if (SIZEOF_CURL_OFF_T > 4) && \
  493. ( (SIZEOF_OFF_T > 4) || defined(USE_WIN32_LARGE_FILES) )
  494. FEATURE("Largefile", NULL, CURL_VERSION_LARGEFILE),
  495. #endif
  496. #ifdef HAVE_LIBZ
  497. FEATURE("libz", NULL, CURL_VERSION_LIBZ),
  498. #endif
  499. #ifdef CURL_WITH_MULTI_SSL
  500. FEATURE("MultiSSL", NULL, CURL_VERSION_MULTI_SSL),
  501. #endif
  502. #ifdef USE_NTLM
  503. FEATURE("NTLM", NULL, CURL_VERSION_NTLM),
  504. #endif
  505. #ifdef USE_LIBPSL
  506. FEATURE("PSL", NULL, CURL_VERSION_PSL),
  507. #endif
  508. #ifdef USE_APPLE_SECTRUST
  509. FEATURE("AppleSecTrust", NULL, 0),
  510. #endif
  511. #ifdef USE_SPNEGO
  512. FEATURE("SPNEGO", NULL, CURL_VERSION_SPNEGO),
  513. #endif
  514. #ifdef USE_SSL
  515. FEATURE("SSL", NULL, CURL_VERSION_SSL),
  516. #endif
  517. #ifdef USE_SSLS_EXPORT
  518. FEATURE("SSLS-EXPORT", NULL, 0),
  519. #endif
  520. #ifdef USE_WINDOWS_SSPI
  521. FEATURE("SSPI", NULL, CURL_VERSION_SSPI),
  522. #endif
  523. #ifdef GLOBAL_INIT_IS_THREADSAFE
  524. FEATURE("threadsafe", NULL, CURL_VERSION_THREADSAFE),
  525. #endif
  526. #ifdef USE_TLS_SRP
  527. FEATURE("TLS-SRP", NULL, CURL_VERSION_TLSAUTH_SRP),
  528. #endif
  529. #ifdef CURLDEBUG
  530. FEATURE("TrackMemory", NULL, CURL_VERSION_CURLDEBUG),
  531. #endif
  532. #if defined(_WIN32) && defined(UNICODE) && defined(_UNICODE)
  533. FEATURE("Unicode", NULL, CURL_VERSION_UNICODE),
  534. #endif
  535. #ifdef USE_UNIX_SOCKETS
  536. FEATURE("UnixSockets", NULL, CURL_VERSION_UNIX_SOCKETS),
  537. #endif
  538. #ifdef HAVE_ZSTD
  539. FEATURE("zstd", NULL, CURL_VERSION_ZSTD),
  540. #endif
  541. {NULL, NULL, 0}
  542. };
  543. static const char *feature_names[sizeof(features_table) /
  544. sizeof(features_table[0])] = {NULL};
  545. static curl_version_info_data version_info = {
  546. CURLVERSION_NOW,
  547. LIBCURL_VERSION,
  548. LIBCURL_VERSION_NUM,
  549. CURL_OS, /* as found by configure or set by hand at build-time */
  550. 0, /* features bitmask is built at runtime */
  551. NULL, /* ssl_version */
  552. 0, /* ssl_version_num, this is kept at zero */
  553. NULL, /* zlib_version */
  554. supported_protocols,
  555. NULL, /* c-ares version */
  556. 0, /* c-ares version numerical */
  557. NULL, /* libidn version */
  558. 0, /* iconv version */
  559. NULL, /* ssh lib version */
  560. 0, /* brotli_ver_num */
  561. NULL, /* brotli version */
  562. 0, /* nghttp2 version number */
  563. NULL, /* nghttp2 version string */
  564. NULL, /* quic library string */
  565. #ifdef CURL_CA_BUNDLE
  566. CURL_CA_BUNDLE, /* cainfo */
  567. #else
  568. NULL,
  569. #endif
  570. #ifdef CURL_CA_PATH
  571. CURL_CA_PATH, /* capath */
  572. #else
  573. NULL,
  574. #endif
  575. 0, /* zstd_ver_num */
  576. NULL, /* zstd version */
  577. NULL, /* Hyper version */
  578. NULL, /* gsasl version */
  579. feature_names,
  580. NULL /* rtmp version */
  581. };
  582. curl_version_info_data *curl_version_info(CURLversion stamp)
  583. {
  584. size_t n;
  585. const struct feat *p;
  586. int features = 0;
  587. #ifdef USE_SSH
  588. static char ssh_buf[80]; /* 'ssh_buffer' clashes with libssh/libssh.h */
  589. #endif
  590. #ifdef USE_SSL
  591. #ifdef CURL_WITH_MULTI_SSL
  592. static char ssl_buffer[200];
  593. #else
  594. static char ssl_buffer[80];
  595. #endif
  596. #endif
  597. #ifdef HAVE_BROTLI
  598. static char brotli_buffer[80];
  599. #endif
  600. #ifdef HAVE_ZSTD
  601. static char zstd_buffer[80];
  602. #endif
  603. (void)stamp;
  604. #ifdef USE_SSL
  605. Curl_ssl_version(ssl_buffer, sizeof(ssl_buffer));
  606. version_info.ssl_version = ssl_buffer;
  607. #endif
  608. #ifdef HAVE_LIBZ
  609. version_info.libz_version = zlibVersion();
  610. /* libz left NULL if non-existing */
  611. #endif
  612. #ifdef USE_ARES
  613. {
  614. int aresnum;
  615. version_info.ares = ares_version(&aresnum);
  616. version_info.ares_num = aresnum;
  617. }
  618. #endif
  619. #ifdef USE_LIBIDN2
  620. /* This returns a version string if we use the given version or later,
  621. otherwise it returns NULL */
  622. version_info.libidn = idn2_check_version(IDN2_VERSION);
  623. #endif
  624. #ifdef USE_SSH
  625. Curl_ssh_version(ssh_buf, sizeof(ssh_buf));
  626. version_info.libssh_version = ssh_buf;
  627. #endif
  628. #ifdef HAVE_BROTLI
  629. version_info.brotli_ver_num = BrotliDecoderVersion();
  630. brotli_version(brotli_buffer, sizeof(brotli_buffer));
  631. version_info.brotli_version = brotli_buffer;
  632. #endif
  633. #ifdef HAVE_ZSTD
  634. version_info.zstd_ver_num = (unsigned int)ZSTD_versionNumber();
  635. zstd_version(zstd_buffer, sizeof(zstd_buffer));
  636. version_info.zstd_version = zstd_buffer;
  637. #endif
  638. #ifdef USE_NGHTTP2
  639. {
  640. nghttp2_info *h2 = nghttp2_version(0);
  641. version_info.nghttp2_ver_num = (unsigned int)h2->version_num;
  642. version_info.nghttp2_version = h2->version_str;
  643. }
  644. #endif
  645. #if !defined(CURL_DISABLE_HTTP) && defined(USE_HTTP3)
  646. {
  647. static char quicbuffer[80];
  648. Curl_quic_ver(quicbuffer, sizeof(quicbuffer));
  649. version_info.quic_version = quicbuffer;
  650. }
  651. #endif
  652. #ifdef USE_GSASL
  653. {
  654. version_info.gsasl_version = gsasl_check_version(NULL);
  655. }
  656. #endif
  657. /* Get available features, build bitmask and names array. */
  658. n = 0;
  659. for(p = features_table; p->name; p++)
  660. if(!p->present || p->present(&version_info)) {
  661. features |= p->bitmask;
  662. feature_names[n++] = p->name;
  663. }
  664. feature_names[n] = NULL; /* Terminate array. */
  665. version_info.features = features;
  666. #ifdef USE_LIBRTMP
  667. {
  668. static char rtmp_version[30];
  669. Curl_rtmp_version(rtmp_version, sizeof(rtmp_version));
  670. version_info.rtmp_version = rtmp_version;
  671. }
  672. #endif
  673. return &version_info;
  674. }