urldata.h 79 KB

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