2
0

setopt.c 93 KB

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