VirtualBox

source: vbox/trunk/src/libs/curl-7.87.0/lib/version.c@ 98929

Last change on this file since 98929 was 98326, checked in by vboxsync, 2 years ago

curl-7.87.0: Applied and adjusted our curl changes to 7.83.1. bugref:10356

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette