telepathy-glib: Use a GVariant to return rejection details
Guillaume Desmottes
gdesmott at kemper.freedesktop.org
Wed May 9 03:15:58 PDT 2012
Module: telepathy-glib
Branch: master
Commit: c40c8cf0548c9800500035b7890ee07976a5ede7
URL: http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=c40c8cf0548c9800500035b7890ee07976a5ede7
Author: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
Date: Thu Apr 19 12:50:41 2012 +0200
Use a GVariant to return rejection details
---
telepathy-glib/tls-certificate.c | 25 ++++++++++++-------------
telepathy-glib/tls-certificate.h | 4 ++--
tests/dbus/tls-certificate.c | 15 +++++++++------
3 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/telepathy-glib/tls-certificate.c b/telepathy-glib/tls-certificate.c
index 4d908d3..62edc97 100644
--- a/telepathy-glib/tls-certificate.c
+++ b/telepathy-glib/tls-certificate.c
@@ -124,7 +124,7 @@ typedef struct {
GError *error /* NULL-initialized later */ ;
TpTLSCertificateRejectReason reason;
gchar *dbus_error;
- GHashTable *details;
+ GVariant *details;
} SignalledRejection;
static void
@@ -141,7 +141,7 @@ tp_tls_certificate_clear_rejections (TpTLSCertificate *self)
g_clear_error (&sr->error);
tp_clear_pointer (&sr->dbus_error, g_free);
- tp_clear_pointer (&sr->details, g_hash_table_unref);
+ tp_clear_pointer (&sr->details, g_variant_unref);
}
}
@@ -175,7 +175,11 @@ tp_tls_certificate_rejected_cb (TpTLSCertificate *self,
"Rejected, no reason given"),
TP_TLS_CERTIFICATE_REJECT_REASON_UNKNOWN,
g_strdup (TP_ERROR_STR_CERT_INVALID),
- tp_asv_new (NULL, NULL) };
+ NULL };
+ GVariantBuilder builder;
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
+ sr.details = g_variant_builder_end (&builder);
self->priv->rejections = g_array_sized_new (FALSE, FALSE,
sizeof (SignalledRejection), 1);
@@ -203,12 +207,7 @@ tp_tls_certificate_rejected_cb (TpTLSCertificate *self,
tp_proxy_dbus_error_to_gerror (self, error_name,
tp_asv_get_string (details, "debug-message"), &sr.error);
- sr.details = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, (GDestroyNotify) tp_g_value_slice_free);
- tp_g_hash_table_update (sr.details, (GHashTable *) details,
- (GBoxedCopyFunc) g_strdup,
- (GBoxedCopyFunc) tp_g_value_slice_dup);
-
+ sr.details = _tp_asv_to_vardict (details);
sr.dbus_error = g_strdup (error_name);
g_array_append_val (self->priv->rejections, sr);
@@ -834,7 +833,7 @@ tp_tls_certificate_init_known_interfaces (void)
* @reason: (out) (allow-none): optionally used to return the reason code
* @dbus_error: (out) (type utf8) (allow-none) (transfer none): optionally
* used to return the D-Bus error name
- * @details: (out) (allow-none) (transfer none) (element-type utf8 GObject.Value):
+ * @details: (out) (allow-none) (transfer none):
* optionally used to return a map from string to #GValue, which must not be
* modified or destroyed by the caller
*
@@ -854,7 +853,7 @@ const GError *
tp_tls_certificate_get_rejection (TpTLSCertificate *self,
TpTLSCertificateRejectReason *reason,
const gchar **dbus_error,
- const GHashTable **details)
+ const GVariant **details)
{
return tp_tls_certificate_get_nth_rejection (self, 0, reason, dbus_error,
details);
@@ -868,7 +867,7 @@ tp_tls_certificate_get_rejection (TpTLSCertificate *self,
* @reason: (out) (allow-none): optionally used to return the reason code
* @dbus_error: (out) (type utf8) (allow-none) (transfer none): optionally
* used to return the D-Bus error name
- * @details: (out) (allow-none) (transfer none) (element-type utf8 GObject.Value):
+ * @details: (out) (allow-none) (transfer none):
* optionally used to return a map from string to #GValue, which must not be
* modified or destroyed by the caller
*
@@ -887,7 +886,7 @@ tp_tls_certificate_get_nth_rejection (TpTLSCertificate *self,
guint n,
TpTLSCertificateRejectReason *reason,
const gchar **dbus_error,
- const GHashTable **details)
+ const GVariant **details)
{
const SignalledRejection *rej;
diff --git a/telepathy-glib/tls-certificate.h b/telepathy-glib/tls-certificate.h
index fd77f84..2a9a75e 100644
--- a/telepathy-glib/tls-certificate.h
+++ b/telepathy-glib/tls-certificate.h
@@ -79,12 +79,12 @@ TpTLSCertificate *tp_tls_certificate_new (TpProxy *conn_or_chan,
const GError *tp_tls_certificate_get_rejection (TpTLSCertificate *self,
TpTLSCertificateRejectReason *reason,
const gchar **dbus_error,
- const GHashTable **details);
+ const GVariant **details);
const GError *tp_tls_certificate_get_nth_rejection (TpTLSCertificate *self,
guint n,
TpTLSCertificateRejectReason *reason,
const gchar **dbus_error,
- const GHashTable **details);
+ const GVariant **details);
void tp_tls_certificate_accept_async (TpTLSCertificate *self,
GAsyncReadyCallback callback,
diff --git a/tests/dbus/tls-certificate.c b/tests/dbus/tls-certificate.c
index 8c0818a..3466d8b 100644
--- a/tests/dbus/tls-certificate.c
+++ b/tests/dbus/tls-certificate.c
@@ -217,10 +217,11 @@ static void
test_reject (Test *test,
gconstpointer data G_GNUC_UNUSED)
{
- GHashTable *details;
+ GVariant *details;
const GError *error;
TpTLSCertificateRejectReason reason;
const gchar *dbus_error;
+ gboolean enabled;
g_signal_connect (test->cert, "notify::state",
G_CALLBACK (notify_cb), test);
@@ -243,17 +244,19 @@ test_reject (Test *test,
TP_TLS_CERTIFICATE_STATE_REJECTED);
error = tp_tls_certificate_get_rejection (test->cert, &reason, &dbus_error,
- (const GHashTable **) &details);
+ (const GVariant **) &details);
g_assert_error (error, TP_ERRORS, TP_ERROR_CERT_REVOKED);
g_assert_cmpstr (dbus_error, ==, TP_ERROR_STR_CERT_REVOKED);
- g_assert_cmpuint (g_hash_table_size (details), ==, 1);
- g_assert (tp_asv_get_boolean (details, "user-requested", NULL));
+ g_assert (g_variant_is_of_type (details, G_VARIANT_TYPE_VARDICT));
+ g_assert_cmpuint (g_variant_n_children (details), ==, 1);
+ g_assert (g_variant_lookup (details, "user-requested", "b", &enabled));
+ g_assert (enabled);
error = tp_tls_certificate_get_nth_rejection (test->cert, 1, &reason,
- &dbus_error, (const GHashTable **) &details);
+ &dbus_error, (const GVariant **) &details);
g_assert_error (error, TP_ERRORS, TP_ERROR_CAPTCHA_NOT_SUPPORTED);
g_assert_cmpstr (dbus_error, ==, TP_ERROR_STR_CAPTCHA_NOT_SUPPORTED);
- g_assert_cmpuint (g_hash_table_size (details), ==, 0);
+ g_assert_cmpuint (g_variant_n_children (details), ==, 0);
}
static void
More information about the telepathy-commits
mailing list