1 #ifndef HEADER_CURL_URLDATA_H 2 #define HEADER_CURL_URLDATA_H 3 /*************************************************************************** 4 * _ _ ____ _ 5 * Project ___| | | | _ \| | 6 * / __| | | | |_) | | 7 * | (__| |_| | _ <| |___ 8 * \___|\___/|_| \_\_____| 9 * 10 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 11 * 12 * This software is licensed as described in the file COPYING, which 13 * you should have received as part of this distribution. The terms 14 * are also available at https://curl.se/docs/copyright.html. 15 * 16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 * copies of the Software, and permit persons to whom the Software is 18 * furnished to do so, under the terms of the COPYING file. 19 * 20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 * KIND, either express or implied. 22 * 23 * SPDX-License-Identifier: curl 24 * 25 ***************************************************************************/ 26 27 /* This file is for lib internal stuff */ 28 29 #include "curl_setup.h" 30 31 #define PORT_FTP 21 32 #define PORT_FTPS 990 33 #define PORT_TELNET 23 34 #define PORT_HTTP 80 35 #define PORT_HTTPS 443 36 #define PORT_DICT 2628 37 #define PORT_LDAP 389 38 #define PORT_LDAPS 636 39 #define PORT_TFTP 69 40 #define PORT_SSH 22 41 #define PORT_IMAP 143 42 #define PORT_IMAPS 993 43 #define PORT_POP3 110 44 #define PORT_POP3S 995 45 #define PORT_SMB 445 46 #define PORT_SMBS 445 47 #define PORT_SMTP 25 48 #define PORT_SMTPS 465 /* sometimes called SSMTP */ 49 #define PORT_RTSP 554 50 #define PORT_RTMP 1935 51 #define PORT_RTMPT PORT_HTTP 52 #define PORT_RTMPS PORT_HTTPS 53 #define PORT_GOPHER 70 54 #define PORT_MQTT 1883 55 56 struct curl_trc_featt; 57 58 #ifdef USE_ECH 59 /* CURLECH_ bits for the tls_ech option */ 60 # define CURLECH_DISABLE (1<<0) 61 # define CURLECH_GREASE (1<<1) 62 # define CURLECH_ENABLE (1<<2) 63 # define CURLECH_HARD (1<<3) 64 # define CURLECH_CLA_CFG (1<<4) 65 #endif 66 67 #ifndef CURL_DISABLE_WEBSOCKETS 68 /* CURLPROTO_GOPHERS (29) is the highest publicly used protocol bit number, 69 * the rest are internal information. If we use higher bits we only do this on 70 * platforms that have a >= 64-bit type and then we use such a type for the 71 * protocol fields in the protocol handler. 72 */ 73 #define CURLPROTO_WS (1<<30) 74 #define CURLPROTO_WSS ((curl_prot_t)1<<31) 75 #else 76 #define CURLPROTO_WS 0 77 #define CURLPROTO_WSS 0 78 #endif 79 80 /* the default protocols accepting a redirect to */ 81 #define CURLPROTO_REDIR (CURLPROTO_HTTP | CURLPROTO_HTTPS | CURLPROTO_FTP | \ 82 CURLPROTO_FTPS) 83 84 /* This should be undefined once we need bit 32 or higher */ 85 #define PROTO_TYPE_SMALL 86 87 #ifndef PROTO_TYPE_SMALL 88 typedef curl_off_t curl_prot_t; 89 #else 90 typedef unsigned int curl_prot_t; 91 #endif 92 93 /* This mask is for all the old protocols that are provided and defined in the 94 public header and shall exclude protocols added since which are not exposed 95 in the API */ 96 #define CURLPROTO_MASK (0x3ffffff) 97 98 #define DICT_MATCH "/MATCH:" 99 #define DICT_MATCH2 "/M:" 100 #define DICT_MATCH3 "/FIND:" 101 #define DICT_DEFINE "/DEFINE:" 102 #define DICT_DEFINE2 "/D:" 103 #define DICT_DEFINE3 "/LOOKUP:" 104 105 #define CURL_DEFAULT_USER "anonymous" 106 #define CURL_DEFAULT_PASSWORD "ftp@example.com" 107 108 #if !defined(_WIN32) && !defined(MSDOS) 109 /* do FTP line-end CRLF => LF conversions on platforms that prefer LF-only. It 110 also means: keep CRLF line endings on the CRLF platforms */ 111 #define CURL_PREFER_LF_LINEENDS 112 #endif 113 114 /* Convenience defines for checking protocols or their SSL based version. Each 115 protocol handler should only ever have a single CURLPROTO_ in its protocol 116 field. */ 117 #define PROTO_FAMILY_HTTP (CURLPROTO_HTTP|CURLPROTO_HTTPS|CURLPROTO_WS| \ 118 CURLPROTO_WSS) 119 #define PROTO_FAMILY_FTP (CURLPROTO_FTP|CURLPROTO_FTPS) 120 #define PROTO_FAMILY_POP3 (CURLPROTO_POP3|CURLPROTO_POP3S) 121 #define PROTO_FAMILY_SMB (CURLPROTO_SMB|CURLPROTO_SMBS) 122 #define PROTO_FAMILY_SMTP (CURLPROTO_SMTP|CURLPROTO_SMTPS) 123 #define PROTO_FAMILY_SSH (CURLPROTO_SCP|CURLPROTO_SFTP) 124 125 #if !defined(CURL_DISABLE_FTP) || defined(USE_SSH) || \ 126 !defined(CURL_DISABLE_POP3) || !defined(CURL_DISABLE_FILE) 127 /* these protocols support CURLOPT_DIRLISTONLY */ 128 #define CURL_LIST_ONLY_PROTOCOL 1 129 #endif 130 131 #define DEFAULT_CONNCACHE_SIZE 5 132 133 /* length of longest IPv6 address string including the trailing null */ 134 #define MAX_IPADR_LEN sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255") 135 136 /* Default FTP/IMAP etc response timeout in milliseconds */ 137 #define RESP_TIMEOUT (120*1000) 138 139 /* Max string input length is a precaution against abuse and to detect junk 140 input easier and better. */ 141 #define CURL_MAX_INPUT_LENGTH 8000000 142 143 144 #include "cookie.h" 145 #include "psl.h" 146 #include "formdata.h" 147 148 #ifdef HAVE_NETINET_IN_H 149 #include <netinet/in.h> 150 #endif 151 #ifdef HAVE_NETINET_IN6_H 152 #include <netinet/in6.h> 153 #endif 154 155 #include "timeval.h" 156 157 #include <curl/curl.h> 158 159 #include "http_chunks.h" /* for the structs and enum stuff */ 160 #include "hostip.h" 161 #include "hash.h" 162 #include "splay.h" 163 #include "dynbuf.h" 164 #include "dynhds.h" 165 #include "request.h" 166 #include "netrc.h" 167 168 /* return the count of bytes sent, or -1 on error */ 169 typedef ssize_t (Curl_send)(struct Curl_easy *data, /* transfer */ 170 int sockindex, /* socketindex */ 171 const void *buf, /* data to write */ 172 size_t len, /* max amount to write */ 173 bool eos, /* last chunk */ 174 CURLcode *err); /* error to return */ 175 176 /* return the count of bytes read, or -1 on error */ 177 typedef ssize_t (Curl_recv)(struct Curl_easy *data, /* transfer */ 178 int sockindex, /* socketindex */ 179 char *buf, /* store data here */ 180 size_t len, /* max amount to read */ 181 CURLcode *err); /* error to return */ 182 183 #include "mime.h" 184 #include "imap.h" 185 #include "pop3.h" 186 #include "smtp.h" 187 #include "ftp.h" 188 #include "file.h" 189 #include "vssh/ssh.h" 190 #include "http.h" 191 #include "rtsp.h" 192 #include "smb.h" 193 #include "mqtt.h" 194 #include "ftplistparser.h" 195 #include "multihandle.h" 196 #include "cf-socket.h" 197 198 #ifdef HAVE_GSSAPI 199 # ifdef HAVE_GSSGNU 200 # include <gss.h> 201 # elif defined HAVE_GSSAPI_GSSAPI_H 202 # include <gssapi/gssapi.h> 203 # else 204 # include <gssapi.h> 205 # endif 206 # ifdef HAVE_GSSAPI_GSSAPI_GENERIC_H 207 # include <gssapi/gssapi_generic.h> 208 # endif 209 #endif 210 211 #ifdef USE_LIBSSH2 212 #include <libssh2.h> 213 #include <libssh2_sftp.h> 214 #endif /* USE_LIBSSH2 */ 215 216 #define READBUFFER_SIZE CURL_MAX_WRITE_SIZE 217 #define READBUFFER_MAX CURL_MAX_READ_SIZE 218 #define READBUFFER_MIN 1024 219 220 /* The default upload buffer size, should not be smaller than 221 CURL_MAX_WRITE_SIZE, as it needs to hold a full buffer as could be sent in 222 a write callback. 223 224 The size was 16KB for many years but was bumped to 64KB because it makes 225 libcurl able to do significantly faster uploads in some circumstances. Even 226 larger buffers can help further, but this is deemed a fair memory/speed 227 compromise. */ 228 #define UPLOADBUFFER_DEFAULT 65536 229 #define UPLOADBUFFER_MAX (2*1024*1024) 230 #define UPLOADBUFFER_MIN CURL_MAX_WRITE_SIZE 231 232 #define CURLEASY_MAGIC_NUMBER 0xc0dedbadU 233 #ifdef DEBUGBUILD 234 /* On a debug build, we want to fail hard on easy handles that 235 * are not NULL, but no longer have the MAGIC touch. This gives 236 * us early warning on things only discovered by valgrind otherwise. */ 237 #define GOOD_EASY_HANDLE(x) \ 238 (((x) && ((x)->magic == CURLEASY_MAGIC_NUMBER))? TRUE: \ 239 (DEBUGASSERT(!(x)), FALSE)) 240 #else 241 #define GOOD_EASY_HANDLE(x) \ 242 ((x) && ((x)->magic == CURLEASY_MAGIC_NUMBER)) 243 #endif 244 245 #ifdef HAVE_GSSAPI 246 /* Types needed for krb5-ftp connections */ 247 struct krb5buffer { 248 struct dynbuf buf; 249 size_t index; 250 BIT(eof_flag); 251 }; 252 253 enum protection_level { 254 PROT_NONE, /* first in list */ 255 PROT_CLEAR, 256 PROT_SAFE, 257 PROT_CONFIDENTIAL, 258 PROT_PRIVATE, 259 PROT_CMD, 260 PROT_LAST /* last in list */ 261 }; 262 #endif 263 264 /* SSL backend-specific data; declared differently by each SSL backend */ 265 struct ssl_backend_data; 266 struct Curl_ssl_scache_entry; 267 268 struct ssl_primary_config { 269 char *CApath; /* certificate dir (does not work on Windows) */ 270 char *CAfile; /* certificate to verify peer against */ 271 char *issuercert; /* optional issuer certificate filename */ 272 char *clientcert; 273 char *cipher_list; /* list of ciphers to use */ 274 char *cipher_list13; /* list of TLS 1.3 cipher suites to use */ 275 char *pinned_key; 276 char *CRLfile; /* CRL to check certificate revocation */ 277 struct curl_blob *cert_blob; 278 struct curl_blob *ca_info_blob; 279 struct curl_blob *issuercert_blob; 280 #ifdef USE_TLS_SRP 281 char *username; /* TLS username (for, e.g., SRP) */ 282 char *password; /* TLS password (for, e.g., SRP) */ 283 #endif 284 char *curves; /* list of curves to use */ 285 unsigned char ssl_options; /* the CURLOPT_SSL_OPTIONS bitmask */ 286 unsigned int version_max; /* max supported version the client wants to use */ 287 unsigned char version; /* what version the client wants to use */ 288 BIT(verifypeer); /* set TRUE if this is desired */ 289 BIT(verifyhost); /* set TRUE if CN/SAN must match hostname */ 290 BIT(verifystatus); /* set TRUE if certificate status must be checked */ 291 BIT(cache_session); /* cache session or not */ 292 }; 293 294 struct ssl_config_data { 295 struct ssl_primary_config primary; 296 long certverifyresult; /* result from the certificate verification */ 297 curl_ssl_ctx_callback fsslctx; /* function to initialize ssl ctx */ 298 void *fsslctxp; /* parameter for call back */ 299 char *cert_type; /* format for certificate (default: PEM)*/ 300 char *key; /* private key filename */ 301 struct curl_blob *key_blob; 302 char *key_type; /* format for private key (default: PEM) */ 303 char *key_passwd; /* plain text private key password */ 304 BIT(certinfo); /* gather lots of certificate info */ 305 BIT(falsestart); 306 BIT(earlydata); /* use tls1.3 early data */ 307 BIT(enable_beast); /* allow this flaw for interoperability's sake */ 308 BIT(no_revoke); /* disable SSL certificate revocation checks */ 309 BIT(no_partialchain); /* do not accept partial certificate chains */ 310 BIT(revoke_best_effort); /* ignore SSL revocation offline/missing revocation 311 list errors */ 312 BIT(native_ca_store); /* use the native ca store of operating system */ 313 BIT(auto_client_cert); /* automatically locate and use a client 314 certificate for authentication (Schannel) */ 315 }; 316 317 struct ssl_general_config { 318 int ca_cache_timeout; /* Certificate store cache timeout (seconds) */ 319 }; 320 321 #ifdef USE_WINDOWS_SSPI 322 #include "curl_sspi.h" 323 #endif 324 325 #ifndef CURL_DISABLE_DIGEST_AUTH 326 /* Struct used for Digest challenge-response authentication */ 327 struct digestdata { 328 #if defined(USE_WINDOWS_SSPI) 329 BYTE *input_token; 330 size_t input_token_len; 331 CtxtHandle *http_context; 332 /* copy of user/passwd used to make the identity for http_context. 333 either may be NULL. */ 334 char *user; 335 char *passwd; 336 #else 337 char *nonce; 338 char *cnonce; 339 char *realm; 340 char *opaque; 341 char *qop; 342 char *algorithm; 343 int nc; /* nonce count */ 344 unsigned char algo; 345 BIT(stale); /* set true for re-negotiation */ 346 BIT(userhash); 347 #endif 348 }; 349 #endif 350 351 typedef enum { 352 NTLMSTATE_NONE, 353 NTLMSTATE_TYPE1, 354 NTLMSTATE_TYPE2, 355 NTLMSTATE_TYPE3, 356 NTLMSTATE_LAST 357 } curlntlm; 358 359 typedef enum { 360 GSS_AUTHNONE, 361 GSS_AUTHRECV, 362 GSS_AUTHSENT, 363 GSS_AUTHDONE, 364 GSS_AUTHSUCC 365 } curlnegotiate; 366 367 /* Struct used for GSSAPI (Kerberos V5) authentication */ 368 #if defined(USE_KERBEROS5) 369 struct kerberos5data { 370 #if defined(USE_WINDOWS_SSPI) 371 CredHandle *credentials; 372 CtxtHandle *context; 373 TCHAR *spn; 374 SEC_WINNT_AUTH_IDENTITY identity; 375 SEC_WINNT_AUTH_IDENTITY *p_identity; 376 size_t token_max; 377 BYTE *output_token; 378 #else 379 gss_ctx_id_t context; 380 gss_name_t spn; 381 #endif 382 }; 383 #endif 384 385 /* Struct used for SCRAM-SHA-1 authentication */ 386 #ifdef USE_GSASL 387 #include <gsasl.h> 388 struct gsasldata { 389 Gsasl *ctx; 390 Gsasl_session *client; 391 }; 392 #endif 393 394 /* Struct used for NTLM challenge-response authentication */ 395 #if defined(USE_NTLM) 396 struct ntlmdata { 397 #ifdef USE_WINDOWS_SSPI 398 /* The sslContext is used for the Schannel bindings. The 399 * api is available on the Windows 7 SDK and later. 400 */ 401 #ifdef SECPKG_ATTR_ENDPOINT_BINDINGS 402 CtxtHandle *sslContext; 403 #endif 404 CredHandle *credentials; 405 CtxtHandle *context; 406 SEC_WINNT_AUTH_IDENTITY identity; 407 SEC_WINNT_AUTH_IDENTITY *p_identity; 408 size_t token_max; 409 BYTE *output_token; 410 BYTE *input_token; 411 size_t input_token_len; 412 TCHAR *spn; 413 #else 414 unsigned int flags; 415 unsigned char nonce[8]; 416 unsigned int target_info_len; 417 void *target_info; /* TargetInfo received in the NTLM type-2 message */ 418 #endif 419 }; 420 #endif 421 422 /* Struct used for Negotiate (SPNEGO) authentication */ 423 #ifdef USE_SPNEGO 424 struct negotiatedata { 425 #ifdef HAVE_GSSAPI 426 OM_uint32 status; 427 gss_ctx_id_t context; 428 gss_name_t spn; 429 gss_buffer_desc output_token; 430 struct dynbuf channel_binding_data; 431 #else 432 #ifdef USE_WINDOWS_SSPI 433 #ifdef SECPKG_ATTR_ENDPOINT_BINDINGS 434 CtxtHandle *sslContext; 435 #endif 436 DWORD status; 437 CredHandle *credentials; 438 CtxtHandle *context; 439 SEC_WINNT_AUTH_IDENTITY identity; 440 SEC_WINNT_AUTH_IDENTITY *p_identity; 441 TCHAR *spn; 442 size_t token_max; 443 BYTE *output_token; 444 size_t output_token_length; 445 #endif 446 #endif 447 BIT(noauthpersist); 448 BIT(havenoauthpersist); 449 BIT(havenegdata); 450 BIT(havemultiplerequests); 451 }; 452 #endif 453 454 #ifdef CURL_DISABLE_PROXY 455 #define CONN_IS_PROXIED(x) 0 456 #else 457 #define CONN_IS_PROXIED(x) x->bits.proxy 458 #endif 459 460 /* 461 * Boolean values that concerns this connection. 462 */ 463 struct ConnectBits { 464 #ifndef CURL_DISABLE_PROXY 465 BIT(httpproxy); /* if set, this transfer is done through an HTTP proxy */ 466 BIT(socksproxy); /* if set, this transfer is done through a socks proxy */ 467 BIT(proxy_user_passwd); /* user+password for the proxy? */ 468 BIT(tunnel_proxy); /* if CONNECT is used to "tunnel" through the proxy. 469 This is implicit when SSL-protocols are used through 470 proxies, but can also be enabled explicitly by 471 apps */ 472 BIT(proxy); /* if set, this transfer is done through a proxy - any type */ 473 #endif 474 /* always modify bits.close with the connclose() and connkeep() macros! */ 475 BIT(close); /* if set, we close the connection after this request */ 476 BIT(reuse); /* if set, this is a reused connection */ 477 BIT(altused); /* this is an alt-svc "redirect" */ 478 BIT(conn_to_host); /* if set, this connection has a "connect to host" 479 that overrides the host in the URL */ 480 BIT(conn_to_port); /* if set, this connection has a "connect to port" 481 that overrides the port in the URL (remote port) */ 482 BIT(ipv6_ip); /* we communicate with a remote site specified with pure IPv6 483 IP address */ 484 BIT(ipv6); /* we communicate with a site using an IPv6 address */ 485 BIT(do_more); /* this is set TRUE if the ->curl_do_more() function is 486 supposed to be called, after ->curl_do() */ 487 BIT(protoconnstart);/* the protocol layer has STARTED its operation after 488 the TCP layer connect */ 489 BIT(retry); /* this connection is about to get closed and then 490 re-attempted at another connection. */ 491 #ifndef CURL_DISABLE_FTP 492 BIT(ftp_use_epsv); /* As set with CURLOPT_FTP_USE_EPSV, but if we find out 493 EPSV does not work we disable it for the forthcoming 494 requests */ 495 BIT(ftp_use_eprt); /* As set with CURLOPT_FTP_USE_EPRT, but if we find out 496 EPRT does not work we disable it for the forthcoming 497 requests */ 498 BIT(ftp_use_data_ssl); /* Enabled SSL for the data connection */ 499 BIT(ftp_use_control_ssl); /* Enabled SSL for the control connection */ 500 #endif 501 #ifndef CURL_DISABLE_NETRC 502 BIT(netrc); /* name+password provided by netrc */ 503 #endif 504 BIT(bound); /* set true if bind() has already been done on this socket/ 505 connection */ 506 BIT(asks_multiplex); /* connection asks for multiplexing, but is not yet */ 507 BIT(multiplex); /* connection is multiplexed */ 508 BIT(tcp_fastopen); /* use TCP Fast Open */ 509 BIT(tls_enable_alpn); /* TLS ALPN extension? */ 510 #ifndef CURL_DISABLE_DOH 511 BIT(doh); 512 #endif 513 #ifdef USE_UNIX_SOCKETS 514 BIT(abstract_unix_socket); 515 #endif 516 BIT(tls_upgraded); 517 BIT(sock_accepted); /* TRUE if the SECONDARYSOCKET was created with 518 accept() */ 519 BIT(parallel_connect); /* set TRUE when a parallel connect attempt has 520 started (happy eyeballs) */ 521 BIT(aborted); /* connection was aborted, e.g. in unclean state */ 522 BIT(shutdown_handler); /* connection shutdown: handler shut down */ 523 BIT(shutdown_filters); /* connection shutdown: filters shut down */ 524 BIT(in_cpool); /* connection is kept in a connection pool */ 525 }; 526 527 struct hostname { 528 char *rawalloc; /* allocated "raw" version of the name */ 529 char *encalloc; /* allocated IDN-encoded version of the name */ 530 char *name; /* name to use internally, might be encoded, might be raw */ 531 const char *dispname; /* name to display, as 'name' might be encoded */ 532 }; 533 534 /* 535 * Flags on the keepon member of the Curl_transfer_keeper 536 */ 537 538 #define KEEP_NONE 0 539 #define KEEP_RECV (1<<0) /* there is or may be data to read */ 540 #define KEEP_SEND (1<<1) /* there is or may be data to write */ 541 #define KEEP_RECV_HOLD (1<<2) /* when set, no reading should be done but there 542 might still be data to read */ 543 #define KEEP_SEND_HOLD (1<<3) /* when set, no writing should be done but there 544 might still be data to write */ 545 #define KEEP_RECV_PAUSE (1<<4) /* reading is paused */ 546 #define KEEP_SEND_PAUSE (1<<5) /* writing is paused */ 547 548 /* KEEP_SEND_TIMED is set when the transfer should attempt sending 549 * at timer (or other) events. A transfer waiting on a timer will 550 * remove KEEP_SEND to suppress POLLOUTs of the connection. 551 * Adding KEEP_SEND_TIMED will then attempt to send whenever the transfer 552 * enters the "readwrite" loop, e.g. when a timer fires. 553 * This is used in HTTP for 'Expect: 100-continue' waiting. */ 554 #define KEEP_SEND_TIMED (1<<6) 555 556 #define KEEP_RECVBITS (KEEP_RECV | KEEP_RECV_HOLD | KEEP_RECV_PAUSE) 557 #define KEEP_SENDBITS (KEEP_SEND | KEEP_SEND_HOLD | KEEP_SEND_PAUSE) 558 559 /* transfer wants to send is not PAUSE or HOLD */ 560 #define CURL_WANT_SEND(data) \ 561 (((data)->req.keepon & KEEP_SENDBITS) == KEEP_SEND) 562 /* transfer receive is not on PAUSE or HOLD */ 563 #define CURL_WANT_RECV(data) \ 564 (((data)->req.keepon & KEEP_RECVBITS) == KEEP_RECV) 565 566 #if defined(CURLRES_ASYNCH) || !defined(CURL_DISABLE_DOH) 567 #define USE_CURL_ASYNC 568 struct Curl_async { 569 char *hostname; 570 struct Curl_dns_entry *dns; 571 struct thread_data *tdata; 572 void *resolver; /* resolver state, if it is used in the URL state - 573 ares_channel e.g. */ 574 int port; 575 int status; /* if done is TRUE, this is the status from the callback */ 576 BIT(done); /* set TRUE when the lookup is complete */ 577 }; 578 579 #endif 580 581 #define FIRSTSOCKET 0 582 #define SECONDARYSOCKET 1 583 584 /* Polling requested by an easy handle. 585 * `action` is CURL_POLL_IN, CURL_POLL_OUT or CURL_POLL_INOUT. 586 */ 587 struct easy_pollset { 588 curl_socket_t sockets[MAX_SOCKSPEREASYHANDLE]; 589 unsigned int num; 590 unsigned char actions[MAX_SOCKSPEREASYHANDLE]; 591 }; 592 593 /* 594 * Specific protocol handler. 595 */ 596 597 struct Curl_handler { 598 const char *scheme; /* URL scheme name in lowercase */ 599 600 /* Complement to setup_connection_internals(). This is done before the 601 transfer "owns" the connection. */ 602 CURLcode (*setup_connection)(struct Curl_easy *data, 603 struct connectdata *conn); 604 605 /* These two functions MUST be set to be protocol dependent */ 606 CURLcode (*do_it)(struct Curl_easy *data, bool *done); 607 CURLcode (*done)(struct Curl_easy *, CURLcode, bool); 608 609 /* If the curl_do() function is better made in two halves, this 610 * curl_do_more() function will be called afterwards, if set. For example 611 * for doing the FTP stuff after the PASV/PORT command. 612 */ 613 CURLcode (*do_more)(struct Curl_easy *, int *); 614 615 /* This function *MAY* be set to a protocol-dependent function that is run 616 * after the connect() and everything is done, as a step in the connection. 617 * The 'done' pointer points to a bool that should be set to TRUE if the 618 * function completes before return. If it does not complete, the caller 619 * should call the ->connecting() function until it is. 620 */ 621 CURLcode (*connect_it)(struct Curl_easy *data, bool *done); 622 623 /* See above. */ 624 CURLcode (*connecting)(struct Curl_easy *data, bool *done); 625 CURLcode (*doing)(struct Curl_easy *data, bool *done); 626 627 /* Called from the multi interface during the PROTOCONNECT phase, and it 628 should then return a proper fd set */ 629 int (*proto_getsock)(struct Curl_easy *data, 630 struct connectdata *conn, curl_socket_t *socks); 631 632 /* Called from the multi interface during the DOING phase, and it should 633 then return a proper fd set */ 634 int (*doing_getsock)(struct Curl_easy *data, 635 struct connectdata *conn, curl_socket_t *socks); 636 637 /* Called from the multi interface during the DO_MORE phase, and it should 638 then return a proper fd set */ 639 int (*domore_getsock)(struct Curl_easy *data, 640 struct connectdata *conn, curl_socket_t *socks); 641 642 /* Called from the multi interface during the DO_DONE, PERFORM and 643 WAITPERFORM phases, and it should then return a proper fd set. Not setting 644 this will make libcurl use the generic default one. */ 645 int (*perform_getsock)(struct Curl_easy *data, 646 struct connectdata *conn, curl_socket_t *socks); 647 648 /* This function *MAY* be set to a protocol-dependent function that is run 649 * by the curl_disconnect(), as a step in the disconnection. If the handler 650 * is called because the connection has been considered dead, 651 * dead_connection is set to TRUE. The connection is (again) associated with 652 * the transfer here. 653 */ 654 CURLcode (*disconnect)(struct Curl_easy *, struct connectdata *, 655 bool dead_connection); 656 657 /* If used, this function gets called from transfer.c to 658 allow the protocol to do extra handling in writing response to 659 the client. */ 660 CURLcode (*write_resp)(struct Curl_easy *data, const char *buf, size_t blen, 661 bool is_eos); 662 663 /* If used, this function gets called from transfer.c to 664 allow the protocol to do extra handling in writing a single response 665 header line to the client. */ 666 CURLcode (*write_resp_hd)(struct Curl_easy *data, 667 const char *hd, size_t hdlen, bool is_eos); 668 669 /* This function can perform various checks on the connection. See 670 CONNCHECK_* for more information about the checks that can be performed, 671 and CONNRESULT_* for the results that can be returned. */ 672 unsigned int (*connection_check)(struct Curl_easy *data, 673 struct connectdata *conn, 674 unsigned int checks_to_perform); 675 676 /* attach() attaches this transfer to this connection */ 677 void (*attach)(struct Curl_easy *data, struct connectdata *conn); 678 679 /* return CURLE_OK if a redirect to `newurl` should be followed, 680 CURLE_TOO_MANY_REDIRECTS otherwise. May alter `data` to change 681 the way the follow request is performed. */ 682 CURLcode (*follow)(struct Curl_easy *data, const char *newurl, 683 followtype type); 684 685 int defport; /* Default port. */ 686 curl_prot_t protocol; /* See CURLPROTO_* - this needs to be the single 687 specific protocol bit */ 688 curl_prot_t family; /* single bit for protocol family; basically the 689 non-TLS name of the protocol this is */ 690 unsigned int flags; /* Extra particular characteristics, see PROTOPT_* */ 691 692 }; 693 694 #define PROTOPT_NONE 0 /* nothing extra */ 695 #define PROTOPT_SSL (1<<0) /* uses SSL */ 696 #define PROTOPT_DUAL (1<<1) /* this protocol uses two connections */ 697 #define PROTOPT_CLOSEACTION (1<<2) /* need action before socket close */ 698 /* some protocols will have to call the underlying functions without regard to 699 what exact state the socket signals. IE even if the socket says "readable", 700 the send function might need to be called while uploading, or vice versa. 701 */ 702 #define PROTOPT_DIRLOCK (1<<3) 703 #define PROTOPT_NONETWORK (1<<4) /* protocol does not use the network! */ 704 #define PROTOPT_NEEDSPWD (1<<5) /* needs a password, and if none is set it 705 gets a default */ 706 #define PROTOPT_NOURLQUERY (1<<6) /* protocol cannot handle 707 URL query strings (?foo=bar) ! */ 708 #define PROTOPT_CREDSPERREQUEST (1<<7) /* requires login credentials per 709 request instead of per connection */ 710 #define PROTOPT_ALPN (1<<8) /* set ALPN for this */ 711 /* (1<<9) was PROTOPT_STREAM, now free */ 712 #define PROTOPT_URLOPTIONS (1<<10) /* allow options part in the userinfo field 713 of the URL */ 714 #define PROTOPT_PROXY_AS_HTTP (1<<11) /* allow this non-HTTP scheme over a 715 HTTP proxy as HTTP proxies may know 716 this protocol and act as a gateway */ 717 #define PROTOPT_WILDCARD (1<<12) /* protocol supports wildcard matching */ 718 #define PROTOPT_USERPWDCTRL (1<<13) /* Allow "control bytes" (< 32 ASCII) in 719 username and password */ 720 #define PROTOPT_NOTCPPROXY (1<<14) /* this protocol cannot proxy over TCP */ 721 722 #define CONNCHECK_NONE 0 /* No checks */ 723 #define CONNCHECK_ISDEAD (1<<0) /* Check if the connection is dead. */ 724 #define CONNCHECK_KEEPALIVE (1<<1) /* Perform any keepalive function. */ 725 726 #define CONNRESULT_NONE 0 /* No extra information. */ 727 #define CONNRESULT_DEAD (1<<0) /* The connection is dead. */ 728 729 struct ip_quadruple { 730 char remote_ip[MAX_IPADR_LEN]; 731 char local_ip[MAX_IPADR_LEN]; 732 int remote_port; 733 int local_port; 734 }; 735 736 struct proxy_info { 737 struct hostname host; 738 int port; 739 unsigned char proxytype; /* curl_proxytype: what kind of proxy that is in 740 use */ 741 char *user; /* proxy username string, allocated */ 742 char *passwd; /* proxy password string, allocated */ 743 }; 744 745 struct ldapconninfo; 746 747 #define TRNSPRT_TCP 3 748 #define TRNSPRT_UDP 4 749 #define TRNSPRT_QUIC 5 750 #define TRNSPRT_UNIX 6 751 752 /* 753 * The connectdata struct contains all fields and variables that should be 754 * unique for an entire connection. 755 */ 756 struct connectdata { 757 struct Curl_llist_node cpool_node; /* conncache lists */ 758 759 curl_closesocket_callback fclosesocket; /* function closing the socket(s) */ 760 void *closesocket_client; 761 762 /* This is used by the connection pool logic. If this returns TRUE, this 763 handle is still used by one or more easy handles and can only used by any 764 other easy handle without careful consideration (== only for 765 multiplexing) and it cannot be used by another multi handle! */ 766 #define CONN_INUSE(c) Curl_llist_count(&(c)->easyq) 767 768 /**** Fields set when inited and not modified again */ 769 curl_off_t connection_id; /* Contains a unique number to make it easier to 770 track the connections in the log output */ 771 char *destination; /* string carrying normalized hostname+port+scope */ 772 size_t destination_len; /* strlen(destination) + 1 */ 773 774 /* 'dns_entry' is the particular host we use. This points to an entry in the 775 DNS cache and it will not get pruned while locked. It gets unlocked in 776 multi_done(). This entry will be NULL if the connection is reused as then 777 there is no name resolve done. */ 778 struct Curl_dns_entry *dns_entry; 779 780 /* 'remote_addr' is the particular IP we connected to. it is owned, set 781 * and NULLed by the connected socket filter (if there is one). */ 782 const struct Curl_sockaddr_ex *remote_addr; 783 784 struct hostname host; 785 char *hostname_resolve; /* hostname to resolve to address, allocated */ 786 char *secondaryhostname; /* secondary socket hostname (ftp) */ 787 struct hostname conn_to_host; /* the host to connect to. valid only if 788 bits.conn_to_host is set */ 789 #ifndef CURL_DISABLE_PROXY 790 struct proxy_info socks_proxy; 791 struct proxy_info http_proxy; 792 #endif 793 /* 'primary' and 'secondary' get filled with IP quadruple 794 (local/remote numerical ip address and port) whenever a connect is 795 *attempted*. 796 When more than one address is tried for a connection these will hold data 797 for the last attempt. When the connection is actually established 798 these are updated with data which comes directly from the socket. */ 799 struct ip_quadruple primary; 800 struct ip_quadruple secondary; 801 char *user; /* username string, allocated */ 802 char *passwd; /* password string, allocated */ 803 char *options; /* options string, allocated */ 804 char *sasl_authzid; /* authorization identity string, allocated */ 805 char *oauth_bearer; /* OAUTH2 bearer, allocated */ 806 struct curltime now; /* "current" time */ 807 struct curltime created; /* creation time */ 808 struct curltime lastused; /* when returned to the connection poolas idle */ 809 curl_socket_t sock[2]; /* two sockets, the second is used for the data 810 transfer when doing FTP */ 811 Curl_recv *recv[2]; 812 Curl_send *send[2]; 813 struct Curl_cfilter *cfilter[2]; /* connection filters */ 814 struct { 815 struct curltime start[2]; /* when filter shutdown started */ 816 unsigned int timeout_ms; /* 0 means no timeout */ 817 } shutdown; 818 /* Last pollset used in connection shutdown. Used to detect changes 819 * for multi_socket API. */ 820 struct easy_pollset shutdown_poll; 821 822 struct ssl_primary_config ssl_config; 823 #ifndef CURL_DISABLE_PROXY 824 struct ssl_primary_config proxy_ssl_config; 825 #endif 826 struct ConnectBits bits; /* various state-flags for this connection */ 827 828 const struct Curl_handler *handler; /* Connection's protocol handler */ 829 const struct Curl_handler *given; /* The protocol first given */ 830 831 /* Protocols can use a custom keepalive mechanism to keep connections alive. 832 This allows those protocols to track the last time the keepalive mechanism 833 was used on this connection. */ 834 struct curltime keepalive; 835 836 /**** curl_get() phase fields */ 837 838 curl_socket_t sockfd; /* socket to read from or CURL_SOCKET_BAD */ 839 curl_socket_t writesockfd; /* socket to write to, it may be the same we read 840 from. CURL_SOCKET_BAD disables */ 841 842 #ifdef HAVE_GSSAPI 843 BIT(sec_complete); /* if Kerberos is enabled for this connection */ 844 unsigned char command_prot; /* enum protection_level */ 845 unsigned char data_prot; /* enum protection_level */ 846 unsigned char request_data_prot; /* enum protection_level */ 847 size_t buffer_size; 848 struct krb5buffer in_buffer; 849 void *app_data; 850 const struct Curl_sec_client_mech *mech; 851 struct sockaddr_in local_addr; 852 #endif 853 854 #if defined(USE_KERBEROS5) /* Consider moving some of the above GSS-API */ 855 struct kerberos5data krb5; /* variables into the structure definition, */ 856 #endif /* however, some of them are ftp specific. */ 857 858 struct Curl_llist easyq; /* List of easy handles using this connection */ 859 860 /*************** Request - specific items ************/ 861 #if defined(USE_WINDOWS_SSPI) && defined(SECPKG_ATTR_ENDPOINT_BINDINGS) 862 CtxtHandle *sslContext; 863 #endif 864 865 #ifdef USE_GSASL 866 struct gsasldata gsasl; 867 #endif 868 869 #if defined(USE_NTLM) 870 curlntlm http_ntlm_state; 871 curlntlm proxy_ntlm_state; 872 873 struct ntlmdata ntlm; /* NTLM differs from other authentication schemes 874 because it authenticates connections, not 875 single requests! */ 876 struct ntlmdata proxyntlm; /* NTLM data for proxy */ 877 #endif 878 879 #ifdef USE_SPNEGO 880 curlnegotiate http_negotiate_state; 881 curlnegotiate proxy_negotiate_state; 882 883 struct negotiatedata negotiate; /* state data for host Negotiate auth */ 884 struct negotiatedata proxyneg; /* state data for proxy Negotiate auth */ 885 #endif 886 887 union { 888 #ifndef CURL_DISABLE_FTP 889 struct ftp_conn ftpc; 890 #endif 891 #ifdef USE_SSH 892 struct ssh_conn sshc; 893 #endif 894 #ifndef CURL_DISABLE_TFTP 895 struct tftp_state_data *tftpc; 896 #endif 897 #ifndef CURL_DISABLE_IMAP 898 struct imap_conn imapc; 899 #endif 900 #ifndef CURL_DISABLE_POP3 901 struct pop3_conn pop3c; 902 #endif 903 #ifndef CURL_DISABLE_SMTP 904 struct smtp_conn smtpc; 905 #endif 906 #ifndef CURL_DISABLE_RTSP 907 struct rtsp_conn rtspc; 908 #endif 909 #ifndef CURL_DISABLE_SMB 910 struct smb_conn smbc; 911 #endif 912 #ifdef USE_LIBRTMP 913 void *rtmp; 914 #endif 915 #ifdef USE_OPENLDAP 916 struct ldapconninfo *ldapc; 917 #endif 918 #ifndef CURL_DISABLE_MQTT 919 struct mqtt_conn mqtt; 920 #endif 921 #ifndef CURL_DISABLE_WEBSOCKETS 922 struct websocket *ws; 923 #endif 924 unsigned int unused:1; /* avoids empty union */ 925 } proto; 926 927 #ifdef USE_UNIX_SOCKETS 928 char *unix_domain_socket; 929 #endif 930 931 /* When this connection is created, store the conditions for the local end 932 bind. This is stored before the actual bind and before any connection is 933 made and will serve the purpose of being used for comparison reasons so 934 that subsequent bound-requested connections are not accidentally reusing 935 wrong connections. */ 936 char *localdev; 937 unsigned short localportrange; 938 int waitfor; /* current READ/WRITE bits to wait for */ 939 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI) 940 int socks5_gssapi_enctype; 941 #endif 942 /* The field below gets set in connect.c:connecthost() */ 943 int remote_port; /* the remote port, not the proxy port! */ 944 int conn_to_port; /* the remote port to connect to. valid only if 945 bits.conn_to_port is set */ 946 #ifdef USE_IPV6 947 unsigned int scope_id; /* Scope id for IPv6 */ 948 #endif 949 unsigned short localport; 950 unsigned short secondary_port; /* secondary socket remote port to connect to 951 (ftp) */ 952 unsigned char alpn; /* APLN TLS negotiated protocol, a CURL_HTTP_VERSION* 953 value */ 954 #ifndef CURL_DISABLE_PROXY 955 unsigned char proxy_alpn; /* APLN of proxy tunnel, CURL_HTTP_VERSION* */ 956 #endif 957 unsigned char transport; /* one of the TRNSPRT_* defines */ 958 unsigned char ip_version; /* copied from the Curl_easy at creation time */ 959 /* HTTP version last responded with by the server. 960 * 0 at start, then one of 09, 10, 11, etc. */ 961 unsigned char httpversion_seen; 962 unsigned char connect_only; 963 unsigned char gssapi_delegation; /* inherited from set.gssapi_delegation */ 964 }; 965 966 #ifndef CURL_DISABLE_PROXY 967 #define CURL_CONN_HOST_DISPNAME(c) \ 968 ((c)->bits.socksproxy ? (c)->socks_proxy.host.dispname : \ 969 (c)->bits.httpproxy ? (c)->http_proxy.host.dispname : \ 970 (c)->bits.conn_to_host ? (c)->conn_to_host.dispname : \ 971 (c)->host.dispname) 972 #else 973 #define CURL_CONN_HOST_DISPNAME(c) \ 974 (c)->bits.conn_to_host ? (c)->conn_to_host.dispname : \ 975 (c)->host.dispname 976 #endif 977 978 /* The end of connectdata. */ 979 980 /* 981 * Struct to keep statistical and informational data. 982 * All variables in this struct must be initialized/reset in Curl_initinfo(). 983 */ 984 struct PureInfo { 985 int httpcode; /* Recent HTTP, FTP, RTSP or SMTP response code */ 986 int httpproxycode; /* response code from proxy when received separate */ 987 int httpversion; /* the http version number X.Y = X*10+Y */ 988 time_t filetime; /* If requested, this is might get set. Set to -1 if the 989 time was unretrievable. */ 990 curl_off_t request_size; /* the amount of bytes sent in the request(s) */ 991 unsigned long proxyauthavail; /* what proxy auth types were announced */ 992 unsigned long httpauthavail; /* what host auth types were announced */ 993 unsigned long proxyauthpicked; /* selected proxy auth type */ 994 unsigned long httpauthpicked; /* selected host auth type */ 995 long numconnects; /* how many new connection did libcurl created */ 996 char *contenttype; /* the content type of the object */ 997 char *wouldredirect; /* URL this would have been redirected to if asked to */ 998 curl_off_t retry_after; /* info from Retry-After: header */ 999 unsigned int header_size; /* size of read header(s) in bytes */ 1000 1001 /* PureInfo primary ip_quadruple is copied over from the connectdata 1002 struct in order to allow curl_easy_getinfo() to return this information 1003 even when the session handle is no longer associated with a connection, 1004 and also allow curl_easy_reset() to clear this information from the 1005 session handle without disturbing information which is still alive, and 1006 that might be reused, in the connection pool. */ 1007 struct ip_quadruple primary; 1008 int conn_remote_port; /* this is the "remote port", which is the port 1009 number of the used URL, independent of proxy or 1010 not */ 1011 const char *conn_scheme; 1012 unsigned int conn_protocol; 1013 struct curl_certinfo certs; /* info about the certs. Asked for with 1014 CURLOPT_CERTINFO / CURLINFO_CERTINFO */ 1015 CURLproxycode pxcode; 1016 BIT(timecond); /* set to TRUE if the time condition did not match, which 1017 thus made the document NOT get fetched */ 1018 BIT(used_proxy); /* the transfer used a proxy */ 1019 }; 1020 1021 struct pgrs_measure { 1022 struct curltime start; /* when measure started */ 1023 curl_off_t start_size; /* the 'cur_size' the measure started at */ 1024 }; 1025 1026 struct pgrs_dir { 1027 curl_off_t total_size; /* total expected bytes */ 1028 curl_off_t cur_size; /* transferred bytes so far */ 1029 curl_off_t speed; /* bytes per second transferred */ 1030 struct pgrs_measure limit; 1031 }; 1032 1033 struct Progress { 1034 time_t lastshow; /* time() of the last displayed progress meter or NULL to 1035 force redraw at next call */ 1036 struct pgrs_dir ul; 1037 struct pgrs_dir dl; 1038 1039 curl_off_t current_speed; /* uses the currently fastest transfer */ 1040 curl_off_t earlydata_sent; 1041 1042 int width; /* screen width at download start */ 1043 int flags; /* see progress.h */ 1044 1045 timediff_t timespent; 1046 1047 timediff_t t_postqueue; 1048 timediff_t t_nslookup; 1049 timediff_t t_connect; 1050 timediff_t t_appconnect; 1051 timediff_t t_pretransfer; 1052 timediff_t t_posttransfer; 1053 timediff_t t_starttransfer; 1054 timediff_t t_redirect; 1055 1056 struct curltime start; 1057 struct curltime t_startsingle; 1058 struct curltime t_startop; 1059 struct curltime t_startqueue; 1060 struct curltime t_acceptdata; 1061 1062 #define CURR_TIME (5 + 1) /* 6 entries for 5 seconds */ 1063 1064 curl_off_t speeder[ CURR_TIME ]; 1065 struct curltime speeder_time[ CURR_TIME ]; 1066 int speeder_c; 1067 BIT(callback); /* set when progress callback is used */ 1068 BIT(is_t_startransfer_set); 1069 }; 1070 1071 typedef enum { 1072 RTSPREQ_NONE, /* first in list */ 1073 RTSPREQ_OPTIONS, 1074 RTSPREQ_DESCRIBE, 1075 RTSPREQ_ANNOUNCE, 1076 RTSPREQ_SETUP, 1077 RTSPREQ_PLAY, 1078 RTSPREQ_PAUSE, 1079 RTSPREQ_TEARDOWN, 1080 RTSPREQ_GET_PARAMETER, 1081 RTSPREQ_SET_PARAMETER, 1082 RTSPREQ_RECORD, 1083 RTSPREQ_RECEIVE, 1084 RTSPREQ_LAST /* last in list */ 1085 } Curl_RtspReq; 1086 1087 struct auth { 1088 unsigned long want; /* Bitmask set to the authentication methods wanted by 1089 app (with CURLOPT_HTTPAUTH or CURLOPT_PROXYAUTH). */ 1090 unsigned long picked; 1091 unsigned long avail; /* Bitmask for what the server reports to support for 1092 this resource */ 1093 BIT(done); /* TRUE when the auth phase is done and ready to do the 1094 actual request */ 1095 BIT(multipass); /* TRUE if this is not yet authenticated but within the 1096 auth multipass negotiation */ 1097 BIT(iestyle); /* TRUE if digest should be done IE-style or FALSE if it 1098 should be RFC compliant */ 1099 }; 1100 1101 #ifdef USE_NGHTTP2 1102 struct Curl_data_prio_node { 1103 struct Curl_data_prio_node *next; 1104 struct Curl_easy *data; 1105 }; 1106 #endif 1107 1108 /** 1109 * Priority information for an easy handle in relation to others 1110 * on the same connection. 1111 * TODO: we need to adapt it to the new priority scheme as defined in RFC 9218 1112 */ 1113 struct Curl_data_priority { 1114 #ifdef USE_NGHTTP2 1115 /* tree like dependencies only implemented in nghttp2 */ 1116 struct Curl_easy *parent; 1117 struct Curl_data_prio_node *children; 1118 #endif 1119 int weight; 1120 #ifdef USE_NGHTTP2 1121 BIT(exclusive); 1122 #endif 1123 }; 1124 1125 /* Timers */ 1126 typedef enum { 1127 EXPIRE_100_TIMEOUT, 1128 EXPIRE_ASYNC_NAME, 1129 EXPIRE_CONNECTTIMEOUT, 1130 EXPIRE_DNS_PER_NAME, /* family1 */ 1131 EXPIRE_DNS_PER_NAME2, /* family2 */ 1132 EXPIRE_HAPPY_EYEBALLS_DNS, /* See asyn-ares.c */ 1133 EXPIRE_HAPPY_EYEBALLS, 1134 EXPIRE_MULTI_PENDING, 1135 EXPIRE_RUN_NOW, 1136 EXPIRE_SPEEDCHECK, 1137 EXPIRE_TIMEOUT, 1138 EXPIRE_TOOFAST, 1139 EXPIRE_QUIC, 1140 EXPIRE_FTP_ACCEPT, 1141 EXPIRE_ALPN_EYEBALLS, 1142 EXPIRE_LAST /* not an actual timer, used as a marker only */ 1143 } expire_id; 1144 1145 1146 typedef enum { 1147 TRAILERS_NONE, 1148 TRAILERS_INITIALIZED, 1149 TRAILERS_SENDING, 1150 TRAILERS_DONE 1151 } trailers_state; 1152 1153 1154 /* 1155 * One instance for each timeout an easy handle can set. 1156 */ 1157 struct time_node { 1158 struct Curl_llist_node list; 1159 struct curltime time; 1160 expire_id eid; 1161 }; 1162 1163 /* individual pieces of the URL */ 1164 struct urlpieces { 1165 char *scheme; 1166 char *hostname; 1167 char *port; 1168 char *user; 1169 char *password; 1170 char *options; 1171 char *path; 1172 char *query; 1173 }; 1174 1175 #define CREDS_NONE 0 1176 #define CREDS_URL 1 /* from URL */ 1177 #define CREDS_OPTION 2 /* set with a CURLOPT_ */ 1178 #define CREDS_NETRC 3 /* found in netrc */ 1179 1180 struct UrlState { 1181 /* buffers to store authentication data in, as parsed from input options */ 1182 struct curltime keeps_speed; /* for the progress meter really */ 1183 1184 curl_off_t lastconnect_id; /* The last connection, -1 if undefined */ 1185 curl_off_t recent_conn_id; /* The most recent connection used, might no 1186 * longer exist */ 1187 struct dynbuf headerb; /* buffer to store headers in */ 1188 struct curl_slist *hstslist; /* list of HSTS files set by 1189 curl_easy_setopt(HSTS) calls */ 1190 curl_off_t current_speed; /* the ProgressShow() function sets this, 1191 bytes / second */ 1192 1193 /* hostname, port number and protocol of the first (not followed) request. 1194 if set, this should be the hostname that we will sent authorization to, 1195 no else. Used to make Location: following not keep sending user+password. 1196 This is strdup()ed data. */ 1197 char *first_host; 1198 int first_remote_port; 1199 curl_prot_t first_remote_protocol; 1200 1201 int retrycount; /* number of retries on a new connection */ 1202 struct Curl_ssl_scache *ssl_scache; /* TLS session pool */ 1203 int os_errno; /* filled in with errno whenever an error occurs */ 1204 long followlocation; /* redirect counter */ 1205 int requests; /* request counter: redirects + authentication retakes */ 1206 #ifdef HAVE_SIGNAL 1207 /* storage for the previous bag^H^H^HSIGPIPE signal handler :-) */ 1208 void (*prev_signal)(int sig); 1209 #endif 1210 #ifndef CURL_DISABLE_DIGEST_AUTH 1211 struct digestdata digest; /* state data for host Digest auth */ 1212 struct digestdata proxydigest; /* state data for proxy Digest auth */ 1213 #endif 1214 struct auth authhost; /* auth details for host */ 1215 struct auth authproxy; /* auth details for proxy */ 1216 #ifdef USE_CURL_ASYNC 1217 struct Curl_async async; /* asynchronous name resolver data */ 1218 #endif 1219 1220 #if defined(USE_OPENSSL) 1221 /* void instead of ENGINE to avoid bleeding OpenSSL into this header */ 1222 void *engine; 1223 /* this is just a flag -- we do not need to reference the provider in any 1224 * way as OpenSSL takes care of that */ 1225 BIT(provider); 1226 BIT(provider_failed); 1227 #endif /* USE_OPENSSL */ 1228 struct curltime expiretime; /* set this with Curl_expire() only */ 1229 struct Curl_tree timenode; /* for the splay stuff */ 1230 struct Curl_llist timeoutlist; /* list of pending timeouts */ 1231 struct time_node expires[EXPIRE_LAST]; /* nodes for each expire type */ 1232 1233 /* a place to store the most recently set (S)FTP entrypath */ 1234 char *most_recent_ftp_entrypath; 1235 char *range; /* range, if used. See README for detailed specification on 1236 this syntax. */ 1237 curl_off_t resume_from; /* continue [ftp] transfer from here */ 1238 1239 #ifndef CURL_DISABLE_RTSP 1240 /* This RTSP state information survives requests and connections */ 1241 long rtsp_next_client_CSeq; /* the session's next client CSeq */ 1242 long rtsp_next_server_CSeq; /* the session's next server CSeq */ 1243 long rtsp_CSeq_recv; /* most recent CSeq received */ 1244 1245 unsigned char rtp_channel_mask[32]; /* for the correctness checking of the 1246 interleaved data */ 1247 #endif 1248 1249 curl_off_t infilesize; /* size of file to upload, -1 means unknown. 1250 Copied from set.filesize at start of operation */ 1251 #if defined(USE_HTTP2) || defined(USE_HTTP3) 1252 struct Curl_data_priority priority; /* shallow copy of data->set */ 1253 #endif 1254 1255 curl_read_callback fread_func; /* read callback/function */ 1256 void *in; /* CURLOPT_READDATA */ 1257 CURLU *uh; /* URL handle for the current parsed URL */ 1258 struct urlpieces up; 1259 char *url; /* work URL, copied from UserDefined */ 1260 char *referer; /* referer string */ 1261 struct curl_slist *resolve; /* set to point to the set.resolve list when 1262 this should be dealt with in pretransfer */ 1263 #ifndef CURL_DISABLE_HTTP 1264 curl_mimepart *mimepost; 1265 #ifndef CURL_DISABLE_FORM_API 1266 curl_mimepart *formp; /* storage for old API form-posting, allocated on 1267 demand */ 1268 #endif 1269 size_t trailers_bytes_sent; 1270 struct dynbuf trailers_buf; /* a buffer containing the compiled trailing 1271 headers */ 1272 struct Curl_llist httphdrs; /* received headers */ 1273 struct curl_header headerout[2]; /* for external purposes */ 1274 struct Curl_header_store *prevhead; /* the latest added header */ 1275 trailers_state trailers_state; /* whether we are sending trailers 1276 and what stage are we at */ 1277 #endif 1278 #ifndef CURL_DISABLE_COOKIES 1279 struct curl_slist *cookielist; /* list of cookie files set by 1280 curl_easy_setopt(COOKIEFILE) calls */ 1281 #endif 1282 1283 #ifndef CURL_DISABLE_VERBOSE_STRINGS 1284 struct curl_trc_feat *feat; /* opt. trace feature transfer is part of */ 1285 #endif 1286 1287 #ifndef CURL_DISABLE_NETRC 1288 struct store_netrc netrc; 1289 #endif 1290 1291 /* Dynamically allocated strings, MUST be freed before this struct is 1292 killed. */ 1293 struct dynamically_allocated_data { 1294 char *uagent; 1295 char *accept_encoding; 1296 char *userpwd; 1297 char *rangeline; 1298 char *ref; 1299 char *host; 1300 #ifndef CURL_DISABLE_COOKIES 1301 char *cookiehost; 1302 #endif 1303 #ifndef CURL_DISABLE_RTSP 1304 char *rtsp_transport; 1305 #endif 1306 char *te; /* TE: request header */ 1307 1308 /* transfer credentials */ 1309 char *user; 1310 char *passwd; 1311 #ifndef CURL_DISABLE_PROXY 1312 char *proxyuserpwd; 1313 char *proxyuser; 1314 char *proxypasswd; 1315 #endif 1316 } aptr; 1317 unsigned char httpwant; /* when non-zero, a specific HTTP version requested 1318 to be used in the library's request(s) */ 1319 unsigned char httpversion; /* the lowest HTTP version*10 reported by any 1320 server involved in this request */ 1321 unsigned char httpreq; /* Curl_HttpReq; what kind of HTTP request (if any) 1322 is this */ 1323 unsigned char select_bits; /* != 0 -> bitmask of socket events for this 1324 transfer overriding anything the socket may 1325 report */ 1326 unsigned int creds_from:2; /* where is the server credentials originating 1327 from, see the CREDS_* defines above */ 1328 1329 /* when curl_easy_perform() is called, the multi handle is "owned" by 1330 the easy handle so curl_easy_cleanup() on such an easy handle will 1331 also close the multi handle! */ 1332 BIT(multi_owned_by_easy); 1333 1334 BIT(this_is_a_follow); /* this is a followed Location: request */ 1335 BIT(refused_stream); /* this was refused, try again */ 1336 BIT(errorbuf); /* Set to TRUE if the error buffer is already filled in. 1337 This must be set to FALSE every time _easy_perform() is 1338 called. */ 1339 BIT(allow_port); /* Is set.use_port allowed to take effect or not. This 1340 is always set TRUE when curl_easy_perform() is called. */ 1341 BIT(authproblem); /* TRUE if there is some problem authenticating */ 1342 /* set after initial USER failure, to prevent an authentication loop */ 1343 BIT(wildcardmatch); /* enable wildcard matching */ 1344 BIT(disableexpect); /* TRUE if Expect: is disabled due to a previous 1345 417 response */ 1346 BIT(use_range); 1347 BIT(rangestringalloc); /* the range string is malloc()'ed */ 1348 BIT(done); /* set to FALSE when Curl_init_do() is called and set to TRUE 1349 when multi_done() is called, to prevent multi_done() to get 1350 invoked twice when the multi interface is used. */ 1351 #ifndef CURL_DISABLE_COOKIES 1352 BIT(cookie_engine); 1353 #endif 1354 BIT(prefer_ascii); /* ASCII rather than binary */ 1355 #ifdef CURL_LIST_ONLY_PROTOCOL 1356 BIT(list_only); /* list directory contents */ 1357 #endif 1358 BIT(url_alloc); /* URL string is malloc()'ed */ 1359 BIT(referer_alloc); /* referer string is malloc()ed */ 1360 BIT(wildcard_resolve); /* Set to true if any resolve change is a wildcard */ 1361 BIT(upload); /* upload request */ 1362 BIT(internal); /* internal: true if this easy handle was created for 1363 internal use and the user does not have ownership of the 1364 handle. */ 1365 }; 1366 1367 /* 1368 * This 'UserDefined' struct must only contain data that is set once to go 1369 * for many (perhaps) independent connections. Values that are generated or 1370 * calculated internally for the "session handle" MUST be defined within the 1371 * 'struct UrlState' instead. The only exceptions MUST note the changes in 1372 * the 'DynamicStatic' struct. 1373 * Character pointer fields point to dynamic storage, unless otherwise stated. 1374 */ 1375 1376 struct Curl_multi; /* declared in multihandle.c */ 1377 1378 enum dupstring { 1379 STRING_CERT, /* client certificate filename */ 1380 STRING_CERT_TYPE, /* format for certificate (default: PEM)*/ 1381 STRING_KEY, /* private key filename */ 1382 STRING_KEY_PASSWD, /* plain text private key password */ 1383 STRING_KEY_TYPE, /* format for private key (default: PEM) */ 1384 STRING_SSL_CAPATH, /* CA directory name (does not work on Windows) */ 1385 STRING_SSL_CAFILE, /* certificate file to verify peer against */ 1386 STRING_SSL_PINNEDPUBLICKEY, /* public key file to verify peer against */ 1387 STRING_SSL_CIPHER_LIST, /* list of ciphers to use */ 1388 STRING_SSL_CIPHER13_LIST, /* list of TLS 1.3 ciphers to use */ 1389 STRING_SSL_CRLFILE, /* crl file to check certificate */ 1390 STRING_SSL_ISSUERCERT, /* issuer cert file to check certificate */ 1391 STRING_SERVICE_NAME, /* Service name */ 1392 #ifndef CURL_DISABLE_PROXY 1393 STRING_CERT_PROXY, /* client certificate filename */ 1394 STRING_CERT_TYPE_PROXY, /* format for certificate (default: PEM)*/ 1395 STRING_KEY_PROXY, /* private key filename */ 1396 STRING_KEY_PASSWD_PROXY, /* plain text private key password */ 1397 STRING_KEY_TYPE_PROXY, /* format for private key (default: PEM) */ 1398 STRING_SSL_CAPATH_PROXY, /* CA directory name (does not work on Windows) */ 1399 STRING_SSL_CAFILE_PROXY, /* certificate file to verify peer against */ 1400 STRING_SSL_PINNEDPUBLICKEY_PROXY, /* public key file to verify proxy */ 1401 STRING_SSL_CIPHER_LIST_PROXY, /* list of ciphers to use */ 1402 STRING_SSL_CIPHER13_LIST_PROXY, /* list of TLS 1.3 ciphers to use */ 1403 STRING_SSL_CRLFILE_PROXY, /* crl file to check certificate */ 1404 STRING_SSL_ISSUERCERT_PROXY, /* issuer cert file to check certificate */ 1405 STRING_PROXY_SERVICE_NAME, /* Proxy service name */ 1406 #endif 1407 #ifndef CURL_DISABLE_COOKIES 1408 STRING_COOKIE, /* HTTP cookie string to send */ 1409 STRING_COOKIEJAR, /* dump all cookies to this file */ 1410 #endif 1411 STRING_CUSTOMREQUEST, /* HTTP/FTP/RTSP request/method to use */ 1412 STRING_DEFAULT_PROTOCOL, /* Protocol to use when the URL does not specify */ 1413 STRING_DEVICE, /* local network interface/address to use */ 1414 STRING_INTERFACE, /* local network interface to use */ 1415 STRING_BINDHOST, /* local address to use */ 1416 STRING_ENCODING, /* Accept-Encoding string */ 1417 #ifndef CURL_DISABLE_FTP 1418 STRING_FTP_ACCOUNT, /* ftp account data */ 1419 STRING_FTP_ALTERNATIVE_TO_USER, /* command to send if USER/PASS fails */ 1420 STRING_FTPPORT, /* port to send with the FTP PORT command */ 1421 #endif 1422 #if defined(HAVE_GSSAPI) 1423 STRING_KRB_LEVEL, /* krb security level */ 1424 #endif 1425 #ifndef CURL_DISABLE_NETRC 1426 STRING_NETRC_FILE, /* if not NULL, use this instead of trying to find 1427 $HOME/.netrc */ 1428 #endif 1429 #ifndef CURL_DISABLE_PROXY 1430 STRING_PROXY, /* proxy to use */ 1431 STRING_PRE_PROXY, /* pre socks proxy to use */ 1432 #endif 1433 STRING_SET_RANGE, /* range, if used */ 1434 STRING_SET_REFERER, /* custom string for the HTTP referer field */ 1435 STRING_SET_URL, /* what original URL to work on */ 1436 STRING_USERAGENT, /* User-Agent string */ 1437 STRING_SSL_ENGINE, /* name of ssl engine */ 1438 STRING_USERNAME, /* <username>, if used */ 1439 STRING_PASSWORD, /* <password>, if used */ 1440 STRING_OPTIONS, /* <options>, if used */ 1441 #ifndef CURL_DISABLE_PROXY 1442 STRING_PROXYUSERNAME, /* Proxy <username>, if used */ 1443 STRING_PROXYPASSWORD, /* Proxy <password>, if used */ 1444 STRING_NOPROXY, /* List of hosts which should not use the proxy, if 1445 used */ 1446 #endif 1447 #ifndef CURL_DISABLE_RTSP 1448 STRING_RTSP_SESSION_ID, /* Session ID to use */ 1449 STRING_RTSP_STREAM_URI, /* Stream URI for this request */ 1450 STRING_RTSP_TRANSPORT, /* Transport for this session */ 1451 #endif 1452 #ifdef USE_SSH 1453 STRING_SSH_PRIVATE_KEY, /* path to the private key file for auth */ 1454 STRING_SSH_PUBLIC_KEY, /* path to the public key file for auth */ 1455 STRING_SSH_HOST_PUBLIC_KEY_MD5, /* md5 of host public key in ASCII hex */ 1456 STRING_SSH_HOST_PUBLIC_KEY_SHA256, /* sha256 of host public key in base64 */ 1457 STRING_SSH_KNOWNHOSTS, /* filename of knownhosts file */ 1458 #endif 1459 #ifndef CURL_DISABLE_SMTP 1460 STRING_MAIL_FROM, 1461 STRING_MAIL_AUTH, 1462 #endif 1463 #ifdef USE_TLS_SRP 1464 STRING_TLSAUTH_USERNAME, /* TLS auth <username> */ 1465 STRING_TLSAUTH_PASSWORD, /* TLS auth <password> */ 1466 #ifndef CURL_DISABLE_PROXY 1467 STRING_TLSAUTH_USERNAME_PROXY, /* TLS auth <username> */ 1468 STRING_TLSAUTH_PASSWORD_PROXY, /* TLS auth <password> */ 1469 #endif 1470 #endif 1471 STRING_BEARER, /* <bearer>, if used */ 1472 #ifdef USE_UNIX_SOCKETS 1473 STRING_UNIX_SOCKET_PATH, /* path to Unix socket, if used */ 1474 #endif 1475 STRING_TARGET, /* CURLOPT_REQUEST_TARGET */ 1476 #ifndef CURL_DISABLE_DOH 1477 STRING_DOH, /* CURLOPT_DOH_URL */ 1478 #endif 1479 #ifndef CURL_DISABLE_ALTSVC 1480 STRING_ALTSVC, /* CURLOPT_ALTSVC */ 1481 #endif 1482 #ifndef CURL_DISABLE_HSTS 1483 STRING_HSTS, /* CURLOPT_HSTS */ 1484 #endif 1485 STRING_SASL_AUTHZID, /* CURLOPT_SASL_AUTHZID */ 1486 #ifdef USE_ARES 1487 STRING_DNS_SERVERS, 1488 STRING_DNS_INTERFACE, 1489 STRING_DNS_LOCAL_IP4, 1490 STRING_DNS_LOCAL_IP6, 1491 #endif 1492 STRING_SSL_EC_CURVES, 1493 #ifndef CURL_DISABLE_AWS 1494 STRING_AWS_SIGV4, /* Parameters for V4 signature */ 1495 #endif 1496 #ifndef CURL_DISABLE_PROXY 1497 STRING_HAPROXY_CLIENT_IP, /* CURLOPT_HAPROXY_CLIENT_IP */ 1498 #endif 1499 STRING_ECH_CONFIG, /* CURLOPT_ECH_CONFIG */ 1500 STRING_ECH_PUBLIC, /* CURLOPT_ECH_PUBLIC */ 1501 1502 /* -- end of null-terminated strings -- */ 1503 1504 STRING_LASTZEROTERMINATED, 1505 1506 /* -- below this are pointers to binary data that cannot be strdup'ed. --- */ 1507 1508 STRING_COPYPOSTFIELDS, /* if POST, set the fields' values here */ 1509 1510 STRING_LAST /* not used, just an end-of-list marker */ 1511 }; 1512 1513 enum dupblob { 1514 BLOB_CERT, 1515 BLOB_KEY, 1516 BLOB_SSL_ISSUERCERT, 1517 BLOB_CAINFO, 1518 #ifndef CURL_DISABLE_PROXY 1519 BLOB_CERT_PROXY, 1520 BLOB_KEY_PROXY, 1521 BLOB_SSL_ISSUERCERT_PROXY, 1522 BLOB_CAINFO_PROXY, 1523 #endif 1524 BLOB_LAST 1525 }; 1526 1527 /* callback that gets called when this easy handle is completed within a multi 1528 handle. Only used for internally created transfers, like for example 1529 DoH. */ 1530 typedef int (*multidone_func)(struct Curl_easy *easy, CURLcode result); 1531 1532 struct UserDefined { 1533 FILE *err; /* the stderr user data goes here */ 1534 void *debugdata; /* the data that will be passed to fdebug */ 1535 char *errorbuffer; /* (Static) store failure messages in here */ 1536 void *out; /* CURLOPT_WRITEDATA */ 1537 void *in_set; /* CURLOPT_READDATA */ 1538 void *writeheader; /* write the header to this if non-NULL */ 1539 unsigned long httpauth; /* kind of HTTP authentication to use (bitmask) */ 1540 unsigned long proxyauth; /* kind of proxy authentication to use (bitmask) */ 1541 long maxredirs; /* maximum no. of http(s) redirects to follow, set to -1 1542 for infinity */ 1543 void *postfields; /* if POST, set the fields' values here */ 1544 curl_seek_callback seek_func; /* function that seeks the input */ 1545 curl_off_t postfieldsize; /* if POST, this might have a size to use instead 1546 of strlen(), and then the data *may* be binary 1547 (contain zero bytes) */ 1548 curl_write_callback fwrite_func; /* function that stores the output */ 1549 curl_write_callback fwrite_header; /* function that stores headers */ 1550 curl_write_callback fwrite_rtp; /* function that stores interleaved RTP */ 1551 curl_read_callback fread_func_set; /* function that reads the input */ 1552 curl_progress_callback fprogress; /* OLD and deprecated progress callback */ 1553 curl_xferinfo_callback fxferinfo; /* progress callback */ 1554 curl_debug_callback fdebug; /* function that write informational data */ 1555 curl_ioctl_callback ioctl_func; /* function for I/O control */ 1556 curl_sockopt_callback fsockopt; /* function for setting socket options */ 1557 void *sockopt_client; /* pointer to pass to the socket options callback */ 1558 curl_opensocket_callback fopensocket; /* function for checking/translating 1559 the address and opening the 1560 socket */ 1561 void *opensocket_client; 1562 curl_closesocket_callback fclosesocket; /* function for closing the 1563 socket */ 1564 void *closesocket_client; 1565 curl_prereq_callback fprereq; /* pre-initial request callback */ 1566 void *prereq_userp; /* pre-initial request user data */ 1567 1568 void *seek_client; /* pointer to pass to the seek callback */ 1569 #ifndef CURL_DISABLE_HSTS 1570 curl_hstsread_callback hsts_read; 1571 void *hsts_read_userp; 1572 curl_hstswrite_callback hsts_write; 1573 void *hsts_write_userp; 1574 #endif 1575 void *progress_client; /* pointer to pass to the progress callback */ 1576 void *ioctl_client; /* pointer to pass to the ioctl callback */ 1577 long maxage_conn; /* in seconds, max idle time to allow a connection that 1578 is to be reused */ 1579 long maxlifetime_conn; /* in seconds, max time since creation to allow a 1580 connection that is to be reused */ 1581 #ifndef CURL_DISABLE_TFTP 1582 long tftp_blksize; /* in bytes, 0 means use default */ 1583 #endif 1584 curl_off_t filesize; /* size of file to upload, -1 means unknown */ 1585 long low_speed_limit; /* bytes/second */ 1586 long low_speed_time; /* number of seconds */ 1587 curl_off_t max_send_speed; /* high speed limit in bytes/second for upload */ 1588 curl_off_t max_recv_speed; /* high speed limit in bytes/second for 1589 download */ 1590 curl_off_t set_resume_from; /* continue [ftp] transfer from here */ 1591 struct curl_slist *headers; /* linked list of extra headers */ 1592 struct curl_httppost *httppost; /* linked list of old POST data */ 1593 #if !defined(CURL_DISABLE_MIME) || !defined(CURL_DISABLE_FORM_API) 1594 curl_mimepart mimepost; /* MIME/POST data. */ 1595 #endif 1596 #ifndef CURL_DISABLE_TELNET 1597 struct curl_slist *telnet_options; /* linked list of telnet options */ 1598 #endif 1599 struct curl_slist *resolve; /* list of names to add/remove from 1600 DNS cache */ 1601 struct curl_slist *connect_to; /* list of host:port mappings to override 1602 the hostname and port to connect to */ 1603 time_t timevalue; /* what time to compare with */ 1604 struct ssl_config_data ssl; /* user defined SSL stuff */ 1605 #ifndef CURL_DISABLE_PROXY 1606 struct ssl_config_data proxy_ssl; /* user defined SSL stuff for proxy */ 1607 struct curl_slist *proxyheaders; /* linked list of extra CONNECT headers */ 1608 unsigned short proxyport; /* If non-zero, use this port number by 1609 default. If the proxy string features a 1610 ":[port]" that one will override this. */ 1611 unsigned char proxytype; /* what kind of proxy: curl_proxytype */ 1612 unsigned char socks5auth;/* kind of SOCKS5 authentication to use (bitmask) */ 1613 #endif 1614 struct ssl_general_config general_ssl; /* general user defined SSL stuff */ 1615 int dns_cache_timeout; /* DNS cache timeout (seconds) */ 1616 unsigned int buffer_size; /* size of receive buffer to use */ 1617 unsigned int upload_buffer_size; /* size of upload buffer to use, 1618 keep it >= CURL_MAX_WRITE_SIZE */ 1619 void *private_data; /* application-private data */ 1620 #ifndef CURL_DISABLE_HTTP 1621 struct curl_slist *http200aliases; /* linked list of aliases for http200 */ 1622 #endif 1623 curl_off_t max_filesize; /* Maximum file size to download */ 1624 #ifndef CURL_DISABLE_FTP 1625 unsigned int accepttimeout; /* in milliseconds, 0 means no timeout */ 1626 unsigned char ftp_filemethod; /* how to get to a file: curl_ftpfile */ 1627 unsigned char ftpsslauth; /* what AUTH XXX to try: curl_ftpauth */ 1628 unsigned char ftp_ccc; /* FTP CCC options: curl_ftpccc */ 1629 #endif 1630 #if !defined(CURL_DISABLE_FTP) || defined(USE_SSH) 1631 struct curl_slist *quote; /* after connection is established */ 1632 struct curl_slist *postquote; /* after the transfer */ 1633 struct curl_slist *prequote; /* before the transfer, after type */ 1634 #endif 1635 #ifdef USE_LIBSSH2 1636 curl_sshhostkeycallback ssh_hostkeyfunc; /* hostkey check callback */ 1637 void *ssh_hostkeyfunc_userp; /* custom pointer to callback */ 1638 #endif 1639 #ifdef USE_SSH 1640 curl_sshkeycallback ssh_keyfunc; /* key matching callback */ 1641 void *ssh_keyfunc_userp; /* custom pointer to callback */ 1642 int ssh_auth_types; /* allowed SSH auth types */ 1643 unsigned int new_directory_perms; /* when creating remote dirs */ 1644 #endif 1645 unsigned int new_file_perms; /* when creating remote files */ 1646 char *str[STRING_LAST]; /* array of strings, pointing to allocated memory */ 1647 struct curl_blob *blobs[BLOB_LAST]; 1648 #ifdef USE_IPV6 1649 unsigned int scope_id; /* Scope id for IPv6 */ 1650 #endif 1651 curl_prot_t allowed_protocols; 1652 curl_prot_t redir_protocols; 1653 #ifndef CURL_DISABLE_RTSP 1654 void *rtp_out; /* write RTP to this if non-NULL */ 1655 /* Common RTSP header options */ 1656 Curl_RtspReq rtspreq; /* RTSP request type */ 1657 #endif 1658 #ifndef CURL_DISABLE_FTP 1659 curl_chunk_bgn_callback chunk_bgn; /* called before part of transfer 1660 starts */ 1661 curl_chunk_end_callback chunk_end; /* called after part transferring 1662 stopped */ 1663 curl_fnmatch_callback fnmatch; /* callback to decide which file corresponds 1664 to pattern (e.g. if WILDCARDMATCH is on) */ 1665 void *fnmatch_data; 1666 void *wildcardptr; 1667 #endif 1668 1669 unsigned int timeout; /* ms, 0 means no timeout */ 1670 unsigned int connecttimeout; /* ms, 0 means default timeout */ 1671 unsigned int happy_eyeballs_timeout; /* ms, 0 is a valid value */ 1672 unsigned int server_response_timeout; /* ms, 0 means no timeout */ 1673 unsigned int shutdowntimeout; /* ms, 0 means default timeout */ 1674 int tcp_keepidle; /* seconds in idle before sending keepalive probe */ 1675 int tcp_keepintvl; /* seconds between TCP keepalive probes */ 1676 int tcp_keepcnt; /* maximum number of keepalive probes */ 1677 1678 long expect_100_timeout; /* in milliseconds */ 1679 #if defined(USE_HTTP2) || defined(USE_HTTP3) 1680 struct Curl_data_priority priority; 1681 #endif 1682 curl_resolver_start_callback resolver_start; /* optional callback called 1683 before resolver start */ 1684 void *resolver_start_client; /* pointer to pass to resolver start callback */ 1685 long upkeep_interval_ms; /* Time between calls for connection upkeep. */ 1686 multidone_func fmultidone; 1687 #ifndef CURL_DISABLE_DOH 1688 curl_off_t dohfor_mid; /* this is a DoH request for that transfer */ 1689 #endif 1690 CURLU *uh; /* URL handle for the current parsed URL */ 1691 #ifndef CURL_DISABLE_HTTP 1692 void *trailer_data; /* pointer to pass to trailer data callback */ 1693 curl_trailer_callback trailer_callback; /* trailing data callback */ 1694 #endif 1695 #ifndef CURL_DISABLE_SMTP 1696 struct curl_slist *mail_rcpt; /* linked list of mail recipients */ 1697 #endif 1698 unsigned int maxconnects; /* Max idle connections in the connection cache */ 1699 unsigned short use_port; /* which port to use (when not using default) */ 1700 #ifndef CURL_DISABLE_BINDLOCAL 1701 unsigned short localport; /* local port number to bind to */ 1702 unsigned short localportrange; /* number of additional port numbers to test 1703 in case the 'localport' one cannot be 1704 bind()ed */ 1705 #endif 1706 #ifndef CURL_DISABLE_NETRC 1707 unsigned char use_netrc; /* enum CURL_NETRC_OPTION values */ 1708 #endif 1709 #if !defined(CURL_DISABLE_FTP) || defined(USE_SSH) 1710 /* Despite the name, ftp_create_missing_dirs is for FTP(S) and SFTP 1711 1 - create directories that do not exist 1712 2 - the same but also allow MKD to fail once 1713 */ 1714 unsigned char ftp_create_missing_dirs; 1715 #endif 1716 unsigned char use_ssl; /* if AUTH TLS is to be attempted etc, for FTP or 1717 IMAP or POP3 or others! (type: curl_usessl)*/ 1718 char keep_post; /* keep POSTs as POSTs after a 30x request; each 1719 bit represents a request, from 301 to 303 */ 1720 unsigned char timecondition; /* kind of time comparison: curl_TimeCond */ 1721 unsigned char method; /* what kind of HTTP request: Curl_HttpReq */ 1722 unsigned char httpwant; /* when non-zero, a specific HTTP version requested 1723 to be used in the library's request(s) */ 1724 unsigned char ipver; /* the CURL_IPRESOLVE_* defines in the public header 1725 file 0 - whatever, 1 - v2, 2 - v6 */ 1726 #ifdef HAVE_GSSAPI 1727 /* GSS-API credential delegation, see the documentation of 1728 CURLOPT_GSSAPI_DELEGATION */ 1729 unsigned char gssapi_delegation; 1730 #endif 1731 BIT(connect_only); /* make connection/request, then let application use the 1732 socket */ 1733 BIT(connect_only_ws); /* special websocket connect-only level */ 1734 #ifndef CURL_DISABLE_SMTP 1735 BIT(mail_rcpt_allowfails); /* allow RCPT TO command to fail for some 1736 recipients */ 1737 #endif 1738 #ifndef CURL_DISABLE_MIME 1739 BIT(mime_formescape); 1740 #endif 1741 BIT(is_fread_set); /* has read callback been set to non-NULL? */ 1742 #ifndef CURL_DISABLE_TFTP 1743 BIT(tftp_no_options); /* do not send TFTP options requests */ 1744 #endif 1745 BIT(sep_headers); /* handle host and proxy headers separately */ 1746 #ifndef CURL_DISABLE_COOKIES 1747 BIT(cookiesession); /* new cookie session? */ 1748 #endif 1749 BIT(crlf); /* convert crlf on ftp upload(?) */ 1750 #ifdef USE_SSH 1751 BIT(ssh_compression); /* enable SSH compression */ 1752 #endif 1753 1754 /* Here follows boolean settings that define how to behave during 1755 this session. They are STATIC, set by libcurl users or at least initially 1756 and they do not change during operations. */ 1757 BIT(quick_exit); /* set 1L when it is okay to leak things (like 1758 threads), as we are about to exit() anyway and 1759 do not want lengthy cleanups to delay termination, 1760 e.g. after a DNS timeout */ 1761 BIT(get_filetime); /* get the time and get of the remote file */ 1762 #ifndef CURL_DISABLE_PROXY 1763 BIT(tunnel_thru_httpproxy); /* use CONNECT through an HTTP proxy */ 1764 #endif 1765 BIT(prefer_ascii); /* ASCII rather than binary */ 1766 BIT(remote_append); /* append, not overwrite, on upload */ 1767 #ifdef CURL_LIST_ONLY_PROTOCOL 1768 BIT(list_only); /* list directory */ 1769 #endif 1770 #ifndef CURL_DISABLE_FTP 1771 BIT(ftp_use_port); /* use the FTP PORT command */ 1772 BIT(ftp_use_epsv); /* if EPSV is to be attempted or not */ 1773 BIT(ftp_use_eprt); /* if EPRT is to be attempted or not */ 1774 BIT(ftp_use_pret); /* if PRET is to be used before PASV or not */ 1775 BIT(ftp_skip_ip); /* skip the IP address the FTP server passes on to 1776 us */ 1777 BIT(wildcard_enabled); /* enable wildcard matching */ 1778 #endif 1779 BIT(hide_progress); /* do not use the progress meter */ 1780 BIT(http_fail_on_error); /* fail on HTTP error codes >= 400 */ 1781 BIT(http_keep_sending_on_error); /* for HTTP status codes >= 300 */ 1782 BIT(http_follow_location); /* follow HTTP redirects */ 1783 BIT(http_transfer_encoding); /* request compressed HTTP transfer-encoding */ 1784 BIT(allow_auth_to_other_hosts); 1785 BIT(include_header); /* include received protocol headers in data output */ 1786 BIT(http_set_referer); /* is a custom referer used */ 1787 BIT(http_auto_referer); /* set "correct" referer when following 1788 location: */ 1789 BIT(opt_no_body); /* as set with CURLOPT_NOBODY */ 1790 BIT(verbose); /* output verbosity */ 1791 #if defined(HAVE_GSSAPI) 1792 BIT(krb); /* Kerberos connection requested */ 1793 #endif 1794 BIT(reuse_forbid); /* forbidden to be reused, close after use */ 1795 BIT(reuse_fresh); /* do not reuse an existing connection */ 1796 BIT(no_signal); /* do not use any signal/alarm handler */ 1797 BIT(tcp_nodelay); /* whether to enable TCP_NODELAY or not */ 1798 BIT(ignorecl); /* ignore content length */ 1799 BIT(http_te_skip); /* pass the raw body data to the user, even when 1800 transfer-encoded (chunked, compressed) */ 1801 BIT(http_ce_skip); /* pass the raw body data to the user, even when 1802 content-encoded (chunked, compressed) */ 1803 BIT(proxy_transfer_mode); /* set transfer mode (;type=<a|i>) when doing 1804 FTP via an HTTP proxy */ 1805 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI) 1806 BIT(socks5_gssapi_nec); /* Flag to support NEC SOCKS5 server */ 1807 #endif 1808 BIT(sasl_ir); /* Enable/disable SASL initial response */ 1809 BIT(tcp_keepalive); /* use TCP keepalives */ 1810 BIT(tcp_fastopen); /* use TCP Fast Open */ 1811 BIT(ssl_enable_alpn);/* TLS ALPN extension? */ 1812 BIT(path_as_is); /* allow dotdots? */ 1813 BIT(pipewait); /* wait for multiplex status before starting a new 1814 connection */ 1815 BIT(suppress_connect_headers); /* suppress proxy CONNECT response headers 1816 from user callbacks */ 1817 BIT(dns_shuffle_addresses); /* whether to shuffle addresses before use */ 1818 #ifndef CURL_DISABLE_PROXY 1819 BIT(haproxyprotocol); /* whether to send HAProxy PROXY protocol v1 1820 header */ 1821 #endif 1822 #ifdef USE_UNIX_SOCKETS 1823 BIT(abstract_unix_socket); 1824 #endif 1825 BIT(disallow_username_in_url); /* disallow username in URL */ 1826 #ifndef CURL_DISABLE_DOH 1827 BIT(doh); /* DNS-over-HTTPS enabled */ 1828 BIT(doh_verifypeer); /* DoH certificate peer verification */ 1829 BIT(doh_verifyhost); /* DoH certificate hostname verification */ 1830 BIT(doh_verifystatus); /* DoH certificate status verification */ 1831 #endif 1832 BIT(http09_allowed); /* allow HTTP/0.9 responses */ 1833 #ifndef CURL_DISABLE_WEBSOCKETS 1834 BIT(ws_raw_mode); 1835 #endif 1836 #ifdef USE_ECH 1837 int tls_ech; /* TLS ECH configuration */ 1838 #endif 1839 }; 1840 1841 #ifndef CURL_DISABLE_MIME 1842 #define IS_MIME_POST(a) ((a)->set.mimepost.kind != MIMEKIND_NONE) 1843 #else 1844 #define IS_MIME_POST(a) FALSE 1845 #endif 1846 1847 struct Names { 1848 struct Curl_hash *hostcache; 1849 enum { 1850 HCACHE_NONE, /* not pointing to anything */ 1851 HCACHE_MULTI, /* points to a shared one in the multi handle */ 1852 HCACHE_SHARED /* points to a shared one in a shared object */ 1853 } hostcachetype; 1854 }; 1855 1856 /* 1857 * The 'connectdata' struct MUST have all the connection oriented stuff as we 1858 * may have several simultaneous connections and connection structs in memory. 1859 * 1860 * The 'struct UserDefined' must only contain data that is set once to go for 1861 * many (perhaps) independent connections. Values that are generated or 1862 * calculated internally for the "session handle" must be defined within the 1863 * 'struct UrlState' instead. 1864 */ 1865 1866 struct Curl_easy { 1867 /* First a simple identifier to easier detect if a user mix up this easy 1868 handle with a multi handle. Set this to CURLEASY_MAGIC_NUMBER */ 1869 unsigned int magic; 1870 /* once an easy handle is tied to a connection pool a non-negative number to 1871 distinguish this transfer from other using the same pool. For easier 1872 tracking in log output. This may wrap around after LONG_MAX to 0 again, 1873 so it has no uniqueness guarantee for large processings. Note: it has no 1874 uniqueness either IFF more than one connection pool is used by the 1875 libcurl application. */ 1876 curl_off_t id; 1877 /* once an easy handle is added to a multi, either explicitly by the 1878 * libcurl application or implicitly during `curl_easy_perform()`, 1879 * a unique identifier inside this one multi instance. */ 1880 curl_off_t mid; 1881 1882 struct connectdata *conn; 1883 struct Curl_llist_node multi_queue; /* for multihandle list management */ 1884 struct Curl_llist_node conn_queue; /* list per connectdata */ 1885 1886 CURLMstate mstate; /* the handle's state */ 1887 CURLcode result; /* previous result */ 1888 1889 struct Curl_message msg; /* A single posted message. */ 1890 1891 /* Array with the plain socket numbers this handle takes care of, in no 1892 particular order. Note that all sockets are added to the sockhash, where 1893 the state etc are also kept. This array is mostly used to detect when a 1894 socket is to be removed from the hash. See singlesocket(). */ 1895 struct easy_pollset last_poll; 1896 1897 struct Names dns; 1898 struct Curl_multi *multi; /* if non-NULL, points to the multi handle 1899 struct to which this "belongs" when used by 1900 the multi interface */ 1901 struct Curl_multi *multi_easy; /* if non-NULL, points to the multi handle 1902 struct to which this "belongs" when used 1903 by the easy interface */ 1904 struct Curl_share *share; /* Share, handles global variable mutexing */ 1905 #ifdef USE_LIBPSL 1906 struct PslCache *psl; /* The associated PSL cache. */ 1907 #endif 1908 struct SingleRequest req; /* Request-specific data */ 1909 struct UserDefined set; /* values set by the libcurl user */ 1910 #ifndef CURL_DISABLE_COOKIES 1911 struct CookieInfo *cookies; /* the cookies, read from files and servers. 1912 NOTE that the 'cookie' field in the 1913 UserDefined struct defines if the "engine" 1914 is to be used or not. */ 1915 #endif 1916 #ifndef CURL_DISABLE_HSTS 1917 struct hsts *hsts; 1918 #endif 1919 #ifndef CURL_DISABLE_ALTSVC 1920 struct altsvcinfo *asi; /* the alt-svc cache */ 1921 #endif 1922 struct Progress progress; /* for all the progress meter data */ 1923 struct UrlState state; /* struct for fields used for state info and 1924 other dynamic purposes */ 1925 #ifndef CURL_DISABLE_FTP 1926 struct WildcardData *wildcard; /* wildcard download state info */ 1927 #endif 1928 struct PureInfo info; /* stats, reports and info data */ 1929 struct curl_tlssessioninfo tsi; /* Information about the TLS session, only 1930 valid after a client has asked for it */ 1931 }; 1932 1933 #define LIBCURL_NAME "libcurl" 1934 1935 #endif /* HEADER_CURL_URLDATA_H */ 1936