curl_easy_reset() added. Need testing and docs. I also think we should make
authorDaniel Stenberg <daniel@haxx.se>
Sat, 24 Jul 2004 21:31:01 +0000 (21:31 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 24 Jul 2004 21:31:01 +0000 (21:31 +0000)
the initial setting up the struct should use this single function to avoid
having the initialisation code at two places.

include/curl/easy.h
lib/easy.c

index ba51fc3..f090807 100644 (file)
@@ -1,10 +1,10 @@
 #ifndef __CURL_EASY_H
 #define __CURL_EASY_H
 /***************************************************************************
- *                                  _   _ ____  _     
- *  Project                     ___| | | |  _ \| |    
- *                             / __| | | | |_) | |    
- *                            | (__| |_| |  _ <| |___ 
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
  * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
@@ -12,7 +12,7 @@
  * 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.
@@ -61,6 +61,19 @@ CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...);
  */
 CURL* curl_easy_duphandle(CURL *curl);
 
+/*
+ * NAME curl_easy_reset()
+ *
+ * DESCRIPTION
+ *
+ * Re-initializes a CURL handle to the default values. This puts back the
+ * handle to the same state as it was in when it was just created.
+ *
+ * It does keep: live connections, the Session ID cache, the DNS cache and the
+ * cookies.
+ */
+CURL* curl_easy_duphandle(CURL *curl);
+
 #ifdef  __cplusplus
 }
 #endif
index 8371afb..53bd13b 100644 (file)
@@ -522,3 +522,62 @@ CURL *curl_easy_duphandle(CURL *incurl)
 
   return outcurl;
 }
+
+/*
+ * curl_easy_reset() is an external interface that allows an app to re-
+ * initialize a session handle to the default values.
+ */
+void curl_easy_reset(CURL *curl)
+{
+  struct SessionHandle *data = (struct SessionHandle *)curl;
+
+  /* zero out UserDefined data: */
+  memset(&data->set, 0, sizeof(struct UserDefined));
+
+  /* zero out Progress data: */
+  memset(&data->progress, 0, sizeof(struct Progress));
+
+  /* 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 = (curl_write_callback)fwrite;
+
+  /* use fread as default function to read input */
+  data->set.fread = (curl_read_callback)fread;
+
+  data->set.infilesize = -1; /* we don't know any size */
+
+  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 */
+
+  /* Set the default size of the SSL session ID cache */
+  data->set.ssl.numsessions = 5;
+
+  data->set.proxyport = 1080;
+  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;
+#ifdef CURL_CA_BUNDLE
+  /* This is our prefered CA cert bundle since install time */
+  data->set.ssl.CAfile = (char *)CURL_CA_BUNDLE;
+#endif
+}