setopt.c 85 KB

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