setopt.c 90 KB

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