setopt.c 77 KB

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