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