urldata.h 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839
  1. #ifndef HEADER_CURL_URLDATA_H
  2. #define HEADER_CURL_URLDATA_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2017, 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 https://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. ***************************************************************************/
  24. /* This file is for lib internal stuff */
  25. #include "curl_setup.h"
  26. #define PORT_FTP 21
  27. #define PORT_FTPS 990
  28. #define PORT_TELNET 23
  29. #define PORT_HTTP 80
  30. #define PORT_HTTPS 443
  31. #define PORT_DICT 2628
  32. #define PORT_LDAP 389
  33. #define PORT_LDAPS 636
  34. #define PORT_TFTP 69
  35. #define PORT_SSH 22
  36. #define PORT_IMAP 143
  37. #define PORT_IMAPS 993
  38. #define PORT_POP3 110
  39. #define PORT_POP3S 995
  40. #define PORT_SMB 445
  41. #define PORT_SMBS 445
  42. #define PORT_SMTP 25
  43. #define PORT_SMTPS 465 /* sometimes called SSMTP */
  44. #define PORT_RTSP 554
  45. #define PORT_RTMP 1935
  46. #define PORT_RTMPT PORT_HTTP
  47. #define PORT_RTMPS PORT_HTTPS
  48. #define PORT_GOPHER 70
  49. #define DICT_MATCH "/MATCH:"
  50. #define DICT_MATCH2 "/M:"
  51. #define DICT_MATCH3 "/FIND:"
  52. #define DICT_DEFINE "/DEFINE:"
  53. #define DICT_DEFINE2 "/D:"
  54. #define DICT_DEFINE3 "/LOOKUP:"
  55. #define CURL_DEFAULT_USER "anonymous"
  56. #define CURL_DEFAULT_PASSWORD "[email protected]"
  57. /* Convenience defines for checking protocols or their SSL based version. Each
  58. protocol handler should only ever have a single CURLPROTO_ in its protocol
  59. field. */
  60. #define PROTO_FAMILY_HTTP (CURLPROTO_HTTP|CURLPROTO_HTTPS)
  61. #define PROTO_FAMILY_FTP (CURLPROTO_FTP|CURLPROTO_FTPS)
  62. #define PROTO_FAMILY_POP3 (CURLPROTO_POP3|CURLPROTO_POP3S)
  63. #define PROTO_FAMILY_SMB (CURLPROTO_SMB|CURLPROTO_SMBS)
  64. #define PROTO_FAMILY_SMTP (CURLPROTO_SMTP|CURLPROTO_SMTPS)
  65. #define DEFAULT_CONNCACHE_SIZE 5
  66. /* length of longest IPv6 address string including the trailing null */
  67. #define MAX_IPADR_LEN sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")
  68. /* Default FTP/IMAP etc response timeout in milliseconds.
  69. Symbian OS panics when given a timeout much greater than 1/2 hour.
  70. */
  71. #define RESP_TIMEOUT (1800*1000)
  72. #include "cookie.h"
  73. #include "formdata.h"
  74. #ifdef USE_OPENSSL
  75. #include <openssl/ssl.h>
  76. #ifdef HAVE_OPENSSL_ENGINE_H
  77. #include <openssl/engine.h>
  78. #endif
  79. #endif /* USE_OPENSSL */
  80. #ifdef USE_GNUTLS
  81. #include <gnutls/gnutls.h>
  82. #endif
  83. #ifdef USE_MBEDTLS
  84. #include <mbedtls/ssl.h>
  85. #include <mbedtls/version.h>
  86. #include <mbedtls/entropy.h>
  87. #include <mbedtls/ctr_drbg.h>
  88. #elif defined USE_POLARSSL
  89. #include <polarssl/ssl.h>
  90. #include <polarssl/version.h>
  91. #if POLARSSL_VERSION_NUMBER<0x01010000
  92. #include <polarssl/havege.h>
  93. #else
  94. #include <polarssl/entropy.h>
  95. #include <polarssl/ctr_drbg.h>
  96. #endif /* POLARSSL_VERSION_NUMBER<0x01010000 */
  97. #endif /* USE_POLARSSL */
  98. #ifdef USE_CYASSL
  99. #undef OCSP_REQUEST /* avoid cyassl/openssl/ssl.h clash with wincrypt.h */
  100. #undef OCSP_RESPONSE /* avoid cyassl/openssl/ssl.h clash with wincrypt.h */
  101. #include <cyassl/openssl/ssl.h>
  102. #endif
  103. #ifdef USE_NSS
  104. #include <nspr.h>
  105. #include <pk11pub.h>
  106. #endif
  107. #ifdef USE_GSKIT
  108. #include <gskssl.h>
  109. #endif
  110. #ifdef USE_AXTLS
  111. #include <axTLS/config.h>
  112. #include <axTLS/ssl.h>
  113. #undef malloc
  114. #undef calloc
  115. #undef realloc
  116. #endif /* USE_AXTLS */
  117. #if defined(USE_SCHANNEL) || defined(USE_WINDOWS_SSPI)
  118. #include "curl_sspi.h"
  119. #endif
  120. #ifdef USE_SCHANNEL
  121. #include <schnlsp.h>
  122. #include <schannel.h>
  123. #endif
  124. #ifdef USE_DARWINSSL
  125. #include <Security/Security.h>
  126. /* For some reason, when building for iOS, the omnibus header above does
  127. * not include SecureTransport.h as of iOS SDK 5.1. */
  128. #include <Security/SecureTransport.h>
  129. #endif
  130. #ifdef HAVE_NETINET_IN_H
  131. #include <netinet/in.h>
  132. #endif
  133. #include "timeval.h"
  134. #ifdef HAVE_ZLIB_H
  135. #include <zlib.h> /* for content-encoding */
  136. #ifdef __SYMBIAN32__
  137. /* zlib pollutes the namespace with this definition */
  138. #undef WIN32
  139. #endif
  140. #endif
  141. #include <curl/curl.h>
  142. #include "http_chunks.h" /* for the structs and enum stuff */
  143. #include "hostip.h"
  144. #include "hash.h"
  145. #include "splay.h"
  146. #include "imap.h"
  147. #include "pop3.h"
  148. #include "smtp.h"
  149. #include "ftp.h"
  150. #include "file.h"
  151. #include "ssh.h"
  152. #include "http.h"
  153. #include "rtsp.h"
  154. #include "smb.h"
  155. #include "wildcard.h"
  156. #include "multihandle.h"
  157. #ifdef HAVE_GSSAPI
  158. # ifdef HAVE_GSSGNU
  159. # include <gss.h>
  160. # elif defined HAVE_GSSMIT
  161. # include <gssapi/gssapi.h>
  162. # include <gssapi/gssapi_generic.h>
  163. # else
  164. # include <gssapi.h>
  165. # endif
  166. #endif
  167. #ifdef HAVE_LIBSSH2_H
  168. #include <libssh2.h>
  169. #include <libssh2_sftp.h>
  170. #endif /* HAVE_LIBSSH2_H */
  171. /* Download buffer size, keep it fairly big for speed reasons */
  172. #undef BUFSIZE
  173. #define BUFSIZE CURL_MAX_WRITE_SIZE
  174. #undef MAX_BUFSIZE
  175. #define MAX_BUFSIZE CURL_MAX_READ_SIZE
  176. #define CURL_BUFSIZE(x) ((x)?(x):(BUFSIZE))
  177. /* Initial size of the buffer to store headers in, it'll be enlarged in case
  178. of need. */
  179. #define HEADERSIZE 256
  180. #define CURLEASY_MAGIC_NUMBER 0xc0dedbadU
  181. #define GOOD_EASY_HANDLE(x) \
  182. ((x) && ((x)->magic == CURLEASY_MAGIC_NUMBER))
  183. /* Some convenience macros to get the larger/smaller value out of two given.
  184. We prefix with CURL to prevent name collisions. */
  185. #define CURLMAX(x,y) ((x)>(y)?(x):(y))
  186. #define CURLMIN(x,y) ((x)<(y)?(x):(y))
  187. #ifdef HAVE_GSSAPI
  188. /* Types needed for krb5-ftp connections */
  189. struct krb5buffer {
  190. void *data;
  191. size_t size;
  192. size_t index;
  193. int eof_flag;
  194. };
  195. enum protection_level {
  196. PROT_NONE, /* first in list */
  197. PROT_CLEAR,
  198. PROT_SAFE,
  199. PROT_CONFIDENTIAL,
  200. PROT_PRIVATE,
  201. PROT_CMD,
  202. PROT_LAST /* last in list */
  203. };
  204. #endif
  205. #ifdef USE_SCHANNEL
  206. /* Structs to store Schannel handles */
  207. struct curl_schannel_cred {
  208. CredHandle cred_handle;
  209. TimeStamp time_stamp;
  210. int refcount;
  211. };
  212. struct curl_schannel_ctxt {
  213. CtxtHandle ctxt_handle;
  214. TimeStamp time_stamp;
  215. };
  216. #endif
  217. /* enum for the nonblocking SSL connection state machine */
  218. typedef enum {
  219. ssl_connect_1,
  220. ssl_connect_2,
  221. ssl_connect_2_reading,
  222. ssl_connect_2_writing,
  223. ssl_connect_3,
  224. ssl_connect_done
  225. } ssl_connect_state;
  226. typedef enum {
  227. ssl_connection_none,
  228. ssl_connection_negotiating,
  229. ssl_connection_complete
  230. } ssl_connection_state;
  231. /* struct for data related to each SSL connection */
  232. struct ssl_connect_data {
  233. /* Use ssl encrypted communications TRUE/FALSE, not necessarily using it atm
  234. but at least asked to or meaning to use it. See 'state' for the exact
  235. current state of the connection. */
  236. bool use;
  237. ssl_connection_state state;
  238. ssl_connect_state connecting_state;
  239. #if defined(USE_OPENSSL)
  240. /* these ones requires specific SSL-types */
  241. SSL_CTX* ctx;
  242. SSL* handle;
  243. X509* server_cert;
  244. #elif defined(USE_GNUTLS)
  245. gnutls_session_t session;
  246. gnutls_certificate_credentials_t cred;
  247. #ifdef USE_TLS_SRP
  248. gnutls_srp_client_credentials_t srp_client_cred;
  249. #endif
  250. #elif defined(USE_MBEDTLS)
  251. mbedtls_ctr_drbg_context ctr_drbg;
  252. mbedtls_entropy_context entropy;
  253. mbedtls_ssl_context ssl;
  254. int server_fd;
  255. mbedtls_x509_crt cacert;
  256. mbedtls_x509_crt clicert;
  257. mbedtls_x509_crl crl;
  258. mbedtls_pk_context pk;
  259. mbedtls_ssl_config config;
  260. const char *protocols[3];
  261. #elif defined(USE_POLARSSL)
  262. ctr_drbg_context ctr_drbg;
  263. entropy_context entropy;
  264. ssl_context ssl;
  265. int server_fd;
  266. x509_crt cacert;
  267. x509_crt clicert;
  268. x509_crl crl;
  269. rsa_context rsa;
  270. #elif defined(USE_CYASSL)
  271. SSL_CTX* ctx;
  272. SSL* handle;
  273. #elif defined(USE_NSS)
  274. PRFileDesc *handle;
  275. char *client_nickname;
  276. struct Curl_easy *data;
  277. struct curl_llist *obj_list;
  278. PK11GenericObject *obj_clicert;
  279. #elif defined(USE_GSKIT)
  280. gsk_handle handle;
  281. int iocport;
  282. int localfd;
  283. int remotefd;
  284. #elif defined(USE_AXTLS)
  285. SSL_CTX* ssl_ctx;
  286. SSL* ssl;
  287. #elif defined(USE_SCHANNEL)
  288. struct curl_schannel_cred *cred;
  289. struct curl_schannel_ctxt *ctxt;
  290. SecPkgContext_StreamSizes stream_sizes;
  291. size_t encdata_length, decdata_length;
  292. size_t encdata_offset, decdata_offset;
  293. unsigned char *encdata_buffer, *decdata_buffer;
  294. unsigned long req_flags, ret_flags;
  295. CURLcode recv_unrecoverable_err; /* schannel_recv had an unrecoverable err */
  296. bool recv_sspi_close_notify; /* true if connection closed by close_notify */
  297. bool recv_connection_closed; /* true if connection closed, regardless how */
  298. bool use_alpn; /* true if ALPN is used for this connection */
  299. #elif defined(USE_DARWINSSL)
  300. SSLContextRef ssl_ctx;
  301. curl_socket_t ssl_sockfd;
  302. bool ssl_direction; /* true if writing, false if reading */
  303. size_t ssl_write_buffered_length;
  304. #elif defined(USE_SSL)
  305. #error "SSL backend specific information missing from ssl_connect_data"
  306. #endif
  307. };
  308. struct ssl_primary_config {
  309. long version; /* what version the client wants to use */
  310. bool verifypeer; /* set TRUE if this is desired */
  311. bool verifyhost; /* set TRUE if CN/SAN must match hostname */
  312. bool verifystatus; /* set TRUE if certificate status must be checked */
  313. char *CApath; /* certificate dir (doesn't work on windows) */
  314. char *CAfile; /* certificate to verify peer against */
  315. char *clientcert;
  316. char *random_file; /* path to file containing "random" data */
  317. char *egdsocket; /* path to file containing the EGD daemon socket */
  318. char *cipher_list; /* list of ciphers to use */
  319. };
  320. struct ssl_config_data {
  321. struct ssl_primary_config primary;
  322. bool enable_beast; /* especially allow this flaw for interoperability's
  323. sake*/
  324. bool no_revoke; /* disable SSL certificate revocation checks */
  325. long certverifyresult; /* result from the certificate verification */
  326. char *CRLfile; /* CRL to check certificate revocation */
  327. char *issuercert;/* optional issuer certificate filename */
  328. curl_ssl_ctx_callback fsslctx; /* function to initialize ssl ctx */
  329. void *fsslctxp; /* parameter for call back */
  330. bool certinfo; /* gather lots of certificate info */
  331. bool falsestart;
  332. char *cert; /* client certificate file name */
  333. char *cert_type; /* format for certificate (default: PEM)*/
  334. char *key; /* private key file name */
  335. char *key_type; /* format for private key (default: PEM) */
  336. char *key_passwd; /* plain text private key password */
  337. #ifdef USE_TLS_SRP
  338. char *username; /* TLS username (for, e.g., SRP) */
  339. char *password; /* TLS password (for, e.g., SRP) */
  340. enum CURL_TLSAUTH authtype; /* TLS authentication type (default SRP) */
  341. #endif
  342. };
  343. struct ssl_general_config {
  344. bool sessionid; /* cache session IDs or not */
  345. size_t max_ssl_sessions; /* SSL session id cache size */
  346. };
  347. /* information stored about one single SSL session */
  348. struct curl_ssl_session {
  349. char *name; /* host name for which this ID was used */
  350. char *conn_to_host; /* host name for the connection (may be NULL) */
  351. const char *scheme; /* protocol scheme used */
  352. void *sessionid; /* as returned from the SSL layer */
  353. size_t idsize; /* if known, otherwise 0 */
  354. long age; /* just a number, the higher the more recent */
  355. int remote_port; /* remote port */
  356. int conn_to_port; /* remote port for the connection (may be -1) */
  357. struct ssl_primary_config ssl_config; /* setup for this session */
  358. };
  359. /* Struct used for Digest challenge-response authentication */
  360. struct digestdata {
  361. #if defined(USE_WINDOWS_SSPI)
  362. BYTE *input_token;
  363. size_t input_token_len;
  364. CtxtHandle *http_context;
  365. #else
  366. char *nonce;
  367. char *cnonce;
  368. char *realm;
  369. int algo;
  370. bool stale; /* set true for re-negotiation */
  371. char *opaque;
  372. char *qop;
  373. char *algorithm;
  374. int nc; /* nounce count */
  375. #endif
  376. };
  377. typedef enum {
  378. NTLMSTATE_NONE,
  379. NTLMSTATE_TYPE1,
  380. NTLMSTATE_TYPE2,
  381. NTLMSTATE_TYPE3,
  382. NTLMSTATE_LAST
  383. } curlntlm;
  384. #ifdef USE_WINDOWS_SSPI
  385. #include "curl_sspi.h"
  386. #endif
  387. #if defined(CURL_DOES_CONVERSIONS) && defined(HAVE_ICONV)
  388. #include <iconv.h>
  389. #endif
  390. /* Struct used for GSSAPI (Kerberos V5) authentication */
  391. #if defined(USE_KERBEROS5)
  392. struct kerberos5data {
  393. #if defined(USE_WINDOWS_SSPI)
  394. CredHandle *credentials;
  395. CtxtHandle *context;
  396. TCHAR *spn;
  397. SEC_WINNT_AUTH_IDENTITY identity;
  398. SEC_WINNT_AUTH_IDENTITY *p_identity;
  399. size_t token_max;
  400. BYTE *output_token;
  401. #else
  402. gss_ctx_id_t context;
  403. gss_name_t spn;
  404. #endif
  405. };
  406. #endif
  407. /* Struct used for NTLM challenge-response authentication */
  408. #if defined(USE_NTLM)
  409. struct ntlmdata {
  410. curlntlm state;
  411. #ifdef USE_WINDOWS_SSPI
  412. CredHandle *credentials;
  413. CtxtHandle *context;
  414. SEC_WINNT_AUTH_IDENTITY identity;
  415. SEC_WINNT_AUTH_IDENTITY *p_identity;
  416. size_t token_max;
  417. BYTE *output_token;
  418. BYTE *input_token;
  419. size_t input_token_len;
  420. #else
  421. unsigned int flags;
  422. unsigned char nonce[8];
  423. void *target_info; /* TargetInfo received in the ntlm type-2 message */
  424. unsigned int target_info_len;
  425. #endif
  426. };
  427. #endif
  428. #ifdef USE_SPNEGO
  429. struct negotiatedata {
  430. /* When doing Negotiate (SPNEGO) auth, we first need to send a token
  431. and then validate the received one. */
  432. enum { GSS_AUTHNONE, GSS_AUTHRECV, GSS_AUTHSENT } state;
  433. #ifdef HAVE_GSSAPI
  434. OM_uint32 status;
  435. gss_ctx_id_t context;
  436. gss_name_t spn;
  437. gss_buffer_desc output_token;
  438. #else
  439. #ifdef USE_WINDOWS_SSPI
  440. DWORD status;
  441. CredHandle *credentials;
  442. CtxtHandle *context;
  443. SEC_WINNT_AUTH_IDENTITY identity;
  444. SEC_WINNT_AUTH_IDENTITY *p_identity;
  445. TCHAR *spn;
  446. size_t token_max;
  447. BYTE *output_token;
  448. size_t output_token_length;
  449. #endif
  450. #endif
  451. };
  452. #endif
  453. /*
  454. * Boolean values that concerns this connection.
  455. */
  456. struct ConnectBits {
  457. /* always modify bits.close with the connclose() and connkeep() macros! */
  458. bool close; /* if set, we close the connection after this request */
  459. bool reuse; /* if set, this is a re-used connection */
  460. bool conn_to_host; /* if set, this connection has a "connect to host"
  461. that overrides the host in the URL */
  462. bool conn_to_port; /* if set, this connection has a "connect to port"
  463. that overrides the port in the URL (remote port) */
  464. bool proxy; /* if set, this transfer is done through a proxy - any type */
  465. bool httpproxy; /* if set, this transfer is done through a http proxy */
  466. bool socksproxy; /* if set, this transfer is done through a socks proxy */
  467. bool user_passwd; /* do we use user+password for this connection? */
  468. bool proxy_user_passwd; /* user+password for the proxy? */
  469. bool ipv6_ip; /* we communicate with a remote site specified with pure IPv6
  470. IP address */
  471. bool ipv6; /* we communicate with a site using an IPv6 address */
  472. bool do_more; /* this is set TRUE if the ->curl_do_more() function is
  473. supposed to be called, after ->curl_do() */
  474. bool tcpconnect[2]; /* the TCP layer (or similar) is connected, this is set
  475. the first time on the first connect function call */
  476. bool protoconnstart;/* the protocol layer has STARTED its operation after
  477. the TCP layer connect */
  478. bool retry; /* this connection is about to get closed and then
  479. re-attempted at another connection. */
  480. bool tunnel_proxy; /* if CONNECT is used to "tunnel" through the proxy.
  481. This is implicit when SSL-protocols are used through
  482. proxies, but can also be enabled explicitly by
  483. apps */
  484. bool authneg; /* TRUE when the auth phase has started, which means
  485. that we are creating a request with an auth header,
  486. but it is not the final request in the auth
  487. negotiation. */
  488. bool rewindaftersend;/* TRUE when the sending couldn't be stopped even
  489. though it will be discarded. When the whole send
  490. operation is done, we must call the data rewind
  491. callback. */
  492. bool ftp_use_epsv; /* As set with CURLOPT_FTP_USE_EPSV, but if we find out
  493. EPSV doesn't work we disable it for the forthcoming
  494. requests */
  495. bool ftp_use_eprt; /* As set with CURLOPT_FTP_USE_EPRT, but if we find out
  496. EPRT doesn't work we disable it for the forthcoming
  497. requests */
  498. bool ftp_use_data_ssl; /* Enabled SSL for the data connection */
  499. bool netrc; /* name+password provided by netrc */
  500. bool userpwd_in_url; /* name+password found in url */
  501. bool stream_was_rewound; /* Indicates that the stream was rewound after a
  502. request read past the end of its response byte
  503. boundary */
  504. bool proxy_connect_closed; /* set true if a proxy disconnected the
  505. connection in a CONNECT request with auth, so
  506. that libcurl should reconnect and continue. */
  507. bool bound; /* set true if bind() has already been done on this socket/
  508. connection */
  509. bool type_set; /* type= was used in the URL */
  510. bool multiplex; /* connection is multiplexed */
  511. bool tcp_fastopen; /* use TCP Fast Open */
  512. bool tls_enable_npn; /* TLS NPN extension? */
  513. bool tls_enable_alpn; /* TLS ALPN extension? */
  514. bool proxy_ssl_connected[2]; /* TRUE when SSL initialization for HTTPS proxy
  515. is complete */
  516. bool socksproxy_connecting; /* connecting through a socks proxy */
  517. };
  518. struct hostname {
  519. char *rawalloc; /* allocated "raw" version of the name */
  520. char *encalloc; /* allocated IDN-encoded version of the name */
  521. char *name; /* name to use internally, might be encoded, might be raw */
  522. const char *dispname; /* name to display, as 'name' might be encoded */
  523. };
  524. /*
  525. * Flags on the keepon member of the Curl_transfer_keeper
  526. */
  527. #define KEEP_NONE 0
  528. #define KEEP_RECV (1<<0) /* there is or may be data to read */
  529. #define KEEP_SEND (1<<1) /* there is or may be data to write */
  530. #define KEEP_RECV_HOLD (1<<2) /* when set, no reading should be done but there
  531. might still be data to read */
  532. #define KEEP_SEND_HOLD (1<<3) /* when set, no writing should be done but there
  533. might still be data to write */
  534. #define KEEP_RECV_PAUSE (1<<4) /* reading is paused */
  535. #define KEEP_SEND_PAUSE (1<<5) /* writing is paused */
  536. #define KEEP_RECVBITS (KEEP_RECV | KEEP_RECV_HOLD | KEEP_RECV_PAUSE)
  537. #define KEEP_SENDBITS (KEEP_SEND | KEEP_SEND_HOLD | KEEP_SEND_PAUSE)
  538. #ifdef HAVE_LIBZ
  539. typedef enum {
  540. ZLIB_UNINIT, /* uninitialized */
  541. ZLIB_INIT, /* initialized */
  542. ZLIB_GZIP_HEADER, /* reading gzip header */
  543. ZLIB_GZIP_INFLATING, /* inflating gzip stream */
  544. ZLIB_INIT_GZIP /* initialized in transparent gzip mode */
  545. } zlibInitState;
  546. #endif
  547. #ifdef CURLRES_ASYNCH
  548. struct Curl_async {
  549. char *hostname;
  550. int port;
  551. struct Curl_dns_entry *dns;
  552. bool done; /* set TRUE when the lookup is complete */
  553. int status; /* if done is TRUE, this is the status from the callback */
  554. void *os_specific; /* 'struct thread_data' for Windows */
  555. };
  556. #endif
  557. #define FIRSTSOCKET 0
  558. #define SECONDARYSOCKET 1
  559. /* These function pointer types are here only to allow easier typecasting
  560. within the source when we need to cast between data pointers (such as NULL)
  561. and function pointers. */
  562. typedef CURLcode (*Curl_do_more_func)(struct connectdata *, int *);
  563. typedef CURLcode (*Curl_done_func)(struct connectdata *, CURLcode, bool);
  564. enum expect100 {
  565. EXP100_SEND_DATA, /* enough waiting, just send the body now */
  566. EXP100_AWAITING_CONTINUE, /* waiting for the 100 Continue header */
  567. EXP100_SENDING_REQUEST, /* still sending the request but will wait for
  568. the 100 header once done with the request */
  569. EXP100_FAILED /* used on 417 Expectation Failed */
  570. };
  571. enum upgrade101 {
  572. UPGR101_INIT, /* default state */
  573. UPGR101_REQUESTED, /* upgrade requested */
  574. UPGR101_RECEIVED, /* response received */
  575. UPGR101_WORKING /* talking upgraded protocol */
  576. };
  577. /*
  578. * Request specific data in the easy handle (Curl_easy). Previously,
  579. * these members were on the connectdata struct but since a conn struct may
  580. * now be shared between different Curl_easys, we store connection-specific
  581. * data here. This struct only keeps stuff that's interesting for *this*
  582. * request, as it will be cleared between multiple ones
  583. */
  584. struct SingleRequest {
  585. curl_off_t size; /* -1 if unknown at this point */
  586. curl_off_t *bytecountp; /* return number of bytes read or NULL */
  587. curl_off_t maxdownload; /* in bytes, the maximum amount of data to fetch,
  588. -1 means unlimited */
  589. curl_off_t *writebytecountp; /* return number of bytes written or NULL */
  590. curl_off_t bytecount; /* total number of bytes read */
  591. curl_off_t writebytecount; /* number of bytes written */
  592. long headerbytecount; /* only count received headers */
  593. long deductheadercount; /* this amount of bytes doesn't count when we check
  594. if anything has been transferred at the end of a
  595. connection. We use this counter to make only a
  596. 100 reply (without a following second response
  597. code) result in a CURLE_GOT_NOTHING error code */
  598. struct timeval start; /* transfer started at this time */
  599. struct timeval now; /* current time */
  600. bool header; /* incoming data has HTTP header */
  601. enum {
  602. HEADER_NORMAL, /* no bad header at all */
  603. HEADER_PARTHEADER, /* part of the chunk is a bad header, the rest
  604. is normal data */
  605. HEADER_ALLBAD /* all was believed to be header */
  606. } badheader; /* the header was deemed bad and will be
  607. written as body */
  608. int headerline; /* counts header lines to better track the
  609. first one */
  610. char *hbufp; /* points at *end* of header line */
  611. size_t hbuflen;
  612. char *str; /* within buf */
  613. char *str_start; /* within buf */
  614. char *end_ptr; /* within buf */
  615. char *p; /* within headerbuff */
  616. bool content_range; /* set TRUE if Content-Range: was found */
  617. curl_off_t offset; /* possible resume offset read from the
  618. Content-Range: header */
  619. int httpcode; /* error code from the 'HTTP/1.? XXX' or
  620. 'RTSP/1.? XXX' line */
  621. struct timeval start100; /* time stamp to wait for the 100 code from */
  622. enum expect100 exp100; /* expect 100 continue state */
  623. enum upgrade101 upgr101; /* 101 upgrade state */
  624. int auto_decoding; /* What content encoding. sec 3.5, RFC2616. */
  625. #define IDENTITY 0 /* No encoding */
  626. #define DEFLATE 1 /* zlib deflate [RFC 1950 & 1951] */
  627. #define GZIP 2 /* gzip algorithm [RFC 1952] */
  628. #ifdef HAVE_LIBZ
  629. zlibInitState zlib_init; /* possible zlib init state;
  630. undefined if Content-Encoding header. */
  631. z_stream z; /* State structure for zlib. */
  632. #endif
  633. time_t timeofdoc;
  634. long bodywrites;
  635. char *buf;
  636. char *uploadbuf;
  637. curl_socket_t maxfd;
  638. int keepon;
  639. bool upload_done; /* set to TRUE when doing chunked transfer-encoding upload
  640. and we're uploading the last chunk */
  641. bool ignorebody; /* we read a response-body but we ignore it! */
  642. bool ignorecl; /* This HTTP response has no body so we ignore the Content-
  643. Length: header */
  644. char *location; /* This points to an allocated version of the Location:
  645. header data */
  646. char *newurl; /* Set to the new URL to use when a redirect or a retry is
  647. wanted */
  648. /* 'upload_present' is used to keep a byte counter of how much data there is
  649. still left in the buffer, aimed for upload. */
  650. ssize_t upload_present;
  651. /* 'upload_fromhere' is used as a read-pointer when we uploaded parts of a
  652. buffer, so the next read should read from where this pointer points to,
  653. and the 'upload_present' contains the number of bytes available at this
  654. position */
  655. char *upload_fromhere;
  656. bool chunk; /* if set, this is a chunked transfer-encoding */
  657. bool upload_chunky; /* set TRUE if we are doing chunked transfer-encoding
  658. on upload */
  659. bool getheader; /* TRUE if header parsing is wanted */
  660. bool forbidchunk; /* used only to explicitly forbid chunk-upload for
  661. specific upload buffers. See readmoredata() in
  662. http.c for details. */
  663. void *protop; /* Allocated protocol-specific data. Each protocol
  664. handler makes sure this points to data it needs. */
  665. };
  666. /*
  667. * Specific protocol handler.
  668. */
  669. struct Curl_handler {
  670. const char *scheme; /* URL scheme name. */
  671. /* Complement to setup_connection_internals(). */
  672. CURLcode (*setup_connection)(struct connectdata *);
  673. /* These two functions MUST be set to be protocol dependent */
  674. CURLcode (*do_it)(struct connectdata *, bool *done);
  675. Curl_done_func done;
  676. /* If the curl_do() function is better made in two halves, this
  677. * curl_do_more() function will be called afterwards, if set. For example
  678. * for doing the FTP stuff after the PASV/PORT command.
  679. */
  680. Curl_do_more_func do_more;
  681. /* This function *MAY* be set to a protocol-dependent function that is run
  682. * after the connect() and everything is done, as a step in the connection.
  683. * The 'done' pointer points to a bool that should be set to TRUE if the
  684. * function completes before return. If it doesn't complete, the caller
  685. * should call the curl_connecting() function until it is.
  686. */
  687. CURLcode (*connect_it)(struct connectdata *, bool *done);
  688. /* See above. Currently only used for FTP. */
  689. CURLcode (*connecting)(struct connectdata *, bool *done);
  690. CURLcode (*doing)(struct connectdata *, bool *done);
  691. /* Called from the multi interface during the PROTOCONNECT phase, and it
  692. should then return a proper fd set */
  693. int (*proto_getsock)(struct connectdata *conn,
  694. curl_socket_t *socks,
  695. int numsocks);
  696. /* Called from the multi interface during the DOING phase, and it should
  697. then return a proper fd set */
  698. int (*doing_getsock)(struct connectdata *conn,
  699. curl_socket_t *socks,
  700. int numsocks);
  701. /* Called from the multi interface during the DO_MORE phase, and it should
  702. then return a proper fd set */
  703. int (*domore_getsock)(struct connectdata *conn,
  704. curl_socket_t *socks,
  705. int numsocks);
  706. /* Called from the multi interface during the DO_DONE, PERFORM and
  707. WAITPERFORM phases, and it should then return a proper fd set. Not setting
  708. this will make libcurl use the generic default one. */
  709. int (*perform_getsock)(const struct connectdata *conn,
  710. curl_socket_t *socks,
  711. int numsocks);
  712. /* This function *MAY* be set to a protocol-dependent function that is run
  713. * by the curl_disconnect(), as a step in the disconnection. If the handler
  714. * is called because the connection has been considered dead, dead_connection
  715. * is set to TRUE.
  716. */
  717. CURLcode (*disconnect)(struct connectdata *, bool dead_connection);
  718. /* If used, this function gets called from transfer.c:readwrite_data() to
  719. allow the protocol to do extra reads/writes */
  720. CURLcode (*readwrite)(struct Curl_easy *data, struct connectdata *conn,
  721. ssize_t *nread, bool *readmore);
  722. long defport; /* Default port. */
  723. unsigned int protocol; /* See CURLPROTO_* - this needs to be the single
  724. specific protocol bit */
  725. unsigned int flags; /* Extra particular characteristics, see PROTOPT_* */
  726. };
  727. #define PROTOPT_NONE 0 /* nothing extra */
  728. #define PROTOPT_SSL (1<<0) /* uses SSL */
  729. #define PROTOPT_DUAL (1<<1) /* this protocol uses two connections */
  730. #define PROTOPT_CLOSEACTION (1<<2) /* need action before socket close */
  731. /* some protocols will have to call the underlying functions without regard to
  732. what exact state the socket signals. IE even if the socket says "readable",
  733. the send function might need to be called while uploading, or vice versa.
  734. */
  735. #define PROTOPT_DIRLOCK (1<<3)
  736. #define PROTOPT_NONETWORK (1<<4) /* protocol doesn't use the network! */
  737. #define PROTOPT_NEEDSPWD (1<<5) /* needs a password, and if none is set it
  738. gets a default */
  739. #define PROTOPT_NOURLQUERY (1<<6) /* protocol can't handle
  740. url query strings (?foo=bar) ! */
  741. #define PROTOPT_CREDSPERREQUEST (1<<7) /* requires login credentials per
  742. request instead of per connection */
  743. #define PROTOPT_ALPN_NPN (1<<8) /* set ALPN and/or NPN for this */
  744. #define PROTOPT_STREAM (1<<9) /* a protocol with individual logical streams */
  745. #define PROTOPT_URLOPTIONS (1<<10) /* allow options part in the userinfo field
  746. of the URL */
  747. /* return the count of bytes sent, or -1 on error */
  748. typedef ssize_t (Curl_send)(struct connectdata *conn, /* connection data */
  749. int sockindex, /* socketindex */
  750. const void *buf, /* data to write */
  751. size_t len, /* max amount to write */
  752. CURLcode *err); /* error to return */
  753. /* return the count of bytes read, or -1 on error */
  754. typedef ssize_t (Curl_recv)(struct connectdata *conn, /* connection data */
  755. int sockindex, /* socketindex */
  756. char *buf, /* store data here */
  757. size_t len, /* max amount to read */
  758. CURLcode *err); /* error to return */
  759. #ifdef USE_RECV_BEFORE_SEND_WORKAROUND
  760. struct postponed_data {
  761. char *buffer; /* Temporal store for received data during
  762. sending, must be freed */
  763. size_t allocated_size; /* Size of temporal store */
  764. size_t recv_size; /* Size of received data during sending */
  765. size_t recv_processed; /* Size of processed part of postponed data */
  766. #ifdef DEBUGBUILD
  767. curl_socket_t bindsock;/* Structure must be bound to specific socket,
  768. used only for DEBUGASSERT */
  769. #endif /* DEBUGBUILD */
  770. };
  771. #endif /* USE_RECV_BEFORE_SEND_WORKAROUND */
  772. struct proxy_info {
  773. struct hostname host;
  774. long port;
  775. curl_proxytype proxytype; /* what kind of proxy that is in use */
  776. char *user; /* proxy user name string, allocated */
  777. char *passwd; /* proxy password string, allocated */
  778. };
  779. /*
  780. * The connectdata struct contains all fields and variables that should be
  781. * unique for an entire connection.
  782. */
  783. struct connectdata {
  784. /* 'data' is the CURRENT Curl_easy using this connection -- take great
  785. caution that this might very well vary between different times this
  786. connection is used! */
  787. struct Curl_easy *data;
  788. /* chunk is for HTTP chunked encoding, but is in the general connectdata
  789. struct only because we can do just about any protocol through a HTTP proxy
  790. and a HTTP proxy may in fact respond using chunked encoding */
  791. struct Curl_chunker chunk;
  792. curl_closesocket_callback fclosesocket; /* function closing the socket(s) */
  793. void *closesocket_client;
  794. bool inuse; /* This is a marker for the connection cache logic. If this is
  795. TRUE this handle is being used by an easy handle and cannot
  796. be used by any other easy handle without careful
  797. consideration (== only for pipelining). */
  798. /**** Fields set when inited and not modified again */
  799. long connection_id; /* Contains a unique number to make it easier to
  800. track the connections in the log output */
  801. /* 'dns_entry' is the particular host we use. This points to an entry in the
  802. DNS cache and it will not get pruned while locked. It gets unlocked in
  803. Curl_done(). This entry will be NULL if the connection is re-used as then
  804. there is no name resolve done. */
  805. struct Curl_dns_entry *dns_entry;
  806. /* 'ip_addr' is the particular IP we connected to. It points to a struct
  807. within the DNS cache, so this pointer is only valid as long as the DNS
  808. cache entry remains locked. It gets unlocked in Curl_done() */
  809. Curl_addrinfo *ip_addr;
  810. Curl_addrinfo *tempaddr[2]; /* for happy eyeballs */
  811. /* 'ip_addr_str' is the ip_addr data as a human readable string.
  812. It remains available as long as the connection does, which is longer than
  813. the ip_addr itself. */
  814. char ip_addr_str[MAX_IPADR_LEN];
  815. unsigned int scope_id; /* Scope id for IPv6 */
  816. int socktype; /* SOCK_STREAM or SOCK_DGRAM */
  817. struct hostname host;
  818. char *secondaryhostname; /* secondary socket host name (ftp) */
  819. struct hostname conn_to_host; /* the host to connect to. valid only if
  820. bits.conn_to_host is set */
  821. struct proxy_info socks_proxy;
  822. struct proxy_info http_proxy;
  823. long port; /* which port to use locally */
  824. int remote_port; /* the remote port, not the proxy port! */
  825. int conn_to_port; /* the remote port to connect to. valid only if
  826. bits.conn_to_port is set */
  827. unsigned short secondary_port; /* secondary socket remote port to connect to
  828. (ftp) */
  829. /* 'primary_ip' and 'primary_port' get filled with peer's numerical
  830. ip address and port number whenever an outgoing connection is
  831. *attempted* from the primary socket to a remote address. When more
  832. than one address is tried for a connection these will hold data
  833. for the last attempt. When the connection is actually established
  834. these are updated with data which comes directly from the socket. */
  835. char primary_ip[MAX_IPADR_LEN];
  836. long primary_port;
  837. /* 'local_ip' and 'local_port' get filled with local's numerical
  838. ip address and port number whenever an outgoing connection is
  839. **established** from the primary socket to a remote address. */
  840. char local_ip[MAX_IPADR_LEN];
  841. long local_port;
  842. char *user; /* user name string, allocated */
  843. char *passwd; /* password string, allocated */
  844. char *options; /* options string, allocated */
  845. char *oauth_bearer; /* bearer token for OAuth 2.0, allocated */
  846. int httpversion; /* the HTTP version*10 reported by the server */
  847. int rtspversion; /* the RTSP version*10 reported by the server */
  848. struct timeval now; /* "current" time */
  849. struct timeval created; /* creation time */
  850. curl_socket_t sock[2]; /* two sockets, the second is used for the data
  851. transfer when doing FTP */
  852. curl_socket_t tempsock[2]; /* temporary sockets for happy eyeballs */
  853. bool sock_accepted[2]; /* TRUE if the socket on this index was created with
  854. accept() */
  855. Curl_recv *recv[2];
  856. Curl_send *send[2];
  857. #ifdef USE_RECV_BEFORE_SEND_WORKAROUND
  858. struct postponed_data postponed[2]; /* two buffers for two sockets */
  859. #endif /* USE_RECV_BEFORE_SEND_WORKAROUND */
  860. struct ssl_connect_data ssl[2]; /* this is for ssl-stuff */
  861. struct ssl_connect_data proxy_ssl[2]; /* this is for proxy ssl-stuff */
  862. struct ssl_primary_config ssl_config;
  863. struct ssl_primary_config proxy_ssl_config;
  864. bool tls_upgraded;
  865. struct ConnectBits bits; /* various state-flags for this connection */
  866. /* connecttime: when connect() is called on the current IP address. Used to
  867. be able to track when to move on to try next IP - but only when the multi
  868. interface is used. */
  869. struct timeval connecttime;
  870. /* The two fields below get set in Curl_connecthost */
  871. int num_addr; /* number of addresses to try to connect to */
  872. time_t timeoutms_per_addr; /* how long time in milliseconds to spend on
  873. trying to connect to each IP address */
  874. const struct Curl_handler *handler; /* Connection's protocol handler */
  875. const struct Curl_handler *given; /* The protocol first given */
  876. long ip_version; /* copied from the Curl_easy at creation time */
  877. /**** curl_get() phase fields */
  878. curl_socket_t sockfd; /* socket to read from or CURL_SOCKET_BAD */
  879. curl_socket_t writesockfd; /* socket to write to, it may very
  880. well be the same we read from.
  881. CURL_SOCKET_BAD disables */
  882. /** Dynamicly allocated strings, MUST be freed before this **/
  883. /** struct is killed. **/
  884. struct dynamically_allocated_data {
  885. char *proxyuserpwd;
  886. char *uagent;
  887. char *accept_encoding;
  888. char *userpwd;
  889. char *rangeline;
  890. char *ref;
  891. char *host;
  892. char *cookiehost;
  893. char *rtsp_transport;
  894. char *te; /* TE: request header */
  895. } allocptr;
  896. #ifdef HAVE_GSSAPI
  897. int sec_complete; /* if Kerberos is enabled for this connection */
  898. enum protection_level command_prot;
  899. enum protection_level data_prot;
  900. enum protection_level request_data_prot;
  901. size_t buffer_size;
  902. struct krb5buffer in_buffer;
  903. void *app_data;
  904. const struct Curl_sec_client_mech *mech;
  905. struct sockaddr_in local_addr;
  906. #endif
  907. #if defined(USE_KERBEROS5) /* Consider moving some of the above GSS-API */
  908. struct kerberos5data krb5; /* variables into the structure definition, */
  909. #endif /* however, some of them are ftp specific. */
  910. /* the two following *_inuse fields are only flags, not counters in any way.
  911. If TRUE it means the channel is in use, and if FALSE it means the channel
  912. is up for grabs by one. */
  913. bool readchannel_inuse; /* whether the read channel is in use by an easy
  914. handle */
  915. bool writechannel_inuse; /* whether the write channel is in use by an easy
  916. handle */
  917. struct curl_llist *send_pipe; /* List of handles waiting to
  918. send on this pipeline */
  919. struct curl_llist *recv_pipe; /* List of handles waiting to read
  920. their responses on this pipeline */
  921. char *master_buffer; /* The master buffer allocated on-demand;
  922. used for pipelining. */
  923. size_t read_pos; /* Current read position in the master buffer */
  924. size_t buf_len; /* Length of the buffer?? */
  925. curl_seek_callback seek_func; /* function that seeks the input */
  926. void *seek_client; /* pointer to pass to the seek() above */
  927. /*************** Request - specific items ************/
  928. #if defined(USE_NTLM)
  929. struct ntlmdata ntlm; /* NTLM differs from other authentication schemes
  930. because it authenticates connections, not
  931. single requests! */
  932. struct ntlmdata proxyntlm; /* NTLM data for proxy */
  933. #if defined(NTLM_WB_ENABLED)
  934. /* used for communication with Samba's winbind daemon helper ntlm_auth */
  935. curl_socket_t ntlm_auth_hlpr_socket;
  936. pid_t ntlm_auth_hlpr_pid;
  937. char *challenge_header;
  938. char *response_header;
  939. #endif
  940. #endif
  941. char syserr_buf [256]; /* buffer for Curl_strerror() */
  942. #ifdef CURLRES_ASYNCH
  943. /* data used for the asynch name resolve callback */
  944. struct Curl_async async;
  945. #endif
  946. /* These three are used for chunked-encoding trailer support */
  947. char *trailer; /* allocated buffer to store trailer in */
  948. int trlMax; /* allocated buffer size */
  949. int trlPos; /* index of where to store data */
  950. union {
  951. struct ftp_conn ftpc;
  952. struct http_conn httpc;
  953. struct ssh_conn sshc;
  954. struct tftp_state_data *tftpc;
  955. struct imap_conn imapc;
  956. struct pop3_conn pop3c;
  957. struct smtp_conn smtpc;
  958. struct rtsp_conn rtspc;
  959. struct smb_conn smbc;
  960. void *generic; /* RTMP and LDAP use this */
  961. } proto;
  962. int cselect_bits; /* bitmask of socket events */
  963. int waitfor; /* current READ/WRITE bits to wait for */
  964. #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
  965. int socks5_gssapi_enctype;
  966. #endif
  967. /* When this connection is created, store the conditions for the local end
  968. bind. This is stored before the actual bind and before any connection is
  969. made and will serve the purpose of being used for comparison reasons so
  970. that subsequent bound-requested connections aren't accidentally re-using
  971. wrong connections. */
  972. char *localdev;
  973. unsigned short localport;
  974. int localportrange;
  975. /* tunnel as in tunnel through a HTTP proxy with CONNECT */
  976. enum {
  977. TUNNEL_INIT, /* init/default/no tunnel state */
  978. TUNNEL_CONNECT, /* CONNECT has been sent off */
  979. TUNNEL_COMPLETE /* CONNECT response received completely */
  980. } tunnel_state[2]; /* two separate ones to allow FTP */
  981. struct connectbundle *bundle; /* The bundle we are member of */
  982. int negnpn; /* APLN or NPN TLS negotiated protocol, CURL_HTTP_VERSION* */
  983. #ifdef USE_UNIX_SOCKETS
  984. char *unix_domain_socket;
  985. bool abstract_unix_socket;
  986. #endif
  987. };
  988. /* The end of connectdata. */
  989. /*
  990. * Struct to keep statistical and informational data.
  991. * All variables in this struct must be initialized/reset in Curl_initinfo().
  992. */
  993. struct PureInfo {
  994. int httpcode; /* Recent HTTP, FTP, RTSP or SMTP response code */
  995. int httpproxycode; /* response code from proxy when received separate */
  996. int httpversion; /* the http version number X.Y = X*10+Y */
  997. long filetime; /* If requested, this is might get set. Set to -1 if the time
  998. was unretrievable. We cannot have this of type time_t,
  999. since time_t is unsigned on several platforms such as
  1000. OpenVMS. */
  1001. bool timecond; /* set to TRUE if the time condition didn't match, which
  1002. thus made the document NOT get fetched */
  1003. long header_size; /* size of read header(s) in bytes */
  1004. long request_size; /* the amount of bytes sent in the request(s) */
  1005. unsigned long proxyauthavail; /* what proxy auth types were announced */
  1006. unsigned long httpauthavail; /* what host auth types were announced */
  1007. long numconnects; /* how many new connection did libcurl created */
  1008. char *contenttype; /* the content type of the object */
  1009. char *wouldredirect; /* URL this would've been redirected to if asked to */
  1010. /* PureInfo members 'conn_primary_ip', 'conn_primary_port', 'conn_local_ip'
  1011. and, 'conn_local_port' are copied over from the connectdata struct in
  1012. order to allow curl_easy_getinfo() to return this information even when
  1013. the session handle is no longer associated with a connection, and also
  1014. allow curl_easy_reset() to clear this information from the session handle
  1015. without disturbing information which is still alive, and that might be
  1016. reused, in the connection cache. */
  1017. char conn_primary_ip[MAX_IPADR_LEN];
  1018. long conn_primary_port;
  1019. char conn_local_ip[MAX_IPADR_LEN];
  1020. long conn_local_port;
  1021. const char *conn_scheme;
  1022. unsigned int conn_protocol;
  1023. struct curl_certinfo certs; /* info about the certs, only populated in
  1024. OpenSSL builds. Asked for with
  1025. CURLOPT_CERTINFO / CURLINFO_CERTINFO */
  1026. };
  1027. struct Progress {
  1028. time_t lastshow; /* time() of the last displayed progress meter or NULL to
  1029. force redraw at next call */
  1030. curl_off_t size_dl; /* total expected size */
  1031. curl_off_t size_ul; /* total expected size */
  1032. curl_off_t downloaded; /* transferred so far */
  1033. curl_off_t uploaded; /* transferred so far */
  1034. curl_off_t current_speed; /* uses the currently fastest transfer */
  1035. bool callback; /* set when progress callback is used */
  1036. int width; /* screen width at download start */
  1037. int flags; /* see progress.h */
  1038. double timespent;
  1039. curl_off_t dlspeed;
  1040. curl_off_t ulspeed;
  1041. double t_nslookup;
  1042. double t_connect;
  1043. double t_appconnect;
  1044. double t_pretransfer;
  1045. double t_starttransfer;
  1046. double t_redirect;
  1047. struct timeval start;
  1048. struct timeval t_startsingle;
  1049. struct timeval t_startop;
  1050. struct timeval t_acceptdata;
  1051. /* upload speed limit */
  1052. struct timeval ul_limit_start;
  1053. curl_off_t ul_limit_size;
  1054. /* download speed limit */
  1055. struct timeval dl_limit_start;
  1056. curl_off_t dl_limit_size;
  1057. #define CURR_TIME (5+1) /* 6 entries for 5 seconds */
  1058. curl_off_t speeder[ CURR_TIME ];
  1059. struct timeval speeder_time[ CURR_TIME ];
  1060. int speeder_c;
  1061. };
  1062. typedef enum {
  1063. HTTPREQ_NONE, /* first in list */
  1064. HTTPREQ_GET,
  1065. HTTPREQ_POST,
  1066. HTTPREQ_POST_FORM, /* we make a difference internally */
  1067. HTTPREQ_PUT,
  1068. HTTPREQ_HEAD,
  1069. HTTPREQ_CUSTOM,
  1070. HTTPREQ_LAST /* last in list */
  1071. } Curl_HttpReq;
  1072. typedef enum {
  1073. RTSPREQ_NONE, /* first in list */
  1074. RTSPREQ_OPTIONS,
  1075. RTSPREQ_DESCRIBE,
  1076. RTSPREQ_ANNOUNCE,
  1077. RTSPREQ_SETUP,
  1078. RTSPREQ_PLAY,
  1079. RTSPREQ_PAUSE,
  1080. RTSPREQ_TEARDOWN,
  1081. RTSPREQ_GET_PARAMETER,
  1082. RTSPREQ_SET_PARAMETER,
  1083. RTSPREQ_RECORD,
  1084. RTSPREQ_RECEIVE,
  1085. RTSPREQ_LAST /* last in list */
  1086. } Curl_RtspReq;
  1087. /*
  1088. * Values that are generated, temporary or calculated internally for a
  1089. * "session handle" must be defined within the 'struct UrlState'. This struct
  1090. * will be used within the Curl_easy struct. When the 'Curl_easy'
  1091. * struct is cloned, this data MUST NOT be copied.
  1092. *
  1093. * Remember that any "state" information goes globally for the curl handle.
  1094. * Session-data MUST be put in the connectdata struct and here. */
  1095. #define MAX_CURL_USER_LENGTH 256
  1096. #define MAX_CURL_PASSWORD_LENGTH 256
  1097. struct auth {
  1098. unsigned long want; /* Bitmask set to the authentication methods wanted by
  1099. app (with CURLOPT_HTTPAUTH or CURLOPT_PROXYAUTH). */
  1100. unsigned long picked;
  1101. unsigned long avail; /* Bitmask for what the server reports to support for
  1102. this resource */
  1103. bool done; /* TRUE when the auth phase is done and ready to do the *actual*
  1104. request */
  1105. bool multi; /* TRUE if this is not yet authenticated but within the auth
  1106. multipass negotiation */
  1107. bool iestyle; /* TRUE if digest should be done IE-style or FALSE if it should
  1108. be RFC compliant */
  1109. };
  1110. struct Curl_http2_dep {
  1111. struct Curl_http2_dep *next;
  1112. struct Curl_easy *data;
  1113. };
  1114. struct UrlState {
  1115. /* Points to the connection cache */
  1116. struct conncache *conn_cache;
  1117. /* when curl_easy_perform() is called, the multi handle is "owned" by
  1118. the easy handle so curl_easy_cleanup() on such an easy handle will
  1119. also close the multi handle! */
  1120. bool multi_owned_by_easy;
  1121. /* buffers to store authentication data in, as parsed from input options */
  1122. struct timeval keeps_speed; /* for the progress meter really */
  1123. struct connectdata *lastconnect; /* The last connection, NULL if undefined */
  1124. char *headerbuff; /* allocated buffer to store headers in */
  1125. size_t headersize; /* size of the allocation */
  1126. char *buffer; /* download buffer */
  1127. char uploadbuffer[BUFSIZE+1]; /* upload buffer */
  1128. curl_off_t current_speed; /* the ProgressShow() funcion sets this,
  1129. bytes / second */
  1130. bool this_is_a_follow; /* this is a followed Location: request */
  1131. char *first_host; /* host name of the first (not followed) request.
  1132. if set, this should be the host name that we will
  1133. sent authorization to, no else. Used to make Location:
  1134. following not keep sending user+password... This is
  1135. strdup() data.
  1136. */
  1137. int first_remote_port; /* remote port of the first (not followed) request */
  1138. struct curl_ssl_session *session; /* array of 'max_ssl_sessions' size */
  1139. long sessionage; /* number of the most recent session */
  1140. char *tempwrite; /* allocated buffer to keep data in when a write
  1141. callback returns to make the connection paused */
  1142. size_t tempwritesize; /* size of the 'tempwrite' allocated buffer */
  1143. int tempwritetype; /* type of the 'tempwrite' buffer as a bitmask that is
  1144. used with Curl_client_write() */
  1145. char *scratch; /* huge buffer[BUFSIZE*2] when doing upload CRLF replacing */
  1146. bool errorbuf; /* Set to TRUE if the error buffer is already filled in.
  1147. This must be set to FALSE every time _easy_perform() is
  1148. called. */
  1149. int os_errno; /* filled in with errno whenever an error occurs */
  1150. #ifdef HAVE_SIGNAL
  1151. /* storage for the previous bag^H^H^HSIGPIPE signal handler :-) */
  1152. void (*prev_signal)(int sig);
  1153. #endif
  1154. bool allow_port; /* Is set.use_port allowed to take effect or not. This
  1155. is always set TRUE when curl_easy_perform() is called. */
  1156. struct digestdata digest; /* state data for host Digest auth */
  1157. struct digestdata proxydigest; /* state data for proxy Digest auth */
  1158. #ifdef USE_SPNEGO
  1159. struct negotiatedata negotiate; /* state data for host Negotiate auth */
  1160. struct negotiatedata proxyneg; /* state data for proxy Negotiate auth */
  1161. #endif
  1162. struct auth authhost; /* auth details for host */
  1163. struct auth authproxy; /* auth details for proxy */
  1164. bool authproblem; /* TRUE if there's some problem authenticating */
  1165. void *resolver; /* resolver state, if it is used in the URL state -
  1166. ares_channel f.e. */
  1167. #if defined(USE_OPENSSL) && defined(HAVE_OPENSSL_ENGINE_H)
  1168. ENGINE *engine;
  1169. #endif /* USE_OPENSSL */
  1170. struct timeval expiretime; /* set this with Curl_expire() only */
  1171. struct Curl_tree timenode; /* for the splay stuff */
  1172. struct curl_llist *timeoutlist; /* list of pending timeouts */
  1173. /* a place to store the most recently set FTP entrypath */
  1174. char *most_recent_ftp_entrypath;
  1175. /* set after initial USER failure, to prevent an authentication loop */
  1176. bool ftp_trying_alternative;
  1177. int httpversion; /* the lowest HTTP version*10 reported by any server
  1178. involved in this request */
  1179. bool expect100header; /* TRUE if we added Expect: 100-continue */
  1180. bool pipe_broke; /* TRUE if the connection we were pipelined on broke
  1181. and we need to restart from the beginning */
  1182. #if !defined(WIN32) && !defined(MSDOS) && !defined(__EMX__) && \
  1183. !defined(__SYMBIAN32__)
  1184. /* do FTP line-end conversions on most platforms */
  1185. #define CURL_DO_LINEEND_CONV
  1186. /* for FTP downloads: track CRLF sequences that span blocks */
  1187. bool prev_block_had_trailing_cr;
  1188. /* for FTP downloads: how many CRLFs did we converted to LFs? */
  1189. curl_off_t crlf_conversions;
  1190. #endif
  1191. char *pathbuffer;/* allocated buffer to store the URL's path part in */
  1192. char *path; /* path to use, points to somewhere within the pathbuffer
  1193. area */
  1194. bool slash_removed; /* set TRUE if the 'path' points to a path where the
  1195. initial URL slash separator has been taken off */
  1196. bool use_range;
  1197. bool rangestringalloc; /* the range string is malloc()'ed */
  1198. char *range; /* range, if used. See README for detailed specification on
  1199. this syntax. */
  1200. curl_off_t resume_from; /* continue [ftp] transfer from here */
  1201. /* This RTSP state information survives requests and connections */
  1202. long rtsp_next_client_CSeq; /* the session's next client CSeq */
  1203. long rtsp_next_server_CSeq; /* the session's next server CSeq */
  1204. long rtsp_CSeq_recv; /* most recent CSeq received */
  1205. curl_off_t infilesize; /* size of file to upload, -1 means unknown.
  1206. Copied from set.filesize at start of operation */
  1207. size_t drain; /* Increased when this stream has data to read, even if its
  1208. socket is not necessarily is readable. Decreased when
  1209. checked. */
  1210. bool done; /* set to FALSE when Curl_init_do() is called and set to TRUE
  1211. when multi_done() is called, to prevent multi_done() to get
  1212. invoked twice when the multi interface is used. */
  1213. curl_read_callback fread_func; /* read callback/function */
  1214. void *in; /* CURLOPT_READDATA */
  1215. struct Curl_easy *stream_depends_on;
  1216. bool stream_depends_e; /* set or don't set the Exclusive bit */
  1217. int stream_weight;
  1218. };
  1219. /*
  1220. * This 'DynamicStatic' struct defines dynamic states that actually change
  1221. * values in the 'UserDefined' area, which MUST be taken into consideration
  1222. * if the UserDefined struct is cloned or similar. You can probably just
  1223. * copy these, but each one indicate a special action on other data.
  1224. */
  1225. struct DynamicStatic {
  1226. char *url; /* work URL, copied from UserDefined */
  1227. bool url_alloc; /* URL string is malloc()'ed */
  1228. char *referer; /* referer string */
  1229. bool referer_alloc; /* referer sting is malloc()ed */
  1230. struct curl_slist *cookielist; /* list of cookie files set by
  1231. curl_easy_setopt(COOKIEFILE) calls */
  1232. struct curl_slist *resolve; /* set to point to the set.resolve list when
  1233. this should be dealt with in pretransfer */
  1234. };
  1235. /*
  1236. * This 'UserDefined' struct must only contain data that is set once to go
  1237. * for many (perhaps) independent connections. Values that are generated or
  1238. * calculated internally for the "session handle" MUST be defined within the
  1239. * 'struct UrlState' instead. The only exceptions MUST note the changes in
  1240. * the 'DynamicStatic' struct.
  1241. * Character pointer fields point to dynamic storage, unless otherwise stated.
  1242. */
  1243. struct Curl_multi; /* declared and used only in multi.c */
  1244. enum dupstring {
  1245. STRING_CERT_ORIG, /* client certificate file name */
  1246. STRING_CERT_PROXY, /* client certificate file name */
  1247. STRING_CERT_TYPE_ORIG, /* format for certificate (default: PEM)*/
  1248. STRING_CERT_TYPE_PROXY, /* format for certificate (default: PEM)*/
  1249. STRING_COOKIE, /* HTTP cookie string to send */
  1250. STRING_COOKIEJAR, /* dump all cookies to this file */
  1251. STRING_CUSTOMREQUEST, /* HTTP/FTP/RTSP request/method to use */
  1252. STRING_DEFAULT_PROTOCOL, /* Protocol to use when the URL doesn't specify */
  1253. STRING_DEVICE, /* local network interface/address to use */
  1254. STRING_ENCODING, /* Accept-Encoding string */
  1255. STRING_FTP_ACCOUNT, /* ftp account data */
  1256. STRING_FTP_ALTERNATIVE_TO_USER, /* command to send if USER/PASS fails */
  1257. STRING_FTPPORT, /* port to send with the FTP PORT command */
  1258. STRING_KEY_ORIG, /* private key file name */
  1259. STRING_KEY_PROXY, /* private key file name */
  1260. STRING_KEY_PASSWD_ORIG, /* plain text private key password */
  1261. STRING_KEY_PASSWD_PROXY, /* plain text private key password */
  1262. STRING_KEY_TYPE_ORIG, /* format for private key (default: PEM) */
  1263. STRING_KEY_TYPE_PROXY, /* format for private key (default: PEM) */
  1264. STRING_KRB_LEVEL, /* krb security level */
  1265. STRING_NETRC_FILE, /* if not NULL, use this instead of trying to find
  1266. $HOME/.netrc */
  1267. STRING_PROXY, /* proxy to use */
  1268. STRING_PRE_PROXY, /* pre socks proxy to use */
  1269. STRING_SET_RANGE, /* range, if used */
  1270. STRING_SET_REFERER, /* custom string for the HTTP referer field */
  1271. STRING_SET_URL, /* what original URL to work on */
  1272. STRING_SSL_CAPATH_ORIG, /* CA directory name (doesn't work on windows) */
  1273. STRING_SSL_CAPATH_PROXY, /* CA directory name (doesn't work on windows) */
  1274. STRING_SSL_CAFILE_ORIG, /* certificate file to verify peer against */
  1275. STRING_SSL_CAFILE_PROXY, /* certificate file to verify peer against */
  1276. STRING_SSL_PINNEDPUBLICKEY_ORIG, /* public key file to verify peer against */
  1277. STRING_SSL_PINNEDPUBLICKEY_PROXY, /* public key file to verify proxy */
  1278. STRING_SSL_CIPHER_LIST_ORIG, /* list of ciphers to use */
  1279. STRING_SSL_CIPHER_LIST_PROXY, /* list of ciphers to use */
  1280. STRING_SSL_EGDSOCKET, /* path to file containing the EGD daemon socket */
  1281. STRING_SSL_RANDOM_FILE, /* path to file containing "random" data */
  1282. STRING_USERAGENT, /* User-Agent string */
  1283. STRING_SSL_CRLFILE_ORIG, /* crl file to check certificate */
  1284. STRING_SSL_CRLFILE_PROXY, /* crl file to check certificate */
  1285. STRING_SSL_ISSUERCERT_ORIG, /* issuer cert file to check certificate */
  1286. STRING_SSL_ISSUERCERT_PROXY, /* issuer cert file to check certificate */
  1287. STRING_USERNAME, /* <username>, if used */
  1288. STRING_PASSWORD, /* <password>, if used */
  1289. STRING_OPTIONS, /* <options>, if used */
  1290. STRING_PROXYUSERNAME, /* Proxy <username>, if used */
  1291. STRING_PROXYPASSWORD, /* Proxy <password>, if used */
  1292. STRING_NOPROXY, /* List of hosts which should not use the proxy, if
  1293. used */
  1294. STRING_RTSP_SESSION_ID, /* Session ID to use */
  1295. STRING_RTSP_STREAM_URI, /* Stream URI for this request */
  1296. STRING_RTSP_TRANSPORT, /* Transport for this session */
  1297. #ifdef USE_LIBSSH2
  1298. STRING_SSH_PRIVATE_KEY, /* path to the private key file for auth */
  1299. STRING_SSH_PUBLIC_KEY, /* path to the public key file for auth */
  1300. STRING_SSH_HOST_PUBLIC_KEY_MD5, /* md5 of host public key in ascii hex */
  1301. STRING_SSH_KNOWNHOSTS, /* file name of knownhosts file */
  1302. #endif
  1303. #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
  1304. STRING_PROXY_SERVICE_NAME, /* Proxy service name */
  1305. #endif
  1306. #if !defined(CURL_DISABLE_CRYPTO_AUTH) || defined(USE_KERBEROS5) || \
  1307. defined(USE_SPNEGO)
  1308. STRING_SERVICE_NAME, /* Service name */
  1309. #endif
  1310. STRING_MAIL_FROM,
  1311. STRING_MAIL_AUTH,
  1312. #ifdef USE_TLS_SRP
  1313. STRING_TLSAUTH_USERNAME_ORIG, /* TLS auth <username> */
  1314. STRING_TLSAUTH_USERNAME_PROXY, /* TLS auth <username> */
  1315. STRING_TLSAUTH_PASSWORD_ORIG, /* TLS auth <password> */
  1316. STRING_TLSAUTH_PASSWORD_PROXY, /* TLS auth <password> */
  1317. #endif
  1318. STRING_BEARER, /* <bearer>, if used */
  1319. #ifdef USE_UNIX_SOCKETS
  1320. STRING_UNIX_SOCKET_PATH, /* path to Unix socket, if used */
  1321. #endif
  1322. /* -- end of zero-terminated strings -- */
  1323. STRING_LASTZEROTERMINATED,
  1324. /* -- below this are pointers to binary data that cannot be strdup'ed.
  1325. Each such pointer must be added manually to Curl_dupset() --- */
  1326. STRING_COPYPOSTFIELDS, /* if POST, set the fields' values here */
  1327. STRING_LAST /* not used, just an end-of-list marker */
  1328. };
  1329. struct UserDefined {
  1330. FILE *err; /* the stderr user data goes here */
  1331. void *debugdata; /* the data that will be passed to fdebug */
  1332. char *errorbuffer; /* (Static) store failure messages in here */
  1333. long proxyport; /* If non-zero, use this port number by default. If the
  1334. proxy string features a ":[port]" that one will override
  1335. this. */
  1336. void *out; /* CURLOPT_WRITEDATA */
  1337. void *in_set; /* CURLOPT_READDATA */
  1338. void *writeheader; /* write the header to this if non-NULL */
  1339. void *rtp_out; /* write RTP to this if non-NULL */
  1340. long use_port; /* which port to use (when not using default) */
  1341. unsigned long httpauth; /* kind of HTTP authentication to use (bitmask) */
  1342. unsigned long proxyauth; /* kind of proxy authentication to use (bitmask) */
  1343. long followlocation; /* as in HTTP Location: */
  1344. long maxredirs; /* maximum no. of http(s) redirects to follow, set to -1
  1345. for infinity */
  1346. int keep_post; /* keep POSTs as POSTs after a 30x request; each
  1347. bit represents a request, from 301 to 303 */
  1348. bool free_referer; /* set TRUE if 'referer' points to a string we
  1349. allocated */
  1350. void *postfields; /* if POST, set the fields' values here */
  1351. curl_seek_callback seek_func; /* function that seeks the input */
  1352. curl_off_t postfieldsize; /* if POST, this might have a size to use instead
  1353. of strlen(), and then the data *may* be binary
  1354. (contain zero bytes) */
  1355. unsigned short localport; /* local port number to bind to */
  1356. int localportrange; /* number of additional port numbers to test in case the
  1357. 'localport' one can't be bind()ed */
  1358. curl_write_callback fwrite_func; /* function that stores the output */
  1359. curl_write_callback fwrite_header; /* function that stores headers */
  1360. curl_write_callback fwrite_rtp; /* function that stores interleaved RTP */
  1361. curl_read_callback fread_func_set; /* function that reads the input */
  1362. int is_fread_set; /* boolean, has read callback been set to non-NULL? */
  1363. int is_fwrite_set; /* boolean, has write callback been set to non-NULL? */
  1364. curl_progress_callback fprogress; /* OLD and deprecated progress callback */
  1365. curl_xferinfo_callback fxferinfo; /* progress callback */
  1366. curl_debug_callback fdebug; /* function that write informational data */
  1367. curl_ioctl_callback ioctl_func; /* function for I/O control */
  1368. curl_sockopt_callback fsockopt; /* function for setting socket options */
  1369. void *sockopt_client; /* pointer to pass to the socket options callback */
  1370. curl_opensocket_callback fopensocket; /* function for checking/translating
  1371. the address and opening the
  1372. socket */
  1373. void *opensocket_client;
  1374. curl_closesocket_callback fclosesocket; /* function for closing the
  1375. socket */
  1376. void *closesocket_client;
  1377. void *seek_client; /* pointer to pass to the seek callback */
  1378. /* the 3 curl_conv_callback functions below are used on non-ASCII hosts */
  1379. /* function to convert from the network encoding: */
  1380. curl_conv_callback convfromnetwork;
  1381. /* function to convert to the network encoding: */
  1382. curl_conv_callback convtonetwork;
  1383. /* function to convert from UTF-8 encoding: */
  1384. curl_conv_callback convfromutf8;
  1385. void *progress_client; /* pointer to pass to the progress callback */
  1386. void *ioctl_client; /* pointer to pass to the ioctl callback */
  1387. long timeout; /* in milliseconds, 0 means no timeout */
  1388. long connecttimeout; /* in milliseconds, 0 means no timeout */
  1389. long accepttimeout; /* in milliseconds, 0 means no timeout */
  1390. long server_response_timeout; /* in milliseconds, 0 means no timeout */
  1391. long tftp_blksize; /* in bytes, 0 means use default */
  1392. bool tftp_no_options; /* do not send TFTP options requests */
  1393. curl_off_t filesize; /* size of file to upload, -1 means unknown */
  1394. long low_speed_limit; /* bytes/second */
  1395. long low_speed_time; /* number of seconds */
  1396. curl_off_t max_send_speed; /* high speed limit in bytes/second for upload */
  1397. curl_off_t max_recv_speed; /* high speed limit in bytes/second for
  1398. download */
  1399. curl_off_t set_resume_from; /* continue [ftp] transfer from here */
  1400. struct curl_slist *headers; /* linked list of extra headers */
  1401. struct curl_slist *proxyheaders; /* linked list of extra CONNECT headers */
  1402. struct curl_httppost *httppost; /* linked list of POST data */
  1403. bool sep_headers; /* handle host and proxy headers separately */
  1404. bool cookiesession; /* new cookie session? */
  1405. bool crlf; /* convert crlf on ftp upload(?) */
  1406. struct curl_slist *quote; /* after connection is established */
  1407. struct curl_slist *postquote; /* after the transfer */
  1408. struct curl_slist *prequote; /* before the transfer, after type */
  1409. struct curl_slist *source_quote; /* 3rd party quote */
  1410. struct curl_slist *source_prequote; /* in 3rd party transfer mode - before
  1411. the transfer on source host */
  1412. struct curl_slist *source_postquote; /* in 3rd party transfer mode - after
  1413. the transfer on source host */
  1414. struct curl_slist *telnet_options; /* linked list of telnet options */
  1415. struct curl_slist *resolve; /* list of names to add/remove from
  1416. DNS cache */
  1417. struct curl_slist *connect_to; /* list of host:port mappings to override
  1418. the hostname and port to connect to */
  1419. curl_TimeCond timecondition; /* kind of time/date comparison */
  1420. time_t timevalue; /* what time to compare with */
  1421. Curl_HttpReq httpreq; /* what kind of HTTP request (if any) is this */
  1422. long httpversion; /* when non-zero, a specific HTTP version requested to
  1423. be used in the library's request(s) */
  1424. struct ssl_config_data ssl; /* user defined SSL stuff */
  1425. struct ssl_config_data proxy_ssl; /* user defined SSL stuff for proxy */
  1426. struct ssl_general_config general_ssl; /* general user defined SSL stuff */
  1427. curl_proxytype proxytype; /* what kind of proxy that is in use */
  1428. long dns_cache_timeout; /* DNS cache timeout */
  1429. long buffer_size; /* size of receive buffer to use */
  1430. void *private_data; /* application-private data */
  1431. struct curl_slist *http200aliases; /* linked list of aliases for http200 */
  1432. long ipver; /* the CURL_IPRESOLVE_* defines in the public header file
  1433. 0 - whatever, 1 - v2, 2 - v6 */
  1434. curl_off_t max_filesize; /* Maximum file size to download */
  1435. curl_ftpfile ftp_filemethod; /* how to get to a file when FTP is used */
  1436. int ftp_create_missing_dirs; /* 1 - create directories that don't exist
  1437. 2 - the same but also allow MKD to fail once
  1438. */
  1439. curl_sshkeycallback ssh_keyfunc; /* key matching callback */
  1440. void *ssh_keyfunc_userp; /* custom pointer to callback */
  1441. /* Here follows boolean settings that define how to behave during
  1442. this session. They are STATIC, set by libcurl users or at least initially
  1443. and they don't change during operations. */
  1444. bool printhost; /* printing host name in debug info */
  1445. bool get_filetime; /* get the time and get of the remote file */
  1446. bool tunnel_thru_httpproxy; /* use CONNECT through a HTTP proxy */
  1447. bool prefer_ascii; /* ASCII rather than binary */
  1448. bool ftp_append; /* append, not overwrite, on upload */
  1449. bool ftp_list_only; /* switch FTP command for listing directories */
  1450. bool ftp_use_port; /* use the FTP PORT command */
  1451. bool hide_progress; /* don't use the progress meter */
  1452. bool http_fail_on_error; /* fail on HTTP error codes >= 400 */
  1453. bool http_keep_sending_on_error; /* for HTTP status codes >= 300 */
  1454. bool http_follow_location; /* follow HTTP redirects */
  1455. bool http_transfer_encoding; /* request compressed HTTP transfer-encoding */
  1456. bool http_disable_hostname_check_before_authentication;
  1457. bool include_header; /* include received protocol headers in data output */
  1458. bool http_set_referer; /* is a custom referer used */
  1459. bool http_auto_referer; /* set "correct" referer when following location: */
  1460. bool opt_no_body; /* as set with CURLOPT_NOBODY */
  1461. bool upload; /* upload request */
  1462. enum CURL_NETRC_OPTION
  1463. use_netrc; /* defined in include/curl.h */
  1464. bool verbose; /* output verbosity */
  1465. bool krb; /* Kerberos connection requested */
  1466. bool reuse_forbid; /* forbidden to be reused, close after use */
  1467. bool reuse_fresh; /* do not re-use an existing connection */
  1468. bool ftp_use_epsv; /* if EPSV is to be attempted or not */
  1469. bool ftp_use_eprt; /* if EPRT is to be attempted or not */
  1470. bool ftp_use_pret; /* if PRET is to be used before PASV or not */
  1471. curl_usessl use_ssl; /* if AUTH TLS is to be attempted etc, for FTP or
  1472. IMAP or POP3 or others! */
  1473. curl_ftpauth ftpsslauth; /* what AUTH XXX to be attempted */
  1474. curl_ftpccc ftp_ccc; /* FTP CCC options */
  1475. bool no_signal; /* do not use any signal/alarm handler */
  1476. bool global_dns_cache; /* subject for future removal */
  1477. bool tcp_nodelay; /* whether to enable TCP_NODELAY or not */
  1478. bool ignorecl; /* ignore content length */
  1479. bool ftp_skip_ip; /* skip the IP address the FTP server passes on to
  1480. us */
  1481. bool connect_only; /* make connection, let application use the socket */
  1482. long ssh_auth_types; /* allowed SSH auth types */
  1483. bool http_te_skip; /* pass the raw body data to the user, even when
  1484. transfer-encoded (chunked, compressed) */
  1485. bool http_ce_skip; /* pass the raw body data to the user, even when
  1486. content-encoded (chunked, compressed) */
  1487. long new_file_perms; /* Permissions to use when creating remote files */
  1488. long new_directory_perms; /* Permissions to use when creating remote dirs */
  1489. bool proxy_transfer_mode; /* set transfer mode (;type=<a|i>) when doing FTP
  1490. via an HTTP proxy */
  1491. char *str[STRING_LAST]; /* array of strings, pointing to allocated memory */
  1492. unsigned int scope_id; /* Scope id for IPv6 */
  1493. long allowed_protocols;
  1494. long redir_protocols;
  1495. #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
  1496. bool socks5_gssapi_nec; /* Flag to support NEC SOCKS5 server */
  1497. #endif
  1498. struct curl_slist *mail_rcpt; /* linked list of mail recipients */
  1499. bool sasl_ir; /* Enable/disable SASL initial response */
  1500. /* Common RTSP header options */
  1501. Curl_RtspReq rtspreq; /* RTSP request type */
  1502. long rtspversion; /* like httpversion, for RTSP */
  1503. bool wildcardmatch; /* enable wildcard matching */
  1504. curl_chunk_bgn_callback chunk_bgn; /* called before part of transfer
  1505. starts */
  1506. curl_chunk_end_callback chunk_end; /* called after part transferring
  1507. stopped */
  1508. curl_fnmatch_callback fnmatch; /* callback to decide which file corresponds
  1509. to pattern (e.g. if WILDCARDMATCH is on) */
  1510. void *fnmatch_data;
  1511. long gssapi_delegation; /* GSS-API credential delegation, see the
  1512. documentation of CURLOPT_GSSAPI_DELEGATION */
  1513. bool tcp_keepalive; /* use TCP keepalives */
  1514. long tcp_keepidle; /* seconds in idle before sending keepalive probe */
  1515. long tcp_keepintvl; /* seconds between TCP keepalive probes */
  1516. bool tcp_fastopen; /* use TCP Fast Open */
  1517. size_t maxconnects; /* Max idle connections in the connection cache */
  1518. bool ssl_enable_npn; /* TLS NPN extension? */
  1519. bool ssl_enable_alpn; /* TLS ALPN extension? */
  1520. bool path_as_is; /* allow dotdots? */
  1521. bool pipewait; /* wait for pipe/multiplex status before starting a
  1522. new connection */
  1523. long expect_100_timeout; /* in milliseconds */
  1524. struct Curl_easy *stream_depends_on;
  1525. bool stream_depends_e; /* set or don't set the Exclusive bit */
  1526. int stream_weight;
  1527. struct Curl_http2_dep *stream_dependents;
  1528. bool abstract_unix_socket;
  1529. };
  1530. struct Names {
  1531. struct curl_hash *hostcache;
  1532. enum {
  1533. HCACHE_NONE, /* not pointing to anything */
  1534. HCACHE_GLOBAL, /* points to the (shrug) global one */
  1535. HCACHE_MULTI, /* points to a shared one in the multi handle */
  1536. HCACHE_SHARED /* points to a shared one in a shared object */
  1537. } hostcachetype;
  1538. };
  1539. /*
  1540. * The 'connectdata' struct MUST have all the connection oriented stuff as we
  1541. * may have several simultaneous connections and connection structs in memory.
  1542. *
  1543. * The 'struct UserDefined' must only contain data that is set once to go for
  1544. * many (perhaps) independent connections. Values that are generated or
  1545. * calculated internally for the "session handle" must be defined within the
  1546. * 'struct UrlState' instead.
  1547. */
  1548. struct Curl_easy {
  1549. /* first, two fields for the linked list of these */
  1550. struct Curl_easy *next;
  1551. struct Curl_easy *prev;
  1552. struct connectdata *easy_conn; /* the "unit's" connection */
  1553. CURLMstate mstate; /* the handle's state */
  1554. CURLcode result; /* previous result */
  1555. struct Curl_message msg; /* A single posted message. */
  1556. /* Array with the plain socket numbers this handle takes care of, in no
  1557. particular order. Note that all sockets are added to the sockhash, where
  1558. the state etc are also kept. This array is mostly used to detect when a
  1559. socket is to be removed from the hash. See singlesocket(). */
  1560. curl_socket_t sockets[MAX_SOCKSPEREASYHANDLE];
  1561. int numsocks;
  1562. struct Names dns;
  1563. struct Curl_multi *multi; /* if non-NULL, points to the multi handle
  1564. struct to which this "belongs" when used by
  1565. the multi interface */
  1566. struct Curl_multi *multi_easy; /* if non-NULL, points to the multi handle
  1567. struct to which this "belongs" when used
  1568. by the easy interface */
  1569. struct Curl_share *share; /* Share, handles global variable mutexing */
  1570. struct SingleRequest req; /* Request-specific data */
  1571. struct UserDefined set; /* values set by the libcurl user */
  1572. struct DynamicStatic change; /* possibly modified userdefined data */
  1573. struct CookieInfo *cookies; /* the cookies, read from files and servers.
  1574. NOTE that the 'cookie' field in the
  1575. UserDefined struct defines if the "engine"
  1576. is to be used or not. */
  1577. struct Progress progress; /* for all the progress meter data */
  1578. struct UrlState state; /* struct for fields used for state info and
  1579. other dynamic purposes */
  1580. struct WildcardData wildcard; /* wildcard download state info */
  1581. struct PureInfo info; /* stats, reports and info data */
  1582. struct curl_tlssessioninfo tsi; /* Information about the TLS session, only
  1583. valid after a client has asked for it */
  1584. #if defined(CURL_DOES_CONVERSIONS) && defined(HAVE_ICONV)
  1585. iconv_t outbound_cd; /* for translating to the network encoding */
  1586. iconv_t inbound_cd; /* for translating from the network encoding */
  1587. iconv_t utf8_cd; /* for translating to UTF8 */
  1588. #endif /* CURL_DOES_CONVERSIONS && HAVE_ICONV */
  1589. unsigned int magic; /* set to a CURLEASY_MAGIC_NUMBER */
  1590. };
  1591. #define LIBCURL_NAME "libcurl"
  1592. #endif /* HEADER_CURL_URLDATA_H */