setopt.c 82 KB

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