setopt.c 88 KB

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