tool_cfgable.c 5.7 KB

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