]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-server-tls-handler.c
Merge branch 'gnome-3-8'
[empathy.git] / libempathy / empathy-server-tls-handler.c
index 95c0b0a9a36d2eccf3c8814693ca61dd02f81aa3..34c3147a38c32fccdbd46569f7ed0df264ce829e 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include "config.h"
 #include "empathy-server-tls-handler.h"
 
-#include <telepathy-glib/util.h>
+#include "empathy-utils.h"
+#include "extensions.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_TLS
 #include "empathy-debug.h"
-#include "empathy-tls-certificate.h"
-#include "empathy-utils.h"
-
-#include "extensions/extensions.h"
 
 static void async_initable_iface_init (GAsyncInitableIface *iface);
 
@@ -42,7 +40,7 @@ enum {
 typedef struct {
   TpChannel *channel;
 
-  EmpathyTLSCertificate *certificate;
+  TpTLSCertificate *certificate;
   gchar *hostname;
   gchar **reference_identities;
 
@@ -60,14 +58,12 @@ tls_certificate_prepared_cb (GObject *source,
     GAsyncResult *result,
     gpointer user_data)
 {
-  EmpathyTLSCertificate *certificate = EMPATHY_TLS_CERTIFICATE (source);
+  TpTLSCertificate *certificate = TP_TLS_CERTIFICATE (source);
   EmpathyServerTLSHandler *self = user_data;
   GError *error = NULL;
   EmpathyServerTLSHandlerPriv *priv = GET_PRIV (self);
 
-  empathy_tls_certificate_prepare_finish (certificate, result, &error);
-
-  if (error != NULL)
+  if (!tp_proxy_prepare_finish (certificate, result, &error))
     {
       g_simple_async_result_set_from_error (priv->async_init_res, error);
       g_error_free (error);
@@ -98,13 +94,11 @@ tls_handler_init_async (GAsyncInitable *initable,
     GAsyncReadyCallback callback,
     gpointer user_data)
 {
-  GHashTable *properties;
+  GVariant *properties;
   const gchar *cert_object_path;
-  const gchar *hostname;
-  const gchar * const *identities;
   const gchar *bus_name;
-  TpDBusDaemon *dbus;
   GError *error = NULL;
+  GQuark features[] = { TP_TLS_CERTIFICATE_FEATURE_CORE, 0 };
   /*
    * Used when channel doesn't implement ReferenceIdentities. A GStrv
    * with [0] the hostname, and [1] a NULL terminator.
@@ -117,52 +111,53 @@ tls_handler_init_async (GAsyncInitable *initable,
 
   priv->async_init_res = g_simple_async_result_new (G_OBJECT (self),
       callback, user_data, empathy_server_tls_handler_new_async);
-  properties = tp_channel_borrow_immutable_properties (priv->channel);
+  properties = tp_channel_dup_immutable_properties (priv->channel);
 
-  hostname = tp_asv_get_string (properties,
-      EMP_IFACE_CHANNEL_TYPE_SERVER_TLS_CONNECTION ".Hostname");
-  priv->hostname = g_strdup (hostname);
+  g_variant_lookup (properties,
+      TP_PROP_CHANNEL_TYPE_SERVER_TLS_CONNECTION_HOSTNAME,
+      "s", &priv->hostname);
 
-  DEBUG ("Received hostname: %s", hostname);
+  DEBUG ("Received hostname: %s", priv->hostname);
 
-  identities = tp_asv_get_strv (properties,
-      EMP_IFACE_CHANNEL_TYPE_SERVER_TLS_CONNECTION ".ReferenceIdentities");
+  g_variant_lookup (properties,
+      TP_PROP_CHANNEL_TYPE_SERVER_TLS_CONNECTION_REFERENCE_IDENTITIES,
+      "^as", &priv->reference_identities);
 
   /*
    * If the channel doesn't implement the ReferenceIdentities parameter
    * then fallback to the hostname.
    */
-  if (identities == NULL)
+  if (priv->reference_identities == NULL)
     {
-      default_identities[0] = (gchar *) hostname;
+      default_identities[0] = (gchar *) priv->hostname;
       default_identities[1] = NULL;
-      identities = (const gchar **) default_identities;
+      priv->reference_identities = g_strdupv (default_identities);
     }
   else
     {
 #ifdef ENABLE_DEBUG
-      gchar *output = g_strjoinv (", ", (gchar **) identities);
+      gchar *output = g_strjoinv (", ", (gchar **) priv->reference_identities);
       DEBUG ("Received reference identities: %s", output);
       g_free (output);
 #endif /* ENABLE_DEBUG */
   }
 
-  priv->reference_identities = g_strdupv ((gchar **) identities);
-
-  cert_object_path = tp_asv_get_object_path (properties,
-      EMP_IFACE_CHANNEL_TYPE_SERVER_TLS_CONNECTION ".ServerCertificate");
+  g_variant_lookup (properties,
+      EMP_IFACE_CHANNEL_TYPE_SERVER_TLS_CONNECTION ".ServerCertificate",
+      "&o", &cert_object_path);
   bus_name = tp_proxy_get_bus_name (TP_PROXY (priv->channel));
-  dbus = tp_proxy_get_dbus_daemon (TP_PROXY (priv->channel));
 
-  DEBUG ("Creating an EmpathyTLSCertificate for path %s, bus name %s",
+  DEBUG ("Creating an TpTLSCertificate for path %s, bus name %s",
       cert_object_path, bus_name);
 
-  priv->certificate = empathy_tls_certificate_new (dbus, bus_name,
+  priv->certificate = tp_tls_certificate_new (TP_PROXY (priv->channel),
       cert_object_path, &error);
 
+  g_variant_unref (properties);
+
   if (error != NULL)
     {
-      DEBUG ("Unable to create the EmpathyTLSCertificate: error %s",
+      DEBUG ("Unable to create the TpTLSCertificate: error %s",
           error->message);
 
       g_simple_async_result_set_from_error (priv->async_init_res, error);
@@ -174,7 +169,7 @@ tls_handler_init_async (GAsyncInitable *initable,
       return;
     }
 
-  empathy_tls_certificate_prepare_async (priv->certificate,
+  tp_proxy_prepare_async (priv->certificate, features,
       tls_certificate_prepared_cb, self);
 }
 
@@ -265,9 +260,9 @@ empathy_server_tls_handler_class_init (EmpathyServerTLSHandlerClass *klass)
       G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
   g_object_class_install_property (oclass, PROP_CHANNEL, pspec);
 
-  pspec = g_param_spec_object ("certificate", "The EmpathyTLSCertificate",
-      "The EmpathyTLSCertificate carried by the channel.",
-      EMPATHY_TYPE_TLS_CERTIFICATE,
+  pspec = g_param_spec_object ("certificate", "The TpTLSCertificate",
+      "The TpTLSCertificate carried by the channel.",
+      TP_TYPE_TLS_CERTIFICATE,
       G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
   g_object_class_install_property (oclass, PROP_TLS_CERTIFICATE, pspec);
 
@@ -279,8 +274,7 @@ empathy_server_tls_handler_class_init (EmpathyServerTLSHandlerClass *klass)
 
   pspec = g_param_spec_boxed ("reference-identities", "Reference Identities",
       "The server certificate should certify one of these identities",
-      G_TYPE_STRV,
-      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+      G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
   g_object_class_install_property (oclass, PROP_REFERENCE_IDENTITIES, pspec);
 
 }
@@ -323,7 +317,7 @@ empathy_server_tls_handler_new_finish (GAsyncResult *result,
     return NULL;
 }
 
-EmpathyTLSCertificate *
+TpTLSCertificate *
 empathy_server_tls_handler_get_certificate (EmpathyServerTLSHandler *self)
 {
   EmpathyServerTLSHandlerPriv *priv = GET_PRIV (self);