libnm: implement special setter for direct string property via g_ascii_strdown()

This commit is contained in:
Thomas Haller 2021-07-14 07:40:35 +02:00
parent d5f08f4a1e
commit 96657b1556
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
4 changed files with 35 additions and 30 deletions

View file

@ -409,34 +409,28 @@ nm_setting_adsl_class_init(NMSettingAdslClass *klass)
*
* ADSL connection protocol. Can be "pppoa", "pppoe" or "ipoatm".
**/
_nm_setting_property_define_direct_string(
properties_override,
obj_properties,
NM_SETTING_ADSL_PROTOCOL,
PROP_PROTOCOL,
NM_SETTING_PARAM_NONE,
NMSettingAdslPrivate,
protocol,
/* it's special, because set_property() calls g_ascii_strdown() on
* the string! */
.direct_has_special_setter = TRUE);
_nm_setting_property_define_direct_string(properties_override,
obj_properties,
NM_SETTING_ADSL_PROTOCOL,
PROP_PROTOCOL,
NM_SETTING_PARAM_NONE,
NMSettingAdslPrivate,
protocol,
.direct_set_string_ascii_strdown = TRUE);
/**
* NMSettingAdsl:encapsulation:
*
* Encapsulation of ADSL connection. Can be "vcmux" or "llc".
**/
_nm_setting_property_define_direct_string(
properties_override,
obj_properties,
NM_SETTING_ADSL_ENCAPSULATION,
PROP_ENCAPSULATION,
NM_SETTING_PARAM_NONE,
NMSettingAdslPrivate,
encapsulation,
/* it's special, because set_property() calls g_ascii_strdown() on
* the string! */
.direct_has_special_setter = TRUE);
_nm_setting_property_define_direct_string(properties_override,
obj_properties,
NM_SETTING_ADSL_ENCAPSULATION,
PROP_ENCAPSULATION,
NM_SETTING_PARAM_NONE,
NMSettingAdslPrivate,
encapsulation,
.direct_set_string_ascii_strdown = TRUE);
/**
* NMSettingAdsl:vpi:

View file

@ -674,6 +674,14 @@ _nm_setting_use_legacy_property(NMSetting * setting,
/*****************************************************************************/
static gboolean
_property_direct_set_string(const NMSettInfoProperty *property_info, char **dst, const char *src)
{
if (property_info->direct_set_string_ascii_strdown)
return nm_utils_strdup_reset_take(dst, src ? g_ascii_strdown(src, -1) : NULL);
return nm_utils_strdup_reset(dst, src);
}
void
_nm_setting_property_get_property_direct(GObject * object,
guint prop_id,
@ -755,9 +763,6 @@ _nm_setting_property_set_property_direct(GObject * object,
nm_assert(property_info->param_spec == pspec);
/* properties with special setters are not yet implemented! */
nm_assert(!property_info->direct_has_special_setter);
switch (property_info->property_type->direct_type) {
case NM_VALUE_TYPE_BOOL:
{
@ -801,13 +806,12 @@ _nm_setting_property_set_property_direct(GObject * object,
goto out_notify;
}
case NM_VALUE_TYPE_STRING:
{
char **p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset);
if (!nm_utils_strdup_reset(p_val, g_value_get_string(value)))
if (!_property_direct_set_string(
property_info,
_nm_setting_get_private(setting, sett_info, property_info->direct_offset),
g_value_get_string(value)))
return;
goto out_notify;
}
default:
goto out_fail;
}

View file

@ -4504,6 +4504,9 @@ test_setting_metadata(void)
} else
g_assert_not_reached();
if (sip->direct_set_string_ascii_strdown)
g_assert(sip->property_type->direct_type == NM_VALUE_TYPE_STRING);
if (!sip->property_type->to_dbus_fcn) {
/* it's allowed to have no to_dbus_fcn(), to ignore a property. But such
* properties must not have a param_spec. */

View file

@ -748,6 +748,10 @@ struct _NMSettInfoProperty {
* the direct location. */
guint16 direct_offset;
/* If TRUE, this is a NM_VALUE_TYPE_STRING direct property, and the setter will
* normalize the string via g_ascii_strdown(). */
bool direct_set_string_ascii_strdown : 1;
/* Currently, properties that set property_type->direct_type only have to_dbus_fcn()
* implemented "the direct way". For the property setter, they still call g_object_set().
* In the future, also other operations, like from_dbus_fcn() should be implemented