changeset 7862:01e6e9c46a01

[gaim-migrate @ 8516] " Patch 1: sslconn.patch Fixes a buglet where ssl_init() would not actually init the loaded SSL plugin until the second time it was called." --Bill Tompkins (obobo) committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Sun, 14 Dec 2003 16:35:35 +0000
parents 271ef14bc97d
children 6ee2fe9bb74e
files plugins/ssl/ssl-gnutls.c plugins/ssl/ssl-nss.c
diffstat 2 files changed, 44 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/ssl/ssl-gnutls.c	Sun Dec 14 16:23:53 2003 +0000
+++ b/plugins/ssl/ssl-gnutls.c	Sun Dec 14 16:35:35 2003 +0000
@@ -40,16 +40,20 @@
 
 static gnutls_certificate_client_credentials xcred;
 
-static gboolean
-ssl_gnutls_init(void)
+static void
+ssl_gnutls_init_gnutls(void)
 {
 	gnutls_global_init();
 
 	gnutls_certificate_allocate_credentials(&xcred);
 	gnutls_certificate_set_x509_trust_file(xcred, "ca.pem",
 										   GNUTLS_X509_FMT_PEM);
+}
 
-	return TRUE;
+static gboolean
+ssl_gnutls_init(void)
+{
+   return TRUE;
 }
 
 static void
@@ -177,8 +181,12 @@
 plugin_load(GaimPlugin *plugin)
 {
 #ifdef HAVE_GNUTLS
-	gaim_ssl_set_ops(&ssl_ops);
+	if (!gaim_ssl_get_ops()) {
+		gaim_ssl_set_ops(&ssl_ops);
+	}
 
+   /* Init GNUTLS now so others can use it even if sslconn never does */
+   ssl_gnutls_init_gnutls();
 	return TRUE;
 #else
 	return FALSE;
@@ -189,7 +197,9 @@
 plugin_unload(GaimPlugin *plugin)
 {
 #ifdef HAVE_GNUTLS
-	gaim_ssl_set_ops(NULL);
+	if (gaim_ssl_get_ops() == &ssl_ops) {
+		gaim_ssl_set_ops(NULL);
+	}
 #endif
 
 	return TRUE;
--- a/plugins/ssl/ssl-nss.c	Sun Dec 14 16:23:53 2003 +0000
+++ b/plugins/ssl/ssl-nss.c	Sun Dec 14 16:35:35 2003 +0000
@@ -51,6 +51,26 @@
 static const PRIOMethods *_nss_methods = NULL;
 static PRDescIdentity _identity;
 
+static void 
+ssl_nss_init_nss(void)
+{
+	PR_Init(PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1);
+	NSS_NoDB_Init(NULL);
+
+	/* TODO: Fix this so autoconf does the work trying to find this lib. */
+	SECMOD_AddNewModule("Builtins",
+#ifndef _WIN32
+                            LIBDIR "/libnssckbi.so",
+#else
+                            "nssckbi.dll",
+#endif
+                            0, 0);
+	NSS_SetDomesticPolicy();
+
+	_identity = PR_GetUniqueIdentity("Gaim");
+	_nss_methods = PR_GetDefaultIOMethods();
+}
+
 static SECStatus
 ssl_auth_cert(void *arg, PRFileDesc *socket, PRBool checksig,
 			  PRBool is_server)
@@ -122,23 +142,7 @@
 static gboolean
 ssl_nss_init(void)
 {
-	PR_Init(PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1);
-	NSS_NoDB_Init(NULL);
-
-	/* TODO: Fix this so autoconf does the work trying to find this lib. */
-	SECMOD_AddNewModule("Builtins",
-#ifndef _WIN32
-                            LIBDIR "/libnssckbi.so",
-#else
-                            "nssckbi.dll",
-#endif
-                            0, 0);
-	NSS_SetDomesticPolicy();
-
-	_identity = PR_GetUniqueIdentity("Gaim");
-	_nss_methods = PR_GetDefaultIOMethods();
-
-	return TRUE;
+   return TRUE;
 }
 
 static void
@@ -265,8 +269,12 @@
 plugin_load(GaimPlugin *plugin)
 {
 #ifdef HAVE_NSS
-	gaim_ssl_set_ops(&ssl_ops);
+	if (!gaim_ssl_get_ops()) {
+		gaim_ssl_set_ops(&ssl_ops);
+	}
 
+   /* Init NSS now, so others can use it even if sslconn never does */
+   ssl_nss_init_nss();
 	return TRUE;
 #else
 	return FALSE;
@@ -277,7 +285,9 @@
 plugin_unload(GaimPlugin *plugin)
 {
 #ifdef HAVE_NSS
-	gaim_ssl_set_ops(NULL);
+	if (gaim_ssl_get_ops() == &ssl_ops) {
+		gaim_ssl_set_ops(NULL);
+	}
 #endif
 
 	return TRUE;