1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2016, 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"
29 #include "curl_printf.h"
32 # if defined(CURL_STATICLIB) && !defined(CARES_STATICLIB) && \
33 (defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__))
34 # define CARES_STATICLIB
40 #include <stringprep.h>
47 #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
52 #include <librtmp/rtmp.h>
59 #ifdef HAVE_LIBSSH2_VERSION
60 /* get it run-time if possible */
61 #define CURL_LIBSSH2_VERSION libssh2_version(0)
63 /* use build-time if run-time not possible */
64 #define CURL_LIBSSH2_VERSION LIBSSH2_VERSION
67 void Curl_version_init(void);
69 /* For thread safety purposes this function is called by global_init so that
70 the static data in both version functions is initialized. */
71 void Curl_version_init(void)
74 curl_version_info(CURLVERSION_NOW);
77 char *curl_version(void)
79 static bool initialized;
80 static char version[200];
83 size_t left = sizeof(version);
88 strcpy(ptr, LIBCURL_NAME "/" LIBCURL_VERSION);
94 len = Curl_ssl_version(ptr + 1, left - 1);
104 len = snprintf(ptr, left, " zlib/%s", zlibVersion());
109 /* this function is only present in c-ares, not in the original ares */
110 len = snprintf(ptr, left, " c-ares/%s", ares_version(NULL));
115 if(stringprep_check_version(LIBIDN_REQUIRED_VERSION)) {
116 len = snprintf(ptr, left, " libidn/%s", stringprep_check_version(NULL));
122 len = snprintf(ptr, left, " libpsl/%s", psl_get_version());
127 len = snprintf(ptr, left, " WinIDN");
131 #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
132 #ifdef _LIBICONV_VERSION
133 len = snprintf(ptr, left, " iconv/%d.%d",
134 _LIBICONV_VERSION >> 8, _LIBICONV_VERSION & 255);
136 /* version unknown */
137 len = snprintf(ptr, left, " iconv");
138 #endif /* _LIBICONV_VERSION */
143 len = snprintf(ptr, left, " libssh2/%s", CURL_LIBSSH2_VERSION);
148 len = Curl_http2_ver(ptr, left);
155 if(RTMP_LIB_VERSION & 0xff) {
156 suff[0] = (RTMP_LIB_VERSION & 0xff) + 'a' - 1;
162 snprintf(ptr, left, " librtmp/%d.%d%s",
163 RTMP_LIB_VERSION >> 16, (RTMP_LIB_VERSION >> 8) & 0xff,
166 If another lib version is added below this one, this code would
169 len = what snprintf() returned
181 /* data for curl_version_info
183 Keep the list sorted alphabetically. It is also written so that each
184 protocol line has its own #if line to make things easier on the eye.
187 static const char * const protocols[] = {
188 #ifndef CURL_DISABLE_DICT
191 #ifndef CURL_DISABLE_FILE
194 #ifndef CURL_DISABLE_FTP
197 #if defined(USE_SSL) && !defined(CURL_DISABLE_FTP)
200 #ifndef CURL_DISABLE_GOPHER
203 #ifndef CURL_DISABLE_HTTP
206 #if defined(USE_SSL) && !defined(CURL_DISABLE_HTTP)
209 #ifndef CURL_DISABLE_IMAP
212 #if defined(USE_SSL) && !defined(CURL_DISABLE_IMAP)
215 #ifndef CURL_DISABLE_LDAP
217 #if !defined(CURL_DISABLE_LDAPS) && \
218 ((defined(USE_OPENLDAP) && defined(USE_SSL)) || \
219 (!defined(USE_OPENLDAP) && defined(HAVE_LDAP_SSL)))
223 #ifndef CURL_DISABLE_POP3
226 #if defined(USE_SSL) && !defined(CURL_DISABLE_POP3)
232 #ifndef CURL_DISABLE_RTSP
241 #if !defined(CURL_DISABLE_SMB) && defined(USE_NTLM) && \
242 (CURL_SIZEOF_CURL_OFF_T > 4) && \
243 (!defined(USE_WINDOWS_SSPI) || defined(USE_WIN32_CRYPTO))
249 #ifndef CURL_DISABLE_SMTP
252 #if defined(USE_SSL) && !defined(CURL_DISABLE_SMTP)
255 #ifndef CURL_DISABLE_TELNET
258 #ifndef CURL_DISABLE_TFTP
265 static curl_version_info_data version_info = {
269 OS, /* as found by configure or set by hand at build-time */
270 0 /* features is 0 by default */
280 #if !defined(CURL_DISABLE_HTTP) && defined(USE_NTLM) && \
281 defined(NTLM_WB_ENABLED)
282 | CURL_VERSION_NTLM_WB
285 | CURL_VERSION_SPNEGO
288 | CURL_VERSION_KERBEROS5
291 | CURL_VERSION_GSSAPI
293 #ifdef USE_WINDOWS_SSPI
303 | CURL_VERSION_CURLDEBUG
305 #ifdef CURLRES_ASYNCH
306 | CURL_VERSION_ASYNCHDNS
308 #if (CURL_SIZEOF_CURL_OFF_T > 4) && \
309 ( (SIZEOF_OFF_T > 4) || defined(USE_WIN32_LARGE_FILES) )
310 | CURL_VERSION_LARGEFILE
312 #if defined(CURL_DOES_CONVERSIONS)
315 #if defined(USE_TLS_SRP)
316 | CURL_VERSION_TLSAUTH_SRP
318 #if defined(USE_NGHTTP2)
321 #if defined(USE_UNIX_SOCKETS)
322 | CURL_VERSION_UNIX_SOCKETS
324 #if defined(USE_LIBPSL)
328 NULL, /* ssl_version */
329 0, /* ssl_version_num, this is kept at zero */
330 NULL, /* zlib_version */
332 NULL, /* c-ares version */
333 0, /* c-ares version numerical */
334 NULL, /* libidn version */
335 0, /* iconv version */
336 NULL, /* ssh lib version */
339 curl_version_info_data *curl_version_info(CURLversion stamp)
341 static bool initialized;
343 static char ssh_buffer[80];
346 static char ssl_buffer[80];
350 return &version_info;
353 Curl_ssl_version(ssl_buffer, sizeof(ssl_buffer));
354 version_info.ssl_version = ssl_buffer;
358 version_info.libz_version = zlibVersion();
359 /* libz left NULL if non-existing */
364 version_info.ares = ares_version(&aresnum);
365 version_info.ares_num = aresnum;
369 /* This returns a version string if we use the given version or later,
370 otherwise it returns NULL */
371 version_info.libidn = stringprep_check_version(LIBIDN_REQUIRED_VERSION);
372 if(version_info.libidn)
373 version_info.features |= CURL_VERSION_IDN;
374 #elif defined(USE_WIN32_IDN)
375 version_info.features |= CURL_VERSION_IDN;
378 #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
379 #ifdef _LIBICONV_VERSION
380 version_info.iconv_ver_num = _LIBICONV_VERSION;
382 /* version unknown */
383 version_info.iconv_ver_num = -1;
384 #endif /* _LIBICONV_VERSION */
388 snprintf(ssh_buffer, sizeof(ssh_buffer), "libssh2/%s", LIBSSH2_VERSION);
389 version_info.libssh_version = ssh_buffer;
392 (void)stamp; /* avoid compiler warnings, we don't use this */
395 return &version_info;