Index: conf.c
===================================================================
--- conf.c	(revision 4146a07de5f44f3ea00a3ef0026098b28e7451de)
+++ conf.c	(revision 643dfc4be2e84dc4acb1a446867705e150480210)
@@ -55,4 +55,5 @@
 	conf->password = NULL;
 	conf->configdir = g_strdup( CONFIG );
+	conf->plugindir = g_strdup( PLUGINDIR );
 	conf->motdfile = g_strdup( ETCDIR "/motd.txt" );
 	conf->ping_interval = 180;
Index: conf.h
===================================================================
--- conf.h	(revision 4146a07de5f44f3ea00a3ef0026098b28e7451de)
+++ conf.h	(revision 643dfc4be2e84dc4acb1a446867705e150480210)
@@ -41,4 +41,5 @@
 	char *hostname;
 	char *configdir;
+	char *plugindir;
 	char *motdfile;
 	char *primary_storage;
Index: configure
===================================================================
--- configure	(revision 4146a07de5f44f3ea00a3ef0026098b28e7451de)
+++ configure	(revision 643dfc4be2e84dc4acb1a446867705e150480210)
@@ -145,8 +145,12 @@
 fi
 
-if type pkg-config > /dev/null 2>/dev/null && pkg-config glib-2.0; then
+if [ -z "$PKG_CONFIG" ]; then
+	PKG_CONFIG=pkg-config
+fi
+
+if $PKG_CONFIG --version > /dev/null 2>/dev/null && $PKG_CONFIG glib-2.0; then
 	cat<<EOF>>Makefile.settings
-EFLAGS+=`pkg-config --libs glib-2.0 gmodule-2.0`
-CFLAGS+=`pkg-config --cflags glib-2.0 gmodule-2.0`
+EFLAGS+=`$PKG_CONFIG --libs glib-2.0 gmodule-2.0`
+CFLAGS+=`$PKG_CONFIG --cflags glib-2.0 gmodule-2.0`
 EOF
 	echo '#define GLIB2' >> config.h
@@ -190,8 +194,8 @@
 detect_nss()
 {
-	if type pkg-config > /dev/null 2>/dev/null && pkg-config mozilla-nss; then
+	if $PKG_CONFIG --version > /dev/null 2>/dev/null && $PKG_CONFIG mozilla-nss; then
 		cat<<EOF>>Makefile.settings
-EFLAGS+=`pkg-config --libs mozilla-nss`
-CFLAGS+=`pkg-config --cflags mozilla-nss`
+EFLAGS+=`$PKG_CONFIG --libs mozilla-nss`
+CFLAGS+=`$PKG_CONFIG --cflags mozilla-nss`
 EOF
 		
Index: protocols/nogaim.c
===================================================================
--- protocols/nogaim.c	(revision 4146a07de5f44f3ea00a3ef0026098b28e7451de)
+++ protocols/nogaim.c	(revision 643dfc4be2e84dc4acb1a446867705e150480210)
@@ -82,5 +82,5 @@
 	GError *error = NULL;
 
-	dir = g_dir_open(PLUGINDIR, 0, &error);
+	dir = g_dir_open(global.conf->plugindir, 0, &error);
 
 	if (dir) {
@@ -89,5 +89,5 @@
 
 		while ((entry = g_dir_read_name(dir))) {
-			path = g_build_filename(PLUGINDIR, entry, NULL);
+			path = g_build_filename(global.conf->plugindir, entry, NULL);
 			if(!path) {
 				log_message(LOGLVL_WARNING, "Can't build path for %s\n", entry);
Index: protocols/oscar/conn.c
===================================================================
--- protocols/oscar/conn.c	(revision 4146a07de5f44f3ea00a3ef0026098b28e7451de)
+++ protocols/oscar/conn.c	(revision 643dfc4be2e84dc4acb1a446867705e150480210)
@@ -627,7 +627,5 @@
 	}
 
-#ifndef _WIN32
-	fcntl(conn->fd, F_SETFL, 0); /* XXX should restore original flags */
-#endif
+	sock_make_blocking(conn->fd);
 
 	conn->status &= ~AIM_CONN_STATUS_INPROGRESS;
Index: protocols/proxy.c
===================================================================
--- protocols/proxy.c	(revision 4146a07de5f44f3ea00a3ef0026098b28e7451de)
+++ protocols/proxy.c	(revision 643dfc4be2e84dc4acb1a446867705e150480210)
@@ -133,6 +133,6 @@
 		return;
 	}
-	fcntl(source, F_SETFL, 0);
 #endif
+	sock_make_blocking(source);
 	gaim_input_remove(phb->inpa);
 	if( phb->proxy_func )
@@ -229,7 +229,5 @@
 		return;
 	}
-#ifdef F_SETFL
-	fcntl(source, F_SETFL, 0);
-#endif
+	sock_make_blocking(source);
 
 	g_snprintf(cmd, sizeof(cmd), "CONNECT %s:%d HTTP/1.1\r\nHost: %s:%d\r\n", phb->host, phb->port,
@@ -322,7 +320,5 @@
 		return;
 	}
-#ifdef F_SETFL
-	fcntl(source, F_SETFL, 0);
-#endif
+	sock_make_blocking(source);
 
 	/* XXX does socks4 not support host name lookups by the proxy? */
@@ -509,7 +505,5 @@
 		return;
 	}
-#ifdef F_SETFL
-	fcntl(source, F_SETFL, 0);
-#endif
+	sock_make_blocking(source);
 
 	i = 0;
Index: protocols/ssl_bogus.c
===================================================================
--- protocols/ssl_bogus.c	(revision 4146a07de5f44f3ea00a3ef0026098b28e7451de)
+++ protocols/ssl_bogus.c	(revision 643dfc4be2e84dc4acb1a446867705e150480210)
@@ -26,4 +26,6 @@
 #include "ssl_client.h"
 
+int ssl_errno;
+
 void *ssl_connect( char *host, int port, SslInputFunction func, gpointer data )
 {
Index: protocols/ssl_client.h
===================================================================
--- protocols/ssl_client.h	(revision 4146a07de5f44f3ea00a3ef0026098b28e7451de)
+++ protocols/ssl_client.h	(revision 643dfc4be2e84dc4acb1a446867705e150480210)
@@ -27,4 +27,10 @@
 #include "proxy.h"
 
+#define SSL_OK            0
+#define SSL_NOHANDSHAKE   1
+#define SSL_AGAIN         2
+
+extern int ssl_errno;
+
 typedef void (*SslInputFunction)(gpointer, void*, GaimInputCondition);
 
Index: protocols/ssl_gnutls.c
===================================================================
--- protocols/ssl_gnutls.c	(revision 4146a07de5f44f3ea00a3ef0026098b28e7451de)
+++ protocols/ssl_gnutls.c	(revision 643dfc4be2e84dc4acb1a446867705e150480210)
@@ -25,8 +25,12 @@
 
 #include <gnutls/gnutls.h>
+#include <fcntl.h>
+#include <unistd.h>
 #include "proxy.h"
 #include "ssl_client.h"
 #include "sock.h"
 #include "stdlib.h"
+
+int ssl_errno = 0;
 
 static gboolean initialized = FALSE;
@@ -38,4 +42,5 @@
 	int fd;
 	gboolean established;
+	int inpa;
 	
 	gnutls_session session;
@@ -44,5 +49,4 @@
 
 static void ssl_connected( gpointer data, gint source, GaimInputCondition cond );
-
 
 
@@ -54,4 +58,5 @@
 	conn->func = func;
 	conn->data = data;
+	conn->inpa = -1;
 	
 	if( conn->fd < 0 )
@@ -76,4 +81,6 @@
 }
 
