setopt.c 93 KB

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