setopt.c 95 KB

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