2
0

setopt.c 94 KB

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