version.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2020, 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 "vssh/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. #ifdef HAVE_BROTLI
  60. static size_t brotli_version(char *buf, size_t bufsz)
  61. {
  62. uint32_t brotli_version = BrotliDecoderVersion();
  63. unsigned int major = brotli_version >> 24;
  64. unsigned int minor = (brotli_version & 0x00FFFFFF) >> 12;
  65. unsigned int patch = brotli_version & 0x00000FFF;
  66. return msnprintf(buf, bufsz, "%u.%u.%u", major, minor, patch);
  67. }
  68. #endif
  69. /*
  70. * curl_version() returns a pointer to a static buffer.
  71. *
  72. * It is implemented to work multi-threaded by making sure repeated invokes
  73. * generate the exact same string and never write any temporary data like
  74. * zeros in the data.
  75. */
  76. #define VERSION_PARTS 14 /* number of substrings we can concatenate */
  77. char *curl_version(void)
  78. {
  79. static char out[300];
  80. char *outp;
  81. size_t outlen;
  82. const char *src[VERSION_PARTS];
  83. #ifdef USE_SSL
  84. char ssl_version[200];
  85. #endif
  86. #ifdef HAVE_LIBZ
  87. char z_version[40];
  88. #endif
  89. #ifdef HAVE_BROTLI
  90. char br_version[40] = "brotli/";
  91. #endif
  92. #ifdef USE_ARES
  93. char cares_version[40];
  94. #endif
  95. #if defined(USE_LIBIDN2)
  96. char idn_version[40];
  97. #endif
  98. #ifdef USE_LIBPSL
  99. char psl_version[40];
  100. #endif
  101. #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
  102. char iconv_version[40]="iconv";
  103. #endif
  104. #ifdef USE_SSH
  105. char ssh_version[40];
  106. #endif
  107. #ifdef USE_NGHTTP2
  108. char h2_version[40];
  109. #endif
  110. #ifdef ENABLE_QUIC
  111. char h3_version[40];
  112. #endif
  113. #ifdef USE_LIBRTMP
  114. char rtmp_version[40];
  115. #endif
  116. int i = 0;
  117. int j;
  118. #ifdef DEBUGBUILD
  119. /* Override version string when environment variable CURL_VERSION is set */
  120. const char *debugversion = getenv("CURL_VERSION");
  121. if(debugversion) {
  122. strncpy(out, debugversion, sizeof(out)-1);
  123. out[sizeof(out)-1] = '\0';
  124. return out;
  125. }
  126. #endif
  127. src[i++] = LIBCURL_NAME "/" LIBCURL_VERSION;
  128. #ifdef USE_SSL
  129. Curl_ssl_version(ssl_version, sizeof(ssl_version));
  130. src[i++] = ssl_version;
  131. #endif
  132. #ifdef HAVE_LIBZ
  133. msnprintf(z_version, sizeof(z_version), "zlib/%s", zlibVersion());
  134. src[i++] = z_version;
  135. #endif
  136. #ifdef HAVE_BROTLI
  137. brotli_version(&br_version[7], sizeof(br_version) - 7);
  138. src[i++] = br_version;
  139. #endif
  140. #ifdef USE_ARES
  141. msnprintf(cares_version, sizeof(cares_version),
  142. "c-ares/%s", ares_version(NULL));
  143. src[i++] = cares_version;
  144. #endif
  145. #ifdef USE_LIBIDN2
  146. msnprintf(idn_version, sizeof(idn_version),
  147. "libidn2/%s", idn2_check_version(NULL));
  148. src[i++] = idn_version;
  149. #elif defined(USE_WIN32_IDN)
  150. src[i++] = (char *)"WinIDN";
  151. #endif
  152. #ifdef USE_LIBPSL
  153. msnprintf(psl_version, sizeof(psl_version), "libpsl/%s", psl_get_version());
  154. src[i++] = psl_version;
  155. #endif
  156. #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
  157. #ifdef _LIBICONV_VERSION
  158. msnprintf(iconv_version, sizeof(iconv_version), "iconv/%d.%d",
  159. _LIBICONV_VERSION >> 8, _LIBICONV_VERSION & 255);
  160. #else
  161. /* version unknown, let the default stand */
  162. #endif /* _LIBICONV_VERSION */
  163. src[i++] = iconv_version;
  164. #endif
  165. #ifdef USE_SSH
  166. Curl_ssh_version(ssh_version, sizeof(ssh_version));
  167. src[i++] = ssh_version;
  168. #endif
  169. #ifdef USE_NGHTTP2
  170. Curl_http2_ver(h2_version, sizeof(h2_version));
  171. src[i++] = h2_version;
  172. #endif
  173. #ifdef ENABLE_QUIC
  174. Curl_quic_ver(h3_version, sizeof(h3_version));
  175. src[i++] = h3_version;
  176. #endif
  177. #ifdef USE_LIBRTMP
  178. {
  179. char suff[2];
  180. if(RTMP_LIB_VERSION & 0xff) {
  181. suff[0] = (RTMP_LIB_VERSION & 0xff) + 'a' - 1;
  182. suff[1] = '\0';
  183. }
  184. else
  185. suff[0] = '\0';
  186. msnprintf(rtmp_version, sizeof(rtmp_version), "librtmp/%d.%d%s",
  187. RTMP_LIB_VERSION >> 16, (RTMP_LIB_VERSION >> 8) & 0xff,
  188. suff);
  189. src[i++] = rtmp_version;
  190. }
  191. #endif
  192. DEBUGASSERT(i <= VERSION_PARTS);
  193. outp = &out[0];
  194. outlen = sizeof(out);
  195. for(j = 0; j < i; j++) {
  196. size_t n = strlen(src[j]);
  197. /* we need room for a space, the string and the final zero */
  198. if(outlen <= (n + 2))
  199. break;
  200. if(j) {
  201. /* prepend a space if not the first */
  202. *outp++ = ' ';
  203. outlen--;
  204. }
  205. memcpy(outp, src[j], n);
  206. outp += n;
  207. outlen -= n;
  208. }
  209. *outp = 0;
  210. return out;
  211. }
  212. /* data for curl_version_info
  213. Keep the list sorted alphabetically. It is also written so that each
  214. protocol line has its own #if line to make things easier on the eye.
  215. */
  216. static const char * const protocols[] = {
  217. #ifndef CURL_DISABLE_DICT
  218. "dict",
  219. #endif
  220. #ifndef CURL_DISABLE_FILE
  221. "file",
  222. #endif
  223. #ifndef CURL_DISABLE_FTP
  224. "ftp",
  225. #endif
  226. #if defined(USE_SSL) && !defined(CURL_DISABLE_FTP)
  227. "ftps",
  228. #endif
  229. #ifndef CURL_DISABLE_GOPHER
  230. "gopher",
  231. #endif
  232. #ifndef CURL_DISABLE_HTTP
  233. "http",
  234. #endif
  235. #if defined(USE_SSL) && !defined(CURL_DISABLE_HTTP)
  236. "https",
  237. #endif
  238. #ifndef CURL_DISABLE_IMAP
  239. "imap",
  240. #endif
  241. #if defined(USE_SSL) && !defined(CURL_DISABLE_IMAP)
  242. "imaps",
  243. #endif
  244. #ifndef CURL_DISABLE_LDAP
  245. "ldap",
  246. #if !defined(CURL_DISABLE_LDAPS) && \
  247. ((defined(USE_OPENLDAP) && defined(USE_SSL)) || \
  248. (!defined(USE_OPENLDAP) && defined(HAVE_LDAP_SSL)))
  249. "ldaps",
  250. #endif
  251. #endif
  252. #ifdef CURL_ENABLE_MQTT
  253. "mqtt",
  254. #endif
  255. #ifndef CURL_DISABLE_POP3
  256. "pop3",
  257. #endif
  258. #if defined(USE_SSL) && !defined(CURL_DISABLE_POP3)
  259. "pop3s",
  260. #endif
  261. #ifdef USE_LIBRTMP
  262. "rtmp",
  263. #endif
  264. #ifndef CURL_DISABLE_RTSP
  265. "rtsp",
  266. #endif
  267. #if defined(USE_SSH) && !defined(USE_WOLFSSH)
  268. "scp",
  269. #endif
  270. #ifdef USE_SSH
  271. "sftp",
  272. #endif
  273. #if !defined(CURL_DISABLE_SMB) && defined(USE_NTLM) && \
  274. (CURL_SIZEOF_CURL_OFF_T > 4) && \
  275. (!defined(USE_WINDOWS_SSPI) || defined(USE_WIN32_CRYPTO))
  276. "smb",
  277. # ifdef USE_SSL
  278. "smbs",
  279. # endif
  280. #endif
  281. #ifndef CURL_DISABLE_SMTP
  282. "smtp",
  283. #endif
  284. #if defined(USE_SSL) && !defined(CURL_DISABLE_SMTP)
  285. "smtps",
  286. #endif
  287. #ifndef CURL_DISABLE_TELNET
  288. "telnet",
  289. #endif
  290. #ifndef CURL_DISABLE_TFTP
  291. "tftp",
  292. #endif
  293. NULL
  294. };
  295. static curl_version_info_data version_info = {
  296. CURLVERSION_NOW,
  297. LIBCURL_VERSION,
  298. LIBCURL_VERSION_NUM,
  299. OS, /* as found by configure or set by hand at build-time */
  300. 0 /* features is 0 by default */
  301. #ifdef ENABLE_IPV6
  302. | CURL_VERSION_IPV6
  303. #endif
  304. #ifdef USE_SSL
  305. | CURL_VERSION_SSL
  306. #endif
  307. #ifdef USE_NTLM
  308. | CURL_VERSION_NTLM
  309. #endif
  310. #if !defined(CURL_DISABLE_HTTP) && defined(USE_NTLM) && \
  311. defined(NTLM_WB_ENABLED)
  312. | CURL_VERSION_NTLM_WB
  313. #endif
  314. #ifdef USE_SPNEGO
  315. | CURL_VERSION_SPNEGO
  316. #endif
  317. #ifdef USE_KERBEROS5
  318. | CURL_VERSION_KERBEROS5
  319. #endif
  320. #ifdef HAVE_GSSAPI
  321. | CURL_VERSION_GSSAPI
  322. #endif
  323. #ifdef USE_WINDOWS_SSPI
  324. | CURL_VERSION_SSPI
  325. #endif
  326. #ifdef HAVE_LIBZ
  327. | CURL_VERSION_LIBZ
  328. #endif
  329. #ifdef DEBUGBUILD
  330. | CURL_VERSION_DEBUG
  331. #endif
  332. #ifdef CURLDEBUG
  333. | CURL_VERSION_CURLDEBUG
  334. #endif
  335. #ifdef CURLRES_ASYNCH
  336. | CURL_VERSION_ASYNCHDNS
  337. #endif
  338. #if (CURL_SIZEOF_CURL_OFF_T > 4) && \
  339. ( (SIZEOF_OFF_T > 4) || defined(USE_WIN32_LARGE_FILES) )
  340. | CURL_VERSION_LARGEFILE
  341. #endif
  342. #if defined(CURL_DOES_CONVERSIONS)
  343. | CURL_VERSION_CONV
  344. #endif
  345. #if defined(USE_TLS_SRP)
  346. | CURL_VERSION_TLSAUTH_SRP
  347. #endif
  348. #if defined(USE_NGHTTP2)
  349. | CURL_VERSION_HTTP2
  350. #endif
  351. #if defined(ENABLE_QUIC)
  352. | CURL_VERSION_HTTP3
  353. #endif
  354. #if defined(USE_UNIX_SOCKETS)
  355. | CURL_VERSION_UNIX_SOCKETS
  356. #endif
  357. #if defined(USE_LIBPSL)
  358. | CURL_VERSION_PSL
  359. #endif
  360. #if defined(CURL_WITH_MULTI_SSL)
  361. | CURL_VERSION_MULTI_SSL
  362. #endif
  363. #if defined(HAVE_BROTLI)
  364. | CURL_VERSION_BROTLI
  365. #endif
  366. #if defined(USE_ALTSVC)
  367. | CURL_VERSION_ALTSVC
  368. #endif
  369. ,
  370. NULL, /* ssl_version */
  371. 0, /* ssl_version_num, this is kept at zero */
  372. NULL, /* zlib_version */
  373. protocols,
  374. NULL, /* c-ares version */
  375. 0, /* c-ares version numerical */
  376. NULL, /* libidn version */
  377. 0, /* iconv version */
  378. NULL, /* ssh lib version */
  379. 0, /* brotli_ver_num */
  380. NULL, /* brotli version */
  381. 0, /* nghttp2 version number */
  382. NULL, /* nghttp2 version string */
  383. NULL, /* quic library string */
  384. #ifdef CURL_CA_BUNDLE
  385. CURL_CA_BUNDLE, /* cainfo */
  386. #else
  387. NULL,
  388. #endif
  389. #ifdef CURL_CA_PATH
  390. CURL_CA_PATH /* capath */
  391. #else
  392. NULL
  393. #endif
  394. };
  395. curl_version_info_data *curl_version_info(CURLversion stamp)
  396. {
  397. #if defined(USE_SSH)
  398. static char ssh_buffer[80];
  399. #endif
  400. #ifdef USE_SSL
  401. #ifdef CURL_WITH_MULTI_SSL
  402. static char ssl_buffer[200];
  403. #else
  404. static char ssl_buffer[80];
  405. #endif
  406. #endif
  407. #ifdef HAVE_BROTLI
  408. static char brotli_buffer[80];
  409. #endif
  410. #ifdef USE_SSL
  411. Curl_ssl_version(ssl_buffer, sizeof(ssl_buffer));
  412. version_info.ssl_version = ssl_buffer;
  413. if(Curl_ssl->supports & SSLSUPP_HTTPS_PROXY)
  414. version_info.features |= CURL_VERSION_HTTPS_PROXY;
  415. else
  416. version_info.features &= ~CURL_VERSION_HTTPS_PROXY;
  417. #endif
  418. #ifdef HAVE_LIBZ
  419. version_info.libz_version = zlibVersion();
  420. /* libz left NULL if non-existing */
  421. #endif
  422. #ifdef USE_ARES
  423. {
  424. int aresnum;
  425. version_info.ares = ares_version(&aresnum);
  426. version_info.ares_num = aresnum;
  427. }
  428. #endif
  429. #ifdef USE_LIBIDN2
  430. /* This returns a version string if we use the given version or later,
  431. otherwise it returns NULL */
  432. version_info.libidn = idn2_check_version(IDN2_VERSION);
  433. if(version_info.libidn)
  434. version_info.features |= CURL_VERSION_IDN;
  435. #elif defined(USE_WIN32_IDN)
  436. version_info.features |= CURL_VERSION_IDN;
  437. #endif
  438. #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
  439. #ifdef _LIBICONV_VERSION
  440. version_info.iconv_ver_num = _LIBICONV_VERSION;
  441. #else
  442. /* version unknown */
  443. version_info.iconv_ver_num = -1;
  444. #endif /* _LIBICONV_VERSION */
  445. #endif
  446. #if defined(USE_SSH)
  447. Curl_ssh_version(ssh_buffer, sizeof(ssh_buffer));
  448. version_info.libssh_version = ssh_buffer;
  449. #endif
  450. #ifdef HAVE_BROTLI
  451. version_info.brotli_ver_num = BrotliDecoderVersion();
  452. brotli_version(brotli_buffer, sizeof(brotli_buffer));
  453. version_info.brotli_version = brotli_buffer;
  454. #endif
  455. #ifdef USE_NGHTTP2
  456. {
  457. nghttp2_info *h2 = nghttp2_version(0);
  458. version_info.nghttp2_ver_num = h2->version_num;
  459. version_info.nghttp2_version = h2->version_str;
  460. }
  461. #endif
  462. #ifdef ENABLE_QUIC
  463. {
  464. static char quicbuffer[80];
  465. Curl_quic_ver(quicbuffer, sizeof(quicbuffer));
  466. version_info.quic_version = quicbuffer;
  467. }
  468. #endif
  469. (void)stamp; /* avoid compiler warnings, we don't use this */
  470. return &version_info;
  471. }