curl tool: move 'Configurable' and free_config_fields() to tool_cfgable.[ch]

Reviewing fields being free'd in free_config_fields() still pending
This commit is contained in:
Yang Tse 2011-09-16 21:44:45 +02:00
parent 93579cc363
commit c0159d0edc
6 changed files with 359 additions and 283 deletions

View File

@ -16,12 +16,12 @@ CURLX_ONES = $(top_srcdir)/lib/strtoofft.c \
CURL_CFILES = main.c hugehelp.c urlglob.c writeout.c writeenv.c \
getpass.c homedir.c curlutil.c os-specific.c xattr.c \
tool_convert.c tool_mfiles.c
tool_cfgable.c tool_convert.c tool_mfiles.c
CURL_HFILES = hugehelp.h setup.h config-win32.h config-mac.h \
config-riscos.h urlglob.h version.h os-specific.h \
writeout.h writeenv.h getpass.h homedir.h curlutil.h \
xattr.h tool_convert.h tool_mfiles.h
xattr.h tool_cfgable.h tool_convert.h tool_mfiles.h
curl_SOURCES = $(CURL_CFILES) $(CURLX_ONES) $(CURL_HFILES)

View File

@ -142,6 +142,7 @@ RELEASE_OBJS= \
os-specificr.obj \
rawstrr.obj \
strtoofftr.obj \
tool_cfgabler.obj \
tool_convertr.obj \
tool_mfilesr.obj \
urlglobr.obj \
@ -159,6 +160,7 @@ DEBUG_OBJS= \
os-specificd.obj \
rawstrd.obj \
strtoofftd.obj \
tool_cfgabled.obj \
tool_convertd.obj \
tool_mfilesd.obj \
urlglobd.obj \
@ -306,6 +308,8 @@ rawstrr.obj: ../lib/rawstr.c
$(CCR) $(CFLAGS) /Fo"$@" ../lib/rawstr.c
strtoofftr.obj: ../lib/strtoofft.c
$(CCR) $(CFLAGS) /Fo"$@" ../lib/strtoofft.c
tool_cfgabler.obj: tool_cfgable.c
$(CCR) $(CFLAGS) /Fo"$@" tool_cfgable.c
tool_convertr.obj: tool_convert.c
$(CCR) $(CFLAGS) /Fo"$@" tool_convert.c
tool_mfilesr.obj: tool_mfiles.c
@ -338,6 +342,8 @@ rawstrd.obj: ../lib/rawstr.c
$(CCD) $(CFLAGS) /Fo"$@" ../lib/rawstr.c
strtoofftd.obj: ../lib/strtoofft.c
$(CCD) $(CFLAGS) /Fo"$@" ../lib/strtoofft.c
tool_cfgabled.obj: tool_cfgable.c
$(CCD) $(CFLAGS) /Fo"$@" tool_cfgable.c
tool_convertd.obj: tool_convert.c
$(CCD) $(CFLAGS) /Fo"$@" tool_convert.c
tool_mfilesd.obj: tool_mfiles.c

View File

