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