tool_getparam.c 81 KB

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