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