Commit c43f8890 authored by Dan Winship's avatar Dan Winship

libnm-core: change DBUS_TYPE_G_UCHAR_ARRAY properties to G_TYPE_BYTES

Change all DBUS_TYPE_G_UCHAR_ARRAY properties to G_TYPE_BYTES, and
update corresponding APIs. Notably, this means they are now refcounted
rather than being copied.

Update the rest of NM for the changes. The daemon still converts SSIDs
to GByteArrays internally, because changing it to use GBytes has lots
of trickle-down effects. It can possibly be changed later.
parent 3fbabde4
......@@ -423,6 +423,34 @@ nmc_convert_string_hash_to_string (const GValue *src_value, GValue *dest_value)
g_value_take_string (dest_value, g_string_free (string, FALSE));
}
static void
nmc_convert_bytes_to_string (const GValue *src_value, GValue *dest_value)
{
GBytes *bytes;
const guint8 *array;
gsize length;
GString *printable;
guint i = 0;
bytes = g_value_get_boxed (src_value);
printable = g_string_new ("[");
if (bytes) {
array = g_bytes_get_data (bytes, &length);
while (i < MIN (length, 35)) {
if (i > 0)
g_string_append_c (printable, ' ');
g_string_append_printf (printable, "0x%02X", array[i++]);
}
if (i < length)
g_string_append (printable, " ... ");
}
g_string_append_c (printable, ']');
g_value_take_string (dest_value, g_string_free (printable, FALSE));
}
static void
nmc_value_transforms_register (void)
{
......@@ -436,6 +464,10 @@ nmc_value_transforms_register (void)
g_value_register_transform_func (G_TYPE_HASH_TABLE,
G_TYPE_STRING,
nmc_convert_string_hash_to_string);
g_value_register_transform_func (G_TYPE_BYTES,
G_TYPE_STRING,
nmc_convert_bytes_to_string);
}
static NMClient *
......
......@@ -663,19 +663,22 @@ wep_key_type_to_string (NMWepKeyType type)
}
static char *
byte_array_to_string (const GByteArray *array)
bytes_to_string (GBytes *bytes)
{
const guint8 *data;
gsize len;
GString *cert = NULL;
int i;
if (array && array->len > 0)
cert = g_string_new (NULL);
if (!bytes)
return NULL;
data = g_bytes_get_data (bytes, &len);
for (i = 0; array && i < array->len; i++) {
g_string_append_printf (cert, "%02X", array->data[i]);
}
cert = g_string_new (NULL);
for (i = 0; i < len; i++)
g_string_append_printf (cert, "%02X", data[i]);
return cert ? g_string_free (cert, FALSE) : NULL;
return g_string_free (cert, FALSE);
}
static char *
......@@ -843,7 +846,7 @@ nmc_property_802_1X_get_ca_cert (NMSetting *setting)
scheme = nm_setting_802_1x_get_ca_cert_scheme (s_8021X);
if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB)
ca_cert_str = byte_array_to_string (nm_setting_802_1x_get_ca_cert_blob (s_8021X));
ca_cert_str = bytes_to_string (nm_setting_802_1x_get_ca_cert_blob (s_8021X));
if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH)
ca_cert_str = g_strdup (nm_setting_802_1x_get_ca_cert_path (s_8021X));
......@@ -859,7 +862,7 @@ nmc_property_802_1X_get_client_cert (NMSetting *setting)
scheme = nm_setting_802_1x_get_client_cert_scheme (s_8021X);
if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB)
client_cert_str = byte_array_to_string (nm_setting_802_1x_get_client_cert_blob (s_8021X));
client_cert_str = bytes_to_string (nm_setting_802_1x_get_client_cert_blob (s_8021X));
if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH)
client_cert_str = g_strdup (nm_setting_802_1x_get_client_cert_path (s_8021X));
......@@ -875,7 +878,7 @@ nmc_property_802_1X_get_phase2_ca_cert (NMSetting *setting)
scheme = nm_setting_802_1x_get_phase2_ca_cert_scheme (s_8021X);
if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB)
phase2_ca_cert_str = byte_array_to_string (nm_setting_802_1x_get_phase2_ca_cert_blob (s_8021X));
phase2_ca_cert_str = bytes_to_string (nm_setting_802_1x_get_phase2_ca_cert_blob (s_8021X));
if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH)
phase2_ca_cert_str = g_strdup (nm_setting_802_1x_get_phase2_ca_cert_path (s_8021X));
......@@ -891,7 +894,7 @@ nmc_property_802_1X_get_phase2_client_cert (NMSetting *setting)
scheme = nm_setting_802_1x_get_phase2_client_cert_scheme (s_8021X);
if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB)
phase2_client_cert_str = byte_array_to_string (nm_setting_802_1x_get_phase2_client_cert_blob (s_8021X));
phase2_client_cert_str = bytes_to_string (nm_setting_802_1x_get_phase2_client_cert_blob (s_8021X));
if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH)
phase2_client_cert_str = g_strdup (nm_setting_802_1x_get_phase2_client_cert_path (s_8021X));
......@@ -902,7 +905,7 @@ static char *
nmc_property_802_1X_get_password_raw (NMSetting *setting)
{
NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting);
return byte_array_to_string (nm_setting_802_1x_get_password_raw (s_8021X));
return bytes_to_string (nm_setting_802_1x_get_password_raw (s_8021X));
}
static char *
......@@ -914,7 +917,7 @@ nmc_property_802_1X_get_private_key (NMSetting *setting)
scheme = nm_setting_802_1x_get_private_key_scheme (s_8021X);
if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB)
private_key_str = byte_array_to_string (nm_setting_802_1x_get_private_key_blob (s_8021X));
private_key_str = bytes_to_string (nm_setting_802_1x_get_private_key_blob (s_8021X));
if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH)
private_key_str = g_strdup (nm_setting_802_1x_get_private_key_path (s_8021X));
......@@ -930,7 +933,7 @@ nmc_property_802_1X_get_phase2_private_key (NMSetting *setting)
scheme = nm_setting_802_1x_get_phase2_private_key_scheme (s_8021X);
if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB)
phase2_private_key_str = byte_array_to_string (nm_setting_802_1x_get_phase2_private_key_blob (s_8021X));
phase2_private_key_str = bytes_to_string (nm_setting_802_1x_get_phase2_private_key_blob (s_8021X));
if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH)
phase2_private_key_str = g_strdup (nm_setting_802_1x_get_phase2_private_key_path (s_8021X));
......@@ -1382,12 +1385,14 @@ static char *
nmc_property_olpc_get_ssid (NMSetting *setting)
{
NMSettingOlpcMesh *s_olpc_mesh = NM_SETTING_OLPC_MESH (setting);
const GByteArray *ssid;
GBytes *ssid;
char *ssid_str = NULL;
ssid = nm_setting_olpc_mesh_get_ssid (s_olpc_mesh);
if (ssid)
ssid_str = nm_utils_ssid_to_utf8 (ssid->data, ssid->len);
if (ssid) {
ssid_str = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL),
g_bytes_get_size (ssid));
}
return ssid_str;
}
......@@ -1525,12 +1530,14 @@ static char *
nmc_property_wireless_get_ssid (NMSetting *setting)
{
NMSettingWireless *s_wireless = NM_SETTING_WIRELESS (setting);
const GByteArray *ssid;
GBytes *ssid;
char *ssid_str = NULL;
ssid = nm_setting_wireless_get_ssid (s_wireless);
if (ssid)
ssid_str = nm_utils_ssid_to_utf8 (ssid->data, ssid->len);
if (ssid) {
ssid_str = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL),
g_bytes_get_size (ssid));
}
return ssid_str;
}
......
......@@ -134,11 +134,12 @@ ssid_transform_to_entry (GBinding *binding,
GValue *target_value,
gpointer user_data)
{
GByteArray *ssid;
GBytes *ssid;
char *utf8;
ssid = g_value_get_boxed (source_value);
utf8 = nm_utils_ssid_to_utf8 (ssid->data, ssid->len);
utf8 = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL),
g_bytes_get_size (ssid));
g_value_take_string (target_value, utf8);
return TRUE;
}
......@@ -151,14 +152,14 @@ ssid_transform_from_entry (GBinding *binding,
{
NMSettingWireless *s_wireless = user_data;
const char *text;
const GByteArray *old_ssid;
GByteArray *ssid;
GBytes *old_ssid, *ssid;
char *utf8;
text = g_value_get_string (source_value);
old_ssid = nm_setting_wireless_get_ssid (s_wireless);
utf8 = nm_utils_ssid_to_utf8 (old_ssid->data, old_ssid->len);
utf8 = nm_utils_ssid_to_utf8 (g_bytes_get_data (old_ssid, NULL),
g_bytes_get_size (old_ssid));
if (!g_strcmp0 (text, utf8)) {
g_free (utf8);
......@@ -166,8 +167,7 @@ ssid_transform_from_entry (GBinding *binding,
}
g_free (utf8);
ssid = g_byte_array_new ();
g_byte_array_append (ssid, (guint8 *)text, strlen (text));
ssid = g_bytes_new (text, strlen (text));
g_value_take_boxed (target_value, ssid);
return TRUE;
}
......
......@@ -329,12 +329,13 @@ request_secrets_from_ui (NmtSecretAgentRequest *request)
if (nm_connection_is_type (request->connection, NM_SETTING_WIRELESS_SETTING_NAME)) {
NMSettingWireless *s_wireless;
const GByteArray *ssid;
GBytes *ssid;
char *ssid_utf8;
s_wireless = nm_connection_get_setting_wireless (request->connection);
ssid = nm_setting_wireless_get_ssid (s_wireless);
ssid_utf8 = nm_utils_ssid_to_utf8 (ssid->data, ssid->len);
ssid_utf8 = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL),
g_bytes_get_size (ssid));
title = _("Authentication required by wireless network");
msg = g_strdup_printf (_("Passwords or encryption keys are required to access the wireless network '%s'."), ssid_utf8);
......
This diff is collapsed.
......@@ -182,7 +182,7 @@ const char * nm_setting_802_1x_get_ca_path (NMSetting8
const char * nm_setting_802_1x_get_phase2_ca_path (NMSetting8021x *setting);
NMSetting8021xCKScheme nm_setting_802_1x_get_ca_cert_scheme (NMSetting8021x *setting);
const GByteArray * nm_setting_802_1x_get_ca_cert_blob (NMSetting8021x *setting);
GBytes * nm_setting_802_1x_get_ca_cert_blob (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_ca_cert_path (NMSetting8021x *setting);
gboolean nm_setting_802_1x_set_ca_cert (NMSetting8021x *setting,
const char *cert_path,
......@@ -204,7 +204,7 @@ gboolean nm_setting_802_1x_remove_altsubject_match_by_value (NMSetting8
void nm_setting_802_1x_clear_altsubject_matches (NMSetting8021x *setting);
NMSetting8021xCKScheme nm_setting_802_1x_get_client_cert_scheme (NMSetting8021x *setting);
const GByteArray * nm_setting_802_1x_get_client_cert_blob (NMSetting8021x *setting);
GBytes * nm_setting_802_1x_get_client_cert_blob (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_client_cert_path (NMSetting8021x *setting);
gboolean nm_setting_802_1x_set_client_cert (NMSetting8021x *setting,
const char *cert_path,
......@@ -223,7 +223,7 @@ const char * nm_setting_802_1x_get_phase2_auth (NMSetting8
const char * nm_setting_802_1x_get_phase2_autheap (NMSetting8021x *setting);
NMSetting8021xCKScheme nm_setting_802_1x_get_phase2_ca_cert_scheme (NMSetting8021x *setting);
const GByteArray * nm_setting_802_1x_get_phase2_ca_cert_blob (NMSetting8021x *setting);
GBytes * nm_setting_802_1x_get_phase2_ca_cert_blob (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_phase2_ca_cert_path (NMSetting8021x *setting);
gboolean nm_setting_802_1x_set_phase2_ca_cert (NMSetting8021x *setting,
const char *cert_path,
......@@ -245,7 +245,7 @@ gboolean nm_setting_802_1x_remove_phase2_altsubject_match_by_value (NMS
void nm_setting_802_1x_clear_phase2_altsubject_matches (NMSetting8021x *setting);
NMSetting8021xCKScheme nm_setting_802_1x_get_phase2_client_cert_scheme (NMSetting8021x *setting);
const GByteArray * nm_setting_802_1x_get_phase2_client_cert_blob (NMSetting8021x *setting);
GBytes * nm_setting_802_1x_get_phase2_client_cert_blob (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_phase2_client_cert_path (NMSetting8021x *setting);
gboolean nm_setting_802_1x_set_phase2_client_cert (NMSetting8021x *setting,
const char *cert_path,
......@@ -255,14 +255,14 @@ gboolean nm_setting_802_1x_set_phase2_client_cert (NMSett
const char * nm_setting_802_1x_get_password (NMSetting8021x *setting);
NMSettingSecretFlags nm_setting_802_1x_get_password_flags (NMSetting8021x *setting);
const GByteArray * nm_setting_802_1x_get_password_raw (NMSetting8021x *setting);
GBytes * nm_setting_802_1x_get_password_raw (NMSetting8021x *setting);
NMSettingSecretFlags nm_setting_802_1x_get_password_raw_flags (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_pin (NMSetting8021x *setting);
NMSettingSecretFlags nm_setting_802_1x_get_pin_flags (NMSetting8021x *setting);
NMSetting8021xCKScheme nm_setting_802_1x_get_private_key_scheme (NMSetting8021x *setting);
const GByteArray * nm_setting_802_1x_get_private_key_blob (NMSetting8021x *setting);
GBytes * nm_setting_802_1x_get_private_key_blob (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_private_key_path (NMSetting8021x *setting);
gboolean nm_setting_802_1x_set_private_key (NMSetting8021x *setting,
const char *key_path,
......@@ -276,7 +276,7 @@ NMSettingSecretFlags nm_setting_802_1x_get_private_key_password_flags (NMSett
NMSetting8021xCKFormat nm_setting_802_1x_get_private_key_format (NMSetting8021x *setting);
NMSetting8021xCKScheme nm_setting_802_1x_get_phase2_private_key_scheme (NMSetting8021x *setting);
const GByteArray * nm_setting_802_1x_get_phase2_private_key_blob (NMSetting8021x *setting);
GBytes * nm_setting_802_1x_get_phase2_private_key_blob (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_phase2_private_key_path (NMSetting8021x *setting);
gboolean nm_setting_802_1x_set_phase2_private_key (NMSetting8021x *setting,
const char *key_path,
......
......@@ -50,7 +50,7 @@ NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_OLPC_MESH)
#define NM_SETTING_OLPC_MESH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_OLPC_MESH, NMSettingOlpcMeshPrivate))
typedef struct {
GByteArray *ssid;
GBytes *ssid;
guint32 channel;
char *dhcp_anycast_addr;
} NMSettingOlpcMeshPrivate;
......@@ -81,7 +81,7 @@ nm_setting_olpc_mesh_init (NMSettingOlpcMesh *setting)
{
}
const GByteArray *
GBytes *
nm_setting_olpc_mesh_get_ssid (NMSettingOlpcMesh *setting)
{
g_return_val_if_fail (NM_IS_SETTING_OLPC_MESH (setting), NULL);
......@@ -109,6 +109,7 @@ static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingOlpcMeshPrivate *priv = NM_SETTING_OLPC_MESH_GET_PRIVATE (setting);
gsize length;
if (!priv->ssid) {
g_set_error_literal (error,
......@@ -119,7 +120,8 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
if (!priv->ssid->len || priv->ssid->len > 32) {
length = g_bytes_get_size (priv->ssid);
if (length == 0 || length > 32) {
g_set_error_literal (error,
NM_SETTING_OLPC_MESH_ERROR,
NM_SETTING_OLPC_MESH_ERROR_INVALID_PROPERTY,
......@@ -156,7 +158,7 @@ finalize (GObject *object)
NMSettingOlpcMeshPrivate *priv = NM_SETTING_OLPC_MESH_GET_PRIVATE (object);
if (priv->ssid)
g_byte_array_free (priv->ssid, TRUE);
g_bytes_unref (priv->ssid);
g_free (priv->dhcp_anycast_addr);
G_OBJECT_CLASS (nm_setting_olpc_mesh_parent_class)->finalize (object);
......@@ -171,7 +173,7 @@ set_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_SSID:
if (priv->ssid)
g_byte_array_free (priv->ssid, TRUE);
g_bytes_unref (priv->ssid);
priv->ssid = g_value_dup_boxed (value);
break;
case PROP_CHANNEL:
......@@ -232,10 +234,14 @@ nm_setting_olpc_mesh_class_init (NMSettingOlpcMeshClass *setting_class)
g_object_class_install_property
(object_class, PROP_SSID,
g_param_spec_boxed (NM_SETTING_OLPC_MESH_SSID, "", "",
DBUS_TYPE_G_UCHAR_ARRAY,
G_TYPE_BYTES,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
_nm_setting_class_transform_property (parent_class, NM_SETTING_OLPC_MESH_SSID,
DBUS_TYPE_G_UCHAR_ARRAY,
_nm_utils_bytes_to_dbus,
_nm_utils_bytes_from_dbus);
/**
* NMSettingOlpcMesh:channel:
......
......@@ -74,7 +74,7 @@ typedef struct {
GType nm_setting_olpc_mesh_get_type (void);
NMSetting * nm_setting_olpc_mesh_new (void);
const GByteArray *nm_setting_olpc_mesh_get_ssid (NMSettingOlpcMesh *setting);
GBytes * nm_setting_olpc_mesh_get_ssid (NMSettingOlpcMesh *setting);
guint32 nm_setting_olpc_mesh_get_channel (NMSettingOlpcMesh *setting);
const char * nm_setting_olpc_mesh_get_dhcp_anycast_address (NMSettingOlpcMesh *setting);
......
......@@ -65,7 +65,7 @@ NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_WIRELESS)
#define NM_SETTING_WIRELESS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_WIRELESS, NMSettingWirelessPrivate))
typedef struct {
GByteArray *ssid;
GBytes *ssid;
char *mode;
char *band;
guint32 channel;
......@@ -315,7 +315,7 @@ nm_setting_wireless_new (void)
*
* Returns: the #NMSettingWireless:ssid property of the setting
**/
const GByteArray *
GBytes *
nm_setting_wireless_get_ssid (NMSettingWireless *setting)
{
g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
......@@ -703,6 +703,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
const char *valid_modes[] = { NM_SETTING_WIRELESS_MODE_INFRA, NM_SETTING_WIRELESS_MODE_ADHOC, NM_SETTING_WIRELESS_MODE_AP, NULL };
const char *valid_bands[] = { "a", "bg", NULL };
GSList *iter;
gsize length;
if (!priv->ssid) {
g_set_error_literal (error,
......@@ -713,7 +714,8 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
if (!priv->ssid->len || priv->ssid->len > 32) {
length = g_bytes_get_size (priv->ssid);
if (length == 0 || length > 32) {
g_set_error_literal (error,
NM_SETTING_WIRELESS_ERROR,
NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY,
......@@ -845,7 +847,7 @@ finalize (GObject *object)
g_free (priv->band);
if (priv->ssid)
g_byte_array_free (priv->ssid, TRUE);
g_bytes_unref (priv->ssid);
g_free (priv->bssid);
g_free (priv->device_mac_address);
g_free (priv->cloned_mac_address);
......@@ -864,7 +866,7 @@ set_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_SSID:
if (priv->ssid)
g_byte_array_free (priv->ssid, TRUE);
g_bytes_unref (priv->ssid);
priv->ssid = g_value_dup_boxed (value);
break;
case PROP_MODE:
......@@ -992,9 +994,13 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *setting_class)
g_object_class_install_property
(object_class, PROP_SSID,
g_param_spec_boxed (NM_SETTING_WIRELESS_SSID, "", "",
DBUS_TYPE_G_UCHAR_ARRAY,
G_TYPE_BYTES,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
_nm_setting_class_transform_property (parent_class, NM_SETTING_WIRELESS_SSID,
DBUS_TYPE_G_UCHAR_ARRAY,
_nm_utils_bytes_to_dbus,
_nm_utils_bytes_from_dbus);
/**
* NMSettingWireless:mode:
......
......@@ -116,7 +116,7 @@ GType nm_setting_wireless_get_type (void);
NMSetting *nm_setting_wireless_new (void);
const GByteArray *nm_setting_wireless_get_ssid (NMSettingWireless *setting);
GBytes *nm_setting_wireless_get_ssid (NMSettingWireless *setting);
const char *nm_setting_wireless_get_mode (NMSettingWireless *setting);
const char *nm_setting_wireless_get_band (NMSettingWireless *setting);
guint32 nm_setting_wireless_get_channel (NMSettingWireless *setting);
......
......@@ -44,6 +44,11 @@ void _nm_utils_strdict_to_dbus (const GValue *prop_value,
void _nm_utils_strdict_from_dbus (const GValue *dbus_value,
GValue *prop_value);
void _nm_utils_bytes_to_dbus (const GValue *prop_value,
GValue *dbus_value);
void _nm_utils_bytes_from_dbus (const GValue *dbus_value,
GValue *prop_value);
void _nm_utils_ip4_dns_to_dbus (const GValue *prop_value,
GValue *dbus_value);
void _nm_utils_ip4_dns_from_dbus (const GValue *dbus_value,
......
......@@ -626,6 +626,35 @@ _nm_utils_copy_array_to_slist (const GPtrArray *array,
return g_slist_reverse (slist);
}
void
_nm_utils_bytes_to_dbus (const GValue *prop_value,
GValue *dbus_value)
{
GBytes *bytes = g_value_get_boxed (prop_value);
GByteArray *ba = NULL;
if (bytes) {
ba = g_byte_array_new ();
g_byte_array_append (ba,
g_bytes_get_data (bytes, NULL),
g_bytes_get_size (bytes));
}
g_value_take_boxed (dbus_value, ba);
}
void
_nm_utils_bytes_from_dbus (const GValue *dbus_value,
GValue *prop_value)
{
GByteArray *ba = g_value_dup_boxed (dbus_value);
GBytes *bytes = NULL;
if (ba)
bytes = g_byte_array_free_to_bytes (ba);
g_value_take_boxed (prop_value, bytes);
}
GSList *
_nm_utils_strv_to_slist (char **strv)
{
......
......@@ -92,33 +92,6 @@ _nm_utils_convert_gvalue_hash_to_string (const GValue *src_value, GValue *dest_v
g_string_free (printable, FALSE);
}
static void
_nm_utils_convert_byte_array_to_string (const GValue *src_value, GValue *dest_value)
{
GArray *array;
GString *printable;
guint i = 0;
g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_UCHAR_ARRAY));
array = (GArray *) g_value_get_boxed (src_value);
printable = g_string_new ("[");
if (array) {
while (i < MIN (array->len, 35)) {
if (i > 0)
g_string_append_c (printable, ' ');
g_string_append_printf (printable, "0x%02X",
g_array_index (array, unsigned char, i++));
}
if (i < array->len)
g_string_append (printable, " ... ");
}
g_string_append_c (printable, ']');
g_value_take_string (dest_value, g_string_free (printable, FALSE));
}
void
_nm_value_transforms_register (void)
{
......@@ -134,9 +107,6 @@ _nm_value_transforms_register (void)
g_value_register_transform_func (DBUS_TYPE_G_MAP_OF_VARIANT,
G_TYPE_STRING,
_nm_utils_convert_gvalue_hash_to_string);
g_value_register_transform_func (DBUS_TYPE_G_UCHAR_ARRAY,
G_TYPE_STRING,
_nm_utils_convert_byte_array_to_string);
registered = TRUE;
}
}
......@@ -721,7 +721,7 @@ test_connection_to_dbus_deprecated_props (void)
{
NMConnection *connection;
NMSetting *s_wireless;
GByteArray *ssid;
GBytes *ssid;
NMSettingWirelessSecurity *s_wsec;
GHashTable *hash, *wireless_hash;
GValue *sec_val;
......@@ -732,12 +732,11 @@ test_connection_to_dbus_deprecated_props (void)
NULL);
s_wireless = nm_setting_wireless_new ();
ssid = g_byte_array_new ();
g_byte_array_append (ssid, (const guint8 *) "1234567", 7);
ssid = g_bytes_new ("1234567", 7);
g_object_set (s_wireless,
NM_SETTING_WIRELESS_SSID, ssid,
NULL);
g_byte_array_unref (ssid);
g_bytes_unref (ssid);
nm_connection_add_setting (connection, s_wireless);
/* Hash should not have an 802-11-wireless.security property */
......@@ -962,7 +961,7 @@ test_connection_replace_settings_from_connection ()
gboolean success;
NMSettingConnection *s_con;
NMSetting *setting;
GByteArray *ssid;
GBytes *ssid;
char *uuid = NULL;
const char *expected_id = "Awesome connection";
......@@ -988,13 +987,12 @@ test_connection_replace_settings_from_connection ()
setting = nm_setting_wireless_new ();
g_assert (setting);
ssid = g_byte_array_new ();
g_byte_array_append (ssid, (const guint8 *) "1234567", 7);
ssid = g_bytes_new ("1234567", 7);
g_object_set (setting,
NM_SETTING_WIRELESS_SSID, ssid,
NM_SETTING_WIRELESS_MODE, "infrastructure",
NULL);
g_byte_array_free (ssid, TRUE);
g_bytes_unref (ssid);
nm_connection_add_setting (replacement, setting);
/* Replace settings and test */
......@@ -1709,7 +1707,7 @@ test_connection_good_base_types (void)
NMSetting *setting;
gboolean success;
GError *error = NULL;
GByteArray *array;
GBytes *ssid;
const char *bdaddr = "11:22:33:44:55:66";
/* Try a basic wired connection */
......@@ -1740,13 +1738,12 @@ test_connection_good_base_types (void)
add_generic_settings (connection, NM_SETTING_WIRELESS_SETTING_NAME);
setting = nm_setting_wireless_new ();
array = g_byte_array_new ();
g_byte_array_append (array, (const guint8 *) "1234567", 7);
ssid = g_bytes_new ("1234567", 7);
g_object_set (setting,
NM_SETTING_WIRELESS_SSID, array,
NM_SETTING_WIRELESS_SSID, ssid,
NM_SETTING_WIRELESS_MODE, "infrastructure",
NULL);
g_byte_array_free (array, TRUE);
g_bytes_unref (ssid);
nm_connection_add_setting (connection, setting);
success = nm_connection_verify (connection, &error);
......@@ -2908,14 +2905,14 @@ _add_setting_fcn_olpc_mesh (NMConnection *con)
{
NMSetting *setting;
const char *ssid_data = "ssid-test";
GByteArray *ssid = g_byte_array_new ();
GBytes *ssid;
g_byte_array_append (ssid, (const guint8 *) ssid_data, strlen (ssid_data));
ssid = g_bytes_new (ssid_data, strlen (ssid_data));
setting =