[jsonrpc-glib] message: handle av encoded string arrays
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [jsonrpc-glib] message: handle av encoded string arrays
- Date: Fri, 20 Apr 2018 08:13:16 +0000 (UTC)
commit d6cfdc2a47f4d9d7d9ce5a56953c4f207cf858bb
Author: Christian Hergert <chergert redhat com>
Date: Fri Apr 20 01:13:54 2018 -0700
message: handle av encoded string arrays
We get these from json-glib, so try to unwrap them too.
src/jsonrpc-message.c | 35 ++++++++++++++++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
---
diff --git a/src/jsonrpc-message.c b/src/jsonrpc-message.c
index 5ba4df5..e72694c 100644
--- a/src/jsonrpc-message.c
+++ b/src/jsonrpc-message.c
@@ -384,7 +384,40 @@ jsonrpc_message_parse_object (GVariantDict *dict,
}
}
else if (IS_GET_STRV (valptr))
- ret = g_variant_dict_lookup (dict, key, "^as", ((JsonrpcMessageGetStrv *)valptr)->valptr);
+ {
+ g_autoptr(GVariant) v = g_variant_dict_lookup_value (dict, key, NULL);
+
+ if (v != NULL)
+ {
+ if (g_variant_is_of_type (v, G_VARIANT_TYPE ("as")))
+ {
+ *((JsonrpcMessageGetStrv *)valptr)->valptr = g_variant_dup_strv (v, NULL);
+ ret = TRUE;
+ }
+ else if (g_variant_is_of_type (v, G_VARIANT_TYPE ("av")))
+ {
+ GPtrArray *ar = g_ptr_array_new ();
+ GVariantIter iter;
+ GVariant *item;
+
+ g_variant_iter_init (&iter, v);
+ while ((item = g_variant_iter_next_value (&iter)))
+ {
+ GVariant *unwrap = g_variant_get_variant (item);
+
+ if (g_variant_is_of_type (unwrap, G_VARIANT_TYPE_STRING))
+ g_ptr_array_add (ar, g_variant_dup_string (unwrap, NULL));
+
+ g_variant_unref (unwrap);
+ g_variant_unref (item);
+ }
+ g_ptr_array_add (ar, NULL);
+
+ *((JsonrpcMessageGetStrv *)valptr)->valptr = (gchar **)g_ptr_array_free (ar, FALSE);
+ ret = TRUE;
+ }
+ }
+ }
else if (IS_GET_INT32 (valptr))
ret = g_variant_dict_lookup (dict, key, "i", ((JsonrpcMessageGetInt32 *)valptr)->valptr);
else if (IS_GET_INT64 (valptr))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]