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