mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 18:50:07 +01:00
cli: add get_fcn() to NMMetaAbstractInfo
This commit is contained in:
parent
022117ff36
commit
19c70ace95
5 changed files with 121 additions and 14 deletions
|
|
@ -83,10 +83,32 @@ _meta_type_nmc_generic_info_get_nested (const NMMetaAbstractInfo *abstract_info,
|
|||
return (const NMMetaAbstractInfo *const*) info->nested;
|
||||
}
|
||||
|
||||
static const char *
|
||||
_meta_type_nmc_generic_info_get_fcn (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NMMetaAbstractInfo *abstract_info,
|
||||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
char **out_to_free)
|
||||
{
|
||||
const NmcMetaGenericInfo *info = (const NmcMetaGenericInfo *) abstract_info;
|
||||
|
||||
nm_assert (out_to_free && !*out_to_free);
|
||||
|
||||
if (!info->get_fcn)
|
||||
g_return_val_if_reached (NULL);
|
||||
return info->get_fcn (environment, environment_user_data,
|
||||
info, target,
|
||||
get_type, get_flags,
|
||||
out_to_free);
|
||||
}
|
||||
|
||||
const NMMetaType nmc_meta_type_generic_info = {
|
||||
.type_name = "nmc-generic-info",
|
||||
.get_name = _meta_type_nmc_generic_info_get_name,
|
||||
.get_nested = _meta_type_nmc_generic_info_get_nested,
|
||||
.get_fcn = _meta_type_nmc_generic_info_get_fcn,
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
|
|
@ -117,6 +117,13 @@ struct _NmcMetaGenericInfo {
|
|||
const NMMetaType *meta_type;
|
||||
const char *name;
|
||||
const NmcMetaGenericInfo *const*nested;
|
||||
const char *(*get_fcn) (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NmcMetaGenericInfo *info,
|
||||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
char **out_to_free);
|
||||
};
|
||||
|
||||
#define NMC_META_GENERIC(n, ...) \
|
||||
|
|
|
|||
|
|
@ -475,10 +475,12 @@ get_property_val (NMSetting *setting, const char *prop, NMMetaAccessorGetType ge
|
|||
/* Traditionally, the "name" property was not handled here.
|
||||
* For the moment, skip it from get_property_val(). */
|
||||
} else if (property_info->property_type->get_fcn) {
|
||||
return property_info->property_type->get_fcn (property_info,
|
||||
return property_info->property_type->get_fcn (&meta_environment,
|
||||
NULL,
|
||||
property_info,
|
||||
setting,
|
||||
get_type,
|
||||
show_secrets);
|
||||
show_secrets ? NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS : 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -853,10 +855,12 @@ setting_details (const NmcConfig *nmc_config, NMSetting *setting, const char *on
|
|||
nm_assert (property_info->setting_info == setting_info);
|
||||
|
||||
if (!property_info->is_secret || show_secrets) {
|
||||
set_val_str (arr, i, property_info->property_type->get_fcn (property_info,
|
||||
set_val_str (arr, i, property_info->property_type->get_fcn (&meta_environment,
|
||||
NULL,
|
||||
property_info,
|
||||
setting,
|
||||
type,
|
||||
show_secrets));
|
||||
show_secrets ? NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS : 0));
|
||||
} else
|
||||
set_val_str (arr, i, g_strdup (_(NM_META_TEXT_HIDDEN)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -528,7 +528,7 @@ _env_warn_fcn (const NMMetaEnvironment *environment,
|
|||
const NMMetaPropertyInfo *property_info, char **out_to_free
|
||||
|
||||
#define ARGS_GET_FCN \
|
||||
const NMMetaPropertyInfo *property_info, NMSetting *setting, NMMetaAccessorGetType get_type, gboolean show_secrets
|
||||
const NMMetaEnvironment *environment, gpointer environment_user_data, const NMMetaPropertyInfo *property_info, NMSetting *setting, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags
|
||||
|
||||
#define ARGS_SET_FCN \
|
||||
const NMMetaEnvironment *environment, gpointer environment_user_data, const NMMetaPropertyInfo *property_info, NMSetting *setting, const char *value, GError **error
|
||||
|
|
@ -571,18 +571,28 @@ _get_fcn_nmc_with_default (ARGS_GET_FCN)
|
|||
}
|
||||
|
||||
static char *
|
||||
_get_fcn_gobject (ARGS_GET_FCN)
|
||||
_get_fcn_gobject_impl (const NMMetaPropertyInfo *property_info,
|
||||
NMSetting *setting,
|
||||
NMMetaAccessorGetType get_type)
|
||||
{
|
||||
char *s;
|
||||
const char *s_c;
|
||||
GType gtype_prop;
|
||||
nm_auto_unset_gvalue GValue val = G_VALUE_INIT;
|
||||
|
||||
gtype_prop = _gobject_property_get_gtype (G_OBJECT (setting), property_info->property_name);
|
||||
|
||||
if (gtype_prop == G_TYPE_BOOLEAN) {
|
||||
gboolean b;
|
||||
|
||||
g_value_init (&val, gtype_prop);
|
||||
g_object_get_property (G_OBJECT (setting), property_info->property_name, &val);
|
||||
s = g_strdup (g_value_get_boolean (&val) ? "yes" : "no");
|
||||
b = g_value_get_boolean (&val);
|
||||
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
|
||||
s_c = b ? _("yes") : _("no");
|
||||
else
|
||||
s_c = b ? "yes" : "no";
|
||||
s = g_strdup (s_c);
|
||||
} else {
|
||||
g_value_init (&val, G_TYPE_STRING);
|
||||
g_object_get_property (G_OBJECT (setting), property_info->property_name, &val);
|
||||
|
|
@ -591,6 +601,12 @@ _get_fcn_gobject (ARGS_GET_FCN)
|
|||
return s;
|
||||
}
|
||||
|
||||
static char *
|
||||
_get_fcn_gobject (ARGS_GET_FCN)
|
||||
{
|
||||
return _get_fcn_gobject_impl (property_info, setting, get_type);
|
||||
}
|
||||
|
||||
static char *
|
||||
_get_fcn_gobject_mtu (ARGS_GET_FCN)
|
||||
{
|
||||
|
|
@ -598,7 +614,7 @@ _get_fcn_gobject_mtu (ARGS_GET_FCN)
|
|||
|
||||
if ( !property_info->property_typ_data
|
||||
|| !property_info->property_typ_data->subtype.mtu.get_fcn)
|
||||
return _get_fcn_gobject (property_info, setting, get_type, show_secrets);
|
||||
return _get_fcn_gobject_impl (property_info, setting, get_type);
|
||||
|
||||
mtu = property_info->property_typ_data->subtype.mtu.get_fcn (setting);
|
||||
if (mtu == 0) {
|
||||
|
|
@ -1646,7 +1662,7 @@ _get_fcn_802_1x_client_cert (ARGS_GET_FCN)
|
|||
|
||||
switch (nm_setting_802_1x_get_client_cert_scheme (s_8021X)) {
|
||||
case NM_SETTING_802_1X_CK_SCHEME_BLOB:
|
||||
if (show_secrets)
|
||||
if (NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS))
|
||||
cert_str = bytes_to_string (nm_setting_802_1x_get_client_cert_blob (s_8021X));
|
||||
else
|
||||
cert_str = g_strdup (_(NM_META_TEXT_HIDDEN));
|
||||
|
|
@ -1695,7 +1711,7 @@ _get_fcn_802_1x_phase2_client_cert (ARGS_GET_FCN)
|
|||
|
||||
switch (nm_setting_802_1x_get_phase2_client_cert_scheme (s_8021X)) {
|
||||
case NM_SETTING_802_1X_CK_SCHEME_BLOB:
|
||||
if (show_secrets)
|
||||
if (NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS))
|
||||
cert_str = bytes_to_string (nm_setting_802_1x_get_phase2_client_cert_blob (s_8021X));
|
||||
else
|
||||
cert_str = g_strdup (_(NM_META_TEXT_HIDDEN));
|
||||
|
|
@ -1728,7 +1744,7 @@ _get_fcn_802_1x_private_key (ARGS_GET_FCN)
|
|||
|
||||
switch (nm_setting_802_1x_get_private_key_scheme (s_8021X)) {
|
||||
case NM_SETTING_802_1X_CK_SCHEME_BLOB:
|
||||
if (show_secrets)
|
||||
if (NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS))
|
||||
key_str = bytes_to_string (nm_setting_802_1x_get_private_key_blob (s_8021X));
|
||||
else
|
||||
key_str = g_strdup (_(NM_META_TEXT_HIDDEN));
|
||||
|
|
@ -1754,7 +1770,7 @@ _get_fcn_802_1x_phase2_private_key (ARGS_GET_FCN)
|
|||
|
||||
switch (nm_setting_802_1x_get_phase2_private_key_scheme (s_8021X)) {
|
||||
case NM_SETTING_802_1X_CK_SCHEME_BLOB:
|
||||
if (show_secrets)
|
||||
if (NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS))
|
||||
key_str = bytes_to_string (nm_setting_802_1x_get_phase2_private_key_blob (s_8021X));
|
||||
else
|
||||
key_str = g_strdup (_(NM_META_TEXT_HIDDEN));
|
||||
|
|
@ -6638,6 +6654,37 @@ _meta_type_property_info_get_name (const NMMetaAbstractInfo *abstract_info)
|
|||
return ((const NMMetaPropertyInfo *) abstract_info)->property_name;
|
||||
}
|
||||
|
||||
static const char *
|
||||
_meta_type_setting_info_editor_get_fcn (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NMMetaAbstractInfo *abstract_info,
|
||||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
char **out_to_free)
|
||||
{
|
||||
nm_assert (out_to_free && !out_to_free);
|
||||
g_return_val_if_reached (NULL);
|
||||
}
|
||||
|
||||
static const char *
|
||||
_meta_type_property_info_get_fcn (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NMMetaAbstractInfo *abstract_info,
|
||||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
char **out_to_free)
|
||||
{
|
||||
const NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info;
|
||||
|
||||
nm_assert (out_to_free && !out_to_free);
|
||||
|
||||
return (*out_to_free = info->property_type->get_fcn (environment, environment_user_data,
|
||||
info, target,
|
||||
get_type, get_flags));
|
||||
}
|
||||
|
||||
static const NMMetaAbstractInfo *const*
|
||||
_meta_type_setting_info_editor_get_nested (const NMMetaAbstractInfo *abstract_info,
|
||||
guint *out_len,
|
||||
|
|
@ -6652,13 +6699,26 @@ _meta_type_setting_info_editor_get_nested (const NMMetaAbstractInfo *abstract_in
|
|||
return (const NMMetaAbstractInfo *const*) nm_property_infos_for_setting_type (info->general->meta_type);
|
||||
}
|
||||
|
||||
static const NMMetaAbstractInfo *const*
|
||||
_meta_type_property_info_get_nested (const NMMetaAbstractInfo *abstract_info,
|
||||
guint *out_len,
|
||||
gpointer *out_to_free)
|
||||
{
|
||||
NM_SET_OUT (out_len, 0);
|
||||
*out_to_free = NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const NMMetaType nm_meta_type_setting_info_editor = {
|
||||
.type_name = "setting_info_editor",
|
||||
.get_name = _meta_type_setting_info_editor_get_name,
|
||||
.get_nested = _meta_type_setting_info_editor_get_nested,
|
||||
.get_fcn = _meta_type_setting_info_editor_get_fcn,
|
||||
};
|
||||
|
||||
const NMMetaType nm_meta_type_property_info = {
|
||||
.type_name = "property_info",
|
||||
.get_name = _meta_type_property_info_get_name,
|
||||
.get_nested = _meta_type_property_info_get_nested,
|
||||
.get_fcn = _meta_type_property_info_get_fcn,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -29,6 +29,11 @@ typedef enum {
|
|||
NM_META_ACCESSOR_GET_TYPE_PARSABLE,
|
||||
} NMMetaAccessorGetType;
|
||||
|
||||
typedef enum {
|
||||
NM_META_ACCESSOR_GET_FLAGS_NONE = 0,
|
||||
NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS = (1LL << 0),
|
||||
} NMMetaAccessorGetFlags;
|
||||
|
||||
typedef enum {
|
||||
NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC = (1LL << 0),
|
||||
NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC_HEX = (1LL << 1),
|
||||
|
|
@ -58,10 +63,12 @@ struct _NMMetaPropertyType {
|
|||
const char *(*describe_fcn) (const NMMetaPropertyInfo *property_info,
|
||||
char **out_to_free);
|
||||
|
||||
char *(*get_fcn) (const NMMetaPropertyInfo *property_info,
|
||||
char *(*get_fcn) (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NMMetaPropertyInfo *property_info,
|
||||
NMSetting *setting,
|
||||
NMMetaAccessorGetType get_type,
|
||||
gboolean show_secrets);
|
||||
NMMetaAccessorGetFlags get_flags);
|
||||
gboolean (*set_fcn) (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NMMetaPropertyInfo *property_info,
|
||||
|
|
@ -142,6 +149,13 @@ struct _NMMetaType {
|
|||
const NMMetaAbstractInfo *const*(*get_nested) (const NMMetaAbstractInfo *abstract_info,
|
||||
guint *out_len,
|
||||
gpointer *out_to_free);
|
||||
const char *(*get_fcn) (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NMMetaAbstractInfo *info,
|
||||
gpointer target,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
char **out_to_free);
|
||||
};
|
||||
|
||||
struct _NMMetaAbstractInfo {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue