setopt.c 81 KB

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