tool_cfgable.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. #include "tool_cfgable.h"
  26. #include "tool_formparse.h"
  27. #include "tool_paramhlp.h"
  28. #include "tool_main.h"
  29. #include "memdebug.h" /* keep this as LAST include */
  30. void config_init(struct OperationConfig *config)
  31. {
  32. memset(config, 0, sizeof(struct OperationConfig));
  33. config->use_httpget = FALSE;
  34. config->create_dirs = FALSE;
  35. config->maxredirs = DEFAULT_MAXREDIRS;
  36. config->proto_present = FALSE;
  37. config->proto_redir_present = FALSE;
  38. config->proto_default = NULL;
  39. config->tcp_nodelay = TRUE; /* enabled by default */
  40. config->happy_eyeballs_timeout_ms = CURL_HET_DEFAULT;
  41. config->http09_allowed = FALSE;
  42. config->ftp_skip_ip = TRUE;
  43. config->file_clobber_mode = CLOBBER_DEFAULT;
  44. curlx_dyn_init(&config->postdata, MAX_FILE2MEMORY);
  45. }
  46. static void free_config_fields(struct OperationConfig *config)
  47. {
  48. struct getout *urlnode;
  49. Curl_safefree(config->useragent);
  50. Curl_safefree(config->altsvc);
  51. Curl_safefree(config->hsts);
  52. Curl_safefree(config->haproxy_clientip);
  53. curl_slist_free_all(config->cookies);
  54. Curl_safefree(config->cookiejar);
  55. curl_slist_free_all(config->cookiefiles);
  56. Curl_dyn_free(&config->postdata);
  57. Curl_safefree(config->query);
  58. Curl_safefree(config->referer);
  59. Curl_safefree(config->headerfile);
  60. Curl_safefree(config->ftpport);
  61. Curl_safefree(config->iface);
  62. Curl_safefree(config->range);
  63. Curl_safefree(config->userpwd);
  64. Curl_safefree(config->tls_username);
  65. Curl_safefree(config->tls_password);
  66. Curl_safefree(config->tls_authtype);
  67. Curl_safefree(config->proxy_tls_username);
  68. Curl_safefree(config->proxy_tls_password);
  69. Curl_safefree(config->proxy_tls_authtype);
  70. Curl_safefree(config->proxyuserpwd);
  71. Curl_safefree(config->proxy);
  72. Curl_safefree(config->dns_ipv6_addr);
  73. Curl_safefree(config->dns_ipv4_addr);
  74. Curl_safefree(config->dns_interface);
  75. Curl_safefree(config->dns_servers);
  76. Curl_safefree(config->noproxy);
  77. Curl_safefree(config->mail_from);
  78. curl_slist_free_all(config->mail_rcpt);
  79. Curl_safefree(config->mail_auth);
  80. Curl_safefree(config->netrc_file);
  81. Curl_safefree(config->output_dir);
  82. Curl_safefree(config->proto_str);
  83. Curl_safefree(config->proto_redir_str);
  84. urlnode = config->url_list;
  85. while(urlnode) {
  86. struct getout *next = urlnode->next;
  87. Curl_safefree(urlnode->url);
  88. Curl_safefree(urlnode->outfile);
  89. Curl_safefree(urlnode->infile);
  90. Curl_safefree(urlnode);
  91. urlnode = next;
  92. }
  93. config->url_list = NULL;
  94. config->url_last = NULL;
  95. config->url_get = NULL;
  96. config->url_out = NULL;
  97. Curl_safefree(config->ipfs_gateway);
  98. Curl_safefree(config->doh_url);
  99. Curl_safefree(config->cipher_list);
  100. Curl_safefree(config->proxy_cipher_list);
  101. Curl_safefree(config->cert);
  102. Curl_safefree(config->proxy_cert);
  103. Curl_safefree(config->cert_type);
  104. Curl_safefree(config->proxy_cert_type);
  105. Curl_safefree(config->cacert);
  106. Curl_safefree(config->login_options);
  107. Curl_safefree(config->proxy_cacert);
  108. Curl_safefree(config->capath);
  109. Curl_safefree(config->proxy_capath);
  110. Curl_safefree(config->crlfile);
  111. Curl_safefree(config->pinnedpubkey);
  112. Curl_safefree(config->proxy_pinnedpubkey);
  113. Curl_safefree(config->proxy_crlfile);
  114. Curl_safefree(config->key);
  115. Curl_safefree(config->proxy_key);
  116. Curl_safefree(config->key_type);
  117. Curl_safefree(config->proxy_key_type);
  118. Curl_safefree(config->key_passwd);
  119. Curl_safefree(config->proxy_key_passwd);
  120. Curl_safefree(config->pubkey);
  121. Curl_safefree(config->hostpubmd5);
  122. Curl_safefree(config->hostpubsha256);
  123. Curl_safefree(config->engine);
  124. Curl_safefree(config->etag_save_file);
  125. Curl_safefree(config->etag_compare_file);
  126. Curl_safefree(config->ssl_ec_curves);
  127. Curl_safefree(config->request_target);
  128. Curl_safefree(config->customrequest);
  129. Curl_safefree(config->krblevel);
  130. Curl_safefree(config->oauth_bearer);
  131. Curl_safefree(config->sasl_authzid);
  132. Curl_safefree(config->unix_socket_path);
  133. Curl_safefree(config->writeout);
  134. Curl_safefree(config->proto_default);
  135. curl_slist_free_all(config->quote);
  136. curl_slist_free_all(config->postquote);
  137. curl_slist_free_all(config->prequote);
  138. curl_slist_free_all(config->headers);
  139. curl_slist_free_all(config->proxyheaders);
  140. curl_mime_free(config->mimepost);
  141. config->mimepost = NULL;
  142. tool_mime_free(config->mimeroot);
  143. config->mimeroot = NULL;
  144. config->mimecurrent = NULL;
  145. curl_slist_free_all(config->telnet_options);
  146. curl_slist_free_all(config->resolve);
  147. curl_slist_free_all(config->connect_to);
  148. Curl_safefree(config->preproxy);
  149. Curl_safefree(config->proxy_service_name);
  150. Curl_safefree(config->service_name);
  151. Curl_safefree(config->ftp_account);
  152. Curl_safefree(config->ftp_alternative_to_user);
  153. Curl_safefree(config->aws_sigv4);
  154. Curl_safefree(config->proto_str);
  155. Curl_safefree(config->proto_redir_str);
  156. }
  157. void config_free(struct OperationConfig *config)
  158. {
  159. struct OperationConfig *last = config;
  160. /* Free each of the structures in reverse order */
  161. while(last) {
  162. struct OperationConfig *prev = last->prev;
  163. free_config_fields(last);
  164. free(last);
  165. last = prev;
  166. }
  167. }