setopt.c 82 KB

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