VirtualBox

source: vbox/trunk/src/libs/curl-8.7.1/lib/version.c@ 106165

最後變更 在這個檔案從106165是 104083,由 vboxsync 提交於 8 月 前

curl-8.7.1: Applied and adjusted our curl changes to 8.4.0. bugref:10639

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

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