diff options
author | Thomas Haller <thaller@redhat.com> | 2020-03-03 13:09:25 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-03-12 10:16:22 +0100 |
commit | 4cfed38135b444c551d4cdce0df7331f263db78d (patch) | |
tree | e74cea4ee8ae2a436f0ec27f5d7c80cae022343d | |
parent | b83f07916a540d482dfabbb13744083b0b6ab8b0 (diff) | |
download | NetworkManager-4cfed38135b444c551d4cdce0df7331f263db78d.tar.gz |
wifi: expose NMRefString for nm_wifi_ap_get_supplicant_path()
We internally track the string as NMRefString. Expose it, so that
users can directly use the reference counted string.
-rw-r--r-- | src/devices/wifi/nm-device-iwd.c | 15 | ||||
-rw-r--r-- | src/devices/wifi/nm-device-wifi.c | 4 | ||||
-rw-r--r-- | src/devices/wifi/nm-iwd-manager.c | 3 | ||||
-rw-r--r-- | src/devices/wifi/nm-wifi-ap.c | 30 | ||||
-rw-r--r-- | src/devices/wifi/nm-wifi-ap.h | 13 |
5 files changed, 34 insertions, 31 deletions
diff --git a/src/devices/wifi/nm-device-iwd.c b/src/devices/wifi/nm-device-iwd.c index 0cf7f5125d..a6cd817f72 100644 --- a/src/devices/wifi/nm-device-iwd.c +++ b/src/devices/wifi/nm-device-iwd.c @@ -229,6 +229,8 @@ insert_ap_from_network (NMDeviceIwd *self, NMWifiAP *ap; gs_unref_bytes GBytes *ssid = NULL; + bss_path = nm_ref_string_new (path); + if (g_hash_table_lookup (aps, path)) { _LOGD (LOGD_WIFI, "Duplicate network at %s", path); return; @@ -272,7 +274,6 @@ insert_ap_from_network (NMDeviceIwd *self, bssid[5] = ap_id; ssid = g_bytes_new (name, NM_MIN (32u, strlen (name))); - bss_path = nm_ref_string_new (path); bss_info = (NMSupplicantBssInfo) { .bss_path = bss_path, @@ -289,7 +290,9 @@ insert_ap_from_network (NMDeviceIwd *self, ap = nm_wifi_ap_new_from_properties (&bss_info); - g_hash_table_insert (aps, (gpointer) nm_wifi_ap_get_supplicant_path (ap), ap); + nm_assert (bss_path == nm_wifi_ap_get_supplicant_path (ap)); + + g_hash_table_insert (aps, bss_path, ap); } static void @@ -333,7 +336,7 @@ get_ordered_networks_cb (GObject *source, GAsyncResult *res, gpointer user_data) return; } - new_aps = g_hash_table_new_full (nm_str_hash, g_str_equal, NULL, g_object_unref); + new_aps = g_hash_table_new_full (nm_direct_hash, NULL, NULL, g_object_unref); g_variant_get (variant, return_sig, &networks); @@ -568,7 +571,7 @@ is_ap_known_network (NMWifiAP *ap) gs_unref_variant GVariant *known_network = NULL; network_proxy = nm_iwd_manager_get_dbus_interface (nm_iwd_manager_get (), - nm_wifi_ap_get_supplicant_path (ap), + nm_ref_string_get_str (nm_wifi_ap_get_supplicant_path (ap)), NM_IWD_NETWORK_INTERFACE); if (!network_proxy) return FALSE; @@ -1810,12 +1813,12 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason) } network_proxy = nm_iwd_manager_get_dbus_interface (nm_iwd_manager_get (), - nm_wifi_ap_get_supplicant_path (ap), + nm_ref_string_get_str (nm_wifi_ap_get_supplicant_path (ap)), NM_IWD_NETWORK_INTERFACE); if (!network_proxy) { _LOGE (LOGD_DEVICE | LOGD_WIFI, "Activation: (wifi) could not get Network interface proxy for %s", - nm_wifi_ap_get_supplicant_path (ap)); + nm_ref_string_get_str (nm_wifi_ap_get_supplicant_path (ap))); NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED); goto out; } diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 1beeb4becf..a00ac6aecb 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -1592,7 +1592,7 @@ supplicant_iface_bss_changed_cb (NMSupplicantInterface *iface, NMWifiAP *found_ap; GBytes *ssid; - found_ap = nm_wifi_aps_find_by_supplicant_path (&priv->aps_lst_head, bss_info->bss_path->str); + found_ap = nm_wifi_aps_find_by_supplicant_path (&priv->aps_lst_head, bss_info->bss_path); if (!is_present) { if (!found_ap) @@ -2222,7 +2222,7 @@ supplicant_iface_notify_current_bss (NMSupplicantInterface *iface, current_bss = nm_supplicant_interface_get_current_bss (iface); if (current_bss) - new_ap = nm_wifi_aps_find_by_supplicant_path (&priv->aps_lst_head, current_bss->str); + new_ap = nm_wifi_aps_find_by_supplicant_path (&priv->aps_lst_head, current_bss); if (new_ap != priv->current_ap) { const char *new_bssid = NULL; diff --git a/src/devices/wifi/nm-iwd-manager.c b/src/devices/wifi/nm-iwd-manager.c index 470cb1c902..39c863a31e 100644 --- a/src/devices/wifi/nm-iwd-manager.c +++ b/src/devices/wifi/nm-iwd-manager.c @@ -874,7 +874,8 @@ nm_iwd_manager_is_known_network (NMIwdManager *self, const char *name, } GDBusProxy * -nm_iwd_manager_get_dbus_interface (NMIwdManager *self, const char *path, +nm_iwd_manager_get_dbus_interface (NMIwdManager *self, + const char *path, const char *name) { NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE (self); diff --git a/src/devices/wifi/nm-wifi-ap.c b/src/devices/wifi/nm-wifi-ap.c index ef0c70cc7f..c5be51750a 100644 --- a/src/devices/wifi/nm-wifi-ap.c +++ b/src/devices/wifi/nm-wifi-ap.c @@ -40,8 +40,6 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMWifiAP, ); struct _NMWifiAPPrivate { - NMRefString *supplicant_path; - /* Scanned or cached values */ GBytes * ssid; char * address; @@ -76,14 +74,6 @@ G_DEFINE_TYPE (NMWifiAP, nm_wifi_ap, NM_TYPE_DBUS_OBJECT) /*****************************************************************************/ -const char * -nm_wifi_ap_get_supplicant_path (NMWifiAP *ap) -{ - g_return_val_if_fail (NM_IS_WIFI_AP (ap), NULL); - - return nm_ref_string_get_str (NM_WIFI_AP_GET_PRIVATE (ap)->supplicant_path); -} - GBytes * nm_wifi_ap_get_ssid (const NMWifiAP *ap) { @@ -392,13 +382,13 @@ nm_wifi_ap_update_from_properties (NMWifiAP *ap, priv = NM_WIFI_AP_GET_PRIVATE (ap); - nm_assert ( !priv->supplicant_path - || priv->supplicant_path == bss_info->bss_path); + nm_assert ( !ap->_supplicant_path + || ap->_supplicant_path == bss_info->bss_path); g_object_freeze_notify (G_OBJECT (ap)); - if (!priv->supplicant_path) { - priv->supplicant_path = nm_ref_string_ref (bss_info->bss_path); + if (!ap->_supplicant_path) { + ap->_supplicant_path = nm_ref_string_ref (bss_info->bss_path); changed = TRUE; } @@ -526,8 +516,8 @@ nm_wifi_ap_to_string (const NMWifiAP *self, priv = NM_WIFI_AP_GET_PRIVATE (self); chan = nm_utils_wifi_freq_to_channel (priv->freq); - if (priv->supplicant_path) - supplicant_id = strrchr (priv->supplicant_path->str, '/') ?: supplicant_id; + if (self->_supplicant_path) + supplicant_id = strrchr (self->_supplicant_path->str, '/') ?: supplicant_id; export_path = nm_dbus_object_get_path (NM_DBUS_OBJECT (self)); if (export_path) @@ -871,7 +861,7 @@ finalize (GObject *object) nm_assert (!self->wifi_device); nm_assert (c_list_is_empty (&self->aps_lst)); - nm_ref_string_unref (priv->supplicant_path); + nm_ref_string_unref (self->_supplicant_path); if (priv->ssid) g_bytes_unref (priv->ssid); g_free (priv->address); @@ -1039,14 +1029,14 @@ nm_wifi_aps_find_first_compatible (const CList *aps_lst_head, } NMWifiAP * -nm_wifi_aps_find_by_supplicant_path (const CList *aps_lst_head, const char *path) +nm_wifi_aps_find_by_supplicant_path (const CList *aps_lst_head, NMRefString *path) { NMWifiAP *ap; - g_return_val_if_fail (path != NULL, NULL); + g_return_val_if_fail (path, NULL); c_list_for_each_entry (ap, aps_lst_head, aps_lst) { - if (nm_streq0 (path, nm_wifi_ap_get_supplicant_path (ap))) + if (path == nm_wifi_ap_get_supplicant_path (ap)) return ap; } return NULL; diff --git a/src/devices/wifi/nm-wifi-ap.h b/src/devices/wifi/nm-wifi-ap.h index f9d258b06c..2cbddf50b6 100644 --- a/src/devices/wifi/nm-wifi-ap.h +++ b/src/devices/wifi/nm-wifi-ap.h @@ -33,6 +33,7 @@ typedef struct { NMDBusObject parent; NMDevice *wifi_device; CList aps_lst; + NMRefString *_supplicant_path; struct _NMWifiAPPrivate *_priv; } NMWifiAP; @@ -56,7 +57,14 @@ gboolean nm_wifi_ap_complete_connection (NMWifiAP *self, gboolean lock_bssid, GError **error); -const char * nm_wifi_ap_get_supplicant_path (NMWifiAP *ap); +static inline NMRefString * +nm_wifi_ap_get_supplicant_path (NMWifiAP *ap) +{ + g_return_val_if_fail (NM_IS_WIFI_AP (ap), NULL); + + return ap->_supplicant_path; +} + GBytes *nm_wifi_ap_get_ssid (const NMWifiAP *ap); gboolean nm_wifi_ap_set_ssid_arr (NMWifiAP *ap, const guint8 *ssid, @@ -94,7 +102,8 @@ const char **nm_wifi_aps_get_paths (const CList *aps_lst_head, NMWifiAP *nm_wifi_aps_find_first_compatible (const CList *aps_lst_head, NMConnection *connection); -NMWifiAP *nm_wifi_aps_find_by_supplicant_path (const CList *aps_lst_head, const char *path); +NMWifiAP *nm_wifi_aps_find_by_supplicant_path (const CList *aps_lst_head, + NMRefString *path); NMWifiAP *nm_wifi_ap_lookup_for_device (NMDevice *device, const char *exported_path); |