3 /***************************************************************************
5 * Project ___| | | | _ \| |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 1998 - 2007, 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.2 2007/03/15 19:22:13 andy Exp $
24 ***************************************************************************/
26 /* This file is for lib internal stuff */
32 #define PORT_TELNET 23
34 #define PORT_HTTPS 443
35 #define PORT_DICT 2628
40 #define DICT_MATCH "/MATCH:"
41 #define DICT_MATCH2 "/M:"
42 #define DICT_MATCH3 "/FIND:"
43 #define DICT_DEFINE "/DEFINE:"
44 #define DICT_DEFINE2 "/D:"
45 #define DICT_DEFINE3 "/LOOKUP:"
47 #define CURL_DEFAULT_USER "anonymous"
48 #define CURL_DEFAULT_PASSWORD "curl_by_daniel@haxx.se"
55 #include "openssl/rsa.h"
56 #include "openssl/crypto.h"
57 #include "openssl/x509.h"
58 #include "openssl/pem.h"
59 #include "openssl/ssl.h"
60 #include "openssl/err.h"
61 #ifdef HAVE_OPENSSL_ENGINE_H
62 #include <openssl/engine.h>
64 #ifdef HAVE_OPENSSL_PKCS12_H
65 #include <openssl/pkcs12.h>
67 #else /* SSLeay-style includes */
74 #endif /* USE_OPENSSL */
75 #endif /* USE_SSLEAY */
78 #include <gnutls/gnutls.h>
81 #ifdef HAVE_NETINET_IN_H
82 #include <netinet/in.h>
88 #include <zlib.h> /* for content-encoding */
95 #include <curl/curl.h>
97 #include "http_chunks.h" /* for the structs and enum stuff */
105 # elif defined HAVE_GSSMIT
106 # include <gssapi/gssapi.h>
107 # include <gssapi/gssapi_generic.h>
113 #ifdef HAVE_LIBSSH2_H
115 #include <libssh2_sftp.h>
116 #endif /* HAVE_LIBSSH2_H */
118 /* Download buffer size, keep it fairly big for speed reasons */
120 #define BUFSIZE CURL_MAX_WRITE_SIZE
122 /* Initial size of the buffer to store headers in, it'll be enlarged in case
124 #define HEADERSIZE 256
126 #define CURLEASY_MAGIC_NUMBER 0xc0dedbad
128 /* Just a convenience macro to get the larger value out of two given.
129 We prefix with CURL to prevent name collisions. */
130 #define CURLMAX(x,y) ((x)>(y)?(x):(y))
133 /* Types needed for krb4-ftp connections */
140 enum protection_level
{
148 /* enum for the nonblocking SSL connection state machine */
152 ssl_connect_2_reading
,
153 ssl_connect_2_writing
,
158 /* struct for data related to each SSL connection */
159 struct ssl_connect_data
{
160 bool use
; /* use ssl encrypted communications TRUE/FALSE */
162 /* these ones requires specific SSL-types */
166 ssl_connect_state connecting_state
;
167 #endif /* USE_SSLEAY */
169 gnutls_session session
;
170 gnutls_certificate_credentials cred
;
171 #endif /* USE_GNUTLS */
174 struct ssl_config_data
{
175 long version
; /* what version the client wants to use */
176 long certverifyresult
; /* result from the certificate verification */
177 long verifypeer
; /* set TRUE if this is desired */
178 long verifyhost
; /* 0: no verify
179 1: check that CN exists
180 2: CN must match hostname */
181 char *CApath
; /* DOES NOT WORK ON WINDOWS */
182 char *CAfile
; /* cerficate to verify peer against */
183 char *random_file
; /* path to file containing "random" data */
184 char *egdsocket
; /* path to file containing the EGD daemon socket */
185 char *cipher_list
; /* list of ciphers to use */
186 long numsessions
; /* SSL session id cache size */
187 curl_ssl_ctx_callback fsslctx
; /* function to initialize ssl ctx */
188 void *fsslctxp
; /* parameter for call back */
189 bool sessionid
; /* cache session IDs or not */
192 /* information stored about one single SSL session */
193 struct curl_ssl_session
{
194 char *name
; /* host name for which this ID was used */
195 void *sessionid
; /* as returned from the SSL layer */
196 size_t idsize
; /* if known, otherwise 0 */
197 long age
; /* just a number, the higher the more recent */
198 unsigned short remote_port
; /* remote port to connect to */
199 struct ssl_config_data ssl_config
; /* setup for this session */
202 /* Struct used for Digest challenge-response authentication */
208 bool stale
; /* set true for re-negotiation */
212 int nc
; /* nounce count */
223 #ifdef USE_WINDOWS_SSPI
224 /* When including these headers, you must define either SECURITY_WIN32
225 * or SECURITY_KERNEL, indicating who is compiling the code.
227 #define SECURITY_WIN32 1
228 #include <security.h>
233 #if defined(CURL_DOES_CONVERSIONS) && defined(HAVE_ICONV)
237 /* Struct used for NTLM challenge-response authentication */
240 #ifdef USE_WINDOWS_SSPI
243 SEC_WINNT_AUTH_IDENTITY identity
;
244 SEC_WINNT_AUTH_IDENTITY
*p_identity
;
250 unsigned char nonce
[8];
255 struct negotiatedata
{
256 bool gss
; /* Whether we're processing GSS-Negotiate or Negotiate */
257 const char* protocol
; /* "GSS-Negotiate" or "Negotiate" */
259 gss_ctx_id_t context
;
260 gss_name_t server_name
;
261 gss_buffer_desc output_token
;
265 /****************************************************************************
267 ***************************************************************************/
269 struct FormData
*sendit
;
270 curl_off_t postsize
; /* off_t to handle large file sizes */
273 const char *p_pragma
; /* Pragma: string */
274 const char *p_accept
; /* Accept: string */
275 curl_off_t readbytecount
;
276 curl_off_t writebytecount
;
278 /* For FORM posting */
280 struct Curl_chunker chunk
;
283 curl_read_callback fread
; /* backup storage for fread pointer */
284 void *fread_in
; /* backup storage for fread_in pointer */
290 HTTPSEND_NADA
, /* init */
291 HTTPSEND_REQUEST
, /* sending a request */
292 HTTPSEND_BODY
, /* sending body */
293 HTTPSEND_LAST
/* never use this */
296 void *send_buffer
; /* used if the request couldn't be sent in one chunk,
297 points to an allocated send_buffer struct */
300 /****************************************************************************
302 ***************************************************************************/
304 FTP_STOP
, /* do nothing state, stops the state machine */
305 FTP_WAIT220
, /* waiting for the initial 220 response immediately after
315 FTP_QUOTE
, /* waiting for a response to a command sent in a quote list */
319 FTP_CWD
, /* change dir */
320 FTP_MKD
, /* if the dir didn't exist */
321 FTP_MDTM
, /* to figure out the datestamp */
322 FTP_TYPE
, /* to set type when doing a head-like request */
323 FTP_LIST_TYPE
, /* set type when about to do a dir list */
324 FTP_RETR_TYPE
, /* set type when about to RETR a file */
325 FTP_STOR_TYPE
, /* set type when about to STOR a file */
326 FTP_SIZE
, /* get the remote file's size for head-like request */
327 FTP_RETR_SIZE
, /* get the remote file's size for RETR */
328 FTP_STOR_SIZE
, /* get the size for (resumed) STOR */
329 FTP_REST
, /* when used to check if the server supports it in head-like */
330 FTP_RETR_REST
, /* when asking for "resume" in for RETR */
331 FTP_PORT
, /* generic state for PORT, LPRT and EPRT, check count1 */
332 FTP_PASV
, /* generic state for PASV and EPSV, check count1 */
333 FTP_LIST
, /* generic state for LIST, NLST or a custom list command */
335 FTP_STOR
, /* generic state for STOR and APPE */
337 FTP_LAST
/* never used */
341 FTPFILE_MULTICWD
= 1, /* as defined by RFC1738 */
342 FTPFILE_NOCWD
= 2, /* use SIZE / RETR / STOR on the full path */
343 FTPFILE_SINGLECWD
= 3 /* make one CWD, then SIZE / RETR / STOR on the file */
346 /* This FTP struct is used in the SessionHandle. All FTP data that is
347 connection-oriented must be in FTP_conn to properly deal with the fact that
348 perhaps the SessionHandle is changed between the times the connection is
351 curl_off_t
*bytecountp
;
352 char *user
; /* user name string */
353 char *passwd
; /* password string */
354 char *urlpath
; /* the originally given path part of the URL */
355 char *file
; /* decoded file */
356 bool no_transfer
; /* nothing was transfered, (possibly because a resumed
357 transfer already was complete) */
358 curl_off_t downloadsize
;
361 /* ftp_conn is used for striuct connection-oriented data in the connectdata
364 char *entrypath
; /* the PWD reply when we logged on */
365 char **dirs
; /* realloc()ed array for path components */
366 int dirdepth
; /* number of entries used in the 'dirs' array */
367 int diralloc
; /* number of entries allocated for the 'dirs' array */
368 char *cache
; /* data cache between getresponse()-calls */
369 curl_off_t cache_size
; /* size of cache in bytes */
370 bool dont_check
; /* Set to TRUE to prevent the final (post-transfer)
371 file size and 226/250 status check. It should still
372 read the line, just ignore the result. */
373 long response_time
; /* When no timeout is given, this is the amount of
374 seconds we await for an FTP response. Initialized
375 in Curl_ftp_connect() */
376 bool ctl_valid
; /* Tells Curl_ftp_quit() whether or not to do anything. If
377 the connection has timed out or been closed, this
378 should be FALSE when it gets to Curl_ftp_quit() */
379 bool cwddone
; /* if it has been determined that the proper CWD combo
380 already has been done */
381 bool cwdfail
; /* set TRUE if a CWD command fails, as then we must prevent
382 caching the current directory */
383 char *prevpath
; /* conn->path from the previous transfer */
384 char transfertype
; /* set by ftp_transfertype for use by Curl_client_write()a
385 and others (A/I or zero) */
386 size_t nread_resp
; /* number of bytes currently read of a server response */
387 char *linestart_resp
; /* line start pointer for the FTP server response
390 int count1
; /* general purpose counter for the state machine */
391 int count2
; /* general purpose counter for the state machine */
392 int count3
; /* general purpose counter for the state machine */
393 char *sendthis
; /* allocated pointer to a buffer that is to be sent to the
395 size_t sendleft
; /* number of bytes left to send from the sendthis buffer */
396 size_t sendsize
; /* total size of the sendthis buffer */
397 struct timeval response
; /* set to Curl_tvnow() when a command has been sent
398 off, used to time-out response reading */
399 ftpstate state
; /* always use ftp.c:state() to change state! */
403 curl_off_t
*bytecountp
;
406 char *path
; /* the path we operate on */
410 LIBSSH2_SESSION
*ssh_session
; /* Secure Shell session */
411 LIBSSH2_CHANNEL
*ssh_channel
; /* Secure Shell channel handle */
412 LIBSSH2_SFTP
*sftp_session
; /* SFTP handle */
413 LIBSSH2_SFTP_HANDLE
*sftp_handle
;
414 #endif /* USE_LIBSSH2 */
418 /****************************************************************************
420 ***************************************************************************/
422 char *path
; /* the path we operate on */
423 char *freepath
; /* pointer to the allocated block we must free, this might
424 differ from the 'path' pointer */
425 int fd
; /* open file descriptor to read from! */
429 * Boolean values that concerns this connection.
432 bool close
; /* if set, we close the connection after this request */
433 bool reuse
; /* if set, this is a re-used connection */
434 bool chunk
; /* if set, this is a chunked transfer-encoding */
435 bool httpproxy
; /* if set, this transfer is done through a http proxy */
436 bool user_passwd
; /* do we use user+password for this connection? */
437 bool proxy_user_passwd
; /* user+password for the proxy? */
438 bool ipv6_ip
; /* we communicate with a remote site specified with pure IPv6
440 bool ipv6
; /* we communicate with a site using an IPv6 address */
442 bool do_more
; /* this is set TRUE if the ->curl_do_more() function is
443 supposed to be called, after ->curl_do() */
445 bool upload_chunky
; /* set TRUE if we are doing chunked transfer-encoding
447 bool getheader
; /* TRUE if header parsing is wanted */
449 bool forbidchunk
; /* used only to explicitly forbid chunk-upload for
450 specific upload buffers. See readmoredata() in
451 http.c for details. */
453 bool tcpconnect
; /* the TCP layer (or simimlar) is connected, this is set
454 the first time on the first connect function call */
455 bool protoconnstart
;/* the protocol layer has STARTED its operation after
456 the TCP layer connect */
458 bool retry
; /* this connection is about to get closed and then
459 re-attempted at another connection. */
460 bool no_body
; /* CURLOPT_NO_BODY (or similar) was set */
461 bool tunnel_proxy
; /* if CONNECT is used to "tunnel" through the proxy.
462 This is implicit when SSL-protocols are used through
463 proxies, but can also be enabled explicitly by
465 bool authneg
; /* TRUE when the auth phase has started, which means
466 that we are creating a request with an auth header,
467 but it is not the final request in the auth
469 bool rewindaftersend
;/* TRUE when the sending couldn't be stopped even
470 though it will be discarded. When the whole send
471 operation is done, we must call the data rewind
473 bool ftp_use_epsv
; /* As set with CURLOPT_FTP_USE_EPSV, but if we find out
474 EPSV doesn't work we disable it for the forthcoming
477 bool ftp_use_eprt
; /* As set with CURLOPT_FTP_USE_EPRT, but if we find out
478 EPRT doesn't work we disable it for the forthcoming
480 bool netrc
; /* name+password provided by netrc */
482 bool trailerHdrPresent
; /* Set when Trailer: header found in HTTP response.
483 Required to determine whether to look for trailers
484 in case of Transfer-Encoding: chunking */
485 bool done
; /* set to FALSE when Curl_do() is called and set to TRUE
486 when Curl_done() is called, to prevent Curl_done() to
487 get invoked twice when the multi interface is
489 bool stream_was_rewound
; /* Indicates that the stream was rewound after a
490 request read past the end of its response byte
492 bool proxy_connect_closed
; /* set true if a proxy disconnected the
493 connection in a CONNECT request with auth, so
494 that libcurl should reconnect and continue. */
498 char *rawalloc
; /* allocated "raw" version of the name */
499 char *encalloc
; /* allocated IDN-encoded version of the name */
500 char *name
; /* name to use internally, might be encoded, might be raw */
501 char *dispname
; /* name to display, as 'name' might be encoded */
505 * Flags on the keepon member of the Curl_transfer_keeper
509 #define KEEP_READ 1 /* there is or may be data to read */
510 #define KEEP_WRITE 2 /* there is or may be data to write */
511 #define KEEP_READ_HOLD 4 /* when set, no reading should be done but there
512 might still be data to read */
513 #define KEEP_WRITE_HOLD 8 /* when set, no writing should be done but there
514 might still be data to write */
517 * This struct is all the previously local variables from Curl_perform() moved
518 * to struct to allow the function to return and get re-invoked better without
522 struct Curl_transfer_keeper
{
524 /** Values copied over from the HandleData struct each time on init **/
526 curl_off_t size
; /* -1 if unknown at this point */
527 curl_off_t
*bytecountp
; /* return number of bytes read or NULL */
529 curl_off_t maxdownload
; /* in bytes, the maximum amount of data to fetch, 0
531 curl_off_t
*writebytecountp
; /* return number of bytes written or NULL */
533 /** End of HandleData struct copies **/
535 curl_off_t bytecount
; /* total number of bytes read */
536 curl_off_t writebytecount
; /* number of bytes written */
538 struct timeval start
; /* transfer started at this time */
539 struct timeval now
; /* current time */
540 bool header
; /* incoming data has HTTP header */
542 HEADER_NORMAL
, /* no bad header at all */
543 HEADER_PARTHEADER
, /* part of the chunk is a bad header, the rest
545 HEADER_ALLBAD
/* all was believed to be header */
546 } badheader
; /* the header was deemed bad and will be
548 int headerline
; /* counts header lines to better track the
550 char *hbufp
; /* points at *end* of header line */
552 char *str
; /* within buf */
553 char *str_start
; /* within buf */
554 char *end_ptr
; /* within buf */
555 char *p
; /* within headerbuff */
556 bool content_range
; /* set TRUE if Content-Range: was found */
557 curl_off_t offset
; /* possible resume offset read from the
558 Content-Range: header */
559 int httpcode
; /* error code from the 'HTTP/1.? XXX' line */
560 int httpversion
; /* the HTTP version*10 */
561 struct timeval start100
; /* time stamp to wait for the 100 code from */
562 bool write_after_100_header
; /* TRUE = we enable the write after we
563 received a 100-continue/timeout or
565 bool wait100_after_headers
; /* TRUE = after the request-headers have been
566 sent off properly, we go into the wait100
567 state, FALSE = don't */
568 int content_encoding
; /* What content encoding. sec 3.5, RFC2616. */
570 #define IDENTITY 0 /* No encoding */
571 #define DEFLATE 1 /* zlib delfate [RFC 1950 & 1951] */
572 #define GZIP 2 /* gzip algorithm [RFC 1952] */
573 #define COMPRESS 3 /* Not handled, added for completeness */
576 bool zlib_init
; /* True if zlib already initialized;
577 undefined if Content-Encoding header. */
578 z_stream z
; /* State structure for zlib. */
590 bool upload_done
; /* set to TRUE when doing chunked transfer-encoding upload
591 and we're uploading the last chunk */
593 bool ignorebody
; /* we read a response-body but we ignore it! */
594 bool ignorecl
; /* This HTTP response has no body so we ignore the Content-
598 #if defined(USE_ARES) || defined(USE_THREADING_GETHOSTBYNAME) || \
599 defined(USE_THREADING_GETADDRINFO)
603 struct Curl_dns_entry
*dns
;
604 bool done
; /* set TRUE when the lookup is complete */
605 int status
; /* if done is TRUE, this is the status from the callback */
606 void *os_specific
; /* 'struct thread_data' for Windows */
610 #define FIRSTSOCKET 0
611 #define SECONDARYSOCKET 1
613 /* These function pointer types are here only to allow easier typecasting
614 within the source when we need to cast between data pointers (such as NULL)
615 and function pointers. */
616 typedef CURLcode (*Curl_do_more_func
)(struct connectdata
*);
617 typedef CURLcode (*Curl_done_func
)(struct connectdata
*, CURLcode
, bool);
621 * Store's request specific data in the easy handle (SessionHandle).
622 * Previously, these members were on the connectdata struct but since
623 * a conn struct may now be shared between different SessionHandles,
624 * we store connection-specifc data here.
628 char *pathbuffer
;/* allocated buffer to store the URL's path part in */
629 char *path
; /* path to use, points to somewhere within the pathbuffer
632 char *newurl
; /* This can only be set if a Location: was in the
635 /* This struct is inited when needed */
636 struct Curl_transfer_keeper keep
;
638 /* 'upload_present' is used to keep a byte counter of how much data there is
639 still left in the buffer, aimed for upload. */
640 ssize_t upload_present
;
642 /* 'upload_fromhere' is used as a read-pointer when we uploaded parts of a
643 buffer, so the next read should read from where this pointer points to,
644 and the 'upload_present' contains the number of bytes available at this
646 char *upload_fromhere
;
648 curl_off_t size
; /* -1 if unknown at this point */
649 curl_off_t
*bytecountp
; /* return number of bytes read or NULL */
651 curl_off_t maxdownload
; /* in bytes, the maximum amount of data to fetch, 0
653 curl_off_t
*writebytecountp
; /* return number of bytes written or NULL */
656 bool rangestringalloc
; /* the range string is malloc()'ed */
658 char *range
; /* range, if used. See README for detailed specification on
660 curl_off_t resume_from
; /* continue [ftp] transfer from here */
662 /* Protocol specific data */
666 struct HTTP
*https
; /* alias, just for the sake of being more readable */
668 void *tftp
; /* private for tftp.c-eyes only */
669 struct FILEPROTO
*file
;
670 void *telnet
; /* private for telnet.c-eyes only */
672 struct SSHPROTO
*ssh
;
677 * The connectdata struct contains all fields and variables that should be
678 * unique for an entire connection.
681 /* 'data' is the CURRENT SessionHandle using this connection -- take great
682 caution that this might very well vary between different times this
683 connection is used! */
684 struct SessionHandle
*data
;
686 bool inuse
; /* This is a marker for the connection cache logic. If this is
687 TRUE this handle is being used by an easy handle and cannot
688 be used by any other easy handle without careful
689 consideration (== only for pipelining). */
691 /**** Fields set when inited and not modified again */
692 long connectindex
; /* what index in the connection cache connects index this
693 particular struct has */
694 long protocol
; /* PROT_* flags concerning the protocol set */
695 #define PROT_MISSING (1<<0)
696 #define PROT_HTTP (1<<2)
697 #define PROT_HTTPS (1<<3)
698 #define PROT_FTP (1<<4)
699 #define PROT_TELNET (1<<5)
700 #define PROT_DICT (1<<6)
701 #define PROT_LDAP (1<<7)
702 #define PROT_FILE (1<<8)
703 #define PROT_FTPS (1<<9)
704 #define PROT_SSL (1<<10) /* protocol requires SSL */
705 #define PROT_TFTP (1<<11)
706 #define PROT_SCP (1<<12)
707 #define PROT_SFTP (1<<13)
709 #define PROT_CLOSEACTION PROT_FTP /* these ones need action before socket
712 /* 'dns_entry' is the particular host we use. This points to an entry in the
713 DNS cache and it will not get pruned while locked. It gets unlocked in
714 Curl_done(). This entry will be NULL if the connection is re-used as then
715 there is no name resolve done. */
716 struct Curl_dns_entry
*dns_entry
;
718 /* 'ip_addr' is the particular IP we connected to. It points to a struct
719 within the DNS cache, so this pointer is only valid as long as the DNS
720 cache entry remains locked. It gets unlocked in Curl_done() */
721 Curl_addrinfo
*ip_addr
;
723 /* 'ip_addr_str' is the ip_addr data as a human readable malloc()ed string.
724 It remains available as long as the connection does, which is longer than
725 the ip_addr itself. Set with Curl_store_ip_addr() when ip_addr has been
729 char protostr
[16]; /* store the protocol string in this buffer */
730 int socktype
; /* SOCK_STREAM or SOCK_DGRAM */
732 struct hostname host
;
733 struct hostname proxy
;
735 long port
; /* which port to use locally */
736 unsigned short remote_port
; /* what remote port to connect to,
737 not the proxy port! */
739 long headerbytecount
; /* only count received headers */
740 long deductheadercount
; /* this amount of bytes doesn't count when we check
741 if anything has been transfered at the end of
742 a connection. We use this counter to make only
743 a 100 reply (without a following second response
744 code) result in a CURLE_GOT_NOTHING error code */
746 char *user
; /* user name string, allocated */
747 char *passwd
; /* password string, allocated */
749 char *proxyuser
; /* proxy user name string, allocated */
750 char *proxypasswd
; /* proxy password string, allocated */
752 struct timeval now
; /* "current" time */
753 struct timeval created
; /* creation time */
754 curl_socket_t sock
[2]; /* two sockets, the second is used for the data
755 transfer when doing FTP */
757 struct ssl_connect_data ssl
[2]; /* this is for ssl-stuff */
758 struct ssl_config_data ssl_config
;
760 struct ConnectBits bits
; /* various state-flags for this connection */
762 /* These two functions MUST be set by the curl_connect() function to be
763 be protocol dependent */
764 CURLcode (*curl_do
)(struct connectdata
*, bool *done
);
765 Curl_done_func curl_done
;
767 /* If the curl_do() function is better made in two halves, this
768 * curl_do_more() function will be called afterwards, if set. For example
769 * for doing the FTP stuff after the PASV/PORT command.
771 Curl_do_more_func curl_do_more
;
773 /* This function *MAY* be set to a protocol-dependent function that is run
774 * after the connect() and everything is done, as a step in the connection.
775 * The 'done' pointer points to a bool that should be set to TRUE if the
776 * function completes before return. If it doesn't complete, the caller
777 * should call the curl_connecting() function until it is.
779 CURLcode (*curl_connect
)(struct connectdata
*, bool *done
);
781 /* See above. Currently only used for FTP. */
782 CURLcode (*curl_connecting
)(struct connectdata
*, bool *done
);
783 CURLcode (*curl_doing
)(struct connectdata
*, bool *done
);
785 /* Called from the multi interface during the PROTOCONNECT phase, and it
786 should then return a proper fd set */
787 int (*curl_proto_getsock
)(struct connectdata
*conn
,
788 curl_socket_t
*socks
,
791 /* Called from the multi interface during the DOING phase, and it should
792 then return a proper fd set */
793 int (*curl_doing_getsock
)(struct connectdata
*conn
,
794 curl_socket_t
*socks
,
797 /* This function *MAY* be set to a protocol-dependent function that is run
798 * by the curl_disconnect(), as a step in the disconnection.
800 CURLcode (*curl_disconnect
)(struct connectdata
*);
802 /* This function *MAY* be set to a protocol-dependent function that is run
803 * in the curl_close() function if protocol-specific cleanups are required.
805 CURLcode (*curl_close
)(struct connectdata
*);
807 /**** curl_get() phase fields */
809 curl_socket_t sockfd
; /* socket to read from or CURL_SOCKET_BAD */
810 curl_socket_t writesockfd
; /* socket to write to, it may very
811 well be the same we read from.
812 CURL_SOCKET_BAD disables */
814 /** Dynamicly allocated strings, may need to be freed before this **/
815 /** struct is killed. **/
816 struct dynamically_allocated_data
{
817 char *proxyuserpwd
; /* free later if not NULL! */
818 char *uagent
; /* free later if not NULL! */
819 char *accept_encoding
; /* free later if not NULL! */
820 char *userpwd
; /* free later if not NULL! */
821 char *rangeline
; /* free later if not NULL! */
822 char *ref
; /* free later if not NULL! */
823 char *host
; /* free later if not NULL */
824 char *cookiehost
; /* free later if not NULL */
827 int sec_complete
; /* if krb4 is enabled for this connection */
829 enum protection_level command_prot
;
830 enum protection_level data_prot
;
831 enum protection_level request_data_prot
;
833 struct krb4buffer in_buffer
, out_buffer
;
835 const struct Curl_sec_client_mech
*mech
;
836 struct sockaddr_in local_addr
;
839 bool readchannel_inuse
; /* whether the read channel is in use by an easy
841 bool writechannel_inuse
; /* whether the write channel is in use by an easy
843 bool is_in_pipeline
; /* TRUE if this connection is in a pipeline */
845 struct curl_llist
*send_pipe
; /* List of handles waiting to
846 send on this pipeline */
847 struct curl_llist
*recv_pipe
; /* List of handles waiting to read
848 their responses on this pipeline */
850 char master_buffer
[BUFSIZE
]; /* The master buffer for this connection. */
851 size_t read_pos
; /* Current read position in the master buffer */
852 size_t buf_len
; /* Length of the buffer?? */
855 /*************** Request - specific items ************/
857 /* previously this was in the urldata struct */
858 curl_read_callback fread
; /* function that reads the input */
859 void *fread_in
; /* pointer to pass to the fread() above */
861 struct ntlmdata ntlm
; /* NTLM differs from other authentication schemes
862 because it authenticates connections, not
864 struct ntlmdata proxyntlm
; /* NTLM data for proxy */
866 char syserr_buf
[256]; /* buffer for Curl_strerror() */
868 #if defined(USE_ARES) || defined(USE_THREADING_GETHOSTBYNAME) || \
869 defined(USE_THREADING_GETADDRINFO)
870 /* data used for the asynch name resolve callback */
871 struct Curl_async async
;
874 /* These three are used for chunked-encoding trailer support */
875 char *trailer
; /* allocated buffer to store trailer in */
876 int trlMax
; /* allocated buffer size */
877 int trlPos
; /* index of where to store data */
880 struct ftp_conn ftpc
;
884 /* The end of connectdata. */
887 * Struct to keep statistical and informational data.
890 int httpcode
; /* Recent HTTP or FTP response code */
893 long filetime
; /* If requested, this is might get set. Set to -1 if the time
894 was unretrievable. We cannot have this of type time_t,
895 since time_t is unsigned on several platforms such as
897 long header_size
; /* size of read header(s) in bytes */
898 long request_size
; /* the amount of bytes sent in the request(s) */
903 long numconnects
; /* how many new connection did libcurl created */
905 char *contenttype
; /* the content type of the object */
910 long lastshow
; /* time() of the last displayed progress meter or NULL to
911 force redraw at next call */
912 curl_off_t size_dl
; /* total expected size */
913 curl_off_t size_ul
; /* total expected size */
914 curl_off_t downloaded
; /* transfered so far */
915 curl_off_t uploaded
; /* transfered so far */
917 curl_off_t current_speed
; /* uses the currently fastest transfer */
919 bool callback
; /* set when progress callback is used */
920 int width
; /* screen width at download start */
921 int flags
; /* see progress.h */
930 double t_pretransfer
;
931 double t_starttransfer
;
934 struct timeval start
;
935 struct timeval t_startsingle
;
936 #define CURR_TIME (5+1) /* 6 entries for 5 seconds */
938 curl_off_t speeder
[ CURR_TIME
];
939 struct timeval speeder_time
[ CURR_TIME
];
944 HTTPREQ_NONE
, /* first in list */
947 HTTPREQ_POST_FORM
, /* we make a difference internally */
951 HTTPREQ_LAST
/* last in list */
955 * Values that are generated, temporary or calculated internally for a
956 * "session handle" must be defined within the 'struct UrlState'. This struct
957 * will be used within the SessionHandle struct. When the 'SessionHandle'
958 * struct is cloned, this data MUST NOT be copied.
960 * Remember that any "state" information goes globally for the curl handle.
961 * Session-data MUST be put in the connectdata struct and here. */
962 #define MAX_CURL_USER_LENGTH 256
963 #define MAX_CURL_PASSWORD_LENGTH 256
964 #define MAX_CURL_USER_LENGTH_TXT "255"
965 #define MAX_CURL_PASSWORD_LENGTH_TXT "255"
968 long want
; /* Bitmask set to the authentication methods wanted by the app
969 (with CURLOPT_HTTPAUTH or CURLOPT_PROXYAUTH). */
971 long avail
; /* bitmask for what the server reports to support for this
973 bool done
; /* TRUE when the auth phase is done and ready to do the *actual*
975 bool multi
; /* TRUE if this is not yet authenticated but within the auth
976 multipass negotiation */
981 /* 'connects' will be an allocated array with pointers. If the pointer is
982 set, it holds an allocated connection. */
983 struct connectdata
**connects
;
984 long num
; /* number of entries of the 'connects' array */
986 CONNCACHE_PRIVATE
, /* used for an easy handle alone */
987 CONNCACHE_MULTI
/* shared within a multi handle */
999 struct conncache
*connc
; /* points to the connection cache this handle
1002 /* buffers to store authentication data in, as parsed from input options */
1003 struct timeval keeps_speed
; /* for the progress meter really */
1005 long lastconnect
; /* index of most recent connect or -1 if undefined */
1007 char *headerbuff
; /* allocated buffer to store headers in */
1008 size_t headersize
; /* size of the allocation */
1010 char buffer
[BUFSIZE
+1]; /* download buffer */
1011 char uploadbuffer
[BUFSIZE
+1]; /* upload buffer */
1012 curl_off_t current_speed
; /* the ProgressShow() funcion sets this,
1014 bool this_is_a_follow
; /* this is a followed Location: request */
1016 bool is_in_pipeline
; /* Indicates whether this handle is part of a pipeline */
1018 char *first_host
; /* if set, this should be the host name that we will
1019 sent authorization to, no else. Used to make Location:
1020 following not keep sending user+password... This is
1024 struct curl_ssl_session
*session
; /* array of 'numsessions' size */
1025 long sessionage
; /* number of the most recent session */
1027 char *scratch
; /* huge buffer[BUFSIZE*2] when doing upload CRLF replacing */
1028 bool errorbuf
; /* Set to TRUE if the error buffer is already filled in.
1029 This must be set to FALSE every time _easy_perform() is
1031 int os_errno
; /* filled in with errno whenever an error occurs */
1033 /* storage for the previous bag^H^H^HSIGPIPE signal handler :-) */
1034 void (*prev_signal
)(int sig
);
1036 bool allow_port
; /* Is set.use_port allowed to take effect or not. This
1037 is always set TRUE when curl_easy_perform() is called. */
1039 struct digestdata digest
;
1040 struct digestdata proxydigest
;
1043 struct negotiatedata negotiate
;
1046 struct auth authhost
;
1047 struct auth authproxy
;
1049 bool authproblem
; /* TRUE if there's some problem authenticating */
1052 ares_channel areschannel
; /* for name resolves */
1055 #if defined(USE_SSLEAY) && defined(HAVE_OPENSSL_ENGINE_H)
1057 #endif /* USE_SSLEAY */
1058 struct timeval expiretime
; /* set this with Curl_expire() only */
1059 struct Curl_tree timenode
; /* for the splay stuff */
1061 /* a place to store the most recenlty set FTP entrypath */
1062 char *most_recent_ftp_entrypath
;
1064 /* set after initial USER failure, to prevent an authentication loop */
1065 bool ftp_trying_alternative
;
1067 bool expect100header
; /* TRUE if we added Expect: 100-continue */
1069 bool pipe_broke
; /* TRUE if the connection we were pipelined on broke
1070 and we need to restart from the beginning */
1071 bool cancelled
; /* TRUE if the request was cancelled */
1074 /* do FTP line-end conversions on most platforms */
1075 #define CURL_DO_LINEEND_CONV
1076 /* for FTP downloads: track CRLF sequences that span blocks */
1077 bool prev_block_had_trailing_cr
;
1078 /* for FTP downloads: how many CRLFs did we converted to LFs? */
1079 curl_off_t crlf_conversions
;
1081 /* If set to non-NULL, there's a connection in a shared connection cache
1082 that uses this handle so we can't kill this SessionHandle just yet but
1083 must keep it around and add it to the list of handles to kill once all
1084 its connections are gone */
1086 bool closed
; /* set to TRUE when curl_easy_cleanup() has been called on this
1087 handle, but it is kept around as mentioned for
1093 * This 'DynamicStatic' struct defines dynamic states that actually change
1094 * values in the 'UserDefined' area, which MUST be taken into consideration
1095 * if the UserDefined struct is cloned or similar. You can probably just
1096 * copy these, but each one indicate a special action on other data.
1099 struct DynamicStatic
{
1100 char *url
; /* work URL, copied from UserDefined */
1101 bool url_alloc
; /* URL string is malloc()'ed */
1102 bool url_changed
; /* set on CURL_OPT_URL, used to detect if the URL was
1103 changed after the connect phase, as we allow callback
1104 to change it and if so, we reconnect to use the new
1106 char *referer
; /* referer string */
1107 bool referer_alloc
; /* referer sting is malloc()ed */
1108 struct curl_slist
*cookielist
; /* list of cookie files set by
1109 curl_easy_setopt(COOKIEFILE) calls */
1113 * This 'UserDefined' struct must only contain data that is set once to go
1114 * for many (perhaps) independent connections. Values that are generated or
1115 * calculated internally for the "session handle" MUST be defined within the
1116 * 'struct UrlState' instead. The only exceptions MUST note the changes in
1117 * the 'DynamicStatic' struct.
1119 struct Curl_one_easy
; /* declared and used only in multi.c */
1120 struct Curl_multi
; /* declared and used only in multi.c */
1122 struct UserDefined
{
1123 FILE *err
; /* the stderr user data goes here */
1124 void *debugdata
; /* the data that will be passed to fdebug */
1125 char *errorbuffer
; /* store failure messages in here */
1126 char *proxyuserpwd
; /* Proxy <user:password>, if used */
1127 long proxyport
; /* If non-zero, use this port number by default. If the
1128 proxy string features a ":[port]" that one will override
1130 void *out
; /* the fetched file goes here */
1131 void *in
; /* the uploaded file is read from here */
1132 void *writeheader
; /* write the header to this if non-NULL */
1133 char *set_url
; /* what original URL to work on */
1134 char *proxy
; /* proxy to use */
1135 long use_port
; /* which port to use (when not using default) */
1136 char *userpwd
; /* <user:password>, if used */
1137 long httpauth
; /* what kind of HTTP authentication to use (bitmask) */
1138 long proxyauth
; /* what kind of proxy authentication to use (bitmask) */
1139 char *set_range
; /* range, if used. See README for detailed specification
1141 long followlocation
; /* as in HTTP Location: */
1142 long maxredirs
; /* maximum no. of http(s) redirects to follow, set to -1
1144 char *set_referer
; /* custom string */
1145 bool free_referer
; /* set TRUE if 'referer' points to a string we
1147 char *useragent
; /* User-Agent string */
1148 char *encoding
; /* Accept-Encoding string */
1149 char *postfields
; /* if POST, set the fields' values here */
1150 curl_off_t postfieldsize
; /* if POST, this might have a size to use instead
1151 of strlen(), and then the data *may* be binary
1152 (contain zero bytes) */
1153 char *ftpport
; /* port to send with the FTP PORT command */
1154 char *device
; /* local network interface/address to use */
1155 unsigned short localport
; /* local port number to bind to */
1156 int localportrange
; /* number of additional port numbers to test in case the
1157 'localport' one can't be bind()ed */
1158 curl_write_callback fwrite
; /* function that stores the output */
1159 curl_write_callback fwrite_header
; /* function that stores headers */
1160 curl_read_callback fread
; /* function that reads the input */
1161 curl_progress_callback fprogress
; /* function for progress information */
1162 curl_debug_callback fdebug
; /* function that write informational data */
1163 curl_ioctl_callback ioctl
; /* function for I/O control */
1164 curl_sockopt_callback fsockopt
; /* function for setting socket options */
1165 void *sockopt_client
; /* pointer to pass to the socket options callback */
1167 /* the 3 curl_conv_callback functions below are used on non-ASCII hosts */
1168 /* function to convert from the network encoding: */
1169 curl_conv_callback convfromnetwork
;
1170 /* function to convert to the network encoding: */
1171 curl_conv_callback convtonetwork
;
1172 /* function to convert from UTF-8 encoding: */
1173 curl_conv_callback convfromutf8
;
1175 void *progress_client
; /* pointer to pass to the progress callback */
1176 void *ioctl_client
; /* pointer to pass to the ioctl callback */
1177 long timeout
; /* in seconds, 0 means no timeout */
1178 long connecttimeout
; /* in seconds, 0 means no timeout */
1179 long ftp_response_timeout
; /* in seconds, 0 means no timeout */
1180 curl_off_t infilesize
; /* size of file to upload, -1 means unknown */
1181 long low_speed_limit
; /* bytes/second */
1182 long low_speed_time
; /* number of seconds */
1183 curl_off_t max_send_speed
; /* high speed limit in bytes/second for upload */
1184 curl_off_t max_recv_speed
; /* high speed limit in bytes/second for download */
1185 curl_off_t set_resume_from
; /* continue [ftp] transfer from here */
1186 char *cookie
; /* HTTP cookie string to send */
1187 struct curl_slist
*headers
; /* linked list of extra headers */
1188 struct curl_httppost
*httppost
; /* linked list of POST data */
1189 char *cert
; /* certificate */
1190 char *cert_type
; /* format for certificate (default: PEM) */
1191 char *key
; /* private key */
1192 char *key_type
; /* format for private key (default: PEM) */
1193 char *key_passwd
; /* plain text private key password */
1194 char *cookiejar
; /* dump all cookies to this file */
1195 bool cookiesession
; /* new cookie session? */
1196 bool crlf
; /* convert crlf on ftp upload(?) */
1197 char *ftp_account
; /* ftp account data */
1198 char *ftp_alternative_to_user
; /* command to send if USER/PASS fails */
1199 struct curl_slist
*quote
; /* after connection is established */
1200 struct curl_slist
*postquote
; /* after the transfer */
1201 struct curl_slist
*prequote
; /* before the transfer, after type */
1202 struct curl_slist
*source_quote
; /* 3rd party quote */
1203 struct curl_slist
*source_prequote
; /* in 3rd party transfer mode - before
1204 the transfer on source host */
1205 struct curl_slist
*source_postquote
; /* in 3rd party transfer mode - after
1206 the transfer on source host */
1207 struct curl_slist
*telnet_options
; /* linked list of telnet options */
1208 curl_TimeCond timecondition
; /* kind of time/date comparison */
1209 time_t timevalue
; /* what time to compare with */
1210 Curl_HttpReq httpreq
; /* what kind of HTTP request (if any) is this */
1211 char *customrequest
; /* HTTP/FTP request to use */
1212 long httpversion
; /* when non-zero, a specific HTTP version requested to
1213 be used in the library's request(s) */
1214 char *auth_host
; /* if set, this is the allocated string to the host name
1215 * to which to send the authorization data to, and no other
1216 * host (which location-following otherwise could lead to)
1218 char *krb4_level
; /* what security level */
1219 struct ssl_config_data ssl
; /* user defined SSL stuff */
1221 curl_proxytype proxytype
; /* what kind of proxy that is in use */
1223 int dns_cache_timeout
; /* DNS cache timeout */
1224 long buffer_size
; /* size of receive buffer to use */
1226 char *private_data
; /* Private data */
1228 struct Curl_one_easy
*one_easy
; /* When adding an easy handle to a multi
1229 handle, an internal 'Curl_one_easy'
1230 struct is created and this is a pointer
1231 to the particular struct associated with
1232 this SessionHandle */
1234 struct curl_slist
*http200aliases
; /* linked list of aliases for http200 */
1238 curl_off_t max_filesize
; /* Maximum file size to download */
1240 char *source_url
; /* for 3rd party transfer */
1241 char *source_userpwd
; /* for 3rd party transfer */
1243 curl_ftpfile ftp_filemethod
; /* how to get to a file when FTP is used */
1245 /* Here follows boolean settings that define how to behave during
1246 this session. They are STATIC, set by libcurl users or at least initially
1247 and they don't change during operations. */
1249 bool printhost
; /* printing host name in debug info */
1251 bool tunnel_thru_httpproxy
;
1252 bool prefer_ascii
; /* ASCII rather than binary */
1255 bool ftp_create_missing_dirs
;
1258 bool http_fail_on_error
;
1259 bool http_follow_location
;
1260 bool http_disable_hostname_check_before_authentication
;
1261 bool include_header
; /* include received protocol headers in data output */
1262 bool http_set_referer
;
1263 bool http_auto_referer
; /* set "correct" referer when following location: */
1264 bool opt_no_body
; /* as set with CURLOPT_NO_BODY */
1267 enum CURL_NETRC_OPTION
1268 use_netrc
; /* defined in include/curl.h */
1269 char *netrc_file
; /* if not NULL, use this instead of trying to find
1272 bool krb4
; /* kerberos4 connection requested */
1273 bool reuse_forbid
; /* forbidden to be reused, close after use */
1274 bool reuse_fresh
; /* do not re-use an existing connection */
1275 bool ftp_use_epsv
; /* if EPSV is to be attempted or not */
1276 bool ftp_use_eprt
; /* if EPRT is to be attempted or not */
1277 bool ftp_use_ccc
; /* if CCC is to be attempted or not */
1279 curl_ftpssl ftp_ssl
; /* if AUTH TLS is to be attempted etc */
1280 curl_ftpauth ftpsslauth
; /* what AUTH XXX to be attempted */
1281 bool no_signal
; /* do not use any signal/alarm handler */
1282 bool global_dns_cache
; /* subject for future removal */
1283 bool tcp_nodelay
; /* whether to enable TCP_NODELAY or not */
1284 bool ignorecl
; /* ignore content length */
1285 bool ftp_skip_ip
; /* skip the IP address the FTP server passes on to
1287 bool connect_only
; /* make connection, let application use the socket */
1288 long ssh_auth_types
; /* allowed SSH auth types */
1289 char *ssh_public_key
; /* the path to the public key file for
1291 char *ssh_private_key
; /* the path to the private key file for
1296 struct curl_hash
*hostcache
;
1298 HCACHE_NONE
, /* not pointing to anything */
1299 HCACHE_PRIVATE
, /* points to our own */
1300 HCACHE_GLOBAL
, /* points to the (shrug) global one */
1301 HCACHE_MULTI
, /* points to a shared one in the multi handle */
1302 HCACHE_SHARED
/* points to a shared one in a shared object */
1307 * The 'connectdata' struct MUST have all the connection oriented stuff as we
1308 * may have several simultaneous connections and connection structs in memory.
1310 * The 'struct UserDefined' must only contain data that is set once to go for
1311 * many (perhaps) independent connections. Values that are generated or
1312 * calculated internally for the "session handle" must be defined within the
1313 * 'struct UrlState' instead.
1316 struct SessionHandle
{
1318 struct Curl_multi
*multi
; /* if non-NULL, points to the multi handle
1319 struct to which this "belongs" */
1320 struct Curl_share
*share
; /* Share, handles global variable mutexing */
1321 struct HandleData reqdata
; /* Request-specific data */
1322 struct UserDefined set
; /* values set by the libcurl user */
1323 struct DynamicStatic change
; /* possibly modified userdefined data */
1325 struct CookieInfo
*cookies
; /* the cookies, read from files and servers */
1326 struct Progress progress
; /* for all the progress meter data */
1327 struct UrlState state
; /* struct for fields used for state info and
1328 other dynamic purposes */
1329 struct PureInfo info
; /* stats, reports and info data */
1330 #if defined(CURL_DOES_CONVERSIONS) && defined(HAVE_ICONV)
1331 iconv_t outbound_cd
; /* for translating to the network encoding */
1332 iconv_t inbound_cd
; /* for translating from the network encoding */
1333 iconv_t utf8_cd
; /* for translating to UTF8 */
1334 #endif /* CURL_DOES_CONVERSIONS && HAVE_ICONV */
1335 unsigned int magic
; /* set to a CURLEASY_MAGIC_NUMBER */
1338 #define LIBCURL_NAME "libcurl"