Commit 551bcffa authored by John Brooks's avatar John Brooks

Add mcp-account-manager-uoa from Empathy

parent cf6bef0e
This is a telepathy authentication handler using libaccounts and libsignon,
kindly borrowed from Empathy's ubuntu-online-account support. Along with a
mission-control plugin (not included) providing a bridge between libaccounts
and telepathy, this allows proper use of libaccounts and libsignon to control
telepathy accounts.
A mission control plugin and authentication handler for Telepathy, integrating
with libaccounts and libsignon to provide IM accounts and authentication.
This code is kindly borrowed from Empathy's ubuntu-online-account support,
but not intended to keep compatibility with UOA.
The code is deliberately kept mostly similar to the upstream empathy code for
now, since there's limited effort towards maintaining it separately.
......
#include "config.h"
#include <gio/gio.h>
#include <telepathy-glib/telepathy-glib.h>
#include <libaccounts-glib/ag-account.h>
#include "empathy-webcredentials-monitor.h"
G_DEFINE_TYPE (EmpathyWebcredentialsMonitor, empathy_webcredentials_monitor, G_TYPE_OBJECT)
#define WEBCRED_BUS_NAME "com.canonical.indicators.webcredentials"
#define WEBCRED_PATH "/com/canonical/indicators/webcredentials"
#define WEBCRED_IFACE "com.canonical.indicators.webcredentials"
#define FAILURES_PROP "Failures"
enum
{
PROP_MANAGER = 1,
N_PROPS
};
enum
{
SIG_FAILURE_ADDED,
SIG_FAILURE_REMOVED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
struct _EmpathyWebcredentialsMonitorPriv
{
AgManager *manager;
GDBusProxy *proxy;
/* array of owned AgAccount */
GPtrArray *failures;
};
static void
empathy_webcredentials_monitor_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
EmpathyWebcredentialsMonitor *self = EMPATHY_WEBCREDENTIALS_MONITOR (object);
switch (property_id)
{
case PROP_MANAGER:
g_value_set_object (value, self->priv->manager);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
empathy_webcredentials_monitor_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
EmpathyWebcredentialsMonitor *self = EMPATHY_WEBCREDENTIALS_MONITOR (object);
switch (property_id)
{
case PROP_MANAGER:
g_assert (self->priv->manager == NULL); /* construct only */
self->priv->manager = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
empathy_webcredentials_monitor_constructed (GObject *object)
{
EmpathyWebcredentialsMonitor *self = EMPATHY_WEBCREDENTIALS_MONITOR (object);
void (*chain_up) (GObject *) =
((GObjectClass *) empathy_webcredentials_monitor_parent_class)->constructed;
chain_up (object);
g_assert (AG_IS_MANAGER (self->priv->manager));
}
static void
empathy_webcredentials_monitor_dispose (GObject *object)
{
EmpathyWebcredentialsMonitor *self = EMPATHY_WEBCREDENTIALS_MONITOR (object);
void (*chain_up) (GObject *) =
((GObjectClass *) empathy_webcredentials_monitor_parent_class)->dispose;
g_clear_object (&self->priv->manager);
g_clear_object (&self->priv->proxy);
chain_up (object);
}
static void
empathy_webcredentials_monitor_finalize (GObject *object)
{
EmpathyWebcredentialsMonitor *self = EMPATHY_WEBCREDENTIALS_MONITOR (object);
void (*chain_up) (GObject *) =
((GObjectClass *) empathy_webcredentials_monitor_parent_class)->finalize;
g_ptr_array_unref (self->priv->failures);
chain_up (object);
}
static void
empathy_webcredentials_monitor_class_init (
EmpathyWebcredentialsMonitorClass *klass)
{
GObjectClass *oclass = G_OBJECT_CLASS (klass);
GParamSpec *spec;
oclass->get_property = empathy_webcredentials_monitor_get_property;
oclass->set_property = empathy_webcredentials_monitor_set_property;
oclass->constructed = empathy_webcredentials_monitor_constructed;
oclass->dispose = empathy_webcredentials_monitor_dispose;
oclass->finalize = empathy_webcredentials_monitor_finalize;
spec = g_param_spec_object ("manager", "Manager",
"AgManager",
AG_TYPE_MANAGER,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (oclass, PROP_MANAGER, spec);
signals[SIG_FAILURE_ADDED] = g_signal_new ("failure-added",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE,
1, AG_TYPE_ACCOUNT);
signals[SIG_FAILURE_REMOVED] = g_signal_new ("failure-removed",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE,
1, AG_TYPE_ACCOUNT);
g_type_class_add_private (klass, sizeof (EmpathyWebcredentialsMonitorPriv));
}
static void
update_failures (EmpathyWebcredentialsMonitor *self)
{
GVariant *failures, *f;
GVariantIter iter;
GList *new_list = NULL;
guint i;
failures = g_dbus_proxy_get_cached_property (self->priv->proxy,
FAILURES_PROP);
if (failures == NULL)
{
g_debug ("Does not implement Failures property");
return;
}
g_variant_iter_init (&iter, failures);
while ((f = g_variant_iter_next_value (&iter)) != NULL)
{
guint32 id;
AgAccount *account;
id = g_variant_get_uint32 (f);
account = ag_manager_get_account (self->priv->manager, id);
if (account == NULL)
continue;
/* Pass ownership of 'account' to the list */
new_list = g_list_append (new_list, account);
if (!tp_g_ptr_array_contains (self->priv->failures, account))
{
g_ptr_array_add (self->priv->failures, g_object_ref (account));
g_signal_emit (self, signals[SIG_FAILURE_ADDED], 0, account);
}
g_variant_unref (f);
}
g_variant_unref (failures);
for (i = 0; i < self->priv->failures->len; i++)
{
AgAccount *account = g_ptr_array_index (self->priv->failures, i);
if (g_list_find (new_list, account) == NULL)
{
g_object_ref (account);
g_ptr_array_remove (self->priv->failures, account);
g_signal_emit (self, signals[SIG_FAILURE_REMOVED], 0, account);
g_object_unref (account);
}
}
g_list_free_full (new_list, g_object_unref);
}
static void
properties_changed_cb (GDBusProxy *proxy,
GVariant *changed_properties,
GStrv invalidated_properties,
EmpathyWebcredentialsMonitor *self)
{
if (g_variant_lookup_value (changed_properties, FAILURES_PROP, NULL) == NULL)
return;
update_failures (self);
}
static void
proxy_new_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
EmpathyWebcredentialsMonitor *self;
TpWeakRef *wr = user_data;
GError *error = NULL;
self = tp_weak_ref_dup_object (wr);
if (self == NULL)
goto out;
self->priv->proxy = g_dbus_proxy_new_for_bus_finish (result, &error);
if (self->priv->proxy == NULL)
{
g_debug ("Failed to create webcredentials proxy: %s", error->message);
g_error_free (error);
goto out;
}
update_failures (self);
g_signal_connect (self->priv->proxy, "g-properties-changed",
G_CALLBACK (properties_changed_cb), self);
out:
tp_weak_ref_destroy (wr);
g_clear_object (&self);
}
static void
empathy_webcredentials_monitor_init (EmpathyWebcredentialsMonitor *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
EMPATHY_TYPE_WEBCREDENTIALS_MONITOR, EmpathyWebcredentialsMonitorPriv);
self->priv->failures = g_ptr_array_new_with_free_func (g_object_unref);
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, NULL,
WEBCRED_BUS_NAME, WEBCRED_PATH, WEBCRED_IFACE,
NULL, proxy_new_cb, tp_weak_ref_new (self, NULL, NULL));
}
EmpathyWebcredentialsMonitor *
empathy_webcredentials_monitor_new (AgManager *manager)
{
return g_object_new (EMPATHY_TYPE_WEBCREDENTIALS_MONITOR,
"manager", manager,
NULL);
}
GPtrArray *
empathy_webcredentials_get_failures (EmpathyWebcredentialsMonitor *self)
{
return self->priv->failures;
}
#ifndef __EMPATHY_WEBCREDENTIALS_MONITOR_H__
#define __EMPATHY_WEBCREDENTIALS_MONITOR_H__
#include <glib-object.h>
#include <libaccounts-glib/ag-manager.h>
G_BEGIN_DECLS
typedef struct _EmpathyWebcredentialsMonitor EmpathyWebcredentialsMonitor;
typedef struct _EmpathyWebcredentialsMonitorClass EmpathyWebcredentialsMonitorClass;
typedef struct _EmpathyWebcredentialsMonitorPriv EmpathyWebcredentialsMonitorPriv;
struct _EmpathyWebcredentialsMonitorClass
{
/*<private>*/
GObjectClass parent_class;
};
struct _EmpathyWebcredentialsMonitor
{
/*<private>*/
GObject parent;
EmpathyWebcredentialsMonitorPriv *priv;
};
GType empathy_webcredentials_monitor_get_type (void);
/* TYPE MACROS */
#define EMPATHY_TYPE_WEBCREDENTIALS_MONITOR \
(empathy_webcredentials_monitor_get_type ())
#define EMPATHY_WEBCREDENTIALS_MONITOR(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
EMPATHY_TYPE_WEBCREDENTIALS_MONITOR, \
EmpathyWebcredentialsMonitor))
#define EMPATHY_WEBCREDENTIALS_MONITOR_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
EMPATHY_TYPE_WEBCREDENTIALS_MONITOR, \
EmpathyWebcredentialsMonitorClass))
#define EMPATHY_IS_WEBCREDENTIALS_MONITOR(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), \
EMPATHY_TYPE_WEBCREDENTIALS_MONITOR))
#define EMPATHY_IS_WEBCREDENTIALS_MONITOR_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), \
EMPATHY_TYPE_WEBCREDENTIALS_MONITOR))
#define EMPATHY_WEBCREDENTIALS_MONITOR_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
EMPATHY_TYPE_WEBCREDENTIALS_MONITOR, \
EmpathyWebcredentialsMonitorClass))
EmpathyWebcredentialsMonitor * empathy_webcredentials_monitor_new (
AgManager *manager);
GPtrArray * empathy_webcredentials_get_failures (
EmpathyWebcredentialsMonitor *self);
G_END_DECLS
#endif /* #ifndef __EMPATHY_WEBCREDENTIALS_MONITOR_H__*/
This diff is collapsed.
/*
* Copyright © 2012 Collabora Ltd.
*
* 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 <mission-control-plugins/mission-control-plugins.h>
#ifndef __MCP_ACCOUNT_MANAGER_UOA_H__
#define __MCP_ACCOUNT_MANAGER_UOA_H__
G_BEGIN_DECLS
#define MCP_TYPE_ACCOUNT_MANAGER_UOA \
(mcp_account_manager_uoa_get_type ())
#define MCP_ACCOUNT_MANAGER_UOA(o) \
(G_TYPE_CHECK_INSTANCE_CAST ((o), MCP_TYPE_ACCOUNT_MANAGER_UOA, \
McpAccountManagerUoa))
#define MCP_ACCOUNT_MANAGER_UOA_CLASS(k) \
(G_TYPE_CHECK_CLASS_CAST((k), MCP_TYPE_ACCOUNT_MANAGER_UOA, \
McpAccountManagerUoaClass))
#define MCP_IS_ACCOUNT_MANAGER_UOA(o) \
(G_TYPE_CHECK_INSTANCE_TYPE ((o), MCP_TYPE_ACCOUNT_MANAGER_UOA))
#define MCP_IS_ACCOUNT_MANAGER_UOA_CLASS(k) \
(G_TYPE_CHECK_CLASS_TYPE ((k), MCP_TYPE_ACCOUNT_MANAGER_UOA))
#define MCP_ACCOUNT_MANAGER_UOA_GET_CLASS(o) \
(G_TYPE_INSTANCE_GET_CLASS ((o), MCP_TYPE_ACCOUNT_MANAGER_UOA, \
McpAccountManagerUoaClass))
typedef struct _McpAccountManagerUoaPrivate McpAccountManagerUoaPrivate;
typedef struct {
GObject parent;
McpAccountManagerUoaPrivate *priv;
} _McpAccountManagerUoa;
typedef struct {
GObjectClass parent_class;
} _McpAccountManagerUoaClass;
typedef _McpAccountManagerUoa McpAccountManagerUoa;
typedef _McpAccountManagerUoaClass McpAccountManagerUoaClass;
GType mcp_account_manager_uoa_get_type (void) G_GNUC_CONST;
McpAccountManagerUoa *mcp_account_manager_uoa_new (void);
G_END_DECLS
#endif
TEMPLATE = lib
TARGET = mcp-account-manager-uoa
CONFIG += link_pkgconfig use_c_linker plugin no_plugin_name_prefix
CONFIG -= qt
PKGCONFIG += mission-control-plugins libaccounts-glib
SOURCES = empathy-webcredentials-monitor.c \
mcp-account-manager-uoa.c \
mission-control-plugin.c
HEADERS = mcp-account-manager-uoa.h\
empathy-webcredentials-monitor.h
target.path = $$system(pkg-config --variable=plugindir mission-control-plugins)
INSTALLS += target
/*
* mission-control-plugin.c
*
* A Mission Control plugin to expose Ubuntu Online Accounts with chat
* capabilities (e.g. Facebook) to Mission Control
*
* Copyright (C) 2012 Collabora Ltd.
*
* 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, see <http://www.gnu.org/licenses/>.
*
* Authors: Xavier Claessens <xavier.claessens@collabora.co.uk>
*/
#include <mission-control-plugins/mission-control-plugins.h>
#include "mcp-account-manager-uoa.h"
GObject *
mcp_plugin_ref_nth_object (guint n)
{
static void *plugin_0 = NULL;
switch (n)
{
case 0:
if (plugin_0 == NULL)
plugin_0 = g_object_new (MCP_TYPE_ACCOUNT_MANAGER_UOA, NULL);
else
g_object_ref (plugin_0);
return plugin_0;
default:
return NULL;
}
}
TEMPLATE = subdirs
SUBDIRS += mcp-account-manager-uoa \
telepathy-sasl-signon
TEMPLATE = app
CONFIG -= qt
CONFIG += link_pkgconfig
PKGCONFIG += libsignon-glib telepathy-glib libaccounts-glib libsoup-2.4
INCLUDEPATH += src
DEFINES += HAVE_UOA \
EMPATHY_UOA_PROVIDER=\\\"im.telepathy.Account.Storage.UOA\\\"
SOURCES += src/empathy-auth-client.c \
src/empathy-auth-factory.c \
src/empathy-server-sasl-handler.c \
src/empathy-server-tls-handler.c \
src/empathy-keyring.c \
src/empathy-uoa-utils.c \
src/empathy-sasl-mechanisms.c \
src/empathy-uoa-auth-handler.c
HEADERS += src/empathy-auth-factory.h \
src/empathy-debug.h \
src/empathy-keyring.h \
src/empathy-sasl-mechanisms.h \
src/empathy-server-sasl-handler.h \
src/empathy-server-tls-handler.h \
src/empathy-uoa-utils.h \
src/empathy-utils.h \
src/empathy-uoa-auth-handler.h
SOURCES += empathy-auth-client.c \
empathy-auth-factory.c \
empathy-server-sasl-handler.c \
empathy-server-tls-handler.c \
empathy-keyring.c \
empathy-uoa-utils.c \
empathy-sasl-mechanisms.c \
empathy-uoa-auth-handler.c
HEADERS += empathy-auth-factory.h \
empathy-debug.h \
empathy-keyring.h \
empathy-sasl-mechanisms.h \
empathy-server-sasl-handler.h \
empathy-server-tls-handler.h \
empathy-uoa-utils.h \
empathy-utils.h \
empathy-uoa-auth-handler.h
OTHER_FILES += org.freedesktop.Telepathy.Client.SaslSignonAuth.service \
SaslSignonAuth.client
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment