diff options
| author | Jelmer Vernooij <jelmer@samba.org> | 2006-03-01 23:48:37 +0100 | 
|---|---|---|
| committer | Jelmer Vernooij <jelmer@samba.org> | 2006-03-01 23:48:37 +0100 | 
| commit | a4dc9f77de03eb46ecabed02dbd1b678319cf11d (patch) | |
| tree | 71a8dfa927ea2ac4bfc30a36b4d9324a51247aeb /protocols/ssl_openssl.c | |
| parent | 8e419cb4f86679636b2d96618e1bec4853636c11 (diff) | |
| parent | 9a1555dc8521f0973347911bcb26d1038259f967 (diff) | |
[merge] Wilmer
Diffstat (limited to 'protocols/ssl_openssl.c')
| -rw-r--r-- | protocols/ssl_openssl.c | 86 | 
1 files changed, 10 insertions, 76 deletions
| diff --git a/protocols/ssl_openssl.c b/protocols/ssl_openssl.c index ae55f3f9..e62f95b9 100644 --- a/protocols/ssl_openssl.c +++ b/protocols/ssl_openssl.c @@ -4,7 +4,7 @@    * Copyright 2002-2004 Wilmer van der Gaast and others                *    \********************************************************************/ -/* SSL module - GnuTLS version                                          */ +/* SSL module - OpenTLS version                                          */  /*    This program is free software; you can redistribute it and/or modify @@ -40,13 +40,11 @@ static gboolean initialized = FALSE;  struct scd  { -	ssl_input_function func; +	SslInputFunction func;  	gpointer data;  	int fd;  	gboolean established; -	int inpa; -	int lasterr;		/* Necessary for SSL_get_error */  	SSL *ssl;  	SSL_CTX *ssl_ctx;  }; @@ -55,7 +53,7 @@ static void ssl_connected( gpointer data, gint source, GaimInputCondition cond ) -void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data ) +void *ssl_connect( char *host, int port, SslInputFunction func, gpointer data )  {  	struct scd *conn = g_new0( struct scd, 1 );  	SSL_METHOD *meth; @@ -94,45 +92,19 @@ void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data  	return( conn );  } -static void ssl_handshake( gpointer data, gint source, GaimInputCondition cond ); -  static void ssl_connected( gpointer data, gint source, GaimInputCondition cond )  {  	struct scd *conn = data;  	if( source == -1 ) -		return ssl_handshake( data, -1, cond ); +		goto ssl_connected_failure; -	/* Make it non-blocking at least during the handshake... */ -	sock_make_nonblocking( conn->fd );  	SSL_set_fd( conn->ssl, conn->fd ); -	return ssl_handshake( data, source, cond ); -}	 - -static void ssl_handshake( gpointer data, gint source, GaimInputCondition cond ) -{ -	struct scd *conn = data; -	int st; -	 -	if( conn->inpa != -1 ) -	{ -		gaim_input_remove( conn->inpa ); -		conn->inpa = -1; -	} -	 -	if( ( st = SSL_connect( conn->ssl ) ) < 0 ) -	{ -		conn->lasterr = SSL_get_error( conn->ssl, st ); -		if( conn->lasterr != SSL_ERROR_WANT_READ && conn->lasterr != SSL_ERROR_WANT_WRITE ) -			goto ssl_connected_failure; -		 -		conn->inpa = gaim_input_add( conn->fd, ssl_getdirection( conn ), ssl_handshake, data ); -		return; -	} +	if( SSL_connect( conn->ssl ) < 0 ) +		goto ssl_connected_failure;  	conn->established = TRUE; -	sock_make_blocking( conn->fd );		/* For now... */  	conn->func( conn->data, conn, cond );  	return; @@ -154,57 +126,24 @@ ssl_connected_failure:  int ssl_read( void *conn, char *buf, int len )  { -	int st; -	  	if( !((struct scd*)conn)->established ) -	{ -		ssl_errno = SSL_NOHANDSHAKE; -		return -1; -	} -	 -	st = SSL_read( ((struct scd*)conn)->ssl, buf, len ); +		return( 0 ); -	ssl_errno = SSL_OK; -	if( st <= 0 ) -	{ -		((struct scd*)conn)->lasterr = SSL_get_error( ((struct scd*)conn)->ssl, st ); -		if( ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_READ || ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_WRITE ) -			ssl_errno = SSL_AGAIN; -	} -	 -	return st; +	return( SSL_read( ((struct scd*)conn)->ssl, buf, len ) );  }  int ssl_write( void *conn, const char *buf, int len )  { -	int st; -	  	if( !((struct scd*)conn)->established ) -	{ -		ssl_errno = SSL_NOHANDSHAKE; -		return -1; -	} -	 -	st = SSL_write( ((struct scd*)conn)->ssl, buf, len ); +		return( 0 ); -	ssl_errno = SSL_OK; -	if( st <= 0 ) -	{ -		((struct scd*)conn)->lasterr = SSL_get_error( ((struct scd*)conn)->ssl, st ); -		if( ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_READ || ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_WRITE ) -			ssl_errno = SSL_AGAIN; -	} -	 -	return st; +	return( SSL_write( ((struct scd*)conn)->ssl, buf, len ) );  }  void ssl_disconnect( void *conn_ )  {  	struct scd *conn = conn_; -	if( conn->inpa != -1 ) -		gaim_input_remove( conn->inpa ); -	  	if( conn->established )  		SSL_shutdown( conn->ssl ); @@ -219,8 +158,3 @@ int ssl_getfd( void *conn )  {  	return( ((struct scd*)conn)->fd );  } - -GaimInputCondition ssl_getdirection( void *conn ) -{ -	return( ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_WRITE ? GAIM_INPUT_WRITE : GAIM_INPUT_READ ); -} | 
