1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2016, 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 https://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 OperationConfig* config)
31 memset(config, 0, sizeof(struct OperationConfig));
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 |
42 config->proto_redir_present = FALSE;
43 config->proto_default = NULL;
44 config->tcp_nodelay = TRUE; /* enabled by default */
47 static void free_config_fields(struct OperationConfig *config)
49 struct getout *urlnode;
51 Curl_safefree(config->random_file);
52 Curl_safefree(config->egd_file);
53 Curl_safefree(config->useragent);
54 Curl_safefree(config->cookie);
55 Curl_safefree(config->cookiejar);
56 Curl_safefree(config->cookiefile);
58 Curl_safefree(config->postfields);
59 Curl_safefree(config->referer);
61 Curl_safefree(config->headerfile);
62 Curl_safefree(config->ftpport);
63 Curl_safefree(config->iface);
65 Curl_safefree(config->range);
67 Curl_safefree(config->userpwd);
68 Curl_safefree(config->tls_username);
69 Curl_safefree(config->tls_password);
70 Curl_safefree(config->tls_authtype);
71 Curl_safefree(config->proxyuserpwd);
72 Curl_safefree(config->proxy);
74 Curl_safefree(config->dns_ipv6_addr);
75 Curl_safefree(config->dns_ipv4_addr);
76 Curl_safefree(config->dns_interface);
77 Curl_safefree(config->dns_servers);
79 Curl_safefree(config->noproxy);
81 Curl_safefree(config->mail_from);
82 curl_slist_free_all(config->mail_rcpt);
83 Curl_safefree(config->mail_auth);
85 Curl_safefree(config->netrc_file);
87 urlnode = config->url_list;
89 struct getout *next = urlnode->next;
90 Curl_safefree(urlnode->url);
91 Curl_safefree(urlnode->outfile);
92 Curl_safefree(urlnode->infile);
93 Curl_safefree(urlnode);
96 config->url_list = NULL;
97 config->url_last = NULL;
98 config->url_get = NULL;
99 config->url_out = NULL;
101 Curl_safefree(config->cipher_list);
102 Curl_safefree(config->cert);
103 Curl_safefree(config->cert_type);
104 Curl_safefree(config->cacert);
105 Curl_safefree(config->capath);
106 Curl_safefree(config->crlfile);
107 Curl_safefree(config->pinnedpubkey);
108 Curl_safefree(config->key);
109 Curl_safefree(config->key_type);
110 Curl_safefree(config->key_passwd);
111 Curl_safefree(config->pubkey);
112 Curl_safefree(config->hostpubmd5);
113 Curl_safefree(config->engine);
115 Curl_safefree(config->customrequest);
116 Curl_safefree(config->krblevel);
118 Curl_safefree(config->oauth_bearer);
120 Curl_safefree(config->unix_socket_path);
121 Curl_safefree(config->writeout);
122 Curl_safefree(config->proto_default);
124 curl_slist_free_all(config->quote);
125 curl_slist_free_all(config->postquote);
126 curl_slist_free_all(config->prequote);
128 curl_slist_free_all(config->headers);
129 curl_slist_free_all(config->proxyheaders);
131 if(config->httppost) {
132 curl_formfree(config->httppost);
133 config->httppost = NULL;
135 config->last_post = NULL;
137 curl_slist_free_all(config->telnet_options);
138 curl_slist_free_all(config->resolve);
139 curl_slist_free_all(config->connect_to);
141 Curl_safefree(config->socksproxy);
142 Curl_safefree(config->proxy_service_name);
143 Curl_safefree(config->service_name);
145 Curl_safefree(config->ftp_account);
146 Curl_safefree(config->ftp_alternative_to_user);
149 void config_free(struct OperationConfig *config)
151 struct OperationConfig *last = config;
153 /* Free each of the structures in reverse order */
155 struct OperationConfig *prev = last->prev;
157 free_config_fields(last);