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_bool(DBusMessageIter *iter_dict, 30 const char *key, 31 const dbus_bool_t value); 32 33 dbus_bool_t wpa_dbus_dict_append_int16(DBusMessageIter *iter_dict, 34 const char *key, 35 const dbus_int16_t value); 36 37 dbus_bool_t wpa_dbus_dict_append_uint16(DBusMessageIter *iter_dict, 38 const char *key, 39 const dbus_uint16_t value); 40 41 dbus_bool_t wpa_dbus_dict_append_int32(DBusMessageIter *iter_dict, 42 const char *key, 43 const dbus_int32_t value); 44 45 dbus_bool_t wpa_dbus_dict_append_uint32(DBusMessageIter *iter_dict, 46 const char *key, 47 const dbus_uint32_t value); 48 49 dbus_bool_t wpa_dbus_dict_append_uint64(DBusMessageIter *iter_dict, 50 const char *key, 51 const dbus_uint64_t value); 52 53 dbus_bool_t wpa_dbus_dict_append_object_path(DBusMessageIter *iter_dict, 54 const char *key, 55 const char *value); 56 57 dbus_bool_t wpa_dbus_dict_append_byte_array(DBusMessageIter *iter_dict, 58 const char *key, 59 const char *value, 60 const dbus_uint32_t value_len); 61 62 dbus_bool_t wpa_dbus_dict_append_double(DBusMessageIter *iter_dict, 63 const char *key, 64 const double value); 65 66 /* Manual construction and addition of array elements */ 67 dbus_bool_t wpa_dbus_dict_begin_array(DBusMessageIter *iter_dict, 68 const char *key, const char *type, 69 DBusMessageIter *iter_dict_entry, 70 DBusMessageIter *iter_dict_val, 71 DBusMessageIter *iter_array); 72 73 dbus_bool_t wpa_dbus_dict_begin_string_array(DBusMessageIter *iter_dict, 74 const char *key, 75 DBusMessageIter *iter_dict_entry, 76 DBusMessageIter *iter_dict_val, 77 DBusMessageIter *iter_array); 78 79 dbus_bool_t wpa_dbus_dict_string_array_add_element(DBusMessageIter *iter_array, 80 const char *elem); 81 82 dbus_bool_t wpa_dbus_dict_bin_array_add_element(DBusMessageIter *iter_array, 83 const u8 *value, 84 size_t value_len); 85 86 dbus_bool_t wpa_dbus_dict_end_array(DBusMessageIter *iter_dict, 87 DBusMessageIter *iter_dict_entry, 88 DBusMessageIter *iter_dict_val, 89 DBusMessageIter *iter_array); 90 91 static inline dbus_bool_t 92 wpa_dbus_dict_end_string_array(DBusMessageIter *iter_dict, 93 DBusMessageIter *iter_dict_entry, 94 DBusMessageIter *iter_dict_val, 95 DBusMessageIter *iter_array) 96 { 97 return wpa_dbus_dict_end_array(iter_dict, iter_dict_entry, 98 iter_dict_val, iter_array); 99 } 100 101 /* Convenience function to add a whole string list */ 102 dbus_bool_t wpa_dbus_dict_append_string_array(DBusMessageIter *iter_dict, 103 const char *key, 104 const char **items, 105 const dbus_uint32_t num_items); 106 107 dbus_bool_t wpa_dbus_dict_append_wpabuf_array(DBusMessageIter *iter_dict, 108 const char *key, 109 const struct wpabuf **items, 110 const dbus_uint32_t num_items); 111 112 /* 113 * Reading a dict from a DBusMessage 114 */ 115 116 /* 117 * Used only in struct wpa_dbus_dict_entry::array_type internally to identify 118 * special binary array case. 119 */ 120 #define WPAS_DBUS_TYPE_BINARRAY ((int) '@') 121 122 struct wpa_dbus_dict_entry { 123 int type; /** the dbus type of the dict entry's value */ 124 int array_type; /** the dbus type of the array elements if the dict 125 entry value contains an array, or the special 126 WPAS_DBUS_TYPE_BINARRAY */ 127 const char *key; /** key of the dict entry */ 128 129 /** Possible values of the property */ 130 union { 131 char *str_value; 132 char byte_value; 133 dbus_bool_t bool_value; 134 dbus_int16_t int16_value; 135 dbus_uint16_t uint16_value; 136 dbus_int32_t int32_value; 137 dbus_uint32_t uint32_value; 138 dbus_int64_t int64_value; 139 dbus_uint64_t uint64_value; 140 double double_value; 141 char *bytearray_value; 142 dbus_uint16_t *uint16array_value; 143 char **strarray_value; 144 struct wpabuf **binarray_value; 145 }; 146 dbus_uint32_t array_len; /** length of the array if the dict entry's 147 value contains an array */ 148 }; 149 150 dbus_bool_t wpa_dbus_dict_open_read(DBusMessageIter *iter, 151 DBusMessageIter *iter_dict, 152 DBusError *error); 153 154 dbus_bool_t wpa_dbus_dict_get_entry(DBusMessageIter *iter_dict, 155 struct wpa_dbus_dict_entry *entry); 156 157 dbus_bool_t wpa_dbus_dict_has_dict_entry(DBusMessageIter *iter_dict); 158 159 void wpa_dbus_dict_entry_clear(struct wpa_dbus_dict_entry *entry); 160 161 #endif /* DBUS_DICT_HELPERS_H */ 162