1
0

urldata.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  1. #ifndef __URLDATA_H
  2. #define __URLDATA_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2004, Daniel Stenberg, <[email protected]>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at http://curl.haxx.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. * $Id$
  24. ***************************************************************************/
  25. /* This file is for lib internal stuff */
  26. #include "setup.h"
  27. #define PORT_FTP 21
  28. #define PORT_FTPS 990
  29. #define PORT_TELNET 23
  30. #define PORT_GOPHER 70
  31. #define PORT_HTTP 80
  32. #define PORT_HTTPS 443
  33. #define PORT_DICT 2628
  34. #define PORT_LDAP 389
  35. #define DICT_MATCH "/MATCH:"
  36. #define DICT_MATCH2 "/M:"
  37. #define DICT_MATCH3 "/FIND:"
  38. #define DICT_DEFINE "/DEFINE:"
  39. #define DICT_DEFINE2 "/D:"
  40. #define DICT_DEFINE3 "/LOOKUP:"
  41. #define CURL_DEFAULT_USER "anonymous"
  42. #define CURL_DEFAULT_PASSWORD "[email protected]"
  43. #include "cookie.h"
  44. #include "formdata.h"
  45. #ifdef USE_SSLEAY
  46. /* SSLeay stuff usually in /usr/local/ssl/include */
  47. #ifdef USE_OPENSSL
  48. #include "openssl/rsa.h"
  49. #include "openssl/crypto.h"
  50. #include "openssl/x509.h"
  51. #include "openssl/pem.h"
  52. #include "openssl/ssl.h"
  53. #include "openssl/err.h"
  54. #ifdef HAVE_OPENSSL_ENGINE_H
  55. #include <openssl/engine.h>
  56. #endif
  57. #else
  58. #include "rsa.h"
  59. #include "crypto.h"
  60. #include "x509.h"
  61. #include "pem.h"
  62. #include "ssl.h"
  63. #include "err.h"
  64. #endif
  65. #endif
  66. #ifdef HAVE_NETINET_IN_H
  67. #include <netinet/in.h>
  68. #endif
  69. #include "timeval.h"
  70. #ifdef HAVE_ZLIB_H
  71. #include <zlib.h> /* for content-encoding */
  72. #endif
  73. #ifdef CURL_SPECIAL_ZLIB_H
  74. #include CURL_SPECIAL_ZLIB_H
  75. #endif
  76. #ifdef USE_ARES
  77. #include <ares.h>
  78. #endif
  79. #include <curl/curl.h>
  80. #include "http_chunks.h" /* for the structs and enum stuff */
  81. #include "hostip.h"
  82. #include "hash.h"
  83. #ifdef HAVE_GSSAPI
  84. #ifdef HAVE_GSSMIT
  85. #include <gssapi/gssapi.h>
  86. #include <gssapi/gssapi_generic.h>
  87. #else
  88. #include <gssapi.h>
  89. #endif
  90. #endif
  91. /* Download buffer size, keep it fairly big for speed reasons */
  92. #define BUFSIZE CURL_MAX_WRITE_SIZE
  93. /* Initial size of the buffer to store headers in, it'll be enlarged in case
  94. of need. */
  95. #define HEADERSIZE 256
  96. /* Just a convenience macro to get the larger value out of two given.
  97. We prefix with CURL to prevent name collisions. */
  98. #define CURLMAX(x,y) ((x)>(y)?(x):(y))
  99. #ifdef HAVE_KRB4
  100. /* Types needed for krb4-ftp connections */
  101. struct krb4buffer {
  102. void *data;
  103. size_t size;
  104. size_t index;
  105. int eof_flag;
  106. };
  107. enum protection_level {
  108. prot_clear,
  109. prot_safe,
  110. prot_confidential,
  111. prot_private
  112. };
  113. #endif
  114. /* struct for data related to each SSL connection */
  115. struct ssl_connect_data {
  116. bool use; /* use ssl encrypted communications TRUE/FALSE */
  117. #ifdef USE_SSLEAY
  118. /* these ones requires specific SSL-types */
  119. SSL_CTX* ctx;
  120. SSL* handle;
  121. X509* server_cert;
  122. #endif /* USE_SSLEAY */
  123. };
  124. struct ssl_config_data {
  125. long version; /* what version the client wants to use */
  126. long certverifyresult; /* result from the certificate verification */
  127. long verifypeer; /* set TRUE if this is desired */
  128. long verifyhost; /* 0: no verify
  129. 1: check that CN exists
  130. 2: CN must match hostname */
  131. char *CApath; /* DOES NOT WORK ON WINDOWS */
  132. char *CAfile; /* cerficate to verify peer against */
  133. char *random_file; /* path to file containing "random" data */
  134. char *egdsocket; /* path to file containing the EGD daemon socket */
  135. char *cipher_list; /* list of ciphers to use */
  136. long numsessions; /* SSL session id cache size */
  137. curl_ssl_ctx_callback fsslctx; /* function to initialize ssl ctx */
  138. void *fsslctxp; /*parameter for call back */
  139. };
  140. /* information stored about one single SSL session */
  141. struct curl_ssl_session {
  142. char *name; /* host name for which this ID was used */
  143. void *sessionid; /* as returned from the SSL layer */
  144. long age; /* just a number, the higher the more recent */
  145. unsigned short remote_port; /* remote port to connect to */
  146. struct ssl_config_data ssl_config; /* setup for this session */
  147. };
  148. /* Struct used for Digest challenge-response authentication */
  149. struct digestdata {
  150. char *nonce;
  151. char *cnonce;
  152. char *realm;
  153. int algo;
  154. bool stale; /* set true for re-negotiation */
  155. char *opaque;
  156. char *qop;
  157. char *algorithm;
  158. int nc; /* nounce count */
  159. };
  160. typedef enum {
  161. NTLMSTATE_NONE,
  162. NTLMSTATE_TYPE1,
  163. NTLMSTATE_TYPE2,
  164. NTLMSTATE_TYPE3,
  165. NTLMSTATE_LAST
  166. } curlntlm;
  167. /* for 3rd party transfers to decide which side that issues PASV */
  168. typedef enum {
  169. CURL_TARGET_PASV,
  170. CURL_SOURCE_PASV
  171. } curl_pasv_side;
  172. /* Struct used for NTLM challenge-response authentication */
  173. struct ntlmdata {
  174. curlntlm state;
  175. unsigned char nonce[8];
  176. };
  177. #ifdef HAVE_GSSAPI
  178. struct negotiatedata {
  179. bool gss; /* Whether we're processing GSS-Negotiate or Negotiate */
  180. const char* protocol; /* "GSS-Negotiate" or "Negotiate" */
  181. OM_uint32 status;
  182. gss_ctx_id_t context;
  183. gss_name_t server_name;
  184. gss_buffer_desc output_token;
  185. };
  186. #endif
  187. /****************************************************************************
  188. * HTTP unique setup
  189. ***************************************************************************/
  190. struct HTTP {
  191. struct FormData *sendit;
  192. curl_off_t postsize; /* off_t to handle large file sizes */
  193. char *postdata;
  194. const char *p_pragma; /* Pragma: string */
  195. const char *p_accept; /* Accept: string */
  196. curl_off_t readbytecount;
  197. curl_off_t writebytecount;
  198. /* For FORM posting */
  199. struct Form form;
  200. struct Curl_chunker chunk;
  201. struct back {
  202. curl_read_callback fread; /* backup storage for fread pointer */
  203. void *fread_in; /* backup storage for fread_in pointer */
  204. char *postdata;
  205. curl_off_t postsize;
  206. } backup;
  207. enum {
  208. HTTPSEND_NADA, /* init */
  209. HTTPSEND_REQUEST, /* sending a request */
  210. HTTPSEND_BODY, /* sending body */
  211. HTTPSEND_LAST /* never use this */
  212. } sending;
  213. void *send_buffer; /* used if the request couldn't be sent in one chunk,
  214. points to an allocated send_buffer struct */
  215. };
  216. /****************************************************************************
  217. * FTP unique setup
  218. ***************************************************************************/
  219. struct FTP {
  220. curl_off_t *bytecountp;
  221. char *user; /* user name string */
  222. char *passwd; /* password string */
  223. char *urlpath; /* the originally given path part of the URL */
  224. char **dirs; /* realloc()ed array for path components */
  225. int dirdepth; /* number of entries used in the 'dirs' array */
  226. int diralloc; /* number of entries allocated for the 'dirs' array */
  227. char *file; /* decoded file */
  228. char *entrypath; /* the PWD reply when we logged on */
  229. char *cache; /* data cache between getresponse()-calls */
  230. curl_off_t cache_size; /* size of cache in bytes */
  231. bool dont_check; /* Set to TRUE to prevent the final (post-transfer)
  232. file size and 226/250 status check. It should still
  233. read the line, just ignore the result. */
  234. bool no_transfer; /* nothing was transfered, (possibly because a resumed
  235. transfer already was complete) */
  236. long response_time; /* When no timeout is given, this is the amount of
  237. seconds we await for an FTP response. Initialized
  238. in Curl_ftp_connect() */
  239. bool ctl_valid; /* Tells Curl_ftp_quit() whether or not to do
  240. anything. If the connection has timed out or
  241. been closed, this should be FALSE when it gets
  242. to Curl_ftp_quit() */
  243. };
  244. /****************************************************************************
  245. * FILE unique setup
  246. ***************************************************************************/
  247. struct FILEPROTO {
  248. char *path; /* the path we operate on */
  249. char *freepath; /* pointer to the allocated block we must free, this might
  250. differ from the 'path' pointer */
  251. int fd; /* open file descriptor to read from! */
  252. };
  253. /*
  254. * Boolean values that concerns this connection.
  255. */
  256. struct ConnectBits {
  257. bool close; /* if set, we close the connection after this request */
  258. bool reuse; /* if set, this is a re-used connection */
  259. bool chunk; /* if set, this is a chunked transfer-encoding */
  260. bool httpproxy; /* if set, this transfer is done through a http proxy */
  261. bool user_passwd; /* do we use user+password for this connection? */
  262. bool proxy_user_passwd; /* user+password for the proxy? */
  263. bool ipv6_ip; /* we communicate with a remove site specified with pure IPv6
  264. IP address */
  265. bool use_range;
  266. bool rangestringalloc; /* the range string is malloc()'ed */
  267. bool do_more; /* this is set TRUE if the ->curl_do_more() function is
  268. supposed to be called, after ->curl_do() */
  269. bool upload_chunky; /* set TRUE if we are doing chunked transfer-encoding
  270. on upload */
  271. bool getheader; /* TRUE if header parsing is wanted */
  272. bool forbidchunk; /* used only to explicitly forbid chunk-upload for
  273. specific upload buffers. See readmoredata() in
  274. http.c for details. */
  275. bool tcpconnect; /* the tcp stream (or simimlar) is connected, this
  276. is set the first time on the first connect function
  277. call */
  278. bool retry; /* this connection is about to get closed and then
  279. re-attempted at another connection. */
  280. bool no_body; /* CURLOPT_NO_BODY (or similar) was set */
  281. bool tunnel_proxy; /* if CONNECT is used to "tunnel" through the proxy.
  282. This is implicit when SSL-protocols are used through
  283. proxies, but can also be enabled explicitly by
  284. apps */
  285. bool authprobe; /* set TRUE when this transfer is done to probe for auth
  286. types, as when asking for "any" type when speaking
  287. HTTP */
  288. };
  289. struct hostname {
  290. char *rawalloc; /* allocated "raw" version of the name */
  291. char *encalloc; /* allocated IDN-encoded version of the name */
  292. char *name; /* name to use internally, might be encoded, might be raw */
  293. char *dispname; /* name to display, as 'name' might be encoded */
  294. };
  295. /*
  296. * This struct is all the previously local variables from Curl_perform() moved
  297. * to struct to allow the function to return and get re-invoked better without
  298. * losing state.
  299. */
  300. struct Curl_transfer_keeper {
  301. curl_off_t bytecount; /* total number of bytes read */
  302. curl_off_t writebytecount; /* number of bytes written */
  303. struct timeval start; /* transfer started at this time */
  304. struct timeval now; /* current time */
  305. bool header; /* incoming data has HTTP header */
  306. enum {
  307. HEADER_NORMAL, /* no bad header at all */
  308. HEADER_PARTHEADER, /* part of the chunk is a bad header, the rest
  309. is normal data */
  310. HEADER_ALLBAD /* all was believed to be header */
  311. } badheader; /* the header was deemed bad and will be
  312. written as body */
  313. int headerline; /* counts header lines to better track the
  314. first one */
  315. char *hbufp; /* points at *end* of header line */
  316. size_t hbuflen;
  317. char *str; /* within buf */
  318. char *str_start; /* within buf */
  319. char *end_ptr; /* within buf */
  320. char *p; /* within headerbuff */
  321. bool content_range; /* set TRUE if Content-Range: was found */
  322. curl_off_t offset; /* possible resume offset read from the
  323. Content-Range: header */
  324. int httpcode; /* error code from the 'HTTP/1.? XXX' line */
  325. int httpversion; /* the HTTP version*10 */
  326. struct timeval start100; /* time stamp to wait for the 100 code from */
  327. bool write_after_100_header; /* TRUE = we enable the write after we
  328. received a 100-continue/timeout or
  329. FALSE = directly */
  330. bool wait100_after_headers; /* TRUE = after the request-headers have been
  331. sent off properly, we go into the wait100
  332. state, FALSE = don't */
  333. int content_encoding; /* What content encoding. sec 3.5, RFC2616. */
  334. #define IDENTITY 0 /* No encoding */
  335. #define DEFLATE 1 /* zlib delfate [RFC 1950 & 1951] */
  336. #define GZIP 2 /* gzip algorithm [RFC 1952] */
  337. #define COMPRESS 3 /* Not handled, added for completeness */
  338. #ifdef HAVE_LIBZ
  339. bool zlib_init; /* True if zlib already initialized;
  340. undefined if Content-Encoding header. */
  341. z_stream z; /* State structure for zlib. */
  342. #endif
  343. time_t timeofdoc;
  344. long bodywrites;
  345. char *buf;
  346. char *uploadbuf;
  347. curl_socket_t maxfd;
  348. /* pointers to the actual descriptors we check */
  349. fd_set *readfdp;
  350. fd_set *writefdp;
  351. /* the file descriptors to play with */
  352. fd_set readfd;
  353. fd_set writefd;
  354. fd_set rkeepfd;
  355. fd_set wkeepfd;
  356. int keepon;
  357. bool upload_done; /* set to TRUE when doing chunked transfer-encoding upload
  358. and we're uploading the last chunk */
  359. bool ignorebody; /* we read a response-body but we ignore it! */
  360. };
  361. #if defined(USE_ARES) || defined(USE_THREADING_GETHOSTBYNAME) || \
  362. defined(USE_THREADING_GETADDRINFO)
  363. struct Curl_async {
  364. char *hostname;
  365. int port;
  366. struct Curl_dns_entry *dns;
  367. bool done; /* set TRUE when the lookup is complete */
  368. int status; /* if done is TRUE, this is the status from the callback */
  369. void *os_specific; /* 'struct thread_data' for Windows */
  370. };
  371. #endif
  372. #define FIRSTSOCKET 0
  373. #define SECONDARYSOCKET 1
  374. /*
  375. * The connectdata struct contains all fields and variables that should be
  376. * unique for an entire connection.
  377. */
  378. struct connectdata {
  379. /**** Fields set when inited and not modified again */
  380. struct SessionHandle *data; /* link to the root CURL struct */
  381. long connectindex; /* what index in the connects index this particular
  382. struct has */
  383. long protocol; /* PROT_* flags concerning the protocol set */
  384. #define PROT_MISSING (1<<0)
  385. #define PROT_GOPHER (1<<1)
  386. #define PROT_HTTP (1<<2)
  387. #define PROT_HTTPS (1<<3)
  388. #define PROT_FTP (1<<4)
  389. #define PROT_TELNET (1<<5)
  390. #define PROT_DICT (1<<6)
  391. #define PROT_LDAP (1<<7)
  392. #define PROT_FILE (1<<8)
  393. #define PROT_FTPS (1<<9)
  394. #define PROT_SSL (1<<10) /* protocol requires SSL */
  395. /* the particular host we use, in two different ways */
  396. struct Curl_dns_entry *dns_entry;
  397. Curl_addrinfo *ip_addr; /* the particular IP we connected to */
  398. char protostr[16]; /* store the protocol string in this buffer */
  399. struct hostname host;
  400. struct hostname proxy;
  401. char *pathbuffer;/* allocated buffer to store the URL's path part in */
  402. char *path; /* path to use, points to somewhere within the pathbuffer
  403. area */
  404. long port; /* which port to use locally */
  405. unsigned short remote_port; /* what remote port to connect to,
  406. not the proxy port! */
  407. curl_off_t bytecount;
  408. long headerbytecount; /* only count received headers */
  409. long deductheadercount; /* this amount of bytes doesn't count when we check
  410. if anything has been transfered at the end of
  411. a connection. We use this counter to make only
  412. a 100 reply (without a following second response
  413. code) result in a CURLE_GOT_NOTHING error code */
  414. char *range; /* range, if used. See README for detailed specification on
  415. this syntax. */
  416. curl_off_t resume_from; /* continue [ftp] transfer from here */
  417. char *user; /* user name string, allocated */
  418. char *passwd; /* password string, allocated */
  419. char *proxyuser; /* proxy user name string, allocated */
  420. char *proxypasswd; /* proxy password string, allocated */
  421. struct timeval now; /* "current" time */
  422. struct timeval created; /* creation time */
  423. curl_socket_t sock[2]; /* two sockets, the second is used for the data
  424. transfer when doing FTP */
  425. curl_off_t maxdownload; /* in bytes, the maximum amount of data to fetch, 0
  426. means unlimited */
  427. struct ssl_connect_data ssl[2]; /* this is for ssl-stuff */
  428. struct ssl_config_data ssl_config;
  429. struct ConnectBits bits; /* various state-flags for this connection */
  430. /* These two functions MUST be set by the curl_connect() function to be
  431. be protocol dependent */
  432. CURLcode (*curl_do)(struct connectdata *);
  433. CURLcode (*curl_done)(struct connectdata *, CURLcode);
  434. /* If the curl_do() function is better made in two halves, this
  435. * curl_do_more() function will be called afterwards, if set. For example
  436. * for doing the FTP stuff after the PASV/PORT command.
  437. */
  438. CURLcode (*curl_do_more)(struct connectdata *);
  439. /* This function *MAY* be set to a protocol-dependent function that is run
  440. * after the connect() and everything is done, as a step in the connection.
  441. */
  442. CURLcode (*curl_connect)(struct connectdata *);
  443. /* This function *MAY* be set to a protocol-dependent function that is run
  444. * by the curl_disconnect(), as a step in the disconnection.
  445. */
  446. CURLcode (*curl_disconnect)(struct connectdata *);
  447. /* This function *MAY* be set to a protocol-dependent function that is run
  448. * in the curl_close() function if protocol-specific cleanups are required.
  449. */
  450. CURLcode (*curl_close)(struct connectdata *);
  451. /**** curl_get() phase fields */
  452. /* READ stuff */
  453. curl_socket_t sockfd; /* socket to read from or CURL_SOCKET_BAD */
  454. curl_off_t size; /* -1 if unknown at this point */
  455. curl_off_t *bytecountp; /* return number of bytes read or NULL */
  456. /* WRITE stuff */
  457. curl_socket_t writesockfd; /* socket to write to, it may very
  458. well be the same we read from.
  459. CURL_SOCKET_BAD disables */
  460. curl_off_t *writebytecountp; /* return number of bytes written or NULL */
  461. /** Dynamicly allocated strings, may need to be freed before this **/
  462. /** struct is killed. **/
  463. struct dynamically_allocated_data {
  464. char *proxyuserpwd; /* free later if not NULL! */
  465. char *uagent; /* free later if not NULL! */
  466. char *accept_encoding; /* free later if not NULL! */
  467. char *userpwd; /* free later if not NULL! */
  468. char *rangeline; /* free later if not NULL! */
  469. char *ref; /* free later if not NULL! */
  470. char *host; /* free later if not NULL */
  471. char *cookiehost; /* free later if not NULL */
  472. } allocptr;
  473. char *newurl; /* This can only be set if a Location: was in the
  474. document headers */
  475. #ifdef HAVE_KRB4
  476. enum protection_level command_prot;
  477. enum protection_level data_prot;
  478. enum protection_level request_data_prot;
  479. size_t buffer_size;
  480. struct krb4buffer in_buffer, out_buffer;
  481. int sec_complete;
  482. void *app_data;
  483. struct Curl_sec_client_mech *mech;
  484. struct sockaddr_in local_addr;
  485. #endif
  486. /*************** Request - specific items ************/
  487. /* previously this was in the urldata struct */
  488. union {
  489. struct HTTP *http;
  490. struct HTTP *gopher; /* alias, just for the sake of being more readable */
  491. struct HTTP *https; /* alias, just for the sake of being more readable */
  492. struct FTP *ftp;
  493. struct FILEPROTO *file;
  494. void *telnet; /* private for telnet.c-eyes only */
  495. void *generic;
  496. } proto;
  497. /* This struct is inited when needed */
  498. struct Curl_transfer_keeper keep;
  499. /* 'upload_present' is used to keep a byte counter of how much data there is
  500. still left in the buffer, aimed for upload. */
  501. ssize_t upload_present;
  502. /* 'upload_fromhere' is used as a read-pointer when we uploaded parts of a
  503. buffer, so the next read should read from where this pointer points to,
  504. and the 'upload_present' contains the number of bytes available at this
  505. position */
  506. char *upload_fromhere;
  507. curl_read_callback fread; /* function that reads the input */
  508. void *fread_in; /* pointer to pass to the fread() above */
  509. struct ntlmdata ntlm; /* NTLM differs from other authentication schemes
  510. because it authenticates connections, not
  511. single requests! */
  512. struct ntlmdata proxyntlm; /* NTLM data for proxy */
  513. char syserr_buf [256]; /* buffer for Curl_strerror() */
  514. #if defined(USE_ARES) || defined(USE_THREADING_GETHOSTBYNAME) || \
  515. defined(USE_THREADING_GETADDRINFO)
  516. /* data used for the asynch name resolve callback */
  517. struct Curl_async async;
  518. #endif
  519. struct connectdata *sec_conn; /* secondary connection for 3rd party
  520. transfer */
  521. };
  522. /* The end of connectdata. */
  523. /*
  524. * Struct to keep statistical and informational data.
  525. */
  526. struct PureInfo {
  527. int httpcode; /* Recent HTTP or FTP response code */
  528. int httpproxycode;
  529. int httpversion;
  530. long filetime; /* If requested, this is might get set. Set to -1 if the time
  531. was unretrievable. We cannot have this of type time_t,
  532. since time_t is unsigned on several platforms such as
  533. OpenVMS. */
  534. long header_size; /* size of read header(s) in bytes */
  535. long request_size; /* the amount of bytes sent in the request(s) */
  536. long proxyauthavail;
  537. long httpauthavail;
  538. char *contenttype; /* the content type of the object */
  539. };
  540. struct Progress {
  541. long lastshow; /* time() of the last displayed progress meter or NULL to
  542. force redraw at next call */
  543. curl_off_t size_dl; /* total expected size */
  544. curl_off_t size_ul; /* total expected size */
  545. curl_off_t downloaded; /* transfered so far */
  546. curl_off_t uploaded; /* transfered so far */
  547. curl_off_t current_speed; /* uses the currently fastest transfer */
  548. bool callback; /* set when progress callback is used */
  549. int width; /* screen width at download start */
  550. int flags; /* see progress.h */
  551. double timespent;
  552. curl_off_t dlspeed;
  553. curl_off_t ulspeed;
  554. double t_nslookup;
  555. double t_connect;
  556. double t_pretransfer;
  557. double t_starttransfer;
  558. double t_redirect;
  559. struct timeval start;
  560. struct timeval t_startsingle;
  561. #define CURR_TIME (5+1) /* 6 entries for 5 seconds */
  562. curl_off_t speeder[ CURR_TIME ];
  563. struct timeval speeder_time[ CURR_TIME ];
  564. int speeder_c;
  565. };
  566. typedef enum {
  567. HTTPREQ_NONE, /* first in list */
  568. HTTPREQ_GET,
  569. HTTPREQ_POST,
  570. HTTPREQ_POST_FORM, /* we make a difference internally */
  571. HTTPREQ_PUT,
  572. HTTPREQ_HEAD,
  573. HTTPREQ_CUSTOM,
  574. HTTPREQ_LAST /* last in list */
  575. } Curl_HttpReq;
  576. /*
  577. * Values that are generated, temporary or calculated internally for a
  578. * "session handle" must be defined within the 'struct urlstate'. This struct
  579. * will be used within the SessionHandle struct. When the 'SessionHandle'
  580. * struct is cloned, this data MUST NOT be copied.
  581. *
  582. * Remember that any "state" information goes globally for the curl handle.
  583. * Session-data MUST be put in the connectdata struct and here. */
  584. #define MAX_CURL_USER_LENGTH 256
  585. #define MAX_CURL_PASSWORD_LENGTH 256
  586. #define MAX_CURL_USER_LENGTH_TXT "255"
  587. #define MAX_CURL_PASSWORD_LENGTH_TXT "255"
  588. struct auth {
  589. long want; /* Bitmask set to the authentication methods wanted by the app
  590. (with CURLOPT_HTTPAUTH or CURLOPT_PROXYAUTH). */
  591. long picked;
  592. long avail; /* bitmask for what the server reports to support for this
  593. resource */
  594. bool done; /* TRUE when the auth phase is done and ready to do the *actual*
  595. request */
  596. };
  597. struct UrlState {
  598. enum {
  599. Curl_if_none,
  600. Curl_if_easy,
  601. Curl_if_multi
  602. } used_interface;
  603. /* buffers to store authentication data in, as parsed from input options */
  604. struct timeval keeps_speed; /* for the progress meter really */
  605. /* 'connects' will be an allocated array with pointers. If the pointer is
  606. set, it holds an allocated connection. */
  607. struct connectdata **connects;
  608. long numconnects; /* size of the 'connects' array */
  609. char *headerbuff; /* allocated buffer to store headers in */
  610. size_t headersize; /* size of the allocation */
  611. char buffer[BUFSIZE+1]; /* download buffer */
  612. char uploadbuffer[BUFSIZE+1]; /* upload buffer */
  613. curl_off_t current_speed; /* the ProgressShow() funcion sets this,
  614. bytes / second */
  615. bool this_is_a_follow; /* this is a followed Location: request */
  616. char *auth_host; /* if set, this should be the host name that we will
  617. sent authorization to, no else. Used to make Location:
  618. following not keep sending user+password... This is
  619. strdup() data.
  620. */
  621. struct curl_ssl_session *session; /* array of 'numsessions' size */
  622. long sessionage; /* number of the most recent session */
  623. char *scratch; /* huge buffer[BUFSIZE*2] when doing upload CRLF replacing */
  624. bool errorbuf; /* Set to TRUE if the error buffer is already filled in.
  625. This must be set to FALSE every time _easy_perform() is
  626. called. */
  627. #ifdef HAVE_SIGNAL
  628. /* storage for the previous bag^H^H^HSIGPIPE signal handler :-) */
  629. void (*prev_signal)(int sig);
  630. #endif
  631. bool allow_port; /* Is set.use_port allowed to take effect or not. This
  632. is always set TRUE when curl_easy_perform() is called. */
  633. struct digestdata digest;
  634. struct digestdata proxydigest;
  635. #ifdef HAVE_GSSAPI
  636. struct negotiatedata negotiate;
  637. #endif
  638. struct auth authhost;
  639. struct auth authproxy;
  640. bool authproblem; /* TRUE if there's some problem authenticating */
  641. #ifdef USE_ARES
  642. ares_channel areschannel; /* for name resolves */
  643. #endif
  644. };
  645. /*
  646. * This 'DynamicStatic' struct defines dynamic states that actually change
  647. * values in the 'UserDefined' area, which MUST be taken into consideration
  648. * if the UserDefined struct is cloned or similar. You can probably just
  649. * copy these, but each one indicate a special action on other data.
  650. */
  651. struct DynamicStatic {
  652. char *url; /* work URL, copied from UserDefined */
  653. bool url_alloc; /* URL string is malloc()'ed */
  654. bool url_changed; /* set on CURL_OPT_URL, used to detect if the URL was
  655. changed after the connect phase, as we allow callback
  656. to change it and if so, we reconnect to use the new
  657. URL instead */
  658. char *proxy; /* work proxy, copied from UserDefined */
  659. bool proxy_alloc; /* http proxy string is malloc()'ed */
  660. char *referer; /* referer string */
  661. bool referer_alloc; /* referer sting is malloc()ed */
  662. struct curl_slist *cookielist; /* list of cookie files set by
  663. curl_easy_setopt(COOKIEFILE) calls */
  664. };
  665. /*
  666. * This 'UserDefined' struct must only contain data that is set once to go
  667. * for many (perhaps) independent connections. Values that are generated or
  668. * calculated internally for the "session handle" MUST be defined within the
  669. * 'struct urlstate' instead. The only exceptions MUST note the changes in
  670. * the 'DynamicStatic' struct.
  671. */
  672. struct UserDefined {
  673. FILE *err; /* the stderr user data goes here */
  674. void *debugdata; /* the data that will be passed to fdebug */
  675. char *errorbuffer; /* store failure messages in here */
  676. char *proxyuserpwd; /* Proxy <user:password>, if used */
  677. long proxyport; /* If non-zero, use this port number by default. If the
  678. proxy string features a ":[port]" that one will override
  679. this. */
  680. void *out; /* the fetched file goes here */
  681. void *in; /* the uploaded file is read from here */
  682. void *writeheader; /* write the header to this is non-NULL */
  683. char *set_url; /* what original URL to work on */
  684. char *set_proxy; /* proxy to use */
  685. long use_port; /* which port to use (when not using default) */
  686. char *userpwd; /* <user:password>, if used */
  687. long httpauth; /* what kind of HTTP authentication to use (bitmask) */
  688. long proxyauth; /* what kind of proxy authentication to use (bitmask) */
  689. char *set_range; /* range, if used. See README for detailed specification
  690. on this syntax. */
  691. long followlocation; /* as in HTTP Location: */
  692. long maxredirs; /* maximum no. of http(s) redirects to follow */
  693. char *set_referer; /* custom string */
  694. bool free_referer; /* set TRUE if 'referer' points to a string we
  695. allocated */
  696. char *useragent; /* User-Agent string */
  697. char *encoding; /* Accept-Encoding string */
  698. char *postfields; /* if POST, set the fields' values here */
  699. curl_off_t postfieldsize; /* if POST, this might have a size to use instead
  700. of strlen(), and then the data *may* be binary
  701. (contain zero bytes) */
  702. char *ftpport; /* port to send with the FTP PORT command */
  703. char *device; /* network interface to use */
  704. curl_write_callback fwrite; /* function that stores the output */
  705. curl_write_callback fwrite_header; /* function that stores headers */
  706. curl_read_callback fread; /* function that reads the input */
  707. curl_progress_callback fprogress; /* function for progress information */
  708. curl_debug_callback fdebug; /* function that write informational data */
  709. void *progress_client; /* pointer to pass to the progress callback */
  710. long timeout; /* in seconds, 0 means no timeout */
  711. long connecttimeout; /* in seconds, 0 means no timeout */
  712. long ftp_response_timeout; /* in seconds, 0 means no timeout */
  713. curl_off_t infilesize; /* size of file to upload, -1 means unknown */
  714. long low_speed_limit; /* bytes/second */
  715. long low_speed_time; /* number of seconds */
  716. curl_off_t set_resume_from; /* continue [ftp] transfer from here */
  717. char *cookie; /* HTTP cookie string to send */
  718. struct curl_slist *headers; /* linked list of extra headers */
  719. struct curl_httppost *httppost; /* linked list of POST data */
  720. char *cert; /* certificate */
  721. char *cert_type; /* format for certificate (default: PEM) */
  722. char *key; /* private key */
  723. char *key_type; /* format for private key (default: PEM) */
  724. char *key_passwd; /* plain text private key password */
  725. char *crypto_engine; /* name of the crypto engine to use */
  726. char *cookiejar; /* dump all cookies to this file */
  727. bool cookiesession; /* new cookie session? */
  728. bool crlf; /* convert crlf on ftp upload(?) */
  729. struct curl_slist *quote; /* after connection is established */
  730. struct curl_slist *postquote; /* after the transfer */
  731. struct curl_slist *prequote; /* before the transfer, after type */
  732. struct curl_slist *source_prequote; /* in 3rd party transfer mode - before
  733. the transfer on source host */
  734. struct curl_slist *source_postquote; /* in 3rd party transfer mode - after
  735. the transfer on source host */
  736. struct curl_slist *telnet_options; /* linked list of telnet options */
  737. curl_TimeCond timecondition; /* kind of time/date comparison */
  738. time_t timevalue; /* what time to compare with */
  739. curl_closepolicy closepolicy; /* connection cache close concept */
  740. Curl_HttpReq httpreq; /* what kind of HTTP request (if any) is this */
  741. char *customrequest; /* HTTP/FTP request to use */
  742. long httpversion; /* when non-zero, a specific HTTP version requested to
  743. be used in the library's request(s) */
  744. char *auth_host; /* if set, this is the allocated string to the host name
  745. * to which to send the authorization data to, and no other
  746. * host (which location-following otherwise could lead to)
  747. */
  748. char *krb4_level; /* what security level */
  749. struct ssl_config_data ssl; /* user defined SSL stuff */
  750. curl_proxytype proxytype; /* what kind of proxy that is in use */
  751. int dns_cache_timeout; /* DNS cache timeout */
  752. long buffer_size; /* size of receive buffer to use */
  753. char *private; /* Private data */
  754. struct curl_slist *http200aliases; /* linked list of aliases for http200 */
  755. long ip_version;
  756. curl_off_t max_filesize; /* Maximum file size to download */
  757. char *source_host; /* for 3rd party transfer */
  758. char *source_port; /* for 3rd party transfer */
  759. char *source_userpwd; /* for 3rd party transfer */
  760. char *source_path; /* for 3rd party transfer */
  761. curl_pasv_side pasvHost; /* for 3rd party transfer indicates passive host */
  762. /* Here follows boolean settings that define how to behave during
  763. this session. They are STATIC, set by libcurl users or at least initially
  764. and they don't change during operations. */
  765. bool printhost; /* printing host name in debug info */
  766. bool get_filetime;
  767. bool tunnel_thru_httpproxy;
  768. bool ftp_append;
  769. bool ftp_ascii;
  770. bool ftp_list_only;
  771. bool ftp_create_missing_dirs;
  772. bool ftp_use_port;
  773. bool hide_progress;
  774. bool http_fail_on_error;
  775. bool http_follow_location;
  776. bool http_disable_hostname_check_before_authentication;
  777. bool include_header; /* include received protocol headers in data output */
  778. bool http_set_referer;
  779. bool http_auto_referer; /* set "correct" referer when following location: */
  780. bool opt_no_body; /* as set with CURLOPT_NO_BODY */
  781. bool set_port;
  782. bool upload;
  783. enum CURL_NETRC_OPTION
  784. use_netrc; /* defined in include/curl.h */
  785. char *netrc_file; /* if not NULL, use this instead of trying to find
  786. $HOME/.netrc */
  787. bool verbose;
  788. bool krb4; /* kerberos4 connection requested */
  789. bool reuse_forbid; /* forbidden to be reused, close after use */
  790. bool reuse_fresh; /* do not re-use an existing connection */
  791. bool expect100header; /* TRUE if we added Expect: 100-continue */
  792. bool ftp_use_epsv; /* if EPSV is to be attempted or not */
  793. bool ftp_use_eprt; /* if EPRT is to be attempted or not */
  794. curl_ftpssl ftp_ssl; /* if AUTH TLS is to be attempted etc */
  795. bool no_signal; /* do not use any signal/alarm handler */
  796. bool global_dns_cache; /* subject for future removal */
  797. bool tcp_nodelay; /* whether to enable TCP_NODELAY or not */
  798. };
  799. /*
  800. * In August 2001, this struct was redesigned and is since stricter than
  801. * before. The 'connectdata' struct MUST have all the connection oriented
  802. * stuff as we may now have several simultaneous connections and connection
  803. * structs in memory.
  804. *
  805. * From now on, the 'SessionHandle' must only contain data that is set once to
  806. * go for many (perhaps) independent connections. Values that are generated or
  807. * calculated internally for the "session handle" must be defined within the
  808. * 'struct urlstate' instead. */
  809. struct SessionHandle {
  810. curl_hash *hostcache;
  811. struct Curl_share *share; /* Share, handles global variable mutexing */
  812. struct UserDefined set; /* values set by the libcurl user */
  813. struct DynamicStatic change; /* possibly modified userdefined data */
  814. struct CookieInfo *cookies; /* the cookies, read from files and servers */
  815. struct Progress progress; /* for all the progress meter data */
  816. struct UrlState state; /* struct for fields used for state info and
  817. other dynamic purposes */
  818. struct PureInfo info; /* stats, reports and info data */
  819. #if defined(USE_SSLEAY) && defined(HAVE_OPENSSL_ENGINE_H)
  820. ENGINE* engine;
  821. #endif /* USE_SSLEAY */
  822. };
  823. #define LIBCURL_NAME "libcurl"
  824. #endif