From bc93011554f57d4d29087001712329ad9e808862 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Thu, 8 Jan 2009 00:31:49 +0000 Subject: Unified much of the SessionHandle initialization done in Curl_open() and curl_easy_reset() by creating Curl_init_userdefined(). This had the side effect of fixing curl_easy_reset() so it now also resets CURLOPT_FTP_FILEMETHOD and CURLOPT_SSL_SESSIONID_CACHE --- lib/url.c | 141 ++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 77 insertions(+), 64 deletions(-) (limited to 'lib/url.c') diff --git a/lib/url.c b/lib/url.c index 24d143420..0145d4935 100644 --- a/lib/url.c +++ b/lib/url.c @@ -622,6 +622,77 @@ void Curl_rm_connc(struct conncache *c) free(c); } +/* + * Initialize the UserDefined fields within a SessionHandle. + * This may be safely called on a new or existing SessionHandle. + */ +CURLcode Curl_init_userdefined(struct UserDefined *set) +{ + CURLcode res = CURLE_OK; + + set->out = stdout; /* default output to stdout */ + set->in = stdin; /* default input from stdin */ + set->err = stderr; /* default stderr to stderr */ + + /* use fwrite as default function to store output */ + set->fwrite_func = (curl_write_callback)fwrite; + + /* use fread as default function to read input */ + set->fread_func = (curl_read_callback)fread; + + set->seek_func = ZERO_NULL; + set->seek_client = ZERO_NULL; + + /* conversion callbacks for non-ASCII hosts */ + set->convfromnetwork = ZERO_NULL; + set->convtonetwork = ZERO_NULL; + set->convfromutf8 = ZERO_NULL; + + set->infilesize = -1; /* we don't know any size */ + set->postfieldsize = -1; /* unknown size */ + set->maxredirs = -1; /* allow any amount by default */ + + set->httpreq = HTTPREQ_GET; /* Default HTTP request */ + set->ftp_use_epsv = TRUE; /* FTP defaults to EPSV operations */ + set->ftp_use_eprt = TRUE; /* FTP defaults to EPRT operations */ + set->ftp_filemethod = FTPFILE_MULTICWD; + + set->dns_cache_timeout = 60; /* Timeout every 60 seconds by default */ + + /* Set the default size of the SSL session ID cache */ + set->ssl.numsessions = 5; + + set->proxyport = CURL_DEFAULT_PROXY_PORT; /* from url.h */ + set->proxytype = CURLPROXY_HTTP; /* defaults to HTTP proxy */ + set->httpauth = CURLAUTH_BASIC; /* defaults to basic */ + set->proxyauth = CURLAUTH_BASIC; /* defaults to basic */ + + /* make libcurl quiet by default: */ + set->hide_progress = TRUE; /* CURLOPT_NOPROGRESS changes these */ + + /* + * libcurl 7.10 introduced SSL verification *by default*! This needs to be + * switched off unless wanted. + */ + set->ssl.verifypeer = TRUE; + set->ssl.verifyhost = 2; + set->ssh_auth_types = CURLSSH_AUTH_DEFAULT; /* defaults to any auth + type */ + set->ssl.sessionid = TRUE; /* session ID caching enabled by default */ + + set->new_file_perms = 0644; /* Default permissions */ + set->new_directory_perms = 0755; /* Default permissions */ + + /* This is our preferred CA cert bundle/path since install time */ +#if defined(CURL_CA_BUNDLE) + res = setstropt(&set->str[STRING_SSL_CAFILE], (char *) CURL_CA_BUNDLE); +#elif defined(CURL_CA_PATH) + res = setstropt(&set->str[STRING_SSL_CAPATH], (char *) CURL_CA_PATH); +#endif + + return res; +} + /** * Curl_open() * @@ -669,26 +740,10 @@ CURLcode Curl_open(struct SessionHandle **curl) res = CURLE_OUT_OF_MEMORY; } else { - data->state.headersize=HEADERSIZE; - - data->set.out = stdout; /* default output to stdout */ - data->set.in = stdin; /* default input from stdin */ - data->set.err = stderr; /* default stderr to stderr */ - - /* use fwrite as default function to store output */ - data->set.fwrite_func = (curl_write_callback)fwrite; - - /* use fread as default function to read input */ - data->set.fread_func = (curl_read_callback)fread; - - /* don't use a seek function by default */ - data->set.seek_func = ZERO_NULL; - data->set.seek_client = ZERO_NULL; + Curl_easy_initHandleData(data); + res = Curl_init_userdefined(&data->set); - /* conversion callbacks for non-ASCII hosts */ - data->set.convfromnetwork = ZERO_NULL; - data->set.convtonetwork = ZERO_NULL; - data->set.convfromutf8 = ZERO_NULL; + data->state.headersize=HEADERSIZE; #if defined(CURL_DOES_CONVERSIONS) && defined(HAVE_ICONV) /* conversion descriptors for iconv calls */ @@ -697,57 +752,15 @@ CURLcode Curl_open(struct SessionHandle **curl) data->utf8_cd = (iconv_t)-1; #endif /* CURL_DOES_CONVERSIONS && HAVE_ICONV */ - data->set.infilesize = -1; /* we don't know any size */ - data->set.postfieldsize = -1; - data->set.maxredirs = -1; /* allow any amount by default */ - data->state.current_speed = -1; /* init to negative == impossible */ - - data->set.httpreq = HTTPREQ_GET; /* Default HTTP request */ - data->set.ftp_use_epsv = TRUE; /* FTP defaults to EPSV operations */ - data->set.ftp_use_eprt = TRUE; /* FTP defaults to EPRT operations */ - data->set.ftp_filemethod = FTPFILE_MULTICWD; - data->set.dns_cache_timeout = 60; /* Timeout every 60 seconds by default */ + /* most recent connection is not yet defined */ + data->state.lastconnect = -1; - /* make libcurl quiet by default: */ - data->set.hide_progress = TRUE; /* CURLOPT_NOPROGRESS changes these */ data->progress.flags |= PGRS_HIDE; - - /* Set the default size of the SSL session ID cache */ - data->set.ssl.numsessions = 5; - - data->set.proxyport = CURL_DEFAULT_PROXY_PORT; /* from url.h */ - data->set.proxytype = CURLPROXY_HTTP; /* defaults to HTTP proxy */ - data->set.httpauth = CURLAUTH_BASIC; /* defaults to basic */ - data->set.proxyauth = CURLAUTH_BASIC; /* defaults to basic */ + data->state.current_speed = -1; /* init to negative == impossible */ /* This no longer creates a connection cache here. It is instead made on the first call to curl_easy_perform() or when the handle is added to a multi stack. */ - - data->set.ssh_auth_types = CURLSSH_AUTH_DEFAULT; /* defaults to any auth - type */ - data->set.new_file_perms = 0644; /* Default permissions */ - data->set.new_directory_perms = 0755; /* Default permissions */ - - /* most recent connection is not yet defined */ - data->state.lastconnect = -1; - - Curl_easy_initHandleData(data); - - /* - * libcurl 7.10 introduced SSL verification *by default*! This needs to be - * switched off unless wanted. - */ - data->set.ssl.verifypeer = TRUE; - data->set.ssl.verifyhost = 2; - data->set.ssl.sessionid = TRUE; /* session ID caching enabled by default */ - /* This is our preferred CA cert bundle/path since install time */ -#if defined(CURL_CA_BUNDLE) - res = setstropt(&data->set.str[STRING_SSL_CAFILE], - (char *) CURL_CA_BUNDLE); -#elif defined(CURL_CA_PATH) - res = setstropt(&data->set.str[STRING_SSL_CAPATH], (char *) CURL_CA_PATH); -#endif } if(res) { -- cgit v1.2.3