+static void ssl_handshake( gpointer data, gint source, GaimInputCondition cond );
+
 static void ssl_connected( gpointer data, gint source, GaimInputCondition cond )
 {
@@ -81,22 +88,57 @@
 	
 	if( source == -1 )
-		goto ssl_connected_failure;
+	{
+		conn->func( conn->data, NULL, cond );
+		
+		gnutls_deinit( conn->session );
+		gnutls_certificate_free_credentials( conn->xcred );
+		
+		g_free( conn );
+		
+		return;
+	}
 	
+	sock_make_nonblocking( conn->fd );
 	gnutls_transport_set_ptr( conn->session, (gnutls_transport_ptr) conn->fd );
 	
-	if( gnutls_handshake( conn->session ) < 0 )
-		goto ssl_connected_failure;
+	ssl_handshake( data, source, cond );
+}
+
+static void ssl_handshake( gpointer data, gint source, GaimInputCondition cond )
+{
+	struct scd *conn = data;
+	int st;
 	
-	conn->established = TRUE;
-	conn->func( conn->data, conn, cond );
-	return;
+	if( conn->inpa != -1 )
+		gaim_input_remove( conn->inpa );
 	
-ssl_connected_failure:
-	conn->func( conn->data, NULL, cond );
-	
-	gnutls_deinit( conn->session );
-	gnutls_certificate_free_credentials( conn->xcred );
-	if( source >= 0 ) closesocket( source );
-	g_free( conn );
+	if( ( st = gnutls_handshake( conn->session ) ) < 0 )
+	{
+		if( st == GNUTLS_E_AGAIN || st == GNUTLS_E_INTERRUPTED )
+		{
+			conn->inpa = gaim_input_add( conn->fd,
+			                             gnutls_record_get_direction( conn->session ) ?
+			                                 GAIM_INPUT_WRITE : GAIM_INPUT_READ,
+			                             ssl_handshake, data );
+		}
+		else
+		{
+			conn->func( conn->data, NULL, cond );
+			
+			gnutls_deinit( conn->session );
+			gnutls_certificate_free_credentials( conn->xcred );
+			closesocket( conn->fd );
+			
+			g_free( conn );
+		}
+	}
+	else
+	{
+		/* For now we can't handle non-blocking perfectly everywhere... */
+		sock_make_blocking( conn->fd );
+		
+		conn->established = TRUE;
+		conn->func( conn->data, conn, cond );
+	}
 }
 
@@ -104,7 +146,11 @@
 {
 	if( !((struct scd*)conn)->established )
-		return( 0 );
+	{
+		ssl_errno = SSL_NOHANDSHAKE;
+		return( -1 );
+	}
 	
 	return( gnutls_record_recv( ((struct scd*)conn)->session, buf, len ) );
+	
 }
 
@@ -112,5 +158,8 @@
 {
 	if( !((struct scd*)conn)->established )
-		return( 0 );
+	{
+		ssl_errno = SSL_NOHANDSHAKE;
+		return( -1 );
+	}
 	
 	return( gnutls_record_send( ((struct scd*)conn)->session, buf, len ) );
Index: protocols/ssl_nss.c
===================================================================
--- protocols/ssl_nss.c	(revision 4146a07de5f44f3ea00a3ef0026098b28e7451de)
+++ protocols/ssl_nss.c	(revision 643dfc4be2e84dc4acb1a446867705e150480210)
@@ -38,4 +38,6 @@
 #include <secerr.h>
 #include <sslerr.h>
+
+int ssl_errno = 0;
 
 static gboolean initialized = FALSE;
Index: protocols/ssl_openssl.c
===================================================================
--- protocols/ssl_openssl.c	(revision 4146a07de5f44f3ea00a3ef0026098b28e7451de)
+++ protocols/ssl_openssl.c	(revision 643dfc4be2e84dc4acb1a446867705e150480210)
@@ -34,4 +34,6 @@
 #include "ssl_client.h"
 #include "sock.h"
+
+int ssl_errno = 0;
 
 static gboolean initialized = FALSE;
Index: sock.h
===================================================================
--- sock.h	(revision 4146a07de5f44f3ea00a3ef0026098b28e7451de)
+++ sock.h	(revision 643dfc4be2e84dc4acb1a446867705e150480210)
@@ -6,4 +6,5 @@
 #include <netdb.h>
 #define sock_make_nonblocking(fd) fcntl(fd, F_SETFL, O_NONBLOCK)
+#define sock_make_blocking(fd) fcntl(fd, F_SETFL, 0)
 #define sockerr_again() (errno == EINPROGRESS || errno == EINTR)
 #define closesocket(a) close(a)
@@ -17,4 +18,5 @@
 # define write(a,b,c) send(a,b,c,0)
 # define sock_make_nonblocking(fd) { int non_block = 1; ioctlsocket(fd, FIONBIO, &non_block); }
+# define sock_make_blocking(fd) { int non_block = 0; ioctlsocket(fd, FIONBIO, &non_block); }
 # define sockerr_again() (WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEINPROGRESS || WSAGetLastError() == WSAEWOULDBLOCK)
 # define ETIMEDOUT WSAETIMEDOUT
Index: storage_text.c
===================================================================
--- storage_text.c	(revision 4146a07de5f44f3ea00a3ef0026098b28e7451de)
+++ storage_text.c	(revision 643dfc4be2e84dc4acb1a446867705e150480210)
@@ -42,5 +42,5 @@
 {
 	switch (id) {
-	case 1: return find_protocol("oscar");
+	case 0: case 1: case 3: return find_protocol("oscar");
 	case 4: return find_protocol("msn");
 	case 2: return find_protocol("yahoo");
