Integrate parts of meta-intel-iot-security
[AGL/meta-agl.git] / meta-security / recipes-core / dbus / dbus-cynara / 0002-New-a-sv-helper-for-using-byte-arrays-as-the-variant.patch
1 From 25cb15916402c55112cae2be0954d24afe74e2f2 Mon Sep 17 00:00:00 2001
2 From: Tyler Hicks <tyhicks@canonical.com>
3 Date: Thu, 13 Mar 2014 17:37:38 -0500
4 Subject: [PATCH 2/8] New a{sv} helper for using byte arrays as the variant
5
6 Create a new helper for using a byte array as the value in the mapping
7 from string to variant.
8
9 Bug: https://bugs.freedesktop.org/show_bug.cgi?id=75113
10 Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89041
11 Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
12 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
13 Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
14 ---
15  dbus/dbus-asv-util.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++
16  dbus/dbus-asv-util.h |  4 ++++
17  2 files changed, 58 insertions(+)
18
19 diff --git a/dbus/dbus-asv-util.c b/dbus/dbus-asv-util.c
20 index 583e41f..d3ac5e9 100644
21 --- a/dbus/dbus-asv-util.c
22 +++ b/dbus/dbus-asv-util.c
23 @@ -258,3 +258,57 @@ _dbus_asv_add_string (DBusMessageIter *arr_iter,
24  
25    return TRUE;
26  }
27 +
28 +/**
29 + * Create a new entry in an a{sv} (map from string to variant)
30 + * with a byte array value.
31 + *
32 + * If this function fails, the a{sv} must be abandoned, for instance
33 + * with _dbus_asv_abandon().
34 + *
35 + * @param arr_iter the iterator which is appending to the array
36 + * @param key a UTF-8 key for the map
37 + * @param value the value
38 + * @param n_elements the number of elements to append
39 + * @returns #TRUE on success, or #FALSE if not enough memory
40 + */
41 +dbus_bool_t
42 +_dbus_asv_add_byte_array (DBusMessageIter *arr_iter,
43 +                          const char      *key,
44 +                          const void      *value,
45 +                          int              n_elements)
46 +{
47 +  DBusMessageIter entry_iter;
48 +  DBusMessageIter var_iter;
49 +  DBusMessageIter byte_array_iter;
50 +
51 +  if (!_dbus_asv_open_entry (arr_iter, &entry_iter, key, "ay", &var_iter))
52 +    return FALSE;
53 +
54 +  if (!dbus_message_iter_open_container (&var_iter, DBUS_TYPE_ARRAY,
55 +                                         DBUS_TYPE_BYTE_AS_STRING,
56 +                                         &byte_array_iter))
57 +    {
58 +      _dbus_asv_abandon_entry (arr_iter, &entry_iter, &var_iter);
59 +      return FALSE;
60 +    }
61 +
62 +  if (!dbus_message_iter_append_fixed_array (&byte_array_iter, DBUS_TYPE_BYTE,
63 +                                             &value, n_elements))
64 +    {
65 +      dbus_message_iter_abandon_container (&var_iter, &byte_array_iter);
66 +      _dbus_asv_abandon_entry (arr_iter, &entry_iter, &var_iter);
67 +      return FALSE;
68 +    }
69 +
70 +  if (!dbus_message_iter_close_container (&var_iter, &byte_array_iter))
71 +    {
72 +      _dbus_asv_abandon_entry (arr_iter, &entry_iter, &var_iter);
73 +      return FALSE;
74 +    }
75 +
76 +  if (!_dbus_asv_close_entry (arr_iter, &entry_iter, &var_iter))
77 +    return FALSE;
78 +
79 +  return TRUE;
80 +}
81 diff --git a/dbus/dbus-asv-util.h b/dbus/dbus-asv-util.h
82 index 0337260..277ab80 100644
83 --- a/dbus/dbus-asv-util.h
84 +++ b/dbus/dbus-asv-util.h
85 @@ -42,5 +42,9 @@ dbus_bool_t  _dbus_asv_add_uint32        (DBusMessageIter *arr_iter,
86  dbus_bool_t  _dbus_asv_add_string        (DBusMessageIter *arr_iter,
87                                            const char      *key,
88                                            const char      *value);
89 +dbus_bool_t  _dbus_asv_add_byte_array    (DBusMessageIter *arr_iter,
90 +                                          const char      *key,
91 +                                          const void      *value,
92 +                                          int              n_elements);
93  
94  #endif
95 -- 
96 2.1.4
97