@ -113,6 +113,7 @@
#include "xattr.h"
#include "tool_convert.h"
#include "tool_mfiles.h"
#include "tool_cfgable.h"
#ifdef USE_MANUAL
# include "hugehelp.h"
#endif
@ -218,16 +219,6 @@ char **__crt0_glob_function (char *arg)
#define CURL_PROGRESS_STATS 0 /* default progress display */
#define CURL_PROGRESS_BAR 1
typedef enum {
HTTPREQ_UNSPEC,
HTTPREQ_GET,
HTTPREQ_HEAD,
HTTPREQ_POST,
HTTPREQ_SIMPLEPOST,
HTTPREQ_CUSTOM,
HTTPREQ_LAST
} HttpReq;
/*
* Large file support (>2Gb) using WIN32 functions.
*/
@ -352,192 +343,6 @@ static int ftruncate64(int fd, curl_off_t where)
#endif /* WIN32 */
typedef enum {
TRACE_NONE, /* no trace/verbose output at all! */
TRACE_BIN, /* tcpdump inspired look */
TRACE_ASCII, /* like *BIN but without the hex output */
TRACE_PLAIN /* -v/--verbose type */
} trace;
struct OutStruct {
char *filename;
bool alloc_filename;
FILE *stream;
struct Configurable *config;
curl_off_t bytes; /* amount written so far */
curl_off_t init; /* original size (non-zero when appending) */
};
struct Configurable {
CURL *easy; /* once we have one, we keep it here */
bool remote_time;
char *random_file;
char *egd_file;
char *useragent;
char *cookie; /* single line with specified cookies */
char *cookiejar; /* write to this file */
char *cookiefile; /* read from this file */
bool cookiesession; /* new session? */
bool encoding; /* Accept-Encoding please */
bool tr_encoding; /* Transfer-Encoding please */
long authtype; /* auth bitmask */
bool use_resume;
bool resume_from_current;
bool disable_epsv;
bool disable_eprt;
bool ftp_pret;
long proto;
bool proto_present;
long proto_redir;
bool proto_redir_present;
curl_off_t resume_from;
char *postfields;
curl_off_t postfieldsize;
char *referer;
long timeout;
long connecttimeout;
long maxredirs;
curl_off_t max_filesize;
char *headerfile;
char *ftpport;
char *iface;
int localport;
int localportrange;
unsigned short porttouse;
char *range;
long low_speed_limit;
long low_speed_time;
bool showerror;
char *userpwd;
char *tls_username;
char *tls_password;
char *tls_authtype;
char *proxyuserpwd;
char *proxy;
int proxyver; /* set to CURLPROXY_HTTP* define */
char *noproxy;
char *mail_from;
struct curl_slist *mail_rcpt;
bool proxytunnel;
bool ftp_append; /* APPE on ftp */
bool mute; /* shutup */
bool use_ascii; /* select ascii or text transfer */
bool autoreferer; /* automatically set referer */
bool failonerror; /* fail on (HTTP) errors */
bool include_headers; /* send headers to data output */
bool no_body; /* don't get the body */
bool dirlistonly; /* only get the FTP dir list */
bool followlocation; /* follow http redirects */
bool unrestricted_auth; /* Continue to send authentication (user+password)
when following ocations, even when hostname
changed */
bool netrc_opt;
bool netrc;
char *netrc_file;
bool noprogress;
bool isatty; /* updated internally only if the output is a tty */
struct getout *url_list; /* point to the first node */
struct getout *url_last; /* point to the last/current node */
struct getout *url_get; /* point to the node to fill in URL */
struct getout *url_out; /* point to the node to fill in outfile */
char *cipher_list;
char *cert;
char *cert_type;
char *cacert;
char *capath;
char *crlfile;
char *key;
char *key_type;
char *key_passwd;
char *pubkey;
char *hostpubmd5;
char *engine;
bool list_engines;
bool crlf;
char *customrequest;
char *krblevel;
char *trace_dump; /* file to dump the network trace to, or NULL */
FILE *trace_stream;
bool trace_fopened;
trace tracetype;
bool tracetime; /* include timestamp? */
long httpversion;
int progressmode;
bool nobuffer;
bool readbusy; /* set when reading input returns EAGAIN */
bool globoff;
bool use_httpget;
bool insecure_ok; /* set TRUE to allow insecure SSL connects */
bool create_dirs;
bool ftp_create_dirs;
bool ftp_skip_ip;
bool proxynegotiate;
bool proxyntlm;
bool proxydigest;
bool proxybasic;
bool proxyanyauth;
char *writeout; /* %-styled format string to output */
bool writeenv; /* write results to environment, if available */
FILE *errors; /* if stderr redirect is requested */
bool errors_fopened;
struct curl_slist *quote;
struct curl_slist *postquote;
struct curl_slist *prequote;
long ssl_version;
long ip_version;
curl_TimeCond timecond;
time_t condtime;
struct curl_slist *headers;
struct curl_httppost *httppost;
struct curl_httppost *last_post;
struct curl_slist *telnet_options;
struct curl_slist *resolve;
HttpReq httpreq;
/* for bandwidth limiting features: */
curl_off_t sendpersecond; /* send to peer */
curl_off_t recvpersecond; /* receive from peer */
bool ftp_ssl;
bool ftp_ssl_reqd;
bool ftp_ssl_control;
bool ftp_ssl_ccc;
int ftp_ssl_ccc_mode;
char *socksproxy; /* set to server string */
int socksver; /* set to CURLPROXY_SOCKS* define */
char *socks5_gssapi_service; /* set service name for gssapi principal
* default rcmd */
int socks5_gssapi_nec ; /* The NEC reference server does not protect
* the encryption type exchange */
bool tcp_nodelay;
long req_retry; /* number of retries */
long retry_delay; /* delay between retries (in seconds) */
long retry_maxtime; /* maximum time to keep retrying */
char *ftp_account; /* for ACCT */
char *ftp_alternative_to_user; /* send command if USER/PASS fails */
int ftp_filemethod;
long tftp_blksize; /* TFTP BLKSIZE option */
bool ignorecl; /* --ignore-content-length */
bool disable_sessionid;
char *libcurl; /* output libcurl code to this file name */
bool raw;
bool post301;
bool post302;
bool nokeepalive; /* for keepalive needs */
long alivetime;
bool content_disposition; /* use Content-disposition filename */
int default_node_flags; /* default flags to search for each 'node', which is
basically each given URL to transfer */
struct OutStruct *outs;
bool xattr; /* store metadata in extended attributes */
long gssapi_delegation;
};
#define WARN_PREFIX "Warning: "
#define WARN_TEXTWIDTH (79 - (int)strlen(WARN_PREFIX))
/* produce this text message to the user unless mute was selected */
@ -634,23 +439,6 @@ static void helpf(FILE *errors, const char *fmt, ...)
"for more information\n");
}
/*
* A chain of these nodes contain URL to get and where to put the URL's
* contents.
*/
struct getout {
struct getout *next; /* next one */
char *url; /* the URL we deal with */
char *outfile; /* where to store the output */
char *infile; /* file to upload, if GETOUT_UPLOAD is set */
int flags; /* options */
};
#define GETOUT_OUTFILE (1<<0) /* set when outfile is deemed done */
#define GETOUT_URL (1<<1) /* set when URL is deemed done */
#define GETOUT_USEREMOTE (1<<2) /* use remote file name locally */
#define GETOUT_UPLOAD (1<<3) /* if set, -T has been used */
#define GETOUT_NOUPLOAD (1<<4) /* if set, -T "" has been used */
static void help(void)
{
int i;
@ -3878,74 +3666,6 @@ int my_trace(CURL *handle, curl_infotype type,
return 0;
}
static void free_config_fields(struct Configurable *config)
{
Curl_safefree(config->random_file);
Curl_safefree(config->egd_file);
Curl_safefree(config->trace_dump);
Curl_safefree(config->cipher_list);
Curl_safefree(config->userpwd);
Curl_safefree(config->postfields);
Curl_safefree(config->proxy);
Curl_safefree(config->proxyuserpwd);
Curl_safefree(config->noproxy);
Curl_safefree(config->cookie);
Curl_safefree(config->cookiefile);
Curl_safefree(config->krblevel);
Curl_safefree(config->headerfile);
Curl_safefree(config->ftpport);
Curl_safefree(config->range);
Curl_safefree(config->customrequest);
Curl_safefree(config->writeout);
if(config->httppost) {
curl_formfree(config->httppost);
config->httppost = NULL;
}
Curl_safefree(config->netrc_file);
Curl_safefree(config->cert);
Curl_safefree(config->cacert);
Curl_safefree(config->cert_type);
Curl_safefree(config->capath);
Curl_safefree(config->crlfile);
Curl_safefree(config->cookiejar);
Curl_safefree(config->ftp_account);
Curl_safefree(config->ftp_alternative_to_user);
Curl_safefree(config->iface);
Curl_safefree(config->socksproxy);
Curl_safefree(config->libcurl);
Curl_safefree(config->key_passwd);
Curl_safefree(config->key);
Curl_safefree(config->key_type);
Curl_safefree(config->pubkey);
Curl_safefree(config->referer);
Curl_safefree(config->hostpubmd5);
Curl_safefree(config->mail_from);
#ifdef USE_TLS_SRP
Curl_safefree(config->tls_authtype);
Curl_safefree(config->tls_username);
Curl_safefree(config->tls_password);
#endif
#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
Curl_safefree(config->socks5_gssapi_service);
#endif
curl_slist_free_all(config->quote); /* checks for config->quote == NULL */
curl_slist_free_all(config->prequote);
curl_slist_free_all(config->postquote);
curl_slist_free_all(config->headers);
curl_slist_free_all(config->telnet_options);
curl_slist_free_all(config->mail_rcpt);
curl_slist_free_all(config->resolve);
if(config->easy) {
curl_easy_cleanup(config->easy);
config->easy = NULL;
}
}
#ifdef WIN32
/* Function to find CACert bundle on a Win32 platform using SearchPath.

98
src/tool_cfgable.c Normal file
View File

@ -0,0 +1,98 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at http://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "setup.h"
#include <curl/curl.h>
#include "tool_cfgable.h"
#include "memdebug.h" /* keep this as LAST include */
/* TODO: review that all dinamically allocated fields are free'd */
void free_config_fields(struct Configurable *config)
{
Curl_safefree(config->random_file);
Curl_safefree(config->egd_file);
Curl_safefree(config->trace_dump);
Curl_safefree(config->cipher_list);
Curl_safefree(config->userpwd);
Curl_safefree(config->postfields);
Curl_safefree(config->proxy);
Curl_safefree(config->proxyuserpwd);
Curl_safefree(config->noproxy);
Curl_safefree(config->cookie);
Curl_safefree(config->cookiefile);
Curl_safefree(config->krblevel);
Curl_safefree(config->headerfile);
Curl_safefree(config->ftpport);
Curl_safefree(config->range);
Curl_safefree(config->customrequest);
Curl_safefree(config->writeout);
if(config->httppost) {
curl_formfree(config->httppost);
config->httppost = NULL;
}
Curl_safefree(config->netrc_file);
Curl_safefree(config->cert);
Curl_safefree(config->cacert);
Curl_safefree(config->cert_type);
Curl_safefree(config->capath);
Curl_safefree(config->crlfile);
Curl_safefree(config->cookiejar);
Curl_safefree(config->ftp_account);
Curl_safefree(config->ftp_alternative_to_user);
Curl_safefree(config->iface);
Curl_safefree(config->socksproxy);
Curl_safefree(config->libcurl);
Curl_safefree(config->key_passwd);
Curl_safefree(config->key);
Curl_safefree(config->key_type);
Curl_safefree(config->pubkey);
Curl_safefree(config->referer);
Curl_safefree(config->hostpubmd5);
Curl_safefree(config->mail_from);
#ifdef USE_TLS_SRP
Curl_safefree(config->tls_authtype);
Curl_safefree(config->tls_username);
Curl_safefree(config->tls_password);
#endif
#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
Curl_safefree(config->socks5_gssapi_service);
#endif
curl_slist_free_all(config->quote); /* checks for config->quote == NULL */
curl_slist_free_all(config->prequote);
curl_slist_free_all(config->postquote);
curl_slist_free_all(config->headers);
curl_slist_free_all(config->telnet_options);
curl_slist_free_all(config->mail_rcpt);
curl_slist_free_all(config->resolve);
if(config->easy) {
curl_easy_cleanup(config->easy);
config->easy = NULL;
}
}

244
src/tool_cfgable.h Normal file
View File

@ -0,0 +1,244 @@
#ifndef HEADER_CURL_TOOL_CFGABLE_H
#define HEADER_CURL_TOOL_CFGABLE_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at http://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "setup.h"
typedef enum {
HTTPREQ_UNSPEC,
HTTPREQ_GET,
HTTPREQ_HEAD,
HTTPREQ_POST,
HTTPREQ_SIMPLEPOST,
HTTPREQ_CUSTOM,
HTTPREQ_LAST
} HttpReq;
typedef enum {
TRACE_NONE, /* no trace/verbose output at all */
TRACE_BIN, /* tcpdump inspired look */
TRACE_ASCII, /* like *BIN but without the hex output */
TRACE_PLAIN /* -v/--verbose type */
} trace;
struct OutStruct {
char *filename;
bool alloc_filename;
FILE *stream;
struct Configurable *config;
curl_off_t bytes; /* amount written so far */
curl_off_t init; /* original size (non-zero when appending) */
};
/*
* A chain of these 'getout' nodes contain URL's to fetch and where to
* place URL's contents.
*/
struct getout {
struct getout *next; /* next one */
char *url; /* the URL we deal with */
char *outfile; /* where to store the output */
char *infile; /* file to upload, if GETOUT_UPLOAD is set */
int flags; /* options - composed of GETOUT_* bits */
};
#define GETOUT_OUTFILE (1<<0) /* set when outfile is deemed done */
#define GETOUT_URL (1<<1) /* set when URL is deemed done */
#define GETOUT_USEREMOTE (1<<2) /* use remote file name locally */
#define GETOUT_UPLOAD (1<<3) /* if set, -T has been used */
#define GETOUT_NOUPLOAD (1<<4) /* if set, -T "" has been used */
struct Configurable {
CURL *easy; /* once we have one, we keep it here */
bool remote_time;
char *random_file;
char *egd_file;
char *useragent;
char *cookie; /* single line with specified cookies */
char *cookiejar; /* write to this file */
char *cookiefile; /* read from this file */
bool cookiesession; /* new session? */
bool encoding; /* Accept-Encoding please */
bool tr_encoding; /* Transfer-Encoding please */
long authtype; /* auth bitmask */
bool use_resume;
bool resume_from_current;
bool disable_epsv;
bool disable_eprt;
bool ftp_pret;
long proto;
bool proto_present;
long proto_redir;
bool proto_redir_present;
curl_off_t resume_from;
char *postfields;
curl_off_t postfieldsize;
char *referer;
long timeout;
long connecttimeout;
long maxredirs;
curl_off_t max_filesize;
char *headerfile;
char *ftpport;
char *iface;
int localport;
int localportrange;
unsigned short porttouse;
char *range;
long low_speed_limit;
long low_speed_time;
bool showerror;
char *userpwd;
char *tls_username;
char *tls_password;
char *tls_authtype;
char *proxyuserpwd;
char *proxy;
int proxyver; /* set to CURLPROXY_HTTP* define */
char *noproxy;
char *mail_from;
struct curl_slist *mail_rcpt;
bool proxytunnel;
bool ftp_append; /* APPE on ftp */
bool mute; /* shutup */
bool use_ascii; /* select ascii or text transfer */
bool autoreferer; /* automatically set referer */
bool failonerror; /* fail on (HTTP) errors */
bool include_headers; /* send headers to data output */
bool no_body; /* don't get the body */
bool dirlistonly; /* only get the FTP dir list */
bool followlocation; /* follow http redirects */
bool unrestricted_auth; /* Continue to send authentication (user+password)
when following ocations, even when hostname
changed */
bool netrc_opt;
bool netrc;
char *netrc_file;
bool noprogress;
bool isatty; /* updated internally only if output is a tty */
struct getout *url_list; /* point to the first node */
struct getout *url_last; /* point to the last/current node */
struct getout *url_get; /* point to the node to fill in URL */
struct getout *url_out; /* point to the node to fill in outfile */
char *cipher_list;
char *cert;
char *cert_type;
char *cacert;
char *capath;
char *crlfile;
char *key;
char *key_type;
char *key_passwd;
char *pubkey;
char *hostpubmd5;
char *engine;
bool list_engines;
bool crlf;
char *customrequest;
char *krblevel;
char *trace_dump; /* file to dump the network trace to, or NULL */
FILE *trace_stream;
bool trace_fopened;
trace tracetype;
bool tracetime; /* include timestamp? */
long httpversion;
int progressmode;
bool nobuffer;
bool readbusy; /* set when reading input returns EAGAIN */
bool globoff;
bool use_httpget;
bool insecure_ok; /* set TRUE to allow insecure SSL connects */
bool create_dirs;
bool ftp_create_dirs;
bool ftp_skip_ip;
bool proxynegotiate;
bool proxyntlm;
bool proxydigest;
bool proxybasic;
bool proxyanyauth;
char *writeout; /* %-styled format string to output */
bool writeenv; /* write results to environment, if available */
FILE *errors; /* if stderr redirect is requested */
bool errors_fopened;
struct curl_slist *quote;
struct curl_slist *postquote;
struct curl_slist *prequote;
long ssl_version;
long ip_version;
curl_TimeCond timecond;
time_t condtime;
struct curl_slist *headers;
struct curl_httppost *httppost;
struct curl_httppost *last_post;
struct curl_slist *telnet_options;
struct curl_slist *resolve;
HttpReq httpreq;
/* for bandwidth limiting features: */
curl_off_t sendpersecond; /* send to peer */
curl_off_t recvpersecond; /* receive from peer */
bool ftp_ssl;
bool ftp_ssl_reqd;
bool ftp_ssl_control;
bool ftp_ssl_ccc;
int ftp_ssl_ccc_mode;
char *socksproxy; /* set to server string */
int socksver; /* set to CURLPROXY_SOCKS* define */
char *socks5_gssapi_service; /* set service name for gssapi principal
* default rcmd */
int socks5_gssapi_nec ; /* The NEC reference server does not protect
* the encryption type exchange */
bool tcp_nodelay;
long req_retry; /* number of retries */
long retry_delay; /* delay between retries (in seconds) */
long retry_maxtime; /* maximum time to keep retrying */
char *ftp_account; /* for ACCT */
char *ftp_alternative_to_user; /* send command if USER/PASS fails */
int ftp_filemethod;
long tftp_blksize; /* TFTP BLKSIZE option */
bool ignorecl; /* --ignore-content-length */
bool disable_sessionid;
char *libcurl; /* output libcurl code to this file name */
bool raw;
bool post301;
bool post302;
bool nokeepalive; /* for keepalive needs */
long alivetime;
bool content_disposition; /* use Content-disposition filename */
int default_node_flags; /* default flags to search for each 'node', which
is basically each given URL to transfer */
struct OutStruct *outs;
bool xattr; /* store metadata in extended attributes */
long gssapi_delegation;
}; /* struct Configurable */
void free_config_fields(struct Configurable *config);
#endif /* HEADER_CURL_TOOL_CFGABLE_H */

View File

@ -175,6 +175,10 @@ SOURCE=..\lib\strtoofft.c
# End Source File
# Begin Source File
SOURCE=.\tool_cfgable.c
# End Source File
# Begin Source File
SOURCE=.\tool_convert.c
# End Source File
# Begin Source File
@ -243,6 +247,10 @@ SOURCE=..\lib\strtoofft.h
# End Source File
# Begin Source File
SOURCE=.\tool_cfgable.h
# End Source File
# Begin Source File
SOURCE=.\tool_convert.h
# End Source File
# Begin Source File