tool_cfgable.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2014, 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 http://curl.haxx.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. ***************************************************************************/
  22. #include "tool_setup.h"
  23. #include "tool_cfgable.h"
  24. #include "tool_main.h"
  25. #include "memdebug.h" /* keep this as LAST include */
  26. void config_init(struct OperationConfig* config)
  27. {
  28. memset(config, 0, sizeof(struct OperationConfig));
  29. config->postfieldsize = -1;
  30. config->use_httpget = FALSE;
  31. config->create_dirs = FALSE;
  32. config->maxredirs = DEFAULT_MAXREDIRS;
  33. config->proto = CURLPROTO_ALL; /* FIXME: better to read from library */
  34. config->proto_present = FALSE;
  35. config->proto_redir =
  36. CURLPROTO_ALL & ~(CURLPROTO_FILE|CURLPROTO_SCP); /* not FILE or SCP */
  37. config->proto_redir_present = FALSE;
  38. }
  39. static void free_config_fields(struct OperationConfig *config)
  40. {
  41. struct getout *urlnode;
  42. Curl_safefree(config->random_file);
  43. Curl_safefree(config->egd_file);
  44. Curl_safefree(config->useragent);
  45. Curl_safefree(config->cookie);
  46. Curl_safefree(config->cookiejar);
  47. Curl_safefree(config->cookiefile);
  48. Curl_safefree(config->postfields);
  49. Curl_safefree(config->referer);
  50. Curl_safefree(config->headerfile);
  51. Curl_safefree(config->ftpport);
  52. Curl_safefree(config->iface);
  53. Curl_safefree(config->range);
  54. Curl_safefree(config->userpwd);
  55. Curl_safefree(config->tls_username);
  56. Curl_safefree(config->tls_password);
  57. Curl_safefree(config->tls_authtype);
  58. Curl_safefree(config->proxyuserpwd);
  59. Curl_safefree(config->proxy);
  60. Curl_safefree(config->dns_ipv6_addr);
  61. Curl_safefree(config->dns_ipv4_addr);
  62. Curl_safefree(config->dns_interface);
  63. Curl_safefree(config->dns_servers);
  64. Curl_safefree(config->noproxy);
  65. Curl_safefree(config->mail_from);
  66. curl_slist_free_all(config->mail_rcpt);
  67. Curl_safefree(config->mail_auth);
  68. Curl_safefree(config->netrc_file);
  69. urlnode = config->url_list;
  70. while(urlnode) {
  71. struct getout *next = urlnode->next;
  72. Curl_safefree(urlnode->url);
  73. Curl_safefree(urlnode->outfile);
  74. Curl_safefree(urlnode->infile);
  75. Curl_safefree(urlnode);
  76. urlnode = next;
  77. }
  78. config->url_list = NULL;
  79. config->url_last = NULL;
  80. config->url_get = NULL;
  81. config->url_out = NULL;
  82. Curl_safefree(config->cipher_list);
  83. Curl_safefree(config->cert);
  84. Curl_safefree(config->cert_type);
  85. Curl_safefree(config->cacert);
  86. Curl_safefree(config->capath);
  87. Curl_safefree(config->crlfile);
  88. Curl_safefree(config->key);
  89. Curl_safefree(config->key_type);
  90. Curl_safefree(config->key_passwd);
  91. Curl_safefree(config->pubkey);
  92. Curl_safefree(config->hostpubmd5);
  93. Curl_safefree(config->engine);
  94. Curl_safefree(config->customrequest);
  95. Curl_safefree(config->krblevel);
  96. Curl_safefree(config->xoauth2_bearer);
  97. Curl_safefree(config->writeout);
  98. curl_slist_free_all(config->quote);
  99. curl_slist_free_all(config->postquote);
  100. curl_slist_free_all(config->prequote);
  101. curl_slist_free_all(config->headers);
  102. curl_slist_free_all(config->proxyheaders);
  103. if(config->httppost) {
  104. curl_formfree(config->httppost);
  105. config->httppost = NULL;
  106. }
  107. config->last_post = NULL;
  108. curl_slist_free_all(config->telnet_options);
  109. curl_slist_free_all(config->resolve);
  110. Curl_safefree(config->socksproxy);
  111. Curl_safefree(config->socks5_gssapi_service);
  112. Curl_safefree(config->ftp_account);
  113. Curl_safefree(config->ftp_alternative_to_user);
  114. }
  115. void config_free(struct OperationConfig *config)
  116. {
  117. struct OperationConfig *last = config;
  118. /* Free each of the structures in reverse order */
  119. while(last) {
  120. struct OperationConfig *prev = last->prev;
  121. free_config_fields(last);
  122. free(last);
  123. last = prev;
  124. }
  125. }