setopt.c 80 KB

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