urldata.h 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971
  1. #ifndef HEADER_CURL_URLDATA_H
  2. #define HEADER_CURL_URLDATA_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at https://curl.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. * SPDX-License-Identifier: curl
  24. *
  25. ***************************************************************************/
  26. /* This file is for lib internal stuff */
  27. #include "curl_setup.h"
  28. #define PORT_FTP 21
  29. #define PORT_FTPS 990
  30. #define PORT_TELNET 23
  31. #define PORT_HTTP 80
  32. #define PORT_HTTPS 443
  33. #define PORT_DICT 2628
  34. #define PORT_LDAP 389
  35. #define PORT_LDAPS 636
  36. #define PORT_TFTP 69
  37. #define PORT_SSH 22
  38. #define PORT_IMAP 143
  39. #define PORT_IMAPS 993
  40. #define PORT_POP3 110
  41. #define PORT_POP3S 995
  42. #define PORT_SMB 445
  43. #define PORT_SMBS 445
  44. #define PORT_SMTP 25
  45. #define PORT_SMTPS 465 /* sometimes called SSMTP */
  46. #define PORT_RTSP 554
  47. #define PORT_RTMP 1935
  48. #define PORT_RTMPT PORT_HTTP
  49. #define PORT_RTMPS PORT_HTTPS
  50. #define PORT_GOPHER 70
  51. #define PORT_MQTT 1883
  52. struct curl_trc_featt;
  53. #ifdef USE_ECH
  54. /* CURLECH_ bits for the tls_ech option */
  55. # define CURLECH_DISABLE (1<<0)
  56. # define CURLECH_GREASE (1<<1)
  57. # define CURLECH_ENABLE (1<<2)
  58. # define CURLECH_HARD (1<<3)
  59. # define CURLECH_CLA_CFG (1<<4)
  60. #endif
  61. #ifdef USE_WEBSOCKETS
  62. /* CURLPROTO_GOPHERS (29) is the highest publicly used protocol bit number,
  63. * the rest are internal information. If we use higher bits we only do this on
  64. * platforms that have a >= 64 bit type and then we use such a type for the
  65. * protocol fields in the protocol handler.
  66. */
  67. #define CURLPROTO_WS (1<<30)
  68. #define CURLPROTO_WSS ((curl_prot_t)1<<31)
  69. #else
  70. #define CURLPROTO_WS 0
  71. #define CURLPROTO_WSS 0
  72. #endif
  73. /* This should be undefined once we need bit 32 or higher */
  74. #define PROTO_TYPE_SMALL
  75. #ifndef PROTO_TYPE_SMALL
  76. typedef curl_off_t curl_prot_t;
  77. #else
  78. typedef unsigned int curl_prot_t;
  79. #endif
  80. /* This mask is for all the old protocols that are provided and defined in the
  81. public header and shall exclude protocols added since which are not exposed
  82. in the API */
  83. #define CURLPROTO_MASK (0x3ffffff)
  84. #define DICT_MATCH "/MATCH:"
  85. #define DICT_MATCH2 "/M:"
  86. #define DICT_MATCH3 "/FIND:"
  87. #define DICT_DEFINE "/DEFINE:"
  88. #define DICT_DEFINE2 "/D:"
  89. #define DICT_DEFINE3 "/LOOKUP:"
  90. #define CURL_DEFAULT_USER "anonymous"
  91. #define CURL_DEFAULT_PASSWORD "ftp@example.com"
  92. /* Convenience defines for checking protocols or their SSL based version. Each
  93. protocol handler should only ever have a single CURLPROTO_ in its protocol
  94. field. */
  95. #define PROTO_FAMILY_HTTP (CURLPROTO_HTTP|CURLPROTO_HTTPS|CURLPROTO_WS| \
  96. CURLPROTO_WSS)
  97. #define PROTO_FAMILY_FTP (CURLPROTO_FTP|CURLPROTO_FTPS)
  98. #define PROTO_FAMILY_POP3 (CURLPROTO_POP3|CURLPROTO_POP3S)
  99. #define PROTO_FAMILY_SMB (CURLPROTO_SMB|CURLPROTO_SMBS)
  100. #define PROTO_FAMILY_SMTP (CURLPROTO_SMTP|CURLPROTO_SMTPS)
  101. #define PROTO_FAMILY_SSH (CURLPROTO_SCP|CURLPROTO_SFTP)
  102. #if !defined(CURL_DISABLE_FTP) || defined(USE_SSH) || \
  103. !defined(CURL_DISABLE_POP3) || !defined(CURL_DISABLE_FILE)
  104. /* these protocols support CURLOPT_DIRLISTONLY */
  105. #define CURL_LIST_ONLY_PROTOCOL 1
  106. #endif
  107. #define DEFAULT_CONNCACHE_SIZE 5
  108. /* length of longest IPv6 address string including the trailing null */
  109. #define MAX_IPADR_LEN sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")
  110. /* Default FTP/IMAP etc response timeout in milliseconds */
  111. #define RESP_TIMEOUT (120*1000)
  112. /* Max string input length is a precaution against abuse and to detect junk
  113. input easier and better. */
  114. #define CURL_MAX_INPUT_LENGTH 8000000
  115. #include "cookie.h"
  116. #include "psl.h"
  117. #include "formdata.h"
  118. #ifdef HAVE_NETINET_IN_H
  119. #include <netinet/in.h>
  120. #endif
  121. #ifdef HAVE_NETINET_IN6_H
  122. #include <netinet/in6.h>
  123. #endif
  124. #include "timeval.h"
  125. #include <curl/curl.h>
  126. #include "http_chunks.h" /* for the structs and enum stuff */
  127. #include "hostip.h"
  128. #include "hash.h"
  129. #include "splay.h"
  130. #include "dynbuf.h"
  131. #include "dynhds.h"
  132. #include "request.h"
  133. /* return the count of bytes sent, or -1 on error */
  134. typedef ssize_t (Curl_send)(struct Curl_easy *data, /* transfer */
  135. int sockindex, /* socketindex */
  136. const void *buf, /* data to write */
  137. size_t len, /* max amount to write */
  138. CURLcode *err); /* error to return */
  139. /* return the count of bytes read, or -1 on error */
  140. typedef ssize_t (Curl_recv)(struct Curl_easy *data, /* transfer */
  141. int sockindex, /* socketindex */
  142. char *buf, /* store data here */
  143. size_t len, /* max amount to read */
  144. CURLcode *err); /* error to return */
  145. #ifdef USE_HYPER
  146. typedef CURLcode (*Curl_datastream)(struct Curl_easy *data,
  147. struct connectdata *conn,
  148. int *didwhat,
  149. int select_res);
  150. #endif
  151. #include "mime.h"
  152. #include "imap.h"
  153. #include "pop3.h"
  154. #include "smtp.h"
  155. #include "ftp.h"
  156. #include "file.h"
  157. #include "vssh/ssh.h"
  158. #include "http.h"
  159. #include "rtsp.h"
  160. #include "smb.h"
  161. #include "mqtt.h"
  162. #include "ftplistparser.h"
  163. #include "multihandle.h"
  164. #include "c-hyper.h"
  165. #include "cf-socket.h"
  166. #ifdef HAVE_GSSAPI
  167. # ifdef HAVE_GSSGNU
  168. # include <gss.h>
  169. # elif defined HAVE_GSSAPI_GSSAPI_H
  170. # include <gssapi/gssapi.h>
  171. # else
  172. # include <gssapi.h>
  173. # endif
  174. # ifdef HAVE_GSSAPI_GSSAPI_GENERIC_H
  175. # include <gssapi/gssapi_generic.h>
  176. # endif
  177. #endif
  178. #ifdef USE_LIBSSH2
  179. #include <libssh2.h>
  180. #include <libssh2_sftp.h>
  181. #endif /* USE_LIBSSH2 */
  182. #define READBUFFER_SIZE CURL_MAX_WRITE_SIZE
  183. #define READBUFFER_MAX CURL_MAX_READ_SIZE
  184. #define READBUFFER_MIN 1024
  185. /* The default upload buffer size, should not be smaller than
  186. CURL_MAX_WRITE_SIZE, as it needs to hold a full buffer as could be sent in
  187. a write callback.
  188. The size was 16KB for many years but was bumped to 64KB because it makes
  189. libcurl able to do significantly faster uploads in some circumstances. Even
  190. larger buffers can help further, but this is deemed a fair memory/speed
  191. compromise. */
  192. #define UPLOADBUFFER_DEFAULT 65536
  193. #define UPLOADBUFFER_MAX (2*1024*1024)
  194. #define UPLOADBUFFER_MIN CURL_MAX_WRITE_SIZE
  195. #define CURLEASY_MAGIC_NUMBER 0xc0dedbadU
  196. #ifdef DEBUGBUILD
  197. /* On a debug build, we want to fail hard on easy handles that
  198. * are not NULL, but no longer have the MAGIC touch. This gives
  199. * us early warning on things only discovered by valgrind otherwise. */
  200. #define GOOD_EASY_HANDLE(x) \
  201. (((x) && ((x)->magic == CURLEASY_MAGIC_NUMBER))? TRUE: \
  202. (DEBUGASSERT(!(x)), FALSE))
  203. #else
  204. #define GOOD_EASY_HANDLE(x) \
  205. ((x) && ((x)->magic == CURLEASY_MAGIC_NUMBER))
  206. #endif
  207. #ifdef HAVE_GSSAPI
  208. /* Types needed for krb5-ftp connections */
  209. struct krb5buffer {
  210. struct dynbuf buf;
  211. size_t index;
  212. BIT(eof_flag);
  213. };
  214. enum protection_level {
  215. PROT_NONE, /* first in list */
  216. PROT_CLEAR,
  217. PROT_SAFE,
  218. PROT_CONFIDENTIAL,
  219. PROT_PRIVATE,
  220. PROT_CMD,
  221. PROT_LAST /* last in list */
  222. };
  223. #endif
  224. /* SSL backend-specific data; declared differently by each SSL backend */
  225. struct ssl_backend_data;
  226. typedef enum {
  227. CURL_SSL_PEER_DNS,
  228. CURL_SSL_PEER_IPV4,
  229. CURL_SSL_PEER_IPV6
  230. } ssl_peer_type;
  231. struct ssl_peer {
  232. char *hostname; /* hostname for verification */
  233. char *dispname; /* display version of hostname */
  234. char *sni; /* SNI version of hostname or NULL if not usable */
  235. ssl_peer_type type; /* type of the peer information */
  236. int port; /* port we are talking to */
  237. int transport; /* TCP or QUIC */
  238. };
  239. struct ssl_primary_config {
  240. char *CApath; /* certificate dir (doesn't work on windows) */
  241. char *CAfile; /* certificate to verify peer against */
  242. char *issuercert; /* optional issuer certificate filename */
  243. char *clientcert;
  244. char *cipher_list; /* list of ciphers to use */
  245. char *cipher_list13; /* list of TLS 1.3 cipher suites to use */
  246. char *pinned_key;
  247. char *CRLfile; /* CRL to check certificate revocation */
  248. struct curl_blob *cert_blob;
  249. struct curl_blob *ca_info_blob;
  250. struct curl_blob *issuercert_blob;
  251. #ifdef USE_TLS_SRP
  252. char *username; /* TLS username (for, e.g., SRP) */
  253. char *password; /* TLS password (for, e.g., SRP) */
  254. #endif
  255. char *curves; /* list of curves to use */
  256. unsigned char ssl_options; /* the CURLOPT_SSL_OPTIONS bitmask */
  257. unsigned int version_max; /* max supported version the client wants to use */
  258. unsigned char version; /* what version the client wants to use */
  259. BIT(verifypeer); /* set TRUE if this is desired */
  260. BIT(verifyhost); /* set TRUE if CN/SAN must match hostname */
  261. BIT(verifystatus); /* set TRUE if certificate status must be checked */
  262. BIT(sessionid); /* cache session IDs or not */
  263. };
  264. struct ssl_config_data {
  265. struct ssl_primary_config primary;
  266. long certverifyresult; /* result from the certificate verification */
  267. curl_ssl_ctx_callback fsslctx; /* function to initialize ssl ctx */
  268. void *fsslctxp; /* parameter for call back */
  269. char *cert_type; /* format for certificate (default: PEM)*/
  270. char *key; /* private key file name */
  271. struct curl_blob *key_blob;
  272. char *key_type; /* format for private key (default: PEM) */
  273. char *key_passwd; /* plain text private key password */
  274. BIT(certinfo); /* gather lots of certificate info */
  275. BIT(falsestart);
  276. BIT(enable_beast); /* allow this flaw for interoperability's sake */
  277. BIT(no_revoke); /* disable SSL certificate revocation checks */
  278. BIT(no_partialchain); /* don't accept partial certificate chains */
  279. BIT(revoke_best_effort); /* ignore SSL revocation offline/missing revocation
  280. list errors */
  281. BIT(native_ca_store); /* use the native ca store of operating system */
  282. BIT(auto_client_cert); /* automatically locate and use a client
  283. certificate for authentication (Schannel) */
  284. };
  285. struct ssl_general_config {
  286. size_t max_ssl_sessions; /* SSL session id cache size */
  287. int ca_cache_timeout; /* Certificate store cache timeout (seconds) */
  288. };
  289. typedef void Curl_ssl_sessionid_dtor(void *sessionid, size_t idsize);
  290. /* information stored about one single SSL session */
  291. struct Curl_ssl_session {
  292. char *name; /* host name for which this ID was used */
  293. char *conn_to_host; /* host name for the connection (may be NULL) */
  294. const char *scheme; /* protocol scheme used */
  295. void *sessionid; /* as returned from the SSL layer */
  296. size_t idsize; /* if known, otherwise 0 */
  297. Curl_ssl_sessionid_dtor *sessionid_free; /* free `sessionid` callback */
  298. long age; /* just a number, the higher the more recent */
  299. int remote_port; /* remote port */
  300. int conn_to_port; /* remote port for the connection (may be -1) */
  301. int transport; /* TCP or QUIC */
  302. struct ssl_primary_config ssl_config; /* setup for this session */
  303. };
  304. #ifdef USE_WINDOWS_SSPI
  305. #include "curl_sspi.h"
  306. #endif
  307. #ifndef CURL_DISABLE_DIGEST_AUTH
  308. /* Struct used for Digest challenge-response authentication */
  309. struct digestdata {
  310. #if defined(USE_WINDOWS_SSPI)
  311. BYTE *input_token;
  312. size_t input_token_len;
  313. CtxtHandle *http_context;
  314. /* copy of user/passwd used to make the identity for http_context.
  315. either may be NULL. */
  316. char *user;
  317. char *passwd;
  318. #else
  319. char *nonce;
  320. char *cnonce;
  321. char *realm;
  322. char *opaque;
  323. char *qop;
  324. char *algorithm;
  325. int nc; /* nonce count */
  326. unsigned char algo;
  327. BIT(stale); /* set true for re-negotiation */
  328. BIT(userhash);
  329. #endif
  330. };
  331. #endif
  332. typedef enum {
  333. NTLMSTATE_NONE,
  334. NTLMSTATE_TYPE1,
  335. NTLMSTATE_TYPE2,
  336. NTLMSTATE_TYPE3,
  337. NTLMSTATE_LAST
  338. } curlntlm;
  339. typedef enum {
  340. GSS_AUTHNONE,
  341. GSS_AUTHRECV,
  342. GSS_AUTHSENT,
  343. GSS_AUTHDONE,
  344. GSS_AUTHSUCC
  345. } curlnegotiate;
  346. /* Struct used for GSSAPI (Kerberos V5) authentication */
  347. #if defined(USE_KERBEROS5)
  348. struct kerberos5data {
  349. #if defined(USE_WINDOWS_SSPI)
  350. CredHandle *credentials;
  351. CtxtHandle *context;
  352. TCHAR *spn;
  353. SEC_WINNT_AUTH_IDENTITY identity;
  354. SEC_WINNT_AUTH_IDENTITY *p_identity;
  355. size_t token_max;
  356. BYTE *output_token;
  357. #else
  358. gss_ctx_id_t context;
  359. gss_name_t spn;
  360. #endif
  361. };
  362. #endif
  363. /* Struct used for SCRAM-SHA-1 authentication */
  364. #ifdef USE_GSASL
  365. #include <gsasl.h>
  366. struct gsasldata {
  367. Gsasl *ctx;
  368. Gsasl_session *client;
  369. };
  370. #endif
  371. /* Struct used for NTLM challenge-response authentication */
  372. #if defined(USE_NTLM)
  373. struct ntlmdata {
  374. #ifdef USE_WINDOWS_SSPI
  375. /* The sslContext is used for the Schannel bindings. The
  376. * api is available on the Windows 7 SDK and later.
  377. */
  378. #ifdef SECPKG_ATTR_ENDPOINT_BINDINGS
  379. CtxtHandle *sslContext;
  380. #endif
  381. CredHandle *credentials;
  382. CtxtHandle *context;
  383. SEC_WINNT_AUTH_IDENTITY identity;
  384. SEC_WINNT_AUTH_IDENTITY *p_identity;
  385. size_t token_max;
  386. BYTE *output_token;
  387. BYTE *input_token;
  388. size_t input_token_len;
  389. TCHAR *spn;
  390. #else
  391. unsigned int flags;
  392. unsigned char nonce[8];
  393. unsigned int target_info_len;
  394. void *target_info; /* TargetInfo received in the ntlm type-2 message */
  395. #endif
  396. };
  397. #endif
  398. /* Struct used for Negotiate (SPNEGO) authentication */
  399. #ifdef USE_SPNEGO
  400. struct negotiatedata {
  401. #ifdef HAVE_GSSAPI
  402. OM_uint32 status;
  403. gss_ctx_id_t context;
  404. gss_name_t spn;
  405. gss_buffer_desc output_token;
  406. #else
  407. #ifdef USE_WINDOWS_SSPI
  408. #ifdef SECPKG_ATTR_ENDPOINT_BINDINGS
  409. CtxtHandle *sslContext;
  410. #endif
  411. DWORD status;
  412. CredHandle *credentials;
  413. CtxtHandle *context;
  414. SEC_WINNT_AUTH_IDENTITY identity;
  415. SEC_WINNT_AUTH_IDENTITY *p_identity;
  416. TCHAR *spn;
  417. size_t token_max;
  418. BYTE *output_token;
  419. size_t output_token_length;
  420. #endif
  421. #endif
  422. BIT(noauthpersist);
  423. BIT(havenoauthpersist);
  424. BIT(havenegdata);
  425. BIT(havemultiplerequests);
  426. };
  427. #endif
  428. #ifdef CURL_DISABLE_PROXY
  429. #define CONN_IS_PROXIED(x) 0
  430. #else
  431. #define CONN_IS_PROXIED(x) x->bits.proxy
  432. #endif
  433. /*
  434. * Boolean values that concerns this connection.
  435. */
  436. struct ConnectBits {
  437. #ifndef CURL_DISABLE_PROXY
  438. BIT(httpproxy); /* if set, this transfer is done through an HTTP proxy */
  439. BIT(socksproxy); /* if set, this transfer is done through a socks proxy */
  440. BIT(proxy_user_passwd); /* user+password for the proxy? */
  441. BIT(tunnel_proxy); /* if CONNECT is used to "tunnel" through the proxy.
  442. This is implicit when SSL-protocols are used through
  443. proxies, but can also be enabled explicitly by
  444. apps */
  445. BIT(proxy_connect_closed); /* TRUE if a proxy disconnected the connection
  446. in a CONNECT request with auth, so that
  447. libcurl should reconnect and continue. */
  448. BIT(proxy); /* if set, this transfer is done through a proxy - any type */
  449. #endif
  450. /* always modify bits.close with the connclose() and connkeep() macros! */
  451. BIT(close); /* if set, we close the connection after this request */
  452. BIT(reuse); /* if set, this is a reused connection */
  453. BIT(altused); /* this is an alt-svc "redirect" */
  454. BIT(conn_to_host); /* if set, this connection has a "connect to host"
  455. that overrides the host in the URL */
  456. BIT(conn_to_port); /* if set, this connection has a "connect to port"
  457. that overrides the port in the URL (remote port) */
  458. BIT(ipv6_ip); /* we communicate with a remote site specified with pure IPv6
  459. IP address */
  460. BIT(ipv6); /* we communicate with a site using an IPv6 address */
  461. BIT(do_more); /* this is set TRUE if the ->curl_do_more() function is
  462. supposed to be called, after ->curl_do() */
  463. BIT(protoconnstart);/* the protocol layer has STARTED its operation after
  464. the TCP layer connect */
  465. BIT(retry); /* this connection is about to get closed and then
  466. re-attempted at another connection. */
  467. #ifndef CURL_DISABLE_FTP
  468. BIT(ftp_use_epsv); /* As set with CURLOPT_FTP_USE_EPSV, but if we find out
  469. EPSV doesn't work we disable it for the forthcoming
  470. requests */
  471. BIT(ftp_use_eprt); /* As set with CURLOPT_FTP_USE_EPRT, but if we find out
  472. EPRT doesn't work we disable it for the forthcoming
  473. requests */
  474. BIT(ftp_use_data_ssl); /* Enabled SSL for the data connection */
  475. BIT(ftp_use_control_ssl); /* Enabled SSL for the control connection */
  476. #endif
  477. #ifndef CURL_DISABLE_NETRC
  478. BIT(netrc); /* name+password provided by netrc */
  479. #endif
  480. BIT(bound); /* set true if bind() has already been done on this socket/
  481. connection */
  482. BIT(multiplex); /* connection is multiplexed */
  483. BIT(tcp_fastopen); /* use TCP Fast Open */
  484. BIT(tls_enable_alpn); /* TLS ALPN extension? */
  485. #ifndef CURL_DISABLE_DOH
  486. BIT(doh);
  487. #endif
  488. #ifdef USE_UNIX_SOCKETS
  489. BIT(abstract_unix_socket);
  490. #endif
  491. BIT(tls_upgraded);
  492. BIT(sock_accepted); /* TRUE if the SECONDARYSOCKET was created with
  493. accept() */
  494. BIT(parallel_connect); /* set TRUE when a parallel connect attempt has
  495. started (happy eyeballs) */
  496. BIT(aborted); /* connection was aborted, e.g. in unclean state */
  497. BIT(shutdown_handler); /* connection shutdown: handler shut down */
  498. BIT(shutdown_filters); /* connection shutdown: filters shut down */
  499. };
  500. struct hostname {
  501. char *rawalloc; /* allocated "raw" version of the name */
  502. char *encalloc; /* allocated IDN-encoded version of the name */
  503. char *name; /* name to use internally, might be encoded, might be raw */
  504. const char *dispname; /* name to display, as 'name' might be encoded */
  505. };
  506. /*
  507. * Flags on the keepon member of the Curl_transfer_keeper
  508. */
  509. #define KEEP_NONE 0
  510. #define KEEP_RECV (1<<0) /* there is or may be data to read */
  511. #define KEEP_SEND (1<<1) /* there is or may be data to write */
  512. #define KEEP_RECV_HOLD (1<<2) /* when set, no reading should be done but there
  513. might still be data to read */
  514. #define KEEP_SEND_HOLD (1<<3) /* when set, no writing should be done but there
  515. might still be data to write */
  516. #define KEEP_RECV_PAUSE (1<<4) /* reading is paused */
  517. #define KEEP_SEND_PAUSE (1<<5) /* writing is paused */
  518. /* KEEP_SEND_TIMED is set when the transfer should attempt sending
  519. * at timer (or other) events. A transfer waiting on a timer will
  520. * remove KEEP_SEND to suppress POLLOUTs of the connection.
  521. * Adding KEEP_SEND_TIMED will then attempt to send whenever the transfer
  522. * enters the "readwrite" loop, e.g. when a timer fires.
  523. * This is used in HTTP for 'Expect: 100-continue' waiting. */
  524. #define KEEP_SEND_TIMED (1<<6)
  525. #define KEEP_RECVBITS (KEEP_RECV | KEEP_RECV_HOLD | KEEP_RECV_PAUSE)
  526. #define KEEP_SENDBITS (KEEP_SEND | KEEP_SEND_HOLD | KEEP_SEND_PAUSE)
  527. /* transfer wants to send is not PAUSE or HOLD */
  528. #define CURL_WANT_SEND(data) \
  529. (((data)->req.keepon & KEEP_SENDBITS) == KEEP_SEND)
  530. /* transfer receive is not on PAUSE or HOLD */
  531. #define CURL_WANT_RECV(data) \
  532. (((data)->req.keepon & KEEP_RECVBITS) == KEEP_RECV)
  533. #if defined(CURLRES_ASYNCH) || !defined(CURL_DISABLE_DOH)
  534. #define USE_CURL_ASYNC
  535. struct Curl_async {
  536. char *hostname;
  537. struct Curl_dns_entry *dns;
  538. struct thread_data *tdata;
  539. void *resolver; /* resolver state, if it is used in the URL state -
  540. ares_channel e.g. */
  541. int port;
  542. int status; /* if done is TRUE, this is the status from the callback */
  543. BIT(done); /* set TRUE when the lookup is complete */
  544. };
  545. #endif
  546. #define FIRSTSOCKET 0
  547. #define SECONDARYSOCKET 1
  548. /* Polling requested by an easy handle.
  549. * `action` is CURL_POLL_IN, CURL_POLL_OUT or CURL_POLL_INOUT.
  550. */
  551. struct easy_pollset {
  552. curl_socket_t sockets[MAX_SOCKSPEREASYHANDLE];
  553. unsigned int num;
  554. unsigned char actions[MAX_SOCKSPEREASYHANDLE];
  555. };
  556. enum doh_slots {
  557. /* Explicit values for first two symbols so as to match hard-coded
  558. * constants in existing code
  559. */
  560. DOH_PROBE_SLOT_IPADDR_V4 = 0, /* make 'V4' stand out for readability */
  561. DOH_PROBE_SLOT_IPADDR_V6 = 1, /* 'V6' likewise */
  562. /* Space here for (possibly build-specific) additional slot definitions */
  563. #ifdef USE_HTTPSRR
  564. DOH_PROBE_SLOT_HTTPS = 2, /* for HTTPS RR */
  565. #endif
  566. /* for example */
  567. /* #ifdef WANT_DOH_FOOBAR_TXT */
  568. /* DOH_PROBE_SLOT_FOOBAR_TXT, */
  569. /* #endif */
  570. /* AFTER all slot definitions, establish how many we have */
  571. DOH_PROBE_SLOTS
  572. };
  573. /*
  574. * Specific protocol handler.
  575. */
  576. struct Curl_handler {
  577. const char *scheme; /* URL scheme name in lowercase */
  578. /* Complement to setup_connection_internals(). This is done before the
  579. transfer "owns" the connection. */
  580. CURLcode (*setup_connection)(struct Curl_easy *data,
  581. struct connectdata *conn);
  582. /* These two functions MUST be set to be protocol dependent */
  583. CURLcode (*do_it)(struct Curl_easy *data, bool *done);
  584. CURLcode (*done)(struct Curl_easy *, CURLcode, bool);
  585. /* If the curl_do() function is better made in two halves, this
  586. * curl_do_more() function will be called afterwards, if set. For example
  587. * for doing the FTP stuff after the PASV/PORT command.
  588. */
  589. CURLcode (*do_more)(struct Curl_easy *, int *);
  590. /* This function *MAY* be set to a protocol-dependent function that is run
  591. * after the connect() and everything is done, as a step in the connection.
  592. * The 'done' pointer points to a bool that should be set to TRUE if the
  593. * function completes before return. If it doesn't complete, the caller
  594. * should call the ->connecting() function until it is.
  595. */
  596. CURLcode (*connect_it)(struct Curl_easy *data, bool *done);
  597. /* See above. */
  598. CURLcode (*connecting)(struct Curl_easy *data, bool *done);
  599. CURLcode (*doing)(struct Curl_easy *data, bool *done);
  600. /* Called from the multi interface during the PROTOCONNECT phase, and it
  601. should then return a proper fd set */
  602. int (*proto_getsock)(struct Curl_easy *data,
  603. struct connectdata *conn, curl_socket_t *socks);
  604. /* Called from the multi interface during the DOING phase, and it should
  605. then return a proper fd set */
  606. int (*doing_getsock)(struct Curl_easy *data,
  607. struct connectdata *conn, curl_socket_t *socks);
  608. /* Called from the multi interface during the DO_MORE phase, and it should
  609. then return a proper fd set */
  610. int (*domore_getsock)(struct Curl_easy *data,
  611. struct connectdata *conn, curl_socket_t *socks);
  612. /* Called from the multi interface during the DO_DONE, PERFORM and
  613. WAITPERFORM phases, and it should then return a proper fd set. Not setting
  614. this will make libcurl use the generic default one. */
  615. int (*perform_getsock)(struct Curl_easy *data,
  616. struct connectdata *conn, curl_socket_t *socks);
  617. /* This function *MAY* be set to a protocol-dependent function that is run
  618. * by the curl_disconnect(), as a step in the disconnection. If the handler
  619. * is called because the connection has been considered dead,
  620. * dead_connection is set to TRUE. The connection is (again) associated with
  621. * the transfer here.
  622. */
  623. CURLcode (*disconnect)(struct Curl_easy *, struct connectdata *,
  624. bool dead_connection);
  625. /* If used, this function gets called from transfer.c to
  626. allow the protocol to do extra handling in writing response to
  627. the client. */
  628. CURLcode (*write_resp)(struct Curl_easy *data, const char *buf, size_t blen,
  629. bool is_eos);
  630. /* If used, this function gets called from transfer.c to
  631. allow the protocol to do extra handling in writing a single response
  632. header line to the client. */
  633. CURLcode (*write_resp_hd)(struct Curl_easy *data,
  634. const char *hd, size_t hdlen, bool is_eos);
  635. /* This function can perform various checks on the connection. See
  636. CONNCHECK_* for more information about the checks that can be performed,
  637. and CONNRESULT_* for the results that can be returned. */
  638. unsigned int (*connection_check)(struct Curl_easy *data,
  639. struct connectdata *conn,
  640. unsigned int checks_to_perform);
  641. /* attach() attaches this transfer to this connection */
  642. void (*attach)(struct Curl_easy *data, struct connectdata *conn);
  643. int defport; /* Default port. */
  644. curl_prot_t protocol; /* See CURLPROTO_* - this needs to be the single
  645. specific protocol bit */
  646. curl_prot_t family; /* single bit for protocol family; basically the
  647. non-TLS name of the protocol this is */
  648. unsigned int flags; /* Extra particular characteristics, see PROTOPT_* */
  649. };
  650. #define PROTOPT_NONE 0 /* nothing extra */
  651. #define PROTOPT_SSL (1<<0) /* uses SSL */
  652. #define PROTOPT_DUAL (1<<1) /* this protocol uses two connections */
  653. #define PROTOPT_CLOSEACTION (1<<2) /* need action before socket close */
  654. /* some protocols will have to call the underlying functions without regard to
  655. what exact state the socket signals. IE even if the socket says "readable",
  656. the send function might need to be called while uploading, or vice versa.
  657. */
  658. #define PROTOPT_DIRLOCK (1<<3)
  659. #define PROTOPT_NONETWORK (1<<4) /* protocol doesn't use the network! */
  660. #define PROTOPT_NEEDSPWD (1<<5) /* needs a password, and if none is set it
  661. gets a default */
  662. #define PROTOPT_NOURLQUERY (1<<6) /* protocol can't handle
  663. url query strings (?foo=bar) ! */
  664. #define PROTOPT_CREDSPERREQUEST (1<<7) /* requires login credentials per
  665. request instead of per connection */
  666. #define PROTOPT_ALPN (1<<8) /* set ALPN for this */
  667. /* (1<<9) was PROTOPT_STREAM, now free */
  668. #define PROTOPT_URLOPTIONS (1<<10) /* allow options part in the userinfo field
  669. of the URL */
  670. #define PROTOPT_PROXY_AS_HTTP (1<<11) /* allow this non-HTTP scheme over a
  671. HTTP proxy as HTTP proxies may know
  672. this protocol and act as a gateway */
  673. #define PROTOPT_WILDCARD (1<<12) /* protocol supports wildcard matching */
  674. #define PROTOPT_USERPWDCTRL (1<<13) /* Allow "control bytes" (< 32 ascii) in
  675. user name and password */
  676. #define PROTOPT_NOTCPPROXY (1<<14) /* this protocol can't proxy over TCP */
  677. #define CONNCHECK_NONE 0 /* No checks */
  678. #define CONNCHECK_ISDEAD (1<<0) /* Check if the connection is dead. */
  679. #define CONNCHECK_KEEPALIVE (1<<1) /* Perform any keepalive function. */
  680. #define CONNRESULT_NONE 0 /* No extra information. */
  681. #define CONNRESULT_DEAD (1<<0) /* The connection is dead. */
  682. struct ip_quadruple {
  683. char remote_ip[MAX_IPADR_LEN];
  684. char local_ip[MAX_IPADR_LEN];
  685. int remote_port;
  686. int local_port;
  687. };
  688. struct proxy_info {
  689. struct hostname host;
  690. int port;
  691. unsigned char proxytype; /* curl_proxytype: what kind of proxy that is in
  692. use */
  693. char *user; /* proxy user name string, allocated */
  694. char *passwd; /* proxy password string, allocated */
  695. };
  696. struct ldapconninfo;
  697. #define TRNSPRT_TCP 3
  698. #define TRNSPRT_UDP 4
  699. #define TRNSPRT_QUIC 5
  700. #define TRNSPRT_UNIX 6
  701. /*
  702. * The connectdata struct contains all fields and variables that should be
  703. * unique for an entire connection.
  704. */
  705. struct connectdata {
  706. struct Curl_llist_element bundle_node; /* conncache */
  707. curl_closesocket_callback fclosesocket; /* function closing the socket(s) */
  708. void *closesocket_client;
  709. /* This is used by the connection cache logic. If this returns TRUE, this
  710. handle is still used by one or more easy handles and can only used by any
  711. other easy handle without careful consideration (== only for
  712. multiplexing) and it cannot be used by another multi handle! */
  713. #define CONN_INUSE(c) ((c)->easyq.size)
  714. /**** Fields set when inited and not modified again */
  715. curl_off_t connection_id; /* Contains a unique number to make it easier to
  716. track the connections in the log output */
  717. /* 'dns_entry' is the particular host we use. This points to an entry in the
  718. DNS cache and it will not get pruned while locked. It gets unlocked in
  719. multi_done(). This entry will be NULL if the connection is reused as then
  720. there is no name resolve done. */
  721. struct Curl_dns_entry *dns_entry;
  722. /* 'remote_addr' is the particular IP we connected to. it is owned, set
  723. * and NULLed by the connected socket filter (if there is one). */
  724. const struct Curl_sockaddr_ex *remote_addr;
  725. struct hostname host;
  726. char *hostname_resolve; /* host name to resolve to address, allocated */
  727. char *secondaryhostname; /* secondary socket host name (ftp) */
  728. struct hostname conn_to_host; /* the host to connect to. valid only if
  729. bits.conn_to_host is set */
  730. #ifndef CURL_DISABLE_PROXY
  731. struct proxy_info socks_proxy;
  732. struct proxy_info http_proxy;
  733. #endif
  734. /* 'primary' and 'secondary' get filled with IP quadruple
  735. (local/remote numerical ip address and port) whenever a is *attempted*.
  736. When more than one address is tried for a connection these will hold data
  737. for the last attempt. When the connection is actually established
  738. these are updated with data which comes directly from the socket. */
  739. struct ip_quadruple primary;
  740. struct ip_quadruple secondary;
  741. char *user; /* user name string, allocated */
  742. char *passwd; /* password string, allocated */
  743. char *options; /* options string, allocated */
  744. char *sasl_authzid; /* authorization identity string, allocated */
  745. char *oauth_bearer; /* OAUTH2 bearer, allocated */
  746. struct curltime now; /* "current" time */
  747. struct curltime created; /* creation time */
  748. struct curltime lastused; /* when returned to the connection cache */
  749. curl_socket_t sock[2]; /* two sockets, the second is used for the data
  750. transfer when doing FTP */
  751. Curl_recv *recv[2];
  752. Curl_send *send[2];
  753. struct Curl_cfilter *cfilter[2]; /* connection filters */
  754. struct {
  755. struct curltime start[2]; /* when filter shutdown started */
  756. unsigned int timeout_ms; /* 0 means no timeout */
  757. } shutdown;
  758. struct ssl_primary_config ssl_config;
  759. #ifndef CURL_DISABLE_PROXY
  760. struct ssl_primary_config proxy_ssl_config;
  761. #endif
  762. struct ConnectBits bits; /* various state-flags for this connection */
  763. const struct Curl_handler *handler; /* Connection's protocol handler */
  764. const struct Curl_handler *given; /* The protocol first given */
  765. /* Protocols can use a custom keepalive mechanism to keep connections alive.
  766. This allows those protocols to track the last time the keepalive mechanism
  767. was used on this connection. */
  768. struct curltime keepalive;
  769. /**** curl_get() phase fields */
  770. curl_socket_t sockfd; /* socket to read from or CURL_SOCKET_BAD */
  771. curl_socket_t writesockfd; /* socket to write to, it may very
  772. well be the same we read from.
  773. CURL_SOCKET_BAD disables */
  774. #ifdef HAVE_GSSAPI
  775. BIT(sec_complete); /* if Kerberos is enabled for this connection */
  776. unsigned char command_prot; /* enum protection_level */
  777. unsigned char data_prot; /* enum protection_level */
  778. unsigned char request_data_prot; /* enum protection_level */
  779. size_t buffer_size;
  780. struct krb5buffer in_buffer;
  781. void *app_data;
  782. const struct Curl_sec_client_mech *mech;
  783. struct sockaddr_in local_addr;
  784. #endif
  785. #if defined(USE_KERBEROS5) /* Consider moving some of the above GSS-API */
  786. struct kerberos5data krb5; /* variables into the structure definition, */
  787. #endif /* however, some of them are ftp specific. */
  788. struct Curl_llist easyq; /* List of easy handles using this connection */
  789. /*************** Request - specific items ************/
  790. #if defined(USE_WINDOWS_SSPI) && defined(SECPKG_ATTR_ENDPOINT_BINDINGS)
  791. CtxtHandle *sslContext;
  792. #endif
  793. #ifdef USE_GSASL
  794. struct gsasldata gsasl;
  795. #endif
  796. #if defined(USE_NTLM)
  797. curlntlm http_ntlm_state;
  798. curlntlm proxy_ntlm_state;
  799. struct ntlmdata ntlm; /* NTLM differs from other authentication schemes
  800. because it authenticates connections, not
  801. single requests! */
  802. struct ntlmdata proxyntlm; /* NTLM data for proxy */
  803. #endif
  804. #ifdef USE_SPNEGO
  805. curlnegotiate http_negotiate_state;
  806. curlnegotiate proxy_negotiate_state;
  807. struct negotiatedata negotiate; /* state data for host Negotiate auth */
  808. struct negotiatedata proxyneg; /* state data for proxy Negotiate auth */
  809. #endif
  810. union {
  811. #ifndef CURL_DISABLE_FTP
  812. struct ftp_conn ftpc;
  813. #endif
  814. #ifdef USE_SSH
  815. struct ssh_conn sshc;
  816. #endif
  817. #ifndef CURL_DISABLE_TFTP
  818. struct tftp_state_data *tftpc;
  819. #endif
  820. #ifndef CURL_DISABLE_IMAP
  821. struct imap_conn imapc;
  822. #endif
  823. #ifndef CURL_DISABLE_POP3
  824. struct pop3_conn pop3c;
  825. #endif
  826. #ifndef CURL_DISABLE_SMTP
  827. struct smtp_conn smtpc;
  828. #endif
  829. #ifndef CURL_DISABLE_RTSP
  830. struct rtsp_conn rtspc;
  831. #endif
  832. #ifndef CURL_DISABLE_SMB
  833. struct smb_conn smbc;
  834. #endif
  835. #ifdef USE_LIBRTMP
  836. void *rtmp;
  837. #endif
  838. #ifdef USE_OPENLDAP
  839. struct ldapconninfo *ldapc;
  840. #endif
  841. #ifndef CURL_DISABLE_MQTT
  842. struct mqtt_conn mqtt;
  843. #endif
  844. #ifdef USE_WEBSOCKETS
  845. struct websocket *ws;
  846. #endif
  847. unsigned int unused:1; /* avoids empty union */
  848. } proto;
  849. struct connectbundle *bundle; /* The bundle we are member of */
  850. #ifdef USE_UNIX_SOCKETS
  851. char *unix_domain_socket;
  852. #endif
  853. #ifdef USE_HYPER
  854. /* if set, an alternative data transfer function */
  855. Curl_datastream datastream;
  856. #endif
  857. /* When this connection is created, store the conditions for the local end
  858. bind. This is stored before the actual bind and before any connection is
  859. made and will serve the purpose of being used for comparison reasons so
  860. that subsequent bound-requested connections aren't accidentally reusing
  861. wrong connections. */
  862. char *localdev;
  863. unsigned short localportrange;
  864. int waitfor; /* current READ/WRITE bits to wait for */
  865. #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
  866. int socks5_gssapi_enctype;
  867. #endif
  868. /* The field below gets set in connect.c:connecthost() */
  869. int remote_port; /* the remote port, not the proxy port! */
  870. int conn_to_port; /* the remote port to connect to. valid only if
  871. bits.conn_to_port is set */
  872. #ifdef USE_IPV6
  873. unsigned int scope_id; /* Scope id for IPv6 */
  874. #endif
  875. unsigned short localport;
  876. unsigned short secondary_port; /* secondary socket remote port to connect to
  877. (ftp) */
  878. unsigned char alpn; /* APLN TLS negotiated protocol, a CURL_HTTP_VERSION*
  879. value */
  880. #ifndef CURL_DISABLE_PROXY
  881. unsigned char proxy_alpn; /* APLN of proxy tunnel, CURL_HTTP_VERSION* */
  882. #endif
  883. unsigned char transport; /* one of the TRNSPRT_* defines */
  884. unsigned char ip_version; /* copied from the Curl_easy at creation time */
  885. unsigned char httpversion; /* the HTTP version*10 reported by the server */
  886. unsigned char connect_only;
  887. unsigned char gssapi_delegation; /* inherited from set.gssapi_delegation */
  888. };
  889. #ifndef CURL_DISABLE_PROXY
  890. #define CURL_CONN_HOST_DISPNAME(c) \
  891. ((c)->bits.socksproxy ? (c)->socks_proxy.host.dispname : \
  892. (c)->bits.httpproxy ? (c)->http_proxy.host.dispname : \
  893. (c)->bits.conn_to_host ? (c)->conn_to_host.dispname : \
  894. (c)->host.dispname)
  895. #else
  896. #define CURL_CONN_HOST_DISPNAME(c) \
  897. (c)->bits.conn_to_host ? (c)->conn_to_host.dispname : \
  898. (c)->host.dispname
  899. #endif
  900. /* The end of connectdata. */
  901. /*
  902. * Struct to keep statistical and informational data.
  903. * All variables in this struct must be initialized/reset in Curl_initinfo().
  904. */
  905. struct PureInfo {
  906. int httpcode; /* Recent HTTP, FTP, RTSP or SMTP response code */
  907. int httpproxycode; /* response code from proxy when received separate */
  908. int httpversion; /* the http version number X.Y = X*10+Y */
  909. time_t filetime; /* If requested, this is might get set. Set to -1 if the
  910. time was unretrievable. */
  911. curl_off_t request_size; /* the amount of bytes sent in the request(s) */
  912. unsigned long proxyauthavail; /* what proxy auth types were announced */
  913. unsigned long httpauthavail; /* what host auth types were announced */
  914. long numconnects; /* how many new connection did libcurl created */
  915. char *contenttype; /* the content type of the object */
  916. char *wouldredirect; /* URL this would've been redirected to if asked to */
  917. curl_off_t retry_after; /* info from Retry-After: header */
  918. unsigned int header_size; /* size of read header(s) in bytes */
  919. /* PureInfo primary ip_quadruple is copied over from the connectdata
  920. struct in order to allow curl_easy_getinfo() to return this information
  921. even when the session handle is no longer associated with a connection,
  922. and also allow curl_easy_reset() to clear this information from the
  923. session handle without disturbing information which is still alive, and
  924. that might be reused, in the connection cache. */
  925. struct ip_quadruple primary;
  926. int conn_remote_port; /* this is the "remote port", which is the port
  927. number of the used URL, independent of proxy or
  928. not */
  929. const char *conn_scheme;
  930. unsigned int conn_protocol;
  931. struct curl_certinfo certs; /* info about the certs. Asked for with
  932. CURLOPT_CERTINFO / CURLINFO_CERTINFO */
  933. CURLproxycode pxcode;
  934. BIT(timecond); /* set to TRUE if the time condition didn't match, which
  935. thus made the document NOT get fetched */
  936. BIT(used_proxy); /* the transfer used a proxy */
  937. };
  938. struct Progress {
  939. time_t lastshow; /* time() of the last displayed progress meter or NULL to
  940. force redraw at next call */
  941. curl_off_t size_dl; /* total expected size */
  942. curl_off_t size_ul; /* total expected size */
  943. curl_off_t downloaded; /* transferred so far */
  944. curl_off_t uploaded; /* transferred so far */
  945. curl_off_t current_speed; /* uses the currently fastest transfer */
  946. int width; /* screen width at download start */
  947. int flags; /* see progress.h */
  948. timediff_t timespent;
  949. curl_off_t dlspeed;
  950. curl_off_t ulspeed;
  951. timediff_t t_postqueue;
  952. timediff_t t_nslookup;
  953. timediff_t t_connect;
  954. timediff_t t_appconnect;
  955. timediff_t t_pretransfer;
  956. timediff_t t_starttransfer;
  957. timediff_t t_redirect;
  958. struct curltime start;
  959. struct curltime t_startsingle;
  960. struct curltime t_startop;
  961. struct curltime t_acceptdata;
  962. /* upload speed limit */
  963. struct curltime ul_limit_start;
  964. curl_off_t ul_limit_size;
  965. /* download speed limit */
  966. struct curltime dl_limit_start;
  967. curl_off_t dl_limit_size;
  968. #define CURR_TIME (5 + 1) /* 6 entries for 5 seconds */
  969. curl_off_t speeder[ CURR_TIME ];
  970. struct curltime speeder_time[ CURR_TIME ];
  971. int speeder_c;
  972. BIT(callback); /* set when progress callback is used */
  973. BIT(is_t_startransfer_set);
  974. };
  975. typedef enum {
  976. RTSPREQ_NONE, /* first in list */
  977. RTSPREQ_OPTIONS,
  978. RTSPREQ_DESCRIBE,
  979. RTSPREQ_ANNOUNCE,
  980. RTSPREQ_SETUP,
  981. RTSPREQ_PLAY,
  982. RTSPREQ_PAUSE,
  983. RTSPREQ_TEARDOWN,
  984. RTSPREQ_GET_PARAMETER,
  985. RTSPREQ_SET_PARAMETER,
  986. RTSPREQ_RECORD,
  987. RTSPREQ_RECEIVE,
  988. RTSPREQ_LAST /* last in list */
  989. } Curl_RtspReq;
  990. struct auth {
  991. unsigned long want; /* Bitmask set to the authentication methods wanted by
  992. app (with CURLOPT_HTTPAUTH or CURLOPT_PROXYAUTH). */
  993. unsigned long picked;
  994. unsigned long avail; /* Bitmask for what the server reports to support for
  995. this resource */
  996. BIT(done); /* TRUE when the auth phase is done and ready to do the
  997. actual request */
  998. BIT(multipass); /* TRUE if this is not yet authenticated but within the
  999. auth multipass negotiation */
  1000. BIT(iestyle); /* TRUE if digest should be done IE-style or FALSE if it
  1001. should be RFC compliant */
  1002. };
  1003. #ifdef USE_NGHTTP2
  1004. struct Curl_data_prio_node {
  1005. struct Curl_data_prio_node *next;
  1006. struct Curl_easy *data;
  1007. };
  1008. #endif
  1009. /**
  1010. * Priority information for an easy handle in relation to others
  1011. * on the same connection.
  1012. * TODO: we need to adapt it to the new priority scheme as defined in RFC 9218
  1013. */
  1014. struct Curl_data_priority {
  1015. #ifdef USE_NGHTTP2
  1016. /* tree like dependencies only implemented in nghttp2 */
  1017. struct Curl_easy *parent;
  1018. struct Curl_data_prio_node *children;
  1019. #endif
  1020. int weight;
  1021. #ifdef USE_NGHTTP2
  1022. BIT(exclusive);
  1023. #endif
  1024. };
  1025. /* Timers */
  1026. typedef enum {
  1027. EXPIRE_100_TIMEOUT,
  1028. EXPIRE_ASYNC_NAME,
  1029. EXPIRE_CONNECTTIMEOUT,
  1030. EXPIRE_DNS_PER_NAME, /* family1 */
  1031. EXPIRE_DNS_PER_NAME2, /* family2 */
  1032. EXPIRE_HAPPY_EYEBALLS_DNS, /* See asyn-ares.c */
  1033. EXPIRE_HAPPY_EYEBALLS,
  1034. EXPIRE_MULTI_PENDING,
  1035. EXPIRE_RUN_NOW,
  1036. EXPIRE_SPEEDCHECK,
  1037. EXPIRE_TIMEOUT,
  1038. EXPIRE_TOOFAST,
  1039. EXPIRE_QUIC,
  1040. EXPIRE_FTP_ACCEPT,
  1041. EXPIRE_ALPN_EYEBALLS,
  1042. EXPIRE_LAST /* not an actual timer, used as a marker only */
  1043. } expire_id;
  1044. typedef enum {
  1045. TRAILERS_NONE,
  1046. TRAILERS_INITIALIZED,
  1047. TRAILERS_SENDING,
  1048. TRAILERS_DONE
  1049. } trailers_state;
  1050. /*
  1051. * One instance for each timeout an easy handle can set.
  1052. */
  1053. struct time_node {
  1054. struct Curl_llist_element list;
  1055. struct curltime time;
  1056. expire_id eid;
  1057. };
  1058. /* individual pieces of the URL */
  1059. struct urlpieces {
  1060. char *scheme;
  1061. char *hostname;
  1062. char *port;
  1063. char *user;
  1064. char *password;
  1065. char *options;
  1066. char *path;
  1067. char *query;
  1068. };
  1069. struct UrlState {
  1070. /* Points to the connection cache */
  1071. struct conncache *conn_cache;
  1072. /* buffers to store authentication data in, as parsed from input options */
  1073. struct curltime keeps_speed; /* for the progress meter really */
  1074. curl_off_t lastconnect_id; /* The last connection, -1 if undefined */
  1075. curl_off_t recent_conn_id; /* The most recent connection used, might no
  1076. * longer exist */
  1077. struct dynbuf headerb; /* buffer to store headers in */
  1078. struct curl_slist *hstslist; /* list of HSTS files set by
  1079. curl_easy_setopt(HSTS) calls */
  1080. curl_off_t current_speed; /* the ProgressShow() function sets this,
  1081. bytes / second */
  1082. /* host name, port number and protocol of the first (not followed) request.
  1083. if set, this should be the host name that we will sent authorization to,
  1084. no else. Used to make Location: following not keep sending user+password.
  1085. This is strdup()ed data. */
  1086. char *first_host;
  1087. int first_remote_port;
  1088. curl_prot_t first_remote_protocol;
  1089. int retrycount; /* number of retries on a new connection */
  1090. struct Curl_ssl_session *session; /* array of 'max_ssl_sessions' size */
  1091. long sessionage; /* number of the most recent session */
  1092. int os_errno; /* filled in with errno whenever an error occurs */
  1093. char *scratch; /* huge buffer[set.buffer_size*2] for upload CRLF replacing */
  1094. long followlocation; /* redirect counter */
  1095. int requests; /* request counter: redirects + authentication retakes */
  1096. #ifdef HAVE_SIGNAL
  1097. /* storage for the previous bag^H^H^HSIGPIPE signal handler :-) */
  1098. void (*prev_signal)(int sig);
  1099. #endif
  1100. #ifndef CURL_DISABLE_DIGEST_AUTH
  1101. struct digestdata digest; /* state data for host Digest auth */
  1102. struct digestdata proxydigest; /* state data for proxy Digest auth */
  1103. #endif
  1104. struct auth authhost; /* auth details for host */
  1105. struct auth authproxy; /* auth details for proxy */
  1106. #ifdef USE_CURL_ASYNC
  1107. struct Curl_async async; /* asynchronous name resolver data */
  1108. #endif
  1109. #if defined(USE_OPENSSL)
  1110. /* void instead of ENGINE to avoid bleeding OpenSSL into this header */
  1111. void *engine;
  1112. #endif /* USE_OPENSSL */
  1113. struct curltime expiretime; /* set this with Curl_expire() only */
  1114. struct Curl_tree timenode; /* for the splay stuff */
  1115. struct Curl_llist timeoutlist; /* list of pending timeouts */
  1116. struct time_node expires[EXPIRE_LAST]; /* nodes for each expire type */
  1117. /* a place to store the most recently set (S)FTP entrypath */
  1118. char *most_recent_ftp_entrypath;
  1119. #if !defined(_WIN32) && !defined(MSDOS) && !defined(__EMX__)
  1120. /* do FTP line-end conversions on most platforms */
  1121. #define CURL_DO_LINEEND_CONV
  1122. /* for FTP downloads: how many CRLFs did we converted to LFs? */
  1123. curl_off_t crlf_conversions;
  1124. #endif
  1125. char *range; /* range, if used. See README for detailed specification on
  1126. this syntax. */
  1127. curl_off_t resume_from; /* continue [ftp] transfer from here */
  1128. #ifndef CURL_DISABLE_RTSP
  1129. /* This RTSP state information survives requests and connections */
  1130. long rtsp_next_client_CSeq; /* the session's next client CSeq */
  1131. long rtsp_next_server_CSeq; /* the session's next server CSeq */
  1132. long rtsp_CSeq_recv; /* most recent CSeq received */
  1133. unsigned char rtp_channel_mask[32]; /* for the correctness checking of the
  1134. interleaved data */
  1135. #endif
  1136. curl_off_t infilesize; /* size of file to upload, -1 means unknown.
  1137. Copied from set.filesize at start of operation */
  1138. #if defined(USE_HTTP2) || defined(USE_HTTP3)
  1139. struct Curl_data_priority priority; /* shallow copy of data->set */
  1140. #endif
  1141. curl_read_callback fread_func; /* read callback/function */
  1142. void *in; /* CURLOPT_READDATA */
  1143. CURLU *uh; /* URL handle for the current parsed URL */
  1144. struct urlpieces up;
  1145. char *url; /* work URL, copied from UserDefined */
  1146. char *referer; /* referer string */
  1147. struct curl_slist *resolve; /* set to point to the set.resolve list when
  1148. this should be dealt with in pretransfer */
  1149. #ifndef CURL_DISABLE_HTTP
  1150. curl_mimepart *mimepost;
  1151. #ifndef CURL_DISABLE_FORM_API
  1152. curl_mimepart *formp; /* storage for old API form-posting, allocated on
  1153. demand */
  1154. #endif
  1155. size_t trailers_bytes_sent;
  1156. struct dynbuf trailers_buf; /* a buffer containing the compiled trailing
  1157. headers */
  1158. struct Curl_llist httphdrs; /* received headers */
  1159. struct curl_header headerout[2]; /* for external purposes */
  1160. struct Curl_header_store *prevhead; /* the latest added header */
  1161. trailers_state trailers_state; /* whether we are sending trailers
  1162. and what stage are we at */
  1163. #endif
  1164. #ifndef CURL_DISABLE_COOKIES
  1165. struct curl_slist *cookielist; /* list of cookie files set by
  1166. curl_easy_setopt(COOKIEFILE) calls */
  1167. #endif
  1168. #ifdef USE_HYPER
  1169. bool hconnect; /* set if a CONNECT request */
  1170. CURLcode hresult; /* used to pass return codes back from hyper callbacks */
  1171. #endif
  1172. #ifndef CURL_DISABLE_VERBOSE_STRINGS
  1173. struct curl_trc_feat *feat; /* opt. trace feature transfer is part of */
  1174. #endif
  1175. /* Dynamically allocated strings, MUST be freed before this struct is
  1176. killed. */
  1177. struct dynamically_allocated_data {
  1178. char *uagent;
  1179. char *accept_encoding;
  1180. char *userpwd;
  1181. char *rangeline;
  1182. char *ref;
  1183. char *host;
  1184. #ifndef CURL_DISABLE_COOKIES
  1185. char *cookiehost;
  1186. #endif
  1187. #ifndef CURL_DISABLE_RTSP
  1188. char *rtsp_transport;
  1189. #endif
  1190. char *te; /* TE: request header */
  1191. /* transfer credentials */
  1192. char *user;
  1193. char *passwd;
  1194. #ifndef CURL_DISABLE_PROXY
  1195. char *proxyuserpwd;
  1196. char *proxyuser;
  1197. char *proxypasswd;
  1198. #endif
  1199. } aptr;
  1200. unsigned char httpwant; /* when non-zero, a specific HTTP version requested
  1201. to be used in the library's request(s) */
  1202. unsigned char httpversion; /* the lowest HTTP version*10 reported by any
  1203. server involved in this request */
  1204. unsigned char httpreq; /* Curl_HttpReq; what kind of HTTP request (if any)
  1205. is this */
  1206. unsigned char select_bits; /* != 0 -> bitmask of socket events for this
  1207. transfer overriding anything the socket may
  1208. report */
  1209. #ifdef DEBUGBUILD
  1210. BIT(conncache_lock);
  1211. #endif
  1212. /* when curl_easy_perform() is called, the multi handle is "owned" by
  1213. the easy handle so curl_easy_cleanup() on such an easy handle will
  1214. also close the multi handle! */
  1215. BIT(multi_owned_by_easy);
  1216. BIT(this_is_a_follow); /* this is a followed Location: request */
  1217. BIT(refused_stream); /* this was refused, try again */
  1218. BIT(errorbuf); /* Set to TRUE if the error buffer is already filled in.
  1219. This must be set to FALSE every time _easy_perform() is
  1220. called. */
  1221. BIT(allow_port); /* Is set.use_port allowed to take effect or not. This
  1222. is always set TRUE when curl_easy_perform() is called. */
  1223. BIT(authproblem); /* TRUE if there's some problem authenticating */
  1224. /* set after initial USER failure, to prevent an authentication loop */
  1225. BIT(wildcardmatch); /* enable wildcard matching */
  1226. BIT(disableexpect); /* TRUE if Expect: is disabled due to a previous
  1227. 417 response */
  1228. BIT(use_range);
  1229. BIT(rangestringalloc); /* the range string is malloc()'ed */
  1230. BIT(done); /* set to FALSE when Curl_init_do() is called and set to TRUE
  1231. when multi_done() is called, to prevent multi_done() to get
  1232. invoked twice when the multi interface is used. */
  1233. #ifndef CURL_DISABLE_COOKIES
  1234. BIT(cookie_engine);
  1235. #endif
  1236. BIT(prefer_ascii); /* ASCII rather than binary */
  1237. #ifdef CURL_LIST_ONLY_PROTOCOL
  1238. BIT(list_only); /* list directory contents */
  1239. #endif
  1240. BIT(url_alloc); /* URL string is malloc()'ed */
  1241. BIT(referer_alloc); /* referer string is malloc()ed */
  1242. BIT(wildcard_resolve); /* Set to true if any resolve change is a wildcard */
  1243. BIT(upload); /* upload request */
  1244. BIT(internal); /* internal: true if this easy handle was created for
  1245. internal use and the user does not have ownership of the
  1246. handle. */
  1247. };
  1248. /*
  1249. * This 'UserDefined' struct must only contain data that is set once to go
  1250. * for many (perhaps) independent connections. Values that are generated or
  1251. * calculated internally for the "session handle" MUST be defined within the
  1252. * 'struct UrlState' instead. The only exceptions MUST note the changes in
  1253. * the 'DynamicStatic' struct.
  1254. * Character pointer fields point to dynamic storage, unless otherwise stated.
  1255. */
  1256. struct Curl_multi; /* declared in multihandle.c */
  1257. enum dupstring {
  1258. STRING_CERT, /* client certificate file name */
  1259. STRING_CERT_TYPE, /* format for certificate (default: PEM)*/
  1260. STRING_KEY, /* private key file name */
  1261. STRING_KEY_PASSWD, /* plain text private key password */
  1262. STRING_KEY_TYPE, /* format for private key (default: PEM) */
  1263. STRING_SSL_CAPATH, /* CA directory name (doesn't work on windows) */
  1264. STRING_SSL_CAFILE, /* certificate file to verify peer against */
  1265. STRING_SSL_PINNEDPUBLICKEY, /* public key file to verify peer against */
  1266. STRING_SSL_CIPHER_LIST, /* list of ciphers to use */
  1267. STRING_SSL_CIPHER13_LIST, /* list of TLS 1.3 ciphers to use */
  1268. STRING_SSL_CRLFILE, /* crl file to check certificate */
  1269. STRING_SSL_ISSUERCERT, /* issuer cert file to check certificate */
  1270. STRING_SERVICE_NAME, /* Service name */
  1271. #ifndef CURL_DISABLE_PROXY
  1272. STRING_CERT_PROXY, /* client certificate file name */
  1273. STRING_CERT_TYPE_PROXY, /* format for certificate (default: PEM)*/
  1274. STRING_KEY_PROXY, /* private key file name */
  1275. STRING_KEY_PASSWD_PROXY, /* plain text private key password */
  1276. STRING_KEY_TYPE_PROXY, /* format for private key (default: PEM) */
  1277. STRING_SSL_CAPATH_PROXY, /* CA directory name (doesn't work on windows) */
  1278. STRING_SSL_CAFILE_PROXY, /* certificate file to verify peer against */
  1279. STRING_SSL_PINNEDPUBLICKEY_PROXY, /* public key file to verify proxy */
  1280. STRING_SSL_CIPHER_LIST_PROXY, /* list of ciphers to use */
  1281. STRING_SSL_CIPHER13_LIST_PROXY, /* list of TLS 1.3 ciphers to use */
  1282. STRING_SSL_CRLFILE_PROXY, /* crl file to check certificate */
  1283. STRING_SSL_ISSUERCERT_PROXY, /* issuer cert file to check certificate */
  1284. STRING_PROXY_SERVICE_NAME, /* Proxy service name */
  1285. #endif
  1286. #ifndef CURL_DISABLE_COOKIES
  1287. STRING_COOKIE, /* HTTP cookie string to send */
  1288. STRING_COOKIEJAR, /* dump all cookies to this file */
  1289. #endif
  1290. STRING_CUSTOMREQUEST, /* HTTP/FTP/RTSP request/method to use */
  1291. STRING_DEFAULT_PROTOCOL, /* Protocol to use when the URL doesn't specify */
  1292. STRING_DEVICE, /* local network interface/address to use */
  1293. STRING_INTERFACE, /* local network interface to use */
  1294. STRING_BINDHOST, /* local address to use */
  1295. STRING_ENCODING, /* Accept-Encoding string */
  1296. #ifndef CURL_DISABLE_FTP
  1297. STRING_FTP_ACCOUNT, /* ftp account data */
  1298. STRING_FTP_ALTERNATIVE_TO_USER, /* command to send if USER/PASS fails */
  1299. STRING_FTPPORT, /* port to send with the FTP PORT command */
  1300. #endif
  1301. #if defined(HAVE_GSSAPI)
  1302. STRING_KRB_LEVEL, /* krb security level */
  1303. #endif
  1304. #ifndef CURL_DISABLE_NETRC
  1305. STRING_NETRC_FILE, /* if not NULL, use this instead of trying to find
  1306. $HOME/.netrc */
  1307. #endif
  1308. #ifndef CURL_DISABLE_PROXY
  1309. STRING_PROXY, /* proxy to use */
  1310. STRING_PRE_PROXY, /* pre socks proxy to use */
  1311. #endif
  1312. STRING_SET_RANGE, /* range, if used */
  1313. STRING_SET_REFERER, /* custom string for the HTTP referer field */
  1314. STRING_SET_URL, /* what original URL to work on */
  1315. STRING_USERAGENT, /* User-Agent string */
  1316. STRING_SSL_ENGINE, /* name of ssl engine */
  1317. STRING_USERNAME, /* <username>, if used */
  1318. STRING_PASSWORD, /* <password>, if used */
  1319. STRING_OPTIONS, /* <options>, if used */
  1320. #ifndef CURL_DISABLE_PROXY
  1321. STRING_PROXYUSERNAME, /* Proxy <username>, if used */
  1322. STRING_PROXYPASSWORD, /* Proxy <password>, if used */
  1323. STRING_NOPROXY, /* List of hosts which should not use the proxy, if
  1324. used */
  1325. #endif
  1326. #ifndef CURL_DISABLE_RTSP
  1327. STRING_RTSP_SESSION_ID, /* Session ID to use */
  1328. STRING_RTSP_STREAM_URI, /* Stream URI for this request */
  1329. STRING_RTSP_TRANSPORT, /* Transport for this session */
  1330. #endif
  1331. #ifdef USE_SSH
  1332. STRING_SSH_PRIVATE_KEY, /* path to the private key file for auth */
  1333. STRING_SSH_PUBLIC_KEY, /* path to the public key file for auth */
  1334. STRING_SSH_HOST_PUBLIC_KEY_MD5, /* md5 of host public key in ascii hex */
  1335. STRING_SSH_HOST_PUBLIC_KEY_SHA256, /* sha256 of host public key in base64 */
  1336. STRING_SSH_KNOWNHOSTS, /* file name of knownhosts file */
  1337. #endif
  1338. #ifndef CURL_DISABLE_SMTP
  1339. STRING_MAIL_FROM,
  1340. STRING_MAIL_AUTH,
  1341. #endif
  1342. #ifdef USE_TLS_SRP
  1343. STRING_TLSAUTH_USERNAME, /* TLS auth <username> */
  1344. STRING_TLSAUTH_PASSWORD, /* TLS auth <password> */
  1345. #ifndef CURL_DISABLE_PROXY
  1346. STRING_TLSAUTH_USERNAME_PROXY, /* TLS auth <username> */
  1347. STRING_TLSAUTH_PASSWORD_PROXY, /* TLS auth <password> */
  1348. #endif
  1349. #endif
  1350. STRING_BEARER, /* <bearer>, if used */
  1351. #ifdef USE_UNIX_SOCKETS
  1352. STRING_UNIX_SOCKET_PATH, /* path to Unix socket, if used */
  1353. #endif
  1354. STRING_TARGET, /* CURLOPT_REQUEST_TARGET */
  1355. #ifndef CURL_DISABLE_DOH
  1356. STRING_DOH, /* CURLOPT_DOH_URL */
  1357. #endif
  1358. #ifndef CURL_DISABLE_ALTSVC
  1359. STRING_ALTSVC, /* CURLOPT_ALTSVC */
  1360. #endif
  1361. #ifndef CURL_DISABLE_HSTS
  1362. STRING_HSTS, /* CURLOPT_HSTS */
  1363. #endif
  1364. STRING_SASL_AUTHZID, /* CURLOPT_SASL_AUTHZID */
  1365. #ifdef USE_ARES
  1366. STRING_DNS_SERVERS,
  1367. STRING_DNS_INTERFACE,
  1368. STRING_DNS_LOCAL_IP4,
  1369. STRING_DNS_LOCAL_IP6,
  1370. #endif
  1371. STRING_SSL_EC_CURVES,
  1372. #ifndef CURL_DISABLE_AWS
  1373. STRING_AWS_SIGV4, /* Parameters for V4 signature */
  1374. #endif
  1375. #ifndef CURL_DISABLE_PROXY
  1376. STRING_HAPROXY_CLIENT_IP, /* CURLOPT_HAPROXY_CLIENT_IP */
  1377. #endif
  1378. STRING_ECH_CONFIG, /* CURLOPT_ECH_CONFIG */
  1379. STRING_ECH_PUBLIC, /* CURLOPT_ECH_PUBLIC */
  1380. /* -- end of null-terminated strings -- */
  1381. STRING_LASTZEROTERMINATED,
  1382. /* -- below this are pointers to binary data that cannot be strdup'ed. --- */
  1383. STRING_COPYPOSTFIELDS, /* if POST, set the fields' values here */
  1384. STRING_LAST /* not used, just an end-of-list marker */
  1385. };
  1386. enum dupblob {
  1387. BLOB_CERT,
  1388. BLOB_KEY,
  1389. BLOB_SSL_ISSUERCERT,
  1390. BLOB_CAINFO,
  1391. #ifndef CURL_DISABLE_PROXY
  1392. BLOB_CERT_PROXY,
  1393. BLOB_KEY_PROXY,
  1394. BLOB_SSL_ISSUERCERT_PROXY,
  1395. BLOB_CAINFO_PROXY,
  1396. #endif
  1397. BLOB_LAST
  1398. };
  1399. /* callback that gets called when this easy handle is completed within a multi
  1400. handle. Only used for internally created transfers, like for example
  1401. DoH. */
  1402. typedef int (*multidone_func)(struct Curl_easy *easy, CURLcode result);
  1403. struct UserDefined {
  1404. FILE *err; /* the stderr user data goes here */
  1405. void *debugdata; /* the data that will be passed to fdebug */
  1406. char *errorbuffer; /* (Static) store failure messages in here */
  1407. void *out; /* CURLOPT_WRITEDATA */
  1408. void *in_set; /* CURLOPT_READDATA */
  1409. void *writeheader; /* write the header to this if non-NULL */
  1410. unsigned short use_port; /* which port to use (when not using default) */
  1411. unsigned long httpauth; /* kind of HTTP authentication to use (bitmask) */
  1412. unsigned long proxyauth; /* kind of proxy authentication to use (bitmask) */
  1413. long maxredirs; /* maximum no. of http(s) redirects to follow, set to -1
  1414. for infinity */
  1415. void *postfields; /* if POST, set the fields' values here */
  1416. curl_seek_callback seek_func; /* function that seeks the input */
  1417. curl_off_t postfieldsize; /* if POST, this might have a size to use instead
  1418. of strlen(), and then the data *may* be binary
  1419. (contain zero bytes) */
  1420. #ifndef CURL_DISABLE_BINDLOCAL
  1421. unsigned short localport; /* local port number to bind to */
  1422. unsigned short localportrange; /* number of additional port numbers to test
  1423. in case the 'localport' one can't be
  1424. bind()ed */
  1425. #endif
  1426. curl_write_callback fwrite_func; /* function that stores the output */
  1427. curl_write_callback fwrite_header; /* function that stores headers */
  1428. curl_write_callback fwrite_rtp; /* function that stores interleaved RTP */
  1429. curl_read_callback fread_func_set; /* function that reads the input */
  1430. curl_progress_callback fprogress; /* OLD and deprecated progress callback */
  1431. curl_xferinfo_callback fxferinfo; /* progress callback */
  1432. curl_debug_callback fdebug; /* function that write informational data */
  1433. curl_ioctl_callback ioctl_func; /* function for I/O control */
  1434. curl_sockopt_callback fsockopt; /* function for setting socket options */
  1435. void *sockopt_client; /* pointer to pass to the socket options callback */
  1436. curl_opensocket_callback fopensocket; /* function for checking/translating
  1437. the address and opening the
  1438. socket */
  1439. void *opensocket_client;
  1440. curl_closesocket_callback fclosesocket; /* function for closing the
  1441. socket */
  1442. void *closesocket_client;
  1443. curl_prereq_callback fprereq; /* pre-initial request callback */
  1444. void *prereq_userp; /* pre-initial request user data */
  1445. void *seek_client; /* pointer to pass to the seek callback */
  1446. #ifndef CURL_DISABLE_HSTS
  1447. curl_hstsread_callback hsts_read;
  1448. void *hsts_read_userp;
  1449. curl_hstswrite_callback hsts_write;
  1450. void *hsts_write_userp;
  1451. #endif
  1452. void *progress_client; /* pointer to pass to the progress callback */
  1453. void *ioctl_client; /* pointer to pass to the ioctl callback */
  1454. unsigned int timeout; /* ms, 0 means no timeout */
  1455. unsigned int connecttimeout; /* ms, 0 means default timeout */
  1456. unsigned int happy_eyeballs_timeout; /* ms, 0 is a valid value */
  1457. unsigned int server_response_timeout; /* ms, 0 means no timeout */
  1458. unsigned int shutdowntimeout; /* ms, 0 means default timeout */
  1459. long maxage_conn; /* in seconds, max idle time to allow a connection that
  1460. is to be reused */
  1461. long maxlifetime_conn; /* in seconds, max time since creation to allow a
  1462. connection that is to be reused */
  1463. #ifndef CURL_DISABLE_TFTP
  1464. long tftp_blksize; /* in bytes, 0 means use default */
  1465. #endif
  1466. curl_off_t filesize; /* size of file to upload, -1 means unknown */
  1467. long low_speed_limit; /* bytes/second */
  1468. long low_speed_time; /* number of seconds */
  1469. curl_off_t max_send_speed; /* high speed limit in bytes/second for upload */
  1470. curl_off_t max_recv_speed; /* high speed limit in bytes/second for
  1471. download */
  1472. curl_off_t set_resume_from; /* continue [ftp] transfer from here */
  1473. struct curl_slist *headers; /* linked list of extra headers */
  1474. struct curl_httppost *httppost; /* linked list of old POST data */
  1475. #if !defined(CURL_DISABLE_MIME) || !defined(CURL_DISABLE_FORM_API)
  1476. curl_mimepart mimepost; /* MIME/POST data. */
  1477. #endif
  1478. #ifndef CURL_DISABLE_TELNET
  1479. struct curl_slist *telnet_options; /* linked list of telnet options */
  1480. #endif
  1481. struct curl_slist *resolve; /* list of names to add/remove from
  1482. DNS cache */
  1483. struct curl_slist *connect_to; /* list of host:port mappings to override
  1484. the hostname and port to connect to */
  1485. time_t timevalue; /* what time to compare with */
  1486. unsigned char timecondition; /* kind of time comparison: curl_TimeCond */
  1487. unsigned char method; /* what kind of HTTP request: Curl_HttpReq */
  1488. unsigned char httpwant; /* when non-zero, a specific HTTP version requested
  1489. to be used in the library's request(s) */
  1490. struct ssl_config_data ssl; /* user defined SSL stuff */
  1491. #ifndef CURL_DISABLE_PROXY
  1492. struct ssl_config_data proxy_ssl; /* user defined SSL stuff for proxy */
  1493. struct curl_slist *proxyheaders; /* linked list of extra CONNECT headers */
  1494. unsigned short proxyport; /* If non-zero, use this port number by
  1495. default. If the proxy string features a
  1496. ":[port]" that one will override this. */
  1497. unsigned char proxytype; /* what kind of proxy: curl_proxytype */
  1498. unsigned char socks5auth;/* kind of SOCKS5 authentication to use (bitmask) */
  1499. #endif
  1500. struct ssl_general_config general_ssl; /* general user defined SSL stuff */
  1501. int dns_cache_timeout; /* DNS cache timeout (seconds) */
  1502. unsigned int buffer_size; /* size of receive buffer to use */
  1503. unsigned int upload_buffer_size; /* size of upload buffer to use,
  1504. keep it >= CURL_MAX_WRITE_SIZE */
  1505. void *private_data; /* application-private data */
  1506. #ifndef CURL_DISABLE_HTTP
  1507. struct curl_slist *http200aliases; /* linked list of aliases for http200 */
  1508. #endif
  1509. unsigned char ipver; /* the CURL_IPRESOLVE_* defines in the public header
  1510. file 0 - whatever, 1 - v2, 2 - v6 */
  1511. curl_off_t max_filesize; /* Maximum file size to download */
  1512. #ifndef CURL_DISABLE_FTP
  1513. unsigned char ftp_filemethod; /* how to get to a file: curl_ftpfile */
  1514. unsigned char ftpsslauth; /* what AUTH XXX to try: curl_ftpauth */
  1515. unsigned char ftp_ccc; /* FTP CCC options: curl_ftpccc */
  1516. unsigned int accepttimeout; /* in milliseconds, 0 means no timeout */
  1517. #endif
  1518. #if !defined(CURL_DISABLE_FTP) || defined(USE_SSH)
  1519. struct curl_slist *quote; /* after connection is established */
  1520. struct curl_slist *postquote; /* after the transfer */
  1521. struct curl_slist *prequote; /* before the transfer, after type */
  1522. /* Despite the name, ftp_create_missing_dirs is for FTP(S) and SFTP
  1523. 1 - create directories that don't exist
  1524. 2 - the same but also allow MKD to fail once
  1525. */
  1526. unsigned char ftp_create_missing_dirs;
  1527. #endif
  1528. #ifdef USE_LIBSSH2
  1529. curl_sshhostkeycallback ssh_hostkeyfunc; /* hostkey check callback */
  1530. void *ssh_hostkeyfunc_userp; /* custom pointer to callback */
  1531. #endif
  1532. #ifdef USE_SSH
  1533. curl_sshkeycallback ssh_keyfunc; /* key matching callback */
  1534. void *ssh_keyfunc_userp; /* custom pointer to callback */
  1535. int ssh_auth_types; /* allowed SSH auth types */
  1536. unsigned int new_directory_perms; /* when creating remote dirs */
  1537. #endif
  1538. #ifndef CURL_DISABLE_NETRC
  1539. unsigned char use_netrc; /* enum CURL_NETRC_OPTION values */
  1540. #endif
  1541. unsigned int new_file_perms; /* when creating remote files */
  1542. char *str[STRING_LAST]; /* array of strings, pointing to allocated memory */
  1543. struct curl_blob *blobs[BLOB_LAST];
  1544. #ifdef USE_IPV6
  1545. unsigned int scope_id; /* Scope id for IPv6 */
  1546. #endif
  1547. curl_prot_t allowed_protocols;
  1548. curl_prot_t redir_protocols;
  1549. #ifndef CURL_DISABLE_RTSP
  1550. void *rtp_out; /* write RTP to this if non-NULL */
  1551. /* Common RTSP header options */
  1552. Curl_RtspReq rtspreq; /* RTSP request type */
  1553. #endif
  1554. #ifndef CURL_DISABLE_FTP
  1555. curl_chunk_bgn_callback chunk_bgn; /* called before part of transfer
  1556. starts */
  1557. curl_chunk_end_callback chunk_end; /* called after part transferring
  1558. stopped */
  1559. curl_fnmatch_callback fnmatch; /* callback to decide which file corresponds
  1560. to pattern (e.g. if WILDCARDMATCH is on) */
  1561. void *fnmatch_data;
  1562. void *wildcardptr;
  1563. #endif
  1564. /* GSS-API credential delegation, see the documentation of
  1565. CURLOPT_GSSAPI_DELEGATION */
  1566. unsigned char gssapi_delegation;
  1567. int tcp_keepidle; /* seconds in idle before sending keepalive probe */
  1568. int tcp_keepintvl; /* seconds between TCP keepalive probes */
  1569. int tcp_keepcnt; /* maximum number of keepalive probes */
  1570. long expect_100_timeout; /* in milliseconds */
  1571. #if defined(USE_HTTP2) || defined(USE_HTTP3)
  1572. struct Curl_data_priority priority;
  1573. #endif
  1574. curl_resolver_start_callback resolver_start; /* optional callback called
  1575. before resolver start */
  1576. void *resolver_start_client; /* pointer to pass to resolver start callback */
  1577. long upkeep_interval_ms; /* Time between calls for connection upkeep. */
  1578. multidone_func fmultidone;
  1579. #ifndef CURL_DISABLE_DOH
  1580. struct Curl_easy *dohfor; /* this is a DoH request for that transfer */
  1581. #endif
  1582. CURLU *uh; /* URL handle for the current parsed URL */
  1583. #ifndef CURL_DISABLE_HTTP
  1584. void *trailer_data; /* pointer to pass to trailer data callback */
  1585. curl_trailer_callback trailer_callback; /* trailing data callback */
  1586. #endif
  1587. char keep_post; /* keep POSTs as POSTs after a 30x request; each
  1588. bit represents a request, from 301 to 303 */
  1589. #ifndef CURL_DISABLE_SMTP
  1590. struct curl_slist *mail_rcpt; /* linked list of mail recipients */
  1591. BIT(mail_rcpt_allowfails); /* allow RCPT TO command to fail for some
  1592. recipients */
  1593. #endif
  1594. unsigned int maxconnects; /* Max idle connections in the connection cache */
  1595. unsigned char use_ssl; /* if AUTH TLS is to be attempted etc, for FTP or
  1596. IMAP or POP3 or others! (type: curl_usessl)*/
  1597. unsigned char connect_only; /* make connection/request, then let
  1598. application use the socket */
  1599. #ifndef CURL_DISABLE_MIME
  1600. BIT(mime_formescape);
  1601. #endif
  1602. BIT(is_fread_set); /* has read callback been set to non-NULL? */
  1603. #ifndef CURL_DISABLE_TFTP
  1604. BIT(tftp_no_options); /* do not send TFTP options requests */
  1605. #endif
  1606. BIT(sep_headers); /* handle host and proxy headers separately */
  1607. #ifndef CURL_DISABLE_COOKIES
  1608. BIT(cookiesession); /* new cookie session? */
  1609. #endif
  1610. BIT(crlf); /* convert crlf on ftp upload(?) */
  1611. #ifdef USE_SSH
  1612. BIT(ssh_compression); /* enable SSH compression */
  1613. #endif
  1614. /* Here follows boolean settings that define how to behave during
  1615. this session. They are STATIC, set by libcurl users or at least initially
  1616. and they don't change during operations. */
  1617. BIT(quick_exit); /* set 1L when it is okay to leak things (like
  1618. threads), as we're about to exit() anyway and
  1619. don't want lengthy cleanups to delay termination,
  1620. e.g. after a DNS timeout */
  1621. BIT(get_filetime); /* get the time and get of the remote file */
  1622. #ifndef CURL_DISABLE_PROXY
  1623. BIT(tunnel_thru_httpproxy); /* use CONNECT through an HTTP proxy */
  1624. #endif
  1625. BIT(prefer_ascii); /* ASCII rather than binary */
  1626. BIT(remote_append); /* append, not overwrite, on upload */
  1627. #ifdef CURL_LIST_ONLY_PROTOCOL
  1628. BIT(list_only); /* list directory */
  1629. #endif
  1630. #ifndef CURL_DISABLE_FTP
  1631. BIT(ftp_use_port); /* use the FTP PORT command */
  1632. BIT(ftp_use_epsv); /* if EPSV is to be attempted or not */
  1633. BIT(ftp_use_eprt); /* if EPRT is to be attempted or not */
  1634. BIT(ftp_use_pret); /* if PRET is to be used before PASV or not */
  1635. BIT(ftp_skip_ip); /* skip the IP address the FTP server passes on to
  1636. us */
  1637. BIT(wildcard_enabled); /* enable wildcard matching */
  1638. #endif
  1639. BIT(hide_progress); /* don't use the progress meter */
  1640. BIT(http_fail_on_error); /* fail on HTTP error codes >= 400 */
  1641. BIT(http_keep_sending_on_error); /* for HTTP status codes >= 300 */
  1642. BIT(http_follow_location); /* follow HTTP redirects */
  1643. BIT(http_transfer_encoding); /* request compressed HTTP transfer-encoding */
  1644. BIT(allow_auth_to_other_hosts);
  1645. BIT(include_header); /* include received protocol headers in data output */
  1646. BIT(http_set_referer); /* is a custom referer used */
  1647. BIT(http_auto_referer); /* set "correct" referer when following
  1648. location: */
  1649. BIT(opt_no_body); /* as set with CURLOPT_NOBODY */
  1650. BIT(verbose); /* output verbosity */
  1651. #if defined(HAVE_GSSAPI)
  1652. BIT(krb); /* Kerberos connection requested */
  1653. #endif
  1654. BIT(reuse_forbid); /* forbidden to be reused, close after use */
  1655. BIT(reuse_fresh); /* do not reuse an existing connection */
  1656. BIT(no_signal); /* do not use any signal/alarm handler */
  1657. BIT(tcp_nodelay); /* whether to enable TCP_NODELAY or not */
  1658. BIT(ignorecl); /* ignore content length */
  1659. BIT(http_te_skip); /* pass the raw body data to the user, even when
  1660. transfer-encoded (chunked, compressed) */
  1661. BIT(http_ce_skip); /* pass the raw body data to the user, even when
  1662. content-encoded (chunked, compressed) */
  1663. BIT(proxy_transfer_mode); /* set transfer mode (;type=<a|i>) when doing
  1664. FTP via an HTTP proxy */
  1665. #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
  1666. BIT(socks5_gssapi_nec); /* Flag to support NEC SOCKS5 server */
  1667. #endif
  1668. BIT(sasl_ir); /* Enable/disable SASL initial response */
  1669. BIT(tcp_keepalive); /* use TCP keepalives */
  1670. BIT(tcp_fastopen); /* use TCP Fast Open */
  1671. BIT(ssl_enable_alpn);/* TLS ALPN extension? */
  1672. BIT(path_as_is); /* allow dotdots? */
  1673. BIT(pipewait); /* wait for multiplex status before starting a new
  1674. connection */
  1675. BIT(suppress_connect_headers); /* suppress proxy CONNECT response headers
  1676. from user callbacks */
  1677. BIT(dns_shuffle_addresses); /* whether to shuffle addresses before use */
  1678. #ifndef CURL_DISABLE_PROXY
  1679. BIT(haproxyprotocol); /* whether to send HAProxy PROXY protocol v1
  1680. header */
  1681. #endif
  1682. #ifdef USE_UNIX_SOCKETS
  1683. BIT(abstract_unix_socket);
  1684. #endif
  1685. BIT(disallow_username_in_url); /* disallow username in url */
  1686. #ifndef CURL_DISABLE_DOH
  1687. BIT(doh); /* DNS-over-HTTPS enabled */
  1688. BIT(doh_verifypeer); /* DoH certificate peer verification */
  1689. BIT(doh_verifyhost); /* DoH certificate hostname verification */
  1690. BIT(doh_verifystatus); /* DoH certificate status verification */
  1691. #endif
  1692. BIT(http09_allowed); /* allow HTTP/0.9 responses */
  1693. #ifdef USE_WEBSOCKETS
  1694. BIT(ws_raw_mode);
  1695. #endif
  1696. #ifdef USE_ECH
  1697. int tls_ech; /* TLS ECH configuration */
  1698. #endif
  1699. };
  1700. #ifndef CURL_DISABLE_MIME
  1701. #define IS_MIME_POST(a) ((a)->set.mimepost.kind != MIMEKIND_NONE)
  1702. #else
  1703. #define IS_MIME_POST(a) FALSE
  1704. #endif
  1705. struct Names {
  1706. struct Curl_hash *hostcache;
  1707. enum {
  1708. HCACHE_NONE, /* not pointing to anything */
  1709. HCACHE_MULTI, /* points to a shared one in the multi handle */
  1710. HCACHE_SHARED /* points to a shared one in a shared object */
  1711. } hostcachetype;
  1712. };
  1713. /*
  1714. * The 'connectdata' struct MUST have all the connection oriented stuff as we
  1715. * may have several simultaneous connections and connection structs in memory.
  1716. *
  1717. * The 'struct UserDefined' must only contain data that is set once to go for
  1718. * many (perhaps) independent connections. Values that are generated or
  1719. * calculated internally for the "session handle" must be defined within the
  1720. * 'struct UrlState' instead.
  1721. */
  1722. struct Curl_easy {
  1723. /* First a simple identifier to easier detect if a user mix up this easy
  1724. handle with a multi handle. Set this to CURLEASY_MAGIC_NUMBER */
  1725. unsigned int magic;
  1726. /* once an easy handle is tied to a connection cache
  1727. a non-negative number to distinguish this transfer from
  1728. other using the same cache. For easier tracking
  1729. in log output.
  1730. This may wrap around after LONG_MAX to 0 again, so it
  1731. has no uniqueness guarantee for very large processings. */
  1732. curl_off_t id;
  1733. /* first, two fields for the linked list of these */
  1734. struct Curl_easy *next;
  1735. struct Curl_easy *prev;
  1736. struct connectdata *conn;
  1737. struct Curl_llist_element connect_queue; /* for the pending and msgsent
  1738. lists */
  1739. struct Curl_llist_element conn_queue; /* list per connectdata */
  1740. CURLMstate mstate; /* the handle's state */
  1741. CURLcode result; /* previous result */
  1742. struct Curl_message msg; /* A single posted message. */
  1743. /* Array with the plain socket numbers this handle takes care of, in no
  1744. particular order. Note that all sockets are added to the sockhash, where
  1745. the state etc are also kept. This array is mostly used to detect when a
  1746. socket is to be removed from the hash. See singlesocket(). */
  1747. struct easy_pollset last_poll;
  1748. struct Names dns;
  1749. struct Curl_multi *multi; /* if non-NULL, points to the multi handle
  1750. struct to which this "belongs" when used by
  1751. the multi interface */
  1752. struct Curl_multi *multi_easy; /* if non-NULL, points to the multi handle
  1753. struct to which this "belongs" when used
  1754. by the easy interface */
  1755. struct Curl_share *share; /* Share, handles global variable mutexing */
  1756. #ifdef USE_LIBPSL
  1757. struct PslCache *psl; /* The associated PSL cache. */
  1758. #endif
  1759. struct SingleRequest req; /* Request-specific data */
  1760. struct UserDefined set; /* values set by the libcurl user */
  1761. #ifndef CURL_DISABLE_COOKIES
  1762. struct CookieInfo *cookies; /* the cookies, read from files and servers.
  1763. NOTE that the 'cookie' field in the
  1764. UserDefined struct defines if the "engine"
  1765. is to be used or not. */
  1766. #endif
  1767. #ifndef CURL_DISABLE_HSTS
  1768. struct hsts *hsts;
  1769. #endif
  1770. #ifndef CURL_DISABLE_ALTSVC
  1771. struct altsvcinfo *asi; /* the alt-svc cache */
  1772. #endif
  1773. struct Progress progress; /* for all the progress meter data */
  1774. struct UrlState state; /* struct for fields used for state info and
  1775. other dynamic purposes */
  1776. #ifndef CURL_DISABLE_FTP
  1777. struct WildcardData *wildcard; /* wildcard download state info */
  1778. #endif
  1779. struct PureInfo info; /* stats, reports and info data */
  1780. struct curl_tlssessioninfo tsi; /* Information about the TLS session, only
  1781. valid after a client has asked for it */
  1782. #ifdef USE_HYPER
  1783. struct hyptransfer hyp;
  1784. #endif
  1785. };
  1786. #define LIBCURL_NAME "libcurl"
  1787. #endif /* HEADER_CURL_URLDATA_H */