aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
diff options
context:
space:
mode:
authorCosimo Cecchi <cosimoc@gnome.org>2010-07-09 22:43:25 +0800
committerCosimo Cecchi <cosimoc@gnome.org>2010-08-13 22:22:21 +0800
commited819ae5dfef5c6fd584fd8a63bbce9080cd4040 (patch)
tree13deb9c27c2bce87a2df6ddb9513c77681986e2c /libempathy
parent2cbd1c3661cc56f3558bd7391c6f15cc16f2f61f (diff)
downloadgsoc2013-empathy-ed819ae5dfef5c6fd584fd8a63bbce9080cd4040.tar
gsoc2013-empathy-ed819ae5dfef5c6fd584fd8a63bbce9080cd4040.tar.gz
gsoc2013-empathy-ed819ae5dfef5c6fd584fd8a63bbce9080cd4040.tar.bz2
gsoc2013-empathy-ed819ae5dfef5c6fd584fd8a63bbce9080cd4040.tar.lz
gsoc2013-empathy-ed819ae5dfef5c6fd584fd8a63bbce9080cd4040.tar.xz
gsoc2013-empathy-ed819ae5dfef5c6fd584fd8a63bbce9080cd4040.tar.zst
gsoc2013-empathy-ed819ae5dfef5c6fd584fd8a63bbce9080cd4040.zip
Add a first skeleton of the auth factory.
Diffstat (limited to 'libempathy')
-rw-r--r--libempathy/Makefile.am2
-rw-r--r--libempathy/empathy-auth-factory.c208
-rw-r--r--libempathy/empathy-auth-factory.h66
3 files changed, 276 insertions, 0 deletions
diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am
index 2817ae650..7a1f16a3e 100644
--- a/libempathy/Makefile.am
+++ b/libempathy/Makefile.am
@@ -26,6 +26,7 @@ noinst_LTLIBRARIES = libempathy.la
libempathy_headers = \
empathy-account-settings.h \
+ empathy-auth-factory.h \
empathy-call-factory.h \
empathy-call-handler.h \
empathy-chatroom-manager.h \
@@ -64,6 +65,7 @@ libempathy_headers = \
libempathy_la_SOURCES = \
$(libempathy_headers) \
empathy-account-settings.c \
+ empathy-auth-factory.c \
empathy-call-factory.c \
empathy-call-handler.c \
empathy-chatroom-manager.c \
diff --git a/libempathy/empathy-auth-factory.c b/libempathy/empathy-auth-factory.c
new file mode 100644
index 000000000..836be14d2
--- /dev/null
+++ b/libempathy/empathy-auth-factory.c
@@ -0,0 +1,208 @@
+/*
+ * empathy-auth-factory.c - Source for EmpathyAuthFactory
+ * Copyright (C) 2010 Collabora Ltd.
+ * @author Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "empathy-auth-factory.h"
+
+#include <telepathy-glib/interfaces.h>
+#include <telepathy-glib/simple-handler.h>
+
+#define DEBUG_FLAG EMPATHY_DEBUG_TLS
+#include "empathy-debug.h"
+#include "empathy-server-tls-handler.h"
+#include "empathy-utils.h"
+
+#include "extensions/extensions.h"
+
+G_DEFINE_TYPE (EmpathyAuthFactory, empathy_auth_factory, G_TYPE_OBJECT);
+
+typedef struct {
+ TpBaseClient *handler;
+} EmpathyAuthFactoryPriv;
+
+enum {
+ NEW_SERVER_TLS_HANDLER,
+ LAST_SIGNAL,
+};
+
+static guint signals[LAST_SIGNAL] = { 0, };
+
+#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAuthFactory)
+
+static EmpathyAuthFactory *auth_factory_singleton = NULL;
+
+static void
+server_tls_handler_ready_cb (GObject *source,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ EmpathyAuthFactory *self = user_data;
+ GError *error = NULL;
+ EmpathyServerTLSHandler *handler;
+
+ handler = empathy_server_tls_handler_new_finish (res, &error);
+
+ if (error != NULL)
+ {
+ DEBUG ("Failed to create a server TLS handler; error %s",
+ error->message);
+ g_error_free (error);
+ }
+ else
+ {
+ g_signal_emit (self, signals[NEW_SERVER_TLS_HANDLER], 0,
+ handler);
+ }
+}
+
+static void
+handle_channels_cb (TpSimpleHandler *handler,
+ TpAccount *account,
+ TpConnection *connection,
+ GList *channels,
+ GList *requests_satisfied,
+ gint64 user_action_time,
+ TpHandleChannelsContext *context,
+ gpointer user_data)
+{
+ TpChannel *channel;
+ EmpathyAuthFactory *self = user_data;
+
+ DEBUG ("Handle TLS carrier channels.");
+
+ /* there can't be more than one ServerTLSConnection channels
+ * at the same time, for the same connection/account.
+ */
+ g_assert (g_list_length (channels) == 1);
+
+ channel = channels->data;
+
+ if (tp_proxy_get_invalidated (channel) != NULL)
+ goto out;
+
+ if (tp_channel_get_channel_type_id (channel) !=
+ EMP_IFACE_QUARK_CHANNEL_TYPE_SERVER_TLS_CONNECTION)
+ goto out;
+
+ /* create a handler */
+ empathy_server_tls_handler_new_async (channel, server_tls_handler_ready_cb,
+ self);
+
+ out:
+ tp_handle_channels_context_accept (context);
+}
+
+static GObject *
+empathy_auth_factory_constructor (GType type,
+ guint n_params,
+ GObjectConstructParam *params)
+{
+ GObject *retval;
+
+ if (auth_factory_singleton != NULL)
+ {
+ retval = g_object_ref (auth_factory_singleton);
+ }
+ else
+ {
+ retval = G_OBJECT_CLASS (empathy_auth_factory_parent_class)->constructor
+ (type, n_params, params);
+
+ auth_factory_singleton = EMPATHY_AUTH_FACTORY (retval);
+ g_object_add_weak_pointer (retval, (gpointer *) &auth_factory_singleton);
+ }
+
+ return retval;
+}
+
+static void
+empathy_auth_factory_init (EmpathyAuthFactory *self)
+{
+ EmpathyAuthFactoryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ EMPATHY_TYPE_AUTH_FACTORY, EmpathyAuthFactoryPriv);
+ TpDBusDaemon *bus;
+ GError *error = NULL;
+
+ self->priv = priv;
+
+ bus = tp_dbus_daemon_dup (&error);
+ if (error != NULL)
+ {
+ g_critical ("Failed to get TpDBusDaemon: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ priv->handler = tp_simple_handler_new (bus, FALSE, FALSE, "Empathy.Auth",
+ FALSE, handle_channels_cb, self, NULL);
+
+ tp_base_client_take_handler_filter (priv->handler, tp_asv_new (
+ TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
+ EMP_IFACE_CHANNEL_TYPE_SERVER_TLS_CONNECTION,
+ TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
+ TP_HANDLE_TYPE_NONE, NULL));
+
+ g_object_unref (bus);
+}
+
+static void
+empathy_auth_factory_finalize (GObject *object)
+{
+ EmpathyAuthFactoryPriv *priv = GET_PRIV (object);
+
+ if (priv->handler != NULL)
+ g_object_unref (priv->handler);
+
+ G_OBJECT_CLASS (empathy_auth_factory_parent_class)->finalize (object);
+}
+
+static void
+empathy_auth_factory_class_init (EmpathyAuthFactoryClass *klass)
+{
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+
+ oclass->constructor = empathy_auth_factory_constructor;
+ oclass->finalize = empathy_auth_factory_finalize;
+
+ g_type_class_add_private (klass, sizeof (EmpathyAuthFactoryPriv));
+
+ signals[NEW_SERVER_TLS_HANDLER] =
+ g_signal_new ("new-server-tls-handler",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST, 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1, EMPATHY_TYPE_SERVER_TLS_HANDLER);
+}
+
+EmpathyAuthFactory *
+empathy_auth_factory_dup_singleton (void)
+{
+ return g_object_new (EMPATHY_TYPE_AUTH_FACTORY, NULL);
+}
+
+gboolean
+empathy_auth_factory_register (EmpathyAuthFactory *self,
+ GError **error)
+{
+ EmpathyAuthFactoryPriv *priv = GET_PRIV (self);
+
+ return tp_base_client_register (priv->handler, error);
+}
diff --git a/libempathy/empathy-auth-factory.h b/libempathy/empathy-auth-factory.h
new file mode 100644
index 000000000..507f69b95
--- /dev/null
+++ b/libempathy/empathy-auth-factory.h
@@ -0,0 +1,66 @@
+/*
+ * empathy-auth-factory.h - Header for EmpathyAuthFactory
+ * Copyright (C) 2010 Collabora Ltd.
+ * @author Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __EMPATHY_AUTH_FACTORY_H__
+#define __EMPATHY_AUTH_FACTORY_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+typedef struct _EmpathyAuthFactory EmpathyAuthFactory;
+typedef struct _EmpathyAuthFactoryClass EmpathyAuthFactoryClass;
+
+struct _EmpathyAuthFactoryClass {
+ GObjectClass parent_class;
+};
+
+struct _EmpathyAuthFactory {
+ GObject parent;
+ gpointer priv;
+};
+
+GType empathy_auth_factory_get_type (void);
+
+/* TYPE MACROS */
+#define EMPATHY_TYPE_AUTH_FACTORY \
+ (empathy_auth_factory_get_type ())
+#define EMPATHY_AUTH_FACTORY(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), EMPATHY_TYPE_AUTH_FACTORY, \
+ EmpathyAuthFactory))
+#define EMPATHY_AUTH_FACTORY_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), EMPATHY_TYPE_AUTH_FACTORY, \
+ EmpathyAuthFactoryClass))
+#define EMPATHY_IS_AUTH_FACTORY(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), EMPATHY_TYPE_AUTH_FACTORY))
+#define EMPATHY_IS_AUTH_FACTORY_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), EMPATHY_TYPE_AUTH_FACTORY))
+#define EMPATHY_AUTH_FACTORY_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_AUTH_FACTORY, \
+ EmpathyAuthFactoryClass))
+
+EmpathyAuthFactory * empathy_auth_factory_dup_singleton (void);
+
+gboolean empathy_auth_factory_register (EmpathyAuthFactory *self,
+ GError **error);
+
+G_END_DECLS
+
+#endif /* #ifndef __EMPATHY_AUTH_FACTORY_H__*/