2
0

setopt.c 88 KB

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