]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
Add win32 initialization support to curl_global_init() and
authorSterling Hughes <sterling@bumblebury.com>
Thu, 12 Jul 2001 01:57:28 +0000 (01:57 +0000)
committerSterling Hughes <sterling@bumblebury.com>
Thu, 12 Jul 2001 01:57:28 +0000 (01:57 +0000)
curl_global_cleanup().  Update corresponding man pages...

Improve the logic in curl_global_cleanup() and curl_global_init() so that
they are not called twice if the application libraries have been
initialized and make sure to reset the init flags in curl_global_cleanup().

docs/TODO
docs/curl_global_init.3
include/curl/curl.h
lib/easy.c
src/main.c

index ff0a48808dee43595b9fcf49edf772c887062e8f..59bfbf61f2a6b936ce3a6f0b149f911c1baf0db9 100644 (file)
--- a/docs/TODO
+++ b/docs/TODO
@@ -20,11 +20,6 @@ To do in a future release (random order):
  * Consider an interface to libcurl that allows applications to easier get to
    know what cookies that are sent back in the response headers.
 
- * The win32_init() and win32_cleanup() functions that are present in
-   src/main.c (and docs/examples/win32sockets.c) would probably be fine to
-   add to curl_global_init() and performed if the correct flag is set. Makes
-   it easier for windows people.
-
  * Make SSL session ids get used if multiple HTTPS documents from the same
    host is requested. http://curl.haxx.se/dev/SSL_session_id.txt
 
index be6aeaa297057b60854a94ee2bf60db80ac2ef77..8842a94525c31fe7d2f736601108082e10f3db04 100644 (file)
@@ -27,10 +27,13 @@ This function was added in libcurl 7.8.
 .SH FLAGS
 .TP 5
 .B CURL_GLOBAL_ALL
-Initialise everyting possible. This sets all known bits.
+Initialize everyting possible. This sets all known bits.
 .TP
 .B CURL_GLOBAL_SSL
-Initialise SSL
+Initialize SSL
+.TP
+.B CURL_GLOBAL_WIN32
+Initialize the Win32 socket libraries.
 .TP
 .B CURL_GLOBAL_NOTHING
 Initialise nothing extra. This sets no bit.
index 464388f57030de3df46d7abbddeab0b973437162..e50c73e8cee01aba80ccfe23bd155846eab880d2 100644 (file)
@@ -575,7 +575,8 @@ typedef enum {
 } curl_closepolicy;
 
 #define CURL_GLOBAL_SSL (1<<0)
-#define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL)
+#define CURL_GLOBAL_WIN32 (1<<1)
+#define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32)
 #define CURL_GLOBAL_NOTHING 0
 #define CURL_GLOBAL_DEFAULT CURL_GLOBAL_ALL
 
index 0099d6be11c33802a32f0872a442d53ffb4034ad..876b4935eab853e0446aaa9720021da5d7506407 100644 (file)
 #define _MPRINTF_REPLACE /* use our functions only */
 #include <curl/mprintf.h>
 
-/* true globals */
+
+/* Silly win32 socket initialization functions */
+
+#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
+static void win32_cleanup(void)
+{
+  WSACleanup();
+}
+
+static CURLcode win32_init(void)
+{
+  WORD wVersionRequested;  
+  WSADATA wsaData; 
+  int err; 
+  wVersionRequested = MAKEWORD(1, 1); 
+    
+  err = WSAStartup(wVersionRequested, &wsaData); 
+    
+  if (err != 0) 
+    /* Tell the user that we couldn't find a useable */ 
+    /* winsock.dll.     */ 
+    return CURLE_FAILED_INIT; 
+    
+  /* Confirm that the Windows Sockets DLL supports 1.1.*/ 
+  /* Note that if the DLL supports versions greater */ 
+  /* than 1.1 in addition to 1.1, it will still return */ 
+  /* 1.1 in wVersion since that is the version we */ 
+  /* requested. */ 
+    
+  if ( LOBYTE( wsaData.wVersion ) != 1 || 
+       HIBYTE( wsaData.wVersion ) != 1 ) { 
+    /* Tell the user that we couldn't find a useable */ 
+
+    /* winsock.dll. */ 
+    WSACleanup(); 
+    return CURLE_FAILED_INIT; 
+  }
+  return CURLE_OK;
+}
+/* The Windows Sockets DLL is acceptable. Proceed. */ 
+#else
+static CURLcode win32_init(void) { return CURLE_OK; }
+#define win32_cleanup()
+#endif
+
+
+/* true globals -- for curl_global_init() and curl_global_cleanup() */
 static unsigned int  initialized = 0;
 static long          init_flags  = 0;
 
