2
0

setopt.c 94 KB

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