1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
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 http://curl.haxx.se/docs/copyright.html.
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
22 #include "tool_setup.h"
24 #include "tool_cfgable.h"
25 #include "tool_main.h"
27 #include "memdebug.h" /* keep this as LAST include */
29 void config_init(struct Configurable* config)
31 memset(config, 0, sizeof(struct Configurable));
33 config->errors = stderr; /* default errors to stderr */
34 config->postfieldsize = -1;
35 config->showerror = -1; /* will show errors */
36 config->use_httpget = FALSE;
37 config->create_dirs = FALSE;
38 config->maxredirs = DEFAULT_MAXREDIRS;
39 config->proto = CURLPROTO_ALL; /* FIXME: better to read from library */
40 config->proto_present = FALSE;
42 CURLPROTO_ALL & ~(CURLPROTO_FILE|CURLPROTO_SCP); /* not FILE or SCP */
43 config->proto_redir_present = FALSE;
46 static void free_config_fields(struct Configurable *config)
48 struct getout *urlnode;
50 Curl_safefree(config->random_file);
51 Curl_safefree(config->egd_file);
52 Curl_safefree(config->useragent);
53 Curl_safefree(config->cookie);
54 Curl_safefree(config->cookiejar);
55 Curl_safefree(config->cookiefile);
57 Curl_safefree(config->postfields);
58 Curl_safefree(config->referer);
60 Curl_safefree(config->headerfile);
61 Curl_safefree(config->ftpport);
62 Curl_safefree(config->iface);
64 Curl_safefree(config->range);
66 Curl_safefree(config->userpwd);
67 Curl_safefree(config->tls_username);
68 Curl_safefree(config->tls_password);
69 Curl_safefree(config->tls_authtype);
70 Curl_safefree(config->proxyuserpwd);
71 Curl_safefree(config->proxy);
73 Curl_safefree(config->dns_ipv6_addr);
74 Curl_safefree(config->dns_ipv4_addr);
75 Curl_safefree(config->dns_interface);
76 Curl_safefree(config->dns_servers);
78 Curl_safefree(config->noproxy);
80 Curl_safefree(config->mail_from);
81 curl_slist_free_all(config->mail_rcpt);
82 Curl_safefree(config->mail_auth);
84 Curl_safefree(config->netrc_file);
86 urlnode = config->url_list;
88 struct getout *next = urlnode->next;
89 Curl_safefree(urlnode->url);
90 Curl_safefree(urlnode->outfile);
91 Curl_safefree(urlnode->infile);
92 Curl_safefree(urlnode);
95 config->url_list = NULL;
96 config->url_last = NULL;
97 config->url_get = NULL;
98 config->url_out = NULL;
100 Curl_safefree(config->cipher_list);
101 Curl_safefree(config->cert);
102 Curl_safefree(config->cert_type);
103 Curl_safefree(config->cacert);
104 Curl_safefree(config->capath);
105 Curl_safefree(config->crlfile);
106 Curl_safefree(config->key);
107 Curl_safefree(config->key_type);
108 Curl_safefree(config->key_passwd);
109 Curl_safefree(config->pubkey);
110 Curl_safefree(config->hostpubmd5);
111 Curl_safefree(config->engine);
113 Curl_safefree(config->customrequest);
114 Curl_safefree(config->krblevel);
115 Curl_safefree(config->trace_dump);
117 Curl_safefree(config->xoauth2_bearer);
119 if(config->trace_fopened && config->trace_stream)
120 fclose(config->trace_stream);
121 config->trace_stream = NULL;
123 Curl_safefree(config->writeout);
125 if(config->errors_fopened && config->errors)
126 fclose(config->errors);
127 config->errors = NULL;
129 curl_slist_free_all(config->quote);
130 curl_slist_free_all(config->postquote);
131 curl_slist_free_all(config->prequote);
133 curl_slist_free_all(config->headers);
135 if(config->httppost) {
136 curl_formfree(config->httppost);
137 config->httppost = NULL;
139 config->last_post = NULL;
141 curl_slist_free_all(config->telnet_options);
142 curl_slist_free_all(config->resolve);
144 Curl_safefree(config->socksproxy);
145 Curl_safefree(config->socks5_gssapi_service);
147 Curl_safefree(config->ftp_account);
148 Curl_safefree(config->ftp_alternative_to_user);
150 Curl_safefree(config->libcurl);
153 void config_free(struct Configurable *config)
155 struct Configurable *last = config;
157 /* Find the last config structure */
161 /* Free each of the structures in reverse order */
163 struct Configurable *prev = last->prev;
167 free_config_fields(last);