+/**
+ * Globally initializes cURL given a bitwise set of 
+ * the different features to initialize.
+ */
 CURLcode curl_global_init(long flags)
 {
-  if(flags & CURL_GLOBAL_SSL)
+  if (initialized)
+    return CURLE_OK;
+  if (flags & CURL_GLOBAL_SSL)
     Curl_SSL_init();
 
+  if (flags & CURL_GLOBAL_WIN32)
+    if (win32_init() != CURLE_OK)
+      return CURLE_FAILED_INIT;
+
   initialized = 1;
   init_flags  = flags;
   
   return CURLE_OK;
 }
 
+/**
+ * Globally cleanup cURL, uses the value of "init_flags" to determine
+ * what needs to be cleaned up and what doesn't
+ */
 void curl_global_cleanup(void)
 {
+  if (!initialized)
+    return;
+
   if (init_flags & CURL_GLOBAL_SSL)
     Curl_SSL_cleanup();
 
+  if (init_flags & CURL_GLOBAL_WIN32)
+    win32_cleanup();
+
   initialized = 0;
+  init_flags  = 0;
 }
 
 CURL *curl_easy_init(void)
index 125222db518088bb2f0db20a0410ed80df17dacb..9f83a855b6326b814a6f05118fadfd6b93fea619 100644 (file)
@@ -126,52 +126,6 @@ char *strdup(char *str)
 
 extern void hugehelp(void);
 
-/***********************************************************************
- * Start with some silly functions to make win32-systems survive
- ***********************************************************************/
-#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
-static void win32_cleanup(void)
-{
-  WSACleanup();
-}
-
-static CURLcode win32_init(void)
-{
-  WORD wVersionRequested;  
-  WSADATA wsaData; 
-  int err; 
-  wVersionRequested = MAKEWORD(1, 1); 
-    
-  err = WSAStartup(wVersionRequested, &wsaData); 
-    
-  if (err != 0) 
-    /* Tell the user that we couldn't find a useable */ 
-    /* winsock.dll.     */ 
-    return CURLE_FAILED_INIT; 
-    
-  /* Confirm that the Windows Sockets DLL supports 1.1.*/ 
-  /* Note that if the DLL supports versions greater */ 
-  /* than 1.1 in addition to 1.1, it will still return */ 
-  /* 1.1 in wVersion since that is the version we */ 
-  /* requested. */ 
-    
-  if ( LOBYTE( wsaData.wVersion ) != 1 || 
-       HIBYTE( wsaData.wVersion ) != 1 ) { 
-    /* Tell the user that we couldn't find a useable */ 
-
-    /* winsock.dll. */ 
-    WSACleanup(); 
-    return CURLE_FAILED_INIT; 
-  }
-  return CURLE_OK;
-}
-/* The Windows Sockets DLL is acceptable. Proceed. */ 
-#else
-static CURLcode win32_init(void) { return CURLE_OK; }
-#define win32_cleanup()
-#endif
-
-
 /*
  * This is the main global constructor for the app. Call this before
  * _any_ libcurl usage. If this fails, *NO* libcurl functions may be
@@ -179,8 +133,7 @@ static CURLcode win32_init(void) { return CURLE_OK; }
  */
 CURLcode main_init(void)
 {
-  curl_global_init(CURL_GLOBAL_DEFAULT);
-  return win32_init();
+  return curl_global_init(CURL_GLOBAL_DEFAULT);
 }
 
 /*
@@ -189,7 +142,6 @@ CURLcode main_init(void)
  */
 void main_free(void)
 {
-  win32_cleanup();
   curl_global_cleanup();
 }