Line data Source code
1 : /*
2 : * WPA Supplicant / dbus-based control interface
3 : * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
4 : *
5 : * This software may be distributed under the terms of the BSD license.
6 : * See README for more details.
7 : */
8 :
9 : #ifndef DBUS_DICT_HELPERS_H
10 : #define DBUS_DICT_HELPERS_H
11 :
12 : #include "wpabuf.h"
13 :
14 : /*
15 : * Adding a dict to a DBusMessage
16 : */
17 :
18 : dbus_bool_t wpa_dbus_dict_open_write(DBusMessageIter *iter,
19 : DBusMessageIter *iter_dict);
20 :
21 : dbus_bool_t wpa_dbus_dict_close_write(DBusMessageIter *iter,
22 : DBusMessageIter *iter_dict);
23 :
24 : const char * wpa_dbus_type_as_string(const int type);
25 :
26 : dbus_bool_t wpa_dbus_dict_append_string(DBusMessageIter *iter_dict,
27 : const char *key, const char *value);
28 :
29 : dbus_bool_t wpa_dbus_dict_append_byte(DBusMessageIter *iter_dict,
30 : const char *key, const char value);
31 :
32 : dbus_bool_t wpa_dbus_dict_append_bool(DBusMessageIter *iter_dict,
33 : const char *key,
34 : const dbus_bool_t value);
35 :
36 : dbus_bool_t wpa_dbus_dict_append_int16(DBusMessageIter *iter_dict,
37 : const char *key,
38 : const dbus_int16_t value);
39 :
40 : dbus_bool_t wpa_dbus_dict_append_uint16(DBusMessageIter *iter_dict,
41 : const char *key,
42 : const dbus_uint16_t value);
43 :
44 : dbus_bool_t wpa_dbus_dict_append_int32(DBusMessageIter *iter_dict,
45 : const char *key,
46 : const dbus_int32_t value);
47 :
48 : dbus_bool_t wpa_dbus_dict_append_uint32(DBusMessageIter *iter_dict,
49 : const char *key,
50 : const dbus_uint32_t value);
51 :
52 : dbus_bool_t wpa_dbus_dict_append_int64(DBusMessageIter *iter_dict,
53 : const char *key,
54 : const dbus_int64_t value);
55 :
56 : dbus_bool_t wpa_dbus_dict_append_uint64(DBusMessageIter *iter_dict,
57 : const char *key,
58 : const dbus_uint64_t value);
59 :
60 : dbus_bool_t wpa_dbus_dict_append_double(DBusMessageIter *iter_dict,
61 : const char *key,
62 : const double value);
63 :
64 : dbus_bool_t wpa_dbus_dict_append_object_path(DBusMessageIter *iter_dict,
65 : const char *key,
66 : const char *value);
67 :
68 : dbus_bool_t wpa_dbus_dict_append_byte_array(DBusMessageIter *iter_dict,
69 : const char *key,
70 : const char *value,
71 : const dbus_uint32_t value_len);
72 :
73 : /* Manual construction and addition of array elements */
74 : dbus_bool_t wpa_dbus_dict_begin_array(DBusMessageIter *iter_dict,
75 : const char *key, const char *type,
76 : DBusMessageIter *iter_dict_entry,
77 : DBusMessageIter *iter_dict_val,
78 : DBusMessageIter *iter_array);
79 :
80 : dbus_bool_t wpa_dbus_dict_begin_string_array(DBusMessageIter *iter_dict,
81 : const char *key,
82 : DBusMessageIter *iter_dict_entry,
83 : DBusMessageIter *iter_dict_val,
84 : DBusMessageIter *iter_array);
85 :
86 : dbus_bool_t wpa_dbus_dict_string_array_add_element(DBusMessageIter *iter_array,
87 : const char *elem);
88 :
89 : dbus_bool_t wpa_dbus_dict_bin_array_add_element(DBusMessageIter *iter_array,
90 : const u8 *value,
91 : size_t value_len);
92 :
93 : dbus_bool_t wpa_dbus_dict_end_array(DBusMessageIter *iter_dict,
94 : DBusMessageIter *iter_dict_entry,
95 : DBusMessageIter *iter_dict_val,
96 : DBusMessageIter *iter_array);
97 :
98 : static inline dbus_bool_t
99 6935 : wpa_dbus_dict_end_string_array(DBusMessageIter *iter_dict,
100 : DBusMessageIter *iter_dict_entry,
101 : DBusMessageIter *iter_dict_val,
102 : DBusMessageIter *iter_array)
103 : {
104 6935 : return wpa_dbus_dict_end_array(iter_dict, iter_dict_entry,
105 : iter_dict_val, iter_array);
106 : }
107 :
108 : /* Convenience function to add a whole string list */
109 : dbus_bool_t wpa_dbus_dict_append_string_array(DBusMessageIter *iter_dict,
110 : const char *key,
111 : const char **items,
112 : const dbus_uint32_t num_items);
113 :
114 : dbus_bool_t wpa_dbus_dict_append_wpabuf_array(DBusMessageIter *iter_dict,
115 : const char *key,
116 : const struct wpabuf **items,
117 : const dbus_uint32_t num_items);
118 :
119 : /*
120 : * Reading a dict from a DBusMessage
121 : */
122 :
123 : /*
124 : * Used only in struct wpa_dbus_dict_entry::array_type internally to identify
125 : * special binary array case.
126 : */
127 : #define WPAS_DBUS_TYPE_BINARRAY ((int) '@')
128 :
129 : struct wpa_dbus_dict_entry {
130 : int type; /** the dbus type of the dict entry's value */
131 : int array_type; /** the dbus type of the array elements if the dict
132 : entry value contains an array, or the special
133 : WPAS_DBUS_TYPE_BINARRAY */
134 : const char *key; /** key of the dict entry */
135 :
136 : /** Possible values of the property */
137 : union {
138 : char *str_value;
139 : char byte_value;
140 : dbus_bool_t bool_value;
141 : dbus_int16_t int16_value;
142 : dbus_uint16_t uint16_value;
143 : dbus_int32_t int32_value;
144 : dbus_uint32_t uint32_value;
145 : dbus_int64_t int64_value;
146 : dbus_uint64_t uint64_value;
147 : double double_value;
148 : char *bytearray_value;
149 : char **strarray_value;
150 : struct wpabuf **binarray_value;
151 : };
152 : dbus_uint32_t array_len; /** length of the array if the dict entry's
153 : value contains an array */
154 : };
155 :
156 : dbus_bool_t wpa_dbus_dict_open_read(DBusMessageIter *iter,
157 : DBusMessageIter *iter_dict,
158 : DBusError *error);
159 :
160 : dbus_bool_t wpa_dbus_dict_get_entry(DBusMessageIter *iter_dict,
161 : struct wpa_dbus_dict_entry *entry);
162 :
163 : dbus_bool_t wpa_dbus_dict_has_dict_entry(DBusMessageIter *iter_dict);
164 :
165 : void wpa_dbus_dict_entry_clear(struct wpa_dbus_dict_entry *entry);
166 :
167 : #endif /* DBUS_DICT_HELPERS_H */
|