diff options
author | Thomas Haller <thaller@redhat.com> | 2017-04-04 13:14:23 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-04-05 16:53:06 +0200 |
commit | 19c70ace955df1c849911bad8838cf02c11bf6b8 (patch) | |
tree | 4c653d3e34c95310e1a5207932030bc46d8db33d | |
parent | 022117ff36f86ce07a933e7689256e3173cfd813 (diff) | |
download | NetworkManager-19c70ace955df1c849911bad8838cf02c11bf6b8.tar.gz |
cli: add get_fcn() to NMMetaAbstractInfo
-rw-r--r-- | clients/cli/nmcli.c | 22 | ||||
-rw-r--r-- | clients/cli/nmcli.h | 7 | ||||
-rw-r--r-- | clients/cli/settings.c | 12 | ||||
-rw-r--r-- | clients/common/nm-meta-setting-desc.c | 76 | ||||
-rw-r--r-- | clients/common/nm-meta-setting-desc.h | 18 |
5 files changed, 121 insertions, 14 deletions
diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c index b34add33ae..cde9423cac 100644 --- a/clients/cli/nmcli.c +++ b/clients/cli/nmcli.c @@ -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, }; /*****************************************************************************/ diff --git a/clients/cli/nmcli.h b/clients/cli/nmcli.h index 6d8edf9269..6bbfa18201 100644 --- a/clients/cli/nmcli.h +++ b/clients/cli/nmcli.h @@ -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, ...) \ diff --git a/clients/cli/settings.c b/clients/cli/settings.c index 158f82ecb6..429d93035c 100644 --- a/clients/cli/settings.c +++ b/clients/cli/settings.c @@ -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))); } diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index afc498a162..1c6aeb005c 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -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); @@ -592,13 +602,19 @@ _get_fcn_gobject (ARGS_GET_FCN) } 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) { guint32 mtu; 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, }; diff --git a/clients/common/nm-meta-setting-desc.h b/clients/common/nm-meta-setting-desc.h index 4363b8b0b5..eb886e2593 100644 --- a/clients/common/nm-meta-setting-desc.h +++ b/clients/common/nm-meta-setting-desc.h @@ -30,6 +30,11 @@ typedef enum { } 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), NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT = (1LL << 2), @@ -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 { |