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