urldata.h 77 KB

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