Changeset 0fd8559 for lib/ssl_gnutls.c


Ignore:
Timestamp:
2007-02-18T17:48:04Z (17 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
0f4c1bb5
Parents:
8de63c3 (diff), c7d0f41 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merging new Jabber module. See the massive changelog for all the cool
improvements. :-)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/ssl_gnutls.c

    r8de63c3 r0fd8559  
    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                g_free( conn );
     111                return FALSE;
    66112        }
    67113       
     
    77123        gnutls_set_default_priority( conn->session );
    78124        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         }
    100125       
    101126        sock_make_nonblocking( conn->fd );
Note: See TracChangeset for help on using the changeset viewer.