setopt.c 85 KB

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