Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/src/tool_cfgable.c
2649 views
1
/***************************************************************************
2
* _ _ ____ _
3
* Project ___| | | | _ \| |
4
* / __| | | | |_) | |
5
* | (__| |_| | _ <| |___
6
* \___|\___/|_| \_\_____|
7
*
8
* Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
*
10
* This software is licensed as described in the file COPYING, which
11
* you should have received as part of this distribution. The terms
12
* are also available at https://curl.se/docs/copyright.html.
13
*
14
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
* copies of the Software, and permit persons to whom the Software is
16
* furnished to do so, under the terms of the COPYING file.
17
*
18
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
* KIND, either express or implied.
20
*
21
* SPDX-License-Identifier: curl
22
*
23
***************************************************************************/
24
#include "tool_setup.h"
25
26
#include "tool_cfgable.h"
27
#include "tool_formparse.h"
28
#include "tool_paramhlp.h"
29
#include "tool_main.h"
30
#include "tool_msgs.h"
31
#include "memdebug.h" /* keep this as LAST include */
32
33
static struct GlobalConfig globalconf;
34
struct GlobalConfig *global;
35
36
struct OperationConfig *config_alloc(void)
37
{
38
struct OperationConfig *config =
39
calloc(1, sizeof(struct OperationConfig));
40
if(!config)
41
return NULL;
42
43
config->use_httpget = FALSE;
44
config->create_dirs = FALSE;
45
config->maxredirs = DEFAULT_MAXREDIRS;
46
config->proto_present = FALSE;
47
config->proto_redir_present = FALSE;
48
config->proto_default = NULL;
49
config->tcp_nodelay = TRUE; /* enabled by default */
50
config->happy_eyeballs_timeout_ms = CURL_HET_DEFAULT;
51
config->http09_allowed = FALSE;
52
config->ftp_skip_ip = TRUE;
53
config->file_clobber_mode = CLOBBER_DEFAULT;
54
config->upload_flags = CURLULFLAG_SEEN;
55
curlx_dyn_init(&config->postdata, MAX_FILE2MEMORY);
56
return config;
57
}
58
59
static void free_config_fields(struct OperationConfig *config)
60
{
61
struct getout *urlnode;
62
63
tool_safefree(config->useragent);
64
tool_safefree(config->altsvc);
65
tool_safefree(config->hsts);
66
tool_safefree(config->haproxy_clientip);
67
curl_slist_free_all(config->cookies);
68
tool_safefree(config->cookiejar);
69
curl_slist_free_all(config->cookiefiles);
70
71
curlx_dyn_free(&config->postdata);
72
tool_safefree(config->query);
73
tool_safefree(config->referer);
74
75
tool_safefree(config->headerfile);
76
tool_safefree(config->ftpport);
77
tool_safefree(config->iface);
78
79
tool_safefree(config->range);
80
81
tool_safefree(config->userpwd);
82
tool_safefree(config->tls_username);
83
tool_safefree(config->tls_password);
84
tool_safefree(config->tls_authtype);
85
tool_safefree(config->proxy_tls_username);
86
tool_safefree(config->proxy_tls_password);
87
tool_safefree(config->proxy_tls_authtype);
88
tool_safefree(config->proxyuserpwd);
89
tool_safefree(config->proxy);
90
91
tool_safefree(config->dns_ipv6_addr);
92
tool_safefree(config->dns_ipv4_addr);
93
tool_safefree(config->dns_interface);
94
tool_safefree(config->dns_servers);
95
96
tool_safefree(config->noproxy);
97
98
tool_safefree(config->mail_from);
99
curl_slist_free_all(config->mail_rcpt);
100
tool_safefree(config->mail_auth);
101
102
tool_safefree(config->netrc_file);
103
tool_safefree(config->output_dir);
104
tool_safefree(config->proto_str);
105
tool_safefree(config->proto_redir_str);
106
107
urlnode = config->url_list;
108
while(urlnode) {
109
struct getout *next = urlnode->next;
110
tool_safefree(urlnode->url);
111
tool_safefree(urlnode->outfile);
112
tool_safefree(urlnode->infile);
113
tool_safefree(urlnode);
114
urlnode = next;
115
}
116
config->url_list = NULL;
117
config->url_last = NULL;
118
config->url_get = NULL;
119
config->url_out = NULL;
120
121
#ifndef CURL_DISABLE_IPFS
122
tool_safefree(config->ipfs_gateway);
123
#endif /* !CURL_DISABLE_IPFS */
124
tool_safefree(config->doh_url);
125
tool_safefree(config->cipher_list);
126
tool_safefree(config->proxy_cipher_list);
127
tool_safefree(config->cipher13_list);
128
tool_safefree(config->proxy_cipher13_list);
129
tool_safefree(config->cert);
130
tool_safefree(config->proxy_cert);
131
tool_safefree(config->cert_type);
132
tool_safefree(config->proxy_cert_type);
133
tool_safefree(config->cacert);
134
tool_safefree(config->login_options);
135
tool_safefree(config->proxy_cacert);
136
tool_safefree(config->capath);
137
tool_safefree(config->proxy_capath);
138
tool_safefree(config->crlfile);
139
tool_safefree(config->pinnedpubkey);
140
tool_safefree(config->proxy_pinnedpubkey);
141
tool_safefree(config->proxy_crlfile);
142
tool_safefree(config->key);
143
tool_safefree(config->proxy_key);
144
tool_safefree(config->key_type);
145
tool_safefree(config->proxy_key_type);
146
tool_safefree(config->key_passwd);
147
tool_safefree(config->proxy_key_passwd);
148
tool_safefree(config->pubkey);
149
tool_safefree(config->hostpubmd5);
150
tool_safefree(config->hostpubsha256);
151
tool_safefree(config->engine);
152
tool_safefree(config->etag_save_file);
153
tool_safefree(config->etag_compare_file);
154
tool_safefree(config->ssl_ec_curves);
155
tool_safefree(config->request_target);
156
tool_safefree(config->customrequest);
157
tool_safefree(config->krblevel);
158
tool_safefree(config->oauth_bearer);
159
tool_safefree(config->sasl_authzid);
160
tool_safefree(config->unix_socket_path);
161
tool_safefree(config->writeout);
162
tool_safefree(config->proto_default);
163
164
curl_slist_free_all(config->quote);
165
curl_slist_free_all(config->postquote);
166
curl_slist_free_all(config->prequote);
167
168
curl_slist_free_all(config->headers);
169
curl_slist_free_all(config->proxyheaders);
170
171
curl_mime_free(config->mimepost);
172
config->mimepost = NULL;
173
tool_mime_free(config->mimeroot);
174
config->mimeroot = NULL;
175
config->mimecurrent = NULL;
176
177
curl_slist_free_all(config->telnet_options);
178
curl_slist_free_all(config->resolve);
179
curl_slist_free_all(config->connect_to);
180
181
tool_safefree(config->preproxy);
182
tool_safefree(config->proxy_service_name);
183
tool_safefree(config->service_name);
184
tool_safefree(config->ftp_account);
185
tool_safefree(config->ftp_alternative_to_user);
186
tool_safefree(config->aws_sigv4);
187
tool_safefree(config->ech);
188
tool_safefree(config->ech_config);
189
tool_safefree(config->ech_public);
190
tool_safefree(config->knownhosts);
191
}
192
193
void config_free(struct OperationConfig *config)
194
{
195
struct OperationConfig *last = config;
196
197
/* Free each of the structures in reverse order */
198
while(last) {
199
struct OperationConfig *prev = last->prev;
200
201
free_config_fields(last);
202
free(last);
203
204
last = prev;
205
}
206
}
207
208
/*
209
* This is the main global constructor for the app. Call this before
210
* _any_ libcurl usage. If this fails, *NO* libcurl functions may be
211
* used, or havoc may be the result.
212
*/
213
CURLcode globalconf_init(void)
214
{
215
CURLcode result = CURLE_OK;
216
global = &globalconf;
217
218
#ifdef __DJGPP__
219
/* stop stat() wasting time */
220
_djstat_flags |= _STAT_INODE | _STAT_EXEC_MAGIC | _STAT_DIRSIZE;
221
#endif
222
223
/* Initialise the global config */
224
global->showerror = FALSE; /* show errors when silent */
225
global->styled_output = TRUE; /* enable detection */
226
global->parallel_max = PARALLEL_DEFAULT;
227
228
/* Allocate the initial operate config */
229
global->first = global->last = config_alloc();
230
if(global->first) {
231
/* Perform the libcurl initialization */
232
result = curl_global_init(CURL_GLOBAL_DEFAULT);
233
if(!result) {
234
/* Get information about libcurl */
235
result = get_libcurl_info();
236
237
if(result) {
238
errorf("error retrieving curl library information");
239
free(global->first);
240
}
241
}
242
else {
243
errorf("error initializing curl library");
244
free(global->first);
245
}
246
}
247
else {
248
errorf("error initializing curl");
249
result = CURLE_FAILED_INIT;
250
}
251
252
return result;
253
}
254
255
static void free_globalconfig(void)
256
{
257
tool_safefree(global->trace_dump);
258
259
if(global->trace_fopened && global->trace_stream)
260
curlx_fclose(global->trace_stream);
261
global->trace_stream = NULL;
262
263
tool_safefree(global->libcurl);
264
#if defined(_WIN32) && !defined(UNDER_CE)
265
free(global->term.buf);
266
#endif
267
}
268
269
/*
270
* This is the main global destructor for the app. Call this after _all_
271
* libcurl usage is done.
272
*/
273
void globalconf_free(void)
274
{
275
/* Cleanup the easy handle */
276
/* Main cleanup */
277
curl_global_cleanup();
278
free_globalconfig();
279
280
/* Free the OperationConfig structures */
281
config_free(global->last);
282
global->first = NULL;
283
global->last = NULL;
284
}
285
286