From 35d6802724106f439bf8bfbbeb27d19e0403268a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 21 May 2017 16:15:29 +0200 Subject: [PATCH] clients: add validate_fcn for string property --- clients/common/nm-meta-setting-desc.c | 36 ++++++++++++++++----------- clients/common/nm-meta-setting-desc.h | 3 +++ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index 5293a0895..77965fbb4 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -764,13 +764,20 @@ _get_fcn_gobject_enum (ARGS_GET_FCN) static gboolean _set_fcn_gobject_string (ARGS_SET_FCN) { - if ( property_info->property_typ_data - && property_info->property_typ_data->values_static) { - value = nmc_string_is_valid (value, - (const char **) property_info->property_typ_data->values_static, - error); - if (!value) - return FALSE; + gs_free char *to_free = NULL; + + if (property_info->property_typ_data) { + if (property_info->property_typ_data->subtype.gobject_string.validate_fcn) { + value = property_info->property_typ_data->subtype.gobject_string.validate_fcn (value, &to_free, error); + if (!value) + return FALSE; + } else if (property_info->property_typ_data->values_static) { + value = nmc_string_is_valid (value, + (const char **) property_info->property_typ_data->values_static, + error); + if (!value) + return FALSE; + } } g_object_set (setting, property_info->property_name, value, NULL); return TRUE; @@ -4284,15 +4291,14 @@ _set_fcn_wireless_security_wep_key_type (ARGS_SET_FCN) return TRUE; } -static gboolean -_set_fcn_wireless_security_psk (ARGS_SET_FCN) +static const char * +_validate_fcn_wireless_security_psk (const char *value, char **out_to_free, GError **error) { if (!nm_utils_wpa_psk_valid (value)) { g_set_error (error, 1, 0, _("'%s' is not a valid PSK"), value); - return FALSE; + return NULL; } - g_object_set (setting, property_info->property_name, value, NULL); - return TRUE; + return value; } /*****************************************************************************/ @@ -6516,9 +6522,9 @@ static const NMMetaPropertyInfo *const property_infos_WIRELESS_SECURITY[] = { ), PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_PSK, .is_secret = TRUE, - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_gobject, - .set_fcn = _set_fcn_wireless_security_psk, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_string, + .validate_fcn = _validate_fcn_wireless_security_psk, ), ), PROPERTY_INFO_WITH_DESC (NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS, diff --git a/clients/common/nm-meta-setting-desc.h b/clients/common/nm-meta-setting-desc.h index f46b86a01..ea77bf7ee 100644 --- a/clients/common/nm-meta-setting-desc.h +++ b/clients/common/nm-meta-setting-desc.h @@ -236,6 +236,9 @@ struct _NMMetaPropertyTypData { int max; const struct _NMUtilsEnumValueInfo *value_infos; } gobject_enum; + struct { + const char *(*validate_fcn) (const char *value, char **out_to_free, GError **error); + } gobject_string; struct { guint32 (*get_fcn) (NMSetting *setting); } mtu;