setopt.c 95 KB

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