1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
23 #include "curl_setup.h"
25 #include <curl/curl.h>
27 #include "vtls/vtls.h"
30 #include "curl_printf.h"
33 # if defined(CURL_STATICLIB) && !defined(CARES_STATICLIB) && \
34 (defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__))
35 # define CARES_STATICLIB
48 #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
53 #include <librtmp/rtmp.h>
60 #ifdef HAVE_LIBSSH2_VERSION
61 /* get it run-time if possible */
62 #define CURL_LIBSSH2_VERSION libssh2_version(0)
64 /* use build-time if run-time not possible */
65 #define CURL_LIBSSH2_VERSION LIBSSH2_VERSION
71 /* zlib pollutes the namespace with this definition */
77 #include <brotli/decode.h>
80 void Curl_version_init(void);
82 /* For thread safety purposes this function is called by global_init so that
83 the static data in both version functions is initialized. */
84 void Curl_version_init(void)
87 curl_version_info(CURLVERSION_NOW);
91 static size_t brotli_version(char *buf, size_t bufsz)
93 uint32_t brotli_version = BrotliDecoderVersion();
94 unsigned int major = brotli_version >> 24;
95 unsigned int minor = (brotli_version & 0x00FFFFFF) >> 12;
96 unsigned int patch = brotli_version & 0x00000FFF;
98 return snprintf(buf, bufsz, "%u.%u.%u", major, minor, patch);
102 char *curl_version(void)
104 static bool initialized;
105 static char version[200];
108 size_t left = sizeof(version);
113 strcpy(ptr, LIBCURL_NAME "/" LIBCURL_VERSION);
119 len = Curl_ssl_version(ptr + 1, left - 1);
129 len = snprintf(ptr, left, " zlib/%s", zlibVersion());
134 len = snprintf(ptr, left, "%s", " brotli/");
137 len = brotli_version(ptr, left);
142 /* this function is only present in c-ares, not in the original ares */
143 len = snprintf(ptr, left, " c-ares/%s", ares_version(NULL));
148 if(idn2_check_version(IDN2_VERSION)) {
149 len = snprintf(ptr, left, " libidn2/%s", idn2_check_version(NULL));
155 len = snprintf(ptr, left, " libpsl/%s", psl_get_version());
160 len = snprintf(ptr, left, " WinIDN");
164 #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
165 #ifdef _LIBICONV_VERSION
166 len = snprintf(ptr, left, " iconv/%d.%d",
167 _LIBICONV_VERSION >> 8, _LIBICONV_VERSION & 255);
169 /* version unknown */
170 len = snprintf(ptr, left, " iconv");
171 #endif /* _LIBICONV_VERSION */
176 len = snprintf(ptr, left, " libssh2/%s", CURL_LIBSSH2_VERSION);
181 len = snprintf(ptr, left, " libssh/%s", CURL_LIBSSH_VERSION);
186 len = Curl_http2_ver(ptr, left);
193 if(RTMP_LIB_VERSION & 0xff) {
194 suff[0] = (RTMP_LIB_VERSION & 0xff) + 'a' - 1;
200 snprintf(ptr, left, " librtmp/%d.%d%s",
201 RTMP_LIB_VERSION >> 16, (RTMP_LIB_VERSION >> 8) & 0xff,
204 If another lib version is added below this one, this code would
207 len = what snprintf() returned
219 /* data for curl_version_info
221 Keep the list sorted alphabetically. It is also written so that each
222 protocol line has its own #if line to make things easier on the eye.
225 static const char * const protocols[] = {
226 #ifndef CURL_DISABLE_DICT
229 #ifndef CURL_DISABLE_FILE
232 #ifndef CURL_DISABLE_FTP
235 #if defined(USE_SSL) && !defined(CURL_DISABLE_FTP)
238 #ifndef CURL_DISABLE_GOPHER
241 #ifndef CURL_DISABLE_HTTP
244 #if defined(USE_SSL) && !defined(CURL_DISABLE_HTTP)
247 #ifndef CURL_DISABLE_IMAP
250 #if defined(USE_SSL) && !defined(CURL_DISABLE_IMAP)
253 #ifndef CURL_DISABLE_LDAP
255 #if !defined(CURL_DISABLE_LDAPS) && \
256 ((defined(USE_OPENLDAP) && defined(USE_SSL)) || \
257 (!defined(USE_OPENLDAP) && defined(HAVE_LDAP_SSL)))
261 #ifndef CURL_DISABLE_POP3
264 #if defined(USE_SSL) && !defined(CURL_DISABLE_POP3)
270 #ifndef CURL_DISABLE_RTSP
273 #if defined(USE_LIBSSH) || defined(USE_LIBSSH2)
277 #if !defined(CURL_DISABLE_SMB) && defined(USE_NTLM) && \
278 (CURL_SIZEOF_CURL_OFF_T > 4) && \
279 (!defined(USE_WINDOWS_SSPI) || defined(USE_WIN32_CRYPTO))
285 #ifndef CURL_DISABLE_SMTP
288 #if defined(USE_SSL) && !defined(CURL_DISABLE_SMTP)
291 #ifndef CURL_DISABLE_TELNET
294 #ifndef CURL_DISABLE_TFTP
301 static curl_version_info_data version_info = {
305 OS, /* as found by configure or set by hand at build-time */
306 0 /* features is 0 by default */
316 #if !defined(CURL_DISABLE_HTTP) && defined(USE_NTLM) && \
317 defined(NTLM_WB_ENABLED)
318 | CURL_VERSION_NTLM_WB
321 | CURL_VERSION_SPNEGO
324 | CURL_VERSION_KERBEROS5
327 | CURL_VERSION_GSSAPI
329 #ifdef USE_WINDOWS_SSPI
339 | CURL_VERSION_CURLDEBUG
341 #ifdef CURLRES_ASYNCH
342 | CURL_VERSION_ASYNCHDNS
344 #if (CURL_SIZEOF_CURL_OFF_T > 4) && \
345 ( (SIZEOF_OFF_T > 4) || defined(USE_WIN32_LARGE_FILES) )
346 | CURL_VERSION_LARGEFILE
348 #if defined(CURL_DOES_CONVERSIONS)
351 #if defined(USE_TLS_SRP)
352 | CURL_VERSION_TLSAUTH_SRP
354 #if defined(USE_NGHTTP2)
357 #if defined(USE_UNIX_SOCKETS)
358 | CURL_VERSION_UNIX_SOCKETS
360 #if defined(USE_LIBPSL)
363 #if defined(CURL_WITH_MULTI_SSL)
364 | CURL_VERSION_MULTI_SSL
366 #if defined(HAVE_BROTLI)
367 | CURL_VERSION_BROTLI
370 NULL, /* ssl_version */
371 0, /* ssl_version_num, this is kept at zero */
372 NULL, /* zlib_version */
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 */
383 curl_version_info_data *curl_version_info(CURLversion stamp)
385 static bool initialized;
386 #if defined(USE_LIBSSH) || defined(USE_LIBSSH2)
387 static char ssh_buffer[80];
390 static char ssl_buffer[80];
393 static char brotli_buffer[80];
397 return &version_info;
400 Curl_ssl_version(ssl_buffer, sizeof(ssl_buffer));
401 version_info.ssl_version = ssl_buffer;
402 if(Curl_ssl->support_https_proxy)
403 version_info.features |= CURL_VERSION_HTTPS_PROXY;
405 version_info.features &= ~CURL_VERSION_HTTPS_PROXY;
409 version_info.libz_version = zlibVersion();
410 /* libz left NULL if non-existing */
415 version_info.ares = ares_version(&aresnum);
416 version_info.ares_num = aresnum;
420 /* This returns a version string if we use the given version or later,
421 otherwise it returns NULL */
422 version_info.libidn = idn2_check_version(IDN2_VERSION);
423 if(version_info.libidn)
424 version_info.features |= CURL_VERSION_IDN;
425 #elif defined(USE_WIN32_IDN)
426 version_info.features |= CURL_VERSION_IDN;
429 #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
430 #ifdef _LIBICONV_VERSION
431 version_info.iconv_ver_num = _LIBICONV_VERSION;
433 /* version unknown */
434 version_info.iconv_ver_num = -1;
435 #endif /* _LIBICONV_VERSION */
438 #if defined(USE_LIBSSH2)
439 snprintf(ssh_buffer, sizeof(ssh_buffer), "libssh2/%s", LIBSSH2_VERSION);
440 version_info.libssh_version = ssh_buffer;
441 #elif defined(USE_LIBSSH)
442 snprintf(ssh_buffer, sizeof(ssh_buffer), "libssh/%s", CURL_LIBSSH_VERSION);
443 version_info.libssh_version = ssh_buffer;
447 version_info.brotli_ver_num = BrotliDecoderVersion();
448 brotli_version(brotli_buffer, sizeof brotli_buffer);
449 version_info.brotli_version = brotli_buffer;
452 (void)stamp; /* avoid compiler warnings, we don't use this */
455 return &version_info;