Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/ssl_gnutls.c

    rc1ed6527 rdf1694b  
    4949
    5050static gboolean ssl_connected( gpointer data, gint source, b_input_condition cond );
    51 static gboolean ssl_starttls_real( gpointer data, gint source, b_input_condition cond );
    52 static gboolean ssl_handshake( gpointer data, gint source, b_input_condition cond );
    5351
    5452
     
    6563        {
    6664                g_free( conn );
    67                 return NULL;
    68         }
    69        
    70         return conn;
    71 }
    72 
    73 void *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 
    96 static 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 
    103 static 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;
     65                return( NULL );
    11466        }
    11567       
     
    12577        gnutls_set_default_priority( conn->session );
    12678        gnutls_credentials_set( conn->session, GNUTLS_CRD_CERTIFICATE, conn->xcred );
     79       
     80        return( conn );
     81}
     82
     83static gboolean ssl_handshake( gpointer data, gint source, b_input_condition cond );
     84
     85static 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        }
    127100       
    128101        sock_make_nonblocking( conn->fd );
Note: See TracChangeset for help on using the changeset viewer.