setopt.c 80 KB

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