urldata.h 79 KB

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