tool_getparam.c 78 KB

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