setopt.c 94 KB

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