diff options
author | Søren Sandmann <sandmann@redhat.com> | 2007-07-30 02:14:54 -0400 |
---|---|---|
committer | Søren Sandmann <sandmann@redhat.com> | 2007-07-30 02:14:54 -0400 |
commit | ce041173ae98ce6c3b2e2f149d6974c4f0046277 (patch) | |
tree | 591075c2398cec2d117a12036639992640d1cab5 | |
parent | cd28b76a9837d9e8818cb24358773ff085886509 (diff) |
Initial LacTlsConnection implementation
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/lac.h | 27 | ||||
-rw-r--r-- | src/lactlsconnection.c | 91 |
3 files changed, 119 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 3307a06..d6ab701 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -20,6 +20,7 @@ liblac_1_la_SOURCES = \ lacdns-nameserver.c \ lacuri.c \ lacconnection.c \ + lactlsconnection.c \ lachttp.c \ \ lacinternals.h \ @@ -329,6 +329,33 @@ void lac_connection_flush (LacConnection *con /* + * LacTlsConnection + */ +typedef struct _LacTlsConnection LacTlsConnection; + +typedef void (* LacTlsConnectionFunc) (LacTlsConnection *connection, + const LacConnectionEvent *event); + +LacTlsConnection * lac_tls_connection_new (const LacAddress *address, + gint port, + LacTlsConnectionFunc callback, + gpointer data); +gpointer lac_tls_connection_get_data (LacTlsConnection *connection); +void lac_tls_connection_write (LacTlsConnection *connection, + const gchar *data, + guint len); +void lac_tls_connection_write_cstr (LacTlsConnection *connection, + const gchar *data); +void lac_tls_connection_shutdown_write (LacTlsConnection *connection); +LacTlsConnection * lac_tls_connection_ref (LacTlsConnection *connection); +void lac_tls_connection_unref (LacTlsConnection *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); + +/* * URI */ typedef enum { diff --git a/src/lactlsconnection.c b/src/lactlsconnection.c new file mode 100644 index 0000000..fb1f5a7 --- /dev/null +++ b/src/lactlsconnection.c @@ -0,0 +1,91 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- */ + +/* Lac - Library for asynchronous communication + * Copyright (C) 2000, 2001, 2002, 2003 Søren Sandmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "lac.h" +#include <string.h> + +struct _LacTlsConnection +{ + LacConnection * tcp_connection; + LacTlsConnectionFunc callback; + gpointer data; + + LacByteQueue * buffer; + gboolean need_handshake; +}; + +static void +tcp_callback (LacConnection *connection, + const LacConnectionEvent *event) +{ + LacTlsConnection *tls = lac_connection_get_data (connection); + + switch (event->type) + { + case LAC_CONNECTION_EVENT_CONNECT: + case LAC_CONNECTION_EVENT_CLOSE: + case LAC_CONNECTION_EVENT_ERROR: + tls->callback (tls, event); + break; + + case LAC_CONNECTION_EVENT_READ: + /* add data to buffer */ + lac_byte_queue_append (tls->buffer, event->read.data, event->read.len); + + if (tls->need_handshake) + { + /* if need handshake, attempt handshake */ + /* if successful + * emit handshake + * tls->need_handshake = FALSE + */ + } + + /* attempt to read from the tls */ + /* if successful, emit read event */ + break; + + /* Connection closed */ + /* just re-emit */ + break; + + /* error */ + /* just re-emit */ + break; + } +} + +LacTlsConnection * +lac_tls_connection_new (const LacAddress *address, + gint port, + LacTlsConnectionFunc callback, + gpointer data) +{ + LacTlsConnection *tls = g_new0 (LacTlsConnection, 1); + + tls->tcp_connection = lac_connection_new ( + address, port, tcp_callback, tls); + tls->need_handshake = TRUE; + tls->callback = callback; + tls->data = data; + + return tls; +} |