| xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 1 | /*************************************************************************** | 
 | 2 |  *                                  _   _ ____  _ | 
 | 3 |  *  Project                     ___| | | |  _ \| | | 
 | 4 |  *                             / __| | | | |_) | | | 
 | 5 |  *                            | (__| |_| |  _ <| |___ | 
 | 6 |  *                             \___|\___/|_| \_\_____| | 
 | 7 |  * | 
 | 8 |  * Copyright (C) 1998 - 2022, 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 |  | 
 | 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 |  | 
 | 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->referer); | 
 | 62 |  | 
 | 63 |   Curl_safefree(config->headerfile); | 
 | 64 |   Curl_safefree(config->ftpport); | 
 | 65 |   Curl_safefree(config->iface); | 
 | 66 |  | 
 | 67 |   Curl_safefree(config->range); | 
 | 68 |  | 
 | 69 |   Curl_safefree(config->userpwd); | 
 | 70 |   Curl_safefree(config->tls_username); | 
 | 71 |   Curl_safefree(config->tls_password); | 
 | 72 |   Curl_safefree(config->tls_authtype); | 
 | 73 |   Curl_safefree(config->proxy_tls_username); | 
 | 74 |   Curl_safefree(config->proxy_tls_password); | 
 | 75 |   Curl_safefree(config->proxy_tls_authtype); | 
 | 76 |   Curl_safefree(config->proxyuserpwd); | 
 | 77 |   Curl_safefree(config->proxy); | 
 | 78 |  | 
 | 79 |   Curl_safefree(config->dns_ipv6_addr); | 
 | 80 |   Curl_safefree(config->dns_ipv4_addr); | 
 | 81 |   Curl_safefree(config->dns_interface); | 
 | 82 |   Curl_safefree(config->dns_servers); | 
 | 83 |  | 
 | 84 |   Curl_safefree(config->noproxy); | 
 | 85 |  | 
 | 86 |   Curl_safefree(config->mail_from); | 
 | 87 |   curl_slist_free_all(config->mail_rcpt); | 
 | 88 |   Curl_safefree(config->mail_auth); | 
 | 89 |  | 
 | 90 |   Curl_safefree(config->netrc_file); | 
 | 91 |   Curl_safefree(config->output_dir); | 
 | 92 |  | 
 | 93 |   urlnode = config->url_list; | 
 | 94 |   while(urlnode) { | 
 | 95 |     struct getout *next = urlnode->next; | 
 | 96 |     Curl_safefree(urlnode->url); | 
 | 97 |     Curl_safefree(urlnode->outfile); | 
 | 98 |     Curl_safefree(urlnode->infile); | 
 | 99 |     Curl_safefree(urlnode); | 
 | 100 |     urlnode = next; | 
 | 101 |   } | 
 | 102 |   config->url_list = NULL; | 
 | 103 |   config->url_last = NULL; | 
 | 104 |   config->url_get = NULL; | 
 | 105 |   config->url_out = NULL; | 
 | 106 |  | 
 | 107 |   Curl_safefree(config->doh_url); | 
 | 108 |   Curl_safefree(config->cipher_list); | 
 | 109 |   Curl_safefree(config->proxy_cipher_list); | 
 | 110 |   Curl_safefree(config->cert); | 
 | 111 |   Curl_safefree(config->proxy_cert); | 
 | 112 |   Curl_safefree(config->cert_type); | 
 | 113 |   Curl_safefree(config->proxy_cert_type); | 
 | 114 |   Curl_safefree(config->cacert); | 
 | 115 |   Curl_safefree(config->login_options); | 
 | 116 |   Curl_safefree(config->proxy_cacert); | 
 | 117 |   Curl_safefree(config->capath); | 
 | 118 |   Curl_safefree(config->proxy_capath); | 
 | 119 |   Curl_safefree(config->crlfile); | 
 | 120 |   Curl_safefree(config->pinnedpubkey); | 
 | 121 |   Curl_safefree(config->proxy_pinnedpubkey); | 
 | 122 |   Curl_safefree(config->proxy_crlfile); | 
 | 123 |   Curl_safefree(config->key); | 
 | 124 |   Curl_safefree(config->proxy_key); | 
 | 125 |   Curl_safefree(config->key_type); | 
 | 126 |   Curl_safefree(config->proxy_key_type); | 
 | 127 |   Curl_safefree(config->key_passwd); | 
 | 128 |   Curl_safefree(config->proxy_key_passwd); | 
 | 129 |   Curl_safefree(config->pubkey); | 
 | 130 |   Curl_safefree(config->hostpubmd5); | 
 | 131 |   Curl_safefree(config->hostpubsha256); | 
 | 132 |   Curl_safefree(config->engine); | 
 | 133 |   Curl_safefree(config->etag_save_file); | 
 | 134 |   Curl_safefree(config->etag_compare_file); | 
 | 135 |   Curl_safefree(config->request_target); | 
 | 136 |   Curl_safefree(config->customrequest); | 
 | 137 |   Curl_safefree(config->krblevel); | 
 | 138 |  | 
 | 139 |   Curl_safefree(config->oauth_bearer); | 
 | 140 |   Curl_safefree(config->sasl_authzid); | 
 | 141 |  | 
 | 142 |   Curl_safefree(config->unix_socket_path); | 
 | 143 |   Curl_safefree(config->writeout); | 
 | 144 |   Curl_safefree(config->proto_default); | 
 | 145 |  | 
 | 146 |   curl_slist_free_all(config->quote); | 
 | 147 |   curl_slist_free_all(config->postquote); | 
 | 148 |   curl_slist_free_all(config->prequote); | 
 | 149 |  | 
 | 150 |   curl_slist_free_all(config->headers); | 
 | 151 |   curl_slist_free_all(config->proxyheaders); | 
 | 152 |  | 
 | 153 |   curl_mime_free(config->mimepost); | 
 | 154 |   config->mimepost = NULL; | 
 | 155 |   tool_mime_free(config->mimeroot); | 
 | 156 |   config->mimeroot = NULL; | 
 | 157 |   config->mimecurrent = NULL; | 
 | 158 |  | 
 | 159 |   curl_slist_free_all(config->telnet_options); | 
 | 160 |   curl_slist_free_all(config->resolve); | 
 | 161 |   curl_slist_free_all(config->connect_to); | 
 | 162 |  | 
 | 163 |   Curl_safefree(config->preproxy); | 
 | 164 |   Curl_safefree(config->proxy_service_name); | 
 | 165 |   Curl_safefree(config->service_name); | 
 | 166 |  | 
 | 167 |   Curl_safefree(config->ftp_account); | 
 | 168 |   Curl_safefree(config->ftp_alternative_to_user); | 
 | 169 |  | 
 | 170 |   Curl_safefree(config->aws_sigv4); | 
 | 171 |   Curl_safefree(config->proto_str); | 
 | 172 |   Curl_safefree(config->proto_redir_str); | 
 | 173 | } | 
 | 174 |  | 
 | 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 | } |