diff options
author | Søren Sandmann <sandmann@redhat.com> | 2007-07-31 00:42:08 -0400 |
---|---|---|
committer | Søren Sandmann <sandmann@redhat.com> | 2007-07-31 00:42:08 -0400 |
commit | f393c0608ace0eb825172bbe368e822055bcd705 (patch) | |
tree | d2eed9d97ca47832739ecfc1d7acc22bc5d3c0ef /src | |
parent | b1b890eeec82439d7355773314150e3e6e030fbe (diff) |
Various stuff
Diffstat (limited to 'src')
-rw-r--r-- | src/lactlsconnection.c | 69 |
1 files changed, 62 insertions, 7 deletions
diff --git a/src/lactlsconnection.c b/src/lactlsconnection.c index 5819764..88f233e 100644 --- a/src/lactlsconnection.c +++ b/src/lactlsconnection.c @@ -26,18 +26,22 @@ struct _LacTlsConnection { - LacConnection * tcp_connection; - LacTlsConnectionFunc callback; - gpointer data; + LacConnection * tcp_connection; + LacTlsConnectionFunc callback; + gpointer data; - LacByteQueue * buffer; - LacByteQueue * unwritten; + LacByteQueue * buffer; + LacByteQueue * unwritten; gnutls_anon_client_credentials_t anoncred; gnutls_certificate_credentials_t xcred; gnutls_session_t session; - gboolean need_handshake; + gboolean need_handshake; + + int ref_count; + + gboolean write_shutdown; }; static void @@ -230,6 +234,9 @@ tcp_callback (LacConnection *connection, switch (event->type) { case LAC_CONNECTION_EVENT_CLOSE: + gnutls_deinit (tls->session); + /* fall thru */ + case LAC_CONNECTION_EVENT_ERROR: tls->callback (tls, event); break; @@ -304,9 +311,9 @@ lac_tls_connection_new (const LacAddress *address, tls->data = data; tls->buffer = lac_byte_queue_new (); tls->unwritten = lac_byte_queue_new (); + tls->write_shutdown = FALSE; gnutls_global_init (); - gnutls_anon_allocate_client_credentials (&tls->anoncred); /* sets the trusted cas file */ @@ -329,6 +336,23 @@ lac_tls_connection_new (const LacAddress *address, return tls; } +LacTlsConnection * +lac_tls_connection_ref (LacTlsConnection *connection) +{ + connection->ref_count++; + + return connection; +} + +void +lac_tls_connection_unref (LacTlsConnection *connection) +{ + if (--connection->ref_count == 0) + { + gnutls_certificate_free_credentials (connection->xcred); + } +} + void lac_tls_connection_write (LacTlsConnection *tls, const gchar *data, @@ -339,6 +363,37 @@ lac_tls_connection_write (LacTlsConnection *tls, do_writes (tls); } +void +lac_tls_connection_write_cstr (LacTlsConnection *connection, + const gchar *data) +{ + guint len; + + g_return_if_fail (connection != NULL); + g_return_if_fail (data != NULL); + g_return_if_fail (!connection->write_shutdown); + + len = strlen (data); + + if (len > 0) + lac_tls_connection_write (connection, data, len); +} + +void +lac_tls_connection_shutdown_write (LacTlsConnection *connection) +{ + /* FIXME: do we really need this? */ + connection->write_shutdown = TRUE; + + lac_connection_shutdown_write (connection->tcp_connection); +} + +G_CONST_RETURN LacAddress *lac_tls_connection_get_address (LacTlsConnection *connection); +gint lac_tls_connection_get_port (LacTlsConnection *connection); +void lac_tls_connection_close (LacTlsConnection *connection); +gboolean lac_tls_connection_is_connected (LacTlsConnection *connection); +void lac_tls_connection_flush (LacTlsConnection *connection); + gpointer lac_tls_connection_get_data (LacTlsConnection *tls) |