1 /***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 1998 - 2021, 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 ***************************************************************************/
22 #include "tool_setup.h"
23
24 #include "tool_cfgable.h"
25 #include "tool_main.h"
26
27 #include "memdebug.h" /* keep this as LAST include */
28
config_init(struct OperationConfig * config)29 void config_init(struct OperationConfig *config)
30 {
31 memset(config, 0, sizeof(struct OperationConfig));
32
33 config->postfieldsize = -1;
34 config->use_httpget = FALSE;
35 config->create_dirs = FALSE;
36 config->maxredirs = DEFAULT_MAXREDIRS;
37 config->proto = CURLPROTO_ALL;
38 config->proto_present = FALSE;
39 config->proto_redir = CURLPROTO_ALL & /* All except FILE, SCP and SMB */
40 ~(CURLPROTO_FILE | CURLPROTO_SCP | CURLPROTO_SMB |
41 CURLPROTO_SMBS);
42 config->proto_redir_present = FALSE;
43 config->proto_default = NULL;
44 config->tcp_nodelay = TRUE; /* enabled by default */
45 config->happy_eyeballs_timeout_ms = CURL_HET_DEFAULT;
46 config->http09_allowed = FALSE;
47 config->ftp_skip_ip = TRUE;
48 }
49
free_config_fields(struct OperationConfig * config)50 static void free_config_fields(struct OperationConfig *config)
51 {
52 struct getout *urlnode;
53
54 Curl_safefree(config->random_file);
55 Curl_safefree(config->egd_file);
56 Curl_safefree(config->useragent);
57 Curl_safefree(config->altsvc);
58 Curl_safefree(config->hsts);
59 curl_slist_free_all(config->cookies);
60 Curl_safefree(config->cookiejar);
61 curl_slist_free_all(config->cookiefiles);
62
63 Curl_safefree(config->postfields);
64 Curl_safefree(config->referer);
65
66 Curl_safefree(config->headerfile);
67 Curl_safefree(config->ftpport);
68 Curl_safefree(config->iface);
69
70 Curl_safefree(config->range);
71
72 Curl_safefree(config->userpwd);
73 Curl_safefree(config->tls_username);
74 Curl_safefree(config->tls_password);
75 Curl_safefree(config->tls_authtype);
76 Curl_safefree(config->proxy_tls_username);
77 Curl_safefree(config->proxy_tls_password);
78 Curl_safefree(config->proxy_tls_authtype);
79 Curl_safefree(config->proxyuserpwd);
80 Curl_safefree(config->proxy);
81
82 Curl_safefree(config->dns_ipv6_addr);
83 Curl_safefree(config->dns_ipv4_addr);
84 Curl_safefree(config->dns_interface);
85 Curl_safefree(config->dns_servers);
86
87 Curl_safefree(config->noproxy);
88
89 Curl_safefree(config->mail_from);
90 curl_slist_free_all(config->mail_rcpt);
91 Curl_safefree(config->mail_auth);
92
93 Curl_safefree(config->netrc_file);
94 Curl_safefree(config->output_dir);
95
96 urlnode = config->url_list;
97 while(urlnode) {
98 struct getout *next = urlnode->next;
99 Curl_safefree(urlnode->url);
100 Curl_safefree(urlnode->outfile);
101 Curl_safefree(urlnode->infile);
102 Curl_safefree(urlnode);
103 urlnode = next;
104 }
105 config->url_list = NULL;
106 config->url_last = NULL;
107 config->url_get = NULL;
108 config->url_out = NULL;
109
110 Curl_safefree(config->doh_url);
111 Curl_safefree(config->cipher_list);
112 Curl_safefree(config->proxy_cipher_list);
113 Curl_safefree(config->cert);
114 Curl_safefree(config->proxy_cert);
115 Curl_safefree(config->cert_type);
116 Curl_safefree(config->proxy_cert_type);
117 Curl_safefree(config->cacert);
118 Curl_safefree(config->login_options);
119 Curl_safefree(config->proxy_cacert);
120 Curl_safefree(config->capath);
121 Curl_safefree(config->proxy_capath);
122 Curl_safefree(config->crlfile);
123 Curl_safefree(config->pinnedpubkey);
124 Curl_safefree(config->proxy_pinnedpubkey);
125 Curl_safefree(config->proxy_crlfile);
126 Curl_safefree(config->key);
127 Curl_safefree(config->proxy_key);
128 Curl_safefree(config->key_type);
129 Curl_safefree(config->proxy_key_type);
130 Curl_safefree(config->key_passwd);
131 Curl_safefree(config->proxy_key_passwd);
132 Curl_safefree(config->pubkey);
133 Curl_safefree(config->hostpubmd5);
134 Curl_safefree(config->engine);
135 Curl_safefree(config->etag_save_file);
136 Curl_safefree(config->etag_compare_file);
137 Curl_safefree(config->request_target);
138 Curl_safefree(config->customrequest);
139 Curl_safefree(config->krblevel);
140
141 Curl_safefree(config->oauth_bearer);
142 Curl_safefree(config->sasl_authzid);
143
144 Curl_safefree(config->unix_socket_path);
145 Curl_safefree(config->writeout);
146 Curl_safefree(config->proto_default);
147
148 curl_slist_free_all(config->quote);
149 curl_slist_free_all(config->postquote);
150 curl_slist_free_all(config->prequote);
151
152 curl_slist_free_all(config->headers);
153 curl_slist_free_all(config->proxyheaders);
154
155 curl_mime_free(config->mimepost);
156 config->mimepost = NULL;
157 tool_mime_free(config->mimeroot);
158 config->mimeroot = NULL;
159 config->mimecurrent = NULL;
160
161 curl_slist_free_all(config->telnet_options);
162 curl_slist_free_all(config->resolve);
163 curl_slist_free_all(config->connect_to);
164
165 Curl_safefree(config->preproxy);
166 Curl_safefree(config->proxy_service_name);
167 Curl_safefree(config->service_name);
168
169 Curl_safefree(config->ftp_account);
170 Curl_safefree(config->ftp_alternative_to_user);
171
172 Curl_safefree(config->aws_sigv4);
173 }
174
config_free(struct OperationConfig * config)175 void config_free(struct OperationConfig *config)
176 {
177 struct OperationConfig *last = config;
178
179 /* Free each of the structures in reverse order */
180 while(last) {
181 struct OperationConfig *prev = last->prev;
182
183 free_config_fields(last);
184 free(last);
185
186 last = prev;
187 }
188 }
189