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