Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/ssl_gnutls.c

    rdf1694b rc1ed6527  
    4949
    5050static gboolean ssl_connected( gpointer data, gint source, b_input_condition cond );
     51static gboolean ssl_starttls_real( gpointer data, gint source, b_input_condition cond );
     52static gboolean ssl_handshake( gpointer data, gint source, b_input_condition cond );
    5153
    5254
     
    6365        {
    6466                g_free( conn );
    65                 return( NULL );
     67                return NULL;
     68        }
     69       
     70        return conn;
     71}
     72
     73void *ssl_starttls( int fd, ssl_input_function func, gpointer data )
     74{
     75        struct scd *conn = g_new0( struct scd, 1 );
     76       
     77        conn->fd = fd;
     78        conn->func = func;
     79        conn->data = data;
     80        conn->inpa = -1;
     81       
     82        /* This function should be called via a (short) timeout instead of
     83           directly from here, because these SSL calls are *supposed* to be
     84           *completely* asynchronous and not ready yet when this function
     85           (or *_connect, for examle) returns. Also, errors are reported via
     86           the callback function, not via this function's return value.
     87           
     88           In short, doing things like this makes the rest of the code a lot
     89           simpler. */
     90       
     91        b_timeout_add( 1, ssl_starttls_real, conn );
     92       
     93        return conn;
     94}
     95
     96static gboolean ssl_starttls_real( gpointer data, gint source, b_input_condition cond )
     97{
     98        struct scd *conn = data;
     99       
     100        return ssl_connected( conn, conn->fd, GAIM_INPUT_WRITE );
     101}
     102
     103static gboolean ssl_connected( gpointer data, gint source, b_input_condition cond )
     104{
     105        struct scd *conn = data;
     106       
     107        if( source == -1 )
     108        {
     109                conn->func( conn->data, NULL, cond );
     110               
     111                g_free( conn );
     112               
     113                return FALSE;
    66114        }
    67115       
     
    77125        gnutls_set_default_priority( conn->session );
    78126        gnutls_credentials_set( conn->session, GNUTLS_CRD_CERTIFICATE, conn->xcred );
    79        
    80         return( conn );
    81 }
    82 
    83 static gboolean ssl_handshake( gpointer data, gint source, b_input_condition cond );
    84 
    85 static gboolean ssl_connected( gpointer data, gint source, b_input_condition cond )
    86 {
    87         struct scd *conn = data;
    88        
    89         if( source == -1 )
    90         {
    91                 conn->func( conn->data, NULL, cond );
    92                
    93                 gnutls_deinit( conn->session );
    94                 gnutls_certificate_free_credentials( conn->xcred );
    95                
    96                 g_free( conn );
    97                
    98                 return FALSE;
    99         }
    100127       
    101128        sock_make_nonblocking( conn->fd );
Note: See TracChangeset for help on using the changeset viewer.