mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-04 18:26:19 +01:00
GDBusProxy: Validate properties received from service if possible
If the proxy has an GInterfaceInfo set, validate properties against it so the application doesn't have to do it. Signed-off-by: David Zeuthen <davidz@redhat.com>
This commit is contained in:
parent
2809964c28
commit
aa59fb9dd1
@ -767,6 +767,36 @@ on_signal_received (GDBusConnection *connection,
|
|||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static void
|
||||||
|
insert_property_checked (GDBusProxy *proxy,
|
||||||
|
gchar *property_name,
|
||||||
|
GVariant *value)
|
||||||
|
{
|
||||||
|
if (proxy->priv->expected_interface != NULL)
|
||||||
|
{
|
||||||
|
const GDBusPropertyInfo *info;
|
||||||
|
|
||||||
|
info = g_dbus_interface_info_lookup_property (proxy->priv->expected_interface, property_name);
|
||||||
|
/* Ignore unknown properties */
|
||||||
|
if (info == NULL)
|
||||||
|
goto invalid;
|
||||||
|
|
||||||
|
/* Ignore properties with the wrong type */
|
||||||
|
if (g_strcmp0 (info->signature, g_variant_get_type_string (value)) != 0)
|
||||||
|
goto invalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_hash_table_insert (proxy->priv->properties,
|
||||||
|
property_name, /* adopts string */
|
||||||
|
value); /* adopts value */
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
invalid:
|
||||||
|
g_variant_unref (value);
|
||||||
|
g_free (property_name);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_properties_changed (GDBusConnection *connection,
|
on_properties_changed (GDBusConnection *connection,
|
||||||
const gchar *sender_name,
|
const gchar *sender_name,
|
||||||
@ -815,7 +845,7 @@ on_properties_changed (GDBusConnection *connection,
|
|||||||
g_variant_iter_init (&iter, changed_properties);
|
g_variant_iter_init (&iter, changed_properties);
|
||||||
while (g_variant_iter_next (&iter, "{sv}", &key, &value))
|
while (g_variant_iter_next (&iter, "{sv}", &key, &value))
|
||||||
{
|
{
|
||||||
g_hash_table_insert (proxy->priv->properties,
|
insert_property_checked (proxy,
|
||||||
key, /* adopts string */
|
key, /* adopts string */
|
||||||
value); /* adopts value */
|
value); /* adopts value */
|
||||||
}
|
}
|
||||||
@ -857,7 +887,7 @@ process_get_all_reply (GDBusProxy *proxy,
|
|||||||
g_variant_get (result, "(a{sv})", &iter);
|
g_variant_get (result, "(a{sv})", &iter);
|
||||||
while (g_variant_iter_next (iter, "{sv}", &key, &value))
|
while (g_variant_iter_next (iter, "{sv}", &key, &value))
|
||||||
{
|
{
|
||||||
g_hash_table_insert (proxy->priv->properties,
|
insert_property_checked (proxy,
|
||||||
key, /* adopts string */
|
key, /* adopts string */
|
||||||
value); /* adopts value */
|
value); /* adopts value */
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user