urldata.h 77 KB

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