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_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 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 	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 #define WPAS_DBUS_TYPE_BINARRAY (DBUS_NUMBER_OF_TYPES + 100)
    124 
    125 struct wpa_dbus_dict_entry {
    126 	int type;         /** the dbus type of the dict entry's value */
    127 	int array_type;   /** the dbus type of the array elements if the dict
    128 			      entry value contains an array, or the special
    129 			      WPAS_DBUS_TYPE_BINARRAY */
    130 	const char *key;  /** key of the dict entry */
    131 
    132 	/** Possible values of the property */
    133 	union {
    134 		char *str_value;
    135 		char byte_value;
    136 		dbus_bool_t bool_value;
    137 		dbus_int16_t int16_value;
    138 		dbus_uint16_t uint16_value;
    139 		dbus_int32_t int32_value;
    140 		dbus_uint32_t uint32_value;
    141 		dbus_int64_t int64_value;
    142 		dbus_uint64_t uint64_value;
    143 		double double_value;
    144 		char *bytearray_value;
    145 		char **strarray_value;
    146 		struct wpabuf **binarray_value;
    147 	};
    148 	dbus_uint32_t array_len; /** length of the array if the dict entry's
    149 				     value contains an array */
    150 };
    151 
    152 dbus_bool_t wpa_dbus_dict_open_read(DBusMessageIter *iter,
    153 				    DBusMessageIter *iter_dict,
    154 				    DBusError *error);
    155 
    156 dbus_bool_t wpa_dbus_dict_get_entry(DBusMessageIter *iter_dict,
    157 				    struct wpa_dbus_dict_entry *entry);
    158 
    159 dbus_bool_t wpa_dbus_dict_has_dict_entry(DBusMessageIter *iter_dict);
    160 
    161 void wpa_dbus_dict_entry_clear(struct wpa_dbus_dict_entry *entry);
    162 
    163 #endif  /* DBUS_DICT_HELPERS_H */
    164