source: UsbWattMeter/trunk/curl-7.47.1/lib/urldata.h@ 164

Last change on this file since 164 was 164, checked in by coas-nagasima, 8 years ago

TOPPERS/ECNLサンプルアプリ「USB充電器電力計」を追加

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