VirtualBox

source: vbox/trunk/src/libs/curl-7.83.1/lib/version.c@ 97623

Last change on this file since 97623 was 95312, checked in by vboxsync, 3 years ago

libs/{curl,libxml2}: OSE export fixes, bugref:8515

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