setopt.c 95 KB

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