libnm/keyfile: add parser_full() hook for reading non GObject based properties

This commit is contained in:
Thomas Haller 2019-03-22 15:16:48 +01:00
parent c02fadecec
commit 408d637930

View file

@ -2275,9 +2275,16 @@ cert_writer (KeyfileWriterInfo *info,
struct _ParseInfoProperty { struct _ParseInfoProperty {
const char *property_name; const char *property_name;
void (*parser) (KeyfileReaderInfo *info, union {
NMSetting *setting, void (*parser) (KeyfileReaderInfo *info,
const char *key); NMSetting *setting,
const char *key);
void (*parser_full) (KeyfileReaderInfo *info,
const NMMetaSettingInfo *setting_info,
const NMSettInfoProperty *property_info,
const ParseInfoProperty *pip,
NMSetting *setting);
};
union { union {
void (*writer) (KeyfileWriterInfo *info, void (*writer) (KeyfileWriterInfo *info,
NMSetting *setting, NMSetting *setting,
@ -2293,6 +2300,7 @@ struct _ParseInfoProperty {
bool parser_no_check_key:1; bool parser_no_check_key:1;
bool writer_skip:1; bool writer_skip:1;
bool has_writer_full:1; bool has_writer_full:1;
bool has_parser_full:1;
/* usually, we skip to write values that have their /* usually, we skip to write values that have their
* default value. By setting this flag to TRUE, also * default value. By setting this flag to TRUE, also
@ -2742,23 +2750,33 @@ read_one_setting_value (KeyfileReaderInfo *info,
gint64 i64; gint64 i64;
nm_assert (!info->error); nm_assert (!info->error);
nm_assert (property_info->param_spec); nm_assert ( !property_info->param_spec
|| nm_streq (property_info->param_spec->name, property_info->name));
if ((property_info->param_spec->flags & (G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)) != G_PARAM_WRITABLE) key = property_info->name;
return;
key = property_info->param_spec->name;
pip = _parse_info_find (setting, key, &setting_info); pip = _parse_info_find (setting, key, &setting_info);
nm_assert (setting_info); nm_assert (setting_info);
if ( !pip if (!pip) {
&& nm_streq (key, NM_SETTING_NAME)) if (nm_streq (key, NM_SETTING_NAME))
return; return;
if (!property_info->param_spec)
return;
if ((property_info->param_spec->flags & (G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)) != G_PARAM_WRITABLE)
return;
} else {
if (pip->parser_skip)
return;
if (pip->has_parser_full) {
pip->parser_full (info, setting_info, property_info, pip, setting);
return;
}
}
if (pip && pip->parser_skip) nm_assert (property_info->param_spec);
return; nm_assert ((property_info->param_spec->flags & (G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)) == G_PARAM_WRITABLE);
/* Check for the exact key in the GKeyFile if required. Most setting /* Check for the exact key in the GKeyFile if required. Most setting
* properties map 1:1 to a key in the GKeyFile, but for those properties * properties map 1:1 to a key in the GKeyFile, but for those properties
@ -2777,7 +2795,8 @@ read_one_setting_value (KeyfileReaderInfo *info,
return; return;
} }
if (pip && pip->parser) { if ( pip
&& pip->parser) {
pip->parser (info, setting, key); pip->parser (info, setting, key);
return; return;
} }
@ -3027,13 +3046,11 @@ _read_setting (KeyfileReaderInfo *info)
} }
for (i = 0; i < sett_info->property_infos_len; i++) { for (i = 0; i < sett_info->property_infos_len; i++) {
const NMSettInfoProperty *property_info = &sett_info->property_infos[i]; read_one_setting_value (info,
setting,
if (property_info->param_spec) { &sett_info->property_infos[i]);
read_one_setting_value (info, setting, property_info); if (info->error)
if (info->error) goto out;
goto out;
}
} }
out: out: