setopt.c 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. * SPDX-License-Identifier: curl
  22. *
  23. ***************************************************************************/
  24. #include "curl_setup.h"
  25. #include <limits.h>
  26. #ifdef HAVE_NETINET_IN_H
  27. #include <netinet/in.h>
  28. #endif
  29. #ifdef HAVE_LINUX_TCP_H
  30. #include <linux/tcp.h>
  31. #elif defined(HAVE_NETINET_TCP_H)
  32. #include <netinet/tcp.h>
  33. #endif
  34. #include "urldata.h"
  35. #include "url.h"
  36. #include "progress.h"
  37. #include "content_encoding.h"
  38. #include "strcase.h"
  39. #include "share.h"
  40. #include "vtls/vtls.h"
  41. #include "warnless.h"
  42. #include "sendf.h"
  43. #include "http2.h"
  44. #include "setopt.h"
  45. #include "multiif.h"
  46. #include "altsvc.h"
  47. #include "hsts.h"
  48. #include "tftp.h"
  49. #include "strdup.h"
  50. #include "escape.h"
  51. /* The last 3 #include files should be in this order */
  52. #include "curl_printf.h"
  53. #include "curl_memory.h"
  54. #include "memdebug.h"
  55. CURLcode Curl_setstropt(char **charp, const char *s)
  56. {
  57. /* Release the previous storage at `charp' and replace by a dynamic storage
  58. copy of `s'. Return CURLE_OK or CURLE_OUT_OF_MEMORY. */
  59. Curl_safefree(*charp);
  60. if(s) {
  61. if(strlen(s) > CURL_MAX_INPUT_LENGTH)
  62. return CURLE_BAD_FUNCTION_ARGUMENT;
  63. *charp = strdup(s);
  64. if(!*charp)
  65. return CURLE_OUT_OF_MEMORY;
  66. }
  67. return CURLE_OK;
  68. }
  69. CURLcode Curl_setblobopt(struct curl_blob **blobp,
  70. const struct curl_blob *blob)
  71. {
  72. /* free the previous storage at `blobp' and replace by a dynamic storage
  73. copy of blob. If CURL_BLOB_COPY is set, the data is copied. */
  74. Curl_safefree(*blobp);
  75. if(blob) {
  76. struct curl_blob *nblob;
  77. if(blob->len > CURL_MAX_INPUT_LENGTH)
  78. return CURLE_BAD_FUNCTION_ARGUMENT;
  79. nblob = (struct curl_blob *)
  80. malloc(sizeof(struct curl_blob) +
  81. ((blob->flags & CURL_BLOB_COPY) ? blob->len : 0));
  82. if(!nblob)
  83. return CURLE_OUT_OF_MEMORY;
  84. *nblob = *blob;
  85. if(blob->flags & CURL_BLOB_COPY) {
  86. /* put the data after the blob struct in memory */
  87. nblob->data = (char *)nblob + sizeof(struct curl_blob);
  88. memcpy(nblob->data, blob->data, blob->len);
  89. }
  90. *blobp = nblob;
  91. return CURLE_OK;
  92. }
  93. return CURLE_OK;
  94. }
  95. static CURLcode setstropt_userpwd(char *option, char **userp, char **passwdp)
  96. {
  97. char *user = NULL;
  98. char *passwd = NULL;
  99. DEBUGASSERT(userp);
  100. DEBUGASSERT(passwdp);
  101. /* Parse the login details if specified. It not then we treat NULL as a hint
  102. to clear the existing data */
  103. if(option) {
  104. size_t len = strlen(option);
  105. CURLcode result;
  106. if(len > CURL_MAX_INPUT_LENGTH)
  107. return CURLE_BAD_FUNCTION_ARGUMENT;
  108. result = Curl_parse_login_details(option, len, &user, &passwd, NULL);
  109. if(result)
  110. return result;
  111. }
  112. free(*userp);
  113. *userp = user;
  114. free(*passwdp);
  115. *passwdp = passwd;
  116. return CURLE_OK;
  117. }
  118. static CURLcode setstropt_interface(char *option, char **devp,
  119. char **ifacep, char **hostp)
  120. {
  121. char *dev = NULL;
  122. char *iface = NULL;
  123. char *host = NULL;
  124. CURLcode result;
  125. DEBUGASSERT(devp);
  126. DEBUGASSERT(ifacep);
  127. DEBUGASSERT(hostp);
  128. if(option) {
  129. /* Parse the interface details if set, otherwise clear them all */
  130. result = Curl_parse_interface(option, &dev, &iface, &host);
  131. if(result)
  132. return result;
  133. }
  134. free(*devp);
  135. *devp = dev;
  136. free(*ifacep);
  137. *ifacep = iface;
  138. free(*hostp);
  139. *hostp = host;
  140. return CURLE_OK;
  141. }
  142. #define C_SSLVERSION_VALUE(x) (x & 0xffff)
  143. #define C_SSLVERSION_MAX_VALUE(x) ((unsigned long)x & 0xffff0000)
  144. static CURLcode protocol2num(const char *str, curl_prot_t *val)
  145. {
  146. /*
  147. * We are asked to cherry-pick protocols, so play it safe and disallow all
  148. * protocols to start with, and re-add the wanted ones back in.
  149. */
  150. *val = 0;
  151. if(!str)
  152. return CURLE_BAD_FUNCTION_ARGUMENT;
  153. if(curl_strequal(str, "all")) {
  154. *val = ~(curl_prot_t) 0;
  155. return CURLE_OK;
  156. }
  157. do {
  158. const char *token = str;
  159. size_t tlen;
  160. str = strchr(str, ',');
  161. tlen = str ? (size_t) (str - token) : strlen(token);
  162. if(tlen) {
  163. const struct Curl_handler *h = Curl_getn_scheme_handler(token, tlen);
  164. if(!h)
  165. return CURLE_UNSUPPORTED_PROTOCOL;
  166. *val |= h->protocol;
  167. }
  168. } while(str && str++);
  169. if(!*val)
  170. /* no protocol listed */
  171. return CURLE_BAD_FUNCTION_ARGUMENT;
  172. return CURLE_OK;
  173. }
  174. static CURLcode httpauth(struct Curl_easy *data, bool proxy, va_list param)
  175. {
  176. unsigned long auth = va_arg(param, unsigned long);
  177. if(auth != CURLAUTH_NONE) {
  178. int bitcheck = 0;
  179. bool authbits = FALSE;
  180. /* the DIGEST_IE bit is only used to set a special marker, for all the
  181. rest we need to handle it as normal DIGEST */
  182. bool iestyle = !!(auth & CURLAUTH_DIGEST_IE);
  183. if(proxy)
  184. data->state.authproxy.iestyle = iestyle;
  185. else
  186. data->state.authhost.iestyle = iestyle;
  187. if(auth & CURLAUTH_DIGEST_IE) {
  188. auth |= CURLAUTH_DIGEST; /* set standard digest bit */
  189. auth &= ~CURLAUTH_DIGEST_IE; /* unset ie digest bit */
  190. }
  191. /* switch off bits we cannot support */
  192. #ifndef USE_NTLM
  193. auth &= ~CURLAUTH_NTLM; /* no NTLM support */
  194. #endif
  195. #ifndef USE_SPNEGO
  196. auth &= ~CURLAUTH_NEGOTIATE; /* no Negotiate (SPNEGO) auth without GSS-API
  197. or SSPI */
  198. #endif
  199. /* check if any auth bit lower than CURLAUTH_ONLY is still set */
  200. while(bitcheck < 31) {
  201. if(auth & (1UL << bitcheck++)) {
  202. authbits = TRUE;
  203. break;
  204. }
  205. }
  206. if(!authbits)
  207. return CURLE_NOT_BUILT_IN; /* no supported types left! */
  208. }
  209. if(proxy)
  210. data->set.proxyauth = auth;
  211. else
  212. data->set.httpauth = auth;
  213. return CURLE_OK;
  214. }
  215. /*
  216. * Do not make Curl_vsetopt() static: it is called from
  217. * packages/OS400/ccsidcurl.c.
  218. */
  219. CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
  220. {
  221. char *argptr;
  222. CURLcode result = CURLE_OK;
  223. long arg;
  224. unsigned long uarg;
  225. curl_off_t bigsize;
  226. switch(option) {
  227. case CURLOPT_DNS_CACHE_TIMEOUT:
  228. arg = va_arg(param, long);
  229. if(arg < -1)
  230. return CURLE_BAD_FUNCTION_ARGUMENT;
  231. else if(arg > INT_MAX)
  232. arg = INT_MAX;
  233. data->set.dns_cache_timeout = (int)arg;
  234. break;
  235. case CURLOPT_CA_CACHE_TIMEOUT:
  236. if(Curl_ssl_supports(data, SSLSUPP_CA_CACHE)) {
  237. arg = va_arg(param, long);
  238. if(arg < -1)
  239. return CURLE_BAD_FUNCTION_ARGUMENT;
  240. else if(arg > INT_MAX)
  241. arg = INT_MAX;
  242. data->set.general_ssl.ca_cache_timeout = (int)arg;
  243. }
  244. else
  245. return CURLE_NOT_BUILT_IN;
  246. break;
  247. case CURLOPT_DNS_USE_GLOBAL_CACHE:
  248. /* deprecated */
  249. break;
  250. case CURLOPT_SSL_CIPHER_LIST:
  251. if(Curl_ssl_supports(data, SSLSUPP_CIPHER_LIST)) {
  252. /* set a list of cipher we want to use in the SSL connection */
  253. result = Curl_setstropt(&data->set.str[STRING_SSL_CIPHER_LIST],
  254. va_arg(param, char *));
  255. }
  256. else
  257. return CURLE_NOT_BUILT_IN;
  258. break;
  259. #ifndef CURL_DISABLE_PROXY
  260. case CURLOPT_PROXY_SSL_CIPHER_LIST:
  261. if(Curl_ssl_supports(data, SSLSUPP_CIPHER_LIST)) {
  262. /* set a list of cipher we want to use in the SSL connection for proxy */
  263. result = Curl_setstropt(&data->set.str[STRING_SSL_CIPHER_LIST_PROXY],
  264. va_arg(param, char *));
  265. }
  266. else
  267. return CURLE_NOT_BUILT_IN;
  268. break;
  269. #endif
  270. case CURLOPT_TLS13_CIPHERS:
  271. if(Curl_ssl_supports(data, SSLSUPP_TLS13_CIPHERSUITES)) {
  272. /* set preferred list of TLS 1.3 cipher suites */
  273. result = Curl_setstropt(&data->set.str[STRING_SSL_CIPHER13_LIST],
  274. va_arg(param, char *));
  275. }
  276. else
  277. return CURLE_NOT_BUILT_IN;
  278. break;
  279. #ifndef CURL_DISABLE_PROXY
  280. case CURLOPT_PROXY_TLS13_CIPHERS:
  281. if(Curl_ssl_supports(data, SSLSUPP_TLS13_CIPHERSUITES)) {
  282. /* set preferred list of TLS 1.3 cipher suites for proxy */
  283. result = Curl_setstropt(&data->set.str[STRING_SSL_CIPHER13_LIST_PROXY],
  284. va_arg(param, char *));
  285. }
  286. else
  287. return CURLE_NOT_BUILT_IN;
  288. break;
  289. #endif
  290. case CURLOPT_RANDOM_FILE:
  291. break;
  292. case CURLOPT_EGDSOCKET:
  293. break;
  294. case CURLOPT_MAXCONNECTS:
  295. /*
  296. * Set the absolute number of maximum simultaneous alive connection that
  297. * libcurl is allowed to have.
  298. */
  299. uarg = va_arg(param, unsigned long);
  300. if(uarg > UINT_MAX)
  301. return CURLE_BAD_FUNCTION_ARGUMENT;
  302. data->set.maxconnects = (unsigned int)uarg;
  303. break;
  304. case CURLOPT_FORBID_REUSE:
  305. /*
  306. * When this transfer is done, it must not be left to be reused by a
  307. * subsequent transfer but shall be closed immediately.
  308. */
  309. data->set.reuse_forbid = (0 != va_arg(param, long));
  310. break;
  311. case CURLOPT_FRESH_CONNECT:
  312. /*
  313. * This transfer shall not use a previously cached connection but
  314. * should be made with a fresh new connect!
  315. */
  316. data->set.reuse_fresh = (0 != va_arg(param, long));
  317. break;
  318. case CURLOPT_VERBOSE:
  319. /*
  320. * Verbose means infof() calls that give a lot of information about
  321. * the connection and transfer procedures as well as internal choices.
  322. */
  323. data->set.verbose = (0 != va_arg(param, long));
  324. break;
  325. case CURLOPT_HEADER:
  326. /*
  327. * Set to include the header in the general data output stream.
  328. */
  329. data->set.include_header = (0 != va_arg(param, long));
  330. break;
  331. case CURLOPT_NOPROGRESS:
  332. /*
  333. * Shut off the internal supported progress meter
  334. */
  335. data->set.hide_progress = (0 != va_arg(param, long));
  336. if(data->set.hide_progress)
  337. data->progress.flags |= PGRS_HIDE;
  338. else
  339. data->progress.flags &= ~PGRS_HIDE;
  340. break;
  341. case CURLOPT_NOBODY:
  342. /*
  343. * Do not include the body part in the output data stream.
  344. */
  345. data->set.opt_no_body = (0 != va_arg(param, long));
  346. #ifndef CURL_DISABLE_HTTP
  347. if(data->set.opt_no_body)
  348. /* in HTTP lingo, no body means using the HEAD request... */
  349. data->set.method = HTTPREQ_HEAD;
  350. else if(data->set.method == HTTPREQ_HEAD)
  351. data->set.method = HTTPREQ_GET;
  352. #endif
  353. break;
  354. case CURLOPT_FAILONERROR:
  355. /*
  356. * Do not output the >=400 error code HTML-page, but instead only
  357. * return error.
  358. */
  359. data->set.http_fail_on_error = (0 != va_arg(param, long));
  360. break;
  361. case CURLOPT_KEEP_SENDING_ON_ERROR:
  362. data->set.http_keep_sending_on_error = (0 != va_arg(param, long));
  363. break;
  364. case CURLOPT_UPLOAD:
  365. case CURLOPT_PUT:
  366. /*
  367. * We want to sent data to the remote host. If this is HTTP, that equals
  368. * using the PUT request.
  369. */
  370. arg = va_arg(param, long);
  371. if(arg) {
  372. /* If this is HTTP, PUT is what's needed to "upload" */
  373. data->set.method = HTTPREQ_PUT;
  374. data->set.opt_no_body = FALSE; /* this is implied */
  375. }
  376. else
  377. /* In HTTP, the opposite of upload is GET (unless NOBODY is true as
  378. then this can be changed to HEAD later on) */
  379. data->set.method = HTTPREQ_GET;
  380. break;
  381. case CURLOPT_REQUEST_TARGET:
  382. result = Curl_setstropt(&data->set.str[STRING_TARGET],
  383. va_arg(param, char *));
  384. break;
  385. case CURLOPT_FILETIME:
  386. /*
  387. * Try to get the file time of the remote document. The time will
  388. * later (possibly) become available using curl_easy_getinfo().
  389. */
  390. data->set.get_filetime = (0 != va_arg(param, long));
  391. break;
  392. case CURLOPT_SERVER_RESPONSE_TIMEOUT:
  393. /*
  394. * Option that specifies how quickly a server response must be obtained
  395. * before it is considered failure. For pingpong protocols.
  396. */
  397. arg = va_arg(param, long);
  398. if((arg >= 0) && (arg <= (INT_MAX/1000)))
  399. data->set.server_response_timeout = (unsigned int)arg * 1000;
  400. else
  401. return CURLE_BAD_FUNCTION_ARGUMENT;
  402. break;
  403. case CURLOPT_SERVER_RESPONSE_TIMEOUT_MS:
  404. /*
  405. * Option that specifies how quickly a server response must be obtained
  406. * before it is considered failure. For pingpong protocols.
  407. */
  408. arg = va_arg(param, long);
  409. if((arg >= 0) && (arg <= INT_MAX))
  410. data->set.server_response_timeout = (unsigned int)arg;
  411. else
  412. return CURLE_BAD_FUNCTION_ARGUMENT;
  413. break;
  414. #ifndef CURL_DISABLE_TFTP
  415. case CURLOPT_TFTP_NO_OPTIONS:
  416. /*
  417. * Option that prevents libcurl from sending TFTP option requests to the
  418. * server.
  419. */
  420. data->set.tftp_no_options = va_arg(param, long) != 0;
  421. break;
  422. case CURLOPT_TFTP_BLKSIZE:
  423. /*
  424. * TFTP option that specifies the block size to use for data transmission.
  425. */
  426. arg = va_arg(param, long);
  427. if(arg < TFTP_BLKSIZE_MIN)
  428. arg = 512;
  429. else if(arg > TFTP_BLKSIZE_MAX)
  430. arg = TFTP_BLKSIZE_MAX;
  431. data->set.tftp_blksize = arg;
  432. break;
  433. #endif
  434. #ifndef CURL_DISABLE_NETRC
  435. case CURLOPT_NETRC:
  436. /*
  437. * Parse the $HOME/.netrc file
  438. */
  439. arg = va_arg(param, long);
  440. if((arg < CURL_NETRC_IGNORED) || (arg >= CURL_NETRC_LAST))
  441. return CURLE_BAD_FUNCTION_ARGUMENT;
  442. data->set.use_netrc = (unsigned char)arg;
  443. break;
  444. case CURLOPT_NETRC_FILE:
  445. /*
  446. * Use this file instead of the $HOME/.netrc file
  447. */
  448. result = Curl_setstropt(&data->set.str[STRING_NETRC_FILE],
  449. va_arg(param, char *));
  450. break;
  451. #endif
  452. case CURLOPT_TRANSFERTEXT:
  453. /*
  454. * This option was previously named 'FTPASCII'. Renamed to work with
  455. * more protocols than merely FTP.
  456. *
  457. * Transfer using ASCII (instead of BINARY).
  458. */
  459. data->set.prefer_ascii = (0 != va_arg(param, long));
  460. break;
  461. case CURLOPT_TIMECONDITION:
  462. /*
  463. * Set HTTP time condition. This must be one of the defines in the
  464. * curl/curl.h header file.
  465. */
  466. arg = va_arg(param, long);
  467. if((arg < CURL_TIMECOND_NONE) || (arg >= CURL_TIMECOND_LAST))
  468. return CURLE_BAD_FUNCTION_ARGUMENT;
  469. data->set.timecondition = (unsigned char)(curl_TimeCond)arg;
  470. break;
  471. case CURLOPT_TIMEVALUE:
  472. /*
  473. * This is the value to compare with the remote document with the
  474. * method set with CURLOPT_TIMECONDITION
  475. */
  476. data->set.timevalue = (time_t)va_arg(param, long);
  477. break;
  478. case CURLOPT_TIMEVALUE_LARGE:
  479. /*
  480. * This is the value to compare with the remote document with the
  481. * method set with CURLOPT_TIMECONDITION
  482. */
  483. data->set.timevalue = (time_t)va_arg(param, curl_off_t);
  484. break;
  485. case CURLOPT_SSLVERSION:
  486. #ifndef CURL_DISABLE_PROXY
  487. case CURLOPT_PROXY_SSLVERSION:
  488. #endif
  489. /*
  490. * Set explicit SSL version to try to connect with, as some SSL
  491. * implementations are lame.
  492. */
  493. #ifdef USE_SSL
  494. {
  495. long version, version_max;
  496. struct ssl_primary_config *primary = &data->set.ssl.primary;
  497. #ifndef CURL_DISABLE_PROXY
  498. if(option != CURLOPT_SSLVERSION)
  499. primary = &data->set.proxy_ssl.primary;
  500. #endif
  501. arg = va_arg(param, long);
  502. version = C_SSLVERSION_VALUE(arg);
  503. version_max = (long)C_SSLVERSION_MAX_VALUE(arg);
  504. if(version < CURL_SSLVERSION_DEFAULT ||
  505. version == CURL_SSLVERSION_SSLv2 ||
  506. version == CURL_SSLVERSION_SSLv3 ||
  507. version >= CURL_SSLVERSION_LAST ||
  508. version_max < CURL_SSLVERSION_MAX_NONE ||
  509. version_max >= CURL_SSLVERSION_MAX_LAST)
  510. return CURLE_BAD_FUNCTION_ARGUMENT;
  511. primary->version = (unsigned char)version;
  512. primary->version_max = (unsigned int)version_max;
  513. }
  514. #else
  515. result = CURLE_NOT_BUILT_IN;
  516. #endif
  517. break;
  518. /* MQTT "borrows" some of the HTTP options */
  519. #if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_MQTT)
  520. case CURLOPT_COPYPOSTFIELDS:
  521. /*
  522. * A string with POST data. Makes curl HTTP POST. Even if it is NULL.
  523. * If needed, CURLOPT_POSTFIELDSIZE must have been set prior to
  524. * CURLOPT_COPYPOSTFIELDS and not altered later.
  525. */
  526. argptr = va_arg(param, char *);
  527. if(!argptr || data->set.postfieldsize == -1)
  528. result = Curl_setstropt(&data->set.str[STRING_COPYPOSTFIELDS], argptr);
  529. else {
  530. /*
  531. * Check that requested length does not overflow the size_t type.
  532. */
  533. if((data->set.postfieldsize < 0) ||
  534. ((sizeof(curl_off_t) != sizeof(size_t)) &&
  535. (data->set.postfieldsize > (curl_off_t)((size_t)-1))))
  536. result = CURLE_OUT_OF_MEMORY;
  537. else {
  538. /* Allocate even when size == 0. This satisfies the need of possible
  539. later address compare to detect the COPYPOSTFIELDS mode, and to
  540. mark that postfields is used rather than read function or form
  541. data.
  542. */
  543. char *p = Curl_memdup0(argptr, (size_t)data->set.postfieldsize);
  544. if(!p)
  545. result = CURLE_OUT_OF_MEMORY;
  546. else {
  547. free(data->set.str[STRING_COPYPOSTFIELDS]);
  548. data->set.str[STRING_COPYPOSTFIELDS] = p;
  549. }
  550. }
  551. }
  552. data->set.postfields = data->set.str[STRING_COPYPOSTFIELDS];
  553. data->set.method = HTTPREQ_POST;
  554. break;
  555. case CURLOPT_POSTFIELDS:
  556. /*
  557. * Like above, but use static data instead of copying it.
  558. */
  559. data->set.postfields = va_arg(param, void *);
  560. /* Release old copied data. */
  561. Curl_safefree(data->set.str[STRING_COPYPOSTFIELDS]);
  562. data->set.method = HTTPREQ_POST;
  563. break;
  564. case CURLOPT_POSTFIELDSIZE:
  565. /*
  566. * The size of the POSTFIELD data to prevent libcurl to do strlen() to
  567. * figure it out. Enables binary posts.
  568. */
  569. bigsize = va_arg(param, long);
  570. if(bigsize < -1)
  571. return CURLE_BAD_FUNCTION_ARGUMENT;
  572. if(data->set.postfieldsize < bigsize &&
  573. data->set.postfields == data->set.str[STRING_COPYPOSTFIELDS]) {
  574. /* Previous CURLOPT_COPYPOSTFIELDS is no longer valid. */
  575. Curl_safefree(data->set.str[STRING_COPYPOSTFIELDS]);
  576. data->set.postfields = NULL;
  577. }
  578. data->set.postfieldsize = bigsize;
  579. break;
  580. case CURLOPT_POSTFIELDSIZE_LARGE:
  581. /*
  582. * The size of the POSTFIELD data to prevent libcurl to do strlen() to
  583. * figure it out. Enables binary posts.
  584. */
  585. bigsize = va_arg(param, curl_off_t);
  586. if(bigsize < -1)
  587. return CURLE_BAD_FUNCTION_ARGUMENT;
  588. if(data->set.postfieldsize < bigsize &&
  589. data->set.postfields == data->set.str[STRING_COPYPOSTFIELDS]) {
  590. /* Previous CURLOPT_COPYPOSTFIELDS is no longer valid. */
  591. Curl_safefree(data->set.str[STRING_COPYPOSTFIELDS]);
  592. data->set.postfields = NULL;
  593. }
  594. data->set.postfieldsize = bigsize;
  595. break;
  596. #endif
  597. #ifndef CURL_DISABLE_HTTP
  598. case CURLOPT_AUTOREFERER:
  599. /*
  600. * Switch on automatic referer that gets set if curl follows locations.
  601. */
  602. data->set.http_auto_referer = (0 != va_arg(param, long));
  603. break;
  604. case CURLOPT_ACCEPT_ENCODING:
  605. /*
  606. * String to use at the value of Accept-Encoding header.
  607. *
  608. * If the encoding is set to "" we use an Accept-Encoding header that
  609. * encompasses all the encodings we support.
  610. * If the encoding is set to NULL we do not send an Accept-Encoding header
  611. * and ignore an received Content-Encoding header.
  612. *
  613. */
  614. argptr = va_arg(param, char *);
  615. if(argptr && !*argptr) {
  616. char all[256];
  617. Curl_all_content_encodings(all, sizeof(all));
  618. result = Curl_setstropt(&data->set.str[STRING_ENCODING], all);
  619. }
  620. else
  621. result = Curl_setstropt(&data->set.str[STRING_ENCODING], argptr);
  622. break;
  623. case CURLOPT_TRANSFER_ENCODING:
  624. data->set.http_transfer_encoding = (0 != va_arg(param, long));
  625. break;
  626. case CURLOPT_FOLLOWLOCATION:
  627. /*
  628. * Follow Location: header hints on an HTTP-server.
  629. */
  630. data->set.http_follow_location = (0 != va_arg(param, long));
  631. break;
  632. case CURLOPT_UNRESTRICTED_AUTH:
  633. /*
  634. * Send authentication (user+password) when following locations, even when
  635. * hostname changed.
  636. */
  637. data->set.allow_auth_to_other_hosts = (0 != va_arg(param, long));
  638. break;
  639. case CURLOPT_MAXREDIRS:
  640. /*
  641. * The maximum amount of hops you allow curl to follow Location:
  642. * headers. This should mostly be used to detect never-ending loops.
  643. */
  644. arg = va_arg(param, long);
  645. if(arg < -1)
  646. return CURLE_BAD_FUNCTION_ARGUMENT;
  647. data->set.maxredirs = arg;
  648. break;
  649. case CURLOPT_POSTREDIR:
  650. /*
  651. * Set the behavior of POST when redirecting
  652. * CURL_REDIR_GET_ALL - POST is changed to GET after 301 and 302
  653. * CURL_REDIR_POST_301 - POST is kept as POST after 301
  654. * CURL_REDIR_POST_302 - POST is kept as POST after 302
  655. * CURL_REDIR_POST_303 - POST is kept as POST after 303
  656. * CURL_REDIR_POST_ALL - POST is kept as POST after 301, 302 and 303
  657. * other - POST is kept as POST after 301 and 302
  658. */
  659. arg = va_arg(param, long);
  660. if(arg < CURL_REDIR_GET_ALL)
  661. /* no return error on too high numbers since the bitmask could be
  662. extended in a future */
  663. return CURLE_BAD_FUNCTION_ARGUMENT;
  664. data->set.keep_post = arg & CURL_REDIR_POST_ALL;
  665. break;
  666. case CURLOPT_POST:
  667. /* Does this option serve a purpose anymore? Yes it does, when
  668. CURLOPT_POSTFIELDS is not used and the POST data is read off the
  669. callback! */
  670. if(va_arg(param, long)) {
  671. data->set.method = HTTPREQ_POST;
  672. data->set.opt_no_body = FALSE; /* this is implied */
  673. }
  674. else
  675. data->set.method = HTTPREQ_GET;
  676. break;
  677. #ifndef CURL_DISABLE_FORM_API
  678. case CURLOPT_HTTPPOST:
  679. /*
  680. * Set to make us do HTTP POST. Legacy API-style.
  681. */
  682. data->set.httppost = va_arg(param, struct curl_httppost *);
  683. data->set.method = HTTPREQ_POST_FORM;
  684. data->set.opt_no_body = FALSE; /* this is implied */
  685. Curl_mime_cleanpart(data->state.formp);
  686. Curl_safefree(data->state.formp);
  687. data->state.mimepost = NULL;
  688. break;
  689. #endif
  690. #if !defined(CURL_DISABLE_AWS)
  691. case CURLOPT_AWS_SIGV4:
  692. /*
  693. * String that is merged to some authentication
  694. * parameters are used by the algorithm.
  695. */
  696. result = Curl_setstropt(&data->set.str[STRING_AWS_SIGV4],
  697. va_arg(param, char *));
  698. /*
  699. * Basic been set by default it need to be unset here
  700. */
  701. if(data->set.str[STRING_AWS_SIGV4])
  702. data->set.httpauth = CURLAUTH_AWS_SIGV4;
  703. break;
  704. #endif
  705. case CURLOPT_REFERER:
  706. /*
  707. * String to set in the HTTP Referer: field.
  708. */
  709. if(data->state.referer_alloc) {
  710. Curl_safefree(data->state.referer);
  711. data->state.referer_alloc = FALSE;
  712. }
  713. result = Curl_setstropt(&data->set.str[STRING_SET_REFERER],
  714. va_arg(param, char *));
  715. data->state.referer = data->set.str[STRING_SET_REFERER];
  716. break;
  717. case CURLOPT_USERAGENT:
  718. /*
  719. * String to use in the HTTP User-Agent field
  720. */
  721. result = Curl_setstropt(&data->set.str[STRING_USERAGENT],
  722. va_arg(param, char *));
  723. break;
  724. #ifndef CURL_DISABLE_PROXY
  725. case CURLOPT_PROXYHEADER:
  726. /*
  727. * Set a list with proxy headers to use (or replace internals with)
  728. *
  729. * Since CURLOPT_HTTPHEADER was the only way to set HTTP headers for a
  730. * long time we remain doing it this way until CURLOPT_PROXYHEADER is
  731. * used. As soon as this option has been used, if set to anything but
  732. * NULL, custom headers for proxies are only picked from this list.
  733. *
  734. * Set this option to NULL to restore the previous behavior.
  735. */
  736. data->set.proxyheaders = va_arg(param, struct curl_slist *);
  737. break;
  738. #endif
  739. case CURLOPT_HEADEROPT:
  740. /*
  741. * Set header option.
  742. */
  743. arg = va_arg(param, long);
  744. data->set.sep_headers = !!(arg & CURLHEADER_SEPARATE);
  745. break;
  746. #if !defined(CURL_DISABLE_COOKIES)
  747. case CURLOPT_COOKIE:
  748. /*
  749. * Cookie string to send to the remote server in the request.
  750. */
  751. result = Curl_setstropt(&data->set.str[STRING_COOKIE],
  752. va_arg(param, char *));
  753. break;
  754. case CURLOPT_COOKIEFILE:
  755. /*
  756. * Set cookie file to read and parse. Can be used multiple times.
  757. */
  758. argptr = (char *)va_arg(param, void *);
  759. if(argptr) {
  760. struct curl_slist *cl;
  761. /* general protection against mistakes and abuse */
  762. if(strlen(argptr) > CURL_MAX_INPUT_LENGTH)
  763. return CURLE_BAD_FUNCTION_ARGUMENT;
  764. /* append the cookie filename to the list of filenames, and deal with
  765. them later */
  766. cl = curl_slist_append(data->state.cookielist, argptr);
  767. if(!cl) {
  768. curl_slist_free_all(data->state.cookielist);
  769. data->state.cookielist = NULL;
  770. return CURLE_OUT_OF_MEMORY;
  771. }
  772. data->state.cookielist = cl; /* store the list for later use */
  773. }
  774. else {
  775. /* clear the list of cookie files */
  776. curl_slist_free_all(data->state.cookielist);
  777. data->state.cookielist = NULL;
  778. if(!data->share || !data->share->cookies) {
  779. /* throw away all existing cookies if this is not a shared cookie
  780. container */
  781. Curl_cookie_clearall(data->cookies);
  782. Curl_cookie_cleanup(data->cookies);
  783. }
  784. /* disable the cookie engine */
  785. data->cookies = NULL;
  786. }
  787. break;
  788. case CURLOPT_COOKIEJAR:
  789. /*
  790. * Set cookie filename to dump all cookies to when we are done.
  791. */
  792. result = Curl_setstropt(&data->set.str[STRING_COOKIEJAR],
  793. va_arg(param, char *));
  794. if(!result) {
  795. /*
  796. * Activate the cookie parser. This may or may not already
  797. * have been made.
  798. */
  799. struct CookieInfo *newcookies =
  800. Curl_cookie_init(data, NULL, data->cookies, data->set.cookiesession);
  801. if(!newcookies)
  802. result = CURLE_OUT_OF_MEMORY;
  803. data->cookies = newcookies;
  804. }
  805. break;
  806. case CURLOPT_COOKIESESSION:
  807. /*
  808. * Set this option to TRUE to start a new "cookie session". It will
  809. * prevent the forthcoming read-cookies-from-file actions to accept
  810. * cookies that are marked as being session cookies, as they belong to a
  811. * previous session.
  812. */
  813. data->set.cookiesession = (0 != va_arg(param, long));
  814. break;
  815. case CURLOPT_COOKIELIST:
  816. argptr = va_arg(param, char *);
  817. if(!argptr)
  818. break;
  819. if(strcasecompare(argptr, "ALL")) {
  820. /* clear all cookies */
  821. Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
  822. Curl_cookie_clearall(data->cookies);
  823. Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
  824. }
  825. else if(strcasecompare(argptr, "SESS")) {
  826. /* clear session cookies */
  827. Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
  828. Curl_cookie_clearsess(data->cookies);
  829. Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
  830. }
  831. else if(strcasecompare(argptr, "FLUSH")) {
  832. /* flush cookies to file, takes care of the locking */
  833. Curl_flush_cookies(data, FALSE);
  834. }
  835. else if(strcasecompare(argptr, "RELOAD")) {
  836. /* reload cookies from file */
  837. Curl_cookie_loadfiles(data);
  838. break;
  839. }
  840. else {
  841. if(!data->cookies)
  842. /* if cookie engine was not running, activate it */
  843. data->cookies = Curl_cookie_init(data, NULL, NULL, TRUE);
  844. /* general protection against mistakes and abuse */
  845. if(strlen(argptr) > CURL_MAX_INPUT_LENGTH)
  846. return CURLE_BAD_FUNCTION_ARGUMENT;
  847. argptr = strdup(argptr);
  848. if(!argptr || !data->cookies) {
  849. result = CURLE_OUT_OF_MEMORY;
  850. free(argptr);
  851. }
  852. else {
  853. Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
  854. if(checkprefix("Set-Cookie:", argptr))
  855. /* HTTP Header format line */
  856. Curl_cookie_add(data, data->cookies, TRUE, FALSE, argptr + 11, NULL,
  857. NULL, TRUE);
  858. else
  859. /* Netscape format line */
  860. Curl_cookie_add(data, data->cookies, FALSE, FALSE, argptr, NULL,
  861. NULL, TRUE);
  862. Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
  863. free(argptr);
  864. }
  865. }
  866. break;
  867. #endif /* !CURL_DISABLE_COOKIES */
  868. case CURLOPT_HTTPGET:
  869. /*
  870. * Set to force us do HTTP GET
  871. */
  872. if(va_arg(param, long)) {
  873. data->set.method = HTTPREQ_GET;
  874. data->set.opt_no_body = FALSE; /* this is implied */
  875. }
  876. break;
  877. case CURLOPT_HTTP_VERSION:
  878. /*
  879. * This sets a requested HTTP version to be used. The value is one of
  880. * the listed enums in curl/curl.h.
  881. */
  882. arg = va_arg(param, long);
  883. switch(arg) {
  884. case CURL_HTTP_VERSION_NONE:
  885. #ifdef USE_HTTP2
  886. /* TODO: this seems an undesirable quirk to force a behaviour on
  887. * lower implementations that they should recognize independently? */
  888. arg = CURL_HTTP_VERSION_2TLS;
  889. #endif
  890. /* accepted */
  891. break;
  892. case CURL_HTTP_VERSION_1_0:
  893. case CURL_HTTP_VERSION_1_1:
  894. /* accepted */
  895. break;
  896. #ifdef USE_HTTP2
  897. case CURL_HTTP_VERSION_2_0:
  898. case CURL_HTTP_VERSION_2TLS:
  899. case CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE:
  900. /* accepted */
  901. break;
  902. #endif
  903. #ifdef USE_HTTP3
  904. case CURL_HTTP_VERSION_3:
  905. case CURL_HTTP_VERSION_3ONLY:
  906. /* accepted */
  907. break;
  908. #endif
  909. default:
  910. /* not accepted */
  911. if(arg < CURL_HTTP_VERSION_NONE)
  912. return CURLE_BAD_FUNCTION_ARGUMENT;
  913. return CURLE_UNSUPPORTED_PROTOCOL;
  914. }
  915. data->set.httpwant = (unsigned char)arg;
  916. break;
  917. case CURLOPT_EXPECT_100_TIMEOUT_MS:
  918. /*
  919. * Time to wait for a response to an HTTP request containing an
  920. * Expect: 100-continue header before sending the data anyway.
  921. */
  922. arg = va_arg(param, long);
  923. if(arg < 0)
  924. return CURLE_BAD_FUNCTION_ARGUMENT;
  925. data->set.expect_100_timeout = arg;
  926. break;
  927. case CURLOPT_HTTP09_ALLOWED:
  928. arg = (long)va_arg(param, unsigned long);
  929. if(arg > 1L)
  930. return CURLE_BAD_FUNCTION_ARGUMENT;
  931. #ifdef USE_HYPER
  932. /* Hyper does not support HTTP/0.9 */
  933. if(arg)
  934. return CURLE_BAD_FUNCTION_ARGUMENT;
  935. #else
  936. data->set.http09_allowed = !!arg;
  937. #endif
  938. break;
  939. case CURLOPT_HTTP200ALIASES:
  940. /*
  941. * Set a list of aliases for HTTP 200 in response header
  942. */
  943. data->set.http200aliases = va_arg(param, struct curl_slist *);
  944. break;
  945. #endif /* CURL_DISABLE_HTTP */
  946. #if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_SMTP) || \
  947. !defined(CURL_DISABLE_IMAP)
  948. # if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_MIME)
  949. case CURLOPT_HTTPHEADER:
  950. /*
  951. * Set a list with HTTP headers to use (or replace internals with)
  952. */
  953. data->set.headers = va_arg(param, struct curl_slist *);
  954. break;
  955. # endif
  956. # ifndef CURL_DISABLE_MIME
  957. case CURLOPT_MIMEPOST:
  958. /*
  959. * Set to make us do MIME POST
  960. */
  961. result = Curl_mime_set_subparts(&data->set.mimepost,
  962. va_arg(param, curl_mime *), FALSE);
  963. if(!result) {
  964. data->set.method = HTTPREQ_POST_MIME;
  965. data->set.opt_no_body = FALSE; /* this is implied */
  966. #ifndef CURL_DISABLE_FORM_API
  967. Curl_mime_cleanpart(data->state.formp);
  968. Curl_safefree(data->state.formp);
  969. data->state.mimepost = NULL;
  970. #endif
  971. }
  972. break;
  973. case CURLOPT_MIME_OPTIONS:
  974. arg = va_arg(param, long);
  975. data->set.mime_formescape = !!(arg & CURLMIMEOPT_FORMESCAPE);
  976. break;
  977. # endif
  978. #endif
  979. case CURLOPT_HTTPAUTH:
  980. return httpauth(data, FALSE, param);
  981. case CURLOPT_CUSTOMREQUEST:
  982. /*
  983. * Set a custom string to use as request
  984. */
  985. result = Curl_setstropt(&data->set.str[STRING_CUSTOMREQUEST],
  986. va_arg(param, char *));
  987. /* we do not set
  988. data->set.method = HTTPREQ_CUSTOM;
  989. here, we continue as if we were using the already set type
  990. and this just changes the actual request keyword */
  991. break;
  992. #ifndef CURL_DISABLE_PROXY
  993. case CURLOPT_HTTPPROXYTUNNEL:
  994. /*
  995. * Tunnel operations through the proxy instead of normal proxy use
  996. */
  997. data->set.tunnel_thru_httpproxy = (0 != va_arg(param, long));
  998. break;
  999. case CURLOPT_PROXYPORT:
  1000. /*
  1001. * Explicitly set HTTP proxy port number.
  1002. */
  1003. arg = va_arg(param, long);
  1004. if((arg < 0) || (arg > 65535))
  1005. return CURLE_BAD_FUNCTION_ARGUMENT;
  1006. data->set.proxyport = (unsigned short)arg;
  1007. break;
  1008. case CURLOPT_PROXYAUTH:
  1009. return httpauth(data, TRUE, param);
  1010. case CURLOPT_PROXY:
  1011. /*
  1012. * Set proxy server:port to use as proxy.
  1013. *
  1014. * If the proxy is set to "" (and CURLOPT_SOCKS_PROXY is set to "" or NULL)
  1015. * we explicitly say that we do not want to use a proxy
  1016. * (even though there might be environment variables saying so).
  1017. *
  1018. * Setting it to NULL, means no proxy but allows the environment variables
  1019. * to decide for us (if CURLOPT_SOCKS_PROXY setting it to NULL).
  1020. */
  1021. result = Curl_setstropt(&data->set.str[STRING_PROXY],
  1022. va_arg(param, char *));
  1023. break;
  1024. case CURLOPT_PRE_PROXY:
  1025. /*
  1026. * Set proxy server:port to use as SOCKS proxy.
  1027. *
  1028. * If the proxy is set to "" or NULL we explicitly say that we do not want
  1029. * to use the socks proxy.
  1030. */
  1031. result = Curl_setstropt(&data->set.str[STRING_PRE_PROXY],
  1032. va_arg(param, char *));
  1033. break;
  1034. case CURLOPT_PROXYTYPE:
  1035. /*
  1036. * Set proxy type.
  1037. */
  1038. arg = va_arg(param, long);
  1039. if((arg < CURLPROXY_HTTP) || (arg > CURLPROXY_SOCKS5_HOSTNAME))
  1040. return CURLE_BAD_FUNCTION_ARGUMENT;
  1041. data->set.proxytype = (unsigned char)(curl_proxytype)arg;
  1042. break;
  1043. case CURLOPT_PROXY_TRANSFER_MODE:
  1044. /*
  1045. * set transfer mode (;type=<a|i>) when doing FTP via an HTTP proxy
  1046. */
  1047. switch(va_arg(param, long)) {
  1048. case 0:
  1049. data->set.proxy_transfer_mode = FALSE;
  1050. break;
  1051. case 1:
  1052. data->set.proxy_transfer_mode = TRUE;
  1053. break;
  1054. default:
  1055. /* reserve other values for future use */
  1056. result = CURLE_BAD_FUNCTION_ARGUMENT;
  1057. break;
  1058. }
  1059. break;
  1060. case CURLOPT_SOCKS5_AUTH:
  1061. data->set.socks5auth = (unsigned char)va_arg(param, unsigned long);
  1062. if(data->set.socks5auth & ~(CURLAUTH_BASIC | CURLAUTH_GSSAPI))
  1063. result = CURLE_NOT_BUILT_IN;
  1064. break;
  1065. #endif /* CURL_DISABLE_PROXY */
  1066. #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
  1067. case CURLOPT_SOCKS5_GSSAPI_NEC:
  1068. /*
  1069. * Set flag for NEC SOCK5 support
  1070. */
  1071. data->set.socks5_gssapi_nec = (0 != va_arg(param, long));
  1072. break;
  1073. #endif
  1074. #ifndef CURL_DISABLE_PROXY
  1075. case CURLOPT_SOCKS5_GSSAPI_SERVICE:
  1076. case CURLOPT_PROXY_SERVICE_NAME:
  1077. /*
  1078. * Set proxy authentication service name for Kerberos 5 and SPNEGO
  1079. */
  1080. result = Curl_setstropt(&data->set.str[STRING_PROXY_SERVICE_NAME],
  1081. va_arg(param, char *));
  1082. break;
  1083. #endif
  1084. case CURLOPT_SERVICE_NAME:
  1085. /*
  1086. * Set authentication service name for DIGEST-MD5, Kerberos 5 and SPNEGO
  1087. */
  1088. result = Curl_setstropt(&data->set.str[STRING_SERVICE_NAME],
  1089. va_arg(param, char *));
  1090. break;
  1091. case CURLOPT_HEADERDATA:
  1092. /*
  1093. * Custom pointer to pass the header write callback function
  1094. */
  1095. data->set.writeheader = (void *)va_arg(param, void *);
  1096. break;
  1097. case CURLOPT_ERRORBUFFER:
  1098. /*
  1099. * Error buffer provided by the caller to get the human readable
  1100. * error string in.
  1101. */
  1102. data->set.errorbuffer = va_arg(param, char *);
  1103. break;
  1104. case CURLOPT_WRITEDATA:
  1105. /*
  1106. * FILE pointer to write to. Or possibly
  1107. * used as argument to the write callback.
  1108. */
  1109. data->set.out = va_arg(param, void *);
  1110. break;
  1111. #ifdef CURL_LIST_ONLY_PROTOCOL
  1112. case CURLOPT_DIRLISTONLY:
  1113. /*
  1114. * An option that changes the command to one that asks for a list only, no
  1115. * file info details. Used for FTP, POP3 and SFTP.
  1116. */
  1117. data->set.list_only = (0 != va_arg(param, long));
  1118. break;
  1119. #endif
  1120. case CURLOPT_APPEND:
  1121. /*
  1122. * We want to upload and append to an existing file. Used for FTP and
  1123. * SFTP.
  1124. */
  1125. data->set.remote_append = (0 != va_arg(param, long));
  1126. break;
  1127. #ifndef CURL_DISABLE_FTP
  1128. case CURLOPT_FTP_FILEMETHOD:
  1129. /*
  1130. * How do access files over FTP.
  1131. */
  1132. arg = va_arg(param, long);
  1133. if((arg < CURLFTPMETHOD_DEFAULT) || (arg >= CURLFTPMETHOD_LAST))
  1134. return CURLE_BAD_FUNCTION_ARGUMENT;
  1135. data->set.ftp_filemethod = (unsigned char)arg;
  1136. break;
  1137. case CURLOPT_FTPPORT:
  1138. /*
  1139. * Use FTP PORT, this also specifies which IP address to use
  1140. */
  1141. result = Curl_setstropt(&data->set.str[STRING_FTPPORT],
  1142. va_arg(param, char *));
  1143. data->set.ftp_use_port = !!(data->set.str[STRING_FTPPORT]);
  1144. break;
  1145. case CURLOPT_FTP_USE_EPRT:
  1146. data->set.ftp_use_eprt = (0 != va_arg(param, long));
  1147. break;
  1148. case CURLOPT_FTP_USE_EPSV:
  1149. data->set.ftp_use_epsv = (0 != va_arg(param, long));
  1150. break;
  1151. case CURLOPT_FTP_USE_PRET:
  1152. data->set.ftp_use_pret = (0 != va_arg(param, long));
  1153. break;
  1154. case CURLOPT_FTP_SSL_CCC:
  1155. arg = va_arg(param, long);
  1156. if((arg < CURLFTPSSL_CCC_NONE) || (arg >= CURLFTPSSL_CCC_LAST))
  1157. return CURLE_BAD_FUNCTION_ARGUMENT;
  1158. data->set.ftp_ccc = (unsigned char)arg;
  1159. break;
  1160. case CURLOPT_FTP_SKIP_PASV_IP:
  1161. /*
  1162. * Enable or disable FTP_SKIP_PASV_IP, which will disable/enable the
  1163. * bypass of the IP address in PASV responses.
  1164. */
  1165. data->set.ftp_skip_ip = (0 != va_arg(param, long));
  1166. break;
  1167. case CURLOPT_FTP_ACCOUNT:
  1168. result = Curl_setstropt(&data->set.str[STRING_FTP_ACCOUNT],
  1169. va_arg(param, char *));
  1170. break;
  1171. case CURLOPT_FTP_ALTERNATIVE_TO_USER:
  1172. result = Curl_setstropt(&data->set.str[STRING_FTP_ALTERNATIVE_TO_USER],
  1173. va_arg(param, char *));
  1174. break;
  1175. case CURLOPT_FTPSSLAUTH:
  1176. /*
  1177. * Set a specific auth for FTP-SSL transfers.
  1178. */
  1179. arg = va_arg(param, long);
  1180. if((arg < CURLFTPAUTH_DEFAULT) || (arg >= CURLFTPAUTH_LAST))
  1181. return CURLE_BAD_FUNCTION_ARGUMENT;
  1182. data->set.ftpsslauth = (unsigned char)(curl_ftpauth)arg;
  1183. break;
  1184. #ifdef HAVE_GSSAPI
  1185. case CURLOPT_KRBLEVEL:
  1186. /*
  1187. * A string that defines the kerberos security level.
  1188. */
  1189. result = Curl_setstropt(&data->set.str[STRING_KRB_LEVEL],
  1190. va_arg(param, char *));
  1191. data->set.krb = !!(data->set.str[STRING_KRB_LEVEL]);
  1192. break;
  1193. #endif
  1194. #endif
  1195. #if !defined(CURL_DISABLE_FTP) || defined(USE_SSH)
  1196. case CURLOPT_FTP_CREATE_MISSING_DIRS:
  1197. /*
  1198. * An FTP/SFTP option that modifies an upload to create missing
  1199. * directories on the server.
  1200. */
  1201. arg = va_arg(param, long);
  1202. /* reserve other values for future use */
  1203. if((arg < CURLFTP_CREATE_DIR_NONE) ||
  1204. (arg > CURLFTP_CREATE_DIR_RETRY))
  1205. result = CURLE_BAD_FUNCTION_ARGUMENT;
  1206. else
  1207. data->set.ftp_create_missing_dirs = (unsigned char)arg;
  1208. break;
  1209. case CURLOPT_POSTQUOTE:
  1210. /*
  1211. * List of RAW FTP commands to use after a transfer
  1212. */
  1213. data->set.postquote = va_arg(param, struct curl_slist *);
  1214. break;
  1215. case CURLOPT_PREQUOTE:
  1216. /*
  1217. * List of RAW FTP commands to use prior to RETR (Wesley Laxton)
  1218. */
  1219. data->set.prequote = va_arg(param, struct curl_slist *);
  1220. break;
  1221. case CURLOPT_QUOTE:
  1222. /*
  1223. * List of RAW FTP commands to use before a transfer
  1224. */
  1225. data->set.quote = va_arg(param, struct curl_slist *);
  1226. break;
  1227. #endif
  1228. case CURLOPT_READDATA:
  1229. /*
  1230. * FILE pointer to read the file to be uploaded from. Or possibly
  1231. * used as argument to the read callback.
  1232. */
  1233. data->set.in_set = va_arg(param, void *);
  1234. break;
  1235. case CURLOPT_INFILESIZE:
  1236. /*
  1237. * If known, this should inform curl about the file size of the
  1238. * to-be-uploaded file.
  1239. */
  1240. arg = va_arg(param, long);
  1241. if(arg < -1)
  1242. return CURLE_BAD_FUNCTION_ARGUMENT;
  1243. data->set.filesize = arg;
  1244. break;
  1245. case CURLOPT_INFILESIZE_LARGE:
  1246. /*
  1247. * If known, this should inform curl about the file size of the
  1248. * to-be-uploaded file.
  1249. */
  1250. bigsize = va_arg(param, curl_off_t);
  1251. if(bigsize < -1)
  1252. return CURLE_BAD_FUNCTION_ARGUMENT;
  1253. data->set.filesize = bigsize;
  1254. break;
  1255. case CURLOPT_LOW_SPEED_LIMIT:
  1256. /*
  1257. * The low speed limit that if transfers are below this for
  1258. * CURLOPT_LOW_SPEED_TIME, the transfer is aborted.
  1259. */
  1260. arg = va_arg(param, long);
  1261. if(arg < 0)
  1262. return CURLE_BAD_FUNCTION_ARGUMENT;
  1263. data->set.low_speed_limit = arg;
  1264. break;
  1265. case CURLOPT_MAX_SEND_SPEED_LARGE:
  1266. /*
  1267. * When transfer uploads are faster then CURLOPT_MAX_SEND_SPEED_LARGE
  1268. * bytes per second the transfer is throttled..
  1269. */
  1270. bigsize = va_arg(param, curl_off_t);
  1271. if(bigsize < 0)
  1272. return CURLE_BAD_FUNCTION_ARGUMENT;
  1273. data->set.max_send_speed = bigsize;
  1274. break;
  1275. case CURLOPT_MAX_RECV_SPEED_LARGE:
  1276. /*
  1277. * When receiving data faster than CURLOPT_MAX_RECV_SPEED_LARGE bytes per
  1278. * second the transfer is throttled..
  1279. */
  1280. bigsize = va_arg(param, curl_off_t);
  1281. if(bigsize < 0)
  1282. return CURLE_BAD_FUNCTION_ARGUMENT;
  1283. data->set.max_recv_speed = bigsize;
  1284. break;
  1285. case CURLOPT_LOW_SPEED_TIME:
  1286. /*
  1287. * The low speed time that if transfers are below the set
  1288. * CURLOPT_LOW_SPEED_LIMIT during this time, the transfer is aborted.
  1289. */
  1290. arg = va_arg(param, long);
  1291. if(arg < 0)
  1292. return CURLE_BAD_FUNCTION_ARGUMENT;
  1293. data->set.low_speed_time = arg;
  1294. break;
  1295. case CURLOPT_CURLU:
  1296. /*
  1297. * pass CURLU to set URL
  1298. */
  1299. data->set.uh = va_arg(param, CURLU *);
  1300. break;
  1301. case CURLOPT_URL:
  1302. /*
  1303. * The URL to fetch.
  1304. */
  1305. if(data->state.url_alloc) {
  1306. /* the already set URL is allocated, free it first! */
  1307. Curl_safefree(data->state.url);
  1308. data->state.url_alloc = FALSE;
  1309. }
  1310. result = Curl_setstropt(&data->set.str[STRING_SET_URL],
  1311. va_arg(param, char *));
  1312. data->state.url = data->set.str[STRING_SET_URL];
  1313. break;
  1314. case CURLOPT_PORT:
  1315. /*
  1316. * The port number to use when getting the URL. 0 disables it.
  1317. */
  1318. arg = va_arg(param, long);
  1319. if((arg < 0) || (arg > 65535))
  1320. return CURLE_BAD_FUNCTION_ARGUMENT;
  1321. data->set.use_port = (unsigned short)arg;
  1322. break;
  1323. case CURLOPT_TIMEOUT:
  1324. /*
  1325. * The maximum time you allow curl to use for a single transfer
  1326. * operation.
  1327. */
  1328. arg = va_arg(param, long);
  1329. if((arg >= 0) && (arg <= (INT_MAX/1000)))
  1330. data->set.timeout = (unsigned int)arg * 1000;
  1331. else
  1332. return CURLE_BAD_FUNCTION_ARGUMENT;
  1333. break;
  1334. case CURLOPT_TIMEOUT_MS:
  1335. uarg = va_arg(param, unsigned long);
  1336. if(uarg > UINT_MAX)
  1337. uarg = UINT_MAX;
  1338. data->set.timeout = (unsigned int)uarg;
  1339. break;
  1340. case CURLOPT_CONNECTTIMEOUT:
  1341. /*
  1342. * The maximum time you allow curl to use to connect.
  1343. */
  1344. arg = va_arg(param, long);
  1345. if((arg >= 0) && (arg <= (INT_MAX/1000)))
  1346. data->set.connecttimeout = (unsigned int)arg * 1000;
  1347. else
  1348. return CURLE_BAD_FUNCTION_ARGUMENT;
  1349. break;
  1350. case CURLOPT_CONNECTTIMEOUT_MS:
  1351. uarg = va_arg(param, unsigned long);
  1352. if(uarg > UINT_MAX)
  1353. uarg = UINT_MAX;
  1354. data->set.connecttimeout = (unsigned int)uarg;
  1355. break;
  1356. #ifndef CURL_DISABLE_FTP
  1357. case CURLOPT_ACCEPTTIMEOUT_MS:
  1358. /*
  1359. * The maximum time for curl to wait for FTP server connect
  1360. */
  1361. uarg = va_arg(param, unsigned long);
  1362. if(uarg > UINT_MAX)
  1363. uarg = UINT_MAX;
  1364. data->set.accepttimeout = (unsigned int)uarg;
  1365. break;
  1366. #endif
  1367. case CURLOPT_USERPWD:
  1368. /*
  1369. * user:password to use in the operation
  1370. */
  1371. result = setstropt_userpwd(va_arg(param, char *),
  1372. &data->set.str[STRING_USERNAME],
  1373. &data->set.str[STRING_PASSWORD]);
  1374. break;
  1375. case CURLOPT_USERNAME:
  1376. /*
  1377. * authentication username to use in the operation
  1378. */
  1379. result = Curl_setstropt(&data->set.str[STRING_USERNAME],
  1380. va_arg(param, char *));
  1381. break;
  1382. case CURLOPT_PASSWORD:
  1383. /*
  1384. * authentication password to use in the operation
  1385. */
  1386. result = Curl_setstropt(&data->set.str[STRING_PASSWORD],
  1387. va_arg(param, char *));
  1388. break;
  1389. case CURLOPT_LOGIN_OPTIONS:
  1390. /*
  1391. * authentication options to use in the operation
  1392. */
  1393. result = Curl_setstropt(&data->set.str[STRING_OPTIONS],
  1394. va_arg(param, char *));
  1395. break;
  1396. case CURLOPT_XOAUTH2_BEARER:
  1397. /*
  1398. * OAuth 2.0 bearer token to use in the operation
  1399. */
  1400. result = Curl_setstropt(&data->set.str[STRING_BEARER],
  1401. va_arg(param, char *));
  1402. break;
  1403. case CURLOPT_RESOLVE:
  1404. /*
  1405. * List of HOST:PORT:[addresses] strings to populate the DNS cache with
  1406. * Entries added this way will remain in the cache until explicitly
  1407. * removed or the handle is cleaned up.
  1408. *
  1409. * Prefix the HOST with plus sign (+) to have the entry expire just like
  1410. * automatically added entries.
  1411. *
  1412. * Prefix the HOST with dash (-) to _remove_ the entry from the cache.
  1413. *
  1414. * This API can remove any entry from the DNS cache, but only entries
  1415. * that are not actually in use right now will be pruned immediately.
  1416. */
  1417. data->set.resolve = va_arg(param, struct curl_slist *);
  1418. data->state.resolve = data->set.resolve;
  1419. break;
  1420. case CURLOPT_PROGRESSFUNCTION:
  1421. /*
  1422. * Progress callback function
  1423. */
  1424. data->set.fprogress = va_arg(param, curl_progress_callback);
  1425. if(data->set.fprogress)
  1426. data->progress.callback = TRUE; /* no longer internal */
  1427. else
  1428. data->progress.callback = FALSE; /* NULL enforces internal */
  1429. break;
  1430. case CURLOPT_XFERINFOFUNCTION:
  1431. /*
  1432. * Transfer info callback function
  1433. */
  1434. data->set.fxferinfo = va_arg(param, curl_xferinfo_callback);
  1435. if(data->set.fxferinfo)
  1436. data->progress.callback = TRUE; /* no longer internal */
  1437. else
  1438. data->progress.callback = FALSE; /* NULL enforces internal */
  1439. break;
  1440. case CURLOPT_PROGRESSDATA:
  1441. /*
  1442. * Custom client data to pass to the progress callback
  1443. */
  1444. data->set.progress_client = va_arg(param, void *);
  1445. break;
  1446. #ifndef CURL_DISABLE_PROXY
  1447. case CURLOPT_PROXYUSERPWD: {
  1448. /*
  1449. * user:password needed to use the proxy
  1450. */
  1451. char *u = NULL;
  1452. char *p = NULL;
  1453. result = setstropt_userpwd(va_arg(param, char *), &u, &p);
  1454. /* URL decode the components */
  1455. if(!result && u)
  1456. result = Curl_urldecode(u, 0, &data->set.str[STRING_PROXYUSERNAME], NULL,
  1457. REJECT_ZERO);
  1458. if(!result && p)
  1459. result = Curl_urldecode(p, 0, &data->set.str[STRING_PROXYPASSWORD], NULL,
  1460. REJECT_ZERO);
  1461. free(u);
  1462. free(p);
  1463. }
  1464. break;
  1465. case CURLOPT_PROXYUSERNAME:
  1466. /*
  1467. * authentication username to use in the operation
  1468. */
  1469. result = Curl_setstropt(&data->set.str[STRING_PROXYUSERNAME],
  1470. va_arg(param, char *));
  1471. break;
  1472. case CURLOPT_PROXYPASSWORD:
  1473. /*
  1474. * authentication password to use in the operation
  1475. */
  1476. result = Curl_setstropt(&data->set.str[STRING_PROXYPASSWORD],
  1477. va_arg(param, char *));
  1478. break;
  1479. case CURLOPT_NOPROXY:
  1480. /*
  1481. * proxy exception list
  1482. */
  1483. result = Curl_setstropt(&data->set.str[STRING_NOPROXY],
  1484. va_arg(param, char *));
  1485. break;
  1486. #endif
  1487. case CURLOPT_RANGE:
  1488. /*
  1489. * What range of the file you want to transfer
  1490. */
  1491. result = Curl_setstropt(&data->set.str[STRING_SET_RANGE],
  1492. va_arg(param, char *));
  1493. break;
  1494. case CURLOPT_RESUME_FROM:
  1495. /*
  1496. * Resume transfer at the given file position
  1497. */
  1498. arg = va_arg(param, long);
  1499. if(arg < -1)
  1500. return CURLE_BAD_FUNCTION_ARGUMENT;
  1501. data->set.set_resume_from = arg;
  1502. break;
  1503. case CURLOPT_RESUME_FROM_LARGE:
  1504. /*
  1505. * Resume transfer at the given file position
  1506. */
  1507. bigsize = va_arg(param, curl_off_t);
  1508. if(bigsize < -1)
  1509. return CURLE_BAD_FUNCTION_ARGUMENT;
  1510. data->set.set_resume_from = bigsize;
  1511. break;
  1512. case CURLOPT_DEBUGFUNCTION:
  1513. /*
  1514. * stderr write callback.
  1515. */
  1516. data->set.fdebug = va_arg(param, curl_debug_callback);
  1517. /*
  1518. * if the callback provided is NULL, it will use the default callback
  1519. */
  1520. break;
  1521. case CURLOPT_DEBUGDATA:
  1522. /*
  1523. * Set to a void * that should receive all error writes. This
  1524. * defaults to CURLOPT_STDERR for normal operations.
  1525. */
  1526. data->set.debugdata = va_arg(param, void *);
  1527. break;
  1528. case CURLOPT_STDERR:
  1529. /*
  1530. * Set to a FILE * that should receive all error writes. This
  1531. * defaults to stderr for normal operations.
  1532. */
  1533. data->set.err = va_arg(param, FILE *);
  1534. if(!data->set.err)
  1535. data->set.err = stderr;
  1536. break;
  1537. case CURLOPT_HEADERFUNCTION:
  1538. /*
  1539. * Set header write callback
  1540. */
  1541. data->set.fwrite_header = va_arg(param, curl_write_callback);
  1542. break;
  1543. case CURLOPT_WRITEFUNCTION:
  1544. /*
  1545. * Set data write callback
  1546. */
  1547. data->set.fwrite_func = va_arg(param, curl_write_callback);
  1548. if(!data->set.fwrite_func)
  1549. /* When set to NULL, reset to our internal default function */
  1550. data->set.fwrite_func = (curl_write_callback)fwrite;
  1551. break;
  1552. case CURLOPT_READFUNCTION:
  1553. /*
  1554. * Read data callback
  1555. */
  1556. data->set.fread_func_set = va_arg(param, curl_read_callback);
  1557. if(!data->set.fread_func_set) {
  1558. data->set.is_fread_set = 0;
  1559. /* When set to NULL, reset to our internal default function */
  1560. data->set.fread_func_set = (curl_read_callback)fread;
  1561. }
  1562. else
  1563. data->set.is_fread_set = 1;
  1564. break;
  1565. case CURLOPT_SEEKFUNCTION:
  1566. /*
  1567. * Seek callback. Might be NULL.
  1568. */
  1569. data->set.seek_func = va_arg(param, curl_seek_callback);
  1570. break;
  1571. case CURLOPT_SEEKDATA:
  1572. /*
  1573. * Seek control callback. Might be NULL.
  1574. */
  1575. data->set.seek_client = va_arg(param, void *);
  1576. break;
  1577. case CURLOPT_IOCTLFUNCTION:
  1578. /*
  1579. * I/O control callback. Might be NULL.
  1580. */
  1581. data->set.ioctl_func = va_arg(param, curl_ioctl_callback);
  1582. break;
  1583. case CURLOPT_IOCTLDATA:
  1584. /*
  1585. * I/O control data pointer. Might be NULL.
  1586. */
  1587. data->set.ioctl_client = va_arg(param, void *);
  1588. break;
  1589. case CURLOPT_SSLCERT:
  1590. /*
  1591. * String that holds filename of the SSL certificate to use
  1592. */
  1593. result = Curl_setstropt(&data->set.str[STRING_CERT],
  1594. va_arg(param, char *));
  1595. break;
  1596. case CURLOPT_SSLCERT_BLOB:
  1597. /*
  1598. * Blob that holds file content of the SSL certificate to use
  1599. */
  1600. result = Curl_setblobopt(&data->set.blobs[BLOB_CERT],
  1601. va_arg(param, struct curl_blob *));
  1602. break;
  1603. #ifndef CURL_DISABLE_PROXY
  1604. case CURLOPT_PROXY_SSLCERT:
  1605. /*
  1606. * String that holds filename of the SSL certificate to use for proxy
  1607. */
  1608. result = Curl_setstropt(&data->set.str[STRING_CERT_PROXY],
  1609. va_arg(param, char *));
  1610. break;
  1611. case CURLOPT_PROXY_SSLCERT_BLOB:
  1612. /*
  1613. * Blob that holds file content of the SSL certificate to use for proxy
  1614. */
  1615. result = Curl_setblobopt(&data->set.blobs[BLOB_CERT_PROXY],
  1616. va_arg(param, struct curl_blob *));
  1617. break;
  1618. #endif
  1619. case CURLOPT_SSLCERTTYPE:
  1620. /*
  1621. * String that holds file type of the SSL certificate to use
  1622. */
  1623. result = Curl_setstropt(&data->set.str[STRING_CERT_TYPE],
  1624. va_arg(param, char *));
  1625. break;
  1626. #ifndef CURL_DISABLE_PROXY
  1627. case CURLOPT_PROXY_SSLCERTTYPE:
  1628. /*
  1629. * String that holds file type of the SSL certificate to use for proxy
  1630. */
  1631. result = Curl_setstropt(&data->set.str[STRING_CERT_TYPE_PROXY],
  1632. va_arg(param, char *));
  1633. break;
  1634. #endif
  1635. case CURLOPT_SSLKEY:
  1636. /*
  1637. * String that holds filename of the SSL key to use
  1638. */
  1639. result = Curl_setstropt(&data->set.str[STRING_KEY],
  1640. va_arg(param, char *));
  1641. break;
  1642. case CURLOPT_SSLKEY_BLOB:
  1643. /*
  1644. * Blob that holds file content of the SSL key to use
  1645. */
  1646. result = Curl_setblobopt(&data->set.blobs[BLOB_KEY],
  1647. va_arg(param, struct curl_blob *));
  1648. break;
  1649. #ifndef CURL_DISABLE_PROXY
  1650. case CURLOPT_PROXY_SSLKEY:
  1651. /*
  1652. * String that holds filename of the SSL key to use for proxy
  1653. */
  1654. result = Curl_setstropt(&data->set.str[STRING_KEY_PROXY],
  1655. va_arg(param, char *));
  1656. break;
  1657. case CURLOPT_PROXY_SSLKEY_BLOB:
  1658. /*
  1659. * Blob that holds file content of the SSL key to use for proxy
  1660. */
  1661. result = Curl_setblobopt(&data->set.blobs[BLOB_KEY_PROXY],
  1662. va_arg(param, struct curl_blob *));
  1663. break;
  1664. #endif
  1665. case CURLOPT_SSLKEYTYPE:
  1666. /*
  1667. * String that holds file type of the SSL key to use
  1668. */
  1669. result = Curl_setstropt(&data->set.str[STRING_KEY_TYPE],
  1670. va_arg(param, char *));
  1671. break;
  1672. #ifndef CURL_DISABLE_PROXY
  1673. case CURLOPT_PROXY_SSLKEYTYPE:
  1674. /*
  1675. * String that holds file type of the SSL key to use for proxy
  1676. */
  1677. result = Curl_setstropt(&data->set.str[STRING_KEY_TYPE_PROXY],
  1678. va_arg(param, char *));
  1679. break;
  1680. #endif
  1681. case CURLOPT_KEYPASSWD:
  1682. /*
  1683. * String that holds the SSL or SSH private key password.
  1684. */
  1685. result = Curl_setstropt(&data->set.str[STRING_KEY_PASSWD],
  1686. va_arg(param, char *));
  1687. break;
  1688. #ifndef CURL_DISABLE_PROXY
  1689. case CURLOPT_PROXY_KEYPASSWD:
  1690. /*
  1691. * String that holds the SSL private key password for proxy.
  1692. */
  1693. result = Curl_setstropt(&data->set.str[STRING_KEY_PASSWD_PROXY],
  1694. va_arg(param, char *));
  1695. break;
  1696. #endif
  1697. case CURLOPT_SSLENGINE:
  1698. /*
  1699. * String that holds the SSL crypto engine.
  1700. */
  1701. argptr = va_arg(param, char *);
  1702. if(argptr && argptr[0]) {
  1703. result = Curl_setstropt(&data->set.str[STRING_SSL_ENGINE], argptr);
  1704. if(!result) {
  1705. result = Curl_ssl_set_engine(data, argptr);
  1706. }
  1707. }
  1708. break;
  1709. case CURLOPT_SSLENGINE_DEFAULT:
  1710. /*
  1711. * flag to set engine as default.
  1712. */
  1713. Curl_safefree(data->set.str[STRING_SSL_ENGINE]);
  1714. result = Curl_ssl_set_engine_default(data);
  1715. break;
  1716. case CURLOPT_CRLF:
  1717. /*
  1718. * Kludgy option to enable CRLF conversions. Subject for removal.
  1719. */
  1720. data->set.crlf = (0 != va_arg(param, long));
  1721. break;
  1722. #ifndef CURL_DISABLE_PROXY
  1723. case CURLOPT_HAPROXYPROTOCOL:
  1724. /*
  1725. * Set to send the HAProxy Proxy Protocol header
  1726. */
  1727. data->set.haproxyprotocol = (0 != va_arg(param, long));
  1728. break;
  1729. case CURLOPT_HAPROXY_CLIENT_IP:
  1730. /*
  1731. * Set the client IP to send through HAProxy PROXY protocol
  1732. */
  1733. result = Curl_setstropt(&data->set.str[STRING_HAPROXY_CLIENT_IP],
  1734. va_arg(param, char *));
  1735. /* We enable implicitly the HAProxy protocol if we use this flag. */
  1736. data->set.haproxyprotocol = TRUE;
  1737. break;
  1738. #endif
  1739. case CURLOPT_INTERFACE:
  1740. /*
  1741. * Set what interface or address/hostname to bind the socket to when
  1742. * performing an operation and thus what from-IP your connection will use.
  1743. */
  1744. result = setstropt_interface(va_arg(param, char *),
  1745. &data->set.str[STRING_DEVICE],
  1746. &data->set.str[STRING_INTERFACE],
  1747. &data->set.str[STRING_BINDHOST]);
  1748. break;
  1749. #ifndef CURL_DISABLE_BINDLOCAL
  1750. case CURLOPT_LOCALPORT:
  1751. /*
  1752. * Set what local port to bind the socket to when performing an operation.
  1753. */
  1754. arg = va_arg(param, long);
  1755. if((arg < 0) || (arg > 65535))
  1756. return CURLE_BAD_FUNCTION_ARGUMENT;
  1757. data->set.localport = curlx_sltous(arg);
  1758. break;
  1759. case CURLOPT_LOCALPORTRANGE:
  1760. /*
  1761. * Set number of local ports to try, starting with CURLOPT_LOCALPORT.
  1762. */
  1763. arg = va_arg(param, long);
  1764. if((arg < 0) || (arg > 65535))
  1765. return CURLE_BAD_FUNCTION_ARGUMENT;
  1766. data->set.localportrange = curlx_sltous(arg);
  1767. break;
  1768. #endif
  1769. case CURLOPT_GSSAPI_DELEGATION:
  1770. /*
  1771. * GSS-API credential delegation bitmask
  1772. */
  1773. uarg = va_arg(param, unsigned long);
  1774. data->set.gssapi_delegation = (unsigned char)uarg&
  1775. (CURLGSSAPI_DELEGATION_POLICY_FLAG|CURLGSSAPI_DELEGATION_FLAG);
  1776. break;
  1777. case CURLOPT_SSL_VERIFYPEER:
  1778. /*
  1779. * Enable peer SSL verifying.
  1780. */
  1781. data->set.ssl.primary.verifypeer = (0 != va_arg(param, long));
  1782. /* Update the current connection ssl_config. */
  1783. Curl_ssl_conn_config_update(data, FALSE);
  1784. break;
  1785. #ifndef CURL_DISABLE_DOH
  1786. case CURLOPT_DOH_SSL_VERIFYPEER:
  1787. /*
  1788. * Enable peer SSL verifying for DoH.
  1789. */
  1790. data->set.doh_verifypeer = (0 != va_arg(param, long));
  1791. break;
  1792. #endif
  1793. #ifndef CURL_DISABLE_PROXY
  1794. case CURLOPT_PROXY_SSL_VERIFYPEER:
  1795. /*
  1796. * Enable peer SSL verifying for proxy.
  1797. */
  1798. data->set.proxy_ssl.primary.verifypeer =
  1799. (0 != va_arg(param, long));
  1800. /* Update the current connection proxy_ssl_config. */
  1801. Curl_ssl_conn_config_update(data, TRUE);
  1802. break;
  1803. #endif
  1804. case CURLOPT_SSL_VERIFYHOST:
  1805. /*
  1806. * Enable verification of the hostname in the peer certificate
  1807. */
  1808. arg = va_arg(param, long);
  1809. /* Obviously people are not reading documentation and too many thought
  1810. this argument took a boolean when it was not and misused it.
  1811. Treat 1 and 2 the same */
  1812. data->set.ssl.primary.verifyhost = !!(arg & 3);
  1813. /* Update the current connection ssl_config. */
  1814. Curl_ssl_conn_config_update(data, FALSE);
  1815. break;
  1816. #ifndef CURL_DISABLE_DOH
  1817. case CURLOPT_DOH_SSL_VERIFYHOST:
  1818. /*
  1819. * Enable verification of the hostname in the peer certificate for DoH
  1820. */
  1821. arg = va_arg(param, long);
  1822. /* Treat both 1 and 2 as TRUE */
  1823. data->set.doh_verifyhost = !!(arg & 3);
  1824. break;
  1825. #endif
  1826. #ifndef CURL_DISABLE_PROXY
  1827. case CURLOPT_PROXY_SSL_VERIFYHOST:
  1828. /*
  1829. * Enable verification of the hostname in the peer certificate for proxy
  1830. */
  1831. arg = va_arg(param, long);
  1832. /* Treat both 1 and 2 as TRUE */
  1833. data->set.proxy_ssl.primary.verifyhost = !!(arg & 3);
  1834. /* Update the current connection proxy_ssl_config. */
  1835. Curl_ssl_conn_config_update(data, TRUE);
  1836. break;
  1837. #endif
  1838. case CURLOPT_SSL_VERIFYSTATUS:
  1839. /*
  1840. * Enable certificate status verifying.
  1841. */
  1842. if(!Curl_ssl_cert_status_request()) {
  1843. result = CURLE_NOT_BUILT_IN;
  1844. break;
  1845. }
  1846. data->set.ssl.primary.verifystatus = (0 != va_arg(param, long));
  1847. /* Update the current connection ssl_config. */
  1848. Curl_ssl_conn_config_update(data, FALSE);
  1849. break;
  1850. #ifndef CURL_DISABLE_DOH
  1851. case CURLOPT_DOH_SSL_VERIFYSTATUS:
  1852. /*
  1853. * Enable certificate status verifying for DoH.
  1854. */
  1855. if(!Curl_ssl_cert_status_request()) {
  1856. result = CURLE_NOT_BUILT_IN;
  1857. break;
  1858. }
  1859. data->set.doh_verifystatus = (0 != va_arg(param, long));
  1860. break;
  1861. #endif
  1862. case CURLOPT_SSL_CTX_FUNCTION:
  1863. /*
  1864. * Set a SSL_CTX callback
  1865. */
  1866. #ifdef USE_SSL
  1867. if(Curl_ssl_supports(data, SSLSUPP_SSL_CTX))
  1868. data->set.ssl.fsslctx = va_arg(param, curl_ssl_ctx_callback);
  1869. else
  1870. #endif
  1871. result = CURLE_NOT_BUILT_IN;
  1872. break;
  1873. case CURLOPT_SSL_CTX_DATA:
  1874. /*
  1875. * Set a SSL_CTX callback parameter pointer
  1876. */
  1877. #ifdef USE_SSL
  1878. if(Curl_ssl_supports(data, SSLSUPP_SSL_CTX))
  1879. data->set.ssl.fsslctxp = va_arg(param, void *);
  1880. else
  1881. #endif
  1882. result = CURLE_NOT_BUILT_IN;
  1883. break;
  1884. case CURLOPT_SSL_FALSESTART:
  1885. /*
  1886. * Enable TLS false start.
  1887. */
  1888. if(!Curl_ssl_false_start(data)) {
  1889. result = CURLE_NOT_BUILT_IN;
  1890. break;
  1891. }
  1892. data->set.ssl.falsestart = (0 != va_arg(param, long));
  1893. break;
  1894. case CURLOPT_CERTINFO:
  1895. #ifdef USE_SSL
  1896. if(Curl_ssl_supports(data, SSLSUPP_CERTINFO))
  1897. data->set.ssl.certinfo = (0 != va_arg(param, long));
  1898. else
  1899. #endif
  1900. result = CURLE_NOT_BUILT_IN;
  1901. break;
  1902. case CURLOPT_PINNEDPUBLICKEY:
  1903. /*
  1904. * Set pinned public key for SSL connection.
  1905. * Specify filename of the public key in DER format.
  1906. */
  1907. #ifdef USE_SSL
  1908. if(Curl_ssl_supports(data, SSLSUPP_PINNEDPUBKEY))
  1909. result = Curl_setstropt(&data->set.str[STRING_SSL_PINNEDPUBLICKEY],
  1910. va_arg(param, char *));
  1911. else
  1912. #endif
  1913. result = CURLE_NOT_BUILT_IN;
  1914. break;
  1915. #ifndef CURL_DISABLE_PROXY
  1916. case CURLOPT_PROXY_PINNEDPUBLICKEY:
  1917. /*
  1918. * Set pinned public key for SSL connection.
  1919. * Specify filename of the public key in DER format.
  1920. */
  1921. #ifdef USE_SSL
  1922. if(Curl_ssl_supports(data, SSLSUPP_PINNEDPUBKEY))
  1923. result = Curl_setstropt(&data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY],
  1924. va_arg(param, char *));
  1925. else
  1926. #endif
  1927. result = CURLE_NOT_BUILT_IN;
  1928. break;
  1929. #endif
  1930. case CURLOPT_CAINFO:
  1931. /*
  1932. * Set CA info for SSL connection. Specify filename of the CA certificate
  1933. */
  1934. result = Curl_setstropt(&data->set.str[STRING_SSL_CAFILE],
  1935. va_arg(param, char *));
  1936. break;
  1937. case CURLOPT_CAINFO_BLOB:
  1938. /*
  1939. * Blob that holds CA info for SSL connection.
  1940. * Specify entire PEM of the CA certificate
  1941. */
  1942. #ifdef USE_SSL
  1943. if(Curl_ssl_supports(data, SSLSUPP_CAINFO_BLOB)) {
  1944. result = Curl_setblobopt(&data->set.blobs[BLOB_CAINFO],
  1945. va_arg(param, struct curl_blob *));
  1946. break;
  1947. }
  1948. else
  1949. #endif
  1950. return CURLE_NOT_BUILT_IN;
  1951. #ifndef CURL_DISABLE_PROXY
  1952. case CURLOPT_PROXY_CAINFO:
  1953. /*
  1954. * Set CA info SSL connection for proxy. Specify filename of the
  1955. * CA certificate
  1956. */
  1957. result = Curl_setstropt(&data->set.str[STRING_SSL_CAFILE_PROXY],
  1958. va_arg(param, char *));
  1959. break;
  1960. case CURLOPT_PROXY_CAINFO_BLOB:
  1961. /*
  1962. * Blob that holds CA info for SSL connection proxy.
  1963. * Specify entire PEM of the CA certificate
  1964. */
  1965. #ifdef USE_SSL
  1966. if(Curl_ssl_supports(data, SSLSUPP_CAINFO_BLOB)) {
  1967. result = Curl_setblobopt(&data->set.blobs[BLOB_CAINFO_PROXY],
  1968. va_arg(param, struct curl_blob *));
  1969. break;
  1970. }
  1971. else
  1972. #endif
  1973. return CURLE_NOT_BUILT_IN;
  1974. #endif
  1975. case CURLOPT_CAPATH:
  1976. /*
  1977. * Set CA path info for SSL connection. Specify directory name of the CA
  1978. * certificates which have been prepared using openssl c_rehash utility.
  1979. */
  1980. #ifdef USE_SSL
  1981. if(Curl_ssl_supports(data, SSLSUPP_CA_PATH))
  1982. /* This does not work on Windows. */
  1983. result = Curl_setstropt(&data->set.str[STRING_SSL_CAPATH],
  1984. va_arg(param, char *));
  1985. else
  1986. #endif
  1987. result = CURLE_NOT_BUILT_IN;
  1988. break;
  1989. #ifndef CURL_DISABLE_PROXY
  1990. case CURLOPT_PROXY_CAPATH:
  1991. /*
  1992. * Set CA path info for SSL connection proxy. Specify directory name of the
  1993. * CA certificates which have been prepared using openssl c_rehash utility.
  1994. */
  1995. #ifdef USE_SSL
  1996. if(Curl_ssl_supports(data, SSLSUPP_CA_PATH))
  1997. /* This does not work on Windows. */
  1998. result = Curl_setstropt(&data->set.str[STRING_SSL_CAPATH_PROXY],
  1999. va_arg(param, char *));
  2000. else
  2001. #endif
  2002. result = CURLE_NOT_BUILT_IN;
  2003. break;
  2004. #endif
  2005. case CURLOPT_CRLFILE:
  2006. /*
  2007. * Set CRL file info for SSL connection. Specify filename of the CRL
  2008. * to check certificates revocation
  2009. */
  2010. result = Curl_setstropt(&data->set.str[STRING_SSL_CRLFILE],
  2011. va_arg(param, char *));
  2012. break;
  2013. #ifndef CURL_DISABLE_PROXY
  2014. case CURLOPT_PROXY_CRLFILE:
  2015. /*
  2016. * Set CRL file info for SSL connection for proxy. Specify filename of the
  2017. * CRL to check certificates revocation
  2018. */
  2019. result = Curl_setstropt(&data->set.str[STRING_SSL_CRLFILE_PROXY],
  2020. va_arg(param, char *));
  2021. break;
  2022. #endif
  2023. case CURLOPT_ISSUERCERT:
  2024. /*
  2025. * Set Issuer certificate file
  2026. * to check certificates issuer
  2027. */
  2028. result = Curl_setstropt(&data->set.str[STRING_SSL_ISSUERCERT],
  2029. va_arg(param, char *));
  2030. break;
  2031. case CURLOPT_ISSUERCERT_BLOB:
  2032. /*
  2033. * Blob that holds Issuer certificate to check certificates issuer
  2034. */
  2035. result = Curl_setblobopt(&data->set.blobs[BLOB_SSL_ISSUERCERT],
  2036. va_arg(param, struct curl_blob *));
  2037. break;
  2038. #ifndef CURL_DISABLE_PROXY
  2039. case CURLOPT_PROXY_ISSUERCERT:
  2040. /*
  2041. * Set Issuer certificate file
  2042. * to check certificates issuer
  2043. */
  2044. result = Curl_setstropt(&data->set.str[STRING_SSL_ISSUERCERT_PROXY],
  2045. va_arg(param, char *));
  2046. break;
  2047. case CURLOPT_PROXY_ISSUERCERT_BLOB:
  2048. /*
  2049. * Blob that holds Issuer certificate to check certificates issuer
  2050. */
  2051. result = Curl_setblobopt(&data->set.blobs[BLOB_SSL_ISSUERCERT_PROXY],
  2052. va_arg(param, struct curl_blob *));
  2053. break;
  2054. #endif
  2055. #ifndef CURL_DISABLE_TELNET
  2056. case CURLOPT_TELNETOPTIONS:
  2057. /*
  2058. * Set a linked list of telnet options
  2059. */
  2060. data->set.telnet_options = va_arg(param, struct curl_slist *);
  2061. break;
  2062. #endif
  2063. case CURLOPT_BUFFERSIZE:
  2064. /*
  2065. * The application kindly asks for a differently sized receive buffer.
  2066. * If it seems reasonable, we will use it.
  2067. */
  2068. arg = va_arg(param, long);
  2069. if(arg > READBUFFER_MAX)
  2070. arg = READBUFFER_MAX;
  2071. else if(arg < 1)
  2072. arg = READBUFFER_SIZE;
  2073. else if(arg < READBUFFER_MIN)
  2074. arg = READBUFFER_MIN;
  2075. data->set.buffer_size = (unsigned int)arg;
  2076. break;
  2077. case CURLOPT_UPLOAD_BUFFERSIZE:
  2078. /*
  2079. * The application kindly asks for a differently sized upload buffer.
  2080. * Cap it to sensible.
  2081. */
  2082. arg = va_arg(param, long);
  2083. if(arg > UPLOADBUFFER_MAX)
  2084. arg = UPLOADBUFFER_MAX;
  2085. else if(arg < UPLOADBUFFER_MIN)
  2086. arg = UPLOADBUFFER_MIN;
  2087. data->set.upload_buffer_size = (unsigned int)arg;
  2088. break;
  2089. case CURLOPT_NOSIGNAL:
  2090. /*
  2091. * The application asks not to set any signal() or alarm() handlers,
  2092. * even when using a timeout.
  2093. */
  2094. data->set.no_signal = (0 != va_arg(param, long));
  2095. break;
  2096. case CURLOPT_SHARE:
  2097. {
  2098. struct Curl_share *set;
  2099. set = va_arg(param, struct Curl_share *);
  2100. /* disconnect from old share, if any */
  2101. if(data->share) {
  2102. Curl_share_lock(data, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE);
  2103. if(data->dns.hostcachetype == HCACHE_SHARED) {
  2104. data->dns.hostcache = NULL;
  2105. data->dns.hostcachetype = HCACHE_NONE;
  2106. }
  2107. #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
  2108. if(data->share->cookies == data->cookies)
  2109. data->cookies = NULL;
  2110. #endif
  2111. #ifndef CURL_DISABLE_HSTS
  2112. if(data->share->hsts == data->hsts)
  2113. data->hsts = NULL;
  2114. #endif
  2115. #ifdef USE_SSL
  2116. if(data->share->sslsession == data->state.session)
  2117. data->state.session = NULL;
  2118. #endif
  2119. #ifdef USE_LIBPSL
  2120. if(data->psl == &data->share->psl)
  2121. data->psl = data->multi ? &data->multi->psl : NULL;
  2122. #endif
  2123. data->share->dirty--;
  2124. Curl_share_unlock(data, CURL_LOCK_DATA_SHARE);
  2125. data->share = NULL;
  2126. }
  2127. if(GOOD_SHARE_HANDLE(set))
  2128. /* use new share if it set */
  2129. data->share = set;
  2130. if(data->share) {
  2131. Curl_share_lock(data, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE);
  2132. data->share->dirty++;
  2133. if(data->share->specifier & (1 << CURL_LOCK_DATA_DNS)) {
  2134. /* use shared host cache */
  2135. data->dns.hostcache = &data->share->hostcache;
  2136. data->dns.hostcachetype = HCACHE_SHARED;
  2137. }
  2138. #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
  2139. if(data->share->cookies) {
  2140. /* use shared cookie list, first free own one if any */
  2141. Curl_cookie_cleanup(data->cookies);
  2142. /* enable cookies since we now use a share that uses cookies! */
  2143. data->cookies = data->share->cookies;
  2144. }
  2145. #endif /* CURL_DISABLE_HTTP */
  2146. #ifndef CURL_DISABLE_HSTS
  2147. if(data->share->hsts) {
  2148. /* first free the private one if any */
  2149. Curl_hsts_cleanup(&data->hsts);
  2150. data->hsts = data->share->hsts;
  2151. }
  2152. #endif
  2153. #ifdef USE_SSL
  2154. if(data->share->sslsession) {
  2155. data->set.general_ssl.max_ssl_sessions = data->share->max_ssl_sessions;
  2156. data->state.session = data->share->sslsession;
  2157. }
  2158. #endif
  2159. #ifdef USE_LIBPSL
  2160. if(data->share->specifier & (1 << CURL_LOCK_DATA_PSL))
  2161. data->psl = &data->share->psl;
  2162. #endif
  2163. Curl_share_unlock(data, CURL_LOCK_DATA_SHARE);
  2164. }
  2165. /* check for host cache not needed,
  2166. * it will be done by curl_easy_perform */
  2167. }
  2168. break;
  2169. case CURLOPT_PRIVATE:
  2170. /*
  2171. * Set private data pointer.
  2172. */
  2173. data->set.private_data = va_arg(param, void *);
  2174. break;
  2175. case CURLOPT_MAXFILESIZE:
  2176. /*
  2177. * Set the maximum size of a file to download.
  2178. */
  2179. arg = va_arg(param, long);
  2180. if(arg < 0)
  2181. return CURLE_BAD_FUNCTION_ARGUMENT;
  2182. data->set.max_filesize = arg;
  2183. break;
  2184. #ifdef USE_SSL
  2185. case CURLOPT_USE_SSL:
  2186. /*
  2187. * Make transfers attempt to use SSL/TLS.
  2188. */
  2189. arg = va_arg(param, long);
  2190. if((arg < CURLUSESSL_NONE) || (arg >= CURLUSESSL_LAST))
  2191. return CURLE_BAD_FUNCTION_ARGUMENT;
  2192. data->set.use_ssl = (unsigned char)arg;
  2193. break;
  2194. case CURLOPT_SSL_OPTIONS:
  2195. arg = va_arg(param, long);
  2196. data->set.ssl.primary.ssl_options = (unsigned char)(arg & 0xff);
  2197. data->set.ssl.enable_beast = !!(arg & CURLSSLOPT_ALLOW_BEAST);
  2198. data->set.ssl.no_revoke = !!(arg & CURLSSLOPT_NO_REVOKE);
  2199. data->set.ssl.no_partialchain = !!(arg & CURLSSLOPT_NO_PARTIALCHAIN);
  2200. data->set.ssl.revoke_best_effort = !!(arg & CURLSSLOPT_REVOKE_BEST_EFFORT);
  2201. data->set.ssl.native_ca_store = !!(arg & CURLSSLOPT_NATIVE_CA);
  2202. data->set.ssl.auto_client_cert = !!(arg & CURLSSLOPT_AUTO_CLIENT_CERT);
  2203. data->set.ssl.earlydata = !!(arg & CURLSSLOPT_EARLYDATA);
  2204. /* If a setting is added here it should also be added in dohprobe()
  2205. which sets its own CURLOPT_SSL_OPTIONS based on these settings. */
  2206. break;
  2207. #ifndef CURL_DISABLE_PROXY
  2208. case CURLOPT_PROXY_SSL_OPTIONS:
  2209. arg = va_arg(param, long);
  2210. data->set.proxy_ssl.primary.ssl_options = (unsigned char)(arg & 0xff);
  2211. data->set.proxy_ssl.enable_beast = !!(arg & CURLSSLOPT_ALLOW_BEAST);
  2212. data->set.proxy_ssl.no_revoke = !!(arg & CURLSSLOPT_NO_REVOKE);
  2213. data->set.proxy_ssl.no_partialchain = !!(arg & CURLSSLOPT_NO_PARTIALCHAIN);
  2214. data->set.proxy_ssl.revoke_best_effort =
  2215. !!(arg & CURLSSLOPT_REVOKE_BEST_EFFORT);
  2216. data->set.proxy_ssl.native_ca_store = !!(arg & CURLSSLOPT_NATIVE_CA);
  2217. data->set.proxy_ssl.auto_client_cert =
  2218. !!(arg & CURLSSLOPT_AUTO_CLIENT_CERT);
  2219. break;
  2220. #endif
  2221. case CURLOPT_SSL_EC_CURVES:
  2222. /*
  2223. * Set accepted curves in SSL connection setup.
  2224. * Specify colon-delimited list of curve algorithm names.
  2225. */
  2226. result = Curl_setstropt(&data->set.str[STRING_SSL_EC_CURVES],
  2227. va_arg(param, char *));
  2228. break;
  2229. #endif
  2230. case CURLOPT_IPRESOLVE:
  2231. arg = va_arg(param, long);
  2232. if((arg < CURL_IPRESOLVE_WHATEVER) || (arg > CURL_IPRESOLVE_V6))
  2233. return CURLE_BAD_FUNCTION_ARGUMENT;
  2234. data->set.ipver = (unsigned char) arg;
  2235. break;
  2236. case CURLOPT_MAXFILESIZE_LARGE:
  2237. /*
  2238. * Set the maximum size of a file to download.
  2239. */
  2240. bigsize = va_arg(param, curl_off_t);
  2241. if(bigsize < 0)
  2242. return CURLE_BAD_FUNCTION_ARGUMENT;
  2243. data->set.max_filesize = bigsize;
  2244. break;
  2245. case CURLOPT_TCP_NODELAY:
  2246. /*
  2247. * Enable or disable TCP_NODELAY, which will disable/enable the Nagle
  2248. * algorithm
  2249. */
  2250. data->set.tcp_nodelay = (0 != va_arg(param, long));
  2251. break;
  2252. case CURLOPT_IGNORE_CONTENT_LENGTH:
  2253. data->set.ignorecl = (0 != va_arg(param, long));
  2254. break;
  2255. case CURLOPT_CONNECT_ONLY:
  2256. /*
  2257. * No data transfer.
  2258. * (1) - only do connection
  2259. * (2) - do first get request but get no content
  2260. */
  2261. arg = va_arg(param, long);
  2262. if(arg > 2)
  2263. return CURLE_BAD_FUNCTION_ARGUMENT;
  2264. data->set.connect_only = (unsigned char)arg;
  2265. break;
  2266. case CURLOPT_SOCKOPTFUNCTION:
  2267. /*
  2268. * socket callback function: called after socket() but before connect()
  2269. */
  2270. data->set.fsockopt = va_arg(param, curl_sockopt_callback);
  2271. break;
  2272. case CURLOPT_SOCKOPTDATA:
  2273. /*
  2274. * socket callback data pointer. Might be NULL.
  2275. */
  2276. data->set.sockopt_client = va_arg(param, void *);
  2277. break;
  2278. case CURLOPT_OPENSOCKETFUNCTION:
  2279. /*
  2280. * open/create socket callback function: called instead of socket(),
  2281. * before connect()
  2282. */
  2283. data->set.fopensocket = va_arg(param, curl_opensocket_callback);
  2284. break;
  2285. case CURLOPT_OPENSOCKETDATA:
  2286. /*
  2287. * socket callback data pointer. Might be NULL.
  2288. */
  2289. data->set.opensocket_client = va_arg(param, void *);
  2290. break;
  2291. case CURLOPT_CLOSESOCKETFUNCTION:
  2292. /*
  2293. * close socket callback function: called instead of close()
  2294. * when shutting down a connection
  2295. */
  2296. data->set.fclosesocket = va_arg(param, curl_closesocket_callback);
  2297. break;
  2298. case CURLOPT_RESOLVER_START_FUNCTION:
  2299. /*
  2300. * resolver start callback function: called before a new resolver request
  2301. * is started
  2302. */
  2303. data->set.resolver_start = va_arg(param, curl_resolver_start_callback);
  2304. break;
  2305. case CURLOPT_RESOLVER_START_DATA:
  2306. /*
  2307. * resolver start callback data pointer. Might be NULL.
  2308. */
  2309. data->set.resolver_start_client = va_arg(param, void *);
  2310. break;
  2311. case CURLOPT_CLOSESOCKETDATA:
  2312. /*
  2313. * socket callback data pointer. Might be NULL.
  2314. */
  2315. data->set.closesocket_client = va_arg(param, void *);
  2316. break;
  2317. case CURLOPT_SSL_SESSIONID_CACHE:
  2318. data->set.ssl.primary.cache_session = (0 != va_arg(param, long));
  2319. #ifndef CURL_DISABLE_PROXY
  2320. data->set.proxy_ssl.primary.cache_session =
  2321. data->set.ssl.primary.cache_session;
  2322. #endif
  2323. break;
  2324. #ifdef USE_SSH
  2325. /* we only include SSH options if explicitly built to support SSH */
  2326. case CURLOPT_SSH_AUTH_TYPES:
  2327. data->set.ssh_auth_types = (int)va_arg(param, long);
  2328. break;
  2329. case CURLOPT_SSH_PUBLIC_KEYFILE:
  2330. /*
  2331. * Use this file instead of the $HOME/.ssh/id_dsa.pub file
  2332. */
  2333. result = Curl_setstropt(&data->set.str[STRING_SSH_PUBLIC_KEY],
  2334. va_arg(param, char *));
  2335. break;
  2336. case CURLOPT_SSH_PRIVATE_KEYFILE:
  2337. /*
  2338. * Use this file instead of the $HOME/.ssh/id_dsa file
  2339. */
  2340. result = Curl_setstropt(&data->set.str[STRING_SSH_PRIVATE_KEY],
  2341. va_arg(param, char *));
  2342. break;
  2343. case CURLOPT_SSH_HOST_PUBLIC_KEY_MD5:
  2344. /*
  2345. * Option to allow for the MD5 of the host public key to be checked
  2346. * for validation purposes.
  2347. */
  2348. result = Curl_setstropt(&data->set.str[STRING_SSH_HOST_PUBLIC_KEY_MD5],
  2349. va_arg(param, char *));
  2350. break;
  2351. case CURLOPT_SSH_KNOWNHOSTS:
  2352. /*
  2353. * Store the filename to read known hosts from.
  2354. */
  2355. result = Curl_setstropt(&data->set.str[STRING_SSH_KNOWNHOSTS],
  2356. va_arg(param, char *));
  2357. break;
  2358. #ifdef USE_LIBSSH2
  2359. case CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256:
  2360. /*
  2361. * Option to allow for the SHA256 of the host public key to be checked
  2362. * for validation purposes.
  2363. */
  2364. result = Curl_setstropt(&data->set.str[STRING_SSH_HOST_PUBLIC_KEY_SHA256],
  2365. va_arg(param, char *));
  2366. break;
  2367. case CURLOPT_SSH_HOSTKEYFUNCTION:
  2368. /* the callback to check the hostkey without the knownhost file */
  2369. data->set.ssh_hostkeyfunc = va_arg(param, curl_sshhostkeycallback);
  2370. break;
  2371. case CURLOPT_SSH_HOSTKEYDATA:
  2372. /*
  2373. * Custom client data to pass to the SSH keyfunc callback
  2374. */
  2375. data->set.ssh_hostkeyfunc_userp = va_arg(param, void *);
  2376. break;
  2377. #endif
  2378. case CURLOPT_SSH_KEYFUNCTION:
  2379. /* setting to NULL is fine since the ssh.c functions themselves will
  2380. then revert to use the internal default */
  2381. data->set.ssh_keyfunc = va_arg(param, curl_sshkeycallback);
  2382. break;
  2383. case CURLOPT_SSH_KEYDATA:
  2384. /*
  2385. * Custom client data to pass to the SSH keyfunc callback
  2386. */
  2387. data->set.ssh_keyfunc_userp = va_arg(param, void *);
  2388. break;
  2389. case CURLOPT_SSH_COMPRESSION:
  2390. data->set.ssh_compression = (0 != va_arg(param, long));
  2391. break;
  2392. #endif /* USE_SSH */
  2393. case CURLOPT_HTTP_TRANSFER_DECODING:
  2394. /*
  2395. * disable libcurl transfer encoding is used
  2396. */
  2397. #ifndef USE_HYPER
  2398. data->set.http_te_skip = (0 == va_arg(param, long));
  2399. break;
  2400. #else
  2401. return CURLE_NOT_BUILT_IN; /* hyper does not support */
  2402. #endif
  2403. case CURLOPT_HTTP_CONTENT_DECODING:
  2404. /*
  2405. * raw data passed to the application when content encoding is used
  2406. */
  2407. data->set.http_ce_skip = (0 == va_arg(param, long));
  2408. break;
  2409. #if !defined(CURL_DISABLE_FTP) || defined(USE_SSH)
  2410. case CURLOPT_NEW_FILE_PERMS:
  2411. /*
  2412. * Uses these permissions instead of 0644
  2413. */
  2414. arg = va_arg(param, long);
  2415. if((arg < 0) || (arg > 0777))
  2416. return CURLE_BAD_FUNCTION_ARGUMENT;
  2417. data->set.new_file_perms = (unsigned int)arg;
  2418. break;
  2419. #endif
  2420. #ifdef USE_SSH
  2421. case CURLOPT_NEW_DIRECTORY_PERMS:
  2422. /*
  2423. * Uses these permissions instead of 0755
  2424. */
  2425. arg = va_arg(param, long);
  2426. if((arg < 0) || (arg > 0777))
  2427. return CURLE_BAD_FUNCTION_ARGUMENT;
  2428. data->set.new_directory_perms = (unsigned int)arg;
  2429. break;
  2430. #endif
  2431. #ifdef USE_IPV6
  2432. case CURLOPT_ADDRESS_SCOPE:
  2433. /*
  2434. * Use this scope id when using IPv6
  2435. * We always get longs when passed plain numericals so we should check
  2436. * that the value fits into an unsigned 32-bit integer.
  2437. */
  2438. uarg = va_arg(param, unsigned long);
  2439. #if SIZEOF_LONG > 4
  2440. if(uarg > UINT_MAX)
  2441. return CURLE_BAD_FUNCTION_ARGUMENT;
  2442. #endif
  2443. data->set.scope_id = (unsigned int)uarg;
  2444. break;
  2445. #endif
  2446. case CURLOPT_PROTOCOLS:
  2447. /* set the bitmask for the protocols that are allowed to be used for the
  2448. transfer, which thus helps the app which takes URLs from users or other
  2449. external inputs and want to restrict what protocol(s) to deal
  2450. with. Defaults to CURLPROTO_ALL. */
  2451. data->set.allowed_protocols = (curl_prot_t)va_arg(param, long);
  2452. break;
  2453. case CURLOPT_REDIR_PROTOCOLS:
  2454. /* set the bitmask for the protocols that libcurl is allowed to follow to,
  2455. as a subset of the CURLOPT_PROTOCOLS ones. That means the protocol needs
  2456. to be set in both bitmasks to be allowed to get redirected to. */
  2457. data->set.redir_protocols = (curl_prot_t)va_arg(param, long);
  2458. break;
  2459. case CURLOPT_PROTOCOLS_STR: {
  2460. argptr = va_arg(param, char *);
  2461. if(argptr) {
  2462. result = protocol2num(argptr, &data->set.allowed_protocols);
  2463. if(result)
  2464. return result;
  2465. }
  2466. else
  2467. /* make a NULL argument reset to default */
  2468. data->set.allowed_protocols = (curl_prot_t) CURLPROTO_ALL;
  2469. break;
  2470. }
  2471. case CURLOPT_REDIR_PROTOCOLS_STR: {
  2472. argptr = va_arg(param, char *);
  2473. if(argptr) {
  2474. result = protocol2num(argptr, &data->set.redir_protocols);
  2475. if(result)
  2476. return result;
  2477. }
  2478. else
  2479. /* make a NULL argument reset to default */
  2480. data->set.redir_protocols = (curl_prot_t) CURLPROTO_REDIR;
  2481. break;
  2482. }
  2483. case CURLOPT_DEFAULT_PROTOCOL:
  2484. /* Set the protocol to use when the URL does not include any protocol */
  2485. result = Curl_setstropt(&data->set.str[STRING_DEFAULT_PROTOCOL],
  2486. va_arg(param, char *));
  2487. break;
  2488. #ifndef CURL_DISABLE_SMTP
  2489. case CURLOPT_MAIL_FROM:
  2490. /* Set the SMTP mail originator */
  2491. result = Curl_setstropt(&data->set.str[STRING_MAIL_FROM],
  2492. va_arg(param, char *));
  2493. break;
  2494. case CURLOPT_MAIL_AUTH:
  2495. /* Set the SMTP auth originator */
  2496. result = Curl_setstropt(&data->set.str[STRING_MAIL_AUTH],
  2497. va_arg(param, char *));
  2498. break;
  2499. case CURLOPT_MAIL_RCPT:
  2500. /* Set the list of mail recipients */
  2501. data->set.mail_rcpt = va_arg(param, struct curl_slist *);
  2502. break;
  2503. case CURLOPT_MAIL_RCPT_ALLOWFAILS:
  2504. /* allow RCPT TO command to fail for some recipients */
  2505. data->set.mail_rcpt_allowfails = (0 != va_arg(param, long));
  2506. break;
  2507. #endif
  2508. case CURLOPT_SASL_AUTHZID:
  2509. /* Authorization identity (identity to act as) */
  2510. result = Curl_setstropt(&data->set.str[STRING_SASL_AUTHZID],
  2511. va_arg(param, char *));
  2512. break;
  2513. case CURLOPT_SASL_IR:
  2514. /* Enable/disable SASL initial response */
  2515. data->set.sasl_ir = (0 != va_arg(param, long));
  2516. break;
  2517. #ifndef CURL_DISABLE_RTSP
  2518. case CURLOPT_RTSP_REQUEST:
  2519. {
  2520. /*
  2521. * Set the RTSP request method (OPTIONS, SETUP, PLAY, etc...)
  2522. * Would this be better if the RTSPREQ_* were just moved into here?
  2523. */
  2524. long in_rtspreq = va_arg(param, long);
  2525. Curl_RtspReq rtspreq = RTSPREQ_NONE;
  2526. switch(in_rtspreq) {
  2527. case CURL_RTSPREQ_OPTIONS:
  2528. rtspreq = RTSPREQ_OPTIONS;
  2529. break;
  2530. case CURL_RTSPREQ_DESCRIBE:
  2531. rtspreq = RTSPREQ_DESCRIBE;
  2532. break;
  2533. case CURL_RTSPREQ_ANNOUNCE:
  2534. rtspreq = RTSPREQ_ANNOUNCE;
  2535. break;
  2536. case CURL_RTSPREQ_SETUP:
  2537. rtspreq = RTSPREQ_SETUP;
  2538. break;
  2539. case CURL_RTSPREQ_PLAY:
  2540. rtspreq = RTSPREQ_PLAY;
  2541. break;
  2542. case CURL_RTSPREQ_PAUSE:
  2543. rtspreq = RTSPREQ_PAUSE;
  2544. break;
  2545. case CURL_RTSPREQ_TEARDOWN:
  2546. rtspreq = RTSPREQ_TEARDOWN;
  2547. break;
  2548. case CURL_RTSPREQ_GET_PARAMETER:
  2549. rtspreq = RTSPREQ_GET_PARAMETER;
  2550. break;
  2551. case CURL_RTSPREQ_SET_PARAMETER:
  2552. rtspreq = RTSPREQ_SET_PARAMETER;
  2553. break;
  2554. case CURL_RTSPREQ_RECORD:
  2555. rtspreq = RTSPREQ_RECORD;
  2556. break;
  2557. case CURL_RTSPREQ_RECEIVE:
  2558. rtspreq = RTSPREQ_RECEIVE;
  2559. break;
  2560. default:
  2561. rtspreq = RTSPREQ_NONE;
  2562. }
  2563. data->set.rtspreq = rtspreq;
  2564. break;
  2565. }
  2566. case CURLOPT_RTSP_SESSION_ID:
  2567. /*
  2568. * Set the RTSP Session ID manually. Useful if the application is
  2569. * resuming a previously established RTSP session
  2570. */
  2571. result = Curl_setstropt(&data->set.str[STRING_RTSP_SESSION_ID],
  2572. va_arg(param, char *));
  2573. break;
  2574. case CURLOPT_RTSP_STREAM_URI:
  2575. /*
  2576. * Set the Stream URI for the RTSP request. Unless the request is
  2577. * for generic server options, the application will need to set this.
  2578. */
  2579. result = Curl_setstropt(&data->set.str[STRING_RTSP_STREAM_URI],
  2580. va_arg(param, char *));
  2581. break;
  2582. case CURLOPT_RTSP_TRANSPORT:
  2583. /*
  2584. * The content of the Transport: header for the RTSP request
  2585. */
  2586. result = Curl_setstropt(&data->set.str[STRING_RTSP_TRANSPORT],
  2587. va_arg(param, char *));
  2588. break;
  2589. case CURLOPT_RTSP_CLIENT_CSEQ:
  2590. /*
  2591. * Set the CSEQ number to issue for the next RTSP request. Useful if the
  2592. * application is resuming a previously broken connection. The CSEQ
  2593. * will increment from this new number henceforth.
  2594. */
  2595. data->state.rtsp_next_client_CSeq = va_arg(param, long);
  2596. break;
  2597. case CURLOPT_RTSP_SERVER_CSEQ:
  2598. /* Same as the above, but for server-initiated requests */
  2599. data->state.rtsp_next_server_CSeq = va_arg(param, long);
  2600. break;
  2601. case CURLOPT_INTERLEAVEDATA:
  2602. data->set.rtp_out = va_arg(param, void *);
  2603. break;
  2604. case CURLOPT_INTERLEAVEFUNCTION:
  2605. /* Set the user defined RTP write function */
  2606. data->set.fwrite_rtp = va_arg(param, curl_write_callback);
  2607. break;
  2608. #endif
  2609. #ifndef CURL_DISABLE_FTP
  2610. case CURLOPT_WILDCARDMATCH:
  2611. data->set.wildcard_enabled = (0 != va_arg(param, long));
  2612. break;
  2613. case CURLOPT_CHUNK_BGN_FUNCTION:
  2614. data->set.chunk_bgn = va_arg(param, curl_chunk_bgn_callback);
  2615. break;
  2616. case CURLOPT_CHUNK_END_FUNCTION:
  2617. data->set.chunk_end = va_arg(param, curl_chunk_end_callback);
  2618. break;
  2619. case CURLOPT_FNMATCH_FUNCTION:
  2620. data->set.fnmatch = va_arg(param, curl_fnmatch_callback);
  2621. break;
  2622. case CURLOPT_CHUNK_DATA:
  2623. data->set.wildcardptr = va_arg(param, void *);
  2624. break;
  2625. case CURLOPT_FNMATCH_DATA:
  2626. data->set.fnmatch_data = va_arg(param, void *);
  2627. break;
  2628. #endif
  2629. #ifdef USE_TLS_SRP
  2630. case CURLOPT_TLSAUTH_USERNAME:
  2631. result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_USERNAME],
  2632. va_arg(param, char *));
  2633. break;
  2634. #ifndef CURL_DISABLE_PROXY
  2635. case CURLOPT_PROXY_TLSAUTH_USERNAME:
  2636. result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_USERNAME_PROXY],
  2637. va_arg(param, char *));
  2638. break;
  2639. #endif
  2640. case CURLOPT_TLSAUTH_PASSWORD:
  2641. result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_PASSWORD],
  2642. va_arg(param, char *));
  2643. break;
  2644. #ifndef CURL_DISABLE_PROXY
  2645. case CURLOPT_PROXY_TLSAUTH_PASSWORD:
  2646. result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_PASSWORD_PROXY],
  2647. va_arg(param, char *));
  2648. break;
  2649. #endif
  2650. case CURLOPT_TLSAUTH_TYPE:
  2651. argptr = va_arg(param, char *);
  2652. if(argptr && !strcasecompare(argptr, "SRP"))
  2653. return CURLE_BAD_FUNCTION_ARGUMENT;
  2654. break;
  2655. #ifndef CURL_DISABLE_PROXY
  2656. case CURLOPT_PROXY_TLSAUTH_TYPE:
  2657. argptr = va_arg(param, char *);
  2658. if(argptr && !strcasecompare(argptr, "SRP"))
  2659. return CURLE_BAD_FUNCTION_ARGUMENT;
  2660. break;
  2661. #endif
  2662. #endif
  2663. #ifdef USE_ARES
  2664. case CURLOPT_DNS_SERVERS:
  2665. result = Curl_setstropt(&data->set.str[STRING_DNS_SERVERS],
  2666. va_arg(param, char *));
  2667. if(result)
  2668. return result;
  2669. result = Curl_set_dns_servers(data, data->set.str[STRING_DNS_SERVERS]);
  2670. break;
  2671. case CURLOPT_DNS_INTERFACE:
  2672. result = Curl_setstropt(&data->set.str[STRING_DNS_INTERFACE],
  2673. va_arg(param, char *));
  2674. if(result)
  2675. return result;
  2676. result = Curl_set_dns_interface(data, data->set.str[STRING_DNS_INTERFACE]);
  2677. break;
  2678. case CURLOPT_DNS_LOCAL_IP4:
  2679. result = Curl_setstropt(&data->set.str[STRING_DNS_LOCAL_IP4],
  2680. va_arg(param, char *));
  2681. if(result)
  2682. return result;
  2683. result = Curl_set_dns_local_ip4(data, data->set.str[STRING_DNS_LOCAL_IP4]);
  2684. break;
  2685. case CURLOPT_DNS_LOCAL_IP6:
  2686. result = Curl_setstropt(&data->set.str[STRING_DNS_LOCAL_IP6],
  2687. va_arg(param, char *));
  2688. if(result)
  2689. return result;
  2690. result = Curl_set_dns_local_ip6(data, data->set.str[STRING_DNS_LOCAL_IP6]);
  2691. break;
  2692. #endif
  2693. case CURLOPT_TCP_KEEPALIVE:
  2694. data->set.tcp_keepalive = (0 != va_arg(param, long));
  2695. break;
  2696. case CURLOPT_TCP_KEEPIDLE:
  2697. arg = va_arg(param, long);
  2698. if(arg < 0)
  2699. return CURLE_BAD_FUNCTION_ARGUMENT;
  2700. else if(arg > INT_MAX)
  2701. arg = INT_MAX;
  2702. data->set.tcp_keepidle = (int)arg;
  2703. break;
  2704. case CURLOPT_TCP_KEEPINTVL:
  2705. arg = va_arg(param, long);
  2706. if(arg < 0)
  2707. return CURLE_BAD_FUNCTION_ARGUMENT;
  2708. else if(arg > INT_MAX)
  2709. arg = INT_MAX;
  2710. data->set.tcp_keepintvl = (int)arg;
  2711. break;
  2712. case CURLOPT_TCP_KEEPCNT:
  2713. arg = va_arg(param, long);
  2714. if(arg < 0)
  2715. return CURLE_BAD_FUNCTION_ARGUMENT;
  2716. else if(arg > INT_MAX)
  2717. arg = INT_MAX;
  2718. data->set.tcp_keepcnt = (int)arg;
  2719. break;
  2720. case CURLOPT_TCP_FASTOPEN:
  2721. #if defined(CONNECT_DATA_IDEMPOTENT) || defined(MSG_FASTOPEN) || \
  2722. defined(TCP_FASTOPEN_CONNECT)
  2723. data->set.tcp_fastopen = (0 != va_arg(param, long));
  2724. #else
  2725. result = CURLE_NOT_BUILT_IN;
  2726. #endif
  2727. break;
  2728. case CURLOPT_SSL_ENABLE_NPN:
  2729. break;
  2730. case CURLOPT_SSL_ENABLE_ALPN:
  2731. data->set.ssl_enable_alpn = (0 != va_arg(param, long));
  2732. break;
  2733. #ifdef USE_UNIX_SOCKETS
  2734. case CURLOPT_UNIX_SOCKET_PATH:
  2735. data->set.abstract_unix_socket = FALSE;
  2736. result = Curl_setstropt(&data->set.str[STRING_UNIX_SOCKET_PATH],
  2737. va_arg(param, char *));
  2738. break;
  2739. case CURLOPT_ABSTRACT_UNIX_SOCKET:
  2740. data->set.abstract_unix_socket = TRUE;
  2741. result = Curl_setstropt(&data->set.str[STRING_UNIX_SOCKET_PATH],
  2742. va_arg(param, char *));
  2743. break;
  2744. #endif
  2745. case CURLOPT_PATH_AS_IS:
  2746. data->set.path_as_is = (0 != va_arg(param, long));
  2747. break;
  2748. case CURLOPT_PIPEWAIT:
  2749. data->set.pipewait = (0 != va_arg(param, long));
  2750. break;
  2751. case CURLOPT_STREAM_WEIGHT:
  2752. #if defined(USE_HTTP2) || defined(USE_HTTP3)
  2753. arg = va_arg(param, long);
  2754. if((arg >= 1) && (arg <= 256))
  2755. data->set.priority.weight = (int)arg;
  2756. break;
  2757. #else
  2758. return CURLE_NOT_BUILT_IN;
  2759. #endif
  2760. case CURLOPT_STREAM_DEPENDS:
  2761. case CURLOPT_STREAM_DEPENDS_E:
  2762. {
  2763. struct Curl_easy *dep = va_arg(param, struct Curl_easy *);
  2764. if(!dep || GOOD_EASY_HANDLE(dep)) {
  2765. return Curl_data_priority_add_child(dep, data,
  2766. option == CURLOPT_STREAM_DEPENDS_E);
  2767. }
  2768. break;
  2769. }
  2770. case CURLOPT_CONNECT_TO:
  2771. data->set.connect_to = va_arg(param, struct curl_slist *);
  2772. break;
  2773. case CURLOPT_SUPPRESS_CONNECT_HEADERS:
  2774. data->set.suppress_connect_headers = (0 != va_arg(param, long));
  2775. break;
  2776. case CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS:
  2777. uarg = va_arg(param, unsigned long);
  2778. if(uarg > UINT_MAX)
  2779. uarg = UINT_MAX;
  2780. data->set.happy_eyeballs_timeout = (unsigned int)uarg;
  2781. break;
  2782. #ifndef CURL_DISABLE_SHUFFLE_DNS
  2783. case CURLOPT_DNS_SHUFFLE_ADDRESSES:
  2784. data->set.dns_shuffle_addresses = (0 != va_arg(param, long));
  2785. break;
  2786. #endif
  2787. case CURLOPT_DISALLOW_USERNAME_IN_URL:
  2788. data->set.disallow_username_in_url = (0 != va_arg(param, long));
  2789. break;
  2790. #ifndef CURL_DISABLE_DOH
  2791. case CURLOPT_DOH_URL:
  2792. result = Curl_setstropt(&data->set.str[STRING_DOH],
  2793. va_arg(param, char *));
  2794. data->set.doh = !!(data->set.str[STRING_DOH]);
  2795. break;
  2796. #endif
  2797. case CURLOPT_UPKEEP_INTERVAL_MS:
  2798. arg = va_arg(param, long);
  2799. if(arg < 0)
  2800. return CURLE_BAD_FUNCTION_ARGUMENT;
  2801. data->set.upkeep_interval_ms = arg;
  2802. break;
  2803. case CURLOPT_MAXAGE_CONN:
  2804. arg = va_arg(param, long);
  2805. if(arg < 0)
  2806. return CURLE_BAD_FUNCTION_ARGUMENT;
  2807. data->set.maxage_conn = arg;
  2808. break;
  2809. case CURLOPT_MAXLIFETIME_CONN:
  2810. arg = va_arg(param, long);
  2811. if(arg < 0)
  2812. return CURLE_BAD_FUNCTION_ARGUMENT;
  2813. data->set.maxlifetime_conn = arg;
  2814. break;
  2815. case CURLOPT_TRAILERFUNCTION:
  2816. #ifndef CURL_DISABLE_HTTP
  2817. data->set.trailer_callback = va_arg(param, curl_trailer_callback);
  2818. #endif
  2819. break;
  2820. case CURLOPT_TRAILERDATA:
  2821. #ifndef CURL_DISABLE_HTTP
  2822. data->set.trailer_data = va_arg(param, void *);
  2823. #endif
  2824. break;
  2825. #ifndef CURL_DISABLE_HSTS
  2826. case CURLOPT_HSTSREADFUNCTION:
  2827. data->set.hsts_read = va_arg(param, curl_hstsread_callback);
  2828. break;
  2829. case CURLOPT_HSTSREADDATA:
  2830. data->set.hsts_read_userp = va_arg(param, void *);
  2831. break;
  2832. case CURLOPT_HSTSWRITEFUNCTION:
  2833. data->set.hsts_write = va_arg(param, curl_hstswrite_callback);
  2834. break;
  2835. case CURLOPT_HSTSWRITEDATA:
  2836. data->set.hsts_write_userp = va_arg(param, void *);
  2837. break;
  2838. case CURLOPT_HSTS: {
  2839. struct curl_slist *h;
  2840. if(!data->hsts) {
  2841. data->hsts = Curl_hsts_init();
  2842. if(!data->hsts)
  2843. return CURLE_OUT_OF_MEMORY;
  2844. }
  2845. argptr = va_arg(param, char *);
  2846. if(argptr) {
  2847. result = Curl_setstropt(&data->set.str[STRING_HSTS], argptr);
  2848. if(result)
  2849. return result;
  2850. /* this needs to build a list of filenames to read from, so that it can
  2851. read them later, as we might get a shared HSTS handle to load them
  2852. into */
  2853. h = curl_slist_append(data->state.hstslist, argptr);
  2854. if(!h) {
  2855. curl_slist_free_all(data->state.hstslist);
  2856. data->state.hstslist = NULL;
  2857. return CURLE_OUT_OF_MEMORY;
  2858. }
  2859. data->state.hstslist = h; /* store the list for later use */
  2860. }
  2861. else {
  2862. /* clear the list of HSTS files */
  2863. curl_slist_free_all(data->state.hstslist);
  2864. data->state.hstslist = NULL;
  2865. if(!data->share || !data->share->hsts)
  2866. /* throw away the HSTS cache unless shared */
  2867. Curl_hsts_cleanup(&data->hsts);
  2868. }
  2869. break;
  2870. }
  2871. case CURLOPT_HSTS_CTRL:
  2872. arg = va_arg(param, long);
  2873. if(arg & CURLHSTS_ENABLE) {
  2874. if(!data->hsts) {
  2875. data->hsts = Curl_hsts_init();
  2876. if(!data->hsts)
  2877. return CURLE_OUT_OF_MEMORY;
  2878. }
  2879. }
  2880. else
  2881. Curl_hsts_cleanup(&data->hsts);
  2882. break;
  2883. #endif
  2884. #ifndef CURL_DISABLE_ALTSVC
  2885. case CURLOPT_ALTSVC:
  2886. if(!data->asi) {
  2887. data->asi = Curl_altsvc_init();
  2888. if(!data->asi)
  2889. return CURLE_OUT_OF_MEMORY;
  2890. }
  2891. argptr = va_arg(param, char *);
  2892. result = Curl_setstropt(&data->set.str[STRING_ALTSVC], argptr);
  2893. if(result)
  2894. return result;
  2895. if(argptr)
  2896. (void)Curl_altsvc_load(data->asi, argptr);
  2897. break;
  2898. case CURLOPT_ALTSVC_CTRL:
  2899. if(!data->asi) {
  2900. data->asi = Curl_altsvc_init();
  2901. if(!data->asi)
  2902. return CURLE_OUT_OF_MEMORY;
  2903. }
  2904. arg = va_arg(param, long);
  2905. if(!arg) {
  2906. DEBUGF(infof(data, "bad CURLOPT_ALTSVC_CTRL input"));
  2907. return CURLE_BAD_FUNCTION_ARGUMENT;
  2908. }
  2909. result = Curl_altsvc_ctrl(data->asi, arg);
  2910. if(result)
  2911. return result;
  2912. break;
  2913. #endif
  2914. case CURLOPT_PREREQFUNCTION:
  2915. data->set.fprereq = va_arg(param, curl_prereq_callback);
  2916. break;
  2917. case CURLOPT_PREREQDATA:
  2918. data->set.prereq_userp = va_arg(param, void *);
  2919. break;
  2920. #ifndef CURL_DISABLE_WEBSOCKETS
  2921. case CURLOPT_WS_OPTIONS: {
  2922. bool raw;
  2923. arg = va_arg(param, long);
  2924. raw = (arg & CURLWS_RAW_MODE);
  2925. data->set.ws_raw_mode = raw;
  2926. break;
  2927. }
  2928. #endif
  2929. #ifdef USE_ECH
  2930. case CURLOPT_ECH: {
  2931. size_t plen = 0;
  2932. argptr = va_arg(param, char *);
  2933. if(!argptr) {
  2934. data->set.tls_ech = CURLECH_DISABLE;
  2935. return CURLE_OK;
  2936. }
  2937. plen = strlen(argptr);
  2938. if(plen > CURL_MAX_INPUT_LENGTH) {
  2939. data->set.tls_ech = CURLECH_DISABLE;
  2940. return CURLE_BAD_FUNCTION_ARGUMENT;
  2941. }
  2942. /* set tls_ech flag value, preserving CLA_CFG bit */
  2943. if(!strcmp(argptr, "false"))
  2944. data->set.tls_ech = CURLECH_DISABLE |
  2945. (data->set.tls_ech & CURLECH_CLA_CFG);
  2946. else if(!strcmp(argptr, "grease"))
  2947. data->set.tls_ech = CURLECH_GREASE |
  2948. (data->set.tls_ech & CURLECH_CLA_CFG);
  2949. else if(!strcmp(argptr, "true"))
  2950. data->set.tls_ech = CURLECH_ENABLE |
  2951. (data->set.tls_ech & CURLECH_CLA_CFG);
  2952. else if(!strcmp(argptr, "hard"))
  2953. data->set.tls_ech = CURLECH_HARD |
  2954. (data->set.tls_ech & CURLECH_CLA_CFG);
  2955. else if(plen > 5 && !strncmp(argptr, "ecl:", 4)) {
  2956. result = Curl_setstropt(&data->set.str[STRING_ECH_CONFIG], argptr + 4);
  2957. if(result)
  2958. return result;
  2959. data->set.tls_ech |= CURLECH_CLA_CFG;
  2960. }
  2961. else if(plen > 4 && !strncmp(argptr, "pn:", 3)) {
  2962. result = Curl_setstropt(&data->set.str[STRING_ECH_PUBLIC], argptr + 3);
  2963. if(result)
  2964. return result;
  2965. }
  2966. break;
  2967. }
  2968. #endif
  2969. case CURLOPT_QUICK_EXIT:
  2970. data->set.quick_exit = (0 != va_arg(param, long)) ? 1L : 0L;
  2971. break;
  2972. default:
  2973. /* unknown tag and its companion, just ignore: */
  2974. result = CURLE_UNKNOWN_OPTION;
  2975. break;
  2976. }
  2977. return result;
  2978. }
  2979. /*
  2980. * curl_easy_setopt() is the external interface for setting options on an
  2981. * easy handle.
  2982. *
  2983. * NOTE: This is one of few API functions that are allowed to be called from
  2984. * within a callback.
  2985. */
  2986. #undef curl_easy_setopt
  2987. CURLcode curl_easy_setopt(CURL *d, CURLoption tag, ...)
  2988. {
  2989. va_list arg;
  2990. CURLcode result;
  2991. struct Curl_easy *data = d;
  2992. if(!data)
  2993. return CURLE_BAD_FUNCTION_ARGUMENT;
  2994. va_start(arg, tag);
  2995. result = Curl_vsetopt(data, tag, arg);
  2996. va_end(arg);
  2997. #ifdef DEBUGBUILD
  2998. if(result == CURLE_BAD_FUNCTION_ARGUMENT)
  2999. infof(data, "setopt arg 0x%x returned CURLE_BAD_FUNCTION_ARGUMENT", tag);
  3000. #endif
  3001. return result;
  3002. }