dbus: Remove separate access variable from properties

The read, write, read-write permissions can be figured out from
getter/setter function pointers, so there is no need for maintaining
that information separately.
This commit is contained in:
Jouni Malinen 2011-08-07 11:16:05 +03:00
parent d26e45a44a
commit 3320666494
4 changed files with 62 additions and 90 deletions

View file

@ -1662,30 +1662,25 @@ static const struct wpa_dbus_method_desc wpas_dbus_global_methods[] = {
static const struct wpa_dbus_property_desc wpas_dbus_global_properties[] = { static const struct wpa_dbus_property_desc wpas_dbus_global_properties[] = {
{ "DebugLevel", WPAS_DBUS_NEW_INTERFACE, "s", { "DebugLevel", WPAS_DBUS_NEW_INTERFACE, "s",
wpas_dbus_getter_debug_level, wpas_dbus_getter_debug_level,
wpas_dbus_setter_debug_level, wpas_dbus_setter_debug_level
RW
}, },
{ "DebugTimestamp", WPAS_DBUS_NEW_INTERFACE, "b", { "DebugTimestamp", WPAS_DBUS_NEW_INTERFACE, "b",
wpas_dbus_getter_debug_timestamp, wpas_dbus_getter_debug_timestamp,
wpas_dbus_setter_debug_timestamp, wpas_dbus_setter_debug_timestamp
RW
}, },
{ "DebugShowKeys", WPAS_DBUS_NEW_INTERFACE, "b", { "DebugShowKeys", WPAS_DBUS_NEW_INTERFACE, "b",
wpas_dbus_getter_debug_show_keys, wpas_dbus_getter_debug_show_keys,
wpas_dbus_setter_debug_show_keys, wpas_dbus_setter_debug_show_keys
RW
}, },
{ "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao", { "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao",
wpas_dbus_getter_interfaces, wpas_dbus_getter_interfaces,
NULL, NULL
R
}, },
{ "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as", { "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as",
wpas_dbus_getter_eap_methods, wpas_dbus_getter_eap_methods,
NULL, NULL
R
}, },
{ NULL, NULL, NULL, NULL, NULL, 0 } { NULL, NULL, NULL, NULL, NULL }
}; };
static const struct wpa_dbus_signal_desc wpas_dbus_global_signals[] = { static const struct wpa_dbus_signal_desc wpas_dbus_global_signals[] = {
@ -1779,15 +1774,13 @@ static void wpa_dbus_free(void *ptr)
static const struct wpa_dbus_property_desc wpas_dbus_network_properties[] = { static const struct wpa_dbus_property_desc wpas_dbus_network_properties[] = {
{ "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}", { "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}",
wpas_dbus_getter_network_properties, wpas_dbus_getter_network_properties,
wpas_dbus_setter_network_properties, wpas_dbus_setter_network_properties
RW
}, },
{ "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b", { "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b",
wpas_dbus_getter_enabled, wpas_dbus_getter_enabled,
wpas_dbus_setter_enabled, wpas_dbus_setter_enabled
RW
}, },
{ NULL, NULL, NULL, NULL, NULL, 0 } { NULL, NULL, NULL, NULL, NULL }
}; };
@ -1926,55 +1919,45 @@ int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
static const struct wpa_dbus_property_desc wpas_dbus_bss_properties[] = { static const struct wpa_dbus_property_desc wpas_dbus_bss_properties[] = {
{ "SSID", WPAS_DBUS_NEW_IFACE_BSS, "ay", { "SSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
wpas_dbus_getter_bss_ssid, wpas_dbus_getter_bss_ssid,
NULL, NULL
R
}, },
{ "BSSID", WPAS_DBUS_NEW_IFACE_BSS, "ay", { "BSSID", WPAS_DBUS_NEW_IFACE_BSS, "ay",
wpas_dbus_getter_bss_bssid, wpas_dbus_getter_bss_bssid,
NULL, NULL
R
}, },
{ "Privacy", WPAS_DBUS_NEW_IFACE_BSS, "b", { "Privacy", WPAS_DBUS_NEW_IFACE_BSS, "b",
wpas_dbus_getter_bss_privacy, wpas_dbus_getter_bss_privacy,
NULL, NULL
R
}, },
{ "Mode", WPAS_DBUS_NEW_IFACE_BSS, "s", { "Mode", WPAS_DBUS_NEW_IFACE_BSS, "s",
wpas_dbus_getter_bss_mode, wpas_dbus_getter_bss_mode,
NULL, NULL
R
}, },
{ "Signal", WPAS_DBUS_NEW_IFACE_BSS, "n", { "Signal", WPAS_DBUS_NEW_IFACE_BSS, "n",
wpas_dbus_getter_bss_signal, wpas_dbus_getter_bss_signal,
NULL, NULL
R
}, },
{ "Frequency", WPAS_DBUS_NEW_IFACE_BSS, "q", { "Frequency", WPAS_DBUS_NEW_IFACE_BSS, "q",
wpas_dbus_getter_bss_frequency, wpas_dbus_getter_bss_frequency,
NULL, NULL
R
}, },
{ "Rates", WPAS_DBUS_NEW_IFACE_BSS, "au", { "Rates", WPAS_DBUS_NEW_IFACE_BSS, "au",
wpas_dbus_getter_bss_rates, wpas_dbus_getter_bss_rates,
NULL, NULL
R
}, },
{ "WPA", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}", { "WPA", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
wpas_dbus_getter_bss_wpa, wpas_dbus_getter_bss_wpa,
NULL, NULL
R
}, },
{ "RSN", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}", { "RSN", WPAS_DBUS_NEW_IFACE_BSS, "a{sv}",
wpas_dbus_getter_bss_rsn, wpas_dbus_getter_bss_rsn,
NULL, NULL
R
}, },
{ "IEs", WPAS_DBUS_NEW_IFACE_BSS, "ay", { "IEs", WPAS_DBUS_NEW_IFACE_BSS, "ay",
wpas_dbus_getter_bss_ies, wpas_dbus_getter_bss_ies,
NULL, NULL
R
}, },
{ NULL, NULL, NULL, NULL, NULL, 0 } { NULL, NULL, NULL, NULL, NULL }
}; };
@ -2355,107 +2338,101 @@ static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = { static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
{ "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}", { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
wpas_dbus_getter_capabilities, wpas_dbus_getter_capabilities,
NULL, R NULL
}, },
{ "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s", { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
wpas_dbus_getter_state, wpas_dbus_getter_state,
NULL, R NULL
}, },
{ "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b", { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
wpas_dbus_getter_scanning, wpas_dbus_getter_scanning,
NULL, R NULL
}, },
{ "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u", { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
wpas_dbus_getter_ap_scan, wpas_dbus_getter_ap_scan,
wpas_dbus_setter_ap_scan, wpas_dbus_setter_ap_scan
RW
}, },
{ "BSSExpireAge", WPAS_DBUS_NEW_IFACE_INTERFACE, "u", { "BSSExpireAge", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
wpas_dbus_getter_bss_expire_age, wpas_dbus_getter_bss_expire_age,
wpas_dbus_setter_bss_expire_age, wpas_dbus_setter_bss_expire_age
RW
}, },
{ "BSSExpireCount", WPAS_DBUS_NEW_IFACE_INTERFACE, "u", { "BSSExpireCount", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
wpas_dbus_getter_bss_expire_count, wpas_dbus_getter_bss_expire_count,
wpas_dbus_setter_bss_expire_count, wpas_dbus_setter_bss_expire_count
RW
}, },
{ "Country", WPAS_DBUS_NEW_IFACE_INTERFACE, "s", { "Country", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
wpas_dbus_getter_country, wpas_dbus_getter_country,
wpas_dbus_setter_country, wpas_dbus_setter_country
RW
}, },
{ "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s", { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
wpas_dbus_getter_ifname, wpas_dbus_getter_ifname,
NULL, R NULL
}, },
{ "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s", { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
wpas_dbus_getter_driver, wpas_dbus_getter_driver,
NULL, R NULL
}, },
{ "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s", { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
wpas_dbus_getter_bridge_ifname, wpas_dbus_getter_bridge_ifname,
NULL, R NULL
}, },
{ "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o", { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
wpas_dbus_getter_current_bss, wpas_dbus_getter_current_bss,
NULL, R NULL
}, },
{ "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o", { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
wpas_dbus_getter_current_network, wpas_dbus_getter_current_network,
NULL, R NULL
}, },
{ "CurrentAuthMode", WPAS_DBUS_NEW_IFACE_INTERFACE, "s", { "CurrentAuthMode", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
wpas_dbus_getter_current_auth_mode, wpas_dbus_getter_current_auth_mode,
NULL, R NULL
}, },
{ "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}", { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
wpas_dbus_getter_blobs, wpas_dbus_getter_blobs,
NULL, R NULL
}, },
{ "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao", { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
wpas_dbus_getter_bsss, wpas_dbus_getter_bsss,
NULL, R NULL
}, },
{ "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao", { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
wpas_dbus_getter_networks, wpas_dbus_getter_networks,
NULL, R NULL
}, },
#ifdef CONFIG_WPS #ifdef CONFIG_WPS
{ "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b", { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
wpas_dbus_getter_process_credentials, wpas_dbus_getter_process_credentials,
wpas_dbus_setter_process_credentials, wpas_dbus_setter_process_credentials
RW
}, },
#endif /* CONFIG_WPS */ #endif /* CONFIG_WPS */
#ifdef CONFIG_P2P #ifdef CONFIG_P2P
{ "P2PDeviceProperties", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "a{sv}", { "P2PDeviceProperties", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "a{sv}",
wpas_dbus_getter_p2p_device_properties, wpas_dbus_getter_p2p_device_properties,
wpas_dbus_setter_p2p_device_properties, wpas_dbus_setter_p2p_device_properties
RW
}, },
{ "Peers", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao", { "Peers", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
wpas_dbus_getter_p2p_peers, wpas_dbus_getter_p2p_peers,
NULL, R NULL
}, },
{ "Role", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "s", { "Role", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "s",
wpas_dbus_getter_p2p_role, wpas_dbus_getter_p2p_role,
NULL, R NULL
}, },
{ "Group", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o", { "Group", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
wpas_dbus_getter_p2p_group, wpas_dbus_getter_p2p_group,
NULL, R NULL
}, },
{ "PeerGO", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o", { "PeerGO", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "o",
wpas_dbus_getter_p2p_peergo, wpas_dbus_getter_p2p_peergo,
NULL, R NULL
}, },
{ "PersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao", { "PersistentGroups", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
wpas_dbus_getter_persistent_groups, wpas_dbus_getter_persistent_groups,
NULL, R NULL
}, },
#endif /* CONFIG_P2P */ #endif /* CONFIG_P2P */
{ NULL, NULL, NULL, NULL, NULL, 0 } { NULL, NULL, NULL, NULL, NULL }
}; };
static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = { static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
@ -2761,13 +2738,13 @@ int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = { static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
{ "Properties", WPAS_DBUS_NEW_IFACE_P2P_PEER, "a{sv}", { "Properties", WPAS_DBUS_NEW_IFACE_P2P_PEER, "a{sv}",
wpas_dbus_getter_p2p_peer_properties, wpas_dbus_getter_p2p_peer_properties,
NULL, R NULL
}, },
{ "IEs", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay", { "IEs", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
wpas_dbus_getter_p2p_peer_ies, wpas_dbus_getter_p2p_peer_ies,
NULL, R NULL
}, },
{ NULL, NULL, NULL, NULL, NULL, 0 } { NULL, NULL, NULL, NULL, NULL }
}; };
static const struct wpa_dbus_signal_desc wpas_dbus_p2p_peer_signals[] = { static const struct wpa_dbus_signal_desc wpas_dbus_p2p_peer_signals[] = {
@ -2958,15 +2935,14 @@ int wpas_dbus_unregister_peer(struct wpa_supplicant *wpa_s,
static const struct wpa_dbus_property_desc wpas_dbus_p2p_group_properties[] = { static const struct wpa_dbus_property_desc wpas_dbus_p2p_group_properties[] = {
{ "Members", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ao", { "Members", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ao",
wpas_dbus_getter_p2p_group_members, wpas_dbus_getter_p2p_group_members,
NULL, R NULL
}, },
{ "Properties", { "Properties",
WPAS_DBUS_NEW_IFACE_P2P_GROUP, "a{sv}", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "a{sv}",
wpas_dbus_getter_p2p_group_properties, wpas_dbus_getter_p2p_group_properties,
wpas_dbus_setter_p2p_group_properties, wpas_dbus_setter_p2p_group_properties
RW
}, },
{ NULL, NULL, NULL, NULL, NULL, 0 } { NULL, NULL, NULL, NULL, NULL }
}; };
static const struct wpa_dbus_signal_desc wpas_dbus_p2p_group_signals[] = { static const struct wpa_dbus_signal_desc wpas_dbus_p2p_group_signals[] = {
@ -3088,9 +3064,9 @@ static const struct wpa_dbus_property_desc
wpas_dbus_p2p_groupmember_properties[] = { wpas_dbus_p2p_groupmember_properties[] = {
{ "Properties", WPAS_DBUS_NEW_IFACE_P2P_GROUPMEMBER, "a{sv}", { "Properties", WPAS_DBUS_NEW_IFACE_P2P_GROUPMEMBER, "a{sv}",
wpas_dbus_getter_p2p_group_properties, wpas_dbus_getter_p2p_group_properties,
NULL, R NULL
}, },
{ NULL, NULL, NULL, NULL, NULL, 0 } { NULL, NULL, NULL, NULL, NULL }
}; };
/** /**
@ -3195,10 +3171,9 @@ static const struct wpa_dbus_property_desc
wpas_dbus_persistent_group_properties[] = { wpas_dbus_persistent_group_properties[] = {
{ "Properties", WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, "a{sv}", { "Properties", WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, "a{sv}",
wpas_dbus_getter_persistent_group_properties, wpas_dbus_getter_persistent_group_properties,
wpas_dbus_setter_persistent_group_properties, wpas_dbus_setter_persistent_group_properties
RW
}, },
{ NULL, NULL, NULL, NULL, NULL, 0 } { NULL, NULL, NULL, NULL, NULL }
}; };
/* No signals intended for persistent group objects */ /* No signals intended for persistent group objects */

View file

@ -38,8 +38,8 @@ static dbus_bool_t fill_dict_with_properties(
WPAS_DBUS_INTERFACE_MAX) != 0) WPAS_DBUS_INTERFACE_MAX) != 0)
continue; continue;
/* Handle access permissions or missing getter */ /* Skip write-only properties */
if (dsc->getter == NULL || dsc->access == W) if (dsc->getter == NULL)
continue; continue;
if (!dbus_message_iter_open_container(dict_iter, if (!dbus_message_iter_open_container(dict_iter,
@ -173,7 +173,7 @@ static DBusMessage * properties_get(DBusMessage *message,
NULL); NULL);
} }
if (dsc->access == W || dsc->getter == NULL) { if (dsc->getter == NULL) {
return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS, return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
"Property is write-only"); "Property is write-only");
} }
@ -207,7 +207,7 @@ static DBusMessage * properties_set(DBusMessage *message,
NULL); NULL);
} }
if (dsc->access == R || dsc->setter == NULL) { if (dsc->setter == NULL) {
return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS, return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
"Property is read-only"); "Property is read-only");
} }

