urldata.h 78 KB

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