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