setopt.c 76 KB

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