Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Utilities / cmcurl-7.19.0 / lib / urldata.h
blob7343c8fe23be4233a2138b0e0e015d5d5b45e616
1 #ifndef __URLDATA_H
2 #define __URLDATA_H
3 /***************************************************************************
4 * _ _ ____ _
5 * Project ___| | | | _ \| |
6 * / __| | | | |_) | |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 * $Id: urldata.h,v 1.1.1.1 2008-09-23 16:32:05 hoffman Exp $
24 ***************************************************************************/
26 /* This file is for lib internal stuff */
28 #include "setup.h"
30 #define PORT_FTP 21
31 #define PORT_FTPS 990
32 #define PORT_TELNET 23
33 #define PORT_HTTP 80
34 #define PORT_HTTPS 443
35 #define PORT_DICT 2628
36 #define PORT_LDAP 389
37 #define PORT_LDAPS 636
38 #define PORT_TFTP 69
39 #define PORT_SSH 22
41 #define DICT_MATCH "/MATCH:"
42 #define DICT_MATCH2 "/M:"
43 #define DICT_MATCH3 "/FIND:"
44 #define DICT_DEFINE "/DEFINE:"
45 #define DICT_DEFINE2 "/D:"
46 #define DICT_DEFINE3 "/LOOKUP:"
48 #define CURL_DEFAULT_USER "anonymous"
49 #define CURL_DEFAULT_PASSWORD "ftp@example.com"
51 #define MAX_IPADR_LEN (4*9) /* should be enough to hold the longest ipv6 one */
53 #include "cookie.h"
54 #include "formdata.h"
56 #ifdef USE_SSLEAY
57 #ifdef USE_OPENSSL
58 #include "openssl/rsa.h"
59 #include "openssl/crypto.h"
60 #include "openssl/x509.h"
61 #include "openssl/pem.h"
62 #include "openssl/ssl.h"
63 #include "openssl/err.h"
64 #ifdef HAVE_OPENSSL_ENGINE_H
65 #include <openssl/engine.h>
66 #endif
67 #ifdef HAVE_OPENSSL_PKCS12_H
68 #include <openssl/pkcs12.h>
69 #endif
70 #else /* SSLeay-style includes */
71 #include "rsa.h"
72 #include "crypto.h"
73 #include "x509.h"
74 #include "pem.h"
75 #include "ssl.h"
76 #include "err.h"
77 #ifdef HAVE_OPENSSL_ENGINE_H
78 #include <engine.h>
79 #endif
80 #ifdef HAVE_OPENSSL_PKCS12_H
81 #include <pkcs12.h>
82 #endif
83 #endif /* USE_OPENSSL */
84 #ifdef USE_GNUTLS
85 #error Configuration error; cannot use GnuTLS *and* OpenSSL.
86 #endif
87 #endif /* USE_SSLEAY */
89 #ifdef USE_GNUTLS
90 #include <gnutls/gnutls.h>
91 #endif
93 #ifdef USE_NSS
94 #include <nspr.h>
95 #endif
97 #ifdef USE_QSOSSL
98 #include <qsossl.h>
99 #endif
101 #ifdef HAVE_NETINET_IN_H
102 #include <netinet/in.h>
103 #endif
105 #include "timeval.h"
107 #ifdef HAVE_ZLIB_H
108 #include <zlib.h> /* for content-encoding */
109 #endif
111 #ifdef USE_ARES
112 #include <ares.h>
113 #endif
115 #include <curl/curl.h>
117 #include "http_chunks.h" /* for the structs and enum stuff */
118 #include "hostip.h"
119 #include "hash.h"
120 #include "splay.h"
122 #ifdef HAVE_GSSAPI
123 # ifdef HAVE_GSSGNU
124 # include <gss.h>
125 # elif defined HAVE_GSSMIT
126 # include <gssapi/gssapi.h>
127 # include <gssapi/gssapi_generic.h>
128 # else
129 # include <gssapi.h>
130 # endif
131 #endif
133 #ifdef HAVE_LIBSSH2_H
134 #include <libssh2.h>
135 #include <libssh2_sftp.h>
136 #endif /* HAVE_LIBSSH2_H */
138 /* Download buffer size, keep it fairly big for speed reasons */
139 #undef BUFSIZE
140 #define BUFSIZE CURL_MAX_WRITE_SIZE
142 /* Initial size of the buffer to store headers in, it'll be enlarged in case
143 of need. */
144 #define HEADERSIZE 256
146 #define CURLEASY_MAGIC_NUMBER 0xc0dedbadU
148 /* Just a convenience macro to get the larger value out of two given.
149 We prefix with CURL to prevent name collisions. */
150 #define CURLMAX(x,y) ((x)>(y)?(x):(y))
152 #if defined(HAVE_KRB4) || defined(HAVE_GSSAPI)
153 /* Types needed for krb4/5-ftp connections */
154 struct krb4buffer {
155 void *data;
156 size_t size;
157 size_t index;
158 int eof_flag;
160 enum protection_level {
161 prot_clear,
162 prot_safe,
163 prot_confidential,
164 prot_private,
165 prot_cmd
167 #endif
169 /* enum for the nonblocking SSL connection state machine */
170 typedef enum {
171 ssl_connect_1,
172 ssl_connect_2,
173 ssl_connect_2_reading,
174 ssl_connect_2_writing,
175 ssl_connect_3,
176 ssl_connect_done
177 } ssl_connect_state;
179 typedef enum {
180 ssl_connection_none,
181 ssl_connection_negotiating,
182 ssl_connection_complete
183 } ssl_connection_state;
185 /* struct for data related to each SSL connection */
186 struct ssl_connect_data {
187 /* Use ssl encrypted communications TRUE/FALSE, not necessarily using it atm
188 but at least asked to or meaning to use it. See 'state' for the exact
189 current state of the connection. */
190 bool use;
191 ssl_connection_state state;
192 #ifdef USE_SSLEAY
193 /* these ones requires specific SSL-types */
194 SSL_CTX* ctx;
195 SSL* handle;
196 X509* server_cert;
197 ssl_connect_state connecting_state;
198 #endif /* USE_SSLEAY */
199 #ifdef USE_GNUTLS
200 gnutls_session session;
201 gnutls_certificate_credentials cred;
202 #endif /* USE_GNUTLS */
203 #ifdef USE_NSS
204 PRFileDesc *handle;
205 char *client_nickname;
206 #endif /* USE_NSS */
207 #ifdef USE_QSOSSL
208 SSLHandle *handle;
209 #endif /* USE_QSOSSL */
212 struct ssl_config_data {
213 long version; /* what version the client wants to use */
214 long certverifyresult; /* result from the certificate verification */
215 long verifypeer; /* set TRUE if this is desired */
216 long verifyhost; /* 0: no verify
217 1: check that CN exists
218 2: CN must match hostname */
219 char *CApath; /* certificate dir (doesn't work on windows) */
220 char *CAfile; /* cerficate to verify peer against */
221 char *CRLfile; /* CRL to check cerficate revocation */
222 char *issuercert; /* optional issuer cerficate filename */
223 char *random_file; /* path to file containing "random" data */
224 char *egdsocket; /* path to file containing the EGD daemon socket */
225 char *cipher_list; /* list of ciphers to use */
226 long numsessions; /* SSL session id cache size */
227 curl_ssl_ctx_callback fsslctx; /* function to initialize ssl ctx */
228 void *fsslctxp; /* parameter for call back */
229 bool sessionid; /* cache session IDs or not */
232 /* information stored about one single SSL session */
233 struct curl_ssl_session {
234 char *name; /* host name for which this ID was used */
235 void *sessionid; /* as returned from the SSL layer */
236 size_t idsize; /* if known, otherwise 0 */
237 long age; /* just a number, the higher the more recent */
238 unsigned short remote_port; /* remote port to connect to */
239 struct ssl_config_data ssl_config; /* setup for this session */
242 /* Struct used for Digest challenge-response authentication */
243 struct digestdata {
244 char *nonce;
245 char *cnonce;
246 char *realm;
247 int algo;
248 bool stale; /* set true for re-negotiation */
249 char *opaque;
250 char *qop;
251 char *algorithm;
252 int nc; /* nounce count */
255 typedef enum {
256 NTLMSTATE_NONE,
257 NTLMSTATE_TYPE1,
258 NTLMSTATE_TYPE2,
259 NTLMSTATE_TYPE3,
260 NTLMSTATE_LAST
261 } curlntlm;
263 #ifdef USE_WINDOWS_SSPI
264 /* When including these headers, you must define either SECURITY_WIN32
265 * or SECURITY_KERNEL, indicating who is compiling the code.
267 #define SECURITY_WIN32 1
268 #include <security.h>
269 #include <sspi.h>
270 #include <rpc.h>
271 #endif
273 #if defined(CURL_DOES_CONVERSIONS) && defined(HAVE_ICONV)
274 #include <iconv.h>
275 #endif
277 /* Struct used for NTLM challenge-response authentication */
278 struct ntlmdata {
279 curlntlm state;
280 #ifdef USE_WINDOWS_SSPI
281 CredHandle handle;
282 CtxtHandle c_handle;
283 SEC_WINNT_AUTH_IDENTITY identity;
284 SEC_WINNT_AUTH_IDENTITY *p_identity;
285 int has_handles;
286 void *type_2;
287 int n_type_2;
288 #else
289 unsigned int flags;
290 unsigned char nonce[8];
291 #endif
294 #ifdef HAVE_GSSAPI
295 struct negotiatedata {
296 bool gss; /* Whether we're processing GSS-Negotiate or Negotiate */
297 const char* protocol; /* "GSS-Negotiate" or "Negotiate" */
298 OM_uint32 status;
299 gss_ctx_id_t context;
300 gss_name_t server_name;
301 gss_buffer_desc output_token;
303 #endif
305 /****************************************************************************
306 * HTTP unique setup
307 ***************************************************************************/
308 struct HTTP {
309 struct FormData *sendit;
310 curl_off_t postsize; /* off_t to handle large file sizes */
311 char *postdata;
313 const char *p_pragma; /* Pragma: string */
314 const char *p_accept; /* Accept: string */
315 curl_off_t readbytecount;
316 curl_off_t writebytecount;
318 /* For FORM posting */
319 struct Form form;
321 struct back {
322 curl_read_callback fread_func; /* backup storage for fread pointer */
323 void *fread_in; /* backup storage for fread_in pointer */
324 char *postdata;
325 curl_off_t postsize;
326 } backup;
328 enum {
329 HTTPSEND_NADA, /* init */
330 HTTPSEND_REQUEST, /* sending a request */
331 HTTPSEND_BODY, /* sending body */
332 HTTPSEND_LAST /* never use this */
333 } sending;
335 void *send_buffer; /* used if the request couldn't be sent in one chunk,
336 points to an allocated send_buffer struct */
339 /****************************************************************************
340 * FTP unique setup
341 ***************************************************************************/
342 typedef enum {
343 FTP_STOP, /* do nothing state, stops the state machine */
344 FTP_WAIT220, /* waiting for the initial 220 response immediately after
345 a connect */
346 FTP_AUTH,
347 FTP_USER,
348 FTP_PASS,
349 FTP_ACCT,
350 FTP_PBSZ,
351 FTP_PROT,
352 FTP_CCC,
353 FTP_PWD,
354 FTP_QUOTE, /* waiting for a response to a command sent in a quote list */
355 FTP_RETR_PREQUOTE,
356 FTP_STOR_PREQUOTE,
357 FTP_POSTQUOTE,
358 FTP_CWD, /* change dir */
359 FTP_MKD, /* if the dir didn't exist */
360 FTP_MDTM, /* to figure out the datestamp */
361 FTP_TYPE, /* to set type when doing a head-like request */
362 FTP_LIST_TYPE, /* set type when about to do a dir list */
363 FTP_RETR_TYPE, /* set type when about to RETR a file */
364 FTP_STOR_TYPE, /* set type when about to STOR a file */
365 FTP_SIZE, /* get the remote file's size for head-like request */
366 FTP_RETR_SIZE, /* get the remote file's size for RETR */
367 FTP_STOR_SIZE, /* get the size for (resumed) STOR */
368 FTP_REST, /* when used to check if the server supports it in head-like */
369 FTP_RETR_REST, /* when asking for "resume" in for RETR */
370 FTP_PORT, /* generic state for PORT, LPRT and EPRT, check count1 */
371 FTP_PASV, /* generic state for PASV and EPSV, check count1 */
372 FTP_LIST, /* generic state for LIST, NLST or a custom list command */
373 FTP_RETR,
374 FTP_STOR, /* generic state for STOR and APPE */
375 FTP_QUIT,
376 FTP_LAST /* never used */
377 } ftpstate;
379 typedef enum {
380 FTPFILE_MULTICWD = 1, /* as defined by RFC1738 */
381 FTPFILE_NOCWD = 2, /* use SIZE / RETR / STOR on the full path */
382 FTPFILE_SINGLECWD = 3 /* make one CWD, then SIZE / RETR / STOR on the file */
383 } curl_ftpfile;
385 typedef enum {
386 FTPTRANSFER_BODY, /* yes do transfer a body */
387 FTPTRANSFER_INFO, /* do still go through to get info/headers */
388 FTPTRANSFER_NONE, /* don't get anything and don't get info */
389 FTPTRANSFER_LAST /* end of list marker, never used */
390 } curl_ftptransfer;
392 /* This FTP struct is used in the SessionHandle. All FTP data that is
393 connection-oriented must be in FTP_conn to properly deal with the fact that
394 perhaps the SessionHandle is changed between the times the connection is
395 used. */
396 struct FTP {
397 curl_off_t *bytecountp;
398 char *user; /* user name string */
399 char *passwd; /* password string */
401 /* transfer a file/body or not, done as a typedefed enum just to make
402 debuggers display the full symbol and not just the numerical value */
403 curl_ftptransfer transfer;
404 curl_off_t downloadsize;
407 /* ftp_conn is used for striuct connection-oriented data in the connectdata
408 struct */
409 struct ftp_conn {
410 char *entrypath; /* the PWD reply when we logged on */
411 char **dirs; /* realloc()ed array for path components */
412 int dirdepth; /* number of entries used in the 'dirs' array */
413 int diralloc; /* number of entries allocated for the 'dirs' array */
414 char *file; /* decoded file */
415 char *cache; /* data cache between getresponse()-calls */
416 curl_off_t cache_size; /* size of cache in bytes */
417 bool dont_check; /* Set to TRUE to prevent the final (post-transfer)
418 file size and 226/250 status check. It should still
419 read the line, just ignore the result. */
420 long response_time; /* When no timeout is given, this is the amount of
421 seconds we await for an FTP response. Initialized
422 in Curl_ftp_connect() */
423 bool ctl_valid; /* Tells Curl_ftp_quit() whether or not to do anything. If
424 the connection has timed out or been closed, this
425 should be FALSE when it gets to Curl_ftp_quit() */
426 bool cwddone; /* if it has been determined that the proper CWD combo
427 already has been done */
428 bool cwdfail; /* set TRUE if a CWD command fails, as then we must prevent
429 caching the current directory */
430 char *prevpath; /* conn->path from the previous transfer */
431 char transfertype; /* set by ftp_transfertype for use by Curl_client_write()a
432 and others (A/I or zero) */
433 size_t nread_resp; /* number of bytes currently read of a server response */
434 char *linestart_resp; /* line start pointer for the FTP server response
435 reader function */
437 int count1; /* general purpose counter for the state machine */
438 int count2; /* general purpose counter for the state machine */
439 int count3; /* general purpose counter for the state machine */
440 char *sendthis; /* allocated pointer to a buffer that is to be sent to the
441 ftp server */
442 size_t sendleft; /* number of bytes left to send from the sendthis buffer */
443 size_t sendsize; /* total size of the sendthis buffer */
444 struct timeval response; /* set to Curl_tvnow() when a command has been sent
445 off, used to time-out response reading */
446 ftpstate state; /* always use ftp.c:state() to change state! */
449 /****************************************************************************
450 * SSH unique setup
451 ***************************************************************************/
452 typedef enum {
453 SSH_NO_STATE = -1, /* Used for "nextState" so say there is none */
454 SSH_STOP = 0, /* do nothing state, stops the state machine */
456 SSH_S_STARTUP, /* Session startup, First state in SSH-CONNECT */
457 SSH_AUTHLIST,
458 SSH_AUTH_PKEY_INIT,
459 SSH_AUTH_PKEY,
460 SSH_AUTH_PASS_INIT,
461 SSH_AUTH_PASS,
462 SSH_AUTH_HOST_INIT,
463 SSH_AUTH_HOST,
464 SSH_AUTH_KEY_INIT,
465 SSH_AUTH_KEY,
466 SSH_AUTH_DONE,
467 SSH_SFTP_INIT,
468 SSH_SFTP_REALPATH, /* Last state in SSH-CONNECT */
470 SSH_SFTP_QUOTE_INIT, /* First state in SFTP-DO */
471 SSH_SFTP_POSTQUOTE_INIT, /* (Possibly) First state in SFTP-DONE */
472 SSH_SFTP_QUOTE,
473 SSH_SFTP_NEXT_QUOTE,
474 SSH_SFTP_QUOTE_STAT,
475 SSH_SFTP_QUOTE_SETSTAT,
476 SSH_SFTP_QUOTE_SYMLINK,
477 SSH_SFTP_QUOTE_MKDIR,
478 SSH_SFTP_QUOTE_RENAME,
479 SSH_SFTP_QUOTE_RMDIR,
480 SSH_SFTP_QUOTE_UNLINK,
481 SSH_SFTP_TRANS_INIT,
482 SSH_SFTP_UPLOAD_INIT,
483 SSH_SFTP_CREATE_DIRS_INIT,
484 SSH_SFTP_CREATE_DIRS,
485 SSH_SFTP_CREATE_DIRS_MKDIR,
486 SSH_SFTP_READDIR_INIT,
487 SSH_SFTP_READDIR,
488 SSH_SFTP_READDIR_LINK,
489 SSH_SFTP_READDIR_BOTTOM,
490 SSH_SFTP_READDIR_DONE,
491 SSH_SFTP_DOWNLOAD_INIT,
492 SSH_SFTP_DOWNLOAD_STAT, /* Last state in SFTP-DO */
493 SSH_SFTP_CLOSE, /* Last state in SFTP-DONE */
494 SSH_SFTP_SHUTDOWN, /* First state in SFTP-DISCONNECT */
495 SSH_SCP_TRANS_INIT, /* First state in SCP-DO */
496 SSH_SCP_UPLOAD_INIT,
497 SSH_SCP_DOWNLOAD_INIT,
498 SSH_SCP_DONE,
499 SSH_SCP_SEND_EOF,
500 SSH_SCP_WAIT_EOF,
501 SSH_SCP_WAIT_CLOSE,
502 SSH_SCP_CHANNEL_FREE, /* Last state in SCP-DONE */
503 SSH_SESSION_DISCONNECT, /* First state in SCP-DISCONNECT */
504 SSH_SESSION_FREE, /* Last state in SCP/SFTP-DISCONNECT */
505 SSH_QUIT,
506 SSH_LAST /* never used */
507 } sshstate;
509 /* this struct is used in the HandleData struct which is part of the
510 SessionHandle, which means this is used on a per-easy handle basis.
511 Everything that is strictly related to a connection is banned from this
512 struct. */
513 struct SSHPROTO {
514 char *path; /* the path we operate on */
517 /* ssh_conn is used for struct connection-oriented data in the connectdata
518 struct */
519 struct ssh_conn {
520 const char *authlist; /* List of auth. methods, managed by libssh2 */
521 #ifdef USE_LIBSSH2
522 const char *passphrase; /* passphrase to use */
523 char *rsa_pub; /* path name */
524 char *rsa; /* path name */
525 bool authed; /* the connection has been authenticated fine */
526 sshstate state; /* always use ssh.c:state() to change state! */
527 sshstate nextstate; /* the state to goto after stopping */
528 CURLcode actualcode; /* the actual error code */
529 struct curl_slist *quote_item; /* for the quote option */
530 char *quote_path1; /* two generic pointers for the QUOTE stuff */
531 char *quote_path2;
532 LIBSSH2_SFTP_ATTRIBUTES quote_attrs; /* used by the SFTP_QUOTE state */
533 char *homedir; /* when doing SFTP we figure out home dir in the
534 connect phase */
536 /* Here's a set of struct members used by the SFTP_READDIR state */
537 LIBSSH2_SFTP_ATTRIBUTES readdir_attrs;
538 char *readdir_filename;
539 char *readdir_longentry;
540 int readdir_len, readdir_totalLen, readdir_currLen;
541 char *readdir_line;
542 char *readdir_linkPath;
543 /* end of READDIR stuff */
545 int secondCreateDirs; /* counter use by the code to see if the
546 second attempt has been made to change
547 to/create a directory */
548 char *slash_pos; /* used by the SFTP_CREATE_DIRS state */
549 LIBSSH2_SESSION *ssh_session; /* Secure Shell session */
550 LIBSSH2_CHANNEL *ssh_channel; /* Secure Shell channel handle */
551 LIBSSH2_SFTP *sftp_session; /* SFTP handle */
552 LIBSSH2_SFTP_HANDLE *sftp_handle;
553 #endif /* USE_LIBSSH2 */
557 /****************************************************************************
558 * FILE unique setup
559 ***************************************************************************/
560 struct FILEPROTO {
561 char *path; /* the path we operate on */
562 char *freepath; /* pointer to the allocated block we must free, this might
563 differ from the 'path' pointer */
564 int fd; /* open file descriptor to read from! */
568 * Boolean values that concerns this connection.
570 struct ConnectBits {
571 bool close; /* if set, we close the connection after this request */
572 bool reuse; /* if set, this is a re-used connection */
573 bool proxy; /* if set, this transfer is done through a proxy - any type */
574 bool httpproxy; /* if set, this transfer is done through a http proxy */
575 bool user_passwd; /* do we use user+password for this connection? */
576 bool proxy_user_passwd; /* user+password for the proxy? */
577 bool ipv6_ip; /* we communicate with a remote site specified with pure IPv6
578 IP address */
579 bool ipv6; /* we communicate with a site using an IPv6 address */
581 bool do_more; /* this is set TRUE if the ->curl_do_more() function is
582 supposed to be called, after ->curl_do() */
584 bool tcpconnect; /* the TCP layer (or simimlar) is connected, this is set
585 the first time on the first connect function call */
586 bool protoconnstart;/* the protocol layer has STARTED its operation after
587 the TCP layer connect */
589 bool retry; /* this connection is about to get closed and then
590 re-attempted at another connection. */
591 bool tunnel_proxy; /* if CONNECT is used to "tunnel" through the proxy.
592 This is implicit when SSL-protocols are used through
593 proxies, but can also be enabled explicitly by
594 apps */
595 bool tunnel_connecting; /* TRUE while we're still waiting for a proxy CONNECT
597 bool authneg; /* TRUE when the auth phase has started, which means
598 that we are creating a request with an auth header,
599 but it is not the final request in the auth
600 negotiation. */
601 bool rewindaftersend;/* TRUE when the sending couldn't be stopped even
602 though it will be discarded. When the whole send
603 operation is done, we must call the data rewind
604 callback. */
605 bool ftp_use_epsv; /* As set with CURLOPT_FTP_USE_EPSV, but if we find out
606 EPSV doesn't work we disable it for the forthcoming
607 requests */
609 bool ftp_use_eprt; /* As set with CURLOPT_FTP_USE_EPRT, but if we find out
610 EPRT doesn't work we disable it for the forthcoming
611 requests */
612 bool netrc; /* name+password provided by netrc */
614 bool done; /* set to FALSE when Curl_do() is called and set to TRUE
615 when Curl_done() is called, to prevent Curl_done() to
616 get invoked twice when the multi interface is
617 used. */
618 bool stream_was_rewound; /* Indicates that the stream was rewound after a
619 request read past the end of its response byte
620 boundary */
621 bool proxy_connect_closed; /* set true if a proxy disconnected the
622 connection in a CONNECT request with auth, so
623 that libcurl should reconnect and continue. */
624 bool bound; /* set true if bind() has already been done on this socket/
625 connection */
628 struct hostname {
629 char *rawalloc; /* allocated "raw" version of the name */
630 char *encalloc; /* allocated IDN-encoded version of the name */
631 char *name; /* name to use internally, might be encoded, might be raw */
632 char *dispname; /* name to display, as 'name' might be encoded */
636 * Flags on the keepon member of the Curl_transfer_keeper
639 #define KEEP_NONE 0
640 #define KEEP_READ (1<<0) /* there is or may be data to read */
641 #define KEEP_WRITE (1<<1) /* there is or may be data to write */
642 #define KEEP_READ_HOLD (1<<2) /* when set, no reading should be done but there
643 might still be data to read */
644 #define KEEP_WRITE_HOLD (1<<3) /* when set, no writing should be done but there
645 might still be data to write */
646 #define KEEP_READ_PAUSE (1<<4) /* reading is paused */
647 #define KEEP_WRITE_PAUSE (1<<5) /* writing is paused */
649 #define KEEP_READBITS (KEEP_READ | KEEP_READ_HOLD | KEEP_READ_PAUSE)
650 #define KEEP_WRITEBITS (KEEP_WRITE | KEEP_WRITE_HOLD | KEEP_WRITE_PAUSE)
653 #ifdef HAVE_LIBZ
654 typedef enum {
655 ZLIB_UNINIT, /* uninitialized */
656 ZLIB_INIT, /* initialized */
657 ZLIB_GZIP_HEADER, /* reading gzip header */
658 ZLIB_GZIP_INFLATING, /* inflating gzip stream */
659 ZLIB_INIT_GZIP /* initialized in transparent gzip mode */
660 } zlibInitState;
661 #endif
663 #if defined(USE_ARES) || defined(USE_THREADING_GETHOSTBYNAME) || \
664 defined(USE_THREADING_GETADDRINFO)
665 struct Curl_async {
666 char *hostname;
667 int port;
668 struct Curl_dns_entry *dns;
669 bool done; /* set TRUE when the lookup is complete */
670 int status; /* if done is TRUE, this is the status from the callback */
671 void *os_specific; /* 'struct thread_data' for Windows */
673 #endif
675 #define FIRSTSOCKET 0
676 #define SECONDARYSOCKET 1
678 /* These function pointer types are here only to allow easier typecasting
679 within the source when we need to cast between data pointers (such as NULL)
680 and function pointers. */
681 typedef CURLcode (*Curl_do_more_func)(struct connectdata *);
682 typedef CURLcode (*Curl_done_func)(struct connectdata *, CURLcode, bool);
685 enum expect100 {
686 EXP100_SEND_DATA, /* enough waiting, just send the body now */
687 EXP100_AWAITING_CONTINUE, /* waiting for the 100 Continue header */
688 EXP100_SENDING_REQUEST, /* still sending the request but will wait for
689 the 100 header once done with the request */
690 EXP100_FAILED /* used on 417 Expectation Failed */
694 * Request specific data in the easy handle (SessionHandle). Previously,
695 * these members were on the connectdata struct but since a conn struct may
696 * now be shared between different SessionHandles, we store connection-specifc
697 * data here. This struct only keeps stuff that's interesting for *this*
698 * request, as it will be cleared between multiple ones
700 struct SingleRequest {
701 curl_off_t size; /* -1 if unknown at this point */
702 curl_off_t *bytecountp; /* return number of bytes read or NULL */
704 curl_off_t maxdownload; /* in bytes, the maximum amount of data to fetch,
705 -1 means unlimited */
706 curl_off_t *writebytecountp; /* return number of bytes written or NULL */
708 curl_off_t bytecount; /* total number of bytes read */
709 curl_off_t writebytecount; /* number of bytes written */
711 long headerbytecount; /* only count received headers */
712 long deductheadercount; /* this amount of bytes doesn't count when we check
713 if anything has been transfered at the end of a
714 connection. We use this counter to make only a
715 100 reply (without a following second response
716 code) result in a CURLE_GOT_NOTHING error code */
718 struct timeval start; /* transfer started at this time */
719 struct timeval now; /* current time */
720 bool header; /* incoming data has HTTP header */
721 enum {
722 HEADER_NORMAL, /* no bad header at all */
723 HEADER_PARTHEADER, /* part of the chunk is a bad header, the rest
724 is normal data */
725 HEADER_ALLBAD /* all was believed to be header */
726 } badheader; /* the header was deemed bad and will be
727 written as body */
728 int headerline; /* counts header lines to better track the
729 first one */
730 char *hbufp; /* points at *end* of header line */
731 size_t hbuflen;
732 char *str; /* within buf */
733 char *str_start; /* within buf */
734 char *end_ptr; /* within buf */
735 char *p; /* within headerbuff */
736 bool content_range; /* set TRUE if Content-Range: was found */
737 curl_off_t offset; /* possible resume offset read from the
738 Content-Range: header */
739 int httpcode; /* error code from the 'HTTP/1.? XXX' line */
740 int httpversion; /* the HTTP version*10 */
741 struct timeval start100; /* time stamp to wait for the 100 code from */
742 enum expect100 exp100; /* expect 100 continue state */
744 int content_encoding; /* What content encoding. sec 3.5, RFC2616. */
746 #define IDENTITY 0 /* No encoding */
747 #define DEFLATE 1 /* zlib delfate [RFC 1950 & 1951] */
748 #define GZIP 2 /* gzip algorithm [RFC 1952] */
749 #define COMPRESS 3 /* Not handled, added for completeness */
751 #ifdef HAVE_LIBZ
752 zlibInitState zlib_init; /* possible zlib init state;
753 undefined if Content-Encoding header. */
754 z_stream z; /* State structure for zlib. */
755 #endif
757 time_t timeofdoc;
758 long bodywrites;
760 char *buf;
761 char *uploadbuf;
762 curl_socket_t maxfd;
764 int keepon;
766 bool upload_done; /* set to TRUE when doing chunked transfer-encoding upload
767 and we're uploading the last chunk */
769 bool ignorebody; /* we read a response-body but we ignore it! */
770 bool ignorecl; /* This HTTP response has no body so we ignore the Content-
771 Length: header */
773 char *location; /* This points to an allocated version of the Location:
774 header data */
775 char *newurl; /* Set to the new URL to use when a redirect or a retry is
776 wanted */
778 /* 'upload_present' is used to keep a byte counter of how much data there is
779 still left in the buffer, aimed for upload. */
780 ssize_t upload_present;
782 /* 'upload_fromhere' is used as a read-pointer when we uploaded parts of a
783 buffer, so the next read should read from where this pointer points to,
784 and the 'upload_present' contains the number of bytes available at this
785 position */
786 char *upload_fromhere;
788 bool chunk; /* if set, this is a chunked transfer-encoding */
789 bool upload_chunky; /* set TRUE if we are doing chunked transfer-encoding
790 on upload */
791 bool getheader; /* TRUE if header parsing is wanted */
793 bool forbidchunk; /* used only to explicitly forbid chunk-upload for
794 specific upload buffers. See readmoredata() in
795 http.c for details. */
796 bool trailerhdrpresent; /* Set when Trailer: header found in HTTP response.
797 Required to determine whether to look for trailers
798 in case of Transfer-Encoding: chunking */
802 * Specific protocol handler.
805 struct Curl_handler {
806 const char * scheme; /* URL scheme name. */
808 /* Complement to setup_connection_internals(). */
809 CURLcode (*setup_connection)(struct connectdata *);
811 /* These two functions MUST be set to be protocol dependent */
812 CURLcode (*do_it)(struct connectdata *, bool *done);
813 Curl_done_func done;
815 /* If the curl_do() function is better made in two halves, this
816 * curl_do_more() function will be called afterwards, if set. For example
817 * for doing the FTP stuff after the PASV/PORT command.
819 Curl_do_more_func do_more;
821 /* This function *MAY* be set to a protocol-dependent function that is run
822 * after the connect() and everything is done, as a step in the connection.
823 * The 'done' pointer points to a bool that should be set to TRUE if the
824 * function completes before return. If it doesn't complete, the caller
825 * should call the curl_connecting() function until it is.
827 CURLcode (*connect_it)(struct connectdata *, bool *done);
829 /* See above. Currently only used for FTP. */
830 CURLcode (*connecting)(struct connectdata *, bool *done);
831 CURLcode (*doing)(struct connectdata *, bool *done);
833 /* Called from the multi interface during the PROTOCONNECT phase, and it
834 should then return a proper fd set */
835 int (*proto_getsock)(struct connectdata *conn,
836 curl_socket_t *socks,
837 int numsocks);
839 /* Called from the multi interface during the DOING phase, and it should
840 then return a proper fd set */
841 int (*doing_getsock)(struct connectdata *conn,
842 curl_socket_t *socks,
843 int numsocks);
845 /* This function *MAY* be set to a protocol-dependent function that is run
846 * by the curl_disconnect(), as a step in the disconnection.
848 CURLcode (*disconnect)(struct connectdata *);
850 long defport; /* Default port. */
851 long protocol; /* PROT_* flags concerning the protocol set */
855 * The connectdata struct contains all fields and variables that should be
856 * unique for an entire connection.
858 struct connectdata {
859 /* 'data' is the CURRENT SessionHandle using this connection -- take great
860 caution that this might very well vary between different times this
861 connection is used! */
862 struct SessionHandle *data;
864 /* chunk is for HTTP chunked encoding, but is in the general connectdata
865 struct only because we can do just about any protocol through a HTTP proxy
866 and a HTTP proxy may in fact respond using chunked encoding */
867 struct Curl_chunker chunk;
869 bool inuse; /* This is a marker for the connection cache logic. If this is
870 TRUE this handle is being used by an easy handle and cannot
871 be used by any other easy handle without careful
872 consideration (== only for pipelining). */
874 /**** Fields set when inited and not modified again */
875 long connectindex; /* what index in the connection cache connects index this
876 particular struct has */
877 long protocol; /* PROT_* flags concerning the protocol set */
878 #define PROT_MISSING (1<<0)
879 #define PROT_HTTP (1<<2)
880 #define PROT_HTTPS (1<<3)
881 #define PROT_FTP (1<<4)
882 #define PROT_TELNET (1<<5)
883 #define PROT_DICT (1<<6)
884 #define PROT_LDAP (1<<7)
885 #define PROT_FILE (1<<8)
886 #define PROT_FTPS (1<<9)
887 #define PROT_SSL (1<<10) /* protocol requires SSL */
888 #define PROT_TFTP (1<<11)
889 #define PROT_SCP (1<<12)
890 #define PROT_SFTP (1<<13)
892 #define PROT_CLOSEACTION PROT_FTP /* these ones need action before socket
893 close */
895 /* 'dns_entry' is the particular host we use. This points to an entry in the
896 DNS cache and it will not get pruned while locked. It gets unlocked in
897 Curl_done(). This entry will be NULL if the connection is re-used as then
898 there is no name resolve done. */
899 struct Curl_dns_entry *dns_entry;
901 /* 'ip_addr' is the particular IP we connected to. It points to a struct
902 within the DNS cache, so this pointer is only valid as long as the DNS
903 cache entry remains locked. It gets unlocked in Curl_done() */
904 Curl_addrinfo *ip_addr;
906 /* 'ip_addr_str' is the ip_addr data as a human readable malloc()ed string.
907 It remains available as long as the connection does, which is longer than
908 the ip_addr itself. Set with Curl_store_ip_addr() when ip_addr has been
909 set. */
910 char *ip_addr_str;
912 unsigned int scope; /* address scope for IPv6 */
914 char protostr[16]; /* store the protocol string in this buffer */
915 int socktype; /* SOCK_STREAM or SOCK_DGRAM */
917 struct hostname host;
918 struct hostname proxy;
920 long port; /* which port to use locally */
921 unsigned short remote_port; /* what remote port to connect to,
922 not the proxy port! */
924 char *user; /* user name string, allocated */
925 char *passwd; /* password string, allocated */
927 char *proxyuser; /* proxy user name string, allocated */
928 char *proxypasswd; /* proxy password string, allocated */
929 curl_proxytype proxytype; /* what kind of proxy that is in use */
931 struct timeval now; /* "current" time */
932 struct timeval created; /* creation time */
933 curl_socket_t sock[2]; /* two sockets, the second is used for the data
934 transfer when doing FTP */
936 struct ssl_connect_data ssl[2]; /* this is for ssl-stuff */
937 struct ssl_config_data ssl_config;
939 struct ConnectBits bits; /* various state-flags for this connection */
941 const struct Curl_handler * handler; /* Connection's protocol handler. */
943 /**** curl_get() phase fields */
945 curl_socket_t sockfd; /* socket to read from or CURL_SOCKET_BAD */
946 curl_socket_t writesockfd; /* socket to write to, it may very
947 well be the same we read from.
948 CURL_SOCKET_BAD disables */
950 /** Dynamicly allocated strings, may need to be freed before this **/
951 /** struct is killed. **/
952 struct dynamically_allocated_data {
953 char *proxyuserpwd; /* free later if not NULL! */
954 char *uagent; /* free later if not NULL! */
955 char *accept_encoding; /* free later if not NULL! */
956 char *userpwd; /* free later if not NULL! */
957 char *rangeline; /* free later if not NULL! */
958 char *ref; /* free later if not NULL! */
959 char *host; /* free later if not NULL */
960 char *cookiehost; /* free later if not NULL */
961 } allocptr;
963 int sec_complete; /* if kerberos is enabled for this connection */
964 #if defined(HAVE_KRB4) || defined(HAVE_GSSAPI)
965 enum protection_level command_prot;
966 enum protection_level data_prot;
967 enum protection_level request_data_prot;
968 size_t buffer_size;
969 struct krb4buffer in_buffer, out_buffer;
970 void *app_data;
971 const struct Curl_sec_client_mech *mech;
972 struct sockaddr_in local_addr;
973 #endif
975 bool readchannel_inuse; /* whether the read channel is in use by an easy
976 handle */
977 bool writechannel_inuse; /* whether the write channel is in use by an easy
978 handle */
979 bool server_supports_pipelining; /* TRUE if server supports pipelining,
980 set after first response */
982 struct curl_llist *send_pipe; /* List of handles waiting to
983 send on this pipeline */
984 struct curl_llist *recv_pipe; /* List of handles waiting to read
985 their responses on this pipeline */
986 struct curl_llist *pend_pipe; /* List of pending handles on
987 this pipeline */
988 #define MAX_PIPELINE_LENGTH 5
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?? */
996 curl_seek_callback seek_func; /* function that seeks the input */
997 void *seek_client; /* pointer to pass to the seek() above */
999 /*************** Request - specific items ************/
1001 /* previously this was in the urldata struct */
1002 curl_read_callback fread_func; /* function that reads the input */
1003 void *fread_in; /* pointer to pass to the fread() above */
1005 struct ntlmdata ntlm; /* NTLM differs from other authentication schemes
1006 because it authenticates connections, not
1007 single requests! */
1008 struct ntlmdata proxyntlm; /* NTLM data for proxy */
1010 char syserr_buf [256]; /* buffer for Curl_strerror() */
1012 #if defined(USE_ARES) || defined(USE_THREADING_GETHOSTBYNAME) || \
1013 defined(USE_THREADING_GETADDRINFO)
1014 /* data used for the asynch name resolve callback */
1015 struct Curl_async async;
1016 #endif
1018 /* These three are used for chunked-encoding trailer support */
1019 char *trailer; /* allocated buffer to store trailer in */
1020 int trlMax; /* allocated buffer size */
1021 int trlPos; /* index of where to store data */
1023 union {
1024 struct ftp_conn ftpc;
1025 struct ssh_conn sshc;
1026 } proto;
1028 int cselect_bits; /* bitmask of socket events */
1031 /* The end of connectdata. */
1034 * Struct to keep statistical and informational data.
1036 struct PureInfo {
1037 int httpcode; /* Recent HTTP or FTP response code */
1038 int httpproxycode; /* response code from proxy when received separate */
1039 int httpversion; /* the http version number X.Y = X*10+Y */
1040 long filetime; /* If requested, this is might get set. Set to -1 if the time
1041 was unretrievable. We cannot have this of type time_t,
1042 since time_t is unsigned on several platforms such as
1043 OpenVMS. */
1044 long header_size; /* size of read header(s) in bytes */
1045 long request_size; /* the amount of bytes sent in the request(s) */
1046 long proxyauthavail; /* what proxy auth types were announced */
1047 long httpauthavail; /* what host auth types were announced */
1048 long numconnects; /* how many new connection did libcurl created */
1049 char *contenttype; /* the content type of the object */
1050 char *wouldredirect; /* URL this would've been redirected to if asked to */
1051 char ip[MAX_IPADR_LEN]; /* this buffer gets the numerical ip version stored
1052 at the connect *attempt* so it will get the last
1053 tried connect IP even on failures */
1057 struct Progress {
1058 long lastshow; /* time() of the last displayed progress meter or NULL to
1059 force redraw at next call */
1060 curl_off_t size_dl; /* total expected size */
1061 curl_off_t size_ul; /* total expected size */
1062 curl_off_t downloaded; /* transfered so far */
1063 curl_off_t uploaded; /* transfered so far */
1065 curl_off_t current_speed; /* uses the currently fastest transfer */
1067 bool callback; /* set when progress callback is used */
1068 int width; /* screen width at download start */
1069 int flags; /* see progress.h */
1071 double timespent;
1073 curl_off_t dlspeed;
1074 curl_off_t ulspeed;
1076 double t_nslookup;
1077 double t_connect;
1078 double t_appconnect;
1079 double t_pretransfer;
1080 double t_starttransfer;
1081 double t_redirect;
1083 struct timeval start;
1084 struct timeval t_startsingle;
1085 #define CURR_TIME (5+1) /* 6 entries for 5 seconds */
1087 curl_off_t speeder[ CURR_TIME ];
1088 struct timeval speeder_time[ CURR_TIME ];
1089 int speeder_c;
1092 typedef enum {
1093 HTTPREQ_NONE, /* first in list */
1094 HTTPREQ_GET,
1095 HTTPREQ_POST,
1096 HTTPREQ_POST_FORM, /* we make a difference internally */
1097 HTTPREQ_PUT,
1098 HTTPREQ_HEAD,
1099 HTTPREQ_CUSTOM,
1100 HTTPREQ_LAST /* last in list */
1101 } Curl_HttpReq;
1104 * Values that are generated, temporary or calculated internally for a
1105 * "session handle" must be defined within the 'struct UrlState'. This struct
1106 * will be used within the SessionHandle struct. When the 'SessionHandle'
1107 * struct is cloned, this data MUST NOT be copied.
1109 * Remember that any "state" information goes globally for the curl handle.
1110 * Session-data MUST be put in the connectdata struct and here. */
1111 #define MAX_CURL_USER_LENGTH 256
1112 #define MAX_CURL_PASSWORD_LENGTH 256
1113 #define MAX_CURL_USER_LENGTH_TXT "255"
1114 #define MAX_CURL_PASSWORD_LENGTH_TXT "255"
1116 struct auth {
1117 long want; /* Bitmask set to the authentication methods wanted by the app
1118 (with CURLOPT_HTTPAUTH or CURLOPT_PROXYAUTH). */
1119 long picked;
1120 long avail; /* bitmask for what the server reports to support for this
1121 resource */
1122 bool done; /* TRUE when the auth phase is done and ready to do the *actual*
1123 request */
1124 bool multi; /* TRUE if this is not yet authenticated but within the auth
1125 multipass negotiation */
1129 struct conncache {
1130 /* 'connects' will be an allocated array with pointers. If the pointer is
1131 set, it holds an allocated connection. */
1132 struct connectdata **connects;
1133 long num; /* number of entries of the 'connects' array */
1134 enum {
1135 CONNCACHE_PRIVATE, /* used for an easy handle alone */
1136 CONNCACHE_MULTI /* shared within a multi handle */
1137 } type;
1141 struct UrlState {
1142 enum {
1143 Curl_if_none,
1144 Curl_if_easy,
1145 Curl_if_multi
1146 } used_interface;
1148 struct conncache *connc; /* points to the connection cache this handle
1149 uses */
1151 /* buffers to store authentication data in, as parsed from input options */
1152 struct timeval keeps_speed; /* for the progress meter really */
1154 long lastconnect; /* index of most recent connect or -1 if undefined */
1156 char *headerbuff; /* allocated buffer to store headers in */
1157 size_t headersize; /* size of the allocation */
1159 char buffer[BUFSIZE+1]; /* download buffer */
1160 char uploadbuffer[BUFSIZE+1]; /* upload buffer */
1161 curl_off_t current_speed; /* the ProgressShow() funcion sets this,
1162 bytes / second */
1163 bool this_is_a_follow; /* this is a followed Location: request */
1165 char *first_host; /* if set, this should be the host name that we will
1166 sent authorization to, no else. Used to make Location:
1167 following not keep sending user+password... This is
1168 strdup() data.
1170 struct curl_ssl_session *session; /* array of 'numsessions' size */
1171 long sessionage; /* number of the most recent session */
1172 char *tempwrite; /* allocated buffer to keep data in when a write
1173 callback returns to make the connection paused */
1174 size_t tempwritesize; /* size of the 'tempwrite' allocated buffer */
1175 int tempwritetype; /* type of the 'tempwrite' buffer as a bitmask that is
1176 used with Curl_client_write() */
1177 char *scratch; /* huge buffer[BUFSIZE*2] when doing upload CRLF replacing */
1178 bool errorbuf; /* Set to TRUE if the error buffer is already filled in.
1179 This must be set to FALSE every time _easy_perform() is
1180 called. */
1181 int os_errno; /* filled in with errno whenever an error occurs */
1182 #ifdef HAVE_SIGNAL
1183 /* storage for the previous bag^H^H^HSIGPIPE signal handler :-) */
1184 void (*prev_signal)(int sig);
1185 #endif
1186 bool allow_port; /* Is set.use_port allowed to take effect or not. This
1187 is always set TRUE when curl_easy_perform() is called. */
1188 struct digestdata digest; /* state data for host Digest auth */
1189 struct digestdata proxydigest; /* state data for proxy Digest auth */
1191 #ifdef HAVE_GSSAPI
1192 struct negotiatedata negotiate; /* state data for host Negotiate auth */
1193 struct negotiatedata proxyneg; /* state data for proxy Negotiate auth */
1194 #endif
1196 struct auth authhost; /* auth details for host */
1197 struct auth authproxy; /* auth details for proxy */
1199 bool authproblem; /* TRUE if there's some problem authenticating */
1201 #ifdef USE_ARES
1202 ares_channel areschannel; /* for name resolves */
1203 #endif
1205 #if defined(USE_SSLEAY) && defined(HAVE_OPENSSL_ENGINE_H)
1206 ENGINE *engine;
1207 #endif /* USE_SSLEAY */
1208 struct timeval expiretime; /* set this with Curl_expire() only */
1209 struct Curl_tree timenode; /* for the splay stuff */
1211 /* a place to store the most recenlty set FTP entrypath */
1212 char *most_recent_ftp_entrypath;
1214 /* set after initial USER failure, to prevent an authentication loop */
1215 bool ftp_trying_alternative;
1217 bool expect100header; /* TRUE if we added Expect: 100-continue */
1219 bool pipe_broke; /* TRUE if the connection we were pipelined on broke
1220 and we need to restart from the beginning */
1222 #if !defined(WIN32) && !defined(MSDOS) && !defined(__EMX__) && \
1223 !defined(__SYMBIAN32__)
1224 /* do FTP line-end conversions on most platforms */
1225 #define CURL_DO_LINEEND_CONV
1226 /* for FTP downloads: track CRLF sequences that span blocks */
1227 bool prev_block_had_trailing_cr;
1228 /* for FTP downloads: how many CRLFs did we converted to LFs? */
1229 curl_off_t crlf_conversions;
1230 #endif
1231 /* If set to non-NULL, there's a connection in a shared connection cache
1232 that uses this handle so we can't kill this SessionHandle just yet but
1233 must keep it around and add it to the list of handles to kill once all
1234 its connections are gone */
1235 void *shared_conn;
1236 bool closed; /* set to TRUE when curl_easy_cleanup() has been called on this
1237 handle, but it is kept around as mentioned for
1238 shared_conn */
1239 char *pathbuffer;/* allocated buffer to store the URL's path part in */
1240 char *path; /* path to use, points to somewhere within the pathbuffer
1241 area */
1243 bool use_range;
1244 bool rangestringalloc; /* the range string is malloc()'ed */
1246 char *range; /* range, if used. See README for detailed specification on
1247 this syntax. */
1248 curl_off_t resume_from; /* continue [ftp] transfer from here */
1250 /* Protocol specific data.
1252 *************************************************************************
1253 * Note that this data will be REMOVED after each request, so anything that
1254 * should be kept/stored on a per-connection basis and thus live for the
1255 * next requst on the same connection MUST be put in the connectdata struct!
1256 *************************************************************************/
1257 union {
1258 struct HTTP *http;
1259 struct HTTP *https; /* alias, just for the sake of being more readable */
1260 struct FTP *ftp;
1261 void *tftp; /* private for tftp.c-eyes only */
1262 struct FILEPROTO *file;
1263 void *telnet; /* private for telnet.c-eyes only */
1264 void *generic;
1265 struct SSHPROTO *ssh;
1266 } proto;
1267 /* current user of this SessionHandle instance, or NULL */
1268 struct connectdata *current_conn;
1273 * This 'DynamicStatic' struct defines dynamic states that actually change
1274 * values in the 'UserDefined' area, which MUST be taken into consideration
1275 * if the UserDefined struct is cloned or similar. You can probably just
1276 * copy these, but each one indicate a special action on other data.
1279 struct DynamicStatic {
1280 char *url; /* work URL, copied from UserDefined */
1281 bool url_alloc; /* URL string is malloc()'ed */
1282 char *referer; /* referer string */
1283 bool referer_alloc; /* referer sting is malloc()ed */
1284 struct curl_slist *cookielist; /* list of cookie files set by
1285 curl_easy_setopt(COOKIEFILE) calls */
1289 * This 'UserDefined' struct must only contain data that is set once to go
1290 * for many (perhaps) independent connections. Values that are generated or
1291 * calculated internally for the "session handle" MUST be defined within the
1292 * 'struct UrlState' instead. The only exceptions MUST note the changes in
1293 * the 'DynamicStatic' struct.
1294 * Character pointer fields point to dynamic storage, unless otherwise stated.
1296 struct Curl_one_easy; /* declared and used only in multi.c */
1297 struct Curl_multi; /* declared and used only in multi.c */
1299 enum dupstring {
1300 STRING_CERT, /* client certificate file name */
1301 STRING_CERT_TYPE, /* format for certificate (default: PEM)*/
1302 STRING_COOKIE, /* HTTP cookie string to send */
1303 STRING_COOKIEJAR, /* dump all cookies to this file */
1304 STRING_CUSTOMREQUEST, /* HTTP/FTP request/method to use */
1305 STRING_DEVICE, /* local network interface/address to use */
1306 STRING_ENCODING, /* Accept-Encoding string */
1307 STRING_FTP_ACCOUNT, /* ftp account data */
1308 STRING_FTP_ALTERNATIVE_TO_USER, /* command to send if USER/PASS fails */
1309 STRING_FTPPORT, /* port to send with the FTP PORT command */
1310 STRING_KEY, /* private key file name */
1311 STRING_KEY_PASSWD, /* plain text private key password */
1312 STRING_KEY_TYPE, /* format for private key (default: PEM) */
1313 STRING_KRB_LEVEL, /* krb security level */
1314 STRING_NETRC_FILE, /* if not NULL, use this instead of trying to find
1315 $HOME/.netrc */
1316 STRING_COPYPOSTFIELDS, /* if POST, set the fields' values here */
1317 STRING_PROXY, /* proxy to use */
1318 STRING_PROXYUSERPWD, /* Proxy <user:password>, if used */
1319 STRING_SET_RANGE, /* range, if used */
1320 STRING_SET_REFERER, /* custom string for the HTTP referer field */
1321 STRING_SET_URL, /* what original URL to work on */
1322 STRING_SSH_PRIVATE_KEY, /* path to the private key file for auth */
1323 STRING_SSH_PUBLIC_KEY, /* path to the public key file for auth */
1324 STRING_SSL_CAPATH, /* CA directory name (doesn't work on windows) */
1325 STRING_SSL_CAFILE, /* certificate file to verify peer against */
1326 STRING_SSL_CIPHER_LIST, /* list of ciphers to use */
1327 STRING_SSL_EGDSOCKET, /* path to file containing the EGD daemon socket */
1328 STRING_SSL_RANDOM_FILE, /* path to file containing "random" data */
1329 STRING_USERAGENT, /* User-Agent string */
1330 STRING_USERPWD, /* <user:password>, if used */
1331 STRING_SSH_HOST_PUBLIC_KEY_MD5, /* md5 of host public key in ascii hex */
1332 STRING_SSL_CRLFILE, /* crl file to check certificate */
1333 STRING_SSL_ISSUERCERT, /* issuer cert file to check certificate */
1335 /* -- end of strings -- */
1336 STRING_LAST /* not used, just an end-of-list marker */
1339 struct UserDefined {
1340 FILE *err; /* the stderr user data goes here */
1341 void *debugdata; /* the data that will be passed to fdebug */
1342 char *errorbuffer; /* (Static) store failure messages in here */
1343 long proxyport; /* If non-zero, use this port number by default. If the
1344 proxy string features a ":[port]" that one will override
1345 this. */
1346 void *out; /* the fetched file goes here */
1347 void *in; /* the uploaded file is read from here */
1348 void *writeheader; /* write the header to this if non-NULL */
1349 long use_port; /* which port to use (when not using default) */
1350 long httpauth; /* what kind of HTTP authentication to use (bitmask) */
1351 long proxyauth; /* what kind of proxy authentication to use (bitmask) */
1352 long followlocation; /* as in HTTP Location: */
1353 long maxredirs; /* maximum no. of http(s) redirects to follow, set to -1
1354 for infinity */
1355 bool post301; /* Obey RFC 2616/10.3.2 and keep POSTs as POSTs after a
1356 301 */
1357 bool free_referer; /* set TRUE if 'referer' points to a string we
1358 allocated */
1359 void *postfields; /* if POST, set the fields' values here */
1360 curl_seek_callback seek_func; /* function that seeks the input */
1361 curl_off_t postfieldsize; /* if POST, this might have a size to use instead
1362 of strlen(), and then the data *may* be binary
1363 (contain zero bytes) */
1364 unsigned short localport; /* local port number to bind to */
1365 int localportrange; /* number of additional port numbers to test in case the
1366 'localport' one can't be bind()ed */
1367 curl_write_callback fwrite_func; /* function that stores the output */
1368 curl_write_callback fwrite_header; /* function that stores headers */
1369 curl_read_callback fread_func; /* function that reads the input */
1370 curl_progress_callback fprogress; /* function for progress information */
1371 curl_debug_callback fdebug; /* function that write informational data */
1372 curl_ioctl_callback ioctl_func; /* function for I/O control */
1373 curl_sockopt_callback fsockopt; /* function for setting socket options */
1374 void *sockopt_client; /* pointer to pass to the socket options callback */
1375 curl_opensocket_callback fopensocket; /* function for checking/translating
1376 the address and opening the socket */
1377 void* opensocket_client;
1379 void *seek_client; /* pointer to pass to the seek callback */
1380 /* the 3 curl_conv_callback functions below are used on non-ASCII hosts */
1381 /* function to convert from the network encoding: */
1382 curl_conv_callback convfromnetwork;
1383 /* function to convert to the network encoding: */
1384 curl_conv_callback convtonetwork;
1385 /* function to convert from UTF-8 encoding: */
1386 curl_conv_callback convfromutf8;
1388 void *progress_client; /* pointer to pass to the progress callback */
1389 void *ioctl_client; /* pointer to pass to the ioctl callback */
1390 long timeout; /* in milliseconds, 0 means no timeout */
1391 long connecttimeout; /* in milliseconds, 0 means no timeout */
1392 long ftp_response_timeout; /* in milliseconds, 0 means no timeout */
1393 curl_off_t infilesize; /* size of file to upload, -1 means unknown */
1394 long low_speed_limit; /* bytes/second */
1395 long low_speed_time; /* number of seconds */
1396 curl_off_t max_send_speed; /* high speed limit in bytes/second for upload */
1397 curl_off_t max_recv_speed; /* high speed limit in bytes/second for download */
1398 curl_off_t set_resume_from; /* continue [ftp] transfer from here */
1399 struct curl_slist *headers; /* linked list of extra headers */
1400 struct curl_httppost *httppost; /* linked list of POST data */
1401 bool cookiesession; /* new cookie session? */
1402 bool crlf; /* convert crlf on ftp upload(?) */
1403 struct curl_slist *quote; /* after connection is established */
1404 struct curl_slist *postquote; /* after the transfer */
1405 struct curl_slist *prequote; /* before the transfer, after type */
1406 struct curl_slist *source_quote; /* 3rd party quote */
1407 struct curl_slist *source_prequote; /* in 3rd party transfer mode - before
1408 the transfer on source host */
1409 struct curl_slist *source_postquote; /* in 3rd party transfer mode - after
1410 the transfer on source host */
1411 struct curl_slist *telnet_options; /* linked list of telnet options */
1412 curl_TimeCond timecondition; /* kind of time/date comparison */
1413 time_t timevalue; /* what time to compare with */
1414 Curl_HttpReq httpreq; /* what kind of HTTP request (if any) is this */
1415 long httpversion; /* when non-zero, a specific HTTP version requested to
1416 be used in the library's request(s) */
1417 struct ssl_config_data ssl; /* user defined SSL stuff */
1418 curl_proxytype proxytype; /* what kind of proxy that is in use */
1419 long dns_cache_timeout; /* DNS cache timeout */
1420 long buffer_size; /* size of receive buffer to use */
1421 void *private_data; /* application-private data */
1423 struct Curl_one_easy *one_easy; /* When adding an easy handle to a multi
1424 handle, an internal 'Curl_one_easy'
1425 struct is created and this is a pointer
1426 to the particular struct associated with
1427 this SessionHandle */
1429 struct curl_slist *http200aliases; /* linked list of aliases for http200 */
1431 long ip_version; /* the CURL_IPRESOLVE_* defines in the public header file
1432 0 - whatever, 1 - v2, 2 - v6 */
1434 curl_off_t max_filesize; /* Maximum file size to download */
1436 curl_ftpfile ftp_filemethod; /* how to get to a file when FTP is used */
1438 /* Here follows boolean settings that define how to behave during
1439 this session. They are STATIC, set by libcurl users or at least initially
1440 and they don't change during operations. */
1442 bool printhost; /* printing host name in debug info */
1443 bool get_filetime; /* get the time and get of the remote file */
1444 bool tunnel_thru_httpproxy; /* use CONNECT through a HTTP proxy */
1445 bool prefer_ascii; /* ASCII rather than binary */
1446 bool ftp_append; /* append, not overwrite, on upload */
1447 bool ftp_list_only; /* switch FTP command for listing directories */
1448 bool ftp_create_missing_dirs; /* create directories that don't exist */
1449 bool ftp_use_port; /* use the FTP PORT command */
1450 bool hide_progress; /* don't use the progress meter */
1451 bool http_fail_on_error; /* fail on HTTP error codes >= 300 */
1452 bool http_follow_location; /* follow HTTP redirects */
1453 bool http_disable_hostname_check_before_authentication;
1454 bool include_header; /* include received protocol headers in data output */
1455 bool http_set_referer; /* is a custom referer used */
1456 bool http_auto_referer; /* set "correct" referer when following location: */
1457 bool opt_no_body; /* as set with CURLOPT_NO_BODY */
1458 bool set_port; /* custom port number used */
1459 bool upload; /* upload request */
1460 enum CURL_NETRC_OPTION
1461 use_netrc; /* defined in include/curl.h */
1462 bool verbose; /* output verbosity */
1463 bool krb; /* kerberos connection requested */
1464 bool reuse_forbid; /* forbidden to be reused, close after use */
1465 bool reuse_fresh; /* do not re-use an existing connection */
1466 bool ftp_use_epsv; /* if EPSV is to be attempted or not */
1467 bool ftp_use_eprt; /* if EPRT is to be attempted or not */
1469 curl_usessl ftp_ssl; /* if AUTH TLS is to be attempted etc */
1470 curl_ftpauth ftpsslauth; /* what AUTH XXX to be attempted */
1471 curl_ftpccc ftp_ccc; /* FTP CCC options */
1472 bool no_signal; /* do not use any signal/alarm handler */
1473 bool global_dns_cache; /* subject for future removal */
1474 bool tcp_nodelay; /* whether to enable TCP_NODELAY or not */
1475 bool ignorecl; /* ignore content length */
1476 bool ftp_skip_ip; /* skip the IP address the FTP server passes on to
1477 us */
1478 bool connect_only; /* make connection, let application use the socket */
1479 long ssh_auth_types; /* allowed SSH auth types */
1480 bool http_te_skip; /* pass the raw body data to the user, even when
1481 transfer-encoded (chunked, compressed) */
1482 bool http_ce_skip; /* pass the raw body data to the user, even when
1483 content-encoded (chunked, compressed) */
1484 long new_file_perms; /* Permissions to use when creating remote files */
1485 long new_directory_perms; /* Permissions to use when creating remote dirs */
1486 bool proxy_transfer_mode; /* set transfer mode (;type=<a|i>) when doing FTP
1487 via an HTTP proxy */
1488 char *str[STRING_LAST]; /* array of strings, pointing to allocated memory */
1489 unsigned int scope; /* address scope for IPv6 */
1492 struct Names {
1493 struct curl_hash *hostcache;
1494 enum {
1495 HCACHE_NONE, /* not pointing to anything */
1496 HCACHE_PRIVATE, /* points to our own */
1497 HCACHE_GLOBAL, /* points to the (shrug) global one */
1498 HCACHE_MULTI, /* points to a shared one in the multi handle */
1499 HCACHE_SHARED /* points to a shared one in a shared object */
1500 } hostcachetype;
1504 * The 'connectdata' struct MUST have all the connection oriented stuff as we
1505 * may have several simultaneous connections and connection structs in memory.
1507 * The 'struct UserDefined' must only contain data that is set once to go for
1508 * many (perhaps) independent connections. Values that are generated or
1509 * calculated internally for the "session handle" must be defined within the
1510 * 'struct UrlState' instead.
1513 struct SessionHandle {
1514 struct Names dns;
1515 struct Curl_multi *multi; /* if non-NULL, points to the multi handle
1516 struct to which this "belongs" */
1517 struct Curl_one_easy *multi_pos; /* if non-NULL, points to the its position
1518 in multi controlling structure to assist
1519 in removal. */
1520 struct Curl_share *share; /* Share, handles global variable mutexing */
1521 struct SingleRequest req; /* Request-specific data */
1522 struct UserDefined set; /* values set by the libcurl user */
1523 struct DynamicStatic change; /* possibly modified userdefined data */
1524 struct CookieInfo *cookies; /* the cookies, read from files and servers.
1525 NOTE that the 'cookie' field in the
1526 UserDefined struct defines if the "engine"
1527 is to be used or not. */
1528 struct Progress progress; /* for all the progress meter data */
1529 struct UrlState state; /* struct for fields used for state info and
1530 other dynamic purposes */
1531 struct PureInfo info; /* stats, reports and info data */
1532 #if defined(CURL_DOES_CONVERSIONS) && defined(HAVE_ICONV)
1533 iconv_t outbound_cd; /* for translating to the network encoding */
1534 iconv_t inbound_cd; /* for translating from the network encoding */
1535 iconv_t utf8_cd; /* for translating to UTF8 */
1536 #endif /* CURL_DOES_CONVERSIONS && HAVE_ICONV */
1537 unsigned int magic; /* set to a CURLEASY_MAGIC_NUMBER */
1540 #define LIBCURL_NAME "libcurl"
1542 #endif