Coverage Report

Created: 2025-07-12 06:28

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