urldata.h 78 KB

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