urldata.h 62 KB

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