diff options
author | Søren Sandmann <sandmann@redhat.com> | 2007-07-30 04:23:39 -0400 |
---|---|---|
committer | Søren Sandmann <sandmann@redhat.com> | 2007-07-30 04:23:39 -0400 |
commit | 0c87c11dd40692a3d9edff224ac8b2b5f482e01a (patch) | |
tree | ebde609034cdadc90ad225b6c2d376156f9d9cd8 /src | |
parent | 35979ec9e6e95570517fcebb58007c5ec26b76eb (diff) |
Better handshaking
Diffstat (limited to 'src')
-rw-r--r-- | src/lactlsconnection.c | 69 |
1 files changed, 59 insertions, 10 deletions
diff --git a/src/lactlsconnection.c b/src/lactlsconnection.c index 983e925..45cf7fd 100644 --- a/src/lactlsconnection.c +++ b/src/lactlsconnection.c @@ -54,6 +54,45 @@ emit_error (LacTlsConnection *tls, } static void +do_handshake (LacTlsConnection *tls) +{ + if (!tls->need_handshake) + return; + + g_print ("handshaking\n"); + + int res = gnutls_handshake (tls->session); + + if (res == 0) + { + g_print (" handshake complete\n"); + + tls->need_handshake = FALSE; + /* FIXME: emit handshake event */ + } + else if (res < 0) + { + if (res != GNUTLS_E_INTERRUPTED && + res != GNUTLS_E_AGAIN) + { + g_print (" handshake error\n"); + /* FIXME: emit an error */ + lac_connection_close (tls->tcp_connection); + return; + } + else + { + g_print (" insufficient data\n"); + return; + } + } + else + { + g_print (" positive return code?\n"); + } +} + +static void do_writes (LacTlsConnection *connection) { gsize n_available; @@ -61,6 +100,9 @@ do_writes (LacTlsConnection *connection) gsize n_written; GError *err = NULL; + if (!lac_connection_is_connected (connection->tcp_connection)) + return; + if (connection->need_handshake) return; @@ -100,28 +142,28 @@ tcp_callback (LacConnection *connection, switch (event->type) { - case LAC_CONNECTION_EVENT_CONNECT: case LAC_CONNECTION_EVENT_CLOSE: case LAC_CONNECTION_EVENT_ERROR: + g_print ("SOMETHING HAPPENED \n"); tls->callback (tls, event); break; + case LAC_CONNECTION_EVENT_CONNECT: + do_handshake (tls); + g_print ("CONNECT HAPPENED\n"); + tls->callback (tls, event); + do_writes (tls); + break; + case LAC_CONNECTION_EVENT_READ: + g_print ("READ HAPPENED \n"); /* add data to buffer */ lac_byte_queue_append (tls->buffer, event->read.data, event->read.len); - if (tls->need_handshake) - { - if (gnutls_handshake (tls->session) == 0) - { - tls->need_handshake = FALSE; - /* FIXME: emit handshake event */ - } - } - /* Writing sometimes requires data to be available for reading * from the TCP connection */ + do_handshake (tls); do_writes (tls); if (!tls->need_handshake) @@ -188,6 +230,8 @@ tls_push (gnutls_transport_ptr_t tptr, { LacTlsConnection *tls = (LacTlsConnection *)tptr; + g_print ("pushing some data\n"); + lac_connection_write (tls->tcp_connection, data, n_bytes); return n_bytes; @@ -202,6 +246,8 @@ tls_pull (gnutls_transport_ptr_t tptr, const gchar *buf; gsize n_available; + g_print ("pulling data\n"); + buf = lac_byte_queue_peek (tls->buffer, &n_available); if (n_available > 0) @@ -216,6 +262,7 @@ tls_pull (gnutls_transport_ptr_t tptr, } else { + g_print (" nothing available\n"); errno = EAGAIN; return -1; @@ -261,6 +308,8 @@ lac_tls_connection_write (LacTlsConnection *tls, { lac_byte_queue_append (tls->unwritten, data, len); + g_print (" USER writes\n"); + do_writes (tls); } |