aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy/empathy-tls-certificate.c
diff options
context:
space:
mode:
Diffstat (limited to 'libempathy/empathy-tls-certificate.c')
-rw-r--r--libempathy/empathy-tls-certificate.c201
1 files changed, 54 insertions, 147 deletions
diff --git a/libempathy/empathy-tls-certificate.c b/libempathy/empathy-tls-certificate.c
index a03fa809f..9b8e5ae15 100644
--- a/libempathy/empathy-tls-certificate.c
+++ b/libempathy/empathy-tls-certificate.c
@@ -29,7 +29,7 @@
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
-#include <telepathy-glib/proxy-subclass.h>
+#include <telepathy-glib/util.h>
#define DEBUG_FLAG EMPATHY_DEBUG_TLS
#include "empathy-debug.h"
@@ -37,26 +37,16 @@
#include "extensions/extensions.h"
-static void async_initable_iface_init (GAsyncInitableIface *iface);
-
enum {
- PROP_OBJECT_PATH = 1,
- PROP_BUS_NAME,
-
/* proxy properties */
- PROP_CERT_TYPE,
+ PROP_CERT_TYPE = 1,
PROP_CERT_DATA,
PROP_STATE,
LAST_PROPERTY,
};
typedef struct {
- gchar *object_path;
- gchar *bus_name;
-
- TpProxy *proxy;
-
- GSimpleAsyncResult *async_init_res;
+ GSimpleAsyncResult *async_prepare_res;
/* TLSCertificate properties */
gchar *cert_type;
@@ -64,27 +54,11 @@ typedef struct {
EmpTLSCertificateState state;
} EmpathyTLSCertificatePriv;
-G_DEFINE_TYPE_WITH_CODE (EmpathyTLSCertificate, empathy_tls_certificate,
- G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, async_initable_iface_init));
+G_DEFINE_TYPE (EmpathyTLSCertificate, empathy_tls_certificate,
+ TP_TYPE_PROXY);
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyTLSCertificate);
-static gboolean
-tls_certificate_init_finish (GAsyncInitable *initable,
- GAsyncResult *res,
- GError **error)
-{
- gboolean retval = TRUE;
- EmpathyTLSCertificate *self = EMPATHY_TLS_CERTIFICATE (initable);
- EmpathyTLSCertificatePriv *priv = GET_PRIV (self);
-
- if (g_simple_async_result_propagate_error (priv->async_init_res, error))
- retval = FALSE;
-
- return retval;
-}
-
static GType
array_of_ay_get_type (void)
{
@@ -113,10 +87,9 @@ tls_certificate_got_all_cb (TpProxy *proxy,
if (error != NULL)
{
- g_simple_async_result_set_from_error (priv->async_init_res, error);
- g_simple_async_result_complete (priv->async_init_res);
-
- g_object_unref (priv->async_init_res);
+ g_simple_async_result_set_from_error (priv->async_prepare_res, error);
+ g_simple_async_result_complete (priv->async_prepare_res);
+ tp_clear_object (&priv->async_prepare_res);
return;
}
@@ -133,63 +106,39 @@ tls_certificate_got_all_cb (TpProxy *proxy,
DEBUG ("Got a certificate chain long %u, of type %s",
priv->cert_data->len, priv->cert_type);
- g_simple_async_result_complete (priv->async_init_res);
- g_object_unref (priv->async_init_res);
+ g_simple_async_result_complete (priv->async_prepare_res);
+ tp_clear_object (&priv->async_prepare_res);
}
-static void
-tls_certificate_init_async (GAsyncInitable *initable,
- gint io_priority,
- GCancellable *cancellable,
+void
+empathy_tls_certificate_prepare_async (EmpathyTLSCertificate *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
- TpDBusDaemon *dbus;
- GError *error = NULL;
- EmpathyTLSCertificate *self = EMPATHY_TLS_CERTIFICATE (initable);
EmpathyTLSCertificatePriv *priv = GET_PRIV (self);
- g_assert (priv->object_path != NULL);
- g_assert (priv->bus_name != NULL);
-
- priv->async_init_res = g_simple_async_result_new (G_OBJECT (self),
- callback, user_data, empathy_tls_certificate_new_async);
- dbus = tp_dbus_daemon_dup (&error);
-
- if (error != NULL)
- {
- g_simple_async_result_set_from_error (priv->async_init_res, error);
- g_simple_async_result_complete_in_idle (priv->async_init_res);
-
- g_error_free (error);
- g_object_unref (priv->async_init_res);
- return;
- }
-
- DEBUG ("Creating a proxy for object at path %s, owned by %s",
- priv->object_path, priv->bus_name);
-
- priv->proxy = g_object_new (TP_TYPE_PROXY,
- "object-path", priv->object_path,
- "bus-name", priv->bus_name,
- "dbus-daemon", dbus, NULL);
-
- tp_proxy_add_interface_by_id (priv->proxy,
- EMP_IFACE_QUARK_AUTHENTICATION_TLS_CERTIFICATE);
+ priv->async_prepare_res = g_simple_async_result_new (G_OBJECT (self),
+ callback, user_data, empathy_tls_certificate_prepare_async);
/* call GetAll() on the certificate */
- tp_cli_dbus_properties_call_get_all (priv->proxy,
+ tp_cli_dbus_properties_call_get_all (self,
-1, EMP_IFACE_AUTHENTICATION_TLS_CERTIFICATE,
- tls_certificate_got_all_cb, NULL, NULL, G_OBJECT (self));
-
- g_object_unref (dbus);
+ tls_certificate_got_all_cb, NULL, NULL,
+ G_OBJECT (self));
}
-static void
-async_initable_iface_init (GAsyncInitableIface *iface)
+gboolean
+empathy_tls_certificate_prepare_finish (EmpathyTLSCertificate *self,
+ GAsyncResult *result,
+ GError **error)
{
- iface->init_async = tls_certificate_init_async;
- iface->init_finish = tls_certificate_init_finish;
+ gboolean retval = TRUE;
+
+ if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
+ error))
+ retval = FALSE;
+
+ return retval;
}
static void
@@ -214,12 +163,6 @@ empathy_tls_certificate_get_property (GObject *object,
switch (property_id)
{
- case PROP_OBJECT_PATH:
- g_value_set_string (value, priv->object_path);
- break;
- case PROP_BUS_NAME:
- g_value_set_string (value, priv->bus_name);
- break;
case PROP_CERT_TYPE:
g_value_set_string (value, priv->cert_type);
break;
@@ -236,28 +179,6 @@ empathy_tls_certificate_get_property (GObject *object,
}
static void
-empathy_tls_certificate_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- EmpathyTLSCertificatePriv *priv = GET_PRIV (object);
-
- switch (property_id)
- {
- case PROP_OBJECT_PATH:
- priv->object_path = g_value_dup_string (value);
- break;
- case PROP_BUS_NAME:
- priv->bus_name = g_value_dup_string (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
-}
-
-static void
empathy_tls_certificate_init (EmpathyTLSCertificate *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
@@ -269,24 +190,15 @@ empathy_tls_certificate_class_init (EmpathyTLSCertificateClass *klass)
{
GParamSpec *pspec;
GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ TpProxyClass *pclass = TP_PROXY_CLASS (klass);
oclass->get_property = empathy_tls_certificate_get_property;
- oclass->set_property = empathy_tls_certificate_set_property;
oclass->finalize = empathy_tls_certificate_finalize;
- g_type_class_add_private (klass, sizeof (EmpathyTLSCertificatePriv));
-
- pspec = g_param_spec_string ("object-path", "The object path",
- "The path on the bus where the object we proxy is living.",
- NULL,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (oclass, PROP_OBJECT_PATH, pspec);
+ pclass->interface = EMP_IFACE_QUARK_AUTHENTICATION_TLS_CERTIFICATE;
+ pclass->must_have_unique_name = TRUE;
- pspec = g_param_spec_string ("bus-name", "The bus name",
- "The bus name owning this certificate.",
- NULL,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (oclass, PROP_BUS_NAME, pspec);
+ g_type_class_add_private (klass, sizeof (EmpathyTLSCertificatePriv));
pspec = g_param_spec_string ("cert-type", "Certificate type",
"The type of this certificate.",
@@ -389,36 +301,33 @@ reject_reason_get_dbus_error (EmpTLSCertificateRejectReason reason)
return retval;
}
-void
-empathy_tls_certificate_new_async (const gchar *bus_name,
+EmpathyTLSCertificate *
+empathy_tls_certificate_new (TpDBusDaemon *dbus,
+ const gchar *bus_name,
const gchar *object_path,
- GAsyncReadyCallback callback,
- gpointer user_data)
+ GError **error)
{
- g_assert (object_path != NULL);
+ EmpathyTLSCertificate *retval = NULL;
- g_async_initable_new_async (EMPATHY_TYPE_TLS_CERTIFICATE,
- G_PRIORITY_DEFAULT, NULL, callback, user_data,
- "bus-name", bus_name,
- "object-path", object_path, NULL);
-}
+ if (!tp_dbus_check_valid_bus_name (bus_name,
+ TP_DBUS_NAME_TYPE_UNIQUE, error))
+ goto finally;
-EmpathyTLSCertificate *
-empathy_tls_certificate_new_finish (GAsyncResult *res,
- GError **error)
-{
- GObject *object, *source_object;
+ if (!tp_dbus_check_valid_object_path (object_path, error))
+ goto finally;
- source_object = g_async_result_get_source_object (res);
+ retval = g_object_new (EMPATHY_TYPE_TLS_CERTIFICATE,
+ "dbus-daemon", dbus,
+ "bus-name", bus_name,
+ "object-path", object_path,
+ NULL);
- object = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object),
- res, error);
- g_object_unref (source_object);
+finally:
+ if (*error != NULL)
+ DEBUG ("Error while creating the TLS certificate: %s",
+ (*error)->message);
- if (object != NULL)
- return EMPATHY_TLS_CERTIFICATE (object);
- else
- return NULL;
+ return retval;
}
void
@@ -427,7 +336,6 @@ empathy_tls_certificate_accept_async (EmpathyTLSCertificate *self,
gpointer user_data)
{
GSimpleAsyncResult *accept_result;
- EmpathyTLSCertificatePriv *priv = GET_PRIV (self);
g_assert (EMPATHY_IS_TLS_CERTIFICATE (self));
@@ -436,7 +344,7 @@ empathy_tls_certificate_accept_async (EmpathyTLSCertificate *self,
accept_result = g_simple_async_result_new (G_OBJECT (self),
callback, user_data, empathy_tls_certificate_accept_async);
- emp_cli_authentication_tls_certificate_call_accept (priv->proxy,
+ emp_cli_authentication_tls_certificate_call_accept (TP_PROXY (self),
-1, cert_proxy_accept_cb,
accept_result, g_object_unref,
G_OBJECT (self));
@@ -463,7 +371,6 @@ empathy_tls_certificate_reject_async (EmpathyTLSCertificate *self,
{
const gchar *dbus_error;
GSimpleAsyncResult *reject_result;
- EmpathyTLSCertificatePriv *priv = GET_PRIV (self);
g_assert (EMPATHY_IS_TLS_CERTIFICATE (self));
@@ -473,7 +380,7 @@ empathy_tls_certificate_reject_async (EmpathyTLSCertificate *self,
reject_result = g_simple_async_result_new (G_OBJECT (self),
callback, user_data, empathy_tls_certificate_reject_async);
- emp_cli_authentication_tls_certificate_call_reject (priv->proxy,
+ emp_cli_authentication_tls_certificate_call_reject (TP_PROXY (self),
-1, reason, dbus_error, details, cert_proxy_reject_cb,
reject_result, g_object_unref, G_OBJECT (self));
}