urldata.h 34 KB

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