[331] | 1 | /***************************************************************************
|
---|
| 2 | * _ _ ____ _
|
---|
| 3 | * Project ___| | | | _ \| |
|
---|
| 4 | * / __| | | | |_) | |
|
---|
| 5 | * | (__| |_| | _ <| |___
|
---|
| 6 | * \___|\___/|_| \_\_____|
|
---|
| 7 | *
|
---|
| 8 | * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, 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.haxx.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 "curl_printf.h"
|
---|
| 30 |
|
---|
| 31 | #ifdef USE_ARES
|
---|
| 32 | # if defined(CURL_STATICLIB) && !defined(CARES_STATICLIB) && \
|
---|
| 33 | (defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__))
|
---|
| 34 | # define CARES_STATICLIB
|
---|
| 35 | # endif
|
---|
| 36 | # include <ares.h>
|
---|
| 37 | #endif
|
---|
| 38 |
|
---|
| 39 | #ifdef USE_LIBIDN2
|
---|
| 40 | #include <idn2.h>
|
---|
| 41 | #endif
|
---|
| 42 |
|
---|
| 43 | #ifdef USE_LIBPSL
|
---|
| 44 | #include <libpsl.h>
|
---|
| 45 | #endif
|
---|
| 46 |
|
---|
| 47 | #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
|
---|
| 48 | #include <iconv.h>
|
---|
| 49 | #endif
|
---|
| 50 |
|
---|
| 51 | #ifdef USE_LIBRTMP
|
---|
| 52 | #include <librtmp/rtmp.h>
|
---|
| 53 | #endif
|
---|
| 54 |
|
---|
| 55 | #ifdef USE_LIBSSH2
|
---|
| 56 | #include <libssh2.h>
|
---|
| 57 | #endif
|
---|
| 58 |
|
---|
| 59 | #ifdef HAVE_LIBSSH2_VERSION
|
---|
| 60 | /* get it run-time if possible */
|
---|
| 61 | #define CURL_LIBSSH2_VERSION libssh2_version(0)
|
---|
| 62 | #else
|
---|
| 63 | /* use build-time if run-time not possible */
|
---|
| 64 | #define CURL_LIBSSH2_VERSION LIBSSH2_VERSION
|
---|
| 65 | #endif
|
---|
| 66 |
|
---|
| 67 | #ifdef HAVE_ZLIB_H
|
---|
| 68 | #include <zlib.h>
|
---|
| 69 | #ifdef __SYMBIAN32__
|
---|
| 70 | /* zlib pollutes the namespace with this definition */
|
---|
| 71 | #undef WIN32
|
---|
| 72 | #endif
|
---|
| 73 | #endif
|
---|
| 74 |
|
---|
| 75 | #ifdef HAVE_BROTLI
|
---|
| 76 | #include <brotli/decode.h>
|
---|
| 77 | #endif
|
---|
| 78 |
|
---|
| 79 | void Curl_version_init(void);
|
---|
| 80 |
|
---|
| 81 | /* For thread safety purposes this function is called by global_init so that
|
---|
| 82 | the static data in both version functions is initialized. */
|
---|
| 83 | void Curl_version_init(void)
|
---|
| 84 | {
|
---|
| 85 | curl_version();
|
---|
| 86 | curl_version_info(CURLVERSION_NOW);
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | #ifdef HAVE_BROTLI
|
---|
| 90 | static size_t brotli_version(char *buf, size_t bufsz)
|
---|
| 91 | {
|
---|
| 92 | uint32_t brotli_version = BrotliDecoderVersion();
|
---|
| 93 | unsigned int major = brotli_version >> 24;
|
---|
| 94 | unsigned int minor = (brotli_version & 0x00FFFFFF) >> 12;
|
---|
| 95 | unsigned int patch = brotli_version & 0x00000FFF;
|
---|
| 96 |
|
---|
| 97 | return snprintf(buf, bufsz, "%u.%u.%u", major, minor, patch);
|
---|
| 98 | }
|
---|
| 99 | #endif
|
---|
| 100 |
|
---|
| 101 | char *curl_version(void)
|
---|
| 102 | {
|
---|
| 103 | static bool initialized;
|
---|
| 104 | static char version[200];
|
---|
| 105 | char *ptr = version;
|
---|
| 106 | size_t len;
|
---|
| 107 | size_t left = sizeof(version);
|
---|
| 108 |
|
---|
| 109 | if(initialized)
|
---|
| 110 | return version;
|
---|
| 111 |
|
---|
| 112 | strcpy(ptr, LIBCURL_NAME "/" LIBCURL_VERSION);
|
---|
| 113 | len = strlen(ptr);
|
---|
| 114 | left -= len;
|
---|
| 115 | ptr += len;
|
---|
| 116 |
|
---|
| 117 | if(left > 1) {
|
---|
| 118 | len = Curl_ssl_version(ptr + 1, left - 1);
|
---|
| 119 |
|
---|
| 120 | if(len > 0) {
|
---|
| 121 | *ptr = ' ';
|
---|
| 122 | left -= ++len;
|
---|
| 123 | ptr += len;
|
---|
| 124 | }
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | #ifdef HAVE_LIBZ
|
---|
| 128 | len = snprintf(ptr, left, " zlib/%s", zlibVersion());
|
---|
| 129 | left -= len;
|
---|
| 130 | ptr += len;
|
---|
| 131 | #endif
|
---|
| 132 | #ifdef HAVE_BROTLI
|
---|
| 133 | len = snprintf(ptr, left, "%s", " brotli/");
|
---|
| 134 | left -= len;
|
---|
| 135 | ptr += len;
|
---|
| 136 | len = brotli_version(ptr, left);
|
---|
| 137 | left -= len;
|
---|
| 138 | ptr += len;
|
---|
| 139 | #endif
|
---|
| 140 | #ifdef USE_ARES
|
---|
| 141 | /* this function is only present in c-ares, not in the original ares */
|
---|
| 142 | len = snprintf(ptr, left, " c-ares/%s", ares_version(NULL));
|
---|
| 143 | left -= len;
|
---|
| 144 | ptr += len;
|
---|
| 145 | #endif
|
---|
| 146 | #ifdef USE_LIBIDN2
|
---|
| 147 | if(idn2_check_version(IDN2_VERSION)) {
|
---|
| 148 | len = snprintf(ptr, left, " libidn2/%s", idn2_check_version(NULL));
|
---|
| 149 | left -= len;
|
---|
| 150 | ptr += len;
|
---|
| 151 | }
|
---|
| 152 | #endif
|
---|
| 153 | #ifdef USE_LIBPSL
|
---|
| 154 | len = snprintf(ptr, left, " libpsl/%s", psl_get_version());
|
---|
| 155 | left -= len;
|
---|
| 156 | ptr += len;
|
---|
| 157 | #endif
|
---|
| 158 | #ifdef USE_WIN32_IDN
|
---|
| 159 | len = snprintf(ptr, left, " WinIDN");
|
---|
| 160 | left -= len;
|
---|
| 161 | ptr += len;
|
---|
| 162 | #endif
|
---|
| 163 | #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
|
---|
| 164 | #ifdef _LIBICONV_VERSION
|
---|
| 165 | len = snprintf(ptr, left, " iconv/%d.%d",
|
---|
| 166 | _LIBICONV_VERSION >> 8, _LIBICONV_VERSION & 255);
|
---|
| 167 | #else
|
---|
| 168 | /* version unknown */
|
---|
| 169 | len = snprintf(ptr, left, " iconv");
|
---|
| 170 | #endif /* _LIBICONV_VERSION */
|
---|
| 171 | left -= len;
|
---|
| 172 | ptr += len;
|
---|
| 173 | #endif
|
---|
| 174 | #ifdef USE_LIBSSH2
|
---|
| 175 | len = snprintf(ptr, left, " libssh2/%s", CURL_LIBSSH2_VERSION);
|
---|
| 176 | left -= len;
|
---|
| 177 | ptr += len;
|
---|
| 178 | #endif
|
---|
| 179 | #ifdef USE_NGHTTP2
|
---|
| 180 | len = Curl_http2_ver(ptr, left);
|
---|
| 181 | left -= len;
|
---|
| 182 | ptr += len;
|
---|
| 183 | #endif
|
---|
| 184 | #ifdef USE_LIBRTMP
|
---|
| 185 | {
|
---|
| 186 | char suff[2];
|
---|
| 187 | if(RTMP_LIB_VERSION & 0xff) {
|
---|
| 188 | suff[0] = (RTMP_LIB_VERSION & 0xff) + 'a' - 1;
|
---|
| 189 | suff[1] = '\0';
|
---|
| 190 | }
|
---|
| 191 | else
|
---|
| 192 | suff[0] = '\0';
|
---|
| 193 |
|
---|
| 194 | snprintf(ptr, left, " librtmp/%d.%d%s",
|
---|
| 195 | RTMP_LIB_VERSION >> 16, (RTMP_LIB_VERSION >> 8) & 0xff,
|
---|
| 196 | suff);
|
---|
| 197 | /*
|
---|
| 198 | If another lib version is added below this one, this code would
|
---|
| 199 | also have to do:
|
---|
| 200 |
|
---|
| 201 | len = what snprintf() returned
|
---|
| 202 |
|
---|
| 203 | left -= len;
|
---|
| 204 | ptr += len;
|
---|
| 205 | */
|
---|
| 206 | }
|
---|
| 207 | #endif
|
---|
| 208 |
|
---|
| 209 | initialized = true;
|
---|
| 210 | return version;
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | /* data for curl_version_info
|
---|
| 214 |
|
---|
| 215 | Keep the list sorted alphabetically. It is also written so that each
|
---|
| 216 | protocol line has its own #if line to make things easier on the eye.
|
---|
| 217 | */
|
---|
| 218 |
|
---|
| 219 | static const char * const protocols[] = {
|
---|
| 220 | #ifndef CURL_DISABLE_DICT
|
---|
| 221 | "dict",
|
---|
| 222 | #endif
|
---|
| 223 | #ifndef CURL_DISABLE_FILE
|
---|
| 224 | "file",
|
---|
| 225 | #endif
|
---|
| 226 | #ifndef CURL_DISABLE_FTP
|
---|
| 227 | "ftp",
|
---|
| 228 | #endif
|
---|
| 229 | #if defined(USE_SSL) && !defined(CURL_DISABLE_FTP)
|
---|
| 230 | "ftps",
|
---|
| 231 | #endif
|
---|
| 232 | #ifndef CURL_DISABLE_GOPHER
|
---|
| 233 | "gopher",
|
---|
| 234 | #endif
|
---|
| 235 | #ifndef CURL_DISABLE_HTTP
|
---|
| 236 | "http",
|
---|
| 237 | #endif
|
---|
| 238 | #if defined(USE_SSL) && !defined(CURL_DISABLE_HTTP)
|
---|
| 239 | "https",
|
---|
| 240 | #endif
|
---|
| 241 | #ifndef CURL_DISABLE_IMAP
|
---|
| 242 | "imap",
|
---|
| 243 | #endif
|
---|
| 244 | #if defined(USE_SSL) && !defined(CURL_DISABLE_IMAP)
|
---|
| 245 | "imaps",
|
---|
| 246 | #endif
|
---|
| 247 | #ifndef CURL_DISABLE_LDAP
|
---|
| 248 | "ldap",
|
---|
| 249 | #if !defined(CURL_DISABLE_LDAPS) && \
|
---|
| 250 | ((defined(USE_OPENLDAP) && defined(USE_SSL)) || \
|
---|
| 251 | (!defined(USE_OPENLDAP) && defined(HAVE_LDAP_SSL)))
|
---|
| 252 | "ldaps",
|
---|
| 253 | #endif
|
---|
| 254 | #endif
|
---|
| 255 | #ifndef CURL_DISABLE_POP3
|
---|
| 256 | "pop3",
|
---|
| 257 | #endif
|
---|
| 258 | #if defined(USE_SSL) && !defined(CURL_DISABLE_POP3)
|
---|
| 259 | "pop3s",
|
---|
| 260 | #endif
|
---|
| 261 | #ifdef USE_LIBRTMP
|
---|
| 262 | "rtmp",
|
---|
| 263 | #endif
|
---|
| 264 | #ifndef CURL_DISABLE_RTSP
|
---|
| 265 | "rtsp",
|
---|
| 266 | #endif
|
---|
| 267 | #ifdef USE_LIBSSH2
|
---|
| 268 | "scp",
|
---|
| 269 | #endif
|
---|
| 270 | #ifdef USE_LIBSSH2
|
---|
| 271 | "sftp",
|
---|
| 272 | #endif
|
---|
| 273 | #if !defined(CURL_DISABLE_SMB) && defined(USE_NTLM) && \
|
---|
| 274 | (CURL_SIZEOF_CURL_OFF_T > 4) && \
|
---|
| 275 | (!defined(USE_WINDOWS_SSPI) || defined(USE_WIN32_CRYPTO))
|
---|
| 276 | "smb",
|
---|
| 277 | # ifdef USE_SSL
|
---|
| 278 | "smbs",
|
---|
| 279 | # endif
|
---|
| 280 | #endif
|
---|
| 281 | #ifndef CURL_DISABLE_SMTP
|
---|
| 282 | "smtp",
|
---|
| 283 | #endif
|
---|
| 284 | #if defined(USE_SSL) && !defined(CURL_DISABLE_SMTP)
|
---|
| 285 | "smtps",
|
---|
| 286 | #endif
|
---|
| 287 | #ifndef CURL_DISABLE_TELNET
|
---|
| 288 | "telnet",
|
---|
| 289 | #endif
|
---|
| 290 | #ifndef CURL_DISABLE_TFTP
|
---|
| 291 | "tftp",
|
---|
| 292 | #endif
|
---|
| 293 |
|
---|
| 294 | NULL
|
---|
| 295 | };
|
---|
| 296 |
|
---|
| 297 | static curl_version_info_data version_info = {
|
---|
| 298 | CURLVERSION_NOW,
|
---|
| 299 | LIBCURL_VERSION,
|
---|
| 300 | LIBCURL_VERSION_NUM,
|
---|
| 301 | OS, /* as found by configure or set by hand at build-time */
|
---|
| 302 | 0 /* features is 0 by default */
|
---|
| 303 | #ifdef ENABLE_IPV6
|
---|
| 304 | | CURL_VERSION_IPV6
|
---|
| 305 | #endif
|
---|
| 306 | #ifdef USE_SSL
|
---|
| 307 | | CURL_VERSION_SSL
|
---|
| 308 | #endif
|
---|
| 309 | #ifdef USE_NTLM
|
---|
| 310 | | CURL_VERSION_NTLM
|
---|
| 311 | #endif
|
---|
| 312 | #if !defined(CURL_DISABLE_HTTP) && defined(USE_NTLM) && \
|
---|
| 313 | defined(NTLM_WB_ENABLED)
|
---|
| 314 | | CURL_VERSION_NTLM_WB
|
---|
| 315 | #endif
|
---|
| 316 | #ifdef USE_SPNEGO
|
---|
| 317 | | CURL_VERSION_SPNEGO
|
---|
| 318 | #endif
|
---|
| 319 | #ifdef USE_KERBEROS5
|
---|
| 320 | | CURL_VERSION_KERBEROS5
|
---|
| 321 | #endif
|
---|
| 322 | #ifdef HAVE_GSSAPI
|
---|
| 323 | | CURL_VERSION_GSSAPI
|
---|
| 324 | #endif
|
---|
| 325 | #ifdef USE_WINDOWS_SSPI
|
---|
| 326 | | CURL_VERSION_SSPI
|
---|
| 327 | #endif
|
---|
| 328 | #ifdef HAVE_LIBZ
|
---|
| 329 | | CURL_VERSION_LIBZ
|
---|
| 330 | #endif
|
---|
| 331 | #ifdef DEBUGBUILD
|
---|
| 332 | | CURL_VERSION_DEBUG
|
---|
| 333 | #endif
|
---|
| 334 | #ifdef CURLDEBUG
|
---|
| 335 | | CURL_VERSION_CURLDEBUG
|
---|
| 336 | #endif
|
---|
| 337 | #ifdef CURLRES_ASYNCH
|
---|
| 338 | | CURL_VERSION_ASYNCHDNS
|
---|
| 339 | #endif
|
---|
| 340 | #if (CURL_SIZEOF_CURL_OFF_T > 4) && \
|
---|
| 341 | ( (SIZEOF_OFF_T > 4) || defined(USE_WIN32_LARGE_FILES) )
|
---|
| 342 | | CURL_VERSION_LARGEFILE
|
---|
| 343 | #endif
|
---|
| 344 | #if defined(CURL_DOES_CONVERSIONS)
|
---|
| 345 | | CURL_VERSION_CONV
|
---|
| 346 | #endif
|
---|
| 347 | #if defined(USE_TLS_SRP)
|
---|
| 348 | | CURL_VERSION_TLSAUTH_SRP
|
---|
| 349 | #endif
|
---|
| 350 | #if defined(USE_NGHTTP2)
|
---|
| 351 | | CURL_VERSION_HTTP2
|
---|
| 352 | #endif
|
---|
| 353 | #if defined(USE_UNIX_SOCKETS)
|
---|
| 354 | | CURL_VERSION_UNIX_SOCKETS
|
---|
| 355 | #endif
|
---|
| 356 | #if defined(USE_LIBPSL)
|
---|
| 357 | | CURL_VERSION_PSL
|
---|
| 358 | #endif
|
---|
| 359 | #if defined(CURL_WITH_MULTI_SSL)
|
---|
| 360 | | CURL_VERSION_MULTI_SSL
|
---|
| 361 | #endif
|
---|
| 362 | #if defined(HAVE_BROTLI)
|
---|
| 363 | | CURL_VERSION_BROTLI
|
---|
| 364 | #endif
|
---|
| 365 | ,
|
---|
| 366 | NULL, /* ssl_version */
|
---|
| 367 | 0, /* ssl_version_num, this is kept at zero */
|
---|
| 368 | NULL, /* zlib_version */
|
---|
| 369 | protocols,
|
---|
| 370 | NULL, /* c-ares version */
|
---|
| 371 | 0, /* c-ares version numerical */
|
---|
| 372 | NULL, /* libidn version */
|
---|
| 373 | 0, /* iconv version */
|
---|
| 374 | NULL, /* ssh lib version */
|
---|
| 375 | 0, /* brotli_ver_num */
|
---|
| 376 | NULL, /* brotli version */
|
---|
| 377 | };
|
---|
| 378 |
|
---|
| 379 | curl_version_info_data *curl_version_info(CURLversion stamp)
|
---|
| 380 | {
|
---|
| 381 | static bool initialized;
|
---|
| 382 | #ifdef USE_LIBSSH2
|
---|
| 383 | static char ssh_buffer[80];
|
---|
| 384 | #endif
|
---|
| 385 | #ifdef USE_SSL
|
---|
| 386 | static char ssl_buffer[80];
|
---|
| 387 | #endif
|
---|
| 388 | #ifdef HAVE_BROTLI
|
---|
| 389 | static char brotli_buffer[80];
|
---|
| 390 | #endif
|
---|
| 391 |
|
---|
| 392 | if(initialized)
|
---|
| 393 | return &version_info;
|
---|
| 394 |
|
---|
| 395 | #ifdef USE_SSL
|
---|
| 396 | Curl_ssl_version(ssl_buffer, sizeof(ssl_buffer));
|
---|
| 397 | version_info.ssl_version = ssl_buffer;
|
---|
| 398 | if(Curl_ssl->support_https_proxy)
|
---|
| 399 | version_info.features |= CURL_VERSION_HTTPS_PROXY;
|
---|
| 400 | else
|
---|
| 401 | version_info.features &= ~CURL_VERSION_HTTPS_PROXY;
|
---|
| 402 | #endif
|
---|
| 403 |
|
---|
| 404 | #ifdef HAVE_LIBZ
|
---|
| 405 | version_info.libz_version = zlibVersion();
|
---|
| 406 | /* libz left NULL if non-existing */
|
---|
| 407 | #endif
|
---|
| 408 | #ifdef USE_ARES
|
---|
| 409 | {
|
---|
| 410 | int aresnum;
|
---|
| 411 | version_info.ares = ares_version(&aresnum);
|
---|
| 412 | version_info.ares_num = aresnum;
|
---|
| 413 | }
|
---|
| 414 | #endif
|
---|
| 415 | #ifdef USE_LIBIDN2
|
---|
| 416 | /* This returns a version string if we use the given version or later,
|
---|
| 417 | otherwise it returns NULL */
|
---|
| 418 | version_info.libidn = idn2_check_version(IDN2_VERSION);
|
---|
| 419 | if(version_info.libidn)
|
---|
| 420 | version_info.features |= CURL_VERSION_IDN;
|
---|
| 421 | #elif defined(USE_WIN32_IDN)
|
---|
| 422 | version_info.features |= CURL_VERSION_IDN;
|
---|
| 423 | #endif
|
---|
| 424 |
|
---|
| 425 | #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
|
---|
| 426 | #ifdef _LIBICONV_VERSION
|
---|
| 427 | version_info.iconv_ver_num = _LIBICONV_VERSION;
|
---|
| 428 | #else
|
---|
| 429 | /* version unknown */
|
---|
| 430 | version_info.iconv_ver_num = -1;
|
---|
| 431 | #endif /* _LIBICONV_VERSION */
|
---|
| 432 | #endif
|
---|
| 433 |
|
---|
| 434 | #ifdef USE_LIBSSH2
|
---|
| 435 | snprintf(ssh_buffer, sizeof(ssh_buffer), "libssh2/%s", LIBSSH2_VERSION);
|
---|
| 436 | version_info.libssh_version = ssh_buffer;
|
---|
| 437 | #endif
|
---|
| 438 |
|
---|
| 439 | #ifdef HAVE_BROTLI
|
---|
| 440 | version_info.brotli_ver_num = BrotliDecoderVersion();
|
---|
| 441 | brotli_version(brotli_buffer, sizeof brotli_buffer);
|
---|
| 442 | version_info.brotli_version = brotli_buffer;
|
---|
| 443 | #endif
|
---|
| 444 |
|
---|
| 445 | (void)stamp; /* avoid compiler warnings, we don't use this */
|
---|
| 446 |
|
---|
| 447 | initialized = true;
|
---|
| 448 | return &version_info;
|
---|
| 449 | }
|
---|