master
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"
26#include "tool_help.h"
27#include "tool_libinfo.h"
28#include "tool_util.h"
29#include "tool_version.h"
30#include "tool_hugehelp.h"
31#include "tool_getparam.h"
32#include "tool_cfgable.h"
33#include "terminal.h"
35struct category_descriptors {
36 const char *opt;
37 const char *desc;
38 unsigned int category;
39};
41static const struct category_descriptors categories[] = {
42 /* important is left out because it is the default help page */
43 { "auth", "Authentication methods", CURLHELP_AUTH },
44 { "connection", "Manage connections", CURLHELP_CONNECTION },
45 { "curl", "The command line tool itself", CURLHELP_CURL },
46 { "deprecated", "Legacy", CURLHELP_DEPRECATED },
47 { "dns", "Names and resolving", CURLHELP_DNS },
48 { "file", "FILE protocol", CURLHELP_FILE },
49 { "ftp", "FTP protocol", CURLHELP_FTP },
50 { "global", "Global options", CURLHELP_GLOBAL },
51 { "http", "HTTP and HTTPS protocol", CURLHELP_HTTP },
52 { "imap", "IMAP protocol", CURLHELP_IMAP },
53 { "ldap", "LDAP protocol", CURLHELP_LDAP },
54 { "mqtt", "MQTT protocol", CURLHELP_MQTT },
55 { "output", "File system output", CURLHELP_OUTPUT },
56 { "pop3", "POP3 protocol", CURLHELP_POP3 },
57 { "post", "HTTP POST specific", CURLHELP_POST },
58 { "proxy", "Options for proxies", CURLHELP_PROXY },
59 { "scp", "SCP protocol", CURLHELP_SCP },
60 { "sftp", "SFTP protocol", CURLHELP_SFTP },
61 { "smtp", "SMTP protocol", CURLHELP_SMTP },
62 { "ssh", "SSH protocol", CURLHELP_SSH },
63 { "telnet", "TELNET protocol", CURLHELP_TELNET },
64 { "tftp", "TFTP protocol", CURLHELP_TFTP },
65 { "timeout", "Timeouts and delays", CURLHELP_TIMEOUT },
66 { "tls", "TLS/SSL related", CURLHELP_TLS },
67 { "upload", "Upload, sending data", CURLHELP_UPLOAD },
68 { "verbose", "Tracing, logging etc", CURLHELP_VERBOSE }
69};
71static void print_category(unsigned int category, unsigned int cols)
72{
73 unsigned int i;
74 size_t longopt = 5;
75 size_t longdesc = 5;
77 for(i = 0; helptext[i].opt; ++i) {
78 size_t len;
79 if(!(helptext[i].categories & category))
80 continue;
81 len = strlen(helptext[i].opt);
82 if(len > longopt)
83 longopt = len;
84 len = strlen(helptext[i].desc);
85 if(len > longdesc)
86 longdesc = len;
87 }
89 if(longdesc > cols)
90 longopt = 0; /* avoid wrap-around */
91 else if(longopt + longdesc > cols)
92 longopt = cols - longdesc;
94 for(i = 0; helptext[i].opt; ++i)
95 if(helptext[i].categories & category) {
96 size_t opt = longopt;
97 size_t desclen = strlen(helptext[i].desc);
98 /* avoid wrap-around */
99 if(cols >= 2 && opt + desclen >= (cols - 2)) {
100 if(desclen < (cols - 2))
101 opt = (cols - 3) - desclen;
102 else
103 opt = 0;
104 }
105 curl_mprintf(" %-*s %s\n", (int)opt, helptext[i].opt, helptext[i].desc);
106 }
107}
109/* Prints category if found. If not, it returns 1 */
110static int get_category_content(const char *category, unsigned int cols)
111{
112 unsigned int i;
113 for(i = 0; i < CURL_ARRAYSIZE(categories); ++i)
114 if(curl_strequal(categories[i].opt, category)) {
115 curl_mprintf("%s: %s\n", categories[i].opt, categories[i].desc);
116 print_category(categories[i].category, cols);
117 return 0;
118 }
119 return 1;
120}
122/* Prints all categories and their description */
123static void get_categories(void)
124{
125 unsigned int i;
126 for(i = 0; i < CURL_ARRAYSIZE(categories); ++i)
127 curl_mprintf(" %-11s %s\n", categories[i].opt, categories[i].desc);
128}
130/* Prints all categories as a comma-separated list of given width */
131static void get_categories_list(unsigned int width)
132{
133 unsigned int i;
134 size_t col = 0;
135 for(i = 0; i < CURL_ARRAYSIZE(categories); ++i) {
136 size_t len = strlen(categories[i].opt);
137 if(i == CURL_ARRAYSIZE(categories) - 1) {
138 /* final category */
139 if(col + len + 1 < width)
140 curl_mprintf("%s.\n", categories[i].opt);
141 else
142 /* start a new line first */
143 curl_mprintf("\n%s.\n", categories[i].opt);
144 }
145 else if(col + len + 2 < width) {
146 curl_mprintf("%s, ", categories[i].opt);
147 col += len + 2;
148 }
149 else {
150 /* start a new line first */
151 curl_mprintf("\n%s, ", categories[i].opt);
152 col = len + 2;
153 }
154 }
155}
157#ifdef USE_MANUAL
159void inithelpscan(struct scan_ctx *ctx,
160 const char *trigger,
161 const char *arg,
162 const char *endarg)
163{
164 ctx->trigger = trigger;
165 ctx->tlen = strlen(trigger);
166 ctx->arg = arg;
167 ctx->flen = strlen(arg);
168 ctx->endarg = endarg;
169 ctx->elen = strlen(endarg);
170 DEBUGASSERT((ctx->elen < sizeof(ctx->rbuf)) &&
171 (ctx->flen < sizeof(ctx->rbuf)) &&
172 (ctx->tlen < sizeof(ctx->rbuf)));
173 ctx->show = 0;
174 ctx->olen = 0;
175 memset(ctx->rbuf, 0, sizeof(ctx->rbuf));
176}
178bool helpscan(const unsigned char *buf, size_t len, struct scan_ctx *ctx)
179{
180 size_t i;
181 for(i = 0; i < len; i++) {
182 if(!ctx->show) {
183 /* wait for the trigger */
184 memmove(&ctx->rbuf[0], &ctx->rbuf[1], ctx->tlen - 1);
185 ctx->rbuf[ctx->tlen - 1] = buf[i];
186 if(!memcmp(ctx->rbuf, ctx->trigger, ctx->tlen))
187 ctx->show++;
188 continue;
189 }
190 /* past the trigger */
191 if(ctx->show == 1) {
192 memmove(&ctx->rbuf[0], &ctx->rbuf[1], ctx->flen - 1);
193 ctx->rbuf[ctx->flen - 1] = buf[i];
194 if(!memcmp(ctx->rbuf, ctx->arg, ctx->flen)) {
195 /* match, now output until endarg */
196 fputs(&ctx->arg[1], stdout);
197 ctx->show++;
198 }
199 continue;
200 }
201 /* show until the end */
202 memmove(&ctx->rbuf[0], &ctx->rbuf[1], ctx->elen - 1);
203 ctx->rbuf[ctx->elen - 1] = buf[i];
204 if(!memcmp(ctx->rbuf, ctx->endarg, ctx->elen))
205 return FALSE;
207 if(buf[i] == '\n') {
208 DEBUGASSERT(ctx->olen < sizeof(ctx->obuf));
209 if(ctx->olen == sizeof(ctx->obuf))
210 return FALSE; /* bail out */
211 ctx->obuf[ctx->olen++] = 0;
212 ctx->olen = 0;
213 puts(ctx->obuf);
214 }
215 else {
216 DEBUGASSERT(ctx->olen < sizeof(ctx->obuf));
217 if(ctx->olen == sizeof(ctx->obuf))
218 return FALSE; /* bail out */
219 ctx->obuf[ctx->olen++] = buf[i];
220 }
221 }
222 return TRUE;
223}
225#endif
227void tool_help(const char *category)
228{
229 unsigned int cols = get_terminal_columns();
230 /* If no category was provided */
231 if(!category) {
232 const char *category_note =
233 "\nThis is not the full help; this "
234 "menu is split into categories.\nUse \"--help category\" to get "
235 "an overview of all categories, which are:";
236 const char *category_note2 =
237 "Use \"--help all\" to list all options"
238#ifdef USE_MANUAL
239 "\nUse \"--help [option]\" to view documentation for a given option"
240#endif
241 ;
242 puts("Usage: curl [options...] <url>");
243 print_category(CURLHELP_IMPORTANT, cols);
244 puts(category_note);
245 get_categories_list(cols);
246 puts(category_note2);
247 }
248 /* Lets print everything if "all" was provided */
249 else if(curl_strequal(category, "all"))
250 /* Print everything */
251 print_category(CURLHELP_ALL, cols);
252 /* Lets handle the string "category" differently to not print an errormsg */
253 else if(curl_strequal(category, "category"))
254 get_categories();
255 else if(category[0] == '-') {
256#ifdef USE_MANUAL
257 /* command line option help */
258 const struct LongShort *a = NULL;
259 if(category[1] == '-') {
260 const char *lookup = &category[2];
261 bool noflagged = FALSE;
262 if(!strncmp(lookup, "no-", 3)) {
263 lookup += 3;
264 noflagged = TRUE;
265 }
266 a = findlongopt(lookup);
267 if(a && noflagged && (ARGTYPE(a->desc) != ARG_BOOL))
268 /* a --no- prefix for a non-boolean is not specifying a proper
269 option */
270 a = NULL;
271 }
272 else if(category[1] && !category[2])
273 a = findshortopt(category[1]);
274 if(!a) {
275 curl_mfprintf(tool_stderr, "Incorrect option name to show help for,"
276 " see curl -h\n");
277 }
278 else {
279 char cmdbuf[80];
280 if(a->letter != ' ')
281 curl_msnprintf(cmdbuf, sizeof(cmdbuf), "\n -%c, --", a->letter);
282 else if(a->desc & ARG_NO)
283 curl_msnprintf(cmdbuf, sizeof(cmdbuf), "\n --no-%s", a->lname);
284 else
285 curl_msnprintf(cmdbuf, sizeof(cmdbuf), "\n %s", category);
286 if(a->cmd == C_XATTR)
287 /* this is the last option, which then ends when FILES starts */
288 showhelp("\nALL OPTIONS\n", cmdbuf, "\nFILES");
289 else
290 showhelp("\nALL OPTIONS\n", cmdbuf, "\n -");
291 }
292#else
293 curl_mfprintf(tool_stderr, "Cannot comply. "
294 "This curl was built without built-in manual\n");
295#endif
296 }
297 /* Otherwise print category and handle the case if the cat was not found */
298 else if(get_category_content(category, cols)) {
299 puts("Unknown category provided, here is a list of all categories:\n");
300 get_categories();
301 }
302}
304static bool is_debug(void)
305{
306 const char * const *builtin;
307 for(builtin = feature_names; *builtin; ++builtin)
308 if(curl_strequal("debug", *builtin))
309 return TRUE;
310 return FALSE;
311}
313void tool_version_info(void)
314{
315 const char * const *builtin;
316 if(is_debug())
317 curl_mfprintf(tool_stderr, "WARNING: this libcurl is Debug-enabled, "
318 "do not use in production\n\n");
320 curl_mprintf(CURL_ID "%s\n", curl_version());
321#ifdef CURL_PATCHSTAMP
322 curl_mprintf("Release-Date: %s, security patched: %s\n",
323 LIBCURL_TIMESTAMP, CURL_PATCHSTAMP);
324#else
325 curl_mprintf("Release-Date: %s\n", LIBCURL_TIMESTAMP);
326#endif
327 if(built_in_protos[0]) {
328#ifndef CURL_DISABLE_IPFS
329 const char *insert = NULL;
330 /* we have ipfs and ipns support if libcurl has http support */
331 for(builtin = built_in_protos; *builtin; ++builtin) {
332 if(insert) {
333 /* update insertion so ipfs is printed in alphabetical order */
334 if(strcmp(*builtin, "ipfs") < 0)
335 insert = *builtin;
336 else
337 break;
338 }
339 else if(!strcmp(*builtin, "http")) {
340 insert = *builtin;
341 }
342 }
343#endif /* !CURL_DISABLE_IPFS */
344 curl_mprintf("Protocols:");
345 for(builtin = built_in_protos; *builtin; ++builtin) {
346 curl_mprintf(" %s", *builtin);
347#ifndef CURL_DISABLE_IPFS
348 if(insert && insert == *builtin) {
349 curl_mprintf(" ipfs ipns");
350 insert = NULL;
351 }
352#endif /* !CURL_DISABLE_IPFS */
353 }
354 puts(""); /* newline */
355 }
356 if(feature_names[0]) {
357 const char **feat_ext;
358 size_t feat_ext_count = feature_count;
359#ifdef CURL_CA_EMBED
360 ++feat_ext_count;
361#endif
362#ifdef CURL_DEBUG_GLOBAL_MEM
363 ++feat_ext_count;
364#endif
365 feat_ext = curlx_malloc(sizeof(*feature_names) * (feat_ext_count + 1));
366 if(feat_ext) {
367 memcpy((void *)feat_ext, feature_names,
368 sizeof(*feature_names) * feature_count);
369 feat_ext_count = feature_count;
370#ifdef CURL_CA_EMBED
371 feat_ext[feat_ext_count++] = "CAcert";
372#endif
373#ifdef CURL_DEBUG_GLOBAL_MEM
374 feat_ext[feat_ext_count++] = "global-mem-debug";
375#endif
376 feat_ext[feat_ext_count] = NULL;
377 qsort((void *)feat_ext, feat_ext_count, sizeof(*feat_ext),
378 struplocompare4sort);
379 curl_mprintf("Features:");
380 for(builtin = feat_ext; *builtin; ++builtin)
381 curl_mprintf(" %s", *builtin);
382 puts(""); /* newline */
383 curlx_free((void *)feat_ext);
384 }
385 }
386 if(strcmp(CURL_VERSION, curlinfo->version)) {
387 curl_mprintf("WARNING: curl and libcurl versions do not match. "
388 "Functionality may be affected.\n");
389 }
390}
392void tool_list_engines(void)
393{
394 CURL *curl = curl_easy_init();
395 struct curl_slist *engines = NULL;
397 /* Get the list of engines */
398 curl_easy_getinfo(curl, CURLINFO_SSL_ENGINES, &engines);
400 puts("Build-time engines:");
401 if(engines) {
402 for(; engines; engines = engines->next)
403 curl_mprintf(" %s\n", engines->data);
404 }
405 else {
406 puts(" <none>");
407 }
409 /* Cleanup the list of engines */
410 curl_slist_free_all(engines);
411 curl_easy_cleanup(curl);
412}
Diagnostics4 git calls · 27 ms
CallStatusSizeTime027 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=21 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2004.3 KiB · hit21 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=4450 git.response.cache=HIT git.response.duration_ms=21 git.fetch.wants=aaf69282c10fdc584ce3d8fee5922ba117a76cc0 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=4450 git.pkt.payload.max=4429 git.sideband.band1.bytes=4428 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e1e9150c98452a
- Request
- a4838820…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format