Imported Upstream version 7.59.0
[platform/upstream/curl.git] / src / tool_cfgable.c
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2018, 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.haxx.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
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; /* FIXME: better to read from library */
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 }
47
48 static void free_config_fields(struct OperationConfig *config)
49 {
50   struct getout *urlnode;
51
52   Curl_safefree(config->random_file);
53   Curl_safefree(config->egd_file);
54   Curl_safefree(config->useragent);
55   Curl_safefree(config->cookie);
56   Curl_safefree(config->cookiejar);
57   Curl_safefree(config->cookiefile);
58
59   Curl_safefree(config->postfields);
60   Curl_safefree(config->referer);
61
62   Curl_safefree(config->headerfile);
63   Curl_safefree(config->ftpport);
64   Curl_safefree(config->iface);
65
66   Curl_safefree(config->range);
67
68   Curl_safefree(config->userpwd);
69   Curl_safefree(config->tls_username);
70   Curl_safefree(config->tls_password);
71   Curl_safefree(config->tls_authtype);
72   Curl_safefree(config->proxy_tls_username);
73   Curl_safefree(config->proxy_tls_password);
74   Curl_safefree(config->proxy_tls_authtype);
75   Curl_safefree(config->proxyuserpwd);
76   Curl_safefree(config->proxy);
77
78   Curl_safefree(config->dns_ipv6_addr);
79   Curl_safefree(config->dns_ipv4_addr);
80   Curl_safefree(config->dns_interface);
81   Curl_safefree(config->dns_servers);
82
83   Curl_safefree(config->noproxy);
84
85   Curl_safefree(config->mail_from);
86   curl_slist_free_all(config->mail_rcpt);
87   Curl_safefree(config->mail_auth);
88
89   Curl_safefree(config->netrc_file);
90
91   urlnode = config->url_list;
92   while(urlnode) {
93     struct getout *next = urlnode->next;
94     Curl_safefree(urlnode->url);
95     Curl_safefree(urlnode->outfile);
96     Curl_safefree(urlnode->infile);
97     Curl_safefree(urlnode);
98     urlnode = next;
99   }
100   config->url_list = NULL;
101   config->url_last = NULL;
102   config->url_get = NULL;
103   config->url_out = NULL;
104
105   Curl_safefree(config->cipher_list);
106   Curl_safefree(config->proxy_cipher_list);
107   Curl_safefree(config->cert);
108   Curl_safefree(config->proxy_cert);
109   Curl_safefree(config->cert_type);
110   Curl_safefree(config->proxy_cert_type);
111   Curl_safefree(config->cacert);
112   Curl_safefree(config->proxy_cacert);
113   Curl_safefree(config->capath);
114   Curl_safefree(config->proxy_capath);
115   Curl_safefree(config->crlfile);
116   Curl_safefree(config->pinnedpubkey);
117   Curl_safefree(config->proxy_pinnedpubkey);
118   Curl_safefree(config->proxy_crlfile);
119   Curl_safefree(config->key);
120   Curl_safefree(config->proxy_key);
121   Curl_safefree(config->key_type);
122   Curl_safefree(config->proxy_key_type);
123   Curl_safefree(config->key_passwd);
124   Curl_safefree(config->proxy_key_passwd);
125   Curl_safefree(config->pubkey);
126   Curl_safefree(config->hostpubmd5);
127   Curl_safefree(config->engine);
128   Curl_safefree(config->request_target);
129   Curl_safefree(config->customrequest);
130   Curl_safefree(config->krblevel);
131
132   Curl_safefree(config->oauth_bearer);
133
134   Curl_safefree(config->unix_socket_path);
135   Curl_safefree(config->writeout);
136   Curl_safefree(config->proto_default);
137
138   curl_slist_free_all(config->quote);
139   curl_slist_free_all(config->postquote);
140   curl_slist_free_all(config->prequote);
141
142   curl_slist_free_all(config->headers);
143   curl_slist_free_all(config->proxyheaders);
144
145   if(config->mimepost) {
146     curl_mime_free(config->mimepost);
147     config->mimepost = NULL;
148   }
149   config->mimecurrent = NULL;
150
151   curl_slist_free_all(config->telnet_options);
152   curl_slist_free_all(config->resolve);
153   curl_slist_free_all(config->connect_to);
154
155   Curl_safefree(config->preproxy);
156   Curl_safefree(config->proxy_service_name);
157   Curl_safefree(config->service_name);
158
159   Curl_safefree(config->ftp_account);
160   Curl_safefree(config->ftp_alternative_to_user);
161 }
162
163 void config_free(struct OperationConfig *config)
164 {
165   struct OperationConfig *last = config;
166
167   /* Free each of the structures in reverse order */
168   while(last) {
169     struct OperationConfig *prev = last->prev;
170
171     free_config_fields(last);
172     free(last);
173
174     last = prev;
175   }
176 }