2
0

setopt.c 88 KB

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