xref: /curl/src/tool_cfgable.c (revision 87d14e77)
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   Curl_safefree(config->ipfs_gateway);
114   Curl_safefree(config->doh_url);
115   Curl_safefree(config->cipher_list);
116   Curl_safefree(config->proxy_cipher_list);
117   Curl_safefree(config->cipher13_list);
118   Curl_safefree(config->proxy_cipher13_list);
119   Curl_safefree(config->cert);
120   Curl_safefree(config->proxy_cert);
121   Curl_safefree(config->cert_type);
122   Curl_safefree(config->proxy_cert_type);
123   Curl_safefree(config->cacert);
124   Curl_safefree(config->login_options);
125   Curl_safefree(config->proxy_cacert);
126   Curl_safefree(config->capath);
127   Curl_safefree(config->proxy_capath);
128   Curl_safefree(config->crlfile);
129   Curl_safefree(config->pinnedpubkey);
130   Curl_safefree(config->proxy_pinnedpubkey);
131   Curl_safefree(config->proxy_crlfile);
132   Curl_safefree(config->key);
133   Curl_safefree(config->proxy_key);
134   Curl_safefree(config->key_type);
135   Curl_safefree(config->proxy_key_type);
136   Curl_safefree(config->key_passwd);
137   Curl_safefree(config->proxy_key_passwd);
138   Curl_safefree(config->pubkey);
139   Curl_safefree(config->hostpubmd5);
140   Curl_safefree(config->hostpubsha256);
141   Curl_safefree(config->engine);
142   Curl_safefree(config->etag_save_file);
143   Curl_safefree(config->etag_compare_file);
144   Curl_safefree(config->ssl_ec_curves);
145   Curl_safefree(config->request_target);
146   Curl_safefree(config->customrequest);
147   Curl_safefree(config->krblevel);
148   Curl_safefree(config->oauth_bearer);
149   Curl_safefree(config->sasl_authzid);
150   Curl_safefree(config->unix_socket_path);
151   Curl_safefree(config->writeout);
152   Curl_safefree(config->proto_default);
153 
154   curl_slist_free_all(config->quote);
155   curl_slist_free_all(config->postquote);
156   curl_slist_free_all(config->prequote);
157 
158   curl_slist_free_all(config->headers);
159   curl_slist_free_all(config->proxyheaders);
160 
161   curl_mime_free(config->mimepost);
162   config->mimepost = NULL;
163   tool_mime_free(config->mimeroot);
164   config->mimeroot = NULL;
165   config->mimecurrent = NULL;
166 
167   curl_slist_free_all(config->telnet_options);
168   curl_slist_free_all(config->resolve);
169   curl_slist_free_all(config->connect_to);
170 
171   Curl_safefree(config->preproxy);
172   Curl_safefree(config->proxy_service_name);
173   Curl_safefree(config->service_name);
174 
175   Curl_safefree(config->ftp_account);
176   Curl_safefree(config->ftp_alternative_to_user);
177 
178   Curl_safefree(config->aws_sigv4);
179   Curl_safefree(config->proto_str);
180   Curl_safefree(config->proto_redir_str);
181 #ifdef USE_ECH
182   Curl_safefree(config->ech);
183   config->ech = NULL;
184   Curl_safefree(config->ech_config);
185   config->ech_config = NULL;
186   Curl_safefree(config->ech_public);
187   config->ech_public = NULL;
188 #endif
189 }
190 
config_free(struct OperationConfig * config)191 void config_free(struct OperationConfig *config)
192 {
193   struct OperationConfig *last = config;
194 
195   /* Free each of the structures in reverse order */
196   while(last) {
197     struct OperationConfig *prev = last->prev;
198 
199     free_config_fields(last);
200     free(last);
201 
202     last = prev;
203   }
204 }
205