mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-03 12:30:32 +01:00
libnm: drop NM_TYPE_SSID, use G_TYPE_BYTES
Make NMAccessPoint:ssid be G_TYPE_BYTES and update the corresponding APIs accordingly.
This commit is contained in:
parent
4eb04dbcf8
commit
20dc44bda9
10 changed files with 36 additions and 98 deletions
|
|
@ -495,7 +495,7 @@ fill_output_access_point (gpointer data, gpointer user_data)
|
|||
NM80211ApSecurityFlags wpa_flags, rsn_flags;
|
||||
guint32 freq, bitrate;
|
||||
guint8 strength;
|
||||
const GByteArray *ssid;
|
||||
GBytes *ssid;
|
||||
const char *bssid;
|
||||
NM80211Mode mode;
|
||||
char *channel_str, *freq_str, *ssid_str = NULL, *ssid_hex_str = NULL,
|
||||
|
|
@ -528,8 +528,12 @@ fill_output_access_point (gpointer data, gpointer user_data)
|
|||
|
||||
/* Convert to strings */
|
||||
if (ssid) {
|
||||
ssid_str = nm_utils_ssid_to_utf8 (ssid->data, ssid->len);
|
||||
ssid_hex_str = ssid_to_hex ((const char *) ssid->data, ssid->len);
|
||||
const guint8 *ssid_data;
|
||||
gsize ssid_len;
|
||||
|
||||
ssid_data = g_bytes_get_data (ssid, &ssid_len);
|
||||
ssid_str = nm_utils_ssid_to_utf8 (ssid_data, ssid_len);
|
||||
ssid_hex_str = ssid_to_hex ((const char *) ssid_data, ssid_len);
|
||||
}
|
||||
channel_str = g_strdup_printf ("%u", nm_utils_wifi_freq_to_channel (freq));
|
||||
freq_str = g_strdup_printf (_("%u MHz"), freq);
|
||||
|
|
@ -2050,12 +2054,12 @@ find_ap_on_device (NMDevice *device, GByteArray *bssid, const char *ssid)
|
|||
|
||||
if (ssid) {
|
||||
/* Parameter is SSID */
|
||||
const GByteArray *candidate_ssid;
|
||||
GBytes *candidate_ssid;
|
||||
|
||||
candidate_ssid = nm_access_point_get_ssid (candidate_ap);
|
||||
if (candidate_ssid) {
|
||||
char *ssid_tmp = nm_utils_ssid_to_utf8 (candidate_ssid->data,
|
||||
candidate_ssid->len);
|
||||
char *ssid_tmp = nm_utils_ssid_to_utf8 (g_bytes_get_data (candidate_ssid, NULL),
|
||||
g_bytes_get_size (candidate_ssid));
|
||||
|
||||
/* Compare SSIDs */
|
||||
if (strcmp (ssid, ssid_tmp) == 0) {
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ static char *
|
|||
hash_ap (NMAccessPoint *ap)
|
||||
{
|
||||
unsigned char input[66];
|
||||
const GByteArray *ssid;
|
||||
GBytes *ssid;
|
||||
NM80211Mode mode;
|
||||
guint32 flags;
|
||||
guint32 wpa_flags;
|
||||
|
|
@ -223,7 +223,7 @@ hash_ap (NMAccessPoint *ap)
|
|||
|
||||
ssid = nm_access_point_get_ssid (ap);
|
||||
if (ssid)
|
||||
memcpy (input, ssid->data, ssid->len);
|
||||
memcpy (input, g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid));
|
||||
|
||||
mode = nm_access_point_get_mode (ap);
|
||||
if (mode == NM_802_11_MODE_INFRA)
|
||||
|
|
@ -266,7 +266,7 @@ add_connections_for_aps (NmtConnectDevice *nmtdev,
|
|||
NMAccessPoint *ap;
|
||||
const GPtrArray *aps;
|
||||
GHashTable *seen_ssids;
|
||||
const GByteArray *ssid;
|
||||
GBytes *ssid;
|
||||
char *ap_hash;
|
||||
GSList *iter;
|
||||
int i;
|
||||
|
|
@ -294,7 +294,8 @@ add_connections_for_aps (NmtConnectDevice *nmtdev,
|
|||
nmtconn->device = nmtdev->device;
|
||||
nmtconn->ap = g_object_ref (ap);
|
||||
ssid = nm_access_point_get_ssid (ap);
|
||||
nmtconn->ssid = nm_utils_ssid_to_utf8 (ssid->data, ssid->len);
|
||||
nmtconn->ssid = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL),
|
||||
g_bytes_get_size (ssid));
|
||||
|
||||
for (iter = connections; iter; iter = iter->next) {
|
||||
conn = iter->data;
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ show_access_point_info (NMAccessPoint *ap)
|
|||
{
|
||||
guint32 flags, wpa_flags, rsn_flags, freq, bitrate;
|
||||
guint8 strength;
|
||||
const GByteArray *ssid;
|
||||
GBytes *ssid;
|
||||
const char *hwaddr;
|
||||
NM80211Mode mode;
|
||||
char *freq_str, *ssid_str, *bitrate_str, *strength_str, *wpa_flags_str, *rsn_flags_str;
|
||||
|
|
@ -97,7 +97,7 @@ show_access_point_info (NMAccessPoint *ap)
|
|||
strength = nm_access_point_get_strength (ap);
|
||||
|
||||
/* Convert to strings */
|
||||
ssid_str = nm_utils_ssid_to_utf8 (ssid->data, ssid->len);
|
||||
ssid_str = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid));
|
||||
freq_str = g_strdup_printf ("%u MHz", freq);
|
||||
bitrate_str = g_strdup_printf ("%u Mbit/s", bitrate/1000);
|
||||
strength_str = g_strdup_printf ("%u", strength);
|
||||
|
|
@ -155,7 +155,7 @@ show_wifi_device_info (NMDevice *device)
|
|||
const char *iface;
|
||||
const char *driver;
|
||||
guint32 speed;
|
||||
const GByteArray *active_ssid;
|
||||
GBytes *active_ssid;
|
||||
char *active_ssid_str = NULL;
|
||||
int i;
|
||||
|
||||
|
|
@ -163,7 +163,8 @@ show_wifi_device_info (NMDevice *device)
|
|||
if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) {
|
||||
if ((active_ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (device)))) {
|
||||
active_ssid = nm_access_point_get_ssid (active_ap);
|
||||
active_ssid_str = nm_utils_ssid_to_utf8 (active_ssid->data, active_ssid->len);
|
||||
active_ssid_str = nm_utils_ssid_to_utf8 (g_bytes_get_data (active_ssid, NULL),
|
||||
g_bytes_get_size (active_ssid));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -862,7 +862,6 @@ global:
|
|||
nm_simple_connection_new;
|
||||
nm_simple_connection_new_clone;
|
||||
nm_simple_connection_new_from_dbus;
|
||||
nm_ssid_get_type;
|
||||
nm_state_get_type;
|
||||
nm_uint_array_get_type;
|
||||
nm_utils_ap_mode_security_valid;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@
|
|||
|
||||
#include "nm-access-point.h"
|
||||
#include "nm-dbus-interface.h"
|
||||
#include "nm-types-private.h"
|
||||
#include "nm-object-private.h"
|
||||
|
||||
G_DEFINE_TYPE (NMAccessPoint, nm_access_point, NM_TYPE_OBJECT)
|
||||
|
|
@ -45,7 +44,7 @@ typedef struct {
|
|||
NM80211ApFlags flags;
|
||||
NM80211ApSecurityFlags wpa_flags;
|
||||
NM80211ApSecurityFlags rsn_flags;
|
||||
GByteArray *ssid;
|
||||
GBytes *ssid;
|
||||
guint32 frequency;
|
||||
char *bssid;
|
||||
NM80211Mode mode;
|
||||
|
|
@ -124,10 +123,9 @@ nm_access_point_get_rsn_flags (NMAccessPoint *ap)
|
|||
*
|
||||
* Gets the SSID of the access point.
|
||||
*
|
||||
* Returns: the #GByteArray containing the SSID. This is the internal copy used by the
|
||||
* access point, and must not be modified.
|
||||
* Returns: the #GBytes containing the SSID.
|
||||
**/
|
||||
const GByteArray *
|
||||
GBytes *
|
||||
nm_access_point_get_ssid (NMAccessPoint *ap)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL);
|
||||
|
|
@ -237,9 +235,7 @@ nm_access_point_connection_valid (NMAccessPoint *ap, NMConnection *connection)
|
|||
NMSettingWirelessSecurity *s_wsec;
|
||||
const char *ctype, *ap_bssid;
|
||||
GBytes *setting_ssid;
|
||||
const guint8 *setting_ssid_data;
|
||||
gsize setting_ssid_len;
|
||||
const GByteArray *ap_ssid;
|
||||
GBytes *ap_ssid;
|
||||
const char *setting_bssid;
|
||||
const char *setting_mode;
|
||||
NM80211Mode ap_mode;
|
||||
|
|
@ -262,10 +258,7 @@ nm_access_point_connection_valid (NMAccessPoint *ap, NMConnection *connection)
|
|||
setting_ssid = nm_setting_wireless_get_ssid (s_wifi);
|
||||
if (!setting_ssid || !ap_ssid)
|
||||
return FALSE;
|
||||
setting_ssid_data = g_bytes_get_data (setting_ssid, &setting_ssid_len);
|
||||
if (setting_ssid_len != ap_ssid->len)
|
||||
return FALSE;
|
||||
if (memcmp (setting_ssid_data, ap_ssid->data, ap_ssid->len) != 0)
|
||||
if (!g_bytes_equal (ap_ssid, setting_ssid))
|
||||
return FALSE;
|
||||
|
||||
/* BSSID checks */
|
||||
|
|
@ -384,7 +377,7 @@ finalize (GObject *object)
|
|||
NMAccessPointPrivate *priv = NM_ACCESS_POINT_GET_PRIVATE (object);
|
||||
|
||||
if (priv->ssid)
|
||||
g_byte_array_free (priv->ssid, TRUE);
|
||||
g_bytes_unref (priv->ssid);
|
||||
|
||||
g_free (priv->bssid);
|
||||
|
||||
|
|
@ -436,16 +429,6 @@ get_property (GObject *object,
|
|||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
demarshal_ssid (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
|
||||
{
|
||||
if (!_nm_ssid_demarshal (value, (GByteArray **) field))
|
||||
return FALSE;
|
||||
|
||||
_nm_object_queue_notify (object, NM_ACCESS_POINT_SSID);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
init_dbus (NMObject *object)
|
||||
{
|
||||
|
|
@ -454,7 +437,7 @@ init_dbus (NMObject *object)
|
|||
{ NM_ACCESS_POINT_FLAGS, &priv->flags },
|
||||
{ NM_ACCESS_POINT_WPA_FLAGS, &priv->wpa_flags },
|
||||
{ NM_ACCESS_POINT_RSN_FLAGS, &priv->rsn_flags },
|
||||
{ NM_ACCESS_POINT_SSID, &priv->ssid, demarshal_ssid },
|
||||
{ NM_ACCESS_POINT_SSID, &priv->ssid },
|
||||
{ NM_ACCESS_POINT_FREQUENCY, &priv->frequency },
|
||||
/* The D-Bus property is HwAddress, but the GObject property is "bssid" */
|
||||
{ NM_ACCESS_POINT_HW_ADDRESS, &priv->bssid },
|
||||
|
|
@ -536,7 +519,7 @@ nm_access_point_class_init (NMAccessPointClass *ap_class)
|
|||
g_object_class_install_property
|
||||
(object_class, PROP_SSID,
|
||||
g_param_spec_boxed (NM_ACCESS_POINT_SSID, "", "",
|
||||
NM_TYPE_SSID,
|
||||
G_TYPE_BYTES,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ GType nm_access_point_get_type (void);
|
|||
NM80211ApFlags nm_access_point_get_flags (NMAccessPoint *ap);
|
||||
NM80211ApSecurityFlags nm_access_point_get_wpa_flags (NMAccessPoint *ap);
|
||||
NM80211ApSecurityFlags nm_access_point_get_rsn_flags (NMAccessPoint *ap);
|
||||
const GByteArray * nm_access_point_get_ssid (NMAccessPoint *ap);
|
||||
GBytes * nm_access_point_get_ssid (NMAccessPoint *ap);
|
||||
const char * nm_access_point_get_bssid (NMAccessPoint *ap);
|
||||
guint32 nm_access_point_get_frequency (NMAccessPoint *ap);
|
||||
NM80211Mode nm_access_point_get_mode (NMAccessPoint *ap);
|
||||
|
|
|
|||
|
|
@ -1147,6 +1147,13 @@ demarshal_generic (NMObject *object,
|
|||
if (*param)
|
||||
g_strfreev (*param);
|
||||
*param = g_value_dup_boxed (value);
|
||||
} else if (pspec->value_type == G_TYPE_BYTES) {
|
||||
GBytes **param = (GBytes **)field;
|
||||
GByteArray *val;
|
||||
if (*param)
|
||||
g_bytes_unref (*param);
|
||||
val = g_value_get_boxed (value);
|
||||
*param = g_bytes_new (val->data, val->len);
|
||||
HANDLE_TYPE(BOOLEAN, boolean, boolean)
|
||||
HANDLE_TYPE(CHAR, char, schar)
|
||||
HANDLE_TYPE(UCHAR, uchar, uchar)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@
|
|||
#include "nm-types.h"
|
||||
#include "nm-object-private.h"
|
||||
|
||||
gboolean _nm_ssid_demarshal (GValue *value, GByteArray **dest);
|
||||
gboolean _nm_uint_array_demarshal (GValue *value, GArray **dest);
|
||||
gboolean _nm_object_array_demarshal (GValue *value,
|
||||
GPtrArray **dest,
|
||||
|
|
|
|||
|
|
@ -28,59 +28,6 @@
|
|||
#include "nm-dbus-glib-types.h"
|
||||
#include "nm-setting-ip6-config.h"
|
||||
|
||||
static gpointer
|
||||
_nm_ssid_copy (GByteArray *src)
|
||||
{
|
||||
GByteArray *dest;
|
||||
|
||||
dest = g_byte_array_sized_new (src->len);
|
||||
g_byte_array_append (dest, src->data, src->len);
|
||||
return dest;
|
||||
}
|
||||
|
||||
static void
|
||||
_nm_ssid_free (GByteArray *ssid)
|
||||
{
|
||||
g_byte_array_free (ssid, TRUE);
|
||||
}
|
||||
|
||||
GType
|
||||
nm_ssid_get_type (void)
|
||||
{
|
||||
static GType our_type = 0;
|
||||
|
||||
if (our_type == 0)
|
||||
our_type = g_boxed_type_register_static (g_intern_static_string ("NMSsid"),
|
||||
(GBoxedCopyFunc) _nm_ssid_copy,
|
||||
(GBoxedFreeFunc) _nm_ssid_free);
|
||||
return our_type;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_nm_ssid_demarshal (GValue *value, GByteArray **dest)
|
||||
{
|
||||
GByteArray *array;
|
||||
|
||||
if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_UCHAR_ARRAY))
|
||||
return FALSE;
|
||||
|
||||
if (*dest) {
|
||||
g_boxed_free (NM_TYPE_SSID, *dest);
|
||||
*dest = NULL;
|
||||
}
|
||||
|
||||
array = (GByteArray *) g_value_get_boxed (value);
|
||||
if (array && (array->len > 0)) {
|
||||
*dest = g_byte_array_sized_new (array->len);
|
||||
(*dest)->len = array->len;
|
||||
memcpy ((*dest)->data, array->data, array->len);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*****************************/
|
||||
|
||||
static gpointer
|
||||
_nm_uint_array_copy (GArray *src)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -32,9 +32,6 @@
|
|||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define NM_TYPE_SSID (nm_ssid_get_type ())
|
||||
GType nm_ssid_get_type (void) G_GNUC_CONST;
|
||||
|
||||
#define NM_TYPE_UINT_ARRAY (nm_uint_array_get_type ())
|
||||
GType nm_uint_array_get_type (void) G_GNUC_CONST;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue