tool_getparam.c 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. * SPDX-License-Identifier: curl
  22. *
  23. ***************************************************************************/
  24. #include "tool_setup.h"
  25. #include "strcase.h"
  26. #define ENABLE_CURLX_PRINTF
  27. /* use our own printf() functions */
  28. #include "curlx.h"
  29. #include "tool_binmode.h"
  30. #include "tool_cfgable.h"
  31. #include "tool_cb_prg.h"
  32. #include "tool_filetime.h"
  33. #include "tool_formparse.h"
  34. #include "tool_getparam.h"
  35. #include "tool_helpers.h"
  36. #include "tool_libinfo.h"
  37. #include "tool_msgs.h"
  38. #include "tool_paramhlp.h"
  39. #include "tool_parsecfg.h"
  40. #include "tool_main.h"
  41. #include "dynbuf.h"
  42. #include "memdebug.h" /* keep this as LAST include */
  43. #ifdef MSDOS
  44. # define USE_WATT32
  45. #endif
  46. #define GetStr(str,val) do { \
  47. if(*(str)) { \
  48. free(*(str)); \
  49. *(str) = NULL; \
  50. } \
  51. if((val)) { \
  52. *(str) = strdup((val)); \
  53. if(!(*(str))) \
  54. return PARAM_NO_MEM; \
  55. } \
  56. } while(0)
  57. struct LongShort {
  58. const char *letter; /* short name option */
  59. const char *lname; /* long name option */
  60. enum {
  61. ARG_NONE, /* stand-alone but not a boolean */
  62. ARG_BOOL, /* accepts a --no-[name] prefix */
  63. ARG_STRING, /* requires an argument */
  64. ARG_FILENAME /* requires an argument, usually a file name */
  65. } desc;
  66. };
  67. static const struct LongShort aliases[]= {
  68. /* 'letter' strings with more than one character have *no* short option to
  69. mention. */
  70. {"*@", "url", ARG_STRING},
  71. {"*4", "dns-ipv4-addr", ARG_STRING},
  72. {"*6", "dns-ipv6-addr", ARG_STRING},
  73. {"*a", "random-file", ARG_FILENAME},
  74. {"*b", "egd-file", ARG_STRING},
  75. {"*B", "oauth2-bearer", ARG_STRING},
  76. {"*c", "connect-timeout", ARG_STRING},
  77. {"*C", "doh-url" , ARG_STRING},
  78. {"*d", "ciphers", ARG_STRING},
  79. {"*D", "dns-interface", ARG_STRING},
  80. {"*e", "disable-epsv", ARG_BOOL},
  81. {"*f", "disallow-username-in-url", ARG_BOOL},
  82. {"*E", "epsv", ARG_BOOL},
  83. /* 'epsv' made like this to make --no-epsv and --epsv to work
  84. although --disable-epsv is the documented option */
  85. {"*F", "dns-servers", ARG_STRING},
  86. {"*g", "trace", ARG_FILENAME},
  87. {"*G", "npn", ARG_BOOL},
  88. {"*h", "trace-ascii", ARG_FILENAME},
  89. {"*H", "alpn", ARG_BOOL},
  90. {"*i", "limit-rate", ARG_STRING},
  91. {"*I", "rate", ARG_STRING},
  92. {"*j", "compressed", ARG_BOOL},
  93. {"*J", "tr-encoding", ARG_BOOL},
  94. {"*k", "digest", ARG_BOOL},
  95. {"*l", "negotiate", ARG_BOOL},
  96. {"*m", "ntlm", ARG_BOOL},
  97. {"*M", "ntlm-wb", ARG_BOOL},
  98. {"*n", "basic", ARG_BOOL},
  99. {"*o", "anyauth", ARG_BOOL},
  100. #ifdef USE_WATT32
  101. {"*p", "wdebug", ARG_BOOL},
  102. #endif
  103. {"*q", "ftp-create-dirs", ARG_BOOL},
  104. {"*r", "create-dirs", ARG_BOOL},
  105. {"*R", "create-file-mode", ARG_STRING},
  106. {"*s", "max-redirs", ARG_STRING},
  107. {"*t", "proxy-ntlm", ARG_BOOL},
  108. {"*u", "crlf", ARG_BOOL},
  109. {"*v", "stderr", ARG_FILENAME},
  110. {"*V", "aws-sigv4", ARG_STRING},
  111. {"*w", "interface", ARG_STRING},
  112. {"*x", "krb", ARG_STRING},
  113. {"*x", "krb4", ARG_STRING},
  114. /* 'krb4' is the previous name */
  115. {"*X", "haproxy-protocol", ARG_BOOL},
  116. {"*y", "max-filesize", ARG_STRING},
  117. {"*z", "disable-eprt", ARG_BOOL},
  118. {"*Z", "eprt", ARG_BOOL},
  119. /* 'eprt' made like this to make --no-eprt and --eprt to work
  120. although --disable-eprt is the documented option */
  121. {"*~", "xattr", ARG_BOOL},
  122. {"$a", "ftp-ssl", ARG_BOOL},
  123. /* 'ftp-ssl' deprecated name since 7.20.0 */
  124. {"$a", "ssl", ARG_BOOL},
  125. /* 'ssl' new option name in 7.20.0, previously this was ftp-ssl */
  126. {"$b", "ftp-pasv", ARG_BOOL},
  127. {"$c", "socks5", ARG_STRING},
  128. {"$d", "tcp-nodelay", ARG_BOOL},
  129. {"$e", "proxy-digest", ARG_BOOL},
  130. {"$f", "proxy-basic", ARG_BOOL},
  131. {"$g", "retry", ARG_STRING},
  132. {"$V", "retry-connrefused", ARG_BOOL},
  133. {"$h", "retry-delay", ARG_STRING},
  134. {"$i", "retry-max-time", ARG_STRING},
  135. {"$k", "proxy-negotiate", ARG_BOOL},
  136. {"$l", "form-escape", ARG_BOOL},
  137. {"$m", "ftp-account", ARG_STRING},
  138. {"$n", "proxy-anyauth", ARG_BOOL},
  139. {"$o", "trace-time", ARG_BOOL},
  140. {"$p", "ignore-content-length", ARG_BOOL},
  141. {"$q", "ftp-skip-pasv-ip", ARG_BOOL},
  142. {"$r", "ftp-method", ARG_STRING},
  143. {"$s", "local-port", ARG_STRING},
  144. {"$t", "socks4", ARG_STRING},
  145. {"$T", "socks4a", ARG_STRING},
  146. {"$u", "ftp-alternative-to-user", ARG_STRING},
  147. {"$v", "ftp-ssl-reqd", ARG_BOOL},
  148. /* 'ftp-ssl-reqd' deprecated name since 7.20.0 */
  149. {"$v", "ssl-reqd", ARG_BOOL},
  150. /* 'ssl-reqd' new in 7.20.0, previously this was ftp-ssl-reqd */
  151. {"$w", "sessionid", ARG_BOOL},
  152. /* 'sessionid' listed as --no-sessionid in the help */
  153. {"$x", "ftp-ssl-control", ARG_BOOL},
  154. {"$y", "ftp-ssl-ccc", ARG_BOOL},
  155. {"$j", "ftp-ssl-ccc-mode", ARG_STRING},
  156. {"$z", "libcurl", ARG_STRING},
  157. {"$#", "raw", ARG_BOOL},
  158. {"$0", "post301", ARG_BOOL},
  159. {"$1", "keepalive", ARG_BOOL},
  160. /* 'keepalive' listed as --no-keepalive in the help */
  161. {"$2", "socks5-hostname", ARG_STRING},
  162. {"$3", "keepalive-time", ARG_STRING},
  163. {"$4", "post302", ARG_BOOL},
  164. {"$5", "noproxy", ARG_STRING},
  165. {"$7", "socks5-gssapi-nec", ARG_BOOL},
  166. {"$8", "proxy1.0", ARG_STRING},
  167. {"$9", "tftp-blksize", ARG_STRING},
  168. {"$A", "mail-from", ARG_STRING},
  169. {"$B", "mail-rcpt", ARG_STRING},
  170. {"$C", "ftp-pret", ARG_BOOL},
  171. {"$D", "proto", ARG_STRING},
  172. {"$E", "proto-redir", ARG_STRING},
  173. {"$F", "resolve", ARG_STRING},
  174. {"$G", "delegation", ARG_STRING},
  175. {"$H", "mail-auth", ARG_STRING},
  176. {"$I", "post303", ARG_BOOL},
  177. {"$J", "metalink", ARG_BOOL},
  178. {"$6", "sasl-authzid", ARG_STRING},
  179. {"$K", "sasl-ir", ARG_BOOL },
  180. {"$L", "test-event", ARG_BOOL},
  181. {"$M", "unix-socket", ARG_FILENAME},
  182. {"$N", "path-as-is", ARG_BOOL},
  183. {"$O", "socks5-gssapi-service", ARG_STRING},
  184. /* 'socks5-gssapi-service' merged with'proxy-service-name' and
  185. deprecated since 7.49.0 */
  186. {"$O", "proxy-service-name", ARG_STRING},
  187. {"$P", "service-name", ARG_STRING},
  188. {"$Q", "proto-default", ARG_STRING},
  189. {"$R", "expect100-timeout", ARG_STRING},
  190. {"$S", "tftp-no-options", ARG_BOOL},
  191. {"$U", "connect-to", ARG_STRING},
  192. {"$W", "abstract-unix-socket", ARG_FILENAME},
  193. {"$X", "tls-max", ARG_STRING},
  194. {"$Y", "suppress-connect-headers", ARG_BOOL},
  195. {"$Z", "compressed-ssh", ARG_BOOL},
  196. {"$~", "happy-eyeballs-timeout-ms", ARG_STRING},
  197. {"$!", "retry-all-errors", ARG_BOOL},
  198. {"0", "http1.0", ARG_NONE},
  199. {"01", "http1.1", ARG_NONE},
  200. {"02", "http2", ARG_NONE},
  201. {"03", "http2-prior-knowledge", ARG_NONE},
  202. {"04", "http3", ARG_NONE},
  203. {"05", "http3-only", ARG_NONE},
  204. {"09", "http0.9", ARG_BOOL},
  205. {"1", "tlsv1", ARG_NONE},
  206. {"10", "tlsv1.0", ARG_NONE},
  207. {"11", "tlsv1.1", ARG_NONE},
  208. {"12", "tlsv1.2", ARG_NONE},
  209. {"13", "tlsv1.3", ARG_NONE},
  210. {"1A", "tls13-ciphers", ARG_STRING},
  211. {"1B", "proxy-tls13-ciphers", ARG_STRING},
  212. {"2", "sslv2", ARG_NONE},
  213. {"3", "sslv3", ARG_NONE},
  214. {"4", "ipv4", ARG_NONE},
  215. {"6", "ipv6", ARG_NONE},
  216. {"a", "append", ARG_BOOL},
  217. {"A", "user-agent", ARG_STRING},
  218. {"b", "cookie", ARG_STRING},
  219. {"ba", "alt-svc", ARG_STRING},
  220. {"bb", "hsts", ARG_STRING},
  221. {"B", "use-ascii", ARG_BOOL},
  222. {"c", "cookie-jar", ARG_STRING},
  223. {"C", "continue-at", ARG_STRING},
  224. {"d", "data", ARG_STRING},
  225. {"dr", "data-raw", ARG_STRING},
  226. {"da", "data-ascii", ARG_STRING},
  227. {"db", "data-binary", ARG_STRING},
  228. {"de", "data-urlencode", ARG_STRING},
  229. {"df", "json", ARG_STRING},
  230. {"dg", "url-query", ARG_STRING},
  231. {"D", "dump-header", ARG_FILENAME},
  232. {"e", "referer", ARG_STRING},
  233. {"E", "cert", ARG_FILENAME},
  234. {"Ea", "cacert", ARG_FILENAME},
  235. {"Eb", "cert-type", ARG_STRING},
  236. {"Ec", "key", ARG_FILENAME},
  237. {"Ed", "key-type", ARG_STRING},
  238. {"Ee", "pass", ARG_STRING},
  239. {"Ef", "engine", ARG_STRING},
  240. {"Eg", "capath", ARG_FILENAME},
  241. {"Eh", "pubkey", ARG_STRING},
  242. {"Ei", "hostpubmd5", ARG_STRING},
  243. {"EF", "hostpubsha256", ARG_STRING},
  244. {"Ej", "crlfile", ARG_FILENAME},
  245. {"Ek", "tlsuser", ARG_STRING},
  246. {"El", "tlspassword", ARG_STRING},
  247. {"Em", "tlsauthtype", ARG_STRING},
  248. {"En", "ssl-allow-beast", ARG_BOOL},
  249. {"Eo", "ssl-auto-client-cert", ARG_BOOL},
  250. {"EO", "proxy-ssl-auto-client-cert", ARG_BOOL},
  251. {"Ep", "pinnedpubkey", ARG_STRING},
  252. {"EP", "proxy-pinnedpubkey", ARG_STRING},
  253. {"Eq", "cert-status", ARG_BOOL},
  254. {"EQ", "doh-cert-status", ARG_BOOL},
  255. {"Er", "false-start", ARG_BOOL},
  256. {"Es", "ssl-no-revoke", ARG_BOOL},
  257. {"ES", "ssl-revoke-best-effort", ARG_BOOL},
  258. {"Et", "tcp-fastopen", ARG_BOOL},
  259. {"Eu", "proxy-tlsuser", ARG_STRING},
  260. {"Ev", "proxy-tlspassword", ARG_STRING},
  261. {"Ew", "proxy-tlsauthtype", ARG_STRING},
  262. {"Ex", "proxy-cert", ARG_FILENAME},
  263. {"Ey", "proxy-cert-type", ARG_STRING},
  264. {"Ez", "proxy-key", ARG_FILENAME},
  265. {"E0", "proxy-key-type", ARG_STRING},
  266. {"E1", "proxy-pass", ARG_STRING},
  267. {"E2", "proxy-ciphers", ARG_STRING},
  268. {"E3", "proxy-crlfile", ARG_FILENAME},
  269. {"E4", "proxy-ssl-allow-beast", ARG_BOOL},
  270. {"E5", "login-options", ARG_STRING},
  271. {"E6", "proxy-cacert", ARG_FILENAME},
  272. {"E7", "proxy-capath", ARG_FILENAME},
  273. {"E8", "proxy-insecure", ARG_BOOL},
  274. {"E9", "proxy-tlsv1", ARG_NONE},
  275. {"EA", "socks5-basic", ARG_BOOL},
  276. {"EB", "socks5-gssapi", ARG_BOOL},
  277. {"EC", "etag-save", ARG_FILENAME},
  278. {"ED", "etag-compare", ARG_FILENAME},
  279. {"EE", "curves", ARG_STRING},
  280. {"f", "fail", ARG_BOOL},
  281. {"fa", "fail-early", ARG_BOOL},
  282. {"fb", "styled-output", ARG_BOOL},
  283. {"fc", "mail-rcpt-allowfails", ARG_BOOL},
  284. {"fd", "fail-with-body", ARG_BOOL},
  285. {"fe", "remove-on-error", ARG_BOOL},
  286. {"F", "form", ARG_STRING},
  287. {"Fs", "form-string", ARG_STRING},
  288. {"g", "globoff", ARG_BOOL},
  289. {"G", "get", ARG_NONE},
  290. {"Ga", "request-target", ARG_STRING},
  291. {"h", "help", ARG_BOOL},
  292. {"H", "header", ARG_STRING},
  293. {"Hp", "proxy-header", ARG_STRING},
  294. {"i", "include", ARG_BOOL},
  295. {"I", "head", ARG_BOOL},
  296. {"j", "junk-session-cookies", ARG_BOOL},
  297. {"J", "remote-header-name", ARG_BOOL},
  298. {"k", "insecure", ARG_BOOL},
  299. {"kd", "doh-insecure", ARG_BOOL},
  300. {"K", "config", ARG_FILENAME},
  301. {"l", "list-only", ARG_BOOL},
  302. {"L", "location", ARG_BOOL},
  303. {"Lt", "location-trusted", ARG_BOOL},
  304. {"m", "max-time", ARG_STRING},
  305. {"M", "manual", ARG_BOOL},
  306. {"n", "netrc", ARG_BOOL},
  307. {"no", "netrc-optional", ARG_BOOL},
  308. {"ne", "netrc-file", ARG_FILENAME},
  309. {"N", "buffer", ARG_BOOL},
  310. /* 'buffer' listed as --no-buffer in the help */
  311. {"o", "output", ARG_FILENAME},
  312. {"O", "remote-name", ARG_BOOL},
  313. {"Oa", "remote-name-all", ARG_BOOL},
  314. {"Ob", "output-dir", ARG_STRING},
  315. {"Oc", "clobber", ARG_BOOL},
  316. {"p", "proxytunnel", ARG_BOOL},
  317. {"P", "ftp-port", ARG_STRING},
  318. {"q", "disable", ARG_BOOL},
  319. {"Q", "quote", ARG_STRING},
  320. {"r", "range", ARG_STRING},
  321. {"R", "remote-time", ARG_BOOL},
  322. {"s", "silent", ARG_BOOL},
  323. {"S", "show-error", ARG_BOOL},
  324. {"t", "telnet-option", ARG_STRING},
  325. {"T", "upload-file", ARG_FILENAME},
  326. {"u", "user", ARG_STRING},
  327. {"U", "proxy-user", ARG_STRING},
  328. {"v", "verbose", ARG_BOOL},
  329. {"V", "version", ARG_BOOL},
  330. {"w", "write-out", ARG_STRING},
  331. {"x", "proxy", ARG_STRING},
  332. {"xa", "preproxy", ARG_STRING},
  333. {"X", "request", ARG_STRING},
  334. {"Y", "speed-limit", ARG_STRING},
  335. {"y", "speed-time", ARG_STRING},
  336. {"z", "time-cond", ARG_STRING},
  337. {"Z", "parallel", ARG_BOOL},
  338. {"Zb", "parallel-max", ARG_STRING},
  339. {"Zc", "parallel-immediate", ARG_BOOL},
  340. {"#", "progress-bar", ARG_BOOL},
  341. {"#m", "progress-meter", ARG_BOOL},
  342. {":", "next", ARG_NONE},
  343. };
  344. /* Split the argument of -E to 'certname' and 'passphrase' separated by colon.
  345. * We allow ':' and '\' to be escaped by '\' so that we can use certificate
  346. * nicknames containing ':'. See <https://sourceforge.net/p/curl/bugs/1196/>
  347. * for details. */
  348. #ifndef UNITTESTS
  349. static
  350. #endif
  351. void parse_cert_parameter(const char *cert_parameter,
  352. char **certname,
  353. char **passphrase)
  354. {
  355. size_t param_length = strlen(cert_parameter);
  356. size_t span;
  357. const char *param_place = NULL;
  358. char *certname_place = NULL;
  359. *certname = NULL;
  360. *passphrase = NULL;
  361. /* most trivial assumption: cert_parameter is empty */
  362. if(param_length == 0)
  363. return;
  364. /* next less trivial: cert_parameter starts 'pkcs11:' and thus
  365. * looks like a RFC7512 PKCS#11 URI which can be used as-is.
  366. * Also if cert_parameter contains no colon nor backslash, this
  367. * means no passphrase was given and no characters escaped */
  368. if(curl_strnequal(cert_parameter, "pkcs11:", 7) ||
  369. !strpbrk(cert_parameter, ":\\")) {
  370. *certname = strdup(cert_parameter);
  371. return;
  372. }
  373. /* deal with escaped chars; find unescaped colon if it exists */
  374. certname_place = malloc(param_length + 1);
  375. if(!certname_place)
  376. return;
  377. *certname = certname_place;
  378. param_place = cert_parameter;
  379. while(*param_place) {
  380. span = strcspn(param_place, ":\\");
  381. strncpy(certname_place, param_place, span);
  382. param_place += span;
  383. certname_place += span;
  384. /* we just ate all the non-special chars. now we're on either a special
  385. * char or the end of the string. */
  386. switch(*param_place) {
  387. case '\0':
  388. break;
  389. case '\\':
  390. param_place++;
  391. switch(*param_place) {
  392. case '\0':
  393. *certname_place++ = '\\';
  394. break;
  395. case '\\':
  396. *certname_place++ = '\\';
  397. param_place++;
  398. break;
  399. case ':':
  400. *certname_place++ = ':';
  401. param_place++;
  402. break;
  403. default:
  404. *certname_place++ = '\\';
  405. *certname_place++ = *param_place;
  406. param_place++;
  407. break;
  408. }
  409. break;
  410. case ':':
  411. /* Since we live in a world of weirdness and confusion, the win32
  412. dudes can use : when using drive letters and thus c:\file:password
  413. needs to work. In order not to break compatibility, we still use : as
  414. separator, but we try to detect when it is used for a file name! On
  415. windows. */
  416. #ifdef WIN32
  417. if((param_place == &cert_parameter[1]) &&
  418. (cert_parameter[2] == '\\' || cert_parameter[2] == '/') &&
  419. (ISALPHA(cert_parameter[0])) ) {
  420. /* colon in the second column, followed by a backslash, and the
  421. first character is an alphabetic letter:
  422. this is a drive letter colon */
  423. *certname_place++ = ':';
  424. param_place++;
  425. break;
  426. }
  427. #endif
  428. /* escaped colons and Windows drive letter colons were handled
  429. * above; if we're still here, this is a separating colon */
  430. param_place++;
  431. if(*param_place) {
  432. *passphrase = strdup(param_place);
  433. }
  434. goto done;
  435. }
  436. }
  437. done:
  438. *certname_place = '\0';
  439. }
  440. /* Replace (in-place) '%20' by '+' according to RFC1866 */
  441. static size_t replace_url_encoded_space_by_plus(char *url)
  442. {
  443. size_t orig_len = strlen(url);
  444. size_t orig_index = 0;
  445. size_t new_index = 0;
  446. while(orig_index < orig_len) {
  447. if((url[orig_index] == '%') &&
  448. (url[orig_index + 1] == '2') &&
  449. (url[orig_index + 2] == '0')) {
  450. url[new_index] = '+';
  451. orig_index += 3;
  452. }
  453. else{
  454. if(new_index != orig_index) {
  455. url[new_index] = url[orig_index];
  456. }
  457. orig_index++;
  458. }
  459. new_index++;
  460. }
  461. url[new_index] = 0; /* terminate string */
  462. return new_index; /* new size */
  463. }
  464. static void
  465. GetFileAndPassword(char *nextarg, char **file, char **password)
  466. {
  467. char *certname, *passphrase;
  468. parse_cert_parameter(nextarg, &certname, &passphrase);
  469. Curl_safefree(*file);
  470. *file = certname;
  471. if(passphrase) {
  472. Curl_safefree(*password);
  473. *password = passphrase;
  474. }
  475. }
  476. /* Get a size parameter for '--limit-rate' or '--max-filesize'.
  477. * We support a 'G', 'M' or 'K' suffix too.
  478. */
  479. static ParameterError GetSizeParameter(struct GlobalConfig *global,
  480. const char *arg,
  481. const char *which,
  482. curl_off_t *value_out)
  483. {
  484. char *unit;
  485. curl_off_t value;
  486. if(curlx_strtoofft(arg, &unit, 10, &value)) {
  487. warnf(global, "invalid number specified for %s\n", which);
  488. return PARAM_BAD_USE;
  489. }
  490. if(!*unit)
  491. unit = (char *)"b";
  492. else if(strlen(unit) > 1)
  493. unit = (char *)"w"; /* unsupported */
  494. switch(*unit) {
  495. case 'G':
  496. case 'g':
  497. if(value > (CURL_OFF_T_MAX / (1024*1024*1024)))
  498. return PARAM_NUMBER_TOO_LARGE;
  499. value *= 1024*1024*1024;
  500. break;
  501. case 'M':
  502. case 'm':
  503. if(value > (CURL_OFF_T_MAX / (1024*1024)))
  504. return PARAM_NUMBER_TOO_LARGE;
  505. value *= 1024*1024;
  506. break;
  507. case 'K':
  508. case 'k':
  509. if(value > (CURL_OFF_T_MAX / 1024))
  510. return PARAM_NUMBER_TOO_LARGE;
  511. value *= 1024;
  512. break;
  513. case 'b':
  514. case 'B':
  515. /* for plain bytes, leave as-is */
  516. break;
  517. default:
  518. warnf(global, "unsupported %s unit. Use G, M, K or B!\n", which);
  519. return PARAM_BAD_USE;
  520. }
  521. *value_out = value;
  522. return PARAM_OK;
  523. }
  524. #ifdef HAVE_WRITABLE_ARGV
  525. static void cleanarg(argv_item_t str)
  526. {
  527. /* now that GetStr has copied the contents of nextarg, wipe the next
  528. * argument out so that the username:password isn't displayed in the
  529. * system process list */
  530. if(str) {
  531. size_t len = strlen(str);
  532. memset(str, ' ', len);
  533. }
  534. }
  535. #else
  536. #define cleanarg(x)
  537. #endif
  538. /* --data-urlencode */
  539. static ParameterError data_urlencode(struct GlobalConfig *global,
  540. char *nextarg,
  541. char **postp,
  542. size_t *lenp)
  543. {
  544. /* [name]=[content], we encode the content part only
  545. * [name]@[file name]
  546. *
  547. * Case 2: we first load the file using that name and then encode
  548. * the content.
  549. */
  550. ParameterError err;
  551. const char *p = strchr(nextarg, '=');
  552. size_t nlen;
  553. char is_file;
  554. char *postdata = NULL;
  555. size_t size = 0;
  556. if(!p)
  557. /* there was no '=' letter, check for a '@' instead */
  558. p = strchr(nextarg, '@');
  559. if(p) {
  560. nlen = p - nextarg; /* length of the name part */
  561. is_file = *p++; /* pass the separator */
  562. }
  563. else {
  564. /* neither @ nor =, so no name and it isn't a file */
  565. nlen = is_file = 0;
  566. p = nextarg;
  567. }
  568. if('@' == is_file) {
  569. FILE *file;
  570. /* a '@' letter, it means that a file name or - (stdin) follows */
  571. if(!strcmp("-", p)) {
  572. file = stdin;
  573. set_binmode(stdin);
  574. }
  575. else {
  576. file = fopen(p, "rb");
  577. if(!file)
  578. warnf(global,
  579. "Couldn't read data from file \"%s\", this makes "
  580. "an empty POST.\n", nextarg);
  581. }
  582. err = file2memory(&postdata, &size, file);
  583. if(file && (file != stdin))
  584. fclose(file);
  585. if(err)
  586. return err;
  587. }
  588. else {
  589. GetStr(&postdata, p);
  590. if(postdata)
  591. size = strlen(postdata);
  592. }
  593. if(!postdata) {
  594. /* no data from the file, point to a zero byte string to make this
  595. get sent as a POST anyway */
  596. postdata = strdup("");
  597. if(!postdata)
  598. return PARAM_NO_MEM;
  599. size = 0;
  600. }
  601. else {
  602. char *enc = curl_easy_escape(NULL, postdata, (int)size);
  603. Curl_safefree(postdata); /* no matter if it worked or not */
  604. if(enc) {
  605. /* replace (in-place) '%20' by '+' according to RFC1866 */
  606. size_t enclen = replace_url_encoded_space_by_plus(enc);
  607. /* now make a string with the name from above and append the
  608. encoded string */
  609. size_t outlen = nlen + enclen + 2;
  610. char *n = malloc(outlen);
  611. if(!n) {
  612. curl_free(enc);
  613. return PARAM_NO_MEM;
  614. }
  615. if(nlen > 0) { /* only append '=' if we have a name */
  616. msnprintf(n, outlen, "%.*s=%s", (int)nlen, nextarg, enc);
  617. size = outlen-1;
  618. }
  619. else {
  620. strcpy(n, enc);
  621. size = outlen-2; /* since no '=' was inserted */
  622. }
  623. curl_free(enc);
  624. postdata = n;
  625. }
  626. else
  627. return PARAM_NO_MEM;
  628. }
  629. *postp = postdata;
  630. *lenp = size;
  631. return PARAM_OK;
  632. }
  633. static void sethttpver(struct GlobalConfig *global,
  634. struct OperationConfig *config,
  635. long httpversion)
  636. {
  637. if(config->httpversion &&
  638. (config->httpversion != httpversion))
  639. warnf(global, "Overrides previous HTTP version option\n");
  640. config->httpversion = httpversion;
  641. }
  642. ParameterError getparameter(const char *flag, /* f or -long-flag */
  643. char *nextarg, /* NULL if unset */
  644. argv_item_t cleararg,
  645. bool *usedarg, /* set to TRUE if the arg
  646. has been used */
  647. struct GlobalConfig *global,
  648. struct OperationConfig *config)
  649. {
  650. char letter;
  651. char subletter = '\0'; /* subletters can only occur on long options */
  652. int rc;
  653. const char *parse = NULL;
  654. unsigned int j;
  655. time_t now;
  656. int hit = -1;
  657. bool longopt = FALSE;
  658. bool singleopt = FALSE; /* when true means '-o foo' used '-ofoo' */
  659. ParameterError err;
  660. bool toggle = TRUE; /* how to switch boolean options, on or off. Controlled
  661. by using --OPTION or --no-OPTION */
  662. static const char *redir_protos[] = {
  663. "http",
  664. "https",
  665. "ftp",
  666. "ftps",
  667. NULL
  668. };
  669. #ifdef HAVE_WRITABLE_ARGV
  670. argv_item_t clearthis = NULL;
  671. #else
  672. (void)cleararg;
  673. #endif
  674. *usedarg = FALSE; /* default is that we don't use the arg */
  675. if(('-' != flag[0]) || ('-' == flag[1])) {
  676. /* this should be a long name */
  677. const char *word = ('-' == flag[0]) ? flag + 2 : flag;
  678. size_t fnam = strlen(word);
  679. int numhits = 0;
  680. bool noflagged = FALSE;
  681. if(!strncmp(word, "no-", 3)) {
  682. /* disable this option but ignore the "no-" part when looking for it */
  683. word += 3;
  684. toggle = FALSE;
  685. noflagged = TRUE;
  686. }
  687. for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
  688. if(curl_strnequal(aliases[j].lname, word, fnam)) {
  689. longopt = TRUE;
  690. numhits++;
  691. if(curl_strequal(aliases[j].lname, word)) {
  692. parse = aliases[j].letter;
  693. hit = j;
  694. numhits = 1; /* a single unique hit */
  695. break;
  696. }
  697. parse = aliases[j].letter;
  698. hit = j;
  699. }
  700. }
  701. if(numhits > 1) {
  702. /* this is at least the second match! */
  703. return PARAM_OPTION_AMBIGUOUS;
  704. }
  705. if(hit < 0) {
  706. return PARAM_OPTION_UNKNOWN;
  707. }
  708. if(noflagged && (aliases[hit].desc != ARG_BOOL))
  709. /* --no- prefixed an option that isn't boolean! */
  710. return PARAM_NO_NOT_BOOLEAN;
  711. }
  712. else {
  713. flag++; /* prefixed with one dash, pass it */
  714. hit = -1;
  715. parse = flag;
  716. }
  717. do {
  718. /* we can loop here if we have multiple single-letters */
  719. if(!longopt) {
  720. letter = (char)*parse;
  721. subletter = '\0';
  722. }
  723. else {
  724. letter = parse[0];
  725. subletter = parse[1];
  726. }
  727. if(hit < 0) {
  728. for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
  729. if(letter == aliases[j].letter[0]) {
  730. hit = j;
  731. break;
  732. }
  733. }
  734. if(hit < 0) {
  735. return PARAM_OPTION_UNKNOWN;
  736. }
  737. }
  738. if(aliases[hit].desc >= ARG_STRING) {
  739. /* this option requires an extra parameter */
  740. if(!longopt && parse[1]) {
  741. nextarg = (char *)&parse[1]; /* this is the actual extra parameter */
  742. singleopt = TRUE; /* don't loop anymore after this */
  743. }
  744. else if(!nextarg)
  745. return PARAM_REQUIRES_PARAMETER;
  746. else {
  747. #ifdef HAVE_WRITABLE_ARGV
  748. clearthis = cleararg;
  749. #endif
  750. *usedarg = TRUE; /* mark it as used */
  751. }
  752. if((aliases[hit].desc == ARG_FILENAME) &&
  753. (nextarg[0] == '-') && nextarg[1]) {
  754. /* if the file name looks like a command line option */
  755. warnf(global, "The file name argument '%s' looks like a flag.\n",
  756. nextarg);
  757. }
  758. }
  759. else if((aliases[hit].desc == ARG_NONE) && !toggle)
  760. return PARAM_NO_PREFIX;
  761. switch(letter) {
  762. case '*': /* options without a short option */
  763. switch(subletter) {
  764. case '4': /* --dns-ipv4-addr */
  765. if(!curlinfo->ares_num) /* c-ares is needed for this */
  766. return PARAM_LIBCURL_DOESNT_SUPPORT;
  767. /* addr in dot notation */
  768. GetStr(&config->dns_ipv4_addr, nextarg);
  769. break;
  770. case '6': /* --dns-ipv6-addr */
  771. if(!curlinfo->ares_num) /* c-ares is needed for this */
  772. return PARAM_LIBCURL_DOESNT_SUPPORT;
  773. /* addr in dot notation */
  774. GetStr(&config->dns_ipv6_addr, nextarg);
  775. break;
  776. case 'a': /* random-file */
  777. break;
  778. case 'b': /* egd-file */
  779. break;
  780. case 'B': /* OAuth 2.0 bearer token */
  781. GetStr(&config->oauth_bearer, nextarg);
  782. cleanarg(clearthis);
  783. config->authtype |= CURLAUTH_BEARER;
  784. break;
  785. case 'c': /* connect-timeout */
  786. err = secs2ms(&config->connecttimeout_ms, nextarg);
  787. if(err)
  788. return err;
  789. break;
  790. case 'C': /* doh-url */
  791. GetStr(&config->doh_url, nextarg);
  792. if(config->doh_url && !config->doh_url[0])
  793. /* if given a blank string, we make it NULL again */
  794. Curl_safefree(config->doh_url);
  795. break;
  796. case 'd': /* ciphers */
  797. GetStr(&config->cipher_list, nextarg);
  798. break;
  799. case 'D': /* --dns-interface */
  800. if(!curlinfo->ares_num) /* c-ares is needed for this */
  801. return PARAM_LIBCURL_DOESNT_SUPPORT;
  802. /* interface name */
  803. GetStr(&config->dns_interface, nextarg);
  804. break;
  805. case 'e': /* --disable-epsv */
  806. config->disable_epsv = toggle;
  807. break;
  808. case 'f': /* --disallow-username-in-url */
  809. config->disallow_username_in_url = toggle;
  810. break;
  811. case 'E': /* --epsv */
  812. config->disable_epsv = (!toggle)?TRUE:FALSE;
  813. break;
  814. case 'F': /* --dns-servers */
  815. if(!curlinfo->ares_num) /* c-ares is needed for this */
  816. return PARAM_LIBCURL_DOESNT_SUPPORT;
  817. /* IP addrs of DNS servers */
  818. GetStr(&config->dns_servers, nextarg);
  819. break;
  820. case 'g': /* --trace */
  821. GetStr(&global->trace_dump, nextarg);
  822. if(global->tracetype && (global->tracetype != TRACE_BIN))
  823. warnf(global, "--trace overrides an earlier trace/verbose option\n");
  824. global->tracetype = TRACE_BIN;
  825. break;
  826. case 'G': /* --npn */
  827. warnf(global, "--npn is no longer supported\n");
  828. break;
  829. case 'h': /* --trace-ascii */
  830. GetStr(&global->trace_dump, nextarg);
  831. if(global->tracetype && (global->tracetype != TRACE_ASCII))
  832. warnf(global,
  833. "--trace-ascii overrides an earlier trace/verbose option\n");
  834. global->tracetype = TRACE_ASCII;
  835. break;
  836. case 'H': /* --alpn */
  837. config->noalpn = (!toggle)?TRUE:FALSE;
  838. break;
  839. case 'i': /* --limit-rate */
  840. {
  841. curl_off_t value;
  842. ParameterError pe = GetSizeParameter(global, nextarg, "rate", &value);
  843. if(pe != PARAM_OK)
  844. return pe;
  845. config->recvpersecond = value;
  846. config->sendpersecond = value;
  847. }
  848. break;
  849. case 'I': /* --rate (request rate) */
  850. {
  851. /* support a few different suffixes, extract the suffix first, then
  852. get the number and convert to per hour.
  853. /s == per second
  854. /m == per minute
  855. /h == per hour (default)
  856. /d == per day (24 hours)
  857. */
  858. char *div = strchr(nextarg, '/');
  859. char number[26];
  860. long denominator;
  861. long numerator = 60*60*1000; /* default per hour */
  862. size_t numlen = div ? (size_t)(div - nextarg) : strlen(nextarg);
  863. if(numlen > sizeof(number)-1)
  864. return PARAM_NUMBER_TOO_LARGE;
  865. strncpy(number, nextarg, numlen);
  866. number[numlen] = 0;
  867. err = str2unum(&denominator, number);
  868. if(err)
  869. return err;
  870. if(denominator < 1)
  871. return PARAM_BAD_USE;
  872. if(div) {
  873. char unit = div[1];
  874. switch(unit) {
  875. case 's': /* per second */
  876. numerator = 1000;
  877. break;
  878. case 'm': /* per minute */
  879. numerator = 60*1000;
  880. break;
  881. case 'h': /* per hour */
  882. break;
  883. case 'd': /* per day */
  884. numerator = 24*60*60*1000;
  885. break;
  886. default:
  887. errorf(global, "unsupported --rate unit\n");
  888. return PARAM_BAD_USE;
  889. }
  890. }
  891. global->ms_per_transfer = numerator/denominator;
  892. }
  893. break;
  894. case 'j': /* --compressed */
  895. if(toggle && !(feature_libz || feature_brotli || feature_zstd))
  896. return PARAM_LIBCURL_DOESNT_SUPPORT;
  897. config->encoding = toggle;
  898. break;
  899. case 'J': /* --tr-encoding */
  900. config->tr_encoding = toggle;
  901. break;
  902. case 'k': /* --digest */
  903. if(toggle)
  904. config->authtype |= CURLAUTH_DIGEST;
  905. else
  906. config->authtype &= ~CURLAUTH_DIGEST;
  907. break;
  908. case 'l': /* --negotiate */
  909. if(!toggle)
  910. config->authtype &= ~CURLAUTH_NEGOTIATE;
  911. else if(feature_spnego)
  912. config->authtype |= CURLAUTH_NEGOTIATE;
  913. else
  914. return PARAM_LIBCURL_DOESNT_SUPPORT;
  915. break;
  916. case 'm': /* --ntlm */
  917. if(!toggle)
  918. config->authtype &= ~CURLAUTH_NTLM;
  919. else if(feature_ntlm)
  920. config->authtype |= CURLAUTH_NTLM;
  921. else
  922. return PARAM_LIBCURL_DOESNT_SUPPORT;
  923. break;
  924. case 'M': /* --ntlm-wb */
  925. if(!toggle)
  926. config->authtype &= ~CURLAUTH_NTLM_WB;
  927. else if(feature_ntlm_wb)
  928. config->authtype |= CURLAUTH_NTLM_WB;
  929. else
  930. return PARAM_LIBCURL_DOESNT_SUPPORT;
  931. break;
  932. case 'n': /* --basic for completeness */
  933. if(toggle)
  934. config->authtype |= CURLAUTH_BASIC;
  935. else
  936. config->authtype &= ~CURLAUTH_BASIC;
  937. break;
  938. case 'o': /* --anyauth, let libcurl pick it */
  939. if(toggle)
  940. config->authtype = CURLAUTH_ANY;
  941. /* --no-anyauth simply doesn't touch it */
  942. break;
  943. #ifdef USE_WATT32
  944. case 'p': /* --wdebug */
  945. dbug_init();
  946. break;
  947. #endif
  948. case 'q': /* --ftp-create-dirs */
  949. config->ftp_create_dirs = toggle;
  950. break;
  951. case 'r': /* --create-dirs */
  952. config->create_dirs = toggle;
  953. break;
  954. case 'R': /* --create-file-mode */
  955. err = oct2nummax(&config->create_file_mode, nextarg, 0777);
  956. if(err)
  957. return err;
  958. break;
  959. case 's': /* --max-redirs */
  960. /* specified max no of redirects (http(s)), this accepts -1 as a
  961. special condition */
  962. err = str2num(&config->maxredirs, nextarg);
  963. if(err)
  964. return err;
  965. if(config->maxredirs < -1)
  966. return PARAM_BAD_NUMERIC;
  967. break;
  968. case 't': /* --proxy-ntlm */
  969. if(!feature_ntlm)
  970. return PARAM_LIBCURL_DOESNT_SUPPORT;
  971. config->proxyntlm = toggle;
  972. break;
  973. case 'u': /* --crlf */
  974. /* LF -> CRLF conversion? */
  975. config->crlf = toggle;
  976. break;
  977. case 'V': /* --aws-sigv4 */
  978. config->authtype |= CURLAUTH_AWS_SIGV4;
  979. GetStr(&config->aws_sigv4, nextarg);
  980. break;
  981. case 'v': /* --stderr */
  982. if(strcmp(nextarg, "-")) {
  983. FILE *newfile = fopen(nextarg, FOPEN_WRITETEXT);
  984. if(!newfile)
  985. warnf(global, "Failed to open %s!\n", nextarg);
  986. else {
  987. if(global->errors_fopened)
  988. fclose(global->errors);
  989. global->errors = newfile;
  990. global->errors_fopened = TRUE;
  991. }
  992. }
  993. else
  994. global->errors = stdout;
  995. break;
  996. case 'w': /* --interface */
  997. /* interface */
  998. GetStr(&config->iface, nextarg);
  999. break;
  1000. case 'x': /* --krb */
  1001. /* kerberos level string */
  1002. if(!feature_spnego)
  1003. return PARAM_LIBCURL_DOESNT_SUPPORT;
  1004. GetStr(&config->krblevel, nextarg);
  1005. break;
  1006. case 'X': /* --haproxy-protocol */
  1007. config->haproxy_protocol = toggle;
  1008. break;
  1009. case 'y': /* --max-filesize */
  1010. {
  1011. curl_off_t value;
  1012. ParameterError pe =
  1013. GetSizeParameter(global, nextarg, "max-filesize", &value);
  1014. if(pe != PARAM_OK)
  1015. return pe;
  1016. config->max_filesize = value;
  1017. }
  1018. break;
  1019. case 'z': /* --disable-eprt */
  1020. config->disable_eprt = toggle;
  1021. break;
  1022. case 'Z': /* --eprt */
  1023. config->disable_eprt = (!toggle)?TRUE:FALSE;
  1024. break;
  1025. case '~': /* --xattr */
  1026. config->xattr = toggle;
  1027. break;
  1028. case '@': /* the URL! */
  1029. {
  1030. struct getout *url;
  1031. if(!config->url_get)
  1032. config->url_get = config->url_list;
  1033. if(config->url_get) {
  1034. /* there's a node here, if it already is filled-in continue to find
  1035. an "empty" node */
  1036. while(config->url_get && (config->url_get->flags & GETOUT_URL))
  1037. config->url_get = config->url_get->next;
  1038. }
  1039. /* now there might or might not be an available node to fill in! */
  1040. if(config->url_get)
  1041. /* existing node */
  1042. url = config->url_get;
  1043. else
  1044. /* there was no free node, create one! */
  1045. config->url_get = url = new_getout(config);
  1046. if(!url)
  1047. return PARAM_NO_MEM;
  1048. /* fill in the URL */
  1049. GetStr(&url->url, nextarg);
  1050. url->flags |= GETOUT_URL;
  1051. }
  1052. }
  1053. break;
  1054. case '$': /* more options without a short option */
  1055. switch(subletter) {
  1056. case 'a': /* --ssl */
  1057. if(toggle && !feature_ssl)
  1058. return PARAM_LIBCURL_DOESNT_SUPPORT;
  1059. config->ftp_ssl = toggle;
  1060. if(config->ftp_ssl)
  1061. warnf(global,
  1062. "--ssl is an insecure option, consider --ssl-reqd instead\n");
  1063. break;
  1064. case 'b': /* --ftp-pasv */
  1065. Curl_safefree(config->ftpport);
  1066. break;
  1067. case 'c': /* --socks5 specifies a socks5 proxy to use, and resolves
  1068. the name locally and passes on the resolved address */
  1069. GetStr(&config->proxy, nextarg);
  1070. config->proxyver = CURLPROXY_SOCKS5;
  1071. break;
  1072. case 't': /* --socks4 specifies a socks4 proxy to use */
  1073. GetStr(&config->proxy, nextarg);
  1074. config->proxyver = CURLPROXY_SOCKS4;
  1075. break;
  1076. case 'T': /* --socks4a specifies a socks4a proxy to use */
  1077. GetStr(&config->proxy, nextarg);
  1078. config->proxyver = CURLPROXY_SOCKS4A;
  1079. break;
  1080. case '2': /* --socks5-hostname specifies a socks5 proxy and enables name
  1081. resolving with the proxy */
  1082. GetStr(&config->proxy, nextarg);
  1083. config->proxyver = CURLPROXY_SOCKS5_HOSTNAME;
  1084. break;
  1085. case 'd': /* --tcp-nodelay option */
  1086. config->tcp_nodelay = toggle;
  1087. break;
  1088. case 'e': /* --proxy-digest */
  1089. config->proxydigest = toggle;
  1090. break;
  1091. case 'f': /* --proxy-basic */
  1092. config->proxybasic = toggle;
  1093. break;
  1094. case 'g': /* --retry */
  1095. err = str2unum(&config->req_retry, nextarg);
  1096. if(err)
  1097. return err;
  1098. break;
  1099. case 'V': /* --retry-connrefused */
  1100. config->retry_connrefused = toggle;
  1101. break;
  1102. case 'h': /* --retry-delay */
  1103. err = str2unummax(&config->retry_delay, nextarg, LONG_MAX/1000);
  1104. if(err)
  1105. return err;
  1106. break;
  1107. case 'i': /* --retry-max-time */
  1108. err = str2unummax(&config->retry_maxtime, nextarg, LONG_MAX/1000);
  1109. if(err)
  1110. return err;
  1111. break;
  1112. case '!': /* --retry-all-errors */
  1113. config->retry_all_errors = toggle;
  1114. break;
  1115. case 'k': /* --proxy-negotiate */
  1116. if(!feature_spnego)
  1117. return PARAM_LIBCURL_DOESNT_SUPPORT;
  1118. config->proxynegotiate = toggle;
  1119. break;
  1120. case 'l': /* --form-escape */
  1121. config->mime_options &= ~CURLMIMEOPT_FORMESCAPE;
  1122. if(toggle)
  1123. config->mime_options |= CURLMIMEOPT_FORMESCAPE;
  1124. break;
  1125. case 'm': /* --ftp-account */
  1126. GetStr(&config->ftp_account, nextarg);
  1127. break;
  1128. case 'n': /* --proxy-anyauth */
  1129. config->proxyanyauth = toggle;
  1130. break;
  1131. case 'o': /* --trace-time */
  1132. global->tracetime = toggle;
  1133. break;
  1134. case 'p': /* --ignore-content-length */
  1135. config->ignorecl = toggle;
  1136. break;
  1137. case 'q': /* --ftp-skip-pasv-ip */
  1138. config->ftp_skip_ip = toggle;
  1139. break;
  1140. case 'r': /* --ftp-method (undocumented at this point) */
  1141. config->ftp_filemethod = ftpfilemethod(config, nextarg);
  1142. break;
  1143. case 's': { /* --local-port */
  1144. /* 16bit base 10 is 5 digits, but we allow 6 so that this catches
  1145. overflows, not just truncates */
  1146. char lrange[7]="";
  1147. char *p = nextarg;
  1148. while(ISDIGIT(*p))
  1149. p++;
  1150. if(*p) {
  1151. /* if there's anything more than a plain decimal number */
  1152. rc = sscanf(p, " - %6s", lrange);
  1153. *p = 0; /* null-terminate to make str2unum() work below */
  1154. }
  1155. else
  1156. rc = 0;
  1157. err = str2unum(&config->localport, nextarg);
  1158. if(err || (config->localport > 65535))
  1159. return PARAM_BAD_USE;
  1160. if(!rc)
  1161. config->localportrange = 1; /* default number of ports to try */
  1162. else {
  1163. err = str2unum(&config->localportrange, lrange);
  1164. if(err || (config->localportrange > 65535))
  1165. return PARAM_BAD_USE;
  1166. config->localportrange -= (config->localport-1);
  1167. if(config->localportrange < 1)
  1168. return PARAM_BAD_USE;
  1169. }
  1170. break;
  1171. }
  1172. case 'u': /* --ftp-alternative-to-user */
  1173. GetStr(&config->ftp_alternative_to_user, nextarg);
  1174. break;
  1175. case 'v': /* --ssl-reqd */
  1176. if(toggle && !feature_ssl)
  1177. return PARAM_LIBCURL_DOESNT_SUPPORT;
  1178. config->ftp_ssl_reqd = toggle;
  1179. break;
  1180. case 'w': /* --no-sessionid */
  1181. config->disable_sessionid = (!toggle)?TRUE:FALSE;
  1182. break;
  1183. case 'x': /* --ftp-ssl-control */
  1184. if(toggle && !feature_ssl)
  1185. return PARAM_LIBCURL_DOESNT_SUPPORT;
  1186. config->ftp_ssl_control = toggle;
  1187. break;
  1188. case 'y': /* --ftp-ssl-ccc */
  1189. config->ftp_ssl_ccc = toggle;
  1190. if(!config->ftp_ssl_ccc_mode)
  1191. config->ftp_ssl_ccc_mode = CURLFTPSSL_CCC_PASSIVE;
  1192. break;
  1193. case 'j': /* --ftp-ssl-ccc-mode */
  1194. config->ftp_ssl_ccc = TRUE;
  1195. config->ftp_ssl_ccc_mode = ftpcccmethod(config, nextarg);
  1196. break;
  1197. case 'z': /* --libcurl */
  1198. #ifdef CURL_DISABLE_LIBCURL_OPTION
  1199. warnf(global,
  1200. "--libcurl option was disabled at build-time!\n");
  1201. return PARAM_OPTION_UNKNOWN;
  1202. #else
  1203. GetStr(&global->libcurl, nextarg);
  1204. break;
  1205. #endif
  1206. case '#': /* --raw */
  1207. config->raw = toggle;
  1208. break;
  1209. case '0': /* --post301 */
  1210. config->post301 = toggle;
  1211. break;
  1212. case '1': /* --no-keepalive */
  1213. config->nokeepalive = (!toggle)?TRUE:FALSE;
  1214. break;
  1215. case '3': /* --keepalive-time */
  1216. err = str2unum(&config->alivetime, nextarg);
  1217. if(err)
  1218. return err;
  1219. break;
  1220. case '4': /* --post302 */
  1221. config->post302 = toggle;
  1222. break;
  1223. case 'I': /* --post303 */
  1224. config->post303 = toggle;
  1225. break;
  1226. case '5': /* --noproxy */
  1227. /* This specifies the noproxy list */
  1228. GetStr(&config->noproxy, nextarg);
  1229. break;
  1230. case '7': /* --socks5-gssapi-nec */
  1231. config->socks5_gssapi_nec = toggle;
  1232. break;
  1233. case '8': /* --proxy1.0 */
  1234. /* http 1.0 proxy */
  1235. GetStr(&config->proxy, nextarg);
  1236. config->proxyver = CURLPROXY_HTTP_1_0;
  1237. break;
  1238. case '9': /* --tftp-blksize */
  1239. err = str2unum(&config->tftp_blksize, nextarg);
  1240. if(err)
  1241. return err;
  1242. break;
  1243. case 'A': /* --mail-from */
  1244. GetStr(&config->mail_from, nextarg);
  1245. break;
  1246. case 'B': /* --mail-rcpt */
  1247. /* append receiver to a list */
  1248. err = add2list(&config->mail_rcpt, nextarg);
  1249. if(err)
  1250. return err;
  1251. break;
  1252. case 'C': /* --ftp-pret */
  1253. config->ftp_pret = toggle;
  1254. break;
  1255. case 'D': /* --proto */
  1256. config->proto_present = TRUE;
  1257. err = proto2num(config, built_in_protos, &config->proto_str, nextarg);
  1258. if(err)
  1259. return err;
  1260. break;
  1261. case 'E': /* --proto-redir */
  1262. config->proto_redir_present = TRUE;
  1263. if(proto2num(config, redir_protos, &config->proto_redir_str, nextarg))
  1264. return PARAM_BAD_USE;
  1265. break;
  1266. case 'F': /* --resolve */
  1267. err = add2list(&config->resolve, nextarg);
  1268. if(err)
  1269. return err;
  1270. break;
  1271. case 'G': /* --delegation LEVEL */
  1272. config->gssapi_delegation = delegation(config, nextarg);
  1273. break;
  1274. case 'H': /* --mail-auth */
  1275. GetStr(&config->mail_auth, nextarg);
  1276. break;
  1277. case 'J': /* --metalink */
  1278. errorf(global, "--metalink is disabled\n");
  1279. return PARAM_BAD_USE;
  1280. case '6': /* --sasl-authzid */
  1281. GetStr(&config->sasl_authzid, nextarg);
  1282. break;
  1283. case 'K': /* --sasl-ir */
  1284. config->sasl_ir = toggle;
  1285. break;
  1286. case 'L': /* --test-event */
  1287. #ifdef CURLDEBUG
  1288. global->test_event_based = toggle;
  1289. #else
  1290. warnf(global, "--test-event is ignored unless a debug build!\n");
  1291. #endif
  1292. break;
  1293. case 'M': /* --unix-socket */
  1294. config->abstract_unix_socket = FALSE;
  1295. GetStr(&config->unix_socket_path, nextarg);
  1296. break;
  1297. case 'N': /* --path-as-is */
  1298. config->path_as_is = toggle;
  1299. break;
  1300. case 'O': /* --proxy-service-name */
  1301. GetStr(&config->proxy_service_name, nextarg);
  1302. break;
  1303. case 'P': /* --service-name */
  1304. GetStr(&config->service_name, nextarg);
  1305. break;
  1306. case 'Q': /* --proto-default */
  1307. GetStr(&config->proto_default, nextarg);
  1308. err = check_protocol(config->proto_default);
  1309. if(err)
  1310. return err;
  1311. break;
  1312. case 'R': /* --expect100-timeout */
  1313. err = secs2ms(&config->expect100timeout_ms, nextarg);
  1314. if(err)
  1315. return err;
  1316. break;
  1317. case 'S': /* --tftp-no-options */
  1318. config->tftp_no_options = toggle;
  1319. break;
  1320. case 'U': /* --connect-to */
  1321. err = add2list(&config->connect_to, nextarg);
  1322. if(err)
  1323. return err;
  1324. break;
  1325. case 'W': /* --abstract-unix-socket */
  1326. config->abstract_unix_socket = TRUE;
  1327. GetStr(&config->unix_socket_path, nextarg);
  1328. break;
  1329. case 'X': /* --tls-max */
  1330. err = str2tls_max(&config->ssl_version_max, nextarg);
  1331. if(err)
  1332. return err;
  1333. break;
  1334. case 'Y': /* --suppress-connect-headers */
  1335. config->suppress_connect_headers = toggle;
  1336. break;
  1337. case 'Z': /* --compressed-ssh */
  1338. config->ssh_compression = toggle;
  1339. break;
  1340. case '~': /* --happy-eyeballs-timeout-ms */
  1341. err = str2unum(&config->happy_eyeballs_timeout_ms, nextarg);
  1342. if(err)
  1343. return err;
  1344. /* 0 is a valid value for this timeout */
  1345. break;
  1346. }
  1347. break;
  1348. case '#':
  1349. switch(subletter) {
  1350. case 'm': /* --progress-meter */
  1351. global->noprogress = !toggle;
  1352. break;
  1353. default: /* --progress-bar */
  1354. global->progressmode =
  1355. toggle ? CURL_PROGRESS_BAR : CURL_PROGRESS_STATS;
  1356. break;
  1357. }
  1358. break;
  1359. case ':': /* --next */
  1360. return PARAM_NEXT_OPERATION;
  1361. case '0': /* --http* options */
  1362. switch(subletter) {
  1363. case '\0':
  1364. /* HTTP version 1.0 */
  1365. sethttpver(global, config, CURL_HTTP_VERSION_1_0);
  1366. break;
  1367. case '1':
  1368. /* HTTP version 1.1 */
  1369. sethttpver(global, config, CURL_HTTP_VERSION_1_1);
  1370. break;
  1371. case '2':
  1372. /* HTTP version 2.0 */
  1373. sethttpver(global, config, CURL_HTTP_VERSION_2_0);
  1374. break;
  1375. case '3': /* --http2-prior-knowledge */
  1376. /* HTTP version 2.0 over clean TCP */
  1377. sethttpver(global, config, CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE);
  1378. break;
  1379. case '4': /* --http3 */
  1380. /* Try HTTP/3, allow fallback */
  1381. if(!feature_http3)
  1382. return PARAM_LIBCURL_DOESNT_SUPPORT;
  1383. sethttpver(global, config, CURL_HTTP_VERSION_3);
  1384. break;
  1385. case '5': /* --http3-only */
  1386. /* Try HTTP/3 without fallback */
  1387. if(!feature_http3)
  1388. return PARAM_LIBCURL_DOESNT_SUPPORT;
  1389. sethttpver(global, config, CURL_HTTP_VERSION_3ONLY);
  1390. break;
  1391. case '9':
  1392. /* Allow HTTP/0.9 responses! */
  1393. config->http09_allowed = toggle;
  1394. break;
  1395. }
  1396. break;
  1397. case '1': /* --tlsv1* options */
  1398. switch(subletter) {
  1399. case '\0':
  1400. /* TLS version 1.x */
  1401. config->ssl_version = CURL_SSLVERSION_TLSv1;
  1402. break;
  1403. case '0':
  1404. /* TLS version 1.0 */
  1405. config->ssl_version = CURL_SSLVERSION_TLSv1_0;
  1406. break;
  1407. case '1':
  1408. /* TLS version 1.1 */
  1409. config->ssl_version = CURL_SSLVERSION_TLSv1_1;
  1410. break;
  1411. case '2':
  1412. /* TLS version 1.2 */
  1413. config->ssl_version = CURL_SSLVERSION_TLSv1_2;
  1414. break;
  1415. case '3':
  1416. /* TLS version 1.3 */
  1417. config->ssl_version = CURL_SSLVERSION_TLSv1_3;
  1418. break;
  1419. case 'A': /* --tls13-ciphers */
  1420. GetStr(&config->cipher13_list, nextarg);
  1421. break;
  1422. case 'B': /* --proxy-tls13-ciphers */
  1423. GetStr(&config->proxy_cipher13_list, nextarg);
  1424. break;
  1425. }
  1426. break;
  1427. case '2':
  1428. /* SSL version 2 */
  1429. warnf(global, "Ignores instruction to use SSLv2\n");
  1430. break;
  1431. case '3':
  1432. /* SSL version 3 */
  1433. warnf(global, "Ignores instruction to use SSLv3\n");
  1434. break;
  1435. case '4':
  1436. /* IPv4 */
  1437. config->ip_version = CURL_IPRESOLVE_V4;
  1438. break;
  1439. case '6':
  1440. /* IPv6 */
  1441. config->ip_version = CURL_IPRESOLVE_V6;
  1442. break;
  1443. case 'a':
  1444. /* This makes the FTP sessions use APPE instead of STOR */
  1445. config->ftp_append = toggle;
  1446. break;
  1447. case 'A':
  1448. /* This specifies the User-Agent name */
  1449. GetStr(&config->useragent, nextarg);
  1450. break;
  1451. case 'b':
  1452. switch(subletter) {
  1453. case 'a': /* --alt-svc */
  1454. if(!feature_altsvc)
  1455. return PARAM_LIBCURL_DOESNT_SUPPORT;
  1456. GetStr(&config->altsvc, nextarg);
  1457. break;
  1458. case 'b': /* --hsts */
  1459. if(!feature_hsts)
  1460. return PARAM_LIBCURL_DOESNT_SUPPORT;
  1461. GetStr(&config->hsts, nextarg);
  1462. break;
  1463. default: /* --cookie string coming up: */
  1464. if(nextarg[0] == '@') {
  1465. nextarg++;
  1466. }
  1467. else if(strchr(nextarg, '=')) {
  1468. /* A cookie string must have a =-letter */
  1469. err = add2list(&config->cookies, nextarg);
  1470. if(err)
  1471. return err;
  1472. break;
  1473. }
  1474. /* We have a cookie file to read from! */
  1475. err = add2list(&config->cookiefiles, nextarg);
  1476. if(err)
  1477. return err;
  1478. }
  1479. break;
  1480. case 'B':
  1481. /* use ASCII/text when transferring */
  1482. config->use_ascii = toggle;
  1483. break;
  1484. case 'c':
  1485. /* get the file name to dump all cookies in */
  1486. GetStr(&config->cookiejar, nextarg);
  1487. break;
  1488. case 'C':
  1489. /* This makes us continue an ftp transfer at given position */
  1490. if(strcmp(nextarg, "-")) {
  1491. err = str2offset(&config->resume_from, nextarg);
  1492. if(err)
  1493. return err;
  1494. config->resume_from_current = FALSE;
  1495. }
  1496. else {
  1497. config->resume_from_current = TRUE;
  1498. config->resume_from = 0;
  1499. }
  1500. config->use_resume = TRUE;
  1501. break;
  1502. case 'd':
  1503. /* postfield data */
  1504. {
  1505. char *postdata = NULL;
  1506. FILE *file;
  1507. size_t size = 0;
  1508. bool raw_mode = (subletter == 'r');
  1509. if(subletter == 'g') { /* --url-query */
  1510. #define MAX_QUERY_LEN 100000 /* larger is not likely to ever work */
  1511. char *query;
  1512. struct curlx_dynbuf dyn;
  1513. curlx_dyn_init(&dyn, MAX_QUERY_LEN);
  1514. if(*nextarg == '+') {
  1515. /* use without encoding */
  1516. query = strdup(&nextarg[1]);
  1517. if(!query)
  1518. return PARAM_NO_MEM;
  1519. }
  1520. else {
  1521. err = data_urlencode(global, nextarg, &query, &size);
  1522. if(err)
  1523. return err;
  1524. }
  1525. if(config->query) {
  1526. CURLcode result =
  1527. curlx_dyn_addf(&dyn, "%s&%s", config->query, query);
  1528. free(query);
  1529. if(result)
  1530. return PARAM_NO_MEM;
  1531. free(config->query);
  1532. config->query = curlx_dyn_ptr(&dyn);
  1533. }
  1534. else
  1535. config->query = query;
  1536. break; /* this is not a POST argument at all */
  1537. }
  1538. else if(subletter == 'e') { /* --data-urlencode */
  1539. err = data_urlencode(global, nextarg, &postdata, &size);
  1540. if(err)
  1541. return err;
  1542. }
  1543. else if('@' == *nextarg && !raw_mode) {
  1544. /* the data begins with a '@' letter, it means that a file name
  1545. or - (stdin) follows */
  1546. nextarg++; /* pass the @ */
  1547. if(!strcmp("-", nextarg)) {
  1548. file = stdin;
  1549. if(subletter == 'b') /* forced data-binary */
  1550. set_binmode(stdin);
  1551. }
  1552. else {
  1553. file = fopen(nextarg, "rb");
  1554. if(!file)
  1555. warnf(global, "Couldn't read data from file \"%s\", this makes "
  1556. "an empty POST.\n", nextarg);
  1557. }
  1558. if((subletter == 'b') || /* --data-binary */
  1559. (subletter == 'f') /* --json */)
  1560. /* forced binary */
  1561. err = file2memory(&postdata, &size, file);
  1562. else {
  1563. err = file2string(&postdata, file);
  1564. if(postdata)
  1565. size = strlen(postdata);
  1566. }
  1567. if(file && (file != stdin))
  1568. fclose(file);
  1569. if(err)
  1570. return err;
  1571. if(!postdata) {
  1572. /* no data from the file, point to a zero byte string to make this
  1573. get sent as a POST anyway */
  1574. postdata = strdup("");
  1575. if(!postdata)
  1576. return PARAM_NO_MEM;
  1577. }
  1578. }
  1579. else {
  1580. GetStr(&postdata, nextarg);
  1581. if(postdata)
  1582. size = strlen(postdata);
  1583. }
  1584. if(subletter == 'f')
  1585. config->jsoned = TRUE;
  1586. if(config->postfields) {
  1587. /* we already have a string, we append this one with a separating
  1588. &-letter */
  1589. char *oldpost = config->postfields;
  1590. curl_off_t oldlen = config->postfieldsize;
  1591. curl_off_t newlen = oldlen + curlx_uztoso(size) + 2;
  1592. config->postfields = malloc((size_t)newlen);
  1593. if(!config->postfields) {
  1594. Curl_safefree(oldpost);
  1595. Curl_safefree(postdata);
  1596. return PARAM_NO_MEM;
  1597. }
  1598. memcpy(config->postfields, oldpost, (size_t)oldlen);
  1599. if(subletter != 'f') {
  1600. /* skip this treatment for --json */
  1601. /* use byte value 0x26 for '&' to accommodate non-ASCII platforms */
  1602. config->postfields[oldlen] = '\x26';
  1603. memcpy(&config->postfields[oldlen + 1], postdata, size);
  1604. config->postfields[oldlen + 1 + size] = '\0';
  1605. config->postfieldsize += size + 1;
  1606. }
  1607. else {
  1608. memcpy(&config->postfields[oldlen], postdata, size);
  1609. config->postfields[oldlen + size] = '\0';
  1610. config->postfieldsize += size;
  1611. }
  1612. Curl_safefree(oldpost);
  1613. Curl_safefree(postdata);
  1614. }
  1615. else {
  1616. config->postfields = postdata;
  1617. config->postfieldsize = curlx_uztoso(size);
  1618. }
  1619. }
  1620. /*
  1621. We can't set the request type here, as this data might be used in
  1622. a simple GET if -G is used. Already or soon.
  1623. if(SetHTTPrequest(HTTPREQ_SIMPLEPOST, &config->httpreq)) {
  1624. Curl_safefree(postdata);
  1625. return PARAM_BAD_USE;
  1626. }
  1627. */
  1628. break;
  1629. case 'D':
  1630. /* dump-header to given file name */
  1631. GetStr(&config->headerfile, nextarg);
  1632. break;
  1633. case 'e':
  1634. {
  1635. char *ptr = strstr(nextarg, ";auto");
  1636. if(ptr) {
  1637. /* Automatic referer requested, this may be combined with a
  1638. set initial one */
  1639. config->autoreferer = TRUE;
  1640. *ptr = 0; /* null-terminate here */
  1641. }
  1642. else
  1643. config->autoreferer = FALSE;
  1644. ptr = *nextarg ? nextarg : NULL;
  1645. GetStr(&config->referer, ptr);
  1646. }
  1647. break;
  1648. case 'E':
  1649. switch(subletter) {
  1650. case '\0': /* certificate file */
  1651. cleanarg(clearthis);
  1652. GetFileAndPassword(nextarg, &config->cert, &config->key_passwd);
  1653. break;
  1654. case 'a': /* CA info PEM file */
  1655. GetStr(&config->cacert, nextarg);
  1656. break;
  1657. case 'b': /* cert file type */
  1658. GetStr(&config->cert_type, nextarg);
  1659. break;
  1660. case 'c': /* private key file */
  1661. GetStr(&config->key, nextarg);
  1662. break;
  1663. case 'd': /* private key file type */
  1664. GetStr(&config->key_type, nextarg);
  1665. break;
  1666. case 'e': /* private key passphrase */
  1667. GetStr(&config->key_passwd, nextarg);
  1668. cleanarg(clearthis);
  1669. break;
  1670. case 'f': /* crypto engine */
  1671. GetStr(&config->engine, nextarg);
  1672. if(config->engine && curl_strequal(config->engine, "list"))
  1673. return PARAM_ENGINES_REQUESTED;
  1674. break;
  1675. case 'g': /* CA cert directory */
  1676. GetStr(&config->capath, nextarg);
  1677. break;
  1678. case 'h': /* --pubkey public key file */
  1679. GetStr(&config->pubkey, nextarg);
  1680. break;
  1681. case 'i': /* --hostpubmd5 md5 of the host public key */
  1682. GetStr(&config->hostpubmd5, nextarg);
  1683. if(!config->hostpubmd5 || strlen(config->hostpubmd5) != 32)
  1684. return PARAM_BAD_USE;
  1685. break;
  1686. case 'F': /* --hostpubsha256 sha256 of the host public key */
  1687. GetStr(&config->hostpubsha256, nextarg);
  1688. break;
  1689. case 'j': /* CRL file */
  1690. GetStr(&config->crlfile, nextarg);
  1691. break;
  1692. case 'k': /* TLS username */
  1693. if(!feature_tls_srp) {
  1694. cleanarg(clearthis);
  1695. return PARAM_LIBCURL_DOESNT_SUPPORT;
  1696. }
  1697. GetStr(&config->tls_username, nextarg);
  1698. cleanarg(clearthis);
  1699. break;
  1700. case 'l': /* TLS password */
  1701. if(!feature_tls_srp) {
  1702. cleanarg(clearthis);
  1703. return PARAM_LIBCURL_DOESNT_SUPPORT;
  1704. }
  1705. GetStr(&config->tls_password, nextarg);
  1706. cleanarg(clearthis);
  1707. break;
  1708. case 'm': /* TLS authentication type */
  1709. if(!feature_tls_srp)
  1710. return PARAM_LIBCURL_DOESNT_SUPPORT;
  1711. GetStr(&config->tls_authtype, nextarg);
  1712. if(!curl_strequal(config->tls_authtype, "SRP"))
  1713. return PARAM_LIBCURL_DOESNT_SUPPORT; /* only support TLS-SRP */
  1714. break;
  1715. case 'n': /* no empty SSL fragments, --ssl-allow-beast */
  1716. if(feature_ssl)
  1717. config->ssl_allow_beast = toggle;
  1718. break;
  1719. case 'o': /* --ssl-auto-client-cert */
  1720. if(feature_ssl)
  1721. config->ssl_auto_client_cert = toggle;
  1722. break;
  1723. case 'O': /* --proxy-ssl-auto-client-cert */
  1724. if(feature_ssl)
  1725. config->proxy_ssl_auto_client_cert = toggle;
  1726. break;
  1727. case 'p': /* Pinned public key DER file */
  1728. GetStr(&config->pinnedpubkey, nextarg);
  1729. break;
  1730. case 'P': /* proxy pinned public key */
  1731. GetStr(&config->proxy_pinnedpubkey, nextarg);
  1732. break;
  1733. case 'q': /* --cert-status */
  1734. config->verifystatus = TRUE;
  1735. break;
  1736. case 'Q': /* --doh-cert-status */
  1737. config->doh_verifystatus = TRUE;
  1738. break;
  1739. case 'r': /* --false-start */
  1740. config->falsestart = TRUE;
  1741. break;
  1742. case 's': /* --ssl-no-revoke */
  1743. if(feature_ssl)
  1744. config->ssl_no_revoke = TRUE;
  1745. break;
  1746. case 'S': /* --ssl-revoke-best-effort */
  1747. if(feature_ssl)
  1748. config->ssl_revoke_best_effort = TRUE;
  1749. break;
  1750. case 't': /* --tcp-fastopen */
  1751. config->tcp_fastopen = TRUE;
  1752. break;
  1753. case 'u': /* TLS username for proxy */
  1754. cleanarg(clearthis);
  1755. if(!feature_tls_srp)
  1756. return PARAM_LIBCURL_DOESNT_SUPPORT;
  1757. GetStr(&config->proxy_tls_username, nextarg);
  1758. break;
  1759. case 'v': /* TLS password for proxy */
  1760. cleanarg(clearthis);
  1761. if(!feature_tls_srp)
  1762. return PARAM_LIBCURL_DOESNT_SUPPORT;
  1763. GetStr(&config->proxy_tls_password, nextarg);
  1764. break;
  1765. case 'w': /* TLS authentication type for proxy */
  1766. if(!feature_tls_srp)
  1767. return PARAM_LIBCURL_DOESNT_SUPPORT;
  1768. GetStr(&config->proxy_tls_authtype, nextarg);
  1769. if(!curl_strequal(config->proxy_tls_authtype, "SRP"))
  1770. return PARAM_LIBCURL_DOESNT_SUPPORT; /* only support TLS-SRP */
  1771. break;
  1772. case 'x': /* certificate file for proxy */
  1773. cleanarg(clearthis);
  1774. GetFileAndPassword(nextarg, &config->proxy_cert,
  1775. &config->proxy_key_passwd);
  1776. break;
  1777. case 'y': /* cert file type for proxy */
  1778. GetStr(&config->proxy_cert_type, nextarg);
  1779. break;
  1780. case 'z': /* private key file for proxy */
  1781. GetStr(&config->proxy_key, nextarg);
  1782. break;
  1783. case '0': /* private key file type for proxy */
  1784. GetStr(&config->proxy_key_type, nextarg);
  1785. break;
  1786. case '1': /* private key passphrase for proxy */
  1787. GetStr(&config->proxy_key_passwd, nextarg);
  1788. cleanarg(clearthis);
  1789. break;
  1790. case '2': /* ciphers for proxy */
  1791. GetStr(&config->proxy_cipher_list, nextarg);
  1792. break;
  1793. case '3': /* CRL file for proxy */
  1794. GetStr(&config->proxy_crlfile, nextarg);
  1795. break;
  1796. case '4': /* no empty SSL fragments for proxy */
  1797. if(feature_ssl)
  1798. config->proxy_ssl_allow_beast = toggle;
  1799. break;
  1800. case '5': /* --login-options */
  1801. GetStr(&config->login_options, nextarg);
  1802. break;
  1803. case '6': /* CA info PEM file for proxy */
  1804. GetStr(&config->proxy_cacert, nextarg);
  1805. break;
  1806. case '7': /* CA cert directory for proxy */
  1807. GetStr(&config->proxy_capath, nextarg);
  1808. break;
  1809. case '8': /* allow insecure SSL connects for proxy */
  1810. config->proxy_insecure_ok = toggle;
  1811. break;
  1812. case '9': /* --proxy-tlsv1 */
  1813. /* TLS version 1 for proxy */
  1814. config->proxy_ssl_version = CURL_SSLVERSION_TLSv1;
  1815. break;
  1816. case 'A':
  1817. /* --socks5-basic */
  1818. if(toggle)
  1819. config->socks5_auth |= CURLAUTH_BASIC;
  1820. else
  1821. config->socks5_auth &= ~CURLAUTH_BASIC;
  1822. break;
  1823. case 'B':
  1824. /* --socks5-gssapi */
  1825. if(toggle)
  1826. config->socks5_auth |= CURLAUTH_GSSAPI;
  1827. else
  1828. config->socks5_auth &= ~CURLAUTH_GSSAPI;
  1829. break;
  1830. case 'C':
  1831. GetStr(&config->etag_save_file, nextarg);
  1832. break;
  1833. case 'D':
  1834. GetStr(&config->etag_compare_file, nextarg);
  1835. break;
  1836. case 'E':
  1837. GetStr(&config->ssl_ec_curves, nextarg);
  1838. break;
  1839. default: /* unknown flag */
  1840. return PARAM_OPTION_UNKNOWN;
  1841. }
  1842. break;
  1843. case 'f':
  1844. switch(subletter) {
  1845. case 'a': /* --fail-early */
  1846. global->fail_early = toggle;
  1847. break;
  1848. case 'b': /* --styled-output */
  1849. global->styled_output = toggle;
  1850. break;
  1851. case 'c': /* --mail-rcpt-allowfails */
  1852. config->mail_rcpt_allowfails = toggle;
  1853. break;
  1854. case 'd': /* --fail-with-body */
  1855. config->failwithbody = toggle;
  1856. break;
  1857. case 'e': /* --remove-on-error */
  1858. config->rm_partial = toggle;
  1859. break;
  1860. default: /* --fail (hard on errors) */
  1861. config->failonerror = toggle;
  1862. break;
  1863. }
  1864. if(config->failonerror && config->failwithbody) {
  1865. errorf(config->global, "You must select either --fail or "
  1866. "--fail-with-body, not both.\n");
  1867. return PARAM_BAD_USE;
  1868. }
  1869. break;
  1870. case 'F':
  1871. /* "form data" simulation, this is a little advanced so lets do our best
  1872. to sort this out slowly and carefully */
  1873. if(formparse(config,
  1874. nextarg,
  1875. &config->mimeroot,
  1876. &config->mimecurrent,
  1877. (subletter == 's')?TRUE:FALSE)) /* 's' is literal string */
  1878. return PARAM_BAD_USE;
  1879. if(SetHTTPrequest(config, HTTPREQ_MIMEPOST, &config->httpreq))
  1880. return PARAM_BAD_USE;
  1881. break;
  1882. case 'g': /* g disables URLglobbing */
  1883. config->globoff = toggle;
  1884. break;
  1885. case 'G': /* HTTP GET */
  1886. if(subletter == 'a') { /* --request-target */
  1887. GetStr(&config->request_target, nextarg);
  1888. }
  1889. else
  1890. config->use_httpget = toggle;
  1891. break;
  1892. case 'h': /* h for help */
  1893. if(toggle) {
  1894. if(nextarg) {
  1895. global->help_category = strdup(nextarg);
  1896. if(!global->help_category)
  1897. return PARAM_NO_MEM;
  1898. }
  1899. return PARAM_HELP_REQUESTED;
  1900. }
  1901. /* we now actually support --no-help too! */
  1902. break;
  1903. case 'H':
  1904. /* A custom header to append to a list */
  1905. if(nextarg[0] == '@') {
  1906. /* read many headers from a file or stdin */
  1907. char *string;
  1908. size_t len;
  1909. bool use_stdin = !strcmp(&nextarg[1], "-");
  1910. FILE *file = use_stdin?stdin:fopen(&nextarg[1], FOPEN_READTEXT);
  1911. if(!file)
  1912. warnf(global, "Failed to open %s!\n", &nextarg[1]);
  1913. else {
  1914. err = file2memory(&string, &len, file);
  1915. if(!err && string) {
  1916. /* Allow strtok() here since this isn't used threaded */
  1917. /* !checksrc! disable BANNEDFUNC 2 */
  1918. char *h = strtok(string, "\r\n");
  1919. while(h) {
  1920. if(subletter == 'p') /* --proxy-header */
  1921. err = add2list(&config->proxyheaders, h);
  1922. else
  1923. err = add2list(&config->headers, h);
  1924. if(err)
  1925. break;
  1926. h = strtok(NULL, "\r\n");
  1927. }
  1928. free(string);
  1929. }
  1930. if(!use_stdin)
  1931. fclose(file);
  1932. if(err)
  1933. return err;
  1934. }
  1935. }
  1936. else {
  1937. if(subletter == 'p') /* --proxy-header */
  1938. err = add2list(&config->proxyheaders, nextarg);
  1939. else
  1940. err = add2list(&config->headers, nextarg);
  1941. if(err)
  1942. return err;
  1943. }
  1944. break;
  1945. case 'i':
  1946. config->show_headers = toggle; /* show the headers as well in the
  1947. general output stream */
  1948. break;
  1949. case 'j':
  1950. config->cookiesession = toggle;
  1951. break;
  1952. case 'I': /* --head */
  1953. config->no_body = toggle;
  1954. config->show_headers = toggle;
  1955. if(SetHTTPrequest(config,
  1956. (config->no_body)?HTTPREQ_HEAD:HTTPREQ_GET,
  1957. &config->httpreq))
  1958. return PARAM_BAD_USE;
  1959. break;
  1960. case 'J': /* --remote-header-name */
  1961. config->content_disposition = toggle;
  1962. break;
  1963. case 'k': /* allow insecure SSL connects */
  1964. if(subletter == 'd') /* --doh-insecure */
  1965. config->doh_insecure_ok = toggle;
  1966. else
  1967. config->insecure_ok = toggle;
  1968. break;
  1969. case 'K': /* parse config file */
  1970. if(parseconfig(nextarg, global)) {
  1971. errorf(global, "cannot read config from '%s'\n", nextarg);
  1972. return PARAM_READ_ERROR;
  1973. }
  1974. break;
  1975. case 'l':
  1976. config->dirlistonly = toggle; /* only list the names of the FTP dir */
  1977. break;
  1978. case 'L':
  1979. config->followlocation = toggle; /* Follow Location: HTTP headers */
  1980. switch(subletter) {
  1981. case 't':
  1982. /* Continue to send authentication (user+password) when following
  1983. * locations, even when hostname changed */
  1984. config->unrestricted_auth = toggle;
  1985. break;
  1986. }
  1987. break;
  1988. case 'm':
  1989. /* specified max time */
  1990. err = secs2ms(&config->timeout_ms, nextarg);
  1991. if(err)
  1992. return err;
  1993. break;
  1994. case 'M': /* M for manual, huge help */
  1995. if(toggle) { /* --no-manual shows no manual... */
  1996. #ifndef USE_MANUAL
  1997. warnf(global,
  1998. "built-in manual was disabled at build-time!\n");
  1999. #endif
  2000. return PARAM_MANUAL_REQUESTED;
  2001. }
  2002. break;
  2003. case 'n':
  2004. switch(subletter) {
  2005. case 'o': /* use .netrc or URL */
  2006. config->netrc_opt = toggle;
  2007. break;
  2008. case 'e': /* netrc-file */
  2009. GetStr(&config->netrc_file, nextarg);
  2010. break;
  2011. default:
  2012. /* pick info from .netrc, if this is used for http, curl will
  2013. automatically enforce user+password with the request */
  2014. config->netrc = toggle;
  2015. break;
  2016. }
  2017. break;
  2018. case 'N':
  2019. /* disable the output I/O buffering. note that the option is called
  2020. --buffer but is mostly used in the negative form: --no-buffer */
  2021. config->nobuffer = longopt ? !toggle : TRUE;
  2022. break;
  2023. case 'O': /* --remote-name */
  2024. if(subletter == 'a') { /* --remote-name-all */
  2025. config->default_node_flags = toggle?GETOUT_USEREMOTE:0;
  2026. break;
  2027. }
  2028. else if(subletter == 'b') { /* --output-dir */
  2029. GetStr(&config->output_dir, nextarg);
  2030. break;
  2031. }
  2032. else if(subletter == 'c') { /* --clobber / --no-clobber */
  2033. config->file_clobber_mode = toggle ? CLOBBER_ALWAYS : CLOBBER_NEVER;
  2034. break;
  2035. }
  2036. /* FALLTHROUGH */
  2037. case 'o': /* --output */
  2038. /* output file */
  2039. {
  2040. struct getout *url;
  2041. if(!config->url_out)
  2042. config->url_out = config->url_list;
  2043. if(config->url_out) {
  2044. /* there's a node here, if it already is filled-in continue to find
  2045. an "empty" node */
  2046. while(config->url_out && (config->url_out->flags & GETOUT_OUTFILE))
  2047. config->url_out = config->url_out->next;
  2048. }
  2049. /* now there might or might not be an available node to fill in! */
  2050. if(config->url_out)
  2051. /* existing node */
  2052. url = config->url_out;
  2053. else
  2054. /* there was no free node, create one! */
  2055. config->url_out = url = new_getout(config);
  2056. if(!url)
  2057. return PARAM_NO_MEM;
  2058. /* fill in the outfile */
  2059. if('o' == letter) {
  2060. if(!*nextarg) {
  2061. warnf(global, "output file name has no length\n");
  2062. return PARAM_BAD_USE;
  2063. }
  2064. GetStr(&url->outfile, nextarg);
  2065. url->flags &= ~GETOUT_USEREMOTE; /* switch off */
  2066. }
  2067. else {
  2068. url->outfile = NULL; /* leave it */
  2069. if(toggle)
  2070. url->flags |= GETOUT_USEREMOTE; /* switch on */
  2071. else
  2072. url->flags &= ~GETOUT_USEREMOTE; /* switch off */
  2073. }
  2074. url->flags |= GETOUT_OUTFILE;
  2075. }
  2076. break;
  2077. case 'P':
  2078. /* This makes the FTP sessions use PORT instead of PASV */
  2079. /* use <eth0> or <192.168.10.10> style addresses. Anything except
  2080. this will make us try to get the "default" address.
  2081. NOTE: this is a changed behavior since the released 4.1!
  2082. */
  2083. GetStr(&config->ftpport, nextarg);
  2084. break;
  2085. case 'p':
  2086. /* proxy tunnel for non-http protocols */
  2087. config->proxytunnel = toggle;
  2088. break;
  2089. case 'q': /* if used first, already taken care of, we do it like
  2090. this so we don't cause an error! */
  2091. break;
  2092. case 'Q':
  2093. /* QUOTE command to send to FTP server */
  2094. switch(nextarg[0]) {
  2095. case '-':
  2096. /* prefixed with a dash makes it a POST TRANSFER one */
  2097. nextarg++;
  2098. err = add2list(&config->postquote, nextarg);
  2099. break;
  2100. case '+':
  2101. /* prefixed with a plus makes it a just-before-transfer one */
  2102. nextarg++;
  2103. err = add2list(&config->prequote, nextarg);
  2104. break;
  2105. default:
  2106. err = add2list(&config->quote, nextarg);
  2107. break;
  2108. }
  2109. if(err)
  2110. return err;
  2111. break;
  2112. case 'r':
  2113. /* Specifying a range WITHOUT A DASH will create an illegal HTTP range
  2114. (and won't actually be range by definition). The man page previously
  2115. claimed that to be a good way, why this code is added to work-around
  2116. it. */
  2117. if(ISDIGIT(*nextarg) && !strchr(nextarg, '-')) {
  2118. char buffer[32];
  2119. curl_off_t off;
  2120. if(curlx_strtoofft(nextarg, NULL, 10, &off)) {
  2121. warnf(global, "unsupported range point\n");
  2122. return PARAM_BAD_USE;
  2123. }
  2124. warnf(global,
  2125. "A specified range MUST include at least one dash (-). "
  2126. "Appending one for you!\n");
  2127. msnprintf(buffer, sizeof(buffer), "%" CURL_FORMAT_CURL_OFF_T "-", off);
  2128. Curl_safefree(config->range);
  2129. config->range = strdup(buffer);
  2130. if(!config->range)
  2131. return PARAM_NO_MEM;
  2132. }
  2133. else {
  2134. /* byte range requested */
  2135. const char *tmp_range = nextarg;
  2136. while(*tmp_range != '\0') {
  2137. if(!ISDIGIT(*tmp_range) && *tmp_range != '-' && *tmp_range != ',') {
  2138. warnf(global, "Invalid character is found in given range. "
  2139. "A specified range MUST have only digits in "
  2140. "\'start\'-\'stop\'. The server's response to this "
  2141. "request is uncertain.\n");
  2142. break;
  2143. }
  2144. tmp_range++;
  2145. }
  2146. GetStr(&config->range, nextarg);
  2147. }
  2148. break;
  2149. case 'R':
  2150. /* use remote file's time */
  2151. config->remote_time = toggle;
  2152. break;
  2153. case 's':
  2154. /* don't show progress meter, don't show errors : */
  2155. if(toggle)
  2156. global->mute = global->noprogress = TRUE;
  2157. else
  2158. global->mute = global->noprogress = FALSE;
  2159. if(global->showerror < 0)
  2160. /* if still on the default value, set showerror to the reverse of
  2161. toggle. This is to allow -S and -s to be used in an independent
  2162. order but still have the same effect. */
  2163. global->showerror = (!toggle)?TRUE:FALSE; /* toggle off */
  2164. break;
  2165. case 'S':
  2166. /* show errors */
  2167. global->showerror = toggle?1:0; /* toggle on if used with -s */
  2168. break;
  2169. case 't':
  2170. /* Telnet options */
  2171. err = add2list(&config->telnet_options, nextarg);
  2172. if(err)
  2173. return err;
  2174. break;
  2175. case 'T':
  2176. /* we are uploading */
  2177. {
  2178. struct getout *url;
  2179. if(!config->url_ul)
  2180. config->url_ul = config->url_list;
  2181. if(config->url_ul) {
  2182. /* there's a node here, if it already is filled-in continue to find
  2183. an "empty" node */
  2184. while(config->url_ul && (config->url_ul->flags & GETOUT_UPLOAD))
  2185. config->url_ul = config->url_ul->next;
  2186. }
  2187. /* now there might or might not be an available node to fill in! */
  2188. if(config->url_ul)
  2189. /* existing node */
  2190. url = config->url_ul;
  2191. else
  2192. /* there was no free node, create one! */
  2193. config->url_ul = url = new_getout(config);
  2194. if(!url)
  2195. return PARAM_NO_MEM;
  2196. url->flags |= GETOUT_UPLOAD; /* mark -T used */
  2197. if(!*nextarg)
  2198. url->flags |= GETOUT_NOUPLOAD;
  2199. else {
  2200. /* "-" equals stdin, but keep the string around for now */
  2201. GetStr(&url->infile, nextarg);
  2202. }
  2203. }
  2204. break;
  2205. case 'u':
  2206. /* user:password */
  2207. GetStr(&config->userpwd, nextarg);
  2208. cleanarg(clearthis);
  2209. break;
  2210. case 'U':
  2211. /* Proxy user:password */
  2212. GetStr(&config->proxyuserpwd, nextarg);
  2213. cleanarg(clearthis);
  2214. break;
  2215. case 'v':
  2216. if(toggle) {
  2217. /* the '%' thing here will cause the trace get sent to stderr */
  2218. Curl_safefree(global->trace_dump);
  2219. global->trace_dump = strdup("%");
  2220. if(!global->trace_dump)
  2221. return PARAM_NO_MEM;
  2222. if(global->tracetype && (global->tracetype != TRACE_PLAIN))
  2223. warnf(global,
  2224. "-v, --verbose overrides an earlier trace/verbose option\n");
  2225. global->tracetype = TRACE_PLAIN;
  2226. }
  2227. else
  2228. /* verbose is disabled here */
  2229. global->tracetype = TRACE_NONE;
  2230. break;
  2231. case 'V':
  2232. if(toggle) /* --no-version yields no output! */
  2233. return PARAM_VERSION_INFO_REQUESTED;
  2234. break;
  2235. case 'w':
  2236. /* get the output string */
  2237. if('@' == *nextarg) {
  2238. /* the data begins with a '@' letter, it means that a file name
  2239. or - (stdin) follows */
  2240. FILE *file;
  2241. const char *fname;
  2242. nextarg++; /* pass the @ */
  2243. if(!strcmp("-", nextarg)) {
  2244. fname = "<stdin>";
  2245. file = stdin;
  2246. }
  2247. else {
  2248. fname = nextarg;
  2249. file = fopen(nextarg, FOPEN_READTEXT);
  2250. }
  2251. Curl_safefree(config->writeout);
  2252. err = file2string(&config->writeout, file);
  2253. if(file && (file != stdin))
  2254. fclose(file);
  2255. if(err)
  2256. return err;
  2257. if(!config->writeout)
  2258. warnf(global, "Failed to read %s", fname);
  2259. }
  2260. else
  2261. GetStr(&config->writeout, nextarg);
  2262. break;
  2263. case 'x':
  2264. switch(subletter) {
  2265. case 'a': /* --preproxy */
  2266. GetStr(&config->preproxy, nextarg);
  2267. break;
  2268. default:
  2269. /* --proxy */
  2270. GetStr(&config->proxy, nextarg);
  2271. config->proxyver = CURLPROXY_HTTP;
  2272. break;
  2273. }
  2274. break;
  2275. case 'X':
  2276. /* set custom request */
  2277. GetStr(&config->customrequest, nextarg);
  2278. break;
  2279. case 'y':
  2280. /* low speed time */
  2281. err = str2unum(&config->low_speed_time, nextarg);
  2282. if(err)
  2283. return err;
  2284. if(!config->low_speed_limit)
  2285. config->low_speed_limit = 1;
  2286. break;
  2287. case 'Y':
  2288. /* low speed limit */
  2289. err = str2unum(&config->low_speed_limit, nextarg);
  2290. if(err)
  2291. return err;
  2292. if(!config->low_speed_time)
  2293. config->low_speed_time = 30;
  2294. break;
  2295. case 'Z':
  2296. switch(subletter) {
  2297. case '\0': /* --parallel */
  2298. global->parallel = toggle;
  2299. break;
  2300. case 'b': /* --parallel-max */
  2301. err = str2unum(&global->parallel_max, nextarg);
  2302. if(err)
  2303. return err;
  2304. if(global->parallel_max > MAX_PARALLEL)
  2305. global->parallel_max = MAX_PARALLEL;
  2306. else if(global->parallel_max < 1)
  2307. global->parallel_max = PARALLEL_DEFAULT;
  2308. break;
  2309. case 'c': /* --parallel-connect */
  2310. global->parallel_connect = toggle;
  2311. break;
  2312. }
  2313. break;
  2314. case 'z': /* time condition coming up */
  2315. switch(*nextarg) {
  2316. case '+':
  2317. nextarg++;
  2318. /* FALLTHROUGH */
  2319. default:
  2320. /* If-Modified-Since: (section 14.28 in RFC2068) */
  2321. config->timecond = CURL_TIMECOND_IFMODSINCE;
  2322. break;
  2323. case '-':
  2324. /* If-Unmodified-Since: (section 14.24 in RFC2068) */
  2325. config->timecond = CURL_TIMECOND_IFUNMODSINCE;
  2326. nextarg++;
  2327. break;
  2328. case '=':
  2329. /* Last-Modified: (section 14.29 in RFC2068) */
  2330. config->timecond = CURL_TIMECOND_LASTMOD;
  2331. nextarg++;
  2332. break;
  2333. }
  2334. now = time(NULL);
  2335. config->condtime = (curl_off_t)curl_getdate(nextarg, &now);
  2336. if(-1 == config->condtime) {
  2337. /* now let's see if it is a file name to get the time from instead! */
  2338. curl_off_t filetime = getfiletime(nextarg, global);
  2339. if(filetime >= 0) {
  2340. /* pull the time out from the file */
  2341. config->condtime = filetime;
  2342. }
  2343. else {
  2344. /* failed, remove time condition */
  2345. config->timecond = CURL_TIMECOND_NONE;
  2346. warnf(global,
  2347. "Illegal date format for -z, --time-cond (and not "
  2348. "a file name). Disabling time condition. "
  2349. "See curl_getdate(3) for valid date syntax.\n");
  2350. }
  2351. }
  2352. break;
  2353. default: /* unknown flag */
  2354. return PARAM_OPTION_UNKNOWN;
  2355. }
  2356. hit = -1;
  2357. } while(!longopt && !singleopt && *++parse && !*usedarg);
  2358. return PARAM_OK;
  2359. }
  2360. ParameterError parse_args(struct GlobalConfig *global, int argc,
  2361. argv_item_t argv[])
  2362. {
  2363. int i;
  2364. bool stillflags;
  2365. char *orig_opt = NULL;
  2366. ParameterError result = PARAM_OK;
  2367. struct OperationConfig *config = global->first;
  2368. for(i = 1, stillflags = TRUE; i < argc && !result; i++) {
  2369. orig_opt = curlx_convert_tchar_to_UTF8(argv[i]);
  2370. if(!orig_opt)
  2371. return PARAM_NO_MEM;
  2372. if(stillflags && ('-' == orig_opt[0])) {
  2373. bool passarg;
  2374. if(!strcmp("--", orig_opt))
  2375. /* This indicates the end of the flags and thus enables the
  2376. following (URL) argument to start with -. */
  2377. stillflags = FALSE;
  2378. else {
  2379. char *nextarg = NULL;
  2380. if(i < (argc - 1)) {
  2381. nextarg = curlx_convert_tchar_to_UTF8(argv[i + 1]);
  2382. if(!nextarg) {
  2383. curlx_unicodefree(orig_opt);
  2384. return PARAM_NO_MEM;
  2385. }
  2386. }
  2387. result = getparameter(orig_opt, nextarg, argv[i + 1], &passarg,
  2388. global, config);
  2389. curlx_unicodefree(nextarg);
  2390. config = global->last;
  2391. if(result == PARAM_NEXT_OPERATION) {
  2392. /* Reset result as PARAM_NEXT_OPERATION is only used here and not
  2393. returned from this function */
  2394. result = PARAM_OK;
  2395. if(config->url_list && config->url_list->url) {
  2396. /* Allocate the next config */
  2397. config->next = malloc(sizeof(struct OperationConfig));
  2398. if(config->next) {
  2399. /* Initialise the newly created config */
  2400. config_init(config->next);
  2401. /* Set the global config pointer */
  2402. config->next->global = global;
  2403. /* Update the last config pointer */
  2404. global->last = config->next;
  2405. /* Move onto the new config */
  2406. config->next->prev = config;
  2407. config = config->next;
  2408. }
  2409. else
  2410. result = PARAM_NO_MEM;
  2411. }
  2412. }
  2413. else if(!result && passarg)
  2414. i++; /* we're supposed to skip this */
  2415. }
  2416. }
  2417. else {
  2418. bool used;
  2419. /* Just add the URL please */
  2420. result = getparameter("--url", orig_opt, argv[i], &used, global, config);
  2421. }
  2422. if(!result)
  2423. curlx_unicodefree(orig_opt);
  2424. }
  2425. if(!result && config->content_disposition) {
  2426. if(config->show_headers)
  2427. result = PARAM_CONTDISP_SHOW_HEADER;
  2428. else if(config->resume_from_current)
  2429. result = PARAM_CONTDISP_RESUME_FROM;
  2430. }
  2431. if(result && result != PARAM_HELP_REQUESTED &&
  2432. result != PARAM_MANUAL_REQUESTED &&
  2433. result != PARAM_VERSION_INFO_REQUESTED &&
  2434. result != PARAM_ENGINES_REQUESTED) {
  2435. const char *reason = param2text(result);
  2436. if(orig_opt && strcmp(":", orig_opt))
  2437. helpf(global->errors, "option %s: %s\n", orig_opt, reason);
  2438. else
  2439. helpf(global->errors, "%s\n", reason);
  2440. }
  2441. curlx_unicodefree(orig_opt);
  2442. return result;
  2443. }