2
0

setopt.c 94 KB

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