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