urldata.h 74 KB

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