Home | History | Annotate | Download | only in src
      1 /***************************************************************************
      2  *                                  _   _ ____  _
      3  *  Project                     ___| | | |  _ \| |
      4  *                             / __| | | | |_) | |
      5  *                            | (__| |_| |  _ <| |___
      6  *                             \___|\___/|_| \_\_____|
      7  *
      8  * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel (at) 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 
     24 #include "tool_cfgable.h"
     25 #include "tool_main.h"
     26 
     27 #include "memdebug.h" /* keep this as LAST include */
     28 
     29 void config_init(struct OperationConfig* config)
     30 {
     31   memset(config, 0, sizeof(struct OperationConfig));
     32 
     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 |
     41                           CURLPROTO_SMBS);
     42   config->proto_redir_present = FALSE;
     43 }
     44 
     45 static void free_config_fields(struct OperationConfig *config)
     46 {
     47   struct getout *urlnode;
     48 
     49   Curl_safefree(config->random_file);
     50   Curl_safefree(config->egd_file);
     51   Curl_safefree(config->useragent);
     52   Curl_safefree(config->cookie);
     53   Curl_safefree(config->cookiejar);
     54   Curl_safefree(config->cookiefile);
     55 
     56   Curl_safefree(config->postfields);
     57   Curl_safefree(config->referer);
     58 
     59   Curl_safefree(config->headerfile);
     60   Curl_safefree(config->ftpport);
     61   Curl_safefree(config->iface);
     62 
     63   Curl_safefree(config->range);
     64 
     65   Curl_safefree(config->userpwd);
     66   Curl_safefree(config->tls_username);
     67   Curl_safefree(config->tls_password);
     68   Curl_safefree(config->tls_authtype);
     69   Curl_safefree(config->proxyuserpwd);
     70   Curl_safefree(config->proxy);
     71 
     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 
     77   Curl_safefree(config->noproxy);
     78 
     79   Curl_safefree(config->mail_from);
     80   curl_slist_free_all(config->mail_rcpt);
     81   Curl_safefree(config->mail_auth);
     82 
     83   Curl_safefree(config->netrc_file);
     84 
     85   urlnode = config->url_list;
     86   while(urlnode) {
     87     struct getout *next = urlnode->next;
     88     Curl_safefree(urlnode->url);
     89     Curl_safefree(urlnode->outfile);
     90     Curl_safefree(urlnode->infile);
     91     Curl_safefree(urlnode);
     92     urlnode = next;
     93   }
     94   config->url_list = NULL;
     95   config->url_last = NULL;
     96   config->url_get = NULL;
     97   config->url_out = NULL;
     98 
     99   Curl_safefree(config->cipher_list);
    100   Curl_safefree(config->cert);
    101   Curl_safefree(config->cert_type);
    102   Curl_safefree(config->cacert);
    103   Curl_safefree(config->capath);
    104   Curl_safefree(config->crlfile);
    105   Curl_safefree(config->pinnedpubkey);
    106   Curl_safefree(config->key);
    107   Curl_safefree(config->key_type);
    108   Curl_safefree(config->key_passwd);
    109   Curl_safefree(config->pubkey);
    110   Curl_safefree(config->hostpubmd5);
    111   Curl_safefree(config->engine);
    112 
    113   Curl_safefree(config->customrequest);
    114   Curl_safefree(config->krblevel);
    115 
    116   Curl_safefree(config->xoauth2_bearer);
    117 
    118   Curl_safefree(config->unix_socket_path);
    119   Curl_safefree(config->writeout);
    120 
    121   curl_slist_free_all(config->quote);
    122   curl_slist_free_all(config->postquote);
    123   curl_slist_free_all(config->prequote);
    124 
    125   curl_slist_free_all(config->headers);
    126   curl_slist_free_all(config->proxyheaders);
    127 
    128   if(config->httppost) {
    129     curl_formfree(config->httppost);
    130     config->httppost = NULL;
    131   }
    132   config->last_post = NULL;
    133 
    134   curl_slist_free_all(config->telnet_options);
    135   curl_slist_free_all(config->resolve);
    136 
    137   Curl_safefree(config->socksproxy);
    138   Curl_safefree(config->socks5_gssapi_service);
    139   Curl_safefree(config->proxy_service_name);
    140   Curl_safefree(config->service_name);
    141 
    142   Curl_safefree(config->ftp_account);
    143   Curl_safefree(config->ftp_alternative_to_user);
    144 }
    145 
    146 void config_free(struct OperationConfig *config)
    147 {
    148   struct OperationConfig *last = config;
    149 
    150   /* Free each of the structures in reverse order */
    151   while(last) {
    152     struct OperationConfig *prev = last->prev;
    153 
    154     free_config_fields(last);
    155     free(last);
    156 
    157     last = prev;
    158   }
    159 }
    160