2020-09-29 16:42:22 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2019-09-25 13:13:40 +02:00
|
|
|
/*
|
2019-10-01 09:20:35 +02:00
|
|
|
* Copyright (C) 2010 - 2017 Red Hat, Inc.
|
2017-03-31 14:45:46 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "nm-default.h"
|
|
|
|
|
|
|
|
|
|
#include "nm-meta-setting-access.h"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
libnm: use NMMetaSettingInfo for tracking setting priority
Previously, each (non abstract) NMSetting class had to register
its name and priority via _nm_register_setting().
Note, that libnm-core.la already links against "nm-meta-setting.c",
which also redundantly keeps track of the settings name and gtype
as well.
Re-use NMMetaSettingInfo also in libnm-core.la, to track this meta
data.
The goal is to get rid of private data structures that track
meta data about NMSetting classes. In this case, "registered_settings"
hash. Instead, we should have one place where all this meta data
is tracked. This was, it is also accessible as internal API,
which can be useful (for keyfile).
Note that NMSettingClass has some overlap with NMMetaSettingInfo.
One difference is, that NMMetaSettingInfo is const, while NMSettingClass
is only initialized during the class_init() method. Appart from that,
it's mostly a matter of taste, whether we attach meta data to
NMSettingClass, to NMMetaSettingInfo, or to a static-array indexed
by NMMetaSettingType.
Note, that previously, _nm_register_setting() was private API. That
means, no user could subclass a functioning NMSetting instance. The same
is still true: NMMetaSettingInfo is internal API and users cannot access
it to create their own NMSetting subclasses. But that is almost desired.
libnm is not designed, to be extensible via subclassing, nor is it
clear why that would be a useful thing to do. One day, we should remove
the NMSetting and NMSettingClass definitions from public headers. Their
only use is subclassing the types, which however does not work.
While libnm-core was linking already against nm-meta-setting.c,
nm_meta_setting_infos was unreferenced. So, this change increases
the binary size of libnm and NetworkManager (1032 bytes). Note however
that roughly the same information was previously allocated at runtime.
2018-07-27 14:08:14 +02:00
|
|
|
static const NMMetaSettingInfoEditor *
|
|
|
|
|
_get_meta_setting_info_editor_from_msi(const NMMetaSettingInfo *meta_setting_info)
|
|
|
|
|
{
|
|
|
|
|
const NMMetaSettingInfoEditor *setting_info;
|
|
|
|
|
|
|
|
|
|
if (!meta_setting_info)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
nm_assert(meta_setting_info->get_setting_gtype);
|
|
|
|
|
nm_assert(meta_setting_info->meta_type < G_N_ELEMENTS(nm_meta_setting_infos_editor));
|
|
|
|
|
|
|
|
|
|
setting_info = &nm_meta_setting_infos_editor[meta_setting_info->meta_type];
|
|
|
|
|
|
|
|
|
|
nm_assert(setting_info->general == meta_setting_info);
|
|
|
|
|
return setting_info;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 14:45:46 +02:00
|
|
|
const NMMetaSettingInfoEditor *
|
2017-04-11 11:31:27 +02:00
|
|
|
nm_meta_setting_info_editor_find_by_name(const char *setting_name, gboolean use_alias)
|
2017-03-31 14:45:46 +02:00
|
|
|
{
|
|
|
|
|
const NMMetaSettingInfoEditor *setting_info;
|
2017-04-11 11:31:27 +02:00
|
|
|
guint i;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-03-31 14:45:46 +02:00
|
|
|
g_return_val_if_fail(setting_name, NULL);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
libnm: use NMMetaSettingInfo for tracking setting priority
Previously, each (non abstract) NMSetting class had to register
its name and priority via _nm_register_setting().
Note, that libnm-core.la already links against "nm-meta-setting.c",
which also redundantly keeps track of the settings name and gtype
as well.
Re-use NMMetaSettingInfo also in libnm-core.la, to track this meta
data.
The goal is to get rid of private data structures that track
meta data about NMSetting classes. In this case, "registered_settings"
hash. Instead, we should have one place where all this meta data
is tracked. This was, it is also accessible as internal API,
which can be useful (for keyfile).
Note that NMSettingClass has some overlap with NMMetaSettingInfo.
One difference is, that NMMetaSettingInfo is const, while NMSettingClass
is only initialized during the class_init() method. Appart from that,
it's mostly a matter of taste, whether we attach meta data to
NMSettingClass, to NMMetaSettingInfo, or to a static-array indexed
by NMMetaSettingType.
Note, that previously, _nm_register_setting() was private API. That
means, no user could subclass a functioning NMSetting instance. The same
is still true: NMMetaSettingInfo is internal API and users cannot access
it to create their own NMSetting subclasses. But that is almost desired.
libnm is not designed, to be extensible via subclassing, nor is it
clear why that would be a useful thing to do. One day, we should remove
the NMSetting and NMSettingClass definitions from public headers. Their
only use is subclassing the types, which however does not work.
While libnm-core was linking already against nm-meta-setting.c,
nm_meta_setting_infos was unreferenced. So, this change increases
the binary size of libnm and NetworkManager (1032 bytes). Note however
that roughly the same information was previously allocated at runtime.
2018-07-27 14:08:14 +02:00
|
|
|
setting_info =
|
|
|
|
|
_get_meta_setting_info_editor_from_msi(nm_meta_setting_infos_by_name(setting_name));
|
2017-04-11 11:31:27 +02:00
|
|
|
if (!setting_info && use_alias) {
|
|
|
|
|
for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) {
|
|
|
|
|
if (nm_streq0(nm_meta_setting_infos_editor[i].alias, setting_name)) {
|
|
|
|
|
setting_info = &nm_meta_setting_infos_editor[i];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-03-31 14:45:46 +02:00
|
|
|
return setting_info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NMMetaSettingInfoEditor *
|
|
|
|
|
nm_meta_setting_info_editor_find_by_gtype(GType gtype)
|
|
|
|
|
{
|
libnm: use NMMetaSettingInfo for tracking setting priority
Previously, each (non abstract) NMSetting class had to register
its name and priority via _nm_register_setting().
Note, that libnm-core.la already links against "nm-meta-setting.c",
which also redundantly keeps track of the settings name and gtype
as well.
Re-use NMMetaSettingInfo also in libnm-core.la, to track this meta
data.
The goal is to get rid of private data structures that track
meta data about NMSetting classes. In this case, "registered_settings"
hash. Instead, we should have one place where all this meta data
is tracked. This was, it is also accessible as internal API,
which can be useful (for keyfile).
Note that NMSettingClass has some overlap with NMMetaSettingInfo.
One difference is, that NMMetaSettingInfo is const, while NMSettingClass
is only initialized during the class_init() method. Appart from that,
it's mostly a matter of taste, whether we attach meta data to
NMSettingClass, to NMMetaSettingInfo, or to a static-array indexed
by NMMetaSettingType.
Note, that previously, _nm_register_setting() was private API. That
means, no user could subclass a functioning NMSetting instance. The same
is still true: NMMetaSettingInfo is internal API and users cannot access
it to create their own NMSetting subclasses. But that is almost desired.
libnm is not designed, to be extensible via subclassing, nor is it
clear why that would be a useful thing to do. One day, we should remove
the NMSetting and NMSettingClass definitions from public headers. Their
only use is subclassing the types, which however does not work.
While libnm-core was linking already against nm-meta-setting.c,
nm_meta_setting_infos was unreferenced. So, this change increases
the binary size of libnm and NetworkManager (1032 bytes). Note however
that roughly the same information was previously allocated at runtime.
2018-07-27 14:08:14 +02:00
|
|
|
return _get_meta_setting_info_editor_from_msi(nm_meta_setting_infos_by_gtype(gtype));
|
2017-03-31 14:45:46 +02:00
|
|
|
}
|
|
|
|
|
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
const NMMetaSettingInfoEditor *
|
2017-03-31 14:45:46 +02:00
|
|
|
nm_meta_setting_info_editor_find_by_setting(NMSetting *setting)
|
|
|
|
|
{
|
|
|
|
|
const NMMetaSettingInfoEditor *setting_info;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail(NM_IS_SETTING(setting), NULL);
|
|
|
|
|
|
|
|
|
|
setting_info = nm_meta_setting_info_editor_find_by_gtype(G_OBJECT_TYPE(setting));
|
|
|
|
|
|
libnm: use NMMetaSettingInfo for tracking setting priority
Previously, each (non abstract) NMSetting class had to register
its name and priority via _nm_register_setting().
Note, that libnm-core.la already links against "nm-meta-setting.c",
which also redundantly keeps track of the settings name and gtype
as well.
Re-use NMMetaSettingInfo also in libnm-core.la, to track this meta
data.
The goal is to get rid of private data structures that track
meta data about NMSetting classes. In this case, "registered_settings"
hash. Instead, we should have one place where all this meta data
is tracked. This was, it is also accessible as internal API,
which can be useful (for keyfile).
Note that NMSettingClass has some overlap with NMMetaSettingInfo.
One difference is, that NMMetaSettingInfo is const, while NMSettingClass
is only initialized during the class_init() method. Appart from that,
it's mostly a matter of taste, whether we attach meta data to
NMSettingClass, to NMMetaSettingInfo, or to a static-array indexed
by NMMetaSettingType.
Note, that previously, _nm_register_setting() was private API. That
means, no user could subclass a functioning NMSetting instance. The same
is still true: NMMetaSettingInfo is internal API and users cannot access
it to create their own NMSetting subclasses. But that is almost desired.
libnm is not designed, to be extensible via subclassing, nor is it
clear why that would be a useful thing to do. One day, we should remove
the NMSetting and NMSettingClass definitions from public headers. Their
only use is subclassing the types, which however does not work.
While libnm-core was linking already against nm-meta-setting.c,
nm_meta_setting_infos was unreferenced. So, this change increases
the binary size of libnm and NetworkManager (1032 bytes). Note however
that roughly the same information was previously allocated at runtime.
2018-07-27 14:08:14 +02:00
|
|
|
nm_assert(setting_info);
|
|
|
|
|
nm_assert(G_TYPE_CHECK_INSTANCE_TYPE(setting, setting_info->general->get_setting_gtype()));
|
2017-03-31 14:45:46 +02:00
|
|
|
return setting_info;
|
|
|
|
|
}
|
|
|
|
|
|
libnm: use NMMetaSettingInfo for tracking setting priority
Previously, each (non abstract) NMSetting class had to register
its name and priority via _nm_register_setting().
Note, that libnm-core.la already links against "nm-meta-setting.c",
which also redundantly keeps track of the settings name and gtype
as well.
Re-use NMMetaSettingInfo also in libnm-core.la, to track this meta
data.
The goal is to get rid of private data structures that track
meta data about NMSetting classes. In this case, "registered_settings"
hash. Instead, we should have one place where all this meta data
is tracked. This was, it is also accessible as internal API,
which can be useful (for keyfile).
Note that NMSettingClass has some overlap with NMMetaSettingInfo.
One difference is, that NMMetaSettingInfo is const, while NMSettingClass
is only initialized during the class_init() method. Appart from that,
it's mostly a matter of taste, whether we attach meta data to
NMSettingClass, to NMMetaSettingInfo, or to a static-array indexed
by NMMetaSettingType.
Note, that previously, _nm_register_setting() was private API. That
means, no user could subclass a functioning NMSetting instance. The same
is still true: NMMetaSettingInfo is internal API and users cannot access
it to create their own NMSetting subclasses. But that is almost desired.
libnm is not designed, to be extensible via subclassing, nor is it
clear why that would be a useful thing to do. One day, we should remove
the NMSetting and NMSettingClass definitions from public headers. Their
only use is subclassing the types, which however does not work.
While libnm-core was linking already against nm-meta-setting.c,
nm_meta_setting_infos was unreferenced. So, this change increases
the binary size of libnm and NetworkManager (1032 bytes). Note however
that roughly the same information was previously allocated at runtime.
2018-07-27 14:08:14 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2017-03-31 14:45:46 +02:00
|
|
|
const NMMetaPropertyInfo *
|
|
|
|
|
nm_meta_setting_info_editor_get_property_info(const NMMetaSettingInfoEditor *setting_info,
|
|
|
|
|
const char * property_name)
|
|
|
|
|
{
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail(setting_info, NULL);
|
|
|
|
|
g_return_val_if_fail(property_name, NULL);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < setting_info->properties_num; i++) {
|
2017-04-12 19:00:03 +02:00
|
|
|
nm_assert(setting_info->properties[i]->property_name);
|
|
|
|
|
nm_assert(setting_info->properties[i]->setting_info == setting_info);
|
|
|
|
|
if (nm_streq(setting_info->properties[i]->property_name, property_name))
|
|
|
|
|
return setting_info->properties[i];
|
2017-03-31 14:45:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-31 11:36:09 +02:00
|
|
|
gboolean
|
|
|
|
|
nm_meta_setting_info_editor_has_secrets(const NMMetaSettingInfoEditor *setting_info)
|
|
|
|
|
{
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
if (!setting_info)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < setting_info->properties_num; i++) {
|
|
|
|
|
if (setting_info->properties[i]->is_secret)
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 14:45:46 +02:00
|
|
|
const NMMetaPropertyInfo *
|
2017-03-31 16:16:06 +02:00
|
|
|
nm_meta_property_info_find_by_name(const char *setting_name, const char *property_name)
|
2017-03-31 14:45:46 +02:00
|
|
|
{
|
|
|
|
|
const NMMetaSettingInfoEditor *setting_info;
|
2017-03-31 16:16:06 +02:00
|
|
|
const NMMetaPropertyInfo * property_info;
|
2017-03-31 14:45:46 +02:00
|
|
|
|
2017-04-11 11:31:27 +02:00
|
|
|
setting_info = nm_meta_setting_info_editor_find_by_name(setting_name, FALSE);
|
2017-03-31 14:45:46 +02:00
|
|
|
if (!setting_info)
|
|
|
|
|
return NULL;
|
2017-03-31 16:16:06 +02:00
|
|
|
|
|
|
|
|
property_info = nm_meta_setting_info_editor_get_property_info(setting_info, property_name);
|
2017-04-12 09:10:14 +02:00
|
|
|
if (!property_info)
|
|
|
|
|
return NULL;
|
2017-03-31 16:16:06 +02:00
|
|
|
|
|
|
|
|
nm_assert(property_info->setting_info == setting_info);
|
|
|
|
|
|
|
|
|
|
return property_info;
|
2017-03-31 14:45:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NMMetaPropertyInfo *
|
2017-03-31 16:16:06 +02:00
|
|
|
nm_meta_property_info_find_by_setting(NMSetting *setting, const char *property_name)
|
2017-03-31 14:45:46 +02:00
|
|
|
{
|
|
|
|
|
const NMMetaSettingInfoEditor *setting_info;
|
|
|
|
|
const NMMetaPropertyInfo * property_info;
|
|
|
|
|
|
|
|
|
|
setting_info = nm_meta_setting_info_editor_find_by_setting(setting);
|
|
|
|
|
if (!setting_info)
|
|
|
|
|
return NULL;
|
|
|
|
|
property_info = nm_meta_setting_info_editor_get_property_info(setting_info, property_name);
|
2017-04-12 09:10:14 +02:00
|
|
|
if (!property_info)
|
|
|
|
|
return NULL;
|
2017-03-31 14:45:46 +02:00
|
|
|
|
2017-03-31 16:16:06 +02:00
|
|
|
nm_assert(property_info->setting_info == setting_info);
|
|
|
|
|
nm_assert(property_info
|
|
|
|
|
== nm_meta_property_info_find_by_name(nm_setting_get_name(setting), property_name));
|
2017-03-31 14:45:46 +02:00
|
|
|
|
|
|
|
|
return property_info;
|
|
|
|
|
}
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
|
2017-04-12 10:13:41 +02:00
|
|
|
NMSetting *
|
|
|
|
|
nm_meta_setting_info_editor_new_setting(const NMMetaSettingInfoEditor *setting_info,
|
|
|
|
|
NMMetaAccessorSettingInitType init_type)
|
|
|
|
|
{
|
|
|
|
|
NMSetting *setting;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail(setting_info, NULL);
|
|
|
|
|
|
|
|
|
|
setting = g_object_new(setting_info->general->get_setting_gtype(), NULL);
|
|
|
|
|
|
|
|
|
|
if (setting_info->setting_init_fcn && init_type != NM_META_ACCESSOR_SETTING_INIT_TYPE_DEFAULT) {
|
|
|
|
|
setting_info->setting_init_fcn(setting_info, setting, init_type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return setting;
|
|
|
|
|
}
|
|
|
|
|
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
const NMMetaSettingInfoEditor *const *
|
|
|
|
|
nm_meta_setting_infos_editor_p(void)
|
|
|
|
|
{
|
|
|
|
|
static const NMMetaSettingInfoEditor *cache[_NM_META_SETTING_TYPE_NUM + 1] = {NULL};
|
|
|
|
|
guint i;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
if (G_UNLIKELY(!cache[0])) {
|
|
|
|
|
for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++)
|
|
|
|
|
cache[i] = &nm_meta_setting_infos_editor[i];
|
|
|
|
|
}
|
|
|
|
|
return cache;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-05 15:48:53 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
const char *
|
2017-04-06 15:14:23 +02:00
|
|
|
nm_meta_abstract_info_get_name(const NMMetaAbstractInfo *abstract_info, gboolean for_header)
|
2017-04-05 15:48:53 +02:00
|
|
|
{
|
|
|
|
|
const char *n;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-05 15:48:53 +02:00
|
|
|
nm_assert(abstract_info);
|
|
|
|
|
nm_assert(abstract_info->meta_type);
|
|
|
|
|
nm_assert(abstract_info->meta_type->get_name);
|
2017-04-06 15:14:23 +02:00
|
|
|
n = abstract_info->meta_type->get_name(abstract_info, for_header);
|
2017-04-05 15:48:53 +02:00
|
|
|
nm_assert(n && n[0]);
|
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NMMetaAbstractInfo *const *
|
|
|
|
|
nm_meta_abstract_info_get_nested(const NMMetaAbstractInfo *abstract_info,
|
|
|
|
|
guint * out_len,
|
|
|
|
|
gpointer * nested_to_free)
|
|
|
|
|
{
|
|
|
|
|
const NMMetaAbstractInfo *const *nested;
|
|
|
|
|
guint l = 0;
|
|
|
|
|
gs_free gpointer f = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-05 15:48:53 +02:00
|
|
|
nm_assert(abstract_info);
|
|
|
|
|
nm_assert(abstract_info->meta_type);
|
|
|
|
|
nm_assert(nested_to_free && !*nested_to_free);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-05 15:48:53 +02:00
|
|
|
if (abstract_info->meta_type->get_nested) {
|
|
|
|
|
nested = abstract_info->meta_type->get_nested(abstract_info, &l, &f);
|
2018-05-03 10:10:07 +02:00
|
|
|
nm_assert(NM_PTRARRAY_LEN(nested) == l);
|
|
|
|
|
nm_assert(!f || nested == f);
|
2017-04-05 15:48:53 +02:00
|
|
|
if (nested && nested[0]) {
|
|
|
|
|
NM_SET_OUT(out_len, l);
|
|
|
|
|
*nested_to_free = g_steal_pointer(&f);
|
|
|
|
|
return nested;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
NM_SET_OUT(out_len, 0);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2017-04-04 15:23:39 +02:00
|
|
|
|
|
|
|
|
gconstpointer
|
|
|
|
|
nm_meta_abstract_info_get(const NMMetaAbstractInfo * abstract_info,
|
|
|
|
|
const NMMetaEnvironment * environment,
|
|
|
|
|
gpointer environment_user_data,
|
|
|
|
|
gpointer target,
|
2018-04-30 13:01:20 +02:00
|
|
|
gpointer target_data,
|
2017-04-04 15:23:39 +02:00
|
|
|
NMMetaAccessorGetType get_type,
|
|
|
|
|
NMMetaAccessorGetFlags get_flags,
|
2017-04-06 15:14:23 +02:00
|
|
|
NMMetaAccessorGetOutFlags *out_flags,
|
2018-02-27 15:34:49 +01:00
|
|
|
gboolean * out_is_default,
|
2017-04-04 15:23:39 +02:00
|
|
|
gpointer * out_to_free)
|
|
|
|
|
{
|
|
|
|
|
nm_assert(abstract_info);
|
|
|
|
|
nm_assert(abstract_info->meta_type);
|
|
|
|
|
nm_assert(!out_to_free || !*out_to_free);
|
2017-04-06 15:14:23 +02:00
|
|
|
nm_assert(out_flags);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-06 15:14:23 +02:00
|
|
|
*out_flags = NM_META_ACCESSOR_GET_OUT_FLAGS_NONE;
|
2018-02-27 15:34:49 +01:00
|
|
|
NM_SET_OUT(out_is_default, FALSE);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-04 15:23:39 +02:00
|
|
|
if (!abstract_info->meta_type->get_fcn)
|
|
|
|
|
g_return_val_if_reached(NULL);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-07 12:58:13 +02:00
|
|
|
return abstract_info->meta_type->get_fcn(abstract_info,
|
|
|
|
|
environment,
|
|
|
|
|
environment_user_data,
|
2017-04-04 15:23:39 +02:00
|
|
|
target,
|
2018-04-30 13:01:20 +02:00
|
|
|
target_data,
|
2017-04-04 15:23:39 +02:00
|
|
|
get_type,
|
|
|
|
|
get_flags,
|
2017-04-06 15:14:23 +02:00
|
|
|
out_flags,
|
2018-02-27 15:34:49 +01:00
|
|
|
out_is_default,
|
2017-04-04 15:23:39 +02:00
|
|
|
out_to_free);
|
|
|
|
|
}
|
2017-04-10 16:38:35 +02:00
|
|
|
|
|
|
|
|
const char *const *
|
|
|
|
|
nm_meta_abstract_info_complete(const NMMetaAbstractInfo * abstract_info,
|
2017-04-11 15:48:04 +02:00
|
|
|
const NMMetaEnvironment * environment,
|
|
|
|
|
gpointer environment_user_data,
|
2017-04-11 15:48:04 +02:00
|
|
|
const NMMetaOperationContext *operation_context,
|
2017-04-10 16:38:35 +02:00
|
|
|
const char * text,
|
2019-04-23 21:35:19 +02:00
|
|
|
gboolean * out_complete_filename,
|
2017-04-10 16:38:35 +02:00
|
|
|
char *** out_to_free)
|
|
|
|
|
{
|
|
|
|
|
const char *const *values;
|
|
|
|
|
gsize i, j, text_len;
|
|
|
|
|
|
|
|
|
|
nm_assert(abstract_info);
|
|
|
|
|
nm_assert(abstract_info->meta_type);
|
|
|
|
|
nm_assert(out_to_free && !*out_to_free);
|
|
|
|
|
|
|
|
|
|
*out_to_free = NULL;
|
|
|
|
|
|
|
|
|
|
if (!abstract_info->meta_type->complete_fcn)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
values = abstract_info->meta_type->complete_fcn(abstract_info,
|
2017-04-11 15:48:04 +02:00
|
|
|
environment,
|
|
|
|
|
environment_user_data,
|
2017-04-11 15:48:04 +02:00
|
|
|
operation_context,
|
2017-04-10 16:38:35 +02:00
|
|
|
text,
|
2019-04-23 21:35:19 +02:00
|
|
|
out_complete_filename,
|
2017-04-10 16:38:35 +02:00
|
|
|
out_to_free);
|
|
|
|
|
|
|
|
|
|
nm_assert(!*out_to_free || values == (const char *const *) *out_to_free);
|
|
|
|
|
|
2017-06-28 14:28:58 +02:00
|
|
|
if (!values)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
if (!values[0]) {
|
|
|
|
|
nm_clear_g_free(out_to_free);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!text || !text[0])
|
2017-04-10 16:38:35 +02:00
|
|
|
return values;
|
|
|
|
|
|
2017-06-28 14:28:58 +02:00
|
|
|
/* for convenience, we allow the complete_fcn() implementations to
|
2017-04-10 16:38:35 +02:00
|
|
|
* ignore "text". We filter out invalid matches here. */
|
|
|
|
|
|
|
|
|
|
text_len = strlen(text);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-10 16:38:35 +02:00
|
|
|
if (*out_to_free) {
|
|
|
|
|
char **v = *out_to_free;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-06-21 14:18:24 +02:00
|
|
|
for (i = 0, j = 0; v[i]; i++) {
|
2017-06-28 14:28:58 +02:00
|
|
|
if (strncmp(v[i], text, text_len) != 0) {
|
|
|
|
|
g_free(v[i]);
|
2017-04-10 16:38:35 +02:00
|
|
|
continue;
|
2017-06-28 14:28:58 +02:00
|
|
|
}
|
2017-04-10 16:38:35 +02:00
|
|
|
v[j++] = v[i];
|
|
|
|
|
}
|
2017-06-21 14:18:24 +02:00
|
|
|
if (j)
|
|
|
|
|
v[j++] = NULL;
|
|
|
|
|
else {
|
|
|
|
|
g_free(v);
|
2017-06-28 14:28:58 +02:00
|
|
|
*out_to_free = v = NULL;
|
2017-06-21 14:18:24 +02:00
|
|
|
}
|
|
|
|
|
return (const char *const *) v;
|
2017-04-10 16:38:35 +02:00
|
|
|
} else {
|
|
|
|
|
const char *const *v = values;
|
|
|
|
|
char ** r;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-10 16:38:35 +02:00
|
|
|
for (i = 0, j = 0; v[i]; i++) {
|
|
|
|
|
if (strncmp(v[i], text, text_len) != 0)
|
|
|
|
|
continue;
|
|
|
|
|
j++;
|
|
|
|
|
}
|
|
|
|
|
if (j == i)
|
|
|
|
|
return values;
|
2017-06-21 14:18:24 +02:00
|
|
|
else if (!j)
|
|
|
|
|
return NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-10 16:38:35 +02:00
|
|
|
r = g_new(char *, j + 1);
|
|
|
|
|
v = values;
|
|
|
|
|
for (i = 0, j = 0; v[i]; i++) {
|
|
|
|
|
if (strncmp(v[i], text, text_len) != 0)
|
|
|
|
|
continue;
|
|
|
|
|
r[j++] = g_strdup(v[i]);
|
|
|
|
|
}
|
|
|
|
|
r[j++] = NULL;
|
|
|
|
|
return (const char *const *) (*out_to_free = r);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-12 15:19:26 +02:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
nm_meta_abstract_info_get_nested_names_str(const NMMetaAbstractInfo *abstract_info,
|
|
|
|
|
const char * name_prefix)
|
|
|
|
|
{
|
|
|
|
|
gs_free gpointer nested_to_free = NULL;
|
|
|
|
|
const NMMetaAbstractInfo *const *nested;
|
|
|
|
|
|
|
|
|
|
nested = nm_meta_abstract_info_get_nested(abstract_info, NULL, &nested_to_free);
|
|
|
|
|
if (!nested)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
if (!name_prefix)
|
|
|
|
|
name_prefix = nm_meta_abstract_info_get_name(abstract_info, FALSE);
|
|
|
|
|
|
2018-05-03 11:02:54 +02:00
|
|
|
return nm_meta_abstract_infos_get_names_str(nested, name_prefix);
|
2017-04-12 15:19:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
nm_meta_abstract_infos_get_names_str(const NMMetaAbstractInfo *const *fields_array,
|
|
|
|
|
const char * name_prefix)
|
|
|
|
|
{
|
2018-05-03 11:02:54 +02:00
|
|
|
GString *str;
|
2017-04-12 15:19:26 +02:00
|
|
|
guint i;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
if (!fields_array || !fields_array[0])
|
|
|
|
|
return NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-05-03 11:02:54 +02:00
|
|
|
str = g_string_sized_new(128);
|
2017-04-12 15:19:26 +02:00
|
|
|
for (i = 0; fields_array[i]; i++) {
|
2018-05-03 11:02:54 +02:00
|
|
|
if (str->len > 0)
|
|
|
|
|
g_string_append_c(str, ',');
|
|
|
|
|
if (name_prefix) {
|
|
|
|
|
g_string_append(str, name_prefix);
|
|
|
|
|
g_string_append_c(str, '.');
|
|
|
|
|
}
|
|
|
|
|
g_string_append(str, nm_meta_abstract_info_get_name(fields_array[i], FALSE));
|
2017-04-12 15:19:26 +02:00
|
|
|
}
|
2018-05-03 11:02:54 +02:00
|
|
|
return g_string_free(str, FALSE);
|
2017-04-12 15:19:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
guint idx;
|
|
|
|
|
gsize self_offset_plus_1;
|
|
|
|
|
gsize sub_offset_plus_1;
|
|
|
|
|
} OutputSelectionItem;
|
|
|
|
|
|
|
|
|
|
static NMMetaSelectionResultList *
|
|
|
|
|
_output_selection_pack(const NMMetaAbstractInfo *const *fields_array, GArray *array, GString *str)
|
|
|
|
|
{
|
|
|
|
|
NMMetaSelectionResultList *result;
|
|
|
|
|
guint i;
|
|
|
|
|
guint len;
|
|
|
|
|
|
|
|
|
|
len = array ? array->len : 0;
|
|
|
|
|
|
|
|
|
|
/* re-organize the collected output data in one buffer that can be freed using
|
|
|
|
|
* g_free(). This makes allocation more complicated, but saves us from special
|
|
|
|
|
* handling for free. */
|
|
|
|
|
result = g_malloc0(sizeof(NMMetaSelectionResultList) + (len * sizeof(NMMetaSelectionItem))
|
|
|
|
|
+ (str ? str->len : 0));
|
|
|
|
|
*((guint *) &result->num) = len;
|
|
|
|
|
if (len > 0) {
|
|
|
|
|
char *pdata =
|
|
|
|
|
&((char *)
|
|
|
|
|
result)[sizeof(NMMetaSelectionResultList) + (len * sizeof(NMMetaSelectionItem))];
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
if (str)
|
|
|
|
|
memcpy(pdata, str->str, str->len);
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
|
const OutputSelectionItem *a = &g_array_index(array, OutputSelectionItem, i);
|
|
|
|
|
NMMetaSelectionItem * p = (NMMetaSelectionItem *) &result->items[i];
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
p->info = fields_array[a->idx];
|
|
|
|
|
p->idx = a->idx;
|
|
|
|
|
if (a->self_offset_plus_1 > 0)
|
|
|
|
|
p->self_selection = &pdata[a->self_offset_plus_1 - 1];
|
|
|
|
|
if (a->sub_offset_plus_1 > 0)
|
|
|
|
|
p->sub_selection = &pdata[a->sub_offset_plus_1 - 1];
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
_output_selection_select_one(const NMMetaAbstractInfo *const *fields_array,
|
|
|
|
|
const char * fields_prefix,
|
|
|
|
|
const char * fields_str,
|
|
|
|
|
gboolean validate_nested,
|
|
|
|
|
GArray ** p_array,
|
|
|
|
|
GString ** p_str,
|
|
|
|
|
GError ** error)
|
|
|
|
|
{
|
|
|
|
|
guint i, j;
|
|
|
|
|
const char * i_name;
|
|
|
|
|
const char * right;
|
|
|
|
|
gboolean found = FALSE;
|
|
|
|
|
const NMMetaAbstractInfo *fields_array_failure = NULL;
|
|
|
|
|
gs_free char * fields_str_clone = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
nm_assert(fields_str);
|
|
|
|
|
nm_assert(p_array);
|
|
|
|
|
nm_assert(p_str);
|
|
|
|
|
nm_assert(!error || !*error);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
right = strchr(fields_str, '.');
|
|
|
|
|
if (right) {
|
|
|
|
|
fields_str_clone = g_strdup(fields_str);
|
|
|
|
|
fields_str_clone[right - fields_str] = '\0';
|
|
|
|
|
i_name = fields_str_clone;
|
|
|
|
|
right = &fields_str_clone[right - fields_str + 1];
|
|
|
|
|
} else
|
|
|
|
|
i_name = fields_str;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
if (!fields_array)
|
|
|
|
|
goto not_found;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
for (i = 0; fields_array[i]; i++) {
|
|
|
|
|
const NMMetaAbstractInfo * fi = fields_array[i];
|
|
|
|
|
const NMMetaAbstractInfo *const *nested;
|
|
|
|
|
gs_free gpointer nested_to_free = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
if (g_ascii_strcasecmp(i_name, nm_meta_abstract_info_get_name(fi, FALSE)) != 0)
|
|
|
|
|
continue;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
if (!right || !validate_nested) {
|
|
|
|
|
found = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
nested = nm_meta_abstract_info_get_nested(fi, NULL, &nested_to_free);
|
|
|
|
|
if (nested) {
|
|
|
|
|
for (j = 0; nested[j]; nested++) {
|
|
|
|
|
if (g_ascii_strcasecmp(right, nm_meta_abstract_info_get_name(nested[j], FALSE))
|
|
|
|
|
== 0) {
|
|
|
|
|
found = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fields_array_failure = fields_array[i];
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
if (!found) {
|
|
|
|
|
not_found:
|
|
|
|
|
if (!right && !fields_prefix
|
|
|
|
|
&& (!g_ascii_strcasecmp(i_name, "all") || !g_ascii_strcasecmp(i_name, "common")))
|
|
|
|
|
g_set_error(error,
|
|
|
|
|
NM_UTILS_ERROR,
|
|
|
|
|
NM_UTILS_ERROR_UNKNOWN,
|
|
|
|
|
_("field '%s' has to be alone"),
|
|
|
|
|
i_name);
|
|
|
|
|
else {
|
|
|
|
|
gs_free char *allowed_fields = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
if (fields_array_failure) {
|
|
|
|
|
gs_free char *p = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
if (fields_prefix) {
|
|
|
|
|
p = g_strdup_printf(
|
|
|
|
|
"%s.%s",
|
|
|
|
|
fields_prefix,
|
|
|
|
|
nm_meta_abstract_info_get_name(fields_array_failure, FALSE));
|
|
|
|
|
}
|
|
|
|
|
allowed_fields =
|
|
|
|
|
nm_meta_abstract_info_get_nested_names_str(fields_array_failure, p);
|
|
|
|
|
} else
|
|
|
|
|
allowed_fields = nm_meta_abstract_infos_get_names_str(fields_array, NULL);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
g_set_error(error,
|
|
|
|
|
NM_UTILS_ERROR,
|
|
|
|
|
NM_UTILS_ERROR_UNKNOWN,
|
|
|
|
|
_("invalid field '%s%s%s%s%s'; %s%s%s"),
|
|
|
|
|
fields_prefix ?: "",
|
|
|
|
|
fields_prefix ? "." : "",
|
|
|
|
|
i_name,
|
|
|
|
|
right ? "." : "",
|
|
|
|
|
right ?: "",
|
|
|
|
|
NM_PRINT_FMT_QUOTED(allowed_fields,
|
|
|
|
|
"allowed fields: ",
|
|
|
|
|
allowed_fields,
|
|
|
|
|
"",
|
|
|
|
|
"no fields"));
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
{
|
|
|
|
|
GString * str;
|
|
|
|
|
OutputSelectionItem s = {
|
|
|
|
|
.idx = i,
|
|
|
|
|
};
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
if (!*p_str)
|
|
|
|
|
*p_str = g_string_sized_new(64);
|
|
|
|
|
str = *p_str;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
s.self_offset_plus_1 = str->len + 1;
|
|
|
|
|
if (fields_prefix) {
|
|
|
|
|
g_string_append(str, fields_prefix);
|
|
|
|
|
g_string_append_c(str, '.');
|
|
|
|
|
}
|
|
|
|
|
g_string_append_len(str, i_name, strlen(i_name) + 1);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
if (right) {
|
|
|
|
|
s.sub_offset_plus_1 = str->len + 1;
|
|
|
|
|
g_string_append_len(str, right, strlen(right) + 1);
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
if (!*p_array)
|
|
|
|
|
*p_array = g_array_new(FALSE, FALSE, sizeof(OutputSelectionItem));
|
|
|
|
|
g_array_append_val(*p_array, s);
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NMMetaSelectionResultList *
|
|
|
|
|
nm_meta_selection_create_all(const NMMetaAbstractInfo *const *fields_array)
|
|
|
|
|
{
|
|
|
|
|
gs_unref_array GArray *array = NULL;
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
if (fields_array) {
|
|
|
|
|
array = g_array_new(FALSE, FALSE, sizeof(OutputSelectionItem));
|
|
|
|
|
for (i = 0; fields_array[i]; i++) {
|
|
|
|
|
OutputSelectionItem s = {
|
|
|
|
|
.idx = i,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
g_array_append_val(array, s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _output_selection_pack(fields_array, array, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NMMetaSelectionResultList *
|
|
|
|
|
nm_meta_selection_create_parse_one(
|
|
|
|
|
const NMMetaAbstractInfo *const *fields_array,
|
|
|
|
|
const char * fields_prefix,
|
|
|
|
|
const char *
|
|
|
|
|
fields_str, /* one field selector (contains no commas) and is already stripped of spaces. */
|
|
|
|
|
gboolean validate_nested,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
gs_unref_array GArray *array = NULL;
|
|
|
|
|
nm_auto_free_gstring GString *str = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
g_return_val_if_fail(!error || !*error, NULL);
|
|
|
|
|
nm_assert(fields_str && !strchr(fields_str, ','));
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
if (!_output_selection_select_one(fields_array,
|
|
|
|
|
fields_prefix,
|
|
|
|
|
fields_str,
|
|
|
|
|
validate_nested,
|
|
|
|
|
&array,
|
|
|
|
|
&str,
|
|
|
|
|
error))
|
|
|
|
|
return NULL;
|
|
|
|
|
return _output_selection_pack(fields_array, array, str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NMMetaSelectionResultList *
|
|
|
|
|
nm_meta_selection_create_parse_list(
|
|
|
|
|
const NMMetaAbstractInfo *const *fields_array,
|
|
|
|
|
const char * fields_str, /* a comma separated list of selectors */
|
|
|
|
|
gboolean validate_nested,
|
|
|
|
|
GError ** error)
|
|
|
|
|
{
|
|
|
|
|
gs_unref_array GArray *array = NULL;
|
|
|
|
|
nm_auto_free_gstring GString *str = NULL;
|
|
|
|
|
gs_free char * fields_str_clone = NULL;
|
|
|
|
|
char * fields_str_cur;
|
|
|
|
|
char * fields_str_next;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
g_return_val_if_fail(!error || !*error, NULL);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
if (!fields_str)
|
|
|
|
|
return nm_meta_selection_create_all(fields_array);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
fields_str_clone = g_strdup(fields_str);
|
|
|
|
|
for (fields_str_cur = fields_str_clone; fields_str_cur; fields_str_cur = fields_str_next) {
|
|
|
|
|
fields_str_cur = nm_str_skip_leading_spaces(fields_str_cur);
|
|
|
|
|
fields_str_next = strchr(fields_str_cur, ',');
|
|
|
|
|
if (fields_str_next)
|
|
|
|
|
*fields_str_next++ = '\0';
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
g_strchomp(fields_str_cur);
|
|
|
|
|
if (!fields_str_cur[0])
|
|
|
|
|
continue;
|
|
|
|
|
if (!_output_selection_select_one(fields_array,
|
2018-06-08 17:02:10 +02:00
|
|
|
NULL,
|
2017-04-12 15:19:26 +02:00
|
|
|
fields_str_cur,
|
|
|
|
|
validate_nested,
|
|
|
|
|
&array,
|
|
|
|
|
&str,
|
|
|
|
|
error))
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-12 15:19:26 +02:00
|
|
|
return _output_selection_pack(fields_array, array, str);
|
|
|
|
|
}
|