xref: /curl/src/tool_cfgable.c (revision 469f5368)
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"
25 
26 #include "tool_cfgable.h"
27 #include "tool_formparse.h"
28 #include "tool_paramhlp.h"
29 #include "tool_main.h"
30 
31 #include "memdebug.h" /* keep this as LAST include */
32 
config_init(struct OperationConfig * config)33 void config_init(struct OperationConfig *config)
34 {
35   memset(config, 0, sizeof(struct OperationConfig));
36 
37   config->use_httpget = FALSE;
38   config->create_dirs = FALSE;
39   config->maxredirs = DEFAULT_MAXREDIRS;
40   config->proto_present = FALSE;
41   config->proto_redir_present = FALSE;
42   config->proto_default = NULL;
43   config->tcp_nodelay = TRUE; /* enabled by default */
44   config->happy_eyeballs_timeout_ms = CURL_HET_DEFAULT;
45   config->http09_allowed = FALSE;
46   config->ftp_skip_ip = TRUE;
47   config->file_clobber_mode = CLOBBER_DEFAULT;
48   curlx_dyn_init(&config->postdata, MAX_FILE2MEMORY);
49 }
50 
free_config_fields(struct OperationConfig * config)51 static void free_config_fields(struct OperationConfig *config)
52 {
53   struct getout *urlnode;
54 
55   Curl_safefree(config->useragent);
56   Curl_safefree(config->altsvc);
57   Curl_safefree(config->hsts);
58   Curl_safefree(config->haproxy_clientip);
59   curl_slist_free_all(config->cookies);
60   Curl_safefree(config->cookiejar);
61   curl_slist_free_all(config->cookiefiles);
62 
63   Curl_dyn_free(&config->postdata);
64   Curl_safefree(config->query);
65   Curl_safefree(config->referer);
66 
67   Curl_safefree(config->headerfile);
68   Curl_safefree(config->ftpport);
69   Curl_safefree(config->iface);
70 
71   Curl_safefree(config->range);
72 
73   Curl_safefree(config->userpwd);
74   Curl_safefree(config->tls_username);
75   Curl_safefree(config->tls_password);
76   Curl_safefree(config->tls_authtype);
77   Curl_safefree(config->proxy_tls_username);
78   Curl_safefree(config->proxy_tls_password);
79   Curl_safefree(config->proxy_tls_authtype);
80   Curl_safefree(config->proxyuserpwd);
81   Curl_safefree(config->proxy);
82 
83   Curl_safefree(config->dns_ipv6_addr);
84   Curl_safefree(config->dns_ipv4_addr);
85   Curl_safefree(config->dns_interface);
86   Curl_safefree(config->dns_servers);
87 
88   Curl_safefree(config->noproxy);
89 
90   Curl_safefree(config->mail_from);
91   curl_slist_free_all(config->mail_rcpt);
92   Curl_safefree(config->mail_auth);
93 
94   Curl_safefree(config->netrc_file);
95   Curl_safefree(config->output_dir);
96   Curl_safefree(config->proto_str);
97   Curl_safefree(config->proto_redir_str);
98 
99   urlnode = config->url_list;
100   while(urlnode) {
101     struct getout *next = urlnode->next;
102     Curl_safefree(urlnode->url);
103     Curl_safefree(urlnode->outfile);
104     Curl_safefree(urlnode->infile);
105     Curl_safefree(urlnode);
106     urlnode = next;
107   }
108   config->url_list = NULL;
109   config->url_last = NULL;
110   config->url_get = NULL;
111   config->url_out = NULL;
112 
113 #ifndef CURL_DISABLE_IPFS
114   Curl_safefree(config->ipfs_gateway);
115 #endif /* !CURL_DISABLE_IPFS */
116   Curl_safefree(config->doh_url);
117   Curl_safefree(config->cipher_list);
118   Curl_safefree(config->proxy_cipher_list);
119   Curl_safefree(config->cipher13_list);
120   Curl_safefree(config->proxy_cipher13_list);
121   Curl_safefree(config->cert);
122   Curl_safefree(config->proxy_cert);
123   Curl_safefree(config->cert_type);
124   Curl_safefree(config->proxy_cert_type);
125   Curl_safefree(config->cacert);
126   Curl_safefree(config->login_options);
127   Curl_safefree(config->proxy_cacert);
128   Curl_safefree(config->capath);
129   Curl_safefree(config->proxy_capath);
130   Curl_safefree(config->crlfile);
131   Curl_safefree(config->pinnedpubkey);
132   Curl_safefree(config->proxy_pinnedpubkey);
133   Curl_safefree(config->proxy_crlfile);
134   Curl_safefree(config->key);
135   Curl_safefree(config->proxy_key);
136   Curl_safefree(config->key_type);
137   Curl_safefree(config->proxy_key_type);
138   Curl_safefree(config->key_passwd);
139   Curl_safefree(config->proxy_key_passwd);
140   Curl_safefree(config->pubkey);
141   Curl_safefree(config->hostpubmd5);
142   Curl_safefree(config->hostpubsha256);
143   Curl_safefree(config->engine);
144   Curl_safefree(config->etag_save_file);
145   Curl_safefree(config->etag_compare_file);
146   Curl_safefree(config->ssl_ec_curves);
147   Curl_safefree(config->request_target);
148   Curl_safefree(config->customrequest);
149   Curl_safefree(config->krblevel);
150   Curl_safefree(config->oauth_bearer);
151   Curl_safefree(config->sasl_authzid);
152   Curl_safefree(config->unix_socket_path);
153   Curl_safefree(config->writeout);
154   Curl_safefree(config->proto_default);
155 
156   curl_slist_free_all(config->quote);
157   curl_slist_free_all(config->postquote);
158   curl_slist_free_all(config->prequote);
159 
160   curl_slist_free_all(config->headers);
161   curl_slist_free_all(config->proxyheaders);
162 
163   curl_mime_free(config->mimepost);
164   config->mimepost = NULL;
165   tool_mime_free(config->mimeroot);
166   config->mimeroot = NULL;
167   config->mimecurrent = NULL;
168 
169   curl_slist_free_all(config->telnet_options);
170   curl_slist_free_all(config->resolve);
171   curl_slist_free_all(config->connect_to);
172 
173   Curl_safefree(config->preproxy);
174   Curl_safefree(config->proxy_service_name);
175   Curl_safefree(config->service_name);
176   Curl_safefree(config->ftp_account);
177   Curl_safefree(config->ftp_alternative_to_user);
178   Curl_safefree(config->aws_sigv4);
179   Curl_safefree(config->proto_str);
180   Curl_safefree(config->proto_redir_str);
181   Curl_safefree(config->ech);
182   Curl_safefree(config->ech_config);
183   Curl_safefree(config->ech_public);
184 }
185 
config_free(struct OperationConfig * config)186 void config_free(struct OperationConfig *config)
187 {
188   struct OperationConfig *last = config;
189 
190   /* Free each of the structures in reverse order */
191   while(last) {
192     struct OperationConfig *prev = last->prev;
193 
194     free_config_fields(last);
195     free(last);
196 
197     last = prev;
198   }
199 }
200