From ba434807edfc0ad475086a9c3c0313e7606d0abe Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Sun, 21 Apr 2013 18:09:03 +0300 Subject: [PATCH] telepathy: add TLS manager class This is the channel manager for TLS certificate user interactions. --- src/telepathy/Makefile.am | 1 + src/telepathy/telepathy-connection.c | 1 + src/telepathy/telepathy-private.h | 4 +- src/telepathy/telepathy-tls.c | 164 +++++++++++++++++++++++++++++++++++ 4 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 src/telepathy/telepathy-tls.c diff --git a/src/telepathy/Makefile.am b/src/telepathy/Makefile.am index b45381df..b893b95d 100644 --- a/src/telepathy/Makefile.am +++ b/src/telepathy/Makefile.am @@ -17,6 +17,7 @@ telepathy_sipe_SOURCES = \ telepathy-search.c \ telepathy-status.c \ telepathy-stubs.c \ + telepathy-tls.c \ telepathy-transport.c AM_CFLAGS = $(st) diff --git a/src/telepathy/telepathy-connection.c b/src/telepathy/telepathy-connection.c index de8e1799..09e9fbf2 100644 --- a/src/telepathy/telepathy-connection.c +++ b/src/telepathy/telepathy-connection.c @@ -373,6 +373,7 @@ static GPtrArray *create_channel_managers(TpBaseConnection *base) g_ptr_array_add(channel_managers, self->password_manager); g_ptr_array_add(channel_managers, sipe_telepathy_search_new(base)); + g_ptr_array_add(channel_managers, sipe_telepathy_tls_new(base)); return(channel_managers); } diff --git a/src/telepathy/telepathy-private.h b/src/telepathy/telepathy-private.h index 195b0675..02798c9b 100644 --- a/src/telepathy/telepathy-private.h +++ b/src/telepathy/telepathy-private.h @@ -3,7 +3,7 @@ * * pidgin-sipe * - * Copyright (C) 2012 SIPE Project + * Copyright (C) 2012-2013 SIPE Project * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -101,6 +101,8 @@ struct _GObject *sipe_telepathy_search_new(struct _TpBaseConnection *connection) void sipe_telepathy_status_init(struct _GObjectClass *object_class, gsize struct_offset); +/* TLS certificate verification */ +GObject *sipe_telepathy_tls_new(struct _TpBaseConnection *connection); /* Local Variables: diff --git a/src/telepathy/telepathy-tls.c b/src/telepathy/telepathy-tls.c new file mode 100644 index 00000000..08e7dbdd --- /dev/null +++ b/src/telepathy/telepathy-tls.c @@ -0,0 +1,164 @@ +/** + * @file telepathy-tls.c + * + * pidgin-sipe + * + * Copyright (C) 2013 SIPE Project + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * TLS certificate accept/reject user interaction + */ + +#include +#include +#include + +#include "sipe-backend.h" +#include "sipe-common.h" + +#include "telepathy-private.h" + +G_BEGIN_DECLS +/* + * TLS Manager class - data structures + */ +typedef struct _SipeTLSManagerClass { + GObjectClass parent_class; +} SipeTLSManagerClass; + +typedef struct _SipeTLSManager { + GObject parent; + + GObject *connection; +} SipeTLSManager; + +/* + * TLS Manager class - type macros + */ +static GType sipe_tls_manager_get_type(void); +#define SIPE_TYPE_TLS_MANAGER \ + (sipe_tls_manager_get_type()) +#define SIPE_TLS_MANAGER(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), SIPE_TYPE_TLS_MANAGER, \ + SipeTLSManager)) + +G_END_DECLS + +/* + * TLS Manager class - type definition + */ +static void channel_manager_iface_init(gpointer, gpointer); +G_DEFINE_TYPE_WITH_CODE(SipeTLSManager, + sipe_tls_manager, + G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE(TP_TYPE_CHANNEL_MANAGER, + channel_manager_iface_init); +) + +/* + * TLS Manager class - instance methods + */ +static void sipe_tls_manager_constructed(GObject *object) +{ + SipeTLSManager *self = SIPE_TLS_MANAGER(object); + void (*chain_up)(GObject *) = G_OBJECT_CLASS(sipe_tls_manager_parent_class)->constructed; + + if (chain_up) + chain_up(object); + + /* @TODO */ + (void)self; +} + +static void sipe_tls_manager_dispose(GObject *object) +{ + SipeTLSManager *self = SIPE_TLS_MANAGER(object); + void (*chain_up)(GObject *) = G_OBJECT_CLASS(sipe_tls_manager_parent_class)->constructed; + + tp_clear_object(&self->connection); + + if (chain_up) + chain_up(object); +} + +/* + * TLS Manager class - type implementation + */ +static void sipe_tls_manager_class_init(SipeTLSManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + + SIPE_DEBUG_INFO_NOFORMAT("SipeTLSManager::class_init"); + + object_class->constructed = sipe_tls_manager_constructed; + object_class->dispose = sipe_tls_manager_dispose; +} + +static void sipe_tls_manager_init(SIPE_UNUSED_PARAMETER SipeTLSManager *self) +{ + SIPE_DEBUG_INFO_NOFORMAT("SipeTLSManager::init"); +} + +/* + * TLS Manager class - interface implementation + * + * Channel Manager + */ +static void foreach_channel(TpChannelManager *manager, + TpExportableChannelFunc func, + gpointer user_data) +{ + SipeTLSManager *self = SIPE_TLS_MANAGER(manager); + + SIPE_DEBUG_INFO_NOFORMAT("SipeTLSManager::foreach_channel"); + + /* @TODO */ + (void)self; + (void)func; + (void)user_data; +} + +static void channel_manager_iface_init(gpointer g_iface, + SIPE_UNUSED_PARAMETER gpointer iface_data) +{ + TpChannelManagerIface *iface = g_iface; + +#define IMPLEMENT(x, y) iface->x = y + IMPLEMENT(foreach_channel, foreach_channel); + /* These channels are not requestable. */ + IMPLEMENT(type_foreach_channel_class, NULL); + IMPLEMENT(create_channel, NULL); + IMPLEMENT(request_channel, NULL); + IMPLEMENT(ensure_channel, NULL); +#undef IMPLEMENT +} + +/* create new TLS manager object */ +GObject *sipe_telepathy_tls_new(TpBaseConnection *connection) +{ + SipeTLSManager *self = g_object_new(SIPE_TYPE_TLS_MANAGER, NULL); + self->connection = g_object_ref(connection); + return(G_OBJECT(self)); +} + +/* + Local Variables: + mode: c + c-file-style: "bsd" + indent-tabs-mode: t + tab-width: 8 + End: +*/ -- 2.11.4.GIT