urldata.h 79 KB

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