urldata.h 75 KB

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