diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2005-12-17 21:56:50 +0100 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2005-12-17 21:56:50 +0100 |
commit | 7c0a4975a538ab75405e64919bbdfee51b898b2e (patch) | |
tree | 47d211522bbed3fda3b33b0233e91e3cf5cb9e23 /protocols/ssl_gnutls.c | |
parent | b5a22e33a1aa2500093e783e79de2f44bf53c150 (diff) | |
parent | ad8b8a367c8e5dd2816096959682e2187df07c6c (diff) |
Moved HTTP-stuff (right now only for passport) into a separate module. This
all works 100% asynchronous and non-blocking, so almost all I/O in BitlBee
should be completely non-blocking now!
Right now support for other modules than GnuTLS is probably broken, I'll fix
it later.
Diffstat (limited to 'protocols/ssl_gnutls.c')
-rw-r--r-- | protocols/ssl_gnutls.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/protocols/ssl_gnutls.c b/protocols/ssl_gnutls.c index c2eb6906..2e307aab 100644 --- a/protocols/ssl_gnutls.c +++ b/protocols/ssl_gnutls.c @@ -37,7 +37,7 @@ static gboolean initialized = FALSE; struct scd { - SslInputFunction func; + ssl_input_function func; gpointer data; int fd; gboolean established; @@ -50,7 +50,7 @@ struct scd static void ssl_connected( gpointer data, gint source, GaimInputCondition cond ); -void *ssl_connect( char *host, int port, SslInputFunction func, gpointer data ) +void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data ) { struct scd *conn = g_new0( struct scd, 1 ); @@ -116,9 +116,7 @@ static void ssl_handshake( gpointer data, gint source, GaimInputCondition cond ) { 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, + conn->inpa = gaim_input_add( conn->fd, ssl_getdirection( conn ), ssl_handshake, data ); } else @@ -144,25 +142,40 @@ static void ssl_handshake( gpointer data, gint source, GaimInputCondition cond ) int ssl_read( void *conn, char *buf, int len ) { + int st; + if( !((struct scd*)conn)->established ) { ssl_errno = SSL_NOHANDSHAKE; return( -1 ); } - return( gnutls_record_recv( ((struct scd*)conn)->session, buf, len ) ); + st = gnutls_record_recv( ((struct scd*)conn)->session, buf, len ); + + ssl_errno = SSL_OK; + if( st == GNUTLS_E_AGAIN || st == GNUTLS_E_INTERRUPTED ) + ssl_errno = SSL_AGAIN; + return st; } int ssl_write( void *conn, const char *buf, int len ) { + int st; + if( !((struct scd*)conn)->established ) { ssl_errno = SSL_NOHANDSHAKE; return( -1 ); } - return( gnutls_record_send( ((struct scd*)conn)->session, buf, len ) ); + st = gnutls_record_send( ((struct scd*)conn)->session, buf, len ); + + ssl_errno = SSL_OK; + if( st == GNUTLS_E_AGAIN || st == GNUTLS_E_INTERRUPTED ) + ssl_errno = SSL_AGAIN; + + return st; } void ssl_disconnect( void *conn_ ) @@ -183,3 +196,9 @@ int ssl_getfd( void *conn ) { return( ((struct scd*)conn)->fd ); } + +GaimInputCondition ssl_getdirection( void *conn ) +{ + return( gnutls_record_get_direction( ((struct scd*)conn)->session ) ? + GAIM_INPUT_WRITE : GAIM_INPUT_READ ); +} |