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