setopt.c 94 KB

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