diff options
author | Thomas Haller <thaller@redhat.com> | 2019-08-25 15:21:05 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-08-26 13:05:50 +0200 |
commit | 50c5f5b0a58e185fa199e835bc9da1707f45e2fb (patch) | |
tree | 4cea169e274acf831beddb5099acbb6d38909af1 | |
parent | 12cdeb31ef996abbf5e4388db375d4d2f2fef05f (diff) | |
download | NetworkManager-th/keyfile-fix-empty-settings.tar.gz |
cli: accept " " as "gsm.apn" to indicate setting to ""th/keyfile-fix-empty-settings
Until just recently, libnm would reject "" as an invalid setting
for "gsm.apn".
%NULL was allowed, and indicated to set the APN in ModemManager to
empty (""). The behavior for $NULL will change to allow lookup the
APN in the mobile-broadband-provider-info. Anyway, "" was kind of
a valid value all along, in fact with the same meaning as %NULL.
(note that oFono implementation migth be different here as it treats
%NULL and "" not the same).
Anyway, since libnm now allows to explicitly set the value to "",
also let nmcli support that. The problem is, that nmcli coerces
"" to %NULL, to reset the value. So, in nmcli, "" already has a
different meaning.
Extend this, so that " " means "", and "" continues to mean %NULL.
Note that the property setter of "gsm.apn" already strips whitespaces
from the APN. So, while we hijack " " to mean "", it was never (and
still is not) possible to set "gsm.apn" to " ". So we can still express
all values that we could previously.
Of course, also the getter needs to be adjsted.
-rw-r--r-- | clients/common/nm-meta-setting-desc.c | 25 | ||||
-rw-r--r-- | clients/common/nm-meta-setting-desc.h | 3 |
2 files changed, 25 insertions, 3 deletions
diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index 6febb49fd6..fad407aed7 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -869,8 +869,21 @@ _get_fcn_gobject_impl (const NMMetaPropertyInfo *property_info, || ( gtype_prop == G_TYPE_STRV && !glib_handles_str_transform)); - if (glib_handles_str_transform) - RETURN_STR_TEMPORARY (g_value_get_string (&val)); + if (glib_handles_str_transform) { + const char *s = g_value_get_string (&val); + + if ( property_info->property_typ_data + && property_info->property_typ_data->coerce_one_space_as_empty) { + /* maybe we should call _coerce_str_emptyunset(), but that quotes + * the entire string. We don't want that either. Just coerce "" to + * " ". */ + if ( s + && s[0] == '\0') + return " "; + } + + RETURN_STR_TEMPORARY (s); + } if (gtype_prop == G_TYPE_BOOLEAN) { gboolean b; @@ -1208,6 +1221,11 @@ _set_fcn_gobject_string (ARGS_SET_FCN) return _gobject_property_reset_default (setting, property_info->property_name); if (property_info->property_typ_data) { + + if ( property_info->property_typ_data->coerce_one_space_as_empty + && nm_streq0 (value, " ")) + value = ""; + 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) @@ -5402,6 +5420,9 @@ static const NMMetaPropertyInfo *const property_infos_GSM[] = { .property_alias = "apn", .prompt = N_("APN"), .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .coerce_one_space_as_empty = TRUE, + ), ), PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_NETWORK_ID, .property_type = &_pt_gobject_string, diff --git a/clients/common/nm-meta-setting-desc.h b/clients/common/nm-meta-setting-desc.h index cb4fe4b259..e539904628 100644 --- a/clients/common/nm-meta-setting-desc.h +++ b/clients/common/nm-meta-setting-desc.h @@ -355,7 +355,8 @@ struct _NMMetaPropertyTypData { gboolean (*is_default_fcn) (NMSetting *setting); const char *const*values_static; const NMMetaPropertyTypDataNested *nested; - NMMetaPropertyTypFlags typ_flags; + NMMetaPropertyTypFlags typ_flags:7; + bool coerce_one_space_as_empty:1; }; typedef enum { |