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 <stddef.h>
28#include "tool_cfgable.h"
29#include "tool_formparse.h"
30#include "tool_libinfo.h"
31#include "tool_paramhlp.h"
32#include "tool_main.h"
33#include "tool_msgs.h"
35static struct GlobalConfig globalconf;
36struct GlobalConfig *global;
38struct OperationConfig *config_alloc(void)
39{
40 struct OperationConfig *config =
41 curlx_calloc(1, sizeof(struct OperationConfig));
42 if(!config)
43 return NULL;
45 config->use_httpget = FALSE;
46 config->create_dirs = FALSE;
47 config->maxredirs = DEFAULT_MAXREDIRS;
48 config->proto_present = FALSE;
49 config->proto_redir_present = FALSE;
50 config->proto_default = NULL;
51 config->tcp_nodelay = TRUE; /* enabled by default */
52 config->happy_eyeballs_timeout_ms = CURL_HET_DEFAULT;
53 config->http09_allowed = FALSE;
54 config->ftp_skip_ip = TRUE;
55 config->file_clobber_mode = CLOBBER_DEFAULT;
56 config->upload_flags = CURLULFLAG_SEEN;
57 curlx_dyn_init(&config->postdata, MAX_FILE2MEMORY);
58 return config;
59}
61static void free_config_fields(struct OperationConfig *config)
62{
63 struct getout *urlnode;
65 curlx_safefree(config->useragent);
66 curlx_safefree(config->altsvc);
67 curlx_safefree(config->hsts);
68 curlx_safefree(config->haproxy_clientip);
69 curl_slist_free_all(config->cookies);
70 curlx_safefree(config->cookiejar);
71 curl_slist_free_all(config->cookiefiles);
73 curlx_dyn_free(&config->postdata);
74 curlx_safefree(config->query);
75 curlx_safefree(config->referer);
77 curlx_safefree(config->headerfile);
78 curlx_safefree(config->ftpport);
79 curlx_safefree(config->iface);
81 curlx_safefree(config->range);
83 curlx_safefree(config->userpwd);
84 curlx_safefree(config->proxyuserpwd);
85 curlx_safefree(config->proxy);
87 curlx_safefree(config->dns_ipv6_addr);
88 curlx_safefree(config->dns_ipv4_addr);
89 curlx_safefree(config->dns_interface);
90 curlx_safefree(config->dns_servers);
92 curlx_safefree(config->noproxy);
94 curlx_safefree(config->mail_from);
95 curl_slist_free_all(config->mail_rcpt);
96 curlx_safefree(config->mail_auth);
98 curlx_safefree(config->netrc_file);
99 curlx_safefree(config->output_dir);
100 curlx_safefree(config->proto_str);
101 curlx_safefree(config->proto_redir_str);
103 urlnode = config->url_list;
104 while(urlnode) {
105 struct getout *next = urlnode->next;
106 curlx_safefree(urlnode->url);
107 curlx_safefree(urlnode->outfile);
108 curlx_safefree(urlnode->infile);
109 curlx_safefree(urlnode);
110 urlnode = next;
111 }
112 config->url_list = NULL;
113 config->url_last = NULL;
114 config->url_get = NULL;
115 config->url_out = NULL;
117#ifndef CURL_DISABLE_IPFS
118 curlx_safefree(config->ipfs_gateway);
119#endif
120 curlx_safefree(config->doh_url);
121 curlx_safefree(config->cipher_list);
122 curlx_safefree(config->proxy_cipher_list);
123 curlx_safefree(config->cipher13_list);
124 curlx_safefree(config->proxy_cipher13_list);
125 curlx_safefree(config->cert);
126 curlx_safefree(config->proxy_cert);
127 curlx_safefree(config->cert_type);
128 curlx_safefree(config->proxy_cert_type);
129 curlx_safefree(config->cacert);
130 curlx_safefree(config->login_options);
131 curlx_safefree(config->proxy_cacert);
132 curlx_safefree(config->capath);
133 curlx_safefree(config->proxy_capath);
134 curlx_safefree(config->crlfile);
135 curlx_safefree(config->pinnedpubkey);
136 curlx_safefree(config->proxy_pinnedpubkey);
137 curlx_safefree(config->proxy_crlfile);
138 curlx_safefree(config->key);
139 curlx_safefree(config->proxy_key);
140 curlx_safefree(config->key_type);
141 curlx_safefree(config->proxy_key_type);
142 curlx_strzero(config->key_passwd);
143 curlx_safefree(config->key_passwd);
144 curlx_strzero(config->proxy_key_passwd);
145 curlx_safefree(config->proxy_key_passwd);
146 curlx_safefree(config->pubkey);
147 curlx_safefree(config->hostpubmd5);
148 curlx_safefree(config->hostpubsha256);
149 curlx_safefree(config->engine);
150 curlx_safefree(config->etag_save_file);
151 curlx_safefree(config->etag_compare_file);
152 curlx_safefree(config->ssl_ec_curves);
153 curlx_safefree(config->ssl_signature_algorithms);
154 curlx_safefree(config->request_target);
155 curlx_safefree(config->customrequest);
156 curlx_safefree(config->krblevel);
157 curlx_strzero(config->oauth_bearer);
158 curlx_safefree(config->oauth_bearer);
159 curlx_safefree(config->sasl_authzid);
160 curlx_safefree(config->unix_socket_path);
161 curlx_safefree(config->writeout);
162 curlx_safefree(config->proto_default);
164 curl_slist_free_all(config->quote);
165 curl_slist_free_all(config->postquote);
166 curl_slist_free_all(config->prequote);
168 curl_slist_free_all(config->headers);
169 curl_slist_free_all(config->proxyheaders);
171 curl_mime_free(config->mimepost);
172 config->mimepost = NULL;
173 tool_mime_free(config->mimeroot);
174 config->mimeroot = NULL;
175 config->mimecurrent = NULL;
177 curl_slist_free_all(config->telnet_options);
178 curl_slist_free_all(config->resolve);
179 curl_slist_free_all(config->connect_to);
181 curlx_safefree(config->preproxy);
182 curlx_safefree(config->proxy_service_name);
183 curlx_safefree(config->service_name);
184 curlx_safefree(config->ftp_account);
185 curlx_safefree(config->ftp_alternative_to_user);
186 curlx_safefree(config->aws_sigv4);
187 curlx_safefree(config->httpsig_algorithm);
188 curlx_safefree(config->httpsig_headers);
189 curlx_safefree(config->httpsig_key);
190 curlx_safefree(config->httpsig_keyid);
191 curlx_safefree(config->ech);
192 curlx_safefree(config->ech_config);
193 curlx_safefree(config->ech_public);
194 curlx_safefree(config->knownhosts);
195}
197void config_free(struct OperationConfig *config)
198{
199 struct OperationConfig *last = config;
201 /* Free each of the structures in reverse order */
202 while(last) {
203 struct OperationConfig *prev = last->prev;
205 free_config_fields(last);
206 curlx_free(last);
208 last = prev;
209 }
210}
212#ifdef CURL_DEBUG_GLOBAL_MEM
214#ifdef CURL_MEMDEBUG
215#error "curl_global_init_mem() testing does not work with memdebug debugging"
216#endif
218/*
219 * This is the custom memory functions handed to curl when we run special test
220 * round to verify them.
221 *
222 * The main point is to make sure that what is returned is different than what
223 * the regular memory functions return so that mixup does trigger problems.
224 *
225 * This test setup currently only works when building with a *shared* libcurl
226 * and not static, as in the latter case the tool and the library share some of
227 * the functions in incompatible ways.
228 */
230/*
231 * This code appends this extra chunk of memory in front of every allocation
232 * done by libcurl with the only purpose to cause trouble when using the wrong
233 * free function on memory.
234 */
235struct extramem {
236 size_t extra;
237 union {
238 curl_off_t o;
239 double d;
240 void *p;
241 } mem[1];
242};
244static void *custom_calloc(size_t wanted_nmemb, size_t wanted_size)
245{
246 struct extramem *m;
247 size_t sz = wanted_size * wanted_nmemb;
248 sz += sizeof(struct extramem);
249 m = curlx_calloc(1, sz);
250 if(m)
251 return m->mem;
252 return NULL;
253}
255static void *custom_malloc(size_t wanted_size)
256{
257 struct extramem *m;
258 size_t sz = wanted_size + sizeof(struct extramem);
259 m = curlx_malloc(sz);
260 if(m)
261 return m->mem;
262 return NULL;
263}
265static char *custom_strdup(const char *ptr)
266{
267 struct extramem *m;
268 size_t len = strlen(ptr);
269 size_t sz = len + sizeof(struct extramem);
270 m = curlx_malloc(sz);
271 if(m) {
272 char *p = (char *)m->mem;
273 /* since strcpy is banned, we do memcpy */
274 memcpy(p, ptr, len);
275 p[len] = 0;
276 return (char *)m->mem;
277 }
278 return NULL;
279}
281static void *custom_realloc(void *ptr, size_t size)
282{
283 struct extramem *m = NULL;
284 size_t sz = size + sizeof(struct extramem);
285 if(ptr)
286 /* if given a pointer, figure out the original */
287 ptr = (void *)((char *)ptr - offsetof(struct extramem, mem));
288 m = curlx_realloc(ptr, sz);
289 if(m)
290 return m->mem;
291 return NULL;
292}
294static void custom_free(void *ptr)
295{
296 struct extramem *m = NULL;
297 if(ptr) {
298 m = (void *)((char *)ptr - offsetof(struct extramem, mem));
299 curlx_free(m);
300 }
301}
303#endif
305/*
306 * This is the main global constructor for the app. Call this before
307 * _any_ libcurl usage. If this fails, *NO* libcurl functions may be
308 * used, or havoc may be the result.
309 */
310CURLcode globalconf_init(void)
311{
312 CURLcode result = CURLE_OK;
313 global = &globalconf;
315#ifdef __DJGPP__
316 /* stop stat() wasting time */
317 _djstat_flags |= _STAT_INODE | _STAT_EXEC_MAGIC | _STAT_DIRSIZE;
318#endif
320 /* Initialize the global config */
321 global->showerror = FALSE; /* show errors when silent */
322 global->styled_output = TRUE; /* enable detection */
323 global->parallel_max = PARALLEL_DEFAULT;
325 /* Allocate the initial operate config */
326 global->first = global->last = config_alloc();
327 if(global->first) {
328 /* Perform the libcurl initialization */
329#ifdef CURL_DEBUG_GLOBAL_MEM
330 result = curl_global_init_mem(CURL_GLOBAL_DEFAULT,
331 custom_malloc, custom_free,
332 custom_realloc, custom_strdup,
333 custom_calloc);
334#else
335 result = curl_global_init(CURL_GLOBAL_DEFAULT);
336#endif
337 if(!result) {
338 /* Get information about libcurl */
339 result = get_libcurl_info();
341 if(result) {
342 errorf("error retrieving curl library information");
343 curlx_free(global->first);
344 }
345 }
346 else {
347 errorf("error initializing curl library");
348 curlx_free(global->first);
349 }
350 }
351 else {
352 errorf("error initializing curl");
353 result = CURLE_FAILED_INIT;
354 }
356 return result;
357}
359static void free_globalconfig(void)
360{
361 curlx_safefree(global->trace_dump);
363 if(global->trace_fopened && global->trace_stream)
364 curlx_fclose(global->trace_stream);
365 global->trace_stream = NULL;
367 curlx_safefree(global->ssl_sessions);
368 curlx_safefree(global->libcurl);
369#ifdef _WIN32
370 curlx_free(global->term.buf);
371#endif
372}
374/*
375 * This is the main global destructor for the app. Call this after _all_
376 * libcurl usage is done.
377 */
378void globalconf_free(void)
379{
380 /* Cleanup the easy handle */
381 /* Main cleanup */
382 curl_global_cleanup();
383 free_globalconfig();
385 /* Free the OperationConfig structures */
386 config_free(global->last);
387 global->first = NULL;
388 global->last = NULL;
389}
Diagnostics4 git calls · 37 ms
CallStatusSizeTime037 ms
discover200152 B4 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 · hit4 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=4 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=4 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 · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=31 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=2 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
fetch2003.5 KiB · hit31 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=3537 git.response.cache=HIT git.response.duration_ms=31 git.fetch.wants=26b44f8438cd2f7cf99edd6836e1ac165e0df2c5 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=3537 git.pkt.payload.max=3516 git.sideband.band1.bytes=3515 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
- a5e9e3d30c2ef3c9
- Request
- 2f81ba52…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format