1 /* 2 * WPA Supplicant / dbus-based control interface 3 * Copyright (c) 2006, Dan Williams <dcbw@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 /* 19 * Adding a dict to a DBusMessage 20 */ 21 22 dbus_bool_t wpa_dbus_dict_open_write(DBusMessageIter *iter, 23 DBusMessageIter *iter_dict); 24 25 dbus_bool_t wpa_dbus_dict_close_write(DBusMessageIter *iter, 26 DBusMessageIter *iter_dict); 27 28 const char * wpa_dbus_type_as_string(const int type); 29 30 dbus_bool_t wpa_dbus_dict_append_string(DBusMessageIter *iter_dict, 31 const char *key, const char *value); 32 33 dbus_bool_t wpa_dbus_dict_append_byte(DBusMessageIter *iter_dict, 34 const char *key, const char value); 35 36 dbus_bool_t wpa_dbus_dict_append_bool(DBusMessageIter *iter_dict, 37 const char *key, 38 const dbus_bool_t value); 39 40 dbus_bool_t wpa_dbus_dict_append_int16(DBusMessageIter *iter_dict, 41 const char *key, 42 const dbus_int16_t value); 43 44 dbus_bool_t wpa_dbus_dict_append_uint16(DBusMessageIter *iter_dict, 45 const char *key, 46 const dbus_uint16_t value); 47 48 dbus_bool_t wpa_dbus_dict_append_int32(DBusMessageIter *iter_dict, 49 const char *key, 50 const dbus_int32_t value); 51 52 dbus_bool_t wpa_dbus_dict_append_uint32(DBusMessageIter *iter_dict, 53 const char *key, 54 const dbus_uint32_t value); 55 56 dbus_bool_t wpa_dbus_dict_append_int64(DBusMessageIter *iter_dict, 57 const char *key, 58 const dbus_int64_t value); 59 60 dbus_bool_t wpa_dbus_dict_append_uint64(DBusMessageIter *iter_dict, 61 const char *key, 62 const dbus_uint64_t value); 63 64 dbus_bool_t wpa_dbus_dict_append_double(DBusMessageIter *iter_dict, 65 const char *key, 66 const double value); 67 68 dbus_bool_t wpa_dbus_dict_append_object_path(DBusMessageIter *iter_dict, 69 const char *key, 70 const char *value); 71 72 dbus_bool_t wpa_dbus_dict_append_byte_array(DBusMessageIter *iter_dict, 73 const char *key, 74 const char *value, 75 const dbus_uint32_t value_len); 76 77 /* Manual construction and addition of string array elements */ 78 dbus_bool_t wpa_dbus_dict_begin_string_array(DBusMessageIter *iter_dict, 79 const char *key, 80 DBusMessageIter *iter_dict_entry, 81 DBusMessageIter *iter_dict_val, 82 DBusMessageIter *iter_array); 83 84 dbus_bool_t wpa_dbus_dict_string_array_add_element(DBusMessageIter *iter_array, 85 const char *elem); 86 87 dbus_bool_t wpa_dbus_dict_end_string_array(DBusMessageIter *iter_dict, 88 DBusMessageIter *iter_dict_entry, 89 DBusMessageIter *iter_dict_val, 90 DBusMessageIter *iter_array); 91 92 /* Convenience function to add a whole string list */ 93 dbus_bool_t wpa_dbus_dict_append_string_array(DBusMessageIter *iter_dict, 94 const char *key, 95 const char **items, 96 const dbus_uint32_t num_items); 97 98 /* 99 * Reading a dict from a DBusMessage 100 */ 101 102 struct wpa_dbus_dict_entry { 103 int type; /** the dbus type of the dict entry's value */ 104 int array_type; /** the dbus type of the array elements if the dict 105 entry value contains an array */ 106 const char *key; /** key of the dict entry */ 107 108 /** Possible values of the property */ 109 union { 110 char *str_value; 111 char byte_value; 112 dbus_bool_t bool_value; 113 dbus_int16_t int16_value; 114 dbus_uint16_t uint16_value; 115 dbus_int32_t int32_value; 116 dbus_uint32_t uint32_value; 117 dbus_int64_t int64_value; 118 dbus_uint64_t uint64_value; 119 double double_value; 120 char *bytearray_value; 121 char **strarray_value; 122 }; 123 dbus_uint32_t array_len; /** length of the array if the dict entry's 124 value contains an array */ 125 }; 126 127 dbus_bool_t wpa_dbus_dict_open_read(DBusMessageIter *iter, 128 DBusMessageIter *iter_dict); 129 130 dbus_bool_t wpa_dbus_dict_get_entry(DBusMessageIter *iter_dict, 131 struct wpa_dbus_dict_entry *entry); 132 133 dbus_bool_t wpa_dbus_dict_has_dict_entry(DBusMessageIter *iter_dict); 134 135 void wpa_dbus_dict_entry_clear(struct wpa_dbus_dict_entry *entry); 136 137 #endif /* DBUS_DICT_HELPERS_H */ 138