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