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