Unified much of the SessionHandle initialization done in Curl_open() and
authorDan Fandrich <dan@coneharvesters.com>
Thu, 8 Jan 2009 00:31:49 +0000 (00:31 +0000)
committerDan Fandrich <dan@coneharvesters.com>
Thu, 8 Jan 2009 00:31:49 +0000 (00:31 +0000)
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

CHANGES
RELEASE-NOTES
lib/easy.c
lib/url.c
lib/url.h

diff --git a/CHANGES b/CHANGES
index ce89bce..b92b229 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,12 @@
                                   Changelog
 
 
+Daniel Fandrich (7 Jan 2009)
+- 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
+
 Daniel Stenberg (7 Jan 2009)
 - Rob Crittenden did once again provide an NSS update:
 
index 72404f3..aefebf4 100644 (file)
@@ -41,6 +41,7 @@ This release includes the following bugfixes:
  o fixed breakage with --with-ssl --disable-verbose
  o TTL "leak" in the DNS cache
  o improved NSS initing
+ o curl_easy_reset now resets more options
 
 This release includes the following known bugs:
 
index ae669f9..4bba1b4 100644 (file)
@@ -722,6 +722,7 @@ void curl_easy_reset(CURL *curl)
   /* zero out UserDefined data: */
   Curl_freeset(data);
   memset(&data->set, 0, sizeof(struct UserDefined));
+  (void)Curl_init_userdefined(&data->set);
 
   /* zero out Progress data: */
   memset(&data->progress, 0, sizeof(struct Progress));
@@ -729,58 +730,8 @@ void curl_easy_reset(CURL *curl)
   /* init Handle data */
   Curl_easy_initHandleData(data);
 
-  /* The remainder of these calls have been taken from Curl_open() */
-
-  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;
-
-  data->set.infilesize = -1;      /* we don't know any size */
-  data->set.postfieldsize = -1;   /* unknown size */
-  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.dns_cache_timeout = 60; /* Timeout every 60 seconds by default */
-
-  /* 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 */
-
-  /*
-   * 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;
-  /* This is our prefered CA cert bundle/path since install time */
-#if defined(CURL_CA_BUNDLE)
-  (void) curl_easy_setopt(curl, CURLOPT_CAINFO, (char *) CURL_CA_BUNDLE);
-#elif defined(CURL_CA_PATH)
-  (void) curl_easy_setopt(curl, CURLOPT_CAPATH, (char *) CURL_CA_PATH);
-#endif
-
-  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 */
+  data->state.current_speed = -1; /* init to negative == impossible */
 }
 
 /*
index 24d1434..0145d49 100644 (file)
--- 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) {
index 8ca70a8..2c60507 100644 (file)
--- a/lib/url.h
+++ b/lib/url.h
@@ -30,6 +30,7 @@
  */
 
 CURLcode Curl_open(struct SessionHandle **curl);
+CURLcode Curl_init_userdefined(struct UserDefined *set);
 CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
                      va_list arg);
 CURLcode Curl_dupset(struct SessionHandle * dst, struct SessionHandle * src);