tool_getparam.c 82 KB

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