View file

@ -45,8 +45,6 @@ struct wpa_dbus_object_desc {
WPADBusArgumentFreeFunction user_data_free_func; WPADBusArgumentFreeFunction user_data_free_func;
}; };
enum dbus_prop_access { R, W, RW };
enum dbus_arg_direction { ARG_IN, ARG_OUT }; enum dbus_arg_direction { ARG_IN, ARG_OUT };
struct wpa_dbus_argument { struct wpa_dbus_argument {
@ -97,8 +95,6 @@ struct wpa_dbus_property_desc {
WPADBusPropertyAccessor getter; WPADBusPropertyAccessor getter;
/* property setter function */ /* property setter function */
WPADBusPropertyAccessor setter; WPADBusPropertyAccessor setter;
/* property access permissions */
enum dbus_prop_access access;
}; };

View file

@ -89,10 +89,11 @@ static void add_entry(struct wpabuf *xml, const char *type, const char *name,
static void add_property(struct wpabuf *xml, static void add_property(struct wpabuf *xml,
const struct wpa_dbus_property_desc *dsc) const struct wpa_dbus_property_desc *dsc)
{ {
wpabuf_printf(xml, "<property name=\"%s\" type=\"%s\" access=\"%s\"/>", wpabuf_printf(xml, "<property name=\"%s\" type=\"%s\" "
"access=\"%s%s\"/>",
dsc->dbus_property, dsc->type, dsc->dbus_property, dsc->type,
(dsc->access == R ? "read" : dsc->getter ? "read" : "",
(dsc->access == W ? "write" : "readwrite"))); dsc->setter ? "write" : "");
} }