setopt.c 92 KB

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