urldata.h 75 KB

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