• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_main.h"
28 
29 #include "memdebug.h" /* keep this as LAST include */
30 
config_init(struct OperationConfig * config)31 void config_init(struct OperationConfig *config)
32 {
33   memset(config, 0, sizeof(struct OperationConfig));
34 
35   config->postfieldsize = -1;
36   config->use_httpget = FALSE;
37   config->create_dirs = FALSE;
38   config->maxredirs = DEFAULT_MAXREDIRS;
39   config->proto_present = FALSE;
40   config->proto_redir_present = FALSE;
41   config->proto_default = NULL;
42   config->tcp_nodelay = TRUE; /* enabled by default */
43   config->happy_eyeballs_timeout_ms = CURL_HET_DEFAULT;
44   config->http09_allowed = FALSE;
45   config->ftp_skip_ip = TRUE;
46   config->file_clobber_mode = CLOBBER_DEFAULT;
47 }
48 
free_config_fields(struct OperationConfig * config)49 static void free_config_fields(struct OperationConfig *config)
50 {
51   struct getout *urlnode;
52 
53   Curl_safefree(config->useragent);
54   Curl_safefree(config->altsvc);
55   Curl_safefree(config->hsts);
56   curl_slist_free_all(config->cookies);
57   Curl_safefree(config->cookiejar);
58   curl_slist_free_all(config->cookiefiles);
59 
60   Curl_safefree(config->postfields);
61   Curl_safefree(config->query);
62   Curl_safefree(config->referer);
63 
64   Curl_safefree(config->headerfile);
65   Curl_safefree(config->ftpport);
66   Curl_safefree(config->iface);
67 
68   Curl_safefree(config->range);
69 
70   Curl_safefree(config->userpwd);
71   Curl_safefree(config->tls_username);
72   Curl_safefree(config->tls_password);
73   Curl_safefree(config->tls_authtype);
74   Curl_safefree(config->proxy_tls_username);
75   Curl_safefree(config->proxy_tls_password);
76   Curl_safefree(config->proxy_tls_authtype);
77   Curl_safefree(config->proxyuserpwd);
78   Curl_safefree(config->proxy);
79 
80   Curl_safefree(config->dns_ipv6_addr);
81   Curl_safefree(config->dns_ipv4_addr);
82   Curl_safefree(config->dns_interface);
83   Curl_safefree(config->dns_servers);
84 
85   Curl_safefree(config->noproxy);
86 
87   Curl_safefree(config->mail_from);
88   curl_slist_free_all(config->mail_rcpt);
89   Curl_safefree(config->mail_auth);
90 
91   Curl_safefree(config->netrc_file);
92   Curl_safefree(config->output_dir);
93   Curl_safefree(config->proto_str);
94   Curl_safefree(config->proto_redir_str);
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->hostpubsha256);
135   Curl_safefree(config->engine);
136   Curl_safefree(config->etag_save_file);
137   Curl_safefree(config->etag_compare_file);
138   Curl_safefree(config->ssl_ec_curves);
139   Curl_safefree(config->request_target);
140   Curl_safefree(config->customrequest);
141   Curl_safefree(config->krblevel);
142   Curl_safefree(config->oauth_bearer);
143   Curl_safefree(config->sasl_authzid);
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   Curl_safefree(config->proto_str);
174   Curl_safefree(config->proto_redir_str);
175 }
176 
config_free(struct OperationConfig * config)177 void config_free(struct OperationConfig *config)
178 {
179   struct OperationConfig *last = config;
180 
181   /* Free each of the structures in reverse order */
182   while(last) {
183     struct OperationConfig *prev = last->prev;
184 
185     free_config_fields(last);
186     free(last);
187 
188     last = prev;
189   }
190 }
191