urldata.h 78 KB

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