summaryrefslogtreecommitdiff
path: root/chat/bitlbee/patches/patch-ad
blob: b5c532a8b67c5e1b8c11002d0a15d1631f3e3a1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Fix stalling issue with OpenSSL and Jabber
From http://bugs.bitlbee.org/bitlbee/changeset/devel%2C359

$NetBSD: patch-ad,v 1.1 2008/04/20 09:29:45 tonio Exp $

--- lib/ssl_openssl.c.orig	Sat Jun 30 23:18:42 2007
+++ lib/ssl_openssl.c
@@ -61,16 +61,16 @@ void *ssl_connect( char *host, int port,
 	struct scd *conn = g_new0( struct scd, 1 );
 	
 	conn->fd = proxy_connect( host, port, ssl_connected, conn );
-	conn->func = func;
-	conn->data = data;
-	conn->inpa = -1;
-	
 	if( conn->fd < 0 )
 	{
 		g_free( conn );
 		return NULL;
 	}
 	
+	conn->func = func;
+	conn->data = data;
+	conn->inpa = -1;
+	
 	return conn;
 }
 
@@ -228,6 +228,21 @@ int ssl_write( void *conn, const char *b
 	}
 	
 	return st;
+}
+
+/* Only OpenSSL *really* needs this (and well, maybe NSS). See for more info:
+   http://www.gnu.org/software/gnutls/manual/gnutls.html#index-gnutls_005frecord_005fcheck_005fpending-209
+   http://www.openssl.org/docs/ssl/SSL_pending.html
+   
+   Required because OpenSSL empties the TCP buffer completely but doesn't
+   necessarily give us all the unencrypted data.
+   
+   Returns 0 if there's nothing left or if we don't have to care (GnuTLS),
+   1 if there's more data. */
+int ssl_pending( void *conn )
+{
+	return ( ((struct scd*)conn) && ((struct scd*)conn)->established ) ?
+	       SSL_pending( ((struct scd*)conn)->ssl ) > 0 : 0;
 }
 
 void ssl_disconnect( void *conn_ )