setopt.c 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906
  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. /* general protection against mistakes and abuse */
  660. if(strlen(argptr) > CURL_MAX_INPUT_LENGTH)
  661. return CURLE_BAD_FUNCTION_ARGUMENT;
  662. /* append the cookie file name to the list of file names, and deal with
  663. them later */
  664. cl = curl_slist_append(data->change.cookielist, argptr);
  665. if(!cl) {
  666. curl_slist_free_all(data->change.cookielist);
  667. data->change.cookielist = NULL;
  668. return CURLE_OUT_OF_MEMORY;
  669. }
  670. data->change.cookielist = cl; /* store the list for later use */
  671. }
  672. break;
  673. case CURLOPT_COOKIEJAR:
  674. /*
  675. * Set cookie file name to dump all cookies to when we're done.
  676. */
  677. {
  678. struct CookieInfo *newcookies;
  679. result = Curl_setstropt(&data->set.str[STRING_COOKIEJAR],
  680. va_arg(param, char *));
  681. /*
  682. * Activate the cookie parser. This may or may not already
  683. * have been made.
  684. */
  685. newcookies = Curl_cookie_init(data, NULL, data->cookies,
  686. data->set.cookiesession);
  687. if(!newcookies)
  688. result = CURLE_OUT_OF_MEMORY;
  689. data->cookies = newcookies;
  690. }
  691. break;
  692. case CURLOPT_COOKIESESSION:
  693. /*
  694. * Set this option to TRUE to start a new "cookie session". It will
  695. * prevent the forthcoming read-cookies-from-file actions to accept
  696. * cookies that are marked as being session cookies, as they belong to a
  697. * previous session.
  698. *
  699. * In the original Netscape cookie spec, "session cookies" are cookies
  700. * with no expire date set. RFC2109 describes the same action if no
  701. * 'Max-Age' is set and RFC2965 includes the RFC2109 description and adds
  702. * a 'Discard' action that can enforce the discard even for cookies that
  703. * have a Max-Age.
  704. *
  705. * We run mostly with the original cookie spec, as hardly anyone implements
  706. * anything else.
  707. */
  708. data->set.cookiesession = (0 != va_arg(param, long)) ? TRUE : FALSE;
  709. break;
  710. case CURLOPT_COOKIELIST:
  711. argptr = va_arg(param, char *);
  712. if(argptr == NULL)
  713. break;
  714. if(strcasecompare(argptr, "ALL")) {
  715. /* clear all cookies */
  716. Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
  717. Curl_cookie_clearall(data->cookies);
  718. Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
  719. }
  720. else if(strcasecompare(argptr, "SESS")) {
  721. /* clear session cookies */
  722. Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
  723. Curl_cookie_clearsess(data->cookies);
  724. Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
  725. }
  726. else if(strcasecompare(argptr, "FLUSH")) {
  727. /* flush cookies to file, takes care of the locking */
  728. Curl_flush_cookies(data, FALSE);
  729. }
  730. else if(strcasecompare(argptr, "RELOAD")) {
  731. /* reload cookies from file */
  732. Curl_cookie_loadfiles(data);
  733. break;
  734. }
  735. else {
  736. if(!data->cookies)
  737. /* if cookie engine was not running, activate it */
  738. data->cookies = Curl_cookie_init(data, NULL, NULL, TRUE);
  739. /* general protection against mistakes and abuse */
  740. if(strlen(argptr) > CURL_MAX_INPUT_LENGTH)
  741. return CURLE_BAD_FUNCTION_ARGUMENT;
  742. argptr = strdup(argptr);
  743. if(!argptr || !data->cookies) {
  744. result = CURLE_OUT_OF_MEMORY;
  745. free(argptr);
  746. }
  747. else {
  748. Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
  749. if(checkprefix("Set-Cookie:", argptr))
  750. /* HTTP Header format line */
  751. Curl_cookie_add(data, data->cookies, TRUE, FALSE, argptr + 11, NULL,
  752. NULL, TRUE);
  753. else
  754. /* Netscape format line */
  755. Curl_cookie_add(data, data->cookies, FALSE, FALSE, argptr, NULL,
  756. NULL, TRUE);
  757. Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
  758. free(argptr);
  759. }
  760. }
  761. break;
  762. #endif /* !CURL_DISABLE_COOKIES */
  763. case CURLOPT_HTTPGET:
  764. /*
  765. * Set to force us do HTTP GET
  766. */
  767. if(va_arg(param, long)) {
  768. data->set.method = HTTPREQ_GET;
  769. data->set.upload = FALSE; /* switch off upload */
  770. data->set.opt_no_body = FALSE; /* this is implied */
  771. }
  772. break;
  773. case CURLOPT_HTTP_VERSION:
  774. /*
  775. * This sets a requested HTTP version to be used. The value is one of
  776. * the listed enums in curl/curl.h.
  777. */
  778. arg = va_arg(param, long);
  779. if(arg < CURL_HTTP_VERSION_NONE)
  780. return CURLE_BAD_FUNCTION_ARGUMENT;
  781. #ifdef ENABLE_QUIC
  782. if(arg == CURL_HTTP_VERSION_3)
  783. ;
  784. else
  785. #endif
  786. #ifndef USE_NGHTTP2
  787. if(arg >= CURL_HTTP_VERSION_2)
  788. return CURLE_UNSUPPORTED_PROTOCOL;
  789. #else
  790. if(arg >= CURL_HTTP_VERSION_LAST)
  791. return CURLE_UNSUPPORTED_PROTOCOL;
  792. if(arg == CURL_HTTP_VERSION_NONE)
  793. arg = CURL_HTTP_VERSION_2TLS;
  794. #endif
  795. data->set.httpversion = arg;
  796. break;
  797. case CURLOPT_EXPECT_100_TIMEOUT_MS:
  798. /*
  799. * Time to wait for a response to a HTTP request containing an
  800. * Expect: 100-continue header before sending the data anyway.
  801. */
  802. arg = va_arg(param, long);
  803. if(arg < 0)
  804. return CURLE_BAD_FUNCTION_ARGUMENT;
  805. data->set.expect_100_timeout = arg;
  806. break;
  807. case CURLOPT_HTTP09_ALLOWED:
  808. arg = va_arg(param, unsigned long);
  809. if(arg > 1L)
  810. return CURLE_BAD_FUNCTION_ARGUMENT;
  811. data->set.http09_allowed = arg ? TRUE : FALSE;
  812. break;
  813. #endif /* CURL_DISABLE_HTTP */
  814. case CURLOPT_HTTPAUTH:
  815. /*
  816. * Set HTTP Authentication type BITMASK.
  817. */
  818. {
  819. int bitcheck;
  820. bool authbits;
  821. unsigned long auth = va_arg(param, unsigned long);
  822. if(auth == CURLAUTH_NONE) {
  823. data->set.httpauth = auth;
  824. break;
  825. }
  826. /* the DIGEST_IE bit is only used to set a special marker, for all the
  827. rest we need to handle it as normal DIGEST */
  828. data->state.authhost.iestyle =
  829. (bool)((auth & CURLAUTH_DIGEST_IE) ? TRUE : FALSE);
  830. if(auth & CURLAUTH_DIGEST_IE) {
  831. auth |= CURLAUTH_DIGEST; /* set standard digest bit */
  832. auth &= ~CURLAUTH_DIGEST_IE; /* unset ie digest bit */
  833. }
  834. /* switch off bits we can't support */
  835. #ifndef USE_NTLM
  836. auth &= ~CURLAUTH_NTLM; /* no NTLM support */
  837. auth &= ~CURLAUTH_NTLM_WB; /* no NTLM_WB support */
  838. #elif !defined(NTLM_WB_ENABLED)
  839. auth &= ~CURLAUTH_NTLM_WB; /* no NTLM_WB support */
  840. #endif
  841. #ifndef USE_SPNEGO
  842. auth &= ~CURLAUTH_NEGOTIATE; /* no Negotiate (SPNEGO) auth without
  843. GSS-API or SSPI */
  844. #endif
  845. /* check if any auth bit lower than CURLAUTH_ONLY is still set */
  846. bitcheck = 0;
  847. authbits = FALSE;
  848. while(bitcheck < 31) {
  849. if(auth & (1UL << bitcheck++)) {
  850. authbits = TRUE;
  851. break;
  852. }
  853. }
  854. if(!authbits)
  855. return CURLE_NOT_BUILT_IN; /* no supported types left! */
  856. data->set.httpauth = auth;
  857. }
  858. break;
  859. case CURLOPT_CUSTOMREQUEST:
  860. /*
  861. * Set a custom string to use as request
  862. */
  863. result = Curl_setstropt(&data->set.str[STRING_CUSTOMREQUEST],
  864. va_arg(param, char *));
  865. /* we don't set
  866. data->set.method = HTTPREQ_CUSTOM;
  867. here, we continue as if we were using the already set type
  868. and this just changes the actual request keyword */
  869. break;
  870. #ifndef CURL_DISABLE_PROXY
  871. case CURLOPT_HTTPPROXYTUNNEL:
  872. /*
  873. * Tunnel operations through the proxy instead of normal proxy use
  874. */
  875. data->set.tunnel_thru_httpproxy = (0 != va_arg(param, long)) ?
  876. TRUE : FALSE;
  877. break;
  878. case CURLOPT_PROXYPORT:
  879. /*
  880. * Explicitly set HTTP proxy port number.
  881. */
  882. arg = va_arg(param, long);
  883. if((arg < 0) || (arg > 65535))
  884. return CURLE_BAD_FUNCTION_ARGUMENT;
  885. data->set.proxyport = arg;
  886. break;
  887. case CURLOPT_PROXYAUTH:
  888. /*
  889. * Set HTTP Authentication type BITMASK.
  890. */
  891. {
  892. int bitcheck;
  893. bool authbits;
  894. unsigned long auth = va_arg(param, unsigned long);
  895. if(auth == CURLAUTH_NONE) {
  896. data->set.proxyauth = auth;
  897. break;
  898. }
  899. /* the DIGEST_IE bit is only used to set a special marker, for all the
  900. rest we need to handle it as normal DIGEST */
  901. data->state.authproxy.iestyle =
  902. (bool)((auth & CURLAUTH_DIGEST_IE) ? TRUE : FALSE);
  903. if(auth & CURLAUTH_DIGEST_IE) {
  904. auth |= CURLAUTH_DIGEST; /* set standard digest bit */
  905. auth &= ~CURLAUTH_DIGEST_IE; /* unset ie digest bit */
  906. }
  907. /* switch off bits we can't support */
  908. #ifndef USE_NTLM
  909. auth &= ~CURLAUTH_NTLM; /* no NTLM support */
  910. auth &= ~CURLAUTH_NTLM_WB; /* no NTLM_WB support */
  911. #elif !defined(NTLM_WB_ENABLED)
  912. auth &= ~CURLAUTH_NTLM_WB; /* no NTLM_WB support */
  913. #endif
  914. #ifndef USE_SPNEGO
  915. auth &= ~CURLAUTH_NEGOTIATE; /* no Negotiate (SPNEGO) auth without
  916. GSS-API or SSPI */
  917. #endif
  918. /* check if any auth bit lower than CURLAUTH_ONLY is still set */
  919. bitcheck = 0;
  920. authbits = FALSE;
  921. while(bitcheck < 31) {
  922. if(auth & (1UL << bitcheck++)) {
  923. authbits = TRUE;
  924. break;
  925. }
  926. }
  927. if(!authbits)
  928. return CURLE_NOT_BUILT_IN; /* no supported types left! */
  929. data->set.proxyauth = auth;
  930. }
  931. break;
  932. case CURLOPT_PROXY:
  933. /*
  934. * Set proxy server:port to use as proxy.
  935. *
  936. * If the proxy is set to "" (and CURLOPT_SOCKS_PROXY is set to "" or NULL)
  937. * we explicitly say that we don't want to use a proxy
  938. * (even though there might be environment variables saying so).
  939. *
  940. * Setting it to NULL, means no proxy but allows the environment variables
  941. * to decide for us (if CURLOPT_SOCKS_PROXY setting it to NULL).
  942. */
  943. result = Curl_setstropt(&data->set.str[STRING_PROXY],
  944. va_arg(param, char *));
  945. break;
  946. case CURLOPT_PRE_PROXY:
  947. /*
  948. * Set proxy server:port to use as SOCKS proxy.
  949. *
  950. * If the proxy is set to "" or NULL we explicitly say that we don't want
  951. * to use the socks proxy.
  952. */
  953. result = Curl_setstropt(&data->set.str[STRING_PRE_PROXY],
  954. va_arg(param, char *));
  955. break;
  956. case CURLOPT_PROXYTYPE:
  957. /*
  958. * Set proxy type. HTTP/HTTP_1_0/SOCKS4/SOCKS4a/SOCKS5/SOCKS5_HOSTNAME
  959. */
  960. arg = va_arg(param, long);
  961. if((arg < CURLPROXY_HTTP) || (arg > CURLPROXY_SOCKS5_HOSTNAME))
  962. return CURLE_BAD_FUNCTION_ARGUMENT;
  963. data->set.proxytype = (curl_proxytype)arg;
  964. break;
  965. case CURLOPT_PROXY_TRANSFER_MODE:
  966. /*
  967. * set transfer mode (;type=<a|i>) when doing FTP via an HTTP proxy
  968. */
  969. switch(va_arg(param, long)) {
  970. case 0:
  971. data->set.proxy_transfer_mode = FALSE;
  972. break;
  973. case 1:
  974. data->set.proxy_transfer_mode = TRUE;
  975. break;
  976. default:
  977. /* reserve other values for future use */
  978. result = CURLE_UNKNOWN_OPTION;
  979. break;
  980. }
  981. break;
  982. #endif /* CURL_DISABLE_PROXY */
  983. case CURLOPT_SOCKS5_AUTH:
  984. data->set.socks5auth = va_arg(param, unsigned long);
  985. if(data->set.socks5auth & ~(CURLAUTH_BASIC | CURLAUTH_GSSAPI))
  986. result = CURLE_NOT_BUILT_IN;
  987. break;
  988. #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
  989. case CURLOPT_SOCKS5_GSSAPI_NEC:
  990. /*
  991. * Set flag for NEC SOCK5 support
  992. */
  993. data->set.socks5_gssapi_nec = (0 != va_arg(param, long)) ? TRUE : FALSE;
  994. break;
  995. #endif
  996. #ifndef CURL_DISABLE_PROXY
  997. case CURLOPT_SOCKS5_GSSAPI_SERVICE:
  998. case CURLOPT_PROXY_SERVICE_NAME:
  999. /*
  1000. * Set proxy authentication service name for Kerberos 5 and SPNEGO
  1001. */
  1002. result = Curl_setstropt(&data->set.str[STRING_PROXY_SERVICE_NAME],
  1003. va_arg(param, char *));
  1004. break;
  1005. #endif
  1006. case CURLOPT_SERVICE_NAME:
  1007. /*
  1008. * Set authentication service name for DIGEST-MD5, Kerberos 5 and SPNEGO
  1009. */
  1010. result = Curl_setstropt(&data->set.str[STRING_SERVICE_NAME],
  1011. va_arg(param, char *));
  1012. break;
  1013. case CURLOPT_HEADERDATA:
  1014. /*
  1015. * Custom pointer to pass the header write callback function
  1016. */
  1017. data->set.writeheader = (void *)va_arg(param, void *);
  1018. break;
  1019. case CURLOPT_ERRORBUFFER:
  1020. /*
  1021. * Error buffer provided by the caller to get the human readable
  1022. * error string in.
  1023. */
  1024. data->set.errorbuffer = va_arg(param, char *);
  1025. break;
  1026. case CURLOPT_WRITEDATA:
  1027. /*
  1028. * FILE pointer to write to. Or possibly
  1029. * used as argument to the write callback.
  1030. */
  1031. data->set.out = va_arg(param, void *);
  1032. break;
  1033. case CURLOPT_DIRLISTONLY:
  1034. /*
  1035. * An option that changes the command to one that asks for a list only, no
  1036. * file info details. Used for FTP, POP3 and SFTP.
  1037. */
  1038. data->set.ftp_list_only = (0 != va_arg(param, long)) ? TRUE : FALSE;
  1039. break;
  1040. case CURLOPT_APPEND:
  1041. /*
  1042. * We want to upload and append to an existing file. Used for FTP and
  1043. * SFTP.
  1044. */
  1045. data->set.ftp_append = (0 != va_arg(param, long)) ? TRUE : FALSE;
  1046. break;
  1047. #ifndef CURL_DISABLE_FTP
  1048. case CURLOPT_FTP_FILEMETHOD:
  1049. /*
  1050. * How do access files over FTP.
  1051. */
  1052. arg = va_arg(param, long);
  1053. if((arg < CURLFTPMETHOD_DEFAULT) || (arg >= CURLFTPMETHOD_LAST))
  1054. return CURLE_BAD_FUNCTION_ARGUMENT;
  1055. data->set.ftp_filemethod = (curl_ftpfile)arg;
  1056. break;
  1057. case CURLOPT_FTPPORT:
  1058. /*
  1059. * Use FTP PORT, this also specifies which IP address to use
  1060. */
  1061. result = Curl_setstropt(&data->set.str[STRING_FTPPORT],
  1062. va_arg(param, char *));
  1063. data->set.ftp_use_port = (data->set.str[STRING_FTPPORT]) ? TRUE : FALSE;
  1064. break;
  1065. case CURLOPT_FTP_USE_EPRT:
  1066. data->set.ftp_use_eprt = (0 != va_arg(param, long)) ? TRUE : FALSE;
  1067. break;
  1068. case CURLOPT_FTP_USE_EPSV:
  1069. data->set.ftp_use_epsv = (0 != va_arg(param, long)) ? TRUE : FALSE;
  1070. break;
  1071. case CURLOPT_FTP_USE_PRET:
  1072. data->set.ftp_use_pret = (0 != va_arg(param, long)) ? TRUE : FALSE;
  1073. break;
  1074. case CURLOPT_FTP_SSL_CCC:
  1075. arg = va_arg(param, long);
  1076. if((arg < CURLFTPSSL_CCC_NONE) || (arg >= CURLFTPSSL_CCC_LAST))
  1077. return CURLE_BAD_FUNCTION_ARGUMENT;
  1078. data->set.ftp_ccc = (curl_ftpccc)arg;
  1079. break;
  1080. case CURLOPT_FTP_SKIP_PASV_IP:
  1081. /*
  1082. * Enable or disable FTP_SKIP_PASV_IP, which will disable/enable the
  1083. * bypass of the IP address in PASV responses.
  1084. */
  1085. data->set.ftp_skip_ip = (0 != va_arg(param, long)) ? TRUE : FALSE;
  1086. break;
  1087. case CURLOPT_FTP_ACCOUNT:
  1088. result = Curl_setstropt(&data->set.str[STRING_FTP_ACCOUNT],
  1089. va_arg(param, char *));
  1090. break;
  1091. case CURLOPT_FTP_ALTERNATIVE_TO_USER:
  1092. result = Curl_setstropt(&data->set.str[STRING_FTP_ALTERNATIVE_TO_USER],
  1093. va_arg(param, char *));
  1094. break;
  1095. case CURLOPT_FTPSSLAUTH:
  1096. /*
  1097. * Set a specific auth for FTP-SSL transfers.
  1098. */
  1099. arg = va_arg(param, long);
  1100. if((arg < CURLFTPAUTH_DEFAULT) || (arg >= CURLFTPAUTH_LAST))
  1101. return CURLE_BAD_FUNCTION_ARGUMENT;
  1102. data->set.ftpsslauth = (curl_ftpauth)arg;
  1103. break;
  1104. case CURLOPT_KRBLEVEL:
  1105. /*
  1106. * A string that defines the kerberos security level.
  1107. */
  1108. result = Curl_setstropt(&data->set.str[STRING_KRB_LEVEL],
  1109. va_arg(param, char *));
  1110. data->set.krb = (data->set.str[STRING_KRB_LEVEL]) ? TRUE : FALSE;
  1111. break;
  1112. #endif
  1113. case CURLOPT_FTP_CREATE_MISSING_DIRS:
  1114. /*
  1115. * An FTP/SFTP option that modifies an upload to create missing
  1116. * directories on the server.
  1117. */
  1118. switch(va_arg(param, long)) {
  1119. case 0:
  1120. data->set.ftp_create_missing_dirs = 0;
  1121. break;
  1122. case 1:
  1123. data->set.ftp_create_missing_dirs = 1;
  1124. break;
  1125. case 2:
  1126. data->set.ftp_create_missing_dirs = 2;
  1127. break;
  1128. default:
  1129. /* reserve other values for future use */
  1130. result = CURLE_UNKNOWN_OPTION;
  1131. break;
  1132. }
  1133. break;
  1134. case CURLOPT_READDATA:
  1135. /*
  1136. * FILE pointer to read the file to be uploaded from. Or possibly
  1137. * used as argument to the read callback.
  1138. */
  1139. data->set.in_set = va_arg(param, void *);
  1140. break;
  1141. case CURLOPT_INFILESIZE:
  1142. /*
  1143. * If known, this should inform curl about the file size of the
  1144. * to-be-uploaded file.
  1145. */
  1146. arg = va_arg(param, long);
  1147. if(arg < -1)
  1148. return CURLE_BAD_FUNCTION_ARGUMENT;
  1149. data->set.filesize = arg;
  1150. break;
  1151. case CURLOPT_INFILESIZE_LARGE:
  1152. /*
  1153. * If known, this should inform curl about the file size of the
  1154. * to-be-uploaded file.
  1155. */
  1156. bigsize = va_arg(param, curl_off_t);
  1157. if(bigsize < -1)
  1158. return CURLE_BAD_FUNCTION_ARGUMENT;
  1159. data->set.filesize = bigsize;
  1160. break;
  1161. case CURLOPT_LOW_SPEED_LIMIT:
  1162. /*
  1163. * The low speed limit that if transfers are below this for
  1164. * CURLOPT_LOW_SPEED_TIME, the transfer is aborted.
  1165. */
  1166. arg = va_arg(param, long);
  1167. if(arg < 0)
  1168. return CURLE_BAD_FUNCTION_ARGUMENT;
  1169. data->set.low_speed_limit = arg;
  1170. break;
  1171. case CURLOPT_MAX_SEND_SPEED_LARGE:
  1172. /*
  1173. * When transfer uploads are faster then CURLOPT_MAX_SEND_SPEED_LARGE
  1174. * bytes per second the transfer is throttled..
  1175. */
  1176. bigsize = va_arg(param, curl_off_t);
  1177. if(bigsize < 0)
  1178. return CURLE_BAD_FUNCTION_ARGUMENT;
  1179. data->set.max_send_speed = bigsize;
  1180. break;
  1181. case CURLOPT_MAX_RECV_SPEED_LARGE:
  1182. /*
  1183. * When receiving data faster than CURLOPT_MAX_RECV_SPEED_LARGE bytes per
  1184. * second the transfer is throttled..
  1185. */
  1186. bigsize = va_arg(param, curl_off_t);
  1187. if(bigsize < 0)
  1188. return CURLE_BAD_FUNCTION_ARGUMENT;
  1189. data->set.max_recv_speed = bigsize;
  1190. break;
  1191. case CURLOPT_LOW_SPEED_TIME:
  1192. /*
  1193. * The low speed time that if transfers are below the set
  1194. * CURLOPT_LOW_SPEED_LIMIT during this time, the transfer is aborted.
  1195. */
  1196. arg = va_arg(param, long);
  1197. if(arg < 0)
  1198. return CURLE_BAD_FUNCTION_ARGUMENT;
  1199. data->set.low_speed_time = arg;
  1200. break;
  1201. case CURLOPT_CURLU:
  1202. /*
  1203. * pass CURLU to set URL
  1204. */
  1205. data->set.uh = va_arg(param, CURLU *);
  1206. break;
  1207. case CURLOPT_URL:
  1208. /*
  1209. * The URL to fetch.
  1210. */
  1211. if(data->change.url_alloc) {
  1212. /* the already set URL is allocated, free it first! */
  1213. Curl_safefree(data->change.url);
  1214. data->change.url_alloc = FALSE;
  1215. }
  1216. result = Curl_setstropt(&data->set.str[STRING_SET_URL],
  1217. va_arg(param, char *));
  1218. data->change.url = data->set.str[STRING_SET_URL];
  1219. break;
  1220. case CURLOPT_PORT:
  1221. /*
  1222. * The port number to use when getting the URL
  1223. */
  1224. arg = va_arg(param, long);
  1225. if((arg < 0) || (arg > 65535))
  1226. return CURLE_BAD_FUNCTION_ARGUMENT;
  1227. data->set.use_port = arg;
  1228. break;
  1229. case CURLOPT_TIMEOUT:
  1230. /*
  1231. * The maximum time you allow curl to use for a single transfer
  1232. * operation.
  1233. */
  1234. arg = va_arg(param, long);
  1235. if((arg >= 0) && (arg <= (INT_MAX/1000)))
  1236. data->set.timeout = arg * 1000;
  1237. else
  1238. return CURLE_BAD_FUNCTION_ARGUMENT;
  1239. break;
  1240. case CURLOPT_TIMEOUT_MS:
  1241. arg = va_arg(param, long);
  1242. if(arg < 0)
  1243. return CURLE_BAD_FUNCTION_ARGUMENT;
  1244. data->set.timeout = arg;
  1245. break;
  1246. case CURLOPT_CONNECTTIMEOUT:
  1247. /*
  1248. * The maximum time you allow curl to use to connect.
  1249. */
  1250. arg = va_arg(param, long);
  1251. if((arg >= 0) && (arg <= (INT_MAX/1000)))
  1252. data->set.connecttimeout = arg * 1000;
  1253. else
  1254. return CURLE_BAD_FUNCTION_ARGUMENT;
  1255. break;
  1256. case CURLOPT_CONNECTTIMEOUT_MS:
  1257. arg = va_arg(param, long);
  1258. if(arg < 0)
  1259. return CURLE_BAD_FUNCTION_ARGUMENT;
  1260. data->set.connecttimeout = arg;
  1261. break;
  1262. case CURLOPT_ACCEPTTIMEOUT_MS:
  1263. /*
  1264. * The maximum time you allow curl to wait for server connect
  1265. */
  1266. arg = va_arg(param, long);
  1267. if(arg < 0)
  1268. return CURLE_BAD_FUNCTION_ARGUMENT;
  1269. data->set.accepttimeout = arg;
  1270. break;
  1271. case CURLOPT_USERPWD:
  1272. /*
  1273. * user:password to use in the operation
  1274. */
  1275. result = setstropt_userpwd(va_arg(param, char *),
  1276. &data->set.str[STRING_USERNAME],
  1277. &data->set.str[STRING_PASSWORD]);
  1278. break;
  1279. case CURLOPT_USERNAME:
  1280. /*
  1281. * authentication user name to use in the operation
  1282. */
  1283. result = Curl_setstropt(&data->set.str[STRING_USERNAME],
  1284. va_arg(param, char *));
  1285. break;
  1286. case CURLOPT_PASSWORD:
  1287. /*
  1288. * authentication password to use in the operation
  1289. */
  1290. result = Curl_setstropt(&data->set.str[STRING_PASSWORD],
  1291. va_arg(param, char *));
  1292. break;
  1293. case CURLOPT_LOGIN_OPTIONS:
  1294. /*
  1295. * authentication options to use in the operation
  1296. */
  1297. result = Curl_setstropt(&data->set.str[STRING_OPTIONS],
  1298. va_arg(param, char *));
  1299. break;
  1300. case CURLOPT_XOAUTH2_BEARER:
  1301. /*
  1302. * OAuth 2.0 bearer token to use in the operation
  1303. */
  1304. result = Curl_setstropt(&data->set.str[STRING_BEARER],
  1305. va_arg(param, char *));
  1306. break;
  1307. case CURLOPT_POSTQUOTE:
  1308. /*
  1309. * List of RAW FTP commands to use after a transfer
  1310. */
  1311. data->set.postquote = va_arg(param, struct curl_slist *);
  1312. break;
  1313. case CURLOPT_PREQUOTE:
  1314. /*
  1315. * List of RAW FTP commands to use prior to RETR (Wesley Laxton)
  1316. */
  1317. data->set.prequote = va_arg(param, struct curl_slist *);
  1318. break;
  1319. case CURLOPT_QUOTE:
  1320. /*
  1321. * List of RAW FTP commands to use before a transfer
  1322. */
  1323. data->set.quote = va_arg(param, struct curl_slist *);
  1324. break;
  1325. case CURLOPT_RESOLVE:
  1326. /*
  1327. * List of NAME:[address] names to populate the DNS cache with
  1328. * Prefix the NAME with dash (-) to _remove_ the name from the cache.
  1329. *
  1330. * Names added with this API will remain in the cache until explicitly
  1331. * removed or the handle is cleaned up.
  1332. *
  1333. * This API can remove any name from the DNS cache, but only entries
  1334. * that aren't actually in use right now will be pruned immediately.
  1335. */
  1336. data->set.resolve = va_arg(param, struct curl_slist *);
  1337. data->change.resolve = data->set.resolve;
  1338. break;
  1339. case CURLOPT_PROGRESSFUNCTION:
  1340. /*
  1341. * Progress callback function
  1342. */
  1343. data->set.fprogress = va_arg(param, curl_progress_callback);
  1344. if(data->set.fprogress)
  1345. data->progress.callback = TRUE; /* no longer internal */
  1346. else
  1347. data->progress.callback = FALSE; /* NULL enforces internal */
  1348. break;
  1349. case CURLOPT_XFERINFOFUNCTION:
  1350. /*
  1351. * Transfer info callback function
  1352. */
  1353. data->set.fxferinfo = va_arg(param, curl_xferinfo_callback);
  1354. if(data->set.fxferinfo)
  1355. data->progress.callback = TRUE; /* no longer internal */
  1356. else
  1357. data->progress.callback = FALSE; /* NULL enforces internal */
  1358. break;
  1359. case CURLOPT_PROGRESSDATA:
  1360. /*
  1361. * Custom client data to pass to the progress callback
  1362. */
  1363. data->set.progress_client = va_arg(param, void *);
  1364. break;
  1365. #ifndef CURL_DISABLE_PROXY
  1366. case CURLOPT_PROXYUSERPWD:
  1367. /*
  1368. * user:password needed to use the proxy
  1369. */
  1370. result = setstropt_userpwd(va_arg(param, char *),
  1371. &data->set.str[STRING_PROXYUSERNAME],
  1372. &data->set.str[STRING_PROXYPASSWORD]);
  1373. break;
  1374. case CURLOPT_PROXYUSERNAME:
  1375. /*
  1376. * authentication user name to use in the operation
  1377. */
  1378. result = Curl_setstropt(&data->set.str[STRING_PROXYUSERNAME],
  1379. va_arg(param, char *));
  1380. break;
  1381. case CURLOPT_PROXYPASSWORD:
  1382. /*
  1383. * authentication password to use in the operation
  1384. */
  1385. result = Curl_setstropt(&data->set.str[STRING_PROXYPASSWORD],
  1386. va_arg(param, char *));
  1387. break;
  1388. case CURLOPT_NOPROXY:
  1389. /*
  1390. * proxy exception list
  1391. */
  1392. result = Curl_setstropt(&data->set.str[STRING_NOPROXY],
  1393. va_arg(param, char *));
  1394. break;
  1395. #endif
  1396. case CURLOPT_RANGE:
  1397. /*
  1398. * What range of the file you want to transfer
  1399. */
  1400. result = Curl_setstropt(&data->set.str[STRING_SET_RANGE],
  1401. va_arg(param, char *));
  1402. break;
  1403. case CURLOPT_RESUME_FROM:
  1404. /*
  1405. * Resume transfer at the given file position
  1406. */
  1407. arg = va_arg(param, long);
  1408. if(arg < -1)
  1409. return CURLE_BAD_FUNCTION_ARGUMENT;
  1410. data->set.set_resume_from = arg;
  1411. break;
  1412. case CURLOPT_RESUME_FROM_LARGE:
  1413. /*
  1414. * Resume transfer at the given file position
  1415. */
  1416. bigsize = va_arg(param, curl_off_t);
  1417. if(bigsize < -1)
  1418. return CURLE_BAD_FUNCTION_ARGUMENT;
  1419. data->set.set_resume_from = bigsize;
  1420. break;
  1421. case CURLOPT_DEBUGFUNCTION:
  1422. /*
  1423. * stderr write callback.
  1424. */
  1425. data->set.fdebug = va_arg(param, curl_debug_callback);
  1426. /*
  1427. * if the callback provided is NULL, it'll use the default callback
  1428. */
  1429. break;
  1430. case CURLOPT_DEBUGDATA:
  1431. /*
  1432. * Set to a void * that should receive all error writes. This
  1433. * defaults to CURLOPT_STDERR for normal operations.
  1434. */
  1435. data->set.debugdata = va_arg(param, void *);
  1436. break;
  1437. case CURLOPT_STDERR:
  1438. /*
  1439. * Set to a FILE * that should receive all error writes. This
  1440. * defaults to stderr for normal operations.
  1441. */
  1442. data->set.err = va_arg(param, FILE *);
  1443. if(!data->set.err)
  1444. data->set.err = stderr;
  1445. break;
  1446. case CURLOPT_HEADERFUNCTION:
  1447. /*
  1448. * Set header write callback
  1449. */
  1450. data->set.fwrite_header = va_arg(param, curl_write_callback);
  1451. break;
  1452. case CURLOPT_WRITEFUNCTION:
  1453. /*
  1454. * Set data write callback
  1455. */
  1456. data->set.fwrite_func = va_arg(param, curl_write_callback);
  1457. if(!data->set.fwrite_func) {
  1458. data->set.is_fwrite_set = 0;
  1459. /* When set to NULL, reset to our internal default function */
  1460. data->set.fwrite_func = (curl_write_callback)fwrite;
  1461. }
  1462. else
  1463. data->set.is_fwrite_set = 1;
  1464. break;
  1465. case CURLOPT_READFUNCTION:
  1466. /*
  1467. * Read data callback
  1468. */
  1469. data->set.fread_func_set = va_arg(param, curl_read_callback);
  1470. if(!data->set.fread_func_set) {
  1471. data->set.is_fread_set = 0;
  1472. /* When set to NULL, reset to our internal default function */
  1473. data->set.fread_func_set = (curl_read_callback)fread;
  1474. }
  1475. else
  1476. data->set.is_fread_set = 1;
  1477. break;
  1478. case CURLOPT_SEEKFUNCTION:
  1479. /*
  1480. * Seek callback. Might be NULL.
  1481. */
  1482. data->set.seek_func = va_arg(param, curl_seek_callback);
  1483. break;
  1484. case CURLOPT_SEEKDATA:
  1485. /*
  1486. * Seek control callback. Might be NULL.
  1487. */
  1488. data->set.seek_client = va_arg(param, void *);
  1489. break;
  1490. case CURLOPT_CONV_FROM_NETWORK_FUNCTION:
  1491. /*
  1492. * "Convert from network encoding" callback
  1493. */
  1494. data->set.convfromnetwork = va_arg(param, curl_conv_callback);
  1495. break;
  1496. case CURLOPT_CONV_TO_NETWORK_FUNCTION:
  1497. /*
  1498. * "Convert to network encoding" callback
  1499. */
  1500. data->set.convtonetwork = va_arg(param, curl_conv_callback);
  1501. break;
  1502. case CURLOPT_CONV_FROM_UTF8_FUNCTION:
  1503. /*
  1504. * "Convert from UTF-8 encoding" callback
  1505. */
  1506. data->set.convfromutf8 = va_arg(param, curl_conv_callback);
  1507. break;
  1508. case CURLOPT_IOCTLFUNCTION:
  1509. /*
  1510. * I/O control callback. Might be NULL.
  1511. */
  1512. data->set.ioctl_func = va_arg(param, curl_ioctl_callback);
  1513. break;
  1514. case CURLOPT_IOCTLDATA:
  1515. /*
  1516. * I/O control data pointer. Might be NULL.
  1517. */
  1518. data->set.ioctl_client = va_arg(param, void *);
  1519. break;
  1520. case CURLOPT_SSLCERT:
  1521. /*
  1522. * String that holds file name of the SSL certificate to use
  1523. */
  1524. result = Curl_setstropt(&data->set.str[STRING_CERT_ORIG],
  1525. va_arg(param, char *));
  1526. break;
  1527. case CURLOPT_SSLCERT_BLOB:
  1528. /*
  1529. * Blob that holds file name of the SSL certificate to use
  1530. */
  1531. result = Curl_setblobopt(&data->set.blobs[BLOB_CERT_ORIG],
  1532. va_arg(param, struct curl_blob *));
  1533. break;
  1534. #ifndef CURL_DISABLE_PROXY
  1535. case CURLOPT_PROXY_SSLCERT:
  1536. /*
  1537. * String that holds file name of the SSL certificate to use for proxy
  1538. */
  1539. result = Curl_setstropt(&data->set.str[STRING_CERT_PROXY],
  1540. va_arg(param, char *));
  1541. break;
  1542. case CURLOPT_PROXY_SSLCERT_BLOB:
  1543. /*
  1544. * Blob that holds file name of the SSL certificate to use for proxy
  1545. */
  1546. result = Curl_setblobopt(&data->set.blobs[BLOB_CERT_PROXY],
  1547. va_arg(param, struct curl_blob *));
  1548. break;
  1549. #endif
  1550. case CURLOPT_SSLCERTTYPE:
  1551. /*
  1552. * String that holds file type of the SSL certificate to use
  1553. */
  1554. result = Curl_setstropt(&data->set.str[STRING_CERT_TYPE_ORIG],
  1555. va_arg(param, char *));
  1556. break;
  1557. #ifndef CURL_DISABLE_PROXY
  1558. case CURLOPT_PROXY_SSLCERTTYPE:
  1559. /*
  1560. * String that holds file type of the SSL certificate to use for proxy
  1561. */
  1562. result = Curl_setstropt(&data->set.str[STRING_CERT_TYPE_PROXY],
  1563. va_arg(param, char *));
  1564. break;
  1565. #endif
  1566. case CURLOPT_SSLKEY:
  1567. /*
  1568. * String that holds file name of the SSL key to use
  1569. */
  1570. result = Curl_setstropt(&data->set.str[STRING_KEY_ORIG],
  1571. va_arg(param, char *));
  1572. break;
  1573. case CURLOPT_SSLKEY_BLOB:
  1574. /*
  1575. * Blob that holds file name of the SSL key to use
  1576. */
  1577. result = Curl_setblobopt(&data->set.blobs[BLOB_KEY_ORIG],
  1578. va_arg(param, struct curl_blob *));
  1579. break;
  1580. #ifndef CURL_DISABLE_PROXY
  1581. case CURLOPT_PROXY_SSLKEY:
  1582. /*
  1583. * String that holds file name of the SSL key to use for proxy
  1584. */
  1585. result = Curl_setstropt(&data->set.str[STRING_KEY_PROXY],
  1586. va_arg(param, char *));
  1587. break;
  1588. case CURLOPT_PROXY_SSLKEY_BLOB:
  1589. /*
  1590. * Blob that holds file name of the SSL key to use for proxy
  1591. */
  1592. result = Curl_setblobopt(&data->set.blobs[BLOB_KEY_PROXY],
  1593. va_arg(param, struct curl_blob *));
  1594. break;
  1595. #endif
  1596. case CURLOPT_SSLKEYTYPE:
  1597. /*
  1598. * String that holds file type of the SSL key to use
  1599. */
  1600. result = Curl_setstropt(&data->set.str[STRING_KEY_TYPE_ORIG],
  1601. va_arg(param, char *));
  1602. break;
  1603. #ifndef CURL_DISABLE_PROXY
  1604. case CURLOPT_PROXY_SSLKEYTYPE:
  1605. /*
  1606. * String that holds file type of the SSL key to use for proxy
  1607. */
  1608. result = Curl_setstropt(&data->set.str[STRING_KEY_TYPE_PROXY],
  1609. va_arg(param, char *));
  1610. break;
  1611. #endif
  1612. case CURLOPT_KEYPASSWD:
  1613. /*
  1614. * String that holds the SSL or SSH private key password.
  1615. */
  1616. result = Curl_setstropt(&data->set.str[STRING_KEY_PASSWD_ORIG],
  1617. va_arg(param, char *));
  1618. break;
  1619. #ifndef CURL_DISABLE_PROXY
  1620. case CURLOPT_PROXY_KEYPASSWD:
  1621. /*
  1622. * String that holds the SSL private key password for proxy.
  1623. */
  1624. result = Curl_setstropt(&data->set.str[STRING_KEY_PASSWD_PROXY],
  1625. va_arg(param, char *));
  1626. break;
  1627. #endif
  1628. case CURLOPT_SSLENGINE:
  1629. /*
  1630. * String that holds the SSL crypto engine.
  1631. */
  1632. argptr = va_arg(param, char *);
  1633. if(argptr && argptr[0]) {
  1634. result = Curl_setstropt(&data->set.str[STRING_SSL_ENGINE], argptr);
  1635. if(!result) {
  1636. result = Curl_ssl_set_engine(data, argptr);
  1637. }
  1638. }
  1639. break;
  1640. case CURLOPT_SSLENGINE_DEFAULT:
  1641. /*
  1642. * flag to set engine as default.
  1643. */
  1644. Curl_setstropt(&data->set.str[STRING_SSL_ENGINE], NULL);
  1645. result = Curl_ssl_set_engine_default(data);
  1646. break;
  1647. case CURLOPT_CRLF:
  1648. /*
  1649. * Kludgy option to enable CRLF conversions. Subject for removal.
  1650. */
  1651. data->set.crlf = (0 != va_arg(param, long)) ? TRUE : FALSE;
  1652. break;
  1653. #ifndef CURL_DISABLE_PROXY
  1654. case CURLOPT_HAPROXYPROTOCOL:
  1655. /*
  1656. * Set to send the HAProxy Proxy Protocol header
  1657. */
  1658. data->set.haproxyprotocol = (0 != va_arg(param, long)) ? TRUE : FALSE;
  1659. break;
  1660. #endif
  1661. case CURLOPT_INTERFACE:
  1662. /*
  1663. * Set what interface or address/hostname to bind the socket to when
  1664. * performing an operation and thus what from-IP your connection will use.
  1665. */
  1666. result = Curl_setstropt(&data->set.str[STRING_DEVICE],
  1667. va_arg(param, char *));
  1668. break;
  1669. case CURLOPT_LOCALPORT:
  1670. /*
  1671. * Set what local port to bind the socket to when performing an operation.
  1672. */
  1673. arg = va_arg(param, long);
  1674. if((arg < 0) || (arg > 65535))
  1675. return CURLE_BAD_FUNCTION_ARGUMENT;
  1676. data->set.localport = curlx_sltous(arg);
  1677. break;
  1678. case CURLOPT_LOCALPORTRANGE:
  1679. /*
  1680. * Set number of local ports to try, starting with CURLOPT_LOCALPORT.
  1681. */
  1682. arg = va_arg(param, long);
  1683. if((arg < 0) || (arg > 65535))
  1684. return CURLE_BAD_FUNCTION_ARGUMENT;
  1685. data->set.localportrange = curlx_sltosi(arg);
  1686. break;
  1687. case CURLOPT_GSSAPI_DELEGATION:
  1688. /*
  1689. * GSS-API credential delegation bitmask
  1690. */
  1691. arg = va_arg(param, long);
  1692. if(arg < CURLGSSAPI_DELEGATION_NONE)
  1693. return CURLE_BAD_FUNCTION_ARGUMENT;
  1694. data->set.gssapi_delegation = arg;
  1695. break;
  1696. case CURLOPT_SSL_VERIFYPEER:
  1697. /*
  1698. * Enable peer SSL verifying.
  1699. */
  1700. data->set.ssl.primary.verifypeer = (0 != va_arg(param, long)) ?
  1701. TRUE : FALSE;
  1702. /* Update the current connection ssl_config. */
  1703. if(data->conn) {
  1704. data->conn->ssl_config.verifypeer =
  1705. data->set.ssl.primary.verifypeer;
  1706. }
  1707. break;
  1708. #ifndef CURL_DISABLE_PROXY
  1709. case CURLOPT_PROXY_SSL_VERIFYPEER:
  1710. /*
  1711. * Enable peer SSL verifying for proxy.
  1712. */
  1713. data->set.proxy_ssl.primary.verifypeer =
  1714. (0 != va_arg(param, long))?TRUE:FALSE;
  1715. /* Update the current connection proxy_ssl_config. */
  1716. if(data->conn) {
  1717. data->conn->proxy_ssl_config.verifypeer =
  1718. data->set.proxy_ssl.primary.verifypeer;
  1719. }
  1720. break;
  1721. #endif
  1722. case CURLOPT_SSL_VERIFYHOST:
  1723. /*
  1724. * Enable verification of the host name in the peer certificate
  1725. */
  1726. arg = va_arg(param, long);
  1727. /* Obviously people are not reading documentation and too many thought
  1728. this argument took a boolean when it wasn't and misused it.
  1729. Treat 1 and 2 the same */
  1730. data->set.ssl.primary.verifyhost = (bool)((arg & 3) ? TRUE : FALSE);
  1731. /* Update the current connection ssl_config. */
  1732. if(data->conn) {
  1733. data->conn->ssl_config.verifyhost =
  1734. data->set.ssl.primary.verifyhost;
  1735. }
  1736. break;
  1737. #ifndef CURL_DISABLE_PROXY
  1738. case CURLOPT_PROXY_SSL_VERIFYHOST:
  1739. /*
  1740. * Enable verification of the host name in the peer certificate for proxy
  1741. */
  1742. arg = va_arg(param, long);
  1743. /* Treat both 1 and 2 as TRUE */
  1744. data->set.proxy_ssl.primary.verifyhost = (bool)((arg & 3)?TRUE:FALSE);
  1745. /* Update the current connection proxy_ssl_config. */
  1746. if(data->conn) {
  1747. data->conn->proxy_ssl_config.verifyhost =
  1748. data->set.proxy_ssl.primary.verifyhost;
  1749. }
  1750. break;
  1751. #endif
  1752. case CURLOPT_SSL_VERIFYSTATUS:
  1753. /*
  1754. * Enable certificate status verifying.
  1755. */
  1756. if(!Curl_ssl_cert_status_request()) {
  1757. result = CURLE_NOT_BUILT_IN;
  1758. break;
  1759. }
  1760. data->set.ssl.primary.verifystatus = (0 != va_arg(param, long)) ?
  1761. TRUE : FALSE;
  1762. /* Update the current connection ssl_config. */
  1763. if(data->conn) {
  1764. data->conn->ssl_config.verifystatus =
  1765. data->set.ssl.primary.verifystatus;
  1766. }
  1767. break;
  1768. case CURLOPT_SSL_CTX_FUNCTION:
  1769. /*
  1770. * Set a SSL_CTX callback
  1771. */
  1772. #ifdef USE_SSL
  1773. if(Curl_ssl->supports & SSLSUPP_SSL_CTX)
  1774. data->set.ssl.fsslctx = va_arg(param, curl_ssl_ctx_callback);
  1775. else
  1776. #endif
  1777. result = CURLE_NOT_BUILT_IN;
  1778. break;
  1779. case CURLOPT_SSL_CTX_DATA:
  1780. /*
  1781. * Set a SSL_CTX callback parameter pointer
  1782. */
  1783. #ifdef USE_SSL
  1784. if(Curl_ssl->supports & SSLSUPP_SSL_CTX)
  1785. data->set.ssl.fsslctxp = va_arg(param, void *);
  1786. else
  1787. #endif
  1788. result = CURLE_NOT_BUILT_IN;
  1789. break;
  1790. case CURLOPT_SSL_FALSESTART:
  1791. /*
  1792. * Enable TLS false start.
  1793. */
  1794. if(!Curl_ssl_false_start()) {
  1795. result = CURLE_NOT_BUILT_IN;
  1796. break;
  1797. }
  1798. data->set.ssl.falsestart = (0 != va_arg(param, long)) ? TRUE : FALSE;
  1799. break;
  1800. case CURLOPT_CERTINFO:
  1801. #ifdef USE_SSL
  1802. if(Curl_ssl->supports & SSLSUPP_CERTINFO)
  1803. data->set.ssl.certinfo = (0 != va_arg(param, long)) ? TRUE : FALSE;
  1804. else
  1805. #endif
  1806. result = CURLE_NOT_BUILT_IN;
  1807. break;
  1808. case CURLOPT_PINNEDPUBLICKEY:
  1809. /*
  1810. * Set pinned public key for SSL connection.
  1811. * Specify file name of the public key in DER format.
  1812. */
  1813. #ifdef USE_SSL
  1814. if(Curl_ssl->supports & SSLSUPP_PINNEDPUBKEY)
  1815. result = Curl_setstropt(&data->set.str[STRING_SSL_PINNEDPUBLICKEY_ORIG],
  1816. va_arg(param, char *));
  1817. else
  1818. #endif
  1819. result = CURLE_NOT_BUILT_IN;
  1820. break;
  1821. #ifndef CURL_DISABLE_PROXY
  1822. case CURLOPT_PROXY_PINNEDPUBLICKEY:
  1823. /*
  1824. * Set pinned public key for SSL connection.
  1825. * Specify file name of the public key in DER format.
  1826. */
  1827. #ifdef USE_SSL
  1828. if(Curl_ssl->supports & SSLSUPP_PINNEDPUBKEY)
  1829. result = Curl_setstropt(&data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY],
  1830. va_arg(param, char *));
  1831. else
  1832. #endif
  1833. result = CURLE_NOT_BUILT_IN;
  1834. break;
  1835. #endif
  1836. case CURLOPT_CAINFO:
  1837. /*
  1838. * Set CA info for SSL connection. Specify file name of the CA certificate
  1839. */
  1840. result = Curl_setstropt(&data->set.str[STRING_SSL_CAFILE_ORIG],
  1841. va_arg(param, char *));
  1842. break;
  1843. #ifndef CURL_DISABLE_PROXY
  1844. case CURLOPT_PROXY_CAINFO:
  1845. /*
  1846. * Set CA info SSL connection for proxy. Specify file name of the
  1847. * CA certificate
  1848. */
  1849. result = Curl_setstropt(&data->set.str[STRING_SSL_CAFILE_PROXY],
  1850. va_arg(param, char *));
  1851. break;
  1852. #endif
  1853. case CURLOPT_CAPATH:
  1854. /*
  1855. * Set CA path info for SSL connection. Specify directory name of the CA
  1856. * certificates which have been prepared using openssl c_rehash utility.
  1857. */
  1858. #ifdef USE_SSL
  1859. if(Curl_ssl->supports & SSLSUPP_CA_PATH)
  1860. /* This does not work on windows. */
  1861. result = Curl_setstropt(&data->set.str[STRING_SSL_CAPATH_ORIG],
  1862. va_arg(param, char *));
  1863. else
  1864. #endif
  1865. result = CURLE_NOT_BUILT_IN;
  1866. break;
  1867. #ifndef CURL_DISABLE_PROXY
  1868. case CURLOPT_PROXY_CAPATH:
  1869. /*
  1870. * Set CA path info for SSL connection proxy. Specify directory name of the
  1871. * CA certificates which have been prepared using openssl c_rehash utility.
  1872. */
  1873. #ifdef USE_SSL
  1874. if(Curl_ssl->supports & SSLSUPP_CA_PATH)
  1875. /* This does not work on windows. */
  1876. result = Curl_setstropt(&data->set.str[STRING_SSL_CAPATH_PROXY],
  1877. va_arg(param, char *));
  1878. else
  1879. #endif
  1880. result = CURLE_NOT_BUILT_IN;
  1881. break;
  1882. #endif
  1883. case CURLOPT_CRLFILE:
  1884. /*
  1885. * Set CRL file info for SSL connection. Specify file name of the CRL
  1886. * to check certificates revocation
  1887. */
  1888. result = Curl_setstropt(&data->set.str[STRING_SSL_CRLFILE_ORIG],
  1889. va_arg(param, char *));
  1890. break;
  1891. #ifndef CURL_DISABLE_PROXY
  1892. case CURLOPT_PROXY_CRLFILE:
  1893. /*
  1894. * Set CRL file info for SSL connection for proxy. Specify file name of the
  1895. * CRL to check certificates revocation
  1896. */
  1897. result = Curl_setstropt(&data->set.str[STRING_SSL_CRLFILE_PROXY],
  1898. va_arg(param, char *));
  1899. break;
  1900. #endif
  1901. case CURLOPT_ISSUERCERT:
  1902. /*
  1903. * Set Issuer certificate file
  1904. * to check certificates issuer
  1905. */
  1906. result = Curl_setstropt(&data->set.str[STRING_SSL_ISSUERCERT_ORIG],
  1907. va_arg(param, char *));
  1908. break;
  1909. case CURLOPT_ISSUERCERT_BLOB:
  1910. /*
  1911. * Blob that holds Issuer certificate to check certificates issuer
  1912. */
  1913. result = Curl_setblobopt(&data->set.blobs[BLOB_SSL_ISSUERCERT_ORIG],
  1914. va_arg(param, struct curl_blob *));
  1915. break;
  1916. #ifndef CURL_DISABLE_PROXY
  1917. case CURLOPT_PROXY_ISSUERCERT:
  1918. /*
  1919. * Set Issuer certificate file
  1920. * to check certificates issuer
  1921. */
  1922. result = Curl_setstropt(&data->set.str[STRING_SSL_ISSUERCERT_PROXY],
  1923. va_arg(param, char *));
  1924. break;
  1925. case CURLOPT_PROXY_ISSUERCERT_BLOB:
  1926. /*
  1927. * Blob that holds Issuer certificate to check certificates issuer
  1928. */
  1929. result = Curl_setblobopt(&data->set.blobs[BLOB_SSL_ISSUERCERT_PROXY],
  1930. va_arg(param, struct curl_blob *));
  1931. break;
  1932. #endif
  1933. #ifndef CURL_DISABLE_TELNET
  1934. case CURLOPT_TELNETOPTIONS:
  1935. /*
  1936. * Set a linked list of telnet options
  1937. */
  1938. data->set.telnet_options = va_arg(param, struct curl_slist *);
  1939. break;
  1940. #endif
  1941. case CURLOPT_BUFFERSIZE:
  1942. /*
  1943. * The application kindly asks for a differently sized receive buffer.
  1944. * If it seems reasonable, we'll use it.
  1945. */
  1946. if(data->state.buffer)
  1947. return CURLE_BAD_FUNCTION_ARGUMENT;
  1948. arg = va_arg(param, long);
  1949. if(arg > READBUFFER_MAX)
  1950. arg = READBUFFER_MAX;
  1951. else if(arg < 1)
  1952. arg = READBUFFER_SIZE;
  1953. else if(arg < READBUFFER_MIN)
  1954. arg = READBUFFER_MIN;
  1955. data->set.buffer_size = arg;
  1956. break;
  1957. case CURLOPT_UPLOAD_BUFFERSIZE:
  1958. /*
  1959. * The application kindly asks for a differently sized upload buffer.
  1960. * Cap it to sensible.
  1961. */
  1962. arg = va_arg(param, long);
  1963. if(arg > UPLOADBUFFER_MAX)
  1964. arg = UPLOADBUFFER_MAX;
  1965. else if(arg < UPLOADBUFFER_MIN)
  1966. arg = UPLOADBUFFER_MIN;
  1967. data->set.upload_buffer_size = arg;
  1968. Curl_safefree(data->state.ulbuf); /* force a realloc next opportunity */
  1969. break;
  1970. case CURLOPT_NOSIGNAL:
  1971. /*
  1972. * The application asks not to set any signal() or alarm() handlers,
  1973. * even when using a timeout.
  1974. */
  1975. data->set.no_signal = (0 != va_arg(param, long)) ? TRUE : FALSE;
  1976. break;
  1977. case CURLOPT_SHARE:
  1978. {
  1979. struct Curl_share *set;
  1980. set = va_arg(param, struct Curl_share *);
  1981. /* disconnect from old share, if any */
  1982. if(data->share) {
  1983. Curl_share_lock(data, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE);
  1984. if(data->dns.hostcachetype == HCACHE_SHARED) {
  1985. data->dns.hostcache = NULL;
  1986. data->dns.hostcachetype = HCACHE_NONE;
  1987. }
  1988. #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
  1989. if(data->share->cookies == data->cookies)
  1990. data->cookies = NULL;
  1991. #endif
  1992. if(data->share->sslsession == data->state.session)
  1993. data->state.session = NULL;
  1994. #ifdef USE_LIBPSL
  1995. if(data->psl == &data->share->psl)
  1996. data->psl = data->multi? &data->multi->psl: NULL;
  1997. #endif
  1998. data->share->dirty--;
  1999. Curl_share_unlock(data, CURL_LOCK_DATA_SHARE);
  2000. data->share = NULL;
  2001. }
  2002. /* use new share if it set */
  2003. data->share = set;
  2004. if(data->share) {
  2005. Curl_share_lock(data, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE);
  2006. data->share->dirty++;
  2007. if(data->share->specifier & (1<< CURL_LOCK_DATA_DNS)) {
  2008. /* use shared host cache */
  2009. data->dns.hostcache = &data->share->hostcache;
  2010. data->dns.hostcachetype = HCACHE_SHARED;
  2011. }
  2012. #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
  2013. if(data->share->cookies) {
  2014. /* use shared cookie list, first free own one if any */
  2015. Curl_cookie_cleanup(data->cookies);
  2016. /* enable cookies since we now use a share that uses cookies! */
  2017. data->cookies = data->share->cookies;
  2018. }
  2019. #endif /* CURL_DISABLE_HTTP */
  2020. if(data->share->sslsession) {
  2021. data->set.general_ssl.max_ssl_sessions = data->share->max_ssl_sessions;
  2022. data->state.session = data->share->sslsession;
  2023. }
  2024. #ifdef USE_LIBPSL
  2025. if(data->share->specifier & (1 << CURL_LOCK_DATA_PSL))
  2026. data->psl = &data->share->psl;
  2027. #endif
  2028. Curl_share_unlock(data, CURL_LOCK_DATA_SHARE);
  2029. }
  2030. /* check for host cache not needed,
  2031. * it will be done by curl_easy_perform */
  2032. }
  2033. break;
  2034. case CURLOPT_PRIVATE:
  2035. /*
  2036. * Set private data pointer.
  2037. */
  2038. data->set.private_data = va_arg(param, void *);
  2039. break;
  2040. case CURLOPT_MAXFILESIZE:
  2041. /*
  2042. * Set the maximum size of a file to download.
  2043. */
  2044. arg = va_arg(param, long);
  2045. if(arg < 0)
  2046. return CURLE_BAD_FUNCTION_ARGUMENT;
  2047. data->set.max_filesize = arg;
  2048. break;
  2049. #ifdef USE_SSL
  2050. case CURLOPT_USE_SSL:
  2051. /*
  2052. * Make transfers attempt to use SSL/TLS.
  2053. */
  2054. arg = va_arg(param, long);
  2055. if((arg < CURLUSESSL_NONE) || (arg >= CURLUSESSL_LAST))
  2056. return CURLE_BAD_FUNCTION_ARGUMENT;
  2057. data->set.use_ssl = (curl_usessl)arg;
  2058. break;
  2059. case CURLOPT_SSL_OPTIONS:
  2060. arg = va_arg(param, long);
  2061. data->set.ssl.enable_beast =
  2062. (bool)((arg&CURLSSLOPT_ALLOW_BEAST) ? TRUE : FALSE);
  2063. data->set.ssl.no_revoke = !!(arg & CURLSSLOPT_NO_REVOKE);
  2064. data->set.ssl.no_partialchain = !!(arg & CURLSSLOPT_NO_PARTIALCHAIN);
  2065. data->set.ssl.revoke_best_effort = !!(arg & CURLSSLOPT_REVOKE_BEST_EFFORT);
  2066. data->set.ssl.native_ca_store = !!(arg & CURLSSLOPT_NATIVE_CA);
  2067. break;
  2068. #ifndef CURL_DISABLE_PROXY
  2069. case CURLOPT_PROXY_SSL_OPTIONS:
  2070. arg = va_arg(param, long);
  2071. data->set.proxy_ssl.enable_beast =
  2072. (bool)((arg&CURLSSLOPT_ALLOW_BEAST) ? TRUE : FALSE);
  2073. data->set.proxy_ssl.no_revoke = !!(arg & CURLSSLOPT_NO_REVOKE);
  2074. data->set.proxy_ssl.no_partialchain = !!(arg & CURLSSLOPT_NO_PARTIALCHAIN);
  2075. data->set.proxy_ssl.native_ca_store = !!(arg & CURLSSLOPT_NATIVE_CA);
  2076. data->set.proxy_ssl.revoke_best_effort =
  2077. !!(arg & CURLSSLOPT_REVOKE_BEST_EFFORT);
  2078. break;
  2079. #endif
  2080. case CURLOPT_SSL_EC_CURVES:
  2081. /*
  2082. * Set accepted curves in SSL connection setup.
  2083. * Specify colon-delimited list of curve algorithm names.
  2084. */
  2085. result = Curl_setstropt(&data->set.str[STRING_SSL_EC_CURVES],
  2086. va_arg(param, char *));
  2087. break;
  2088. #endif
  2089. case CURLOPT_IPRESOLVE:
  2090. arg = va_arg(param, long);
  2091. if((arg < CURL_IPRESOLVE_WHATEVER) || (arg > CURL_IPRESOLVE_V6))
  2092. return CURLE_BAD_FUNCTION_ARGUMENT;
  2093. data->set.ipver = arg;
  2094. break;
  2095. case CURLOPT_MAXFILESIZE_LARGE:
  2096. /*
  2097. * Set the maximum size of a file to download.
  2098. */
  2099. bigsize = va_arg(param, curl_off_t);
  2100. if(bigsize < 0)
  2101. return CURLE_BAD_FUNCTION_ARGUMENT;
  2102. data->set.max_filesize = bigsize;
  2103. break;
  2104. case CURLOPT_TCP_NODELAY:
  2105. /*
  2106. * Enable or disable TCP_NODELAY, which will disable/enable the Nagle
  2107. * algorithm
  2108. */
  2109. data->set.tcp_nodelay = (0 != va_arg(param, long)) ? TRUE : FALSE;
  2110. break;
  2111. case CURLOPT_IGNORE_CONTENT_LENGTH:
  2112. data->set.ignorecl = (0 != va_arg(param, long)) ? TRUE : FALSE;
  2113. break;
  2114. case CURLOPT_CONNECT_ONLY:
  2115. /*
  2116. * No data transfer, set up connection and let application use the socket
  2117. */
  2118. data->set.connect_only = (0 != va_arg(param, long)) ? TRUE : FALSE;
  2119. break;
  2120. case CURLOPT_SOCKOPTFUNCTION:
  2121. /*
  2122. * socket callback function: called after socket() but before connect()
  2123. */
  2124. data->set.fsockopt = va_arg(param, curl_sockopt_callback);
  2125. break;
  2126. case CURLOPT_SOCKOPTDATA:
  2127. /*
  2128. * socket callback data pointer. Might be NULL.
  2129. */
  2130. data->set.sockopt_client = va_arg(param, void *);
  2131. break;
  2132. case CURLOPT_OPENSOCKETFUNCTION:
  2133. /*
  2134. * open/create socket callback function: called instead of socket(),
  2135. * before connect()
  2136. */
  2137. data->set.fopensocket = va_arg(param, curl_opensocket_callback);
  2138. break;
  2139. case CURLOPT_OPENSOCKETDATA:
  2140. /*
  2141. * socket callback data pointer. Might be NULL.
  2142. */
  2143. data->set.opensocket_client = va_arg(param, void *);
  2144. break;
  2145. case CURLOPT_CLOSESOCKETFUNCTION:
  2146. /*
  2147. * close socket callback function: called instead of close()
  2148. * when shutting down a connection
  2149. */
  2150. data->set.fclosesocket = va_arg(param, curl_closesocket_callback);
  2151. break;
  2152. case CURLOPT_RESOLVER_START_FUNCTION:
  2153. /*
  2154. * resolver start callback function: called before a new resolver request
  2155. * is started
  2156. */
  2157. data->set.resolver_start = va_arg(param, curl_resolver_start_callback);
  2158. break;
  2159. case CURLOPT_RESOLVER_START_DATA:
  2160. /*
  2161. * resolver start callback data pointer. Might be NULL.
  2162. */
  2163. data->set.resolver_start_client = va_arg(param, void *);
  2164. break;
  2165. case CURLOPT_CLOSESOCKETDATA:
  2166. /*
  2167. * socket callback data pointer. Might be NULL.
  2168. */
  2169. data->set.closesocket_client = va_arg(param, void *);
  2170. break;
  2171. case CURLOPT_SSL_SESSIONID_CACHE:
  2172. data->set.ssl.primary.sessionid = (0 != va_arg(param, long)) ?
  2173. TRUE : FALSE;
  2174. #ifndef CURL_DISABLE_PROXY
  2175. data->set.proxy_ssl.primary.sessionid = data->set.ssl.primary.sessionid;
  2176. #endif
  2177. break;
  2178. #ifdef USE_SSH
  2179. /* we only include SSH options if explicitly built to support SSH */
  2180. case CURLOPT_SSH_AUTH_TYPES:
  2181. data->set.ssh_auth_types = va_arg(param, long);
  2182. break;
  2183. case CURLOPT_SSH_PUBLIC_KEYFILE:
  2184. /*
  2185. * Use this file instead of the $HOME/.ssh/id_dsa.pub file
  2186. */
  2187. result = Curl_setstropt(&data->set.str[STRING_SSH_PUBLIC_KEY],
  2188. va_arg(param, char *));
  2189. break;
  2190. case CURLOPT_SSH_PRIVATE_KEYFILE:
  2191. /*
  2192. * Use this file instead of the $HOME/.ssh/id_dsa file
  2193. */
  2194. result = Curl_setstropt(&data->set.str[STRING_SSH_PRIVATE_KEY],
  2195. va_arg(param, char *));
  2196. break;
  2197. case CURLOPT_SSH_HOST_PUBLIC_KEY_MD5:
  2198. /*
  2199. * Option to allow for the MD5 of the host public key to be checked
  2200. * for validation purposes.
  2201. */
  2202. result = Curl_setstropt(&data->set.str[STRING_SSH_HOST_PUBLIC_KEY_MD5],
  2203. va_arg(param, char *));
  2204. break;
  2205. case CURLOPT_SSH_KNOWNHOSTS:
  2206. /*
  2207. * Store the file name to read known hosts from.
  2208. */
  2209. result = Curl_setstropt(&data->set.str[STRING_SSH_KNOWNHOSTS],
  2210. va_arg(param, char *));
  2211. break;
  2212. case CURLOPT_SSH_KEYFUNCTION:
  2213. /* setting to NULL is fine since the ssh.c functions themselves will
  2214. then revert to use the internal default */
  2215. data->set.ssh_keyfunc = va_arg(param, curl_sshkeycallback);
  2216. break;
  2217. case CURLOPT_SSH_KEYDATA:
  2218. /*
  2219. * Custom client data to pass to the SSH keyfunc callback
  2220. */
  2221. data->set.ssh_keyfunc_userp = va_arg(param, void *);
  2222. break;
  2223. case CURLOPT_SSH_COMPRESSION:
  2224. data->set.ssh_compression = (0 != va_arg(param, long))?TRUE:FALSE;
  2225. break;
  2226. #endif /* USE_SSH */
  2227. case CURLOPT_HTTP_TRANSFER_DECODING:
  2228. /*
  2229. * disable libcurl transfer encoding is used
  2230. */
  2231. data->set.http_te_skip = (0 == va_arg(param, long)) ? TRUE : FALSE;
  2232. break;
  2233. case CURLOPT_HTTP_CONTENT_DECODING:
  2234. /*
  2235. * raw data passed to the application when content encoding is used
  2236. */
  2237. data->set.http_ce_skip = (0 == va_arg(param, long)) ? TRUE : FALSE;
  2238. break;
  2239. #if !defined(CURL_DISABLE_FTP) || defined(USE_SSH)
  2240. case CURLOPT_NEW_FILE_PERMS:
  2241. /*
  2242. * Uses these permissions instead of 0644
  2243. */
  2244. arg = va_arg(param, long);
  2245. if((arg < 0) || (arg > 0777))
  2246. return CURLE_BAD_FUNCTION_ARGUMENT;
  2247. data->set.new_file_perms = arg;
  2248. break;
  2249. case CURLOPT_NEW_DIRECTORY_PERMS:
  2250. /*
  2251. * Uses these permissions instead of 0755
  2252. */
  2253. arg = va_arg(param, long);
  2254. if((arg < 0) || (arg > 0777))
  2255. return CURLE_BAD_FUNCTION_ARGUMENT;
  2256. data->set.new_directory_perms = arg;
  2257. break;
  2258. #endif
  2259. case CURLOPT_ADDRESS_SCOPE:
  2260. /*
  2261. * Use this scope id when using IPv6
  2262. * We always get longs when passed plain numericals so we should check
  2263. * that the value fits into an unsigned 32 bit integer.
  2264. */
  2265. uarg = va_arg(param, unsigned long);
  2266. #if SIZEOF_LONG > 4
  2267. if(uarg > UINT_MAX)
  2268. return CURLE_BAD_FUNCTION_ARGUMENT;
  2269. #endif
  2270. data->set.scope_id = (unsigned int)uarg;
  2271. break;
  2272. case CURLOPT_PROTOCOLS:
  2273. /* set the bitmask for the protocols that are allowed to be used for the
  2274. transfer, which thus helps the app which takes URLs from users or other
  2275. external inputs and want to restrict what protocol(s) to deal
  2276. with. Defaults to CURLPROTO_ALL. */
  2277. data->set.allowed_protocols = va_arg(param, long);
  2278. break;
  2279. case CURLOPT_REDIR_PROTOCOLS:
  2280. /* set the bitmask for the protocols that libcurl is allowed to follow to,
  2281. as a subset of the CURLOPT_PROTOCOLS ones. That means the protocol needs
  2282. to be set in both bitmasks to be allowed to get redirected to. */
  2283. data->set.redir_protocols = va_arg(param, long);
  2284. break;
  2285. case CURLOPT_DEFAULT_PROTOCOL:
  2286. /* Set the protocol to use when the URL doesn't include any protocol */
  2287. result = Curl_setstropt(&data->set.str[STRING_DEFAULT_PROTOCOL],
  2288. va_arg(param, char *));
  2289. break;
  2290. #ifndef CURL_DISABLE_SMTP
  2291. case CURLOPT_MAIL_FROM:
  2292. /* Set the SMTP mail originator */
  2293. result = Curl_setstropt(&data->set.str[STRING_MAIL_FROM],
  2294. va_arg(param, char *));
  2295. break;
  2296. case CURLOPT_MAIL_AUTH:
  2297. /* Set the SMTP auth originator */
  2298. result = Curl_setstropt(&data->set.str[STRING_MAIL_AUTH],
  2299. va_arg(param, char *));
  2300. break;
  2301. case CURLOPT_MAIL_RCPT:
  2302. /* Set the list of mail recipients */
  2303. data->set.mail_rcpt = va_arg(param, struct curl_slist *);
  2304. break;
  2305. case CURLOPT_MAIL_RCPT_ALLLOWFAILS:
  2306. /* allow RCPT TO command to fail for some recipients */
  2307. data->set.mail_rcpt_allowfails = (0 != va_arg(param, long)) ? TRUE : FALSE;
  2308. break;
  2309. #endif
  2310. case CURLOPT_SASL_AUTHZID:
  2311. /* Authorisation identity (identity to act as) */
  2312. result = Curl_setstropt(&data->set.str[STRING_SASL_AUTHZID],
  2313. va_arg(param, char *));
  2314. break;
  2315. case CURLOPT_SASL_IR:
  2316. /* Enable/disable SASL initial response */
  2317. data->set.sasl_ir = (0 != va_arg(param, long)) ? TRUE : FALSE;
  2318. break;
  2319. #ifndef CURL_DISABLE_RTSP
  2320. case CURLOPT_RTSP_REQUEST:
  2321. {
  2322. /*
  2323. * Set the RTSP request method (OPTIONS, SETUP, PLAY, etc...)
  2324. * Would this be better if the RTSPREQ_* were just moved into here?
  2325. */
  2326. long curl_rtspreq = va_arg(param, long);
  2327. Curl_RtspReq rtspreq = RTSPREQ_NONE;
  2328. switch(curl_rtspreq) {
  2329. case CURL_RTSPREQ_OPTIONS:
  2330. rtspreq = RTSPREQ_OPTIONS;
  2331. break;
  2332. case CURL_RTSPREQ_DESCRIBE:
  2333. rtspreq = RTSPREQ_DESCRIBE;
  2334. break;
  2335. case CURL_RTSPREQ_ANNOUNCE:
  2336. rtspreq = RTSPREQ_ANNOUNCE;
  2337. break;
  2338. case CURL_RTSPREQ_SETUP:
  2339. rtspreq = RTSPREQ_SETUP;
  2340. break;
  2341. case CURL_RTSPREQ_PLAY:
  2342. rtspreq = RTSPREQ_PLAY;
  2343. break;
  2344. case CURL_RTSPREQ_PAUSE:
  2345. rtspreq = RTSPREQ_PAUSE;
  2346. break;
  2347. case CURL_RTSPREQ_TEARDOWN:
  2348. rtspreq = RTSPREQ_TEARDOWN;
  2349. break;
  2350. case CURL_RTSPREQ_GET_PARAMETER:
  2351. rtspreq = RTSPREQ_GET_PARAMETER;
  2352. break;
  2353. case CURL_RTSPREQ_SET_PARAMETER:
  2354. rtspreq = RTSPREQ_SET_PARAMETER;
  2355. break;
  2356. case CURL_RTSPREQ_RECORD:
  2357. rtspreq = RTSPREQ_RECORD;
  2358. break;
  2359. case CURL_RTSPREQ_RECEIVE:
  2360. rtspreq = RTSPREQ_RECEIVE;
  2361. break;
  2362. default:
  2363. rtspreq = RTSPREQ_NONE;
  2364. }
  2365. data->set.rtspreq = rtspreq;
  2366. break;
  2367. }
  2368. case CURLOPT_RTSP_SESSION_ID:
  2369. /*
  2370. * Set the RTSP Session ID manually. Useful if the application is
  2371. * resuming a previously established RTSP session
  2372. */
  2373. result = Curl_setstropt(&data->set.str[STRING_RTSP_SESSION_ID],
  2374. va_arg(param, char *));
  2375. break;
  2376. case CURLOPT_RTSP_STREAM_URI:
  2377. /*
  2378. * Set the Stream URI for the RTSP request. Unless the request is
  2379. * for generic server options, the application will need to set this.
  2380. */
  2381. result = Curl_setstropt(&data->set.str[STRING_RTSP_STREAM_URI],
  2382. va_arg(param, char *));
  2383. break;
  2384. case CURLOPT_RTSP_TRANSPORT:
  2385. /*
  2386. * The content of the Transport: header for the RTSP request
  2387. */
  2388. result = Curl_setstropt(&data->set.str[STRING_RTSP_TRANSPORT],
  2389. va_arg(param, char *));
  2390. break;
  2391. case CURLOPT_RTSP_CLIENT_CSEQ:
  2392. /*
  2393. * Set the CSEQ number to issue for the next RTSP request. Useful if the
  2394. * application is resuming a previously broken connection. The CSEQ
  2395. * will increment from this new number henceforth.
  2396. */
  2397. data->state.rtsp_next_client_CSeq = va_arg(param, long);
  2398. break;
  2399. case CURLOPT_RTSP_SERVER_CSEQ:
  2400. /* Same as the above, but for server-initiated requests */
  2401. data->state.rtsp_next_server_CSeq = va_arg(param, long);
  2402. break;
  2403. case CURLOPT_INTERLEAVEDATA:
  2404. data->set.rtp_out = va_arg(param, void *);
  2405. break;
  2406. case CURLOPT_INTERLEAVEFUNCTION:
  2407. /* Set the user defined RTP write function */
  2408. data->set.fwrite_rtp = va_arg(param, curl_write_callback);
  2409. break;
  2410. #endif
  2411. #ifndef CURL_DISABLE_FTP
  2412. case CURLOPT_WILDCARDMATCH:
  2413. data->set.wildcard_enabled = (0 != va_arg(param, long)) ? TRUE : FALSE;
  2414. break;
  2415. case CURLOPT_CHUNK_BGN_FUNCTION:
  2416. data->set.chunk_bgn = va_arg(param, curl_chunk_bgn_callback);
  2417. break;
  2418. case CURLOPT_CHUNK_END_FUNCTION:
  2419. data->set.chunk_end = va_arg(param, curl_chunk_end_callback);
  2420. break;
  2421. case CURLOPT_FNMATCH_FUNCTION:
  2422. data->set.fnmatch = va_arg(param, curl_fnmatch_callback);
  2423. break;
  2424. case CURLOPT_CHUNK_DATA:
  2425. data->wildcard.customptr = va_arg(param, void *);
  2426. break;
  2427. case CURLOPT_FNMATCH_DATA:
  2428. data->set.fnmatch_data = va_arg(param, void *);
  2429. break;
  2430. #endif
  2431. #ifdef USE_TLS_SRP
  2432. case CURLOPT_TLSAUTH_USERNAME:
  2433. result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_USERNAME_ORIG],
  2434. va_arg(param, char *));
  2435. if(data->set.str[STRING_TLSAUTH_USERNAME_ORIG] && !data->set.ssl.authtype)
  2436. data->set.ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */
  2437. break;
  2438. case CURLOPT_PROXY_TLSAUTH_USERNAME:
  2439. result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_USERNAME_PROXY],
  2440. va_arg(param, char *));
  2441. #ifndef CURL_DISABLE_PROXY
  2442. if(data->set.str[STRING_TLSAUTH_USERNAME_PROXY] &&
  2443. !data->set.proxy_ssl.authtype)
  2444. data->set.proxy_ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */
  2445. #endif
  2446. break;
  2447. case CURLOPT_TLSAUTH_PASSWORD:
  2448. result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_PASSWORD_ORIG],
  2449. va_arg(param, char *));
  2450. if(data->set.str[STRING_TLSAUTH_USERNAME_ORIG] && !data->set.ssl.authtype)
  2451. data->set.ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */
  2452. break;
  2453. case CURLOPT_PROXY_TLSAUTH_PASSWORD:
  2454. result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_PASSWORD_PROXY],
  2455. va_arg(param, char *));
  2456. #ifndef CURL_DISABLE_PROXY
  2457. if(data->set.str[STRING_TLSAUTH_USERNAME_PROXY] &&
  2458. !data->set.proxy_ssl.authtype)
  2459. data->set.proxy_ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */
  2460. #endif
  2461. break;
  2462. case CURLOPT_TLSAUTH_TYPE:
  2463. argptr = va_arg(param, char *);
  2464. if(!argptr ||
  2465. strncasecompare(argptr, "SRP", strlen("SRP")))
  2466. data->set.ssl.authtype = CURL_TLSAUTH_SRP;
  2467. else
  2468. data->set.ssl.authtype = CURL_TLSAUTH_NONE;
  2469. break;
  2470. #ifndef CURL_DISABLE_PROXY
  2471. case CURLOPT_PROXY_TLSAUTH_TYPE:
  2472. argptr = va_arg(param, char *);
  2473. if(!argptr ||
  2474. strncasecompare(argptr, "SRP", strlen("SRP")))
  2475. data->set.proxy_ssl.authtype = CURL_TLSAUTH_SRP;
  2476. else
  2477. data->set.proxy_ssl.authtype = CURL_TLSAUTH_NONE;
  2478. break;
  2479. #endif
  2480. #endif
  2481. #ifdef USE_ARES
  2482. case CURLOPT_DNS_SERVERS:
  2483. result = Curl_setstropt(&data->set.str[STRING_DNS_SERVERS],
  2484. va_arg(param, char *));
  2485. if(result)
  2486. return result;
  2487. result = Curl_set_dns_servers(data, data->set.str[STRING_DNS_SERVERS]);
  2488. break;
  2489. case CURLOPT_DNS_INTERFACE:
  2490. result = Curl_setstropt(&data->set.str[STRING_DNS_INTERFACE],
  2491. va_arg(param, char *));
  2492. if(result)
  2493. return result;
  2494. result = Curl_set_dns_interface(data, data->set.str[STRING_DNS_INTERFACE]);
  2495. break;
  2496. case CURLOPT_DNS_LOCAL_IP4:
  2497. result = Curl_setstropt(&data->set.str[STRING_DNS_LOCAL_IP4],
  2498. va_arg(param, char *));
  2499. if(result)
  2500. return result;
  2501. result = Curl_set_dns_local_ip4(data, data->set.str[STRING_DNS_LOCAL_IP4]);
  2502. break;
  2503. case CURLOPT_DNS_LOCAL_IP6:
  2504. result = Curl_setstropt(&data->set.str[STRING_DNS_LOCAL_IP6],
  2505. va_arg(param, char *));
  2506. if(result)
  2507. return result;
  2508. result = Curl_set_dns_local_ip6(data, data->set.str[STRING_DNS_LOCAL_IP6]);
  2509. break;
  2510. #endif
  2511. case CURLOPT_TCP_KEEPALIVE:
  2512. data->set.tcp_keepalive = (0 != va_arg(param, long)) ? TRUE : FALSE;
  2513. break;
  2514. case CURLOPT_TCP_KEEPIDLE:
  2515. arg = va_arg(param, long);
  2516. if(arg < 0)
  2517. return CURLE_BAD_FUNCTION_ARGUMENT;
  2518. data->set.tcp_keepidle = arg;
  2519. break;
  2520. case CURLOPT_TCP_KEEPINTVL:
  2521. arg = va_arg(param, long);
  2522. if(arg < 0)
  2523. return CURLE_BAD_FUNCTION_ARGUMENT;
  2524. data->set.tcp_keepintvl = arg;
  2525. break;
  2526. case CURLOPT_TCP_FASTOPEN:
  2527. #if defined(CONNECT_DATA_IDEMPOTENT) || defined(MSG_FASTOPEN) || \
  2528. defined(TCP_FASTOPEN_CONNECT)
  2529. data->set.tcp_fastopen = (0 != va_arg(param, long))?TRUE:FALSE;
  2530. #else
  2531. result = CURLE_NOT_BUILT_IN;
  2532. #endif
  2533. break;
  2534. case CURLOPT_SSL_ENABLE_NPN:
  2535. data->set.ssl_enable_npn = (0 != va_arg(param, long)) ? TRUE : FALSE;
  2536. break;
  2537. case CURLOPT_SSL_ENABLE_ALPN:
  2538. data->set.ssl_enable_alpn = (0 != va_arg(param, long)) ? TRUE : FALSE;
  2539. break;
  2540. #ifdef USE_UNIX_SOCKETS
  2541. case CURLOPT_UNIX_SOCKET_PATH:
  2542. data->set.abstract_unix_socket = FALSE;
  2543. result = Curl_setstropt(&data->set.str[STRING_UNIX_SOCKET_PATH],
  2544. va_arg(param, char *));
  2545. break;
  2546. case CURLOPT_ABSTRACT_UNIX_SOCKET:
  2547. data->set.abstract_unix_socket = TRUE;
  2548. result = Curl_setstropt(&data->set.str[STRING_UNIX_SOCKET_PATH],
  2549. va_arg(param, char *));
  2550. break;
  2551. #endif
  2552. case CURLOPT_PATH_AS_IS:
  2553. data->set.path_as_is = (0 != va_arg(param, long)) ? TRUE : FALSE;
  2554. break;
  2555. case CURLOPT_PIPEWAIT:
  2556. data->set.pipewait = (0 != va_arg(param, long)) ? TRUE : FALSE;
  2557. break;
  2558. case CURLOPT_STREAM_WEIGHT:
  2559. #ifndef USE_NGHTTP2
  2560. return CURLE_NOT_BUILT_IN;
  2561. #else
  2562. arg = va_arg(param, long);
  2563. if((arg >= 1) && (arg <= 256))
  2564. data->set.stream_weight = (int)arg;
  2565. break;
  2566. #endif
  2567. case CURLOPT_STREAM_DEPENDS:
  2568. case CURLOPT_STREAM_DEPENDS_E:
  2569. {
  2570. #ifndef USE_NGHTTP2
  2571. return CURLE_NOT_BUILT_IN;
  2572. #else
  2573. struct Curl_easy *dep = va_arg(param, struct Curl_easy *);
  2574. if(!dep || GOOD_EASY_HANDLE(dep)) {
  2575. if(data->set.stream_depends_on) {
  2576. Curl_http2_remove_child(data->set.stream_depends_on, data);
  2577. }
  2578. Curl_http2_add_child(dep, data, (option == CURLOPT_STREAM_DEPENDS_E));
  2579. }
  2580. break;
  2581. #endif
  2582. }
  2583. case CURLOPT_CONNECT_TO:
  2584. data->set.connect_to = va_arg(param, struct curl_slist *);
  2585. break;
  2586. case CURLOPT_SUPPRESS_CONNECT_HEADERS:
  2587. data->set.suppress_connect_headers = (0 != va_arg(param, long))?TRUE:FALSE;
  2588. break;
  2589. case CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS:
  2590. arg = va_arg(param, long);
  2591. if(arg < 0)
  2592. return CURLE_BAD_FUNCTION_ARGUMENT;
  2593. data->set.happy_eyeballs_timeout = arg;
  2594. break;
  2595. #ifndef CURL_DISABLE_SHUFFLE_DNS
  2596. case CURLOPT_DNS_SHUFFLE_ADDRESSES:
  2597. data->set.dns_shuffle_addresses = (0 != va_arg(param, long)) ? TRUE:FALSE;
  2598. break;
  2599. #endif
  2600. case CURLOPT_DISALLOW_USERNAME_IN_URL:
  2601. data->set.disallow_username_in_url =
  2602. (0 != va_arg(param, long)) ? TRUE : FALSE;
  2603. break;
  2604. #ifndef CURL_DISABLE_DOH
  2605. case CURLOPT_DOH_URL:
  2606. result = Curl_setstropt(&data->set.str[STRING_DOH],
  2607. va_arg(param, char *));
  2608. data->set.doh = data->set.str[STRING_DOH]?TRUE:FALSE;
  2609. break;
  2610. #endif
  2611. case CURLOPT_UPKEEP_INTERVAL_MS:
  2612. arg = va_arg(param, long);
  2613. if(arg < 0)
  2614. return CURLE_BAD_FUNCTION_ARGUMENT;
  2615. data->set.upkeep_interval_ms = arg;
  2616. break;
  2617. case CURLOPT_MAXAGE_CONN:
  2618. arg = va_arg(param, long);
  2619. if(arg < 0)
  2620. return CURLE_BAD_FUNCTION_ARGUMENT;
  2621. data->set.maxage_conn = arg;
  2622. break;
  2623. case CURLOPT_TRAILERFUNCTION:
  2624. #ifndef CURL_DISABLE_HTTP
  2625. data->set.trailer_callback = va_arg(param, curl_trailer_callback);
  2626. #endif
  2627. break;
  2628. case CURLOPT_TRAILERDATA:
  2629. #ifndef CURL_DISABLE_HTTP
  2630. data->set.trailer_data = va_arg(param, void *);
  2631. #endif
  2632. break;
  2633. #ifdef USE_ALTSVC
  2634. case CURLOPT_ALTSVC:
  2635. if(!data->asi) {
  2636. data->asi = Curl_altsvc_init();
  2637. if(!data->asi)
  2638. return CURLE_OUT_OF_MEMORY;
  2639. }
  2640. argptr = va_arg(param, char *);
  2641. result = Curl_setstropt(&data->set.str[STRING_ALTSVC], argptr);
  2642. if(result)
  2643. return result;
  2644. if(argptr)
  2645. (void)Curl_altsvc_load(data->asi, argptr);
  2646. break;
  2647. case CURLOPT_ALTSVC_CTRL:
  2648. if(!data->asi) {
  2649. data->asi = Curl_altsvc_init();
  2650. if(!data->asi)
  2651. return CURLE_OUT_OF_MEMORY;
  2652. }
  2653. arg = va_arg(param, long);
  2654. result = Curl_altsvc_ctrl(data->asi, arg);
  2655. if(result)
  2656. return result;
  2657. break;
  2658. #endif
  2659. default:
  2660. /* unknown tag and its companion, just ignore: */
  2661. result = CURLE_UNKNOWN_OPTION;
  2662. break;
  2663. }
  2664. return result;
  2665. }
  2666. /*
  2667. * curl_easy_setopt() is the external interface for setting options on an
  2668. * easy handle.
  2669. *
  2670. * NOTE: This is one of few API functions that are allowed to be called from
  2671. * within a callback.
  2672. */
  2673. #undef curl_easy_setopt
  2674. CURLcode curl_easy_setopt(struct Curl_easy *data, CURLoption tag, ...)
  2675. {
  2676. va_list arg;
  2677. CURLcode result;
  2678. if(!data)
  2679. return CURLE_BAD_FUNCTION_ARGUMENT;
  2680. va_start(arg, tag);
  2681. result = Curl_vsetopt(data, tag, arg);
  2682. va_end(arg);
  2683. return result;
  2684. }