1*6236dae4SAndroid Build Coastguard Worker /***************************************************************************
2*6236dae4SAndroid Build Coastguard Worker * _ _ ____ _
3*6236dae4SAndroid Build Coastguard Worker * Project ___| | | | _ \| |
4*6236dae4SAndroid Build Coastguard Worker * / __| | | | |_) | |
5*6236dae4SAndroid Build Coastguard Worker * | (__| |_| | _ <| |___
6*6236dae4SAndroid Build Coastguard Worker * \___|\___/|_| \_\_____|
7*6236dae4SAndroid Build Coastguard Worker *
8*6236dae4SAndroid Build Coastguard Worker * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9*6236dae4SAndroid Build Coastguard Worker *
10*6236dae4SAndroid Build Coastguard Worker * This software is licensed as described in the file COPYING, which
11*6236dae4SAndroid Build Coastguard Worker * you should have received as part of this distribution. The terms
12*6236dae4SAndroid Build Coastguard Worker * are also available at https://curl.se/docs/copyright.html.
13*6236dae4SAndroid Build Coastguard Worker *
14*6236dae4SAndroid Build Coastguard Worker * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15*6236dae4SAndroid Build Coastguard Worker * copies of the Software, and permit persons to whom the Software is
16*6236dae4SAndroid Build Coastguard Worker * furnished to do so, under the terms of the COPYING file.
17*6236dae4SAndroid Build Coastguard Worker *
18*6236dae4SAndroid Build Coastguard Worker * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19*6236dae4SAndroid Build Coastguard Worker * KIND, either express or implied.
20*6236dae4SAndroid Build Coastguard Worker *
21*6236dae4SAndroid Build Coastguard Worker * SPDX-License-Identifier: curl
22*6236dae4SAndroid Build Coastguard Worker *
23*6236dae4SAndroid Build Coastguard Worker ***************************************************************************/
24*6236dae4SAndroid Build Coastguard Worker #include "tool_setup.h"
25*6236dae4SAndroid Build Coastguard Worker
26*6236dae4SAndroid Build Coastguard Worker #include "tool_cfgable.h"
27*6236dae4SAndroid Build Coastguard Worker #include "tool_formparse.h"
28*6236dae4SAndroid Build Coastguard Worker #include "tool_paramhlp.h"
29*6236dae4SAndroid Build Coastguard Worker #include "tool_main.h"
30*6236dae4SAndroid Build Coastguard Worker
31*6236dae4SAndroid Build Coastguard Worker #include "memdebug.h" /* keep this as LAST include */
32*6236dae4SAndroid Build Coastguard Worker
config_init(struct OperationConfig * config)33*6236dae4SAndroid Build Coastguard Worker void config_init(struct OperationConfig *config)
34*6236dae4SAndroid Build Coastguard Worker {
35*6236dae4SAndroid Build Coastguard Worker memset(config, 0, sizeof(struct OperationConfig));
36*6236dae4SAndroid Build Coastguard Worker
37*6236dae4SAndroid Build Coastguard Worker config->use_httpget = FALSE;
38*6236dae4SAndroid Build Coastguard Worker config->create_dirs = FALSE;
39*6236dae4SAndroid Build Coastguard Worker config->maxredirs = DEFAULT_MAXREDIRS;
40*6236dae4SAndroid Build Coastguard Worker config->proto_present = FALSE;
41*6236dae4SAndroid Build Coastguard Worker config->proto_redir_present = FALSE;
42*6236dae4SAndroid Build Coastguard Worker config->proto_default = NULL;
43*6236dae4SAndroid Build Coastguard Worker config->tcp_nodelay = TRUE; /* enabled by default */
44*6236dae4SAndroid Build Coastguard Worker config->happy_eyeballs_timeout_ms = CURL_HET_DEFAULT;
45*6236dae4SAndroid Build Coastguard Worker config->http09_allowed = FALSE;
46*6236dae4SAndroid Build Coastguard Worker config->ftp_skip_ip = TRUE;
47*6236dae4SAndroid Build Coastguard Worker config->file_clobber_mode = CLOBBER_DEFAULT;
48*6236dae4SAndroid Build Coastguard Worker curlx_dyn_init(&config->postdata, MAX_FILE2MEMORY);
49*6236dae4SAndroid Build Coastguard Worker }
50*6236dae4SAndroid Build Coastguard Worker
free_config_fields(struct OperationConfig * config)51*6236dae4SAndroid Build Coastguard Worker static void free_config_fields(struct OperationConfig *config)
52*6236dae4SAndroid Build Coastguard Worker {
53*6236dae4SAndroid Build Coastguard Worker struct getout *urlnode;
54*6236dae4SAndroid Build Coastguard Worker
55*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->useragent);
56*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->altsvc);
57*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->hsts);
58*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->haproxy_clientip);
59*6236dae4SAndroid Build Coastguard Worker curl_slist_free_all(config->cookies);
60*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->cookiejar);
61*6236dae4SAndroid Build Coastguard Worker curl_slist_free_all(config->cookiefiles);
62*6236dae4SAndroid Build Coastguard Worker
63*6236dae4SAndroid Build Coastguard Worker Curl_dyn_free(&config->postdata);
64*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->query);
65*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->referer);
66*6236dae4SAndroid Build Coastguard Worker
67*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->headerfile);
68*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->ftpport);
69*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->iface);
70*6236dae4SAndroid Build Coastguard Worker
71*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->range);
72*6236dae4SAndroid Build Coastguard Worker
73*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->userpwd);
74*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->tls_username);
75*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->tls_password);
76*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->tls_authtype);
77*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proxy_tls_username);
78*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proxy_tls_password);
79*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proxy_tls_authtype);
80*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proxyuserpwd);
81*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proxy);
82*6236dae4SAndroid Build Coastguard Worker
83*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->dns_ipv6_addr);
84*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->dns_ipv4_addr);
85*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->dns_interface);
86*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->dns_servers);
87*6236dae4SAndroid Build Coastguard Worker
88*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->noproxy);
89*6236dae4SAndroid Build Coastguard Worker
90*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->mail_from);
91*6236dae4SAndroid Build Coastguard Worker curl_slist_free_all(config->mail_rcpt);
92*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->mail_auth);
93*6236dae4SAndroid Build Coastguard Worker
94*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->netrc_file);
95*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->output_dir);
96*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proto_str);
97*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proto_redir_str);
98*6236dae4SAndroid Build Coastguard Worker
99*6236dae4SAndroid Build Coastguard Worker urlnode = config->url_list;
100*6236dae4SAndroid Build Coastguard Worker while(urlnode) {
101*6236dae4SAndroid Build Coastguard Worker struct getout *next = urlnode->next;
102*6236dae4SAndroid Build Coastguard Worker Curl_safefree(urlnode->url);
103*6236dae4SAndroid Build Coastguard Worker Curl_safefree(urlnode->outfile);
104*6236dae4SAndroid Build Coastguard Worker Curl_safefree(urlnode->infile);
105*6236dae4SAndroid Build Coastguard Worker Curl_safefree(urlnode);
106*6236dae4SAndroid Build Coastguard Worker urlnode = next;
107*6236dae4SAndroid Build Coastguard Worker }
108*6236dae4SAndroid Build Coastguard Worker config->url_list = NULL;
109*6236dae4SAndroid Build Coastguard Worker config->url_last = NULL;
110*6236dae4SAndroid Build Coastguard Worker config->url_get = NULL;
111*6236dae4SAndroid Build Coastguard Worker config->url_out = NULL;
112*6236dae4SAndroid Build Coastguard Worker
113*6236dae4SAndroid Build Coastguard Worker #ifndef CURL_DISABLE_IPFS
114*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->ipfs_gateway);
115*6236dae4SAndroid Build Coastguard Worker #endif /* !CURL_DISABLE_IPFS */
116*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->doh_url);
117*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->cipher_list);
118*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proxy_cipher_list);
119*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->cipher13_list);
120*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proxy_cipher13_list);
121*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->cert);
122*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proxy_cert);
123*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->cert_type);
124*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proxy_cert_type);
125*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->cacert);
126*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->login_options);
127*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proxy_cacert);
128*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->capath);
129*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proxy_capath);
130*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->crlfile);
131*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->pinnedpubkey);
132*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proxy_pinnedpubkey);
133*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proxy_crlfile);
134*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->key);
135*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proxy_key);
136*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->key_type);
137*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proxy_key_type);
138*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->key_passwd);
139*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proxy_key_passwd);
140*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->pubkey);
141*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->hostpubmd5);
142*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->hostpubsha256);
143*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->engine);
144*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->etag_save_file);
145*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->etag_compare_file);
146*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->ssl_ec_curves);
147*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->request_target);
148*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->customrequest);
149*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->krblevel);
150*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->oauth_bearer);
151*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->sasl_authzid);
152*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->unix_socket_path);
153*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->writeout);
154*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proto_default);
155*6236dae4SAndroid Build Coastguard Worker
156*6236dae4SAndroid Build Coastguard Worker curl_slist_free_all(config->quote);
157*6236dae4SAndroid Build Coastguard Worker curl_slist_free_all(config->postquote);
158*6236dae4SAndroid Build Coastguard Worker curl_slist_free_all(config->prequote);
159*6236dae4SAndroid Build Coastguard Worker
160*6236dae4SAndroid Build Coastguard Worker curl_slist_free_all(config->headers);
161*6236dae4SAndroid Build Coastguard Worker curl_slist_free_all(config->proxyheaders);
162*6236dae4SAndroid Build Coastguard Worker
163*6236dae4SAndroid Build Coastguard Worker curl_mime_free(config->mimepost);
164*6236dae4SAndroid Build Coastguard Worker config->mimepost = NULL;
165*6236dae4SAndroid Build Coastguard Worker tool_mime_free(config->mimeroot);
166*6236dae4SAndroid Build Coastguard Worker config->mimeroot = NULL;
167*6236dae4SAndroid Build Coastguard Worker config->mimecurrent = NULL;
168*6236dae4SAndroid Build Coastguard Worker
169*6236dae4SAndroid Build Coastguard Worker curl_slist_free_all(config->telnet_options);
170*6236dae4SAndroid Build Coastguard Worker curl_slist_free_all(config->resolve);
171*6236dae4SAndroid Build Coastguard Worker curl_slist_free_all(config->connect_to);
172*6236dae4SAndroid Build Coastguard Worker
173*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->preproxy);
174*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proxy_service_name);
175*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->service_name);
176*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->ftp_account);
177*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->ftp_alternative_to_user);
178*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->aws_sigv4);
179*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proto_str);
180*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->proto_redir_str);
181*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->ech);
182*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->ech_config);
183*6236dae4SAndroid Build Coastguard Worker Curl_safefree(config->ech_public);
184*6236dae4SAndroid Build Coastguard Worker }
185*6236dae4SAndroid Build Coastguard Worker
config_free(struct OperationConfig * config)186*6236dae4SAndroid Build Coastguard Worker void config_free(struct OperationConfig *config)
187*6236dae4SAndroid Build Coastguard Worker {
188*6236dae4SAndroid Build Coastguard Worker struct OperationConfig *last = config;
189*6236dae4SAndroid Build Coastguard Worker
190*6236dae4SAndroid Build Coastguard Worker /* Free each of the structures in reverse order */
191*6236dae4SAndroid Build Coastguard Worker while(last) {
192*6236dae4SAndroid Build Coastguard Worker struct OperationConfig *prev = last->prev;
193*6236dae4SAndroid Build Coastguard Worker
194*6236dae4SAndroid Build Coastguard Worker free_config_fields(last);
195*6236dae4SAndroid Build Coastguard Worker free(last);
196*6236dae4SAndroid Build Coastguard Worker
197*6236dae4SAndroid Build Coastguard Worker last = prev;
198*6236dae4SAndroid Build Coastguard Worker }
199*6236dae4SAndroid Build Coastguard Worker }
200