mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-03-22 20:50:42 +01:00
cli: add values_func() to NmcPropertyInfo and use for "connection" setting
This commit is contained in:
parent
10119aa3a3
commit
cb66cf96d7
7 changed files with 38 additions and 49 deletions
|
|
@ -1500,7 +1500,7 @@ nmc_readline_echo (gboolean echo_on, const char *prompt_fmt, ...)
|
|||
* See e.g. http://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC49
|
||||
*/
|
||||
char *
|
||||
nmc_rl_gen_func_basic (const char *text, int state, const char **words)
|
||||
nmc_rl_gen_func_basic (const char *text, int state, const char *const*words)
|
||||
{
|
||||
static int list_idx, len;
|
||||
const char *name;
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ char *nmc_unique_connection_name (const GPtrArray *connections,
|
|||
void nmc_cleanup_readline (void);
|
||||
char *nmc_readline (const char *prompt_fmt, ...) G_GNUC_PRINTF (1, 2);
|
||||
char *nmc_readline_echo (gboolean echo_on, const char *prompt_fmt, ...) G_GNUC_PRINTF (2, 3);
|
||||
char *nmc_rl_gen_func_basic (const char *text, int state, const char **words);
|
||||
char *nmc_rl_gen_func_basic (const char *text, int state, const char *const*words);
|
||||
char *nmc_rl_gen_func_ifnames (const char *text, int state);
|
||||
gboolean nmc_get_in_readline (void);
|
||||
void nmc_set_in_readline (gboolean in_readline);
|
||||
|
|
|
|||
|
|
@ -5705,12 +5705,12 @@ should_complete_vpn_uuids (const char *prompt, const char *line)
|
|||
return _get_and_check_property (prompt, line, uuid_properties, NULL, NULL);
|
||||
}
|
||||
|
||||
static const char **
|
||||
static const char *const*
|
||||
get_allowed_property_values (void)
|
||||
{
|
||||
NMSetting *setting;
|
||||
char *property;
|
||||
const char **avals = NULL;
|
||||
const char *const*avals = NULL;
|
||||
|
||||
get_setting_and_property (rl_prompt, rl_line_buffer, &setting, &property);
|
||||
if (setting && property)
|
||||
|
|
@ -5781,7 +5781,7 @@ static char *
|
|||
gen_property_values (const char *text, int state)
|
||||
{
|
||||
char *ret = NULL;
|
||||
const char **avals;
|
||||
const char *const*avals;
|
||||
|
||||
avals = get_allowed_property_values ();
|
||||
if (avals)
|
||||
|
|
@ -6662,7 +6662,8 @@ property_edit_submenu (NmCli *nmc,
|
|||
* single values: : both SET and ADD sets the new value
|
||||
*/
|
||||
if (!cmd_property_arg) {
|
||||
const char **avals = nmc_setting_get_property_allowed_values (curr_setting, prop_name);
|
||||
const char *const*avals = nmc_setting_get_property_allowed_values (curr_setting, prop_name);
|
||||
|
||||
if (avals) {
|
||||
char *avals_str = nmc_util_strv_for_display (avals, FALSE);
|
||||
g_print (_("Allowed values for '%s' property: %s\n"),
|
||||
|
|
@ -7074,7 +7075,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
if (menu_ctx.level == 1) {
|
||||
const char *prop_name;
|
||||
char *prop_val_user = NULL;
|
||||
const char **avals;
|
||||
const char *const*avals;
|
||||
GError *tmp_err = NULL;
|
||||
|
||||
prop_name = ask_check_property (cmd_arg,
|
||||
|
|
@ -7141,7 +7142,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
|
||||
/* Ask for value */
|
||||
if (!cmd_arg_v) {
|
||||
const char **avals = nmc_setting_get_property_allowed_values (ss, prop_name);
|
||||
const char *const*avals = nmc_setting_get_property_allowed_values (ss, prop_name);
|
||||
if (avals) {
|
||||
char *avals_str = nmc_util_strv_for_display (avals, FALSE);
|
||||
g_print (_("Allowed values for '%s' property: %s\n"),
|
||||
|
|
|
|||
|
|
@ -1456,14 +1456,14 @@ vpn_data_item (const char *key, const char *value, gpointer user_data)
|
|||
}
|
||||
|
||||
#define DEFINE_ALLOWED_VAL_FUNC(def_func, valid_values) \
|
||||
static const char ** \
|
||||
static const char *const* \
|
||||
def_func (NMSetting *setting, const char *prop) \
|
||||
{ \
|
||||
return valid_values; \
|
||||
}
|
||||
|
||||
#define DEFINE_ALLOWED_FOR_ENUMS(def_func, get_type_func, min, max) \
|
||||
static const char ** \
|
||||
static const char *const* \
|
||||
def_func (NMSetting *setting, const char *prop) \
|
||||
{ \
|
||||
static const char **words = NULL; \
|
||||
|
|
@ -2654,7 +2654,7 @@ nmc_property_bond_describe_options (NMSetting *setting, const char *prop)
|
|||
return desc;
|
||||
}
|
||||
|
||||
static const char **
|
||||
static const char *const*
|
||||
nmc_property_bond_allowed_options (NMSetting *setting, const char *prop)
|
||||
{
|
||||
return nm_setting_bond_get_valid_options (NM_SETTING_BOND (setting));
|
||||
|
|
@ -2895,8 +2895,6 @@ nmc_property_con_set_slave_type (NMSetting *setting, const char *prop, const cha
|
|||
return check_and_set_string (setting, prop, val, con_valid_slave_types, error);
|
||||
}
|
||||
|
||||
DEFINE_ALLOWED_VAL_FUNC (nmc_property_con_allowed_slave_type, con_valid_slave_types)
|
||||
|
||||
static gboolean
|
||||
_set_fcn_connection_secondaries (const NmcSettingInfo *setting_info,
|
||||
const NmcPropertyInfo *property_info,
|
||||
|
|
@ -3039,9 +3037,6 @@ _set_fcn_connection_metered (const NmcSettingInfo *setting_info,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static const char *metered_valid_values[] = { "yes", "no", "unknown", NULL };
|
||||
DEFINE_ALLOWED_VAL_FUNC (nmc_property_connection_allowed_metered, metered_valid_values)
|
||||
|
||||
static char *
|
||||
nmc_property_connection_get_lldp (NMSetting *setting, NmcPropertyGetType get_type)
|
||||
{
|
||||
|
|
@ -3094,10 +3089,6 @@ _set_fcn_connection_lldp (const NmcSettingInfo *setting_info,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static const char *lldp_valid_values[] = { "default", "disable", "enable-rx", NULL };
|
||||
DEFINE_ALLOWED_VAL_FUNC (nmc_property_connection_allowed_lldp, lldp_valid_values)
|
||||
|
||||
|
||||
/* --- NM_SETTING_DCB_SETTING_NAME property functions --- */
|
||||
static char *
|
||||
dcb_flags_to_string (NMSettingDcbFlags flags)
|
||||
|
|
@ -5384,7 +5375,7 @@ DEFINE_REMOVER_OPTION (nmc_property_wired_remove_option_s390_options,
|
|||
NM_SETTING_WIRED,
|
||||
nm_setting_wired_remove_s390_option)
|
||||
|
||||
static const char **
|
||||
static const char *const*
|
||||
nmc_property_wired_allowed_s390_options (NMSetting *setting, const char *prop)
|
||||
{
|
||||
return nm_setting_wired_get_valid_s390_options (NM_SETTING_WIRED (setting));
|
||||
|
|
@ -5974,7 +5965,7 @@ typedef char * (*NmcPropertyGetFunc) (NMSetting *, NmcPropertyGetTyp
|
|||
typedef gboolean (*NmcPropertySetFunc) (NMSetting *, const char *, const char *, GError **);
|
||||
typedef gboolean (*NmcPropertyRemoveFunc) (NMSetting *, const char *, const char *, guint32, GError **);
|
||||
typedef const char * (*NmcPropertyDescribeFunc) (NMSetting *, const char *);
|
||||
typedef const char ** (*NmcPropertyValuesFunc) (NMSetting *, const char *);
|
||||
typedef const char *const* (*NmcPropertyValuesFunc) (NMSetting *, const char *);
|
||||
|
||||
typedef struct {
|
||||
/* The order of the fields is important as they correspond
|
||||
|
|
@ -6889,28 +6880,6 @@ nmc_properties_init (void)
|
|||
NULL,
|
||||
NULL);
|
||||
|
||||
nmc_add_prop_funcs (GLUE (CONNECTION, SLAVE_TYPE),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
nmc_property_con_allowed_slave_type,
|
||||
NULL);
|
||||
nmc_add_prop_funcs (GLUE (CONNECTION, METERED),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
nmc_property_connection_allowed_metered,
|
||||
NULL);
|
||||
nmc_add_prop_funcs (GLUE (CONNECTION, LLDP),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
nmc_property_connection_allowed_lldp,
|
||||
NULL);
|
||||
|
||||
/* Add editable properties for NM_SETTING_DCB_SETTING_NAME */
|
||||
nmc_add_prop_funcs (GLUE (DCB, APP_FCOE_FLAGS),
|
||||
nmc_property_dcb_get_app_fcoe_flags,
|
||||
|
|
@ -8715,11 +8684,13 @@ nmc_setting_get_valid_properties (NMSetting *setting)
|
|||
/*
|
||||
* Return allowed values for 'prop' as a string.
|
||||
*/
|
||||
const char **
|
||||
const char *const*
|
||||
nmc_setting_get_property_allowed_values (NMSetting *setting, const char *prop)
|
||||
{
|
||||
|
||||
const NmcPropertyFuncs *item;
|
||||
const NmcSettingInfo *setting_info;
|
||||
const NmcPropertyInfo *property_info;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING (setting), FALSE);
|
||||
|
||||
|
|
@ -8727,7 +8698,17 @@ nmc_setting_get_property_allowed_values (NMSetting *setting, const char *prop)
|
|||
if (item && item->values_func)
|
||||
return item->values_func (setting, prop);
|
||||
|
||||
return NULL;
|
||||
if ((property_info = _meta_find_property_info_by_setting (setting, prop, &setting_info))) {
|
||||
nm_assert (property_info == _meta_find_property_info_by_name (nm_setting_get_name (setting), prop, NULL));
|
||||
|
||||
if (property_info->is_name) {
|
||||
/* NmcPropertyFuncs would not register the "name" property.
|
||||
* For the moment, skip it from get_property_val(). */
|
||||
} else if (property_info->values_static)
|
||||
return property_info->values_static;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#include "settings-docs.c"
|
||||
|
|
@ -9893,6 +9874,8 @@ setting_proxy_details (const NmcSettingInfo *setting_info, NMSetting *setting, N
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define VALUES_STATIC(...) (((const char *[]) { __VA_ARGS__, NULL }))
|
||||
|
||||
static const NmcPropertyInfo properties_setting_connection[] = {
|
||||
{
|
||||
.property_name = N_ ("name"),
|
||||
|
|
@ -9977,6 +9960,7 @@ static const NmcPropertyInfo properties_setting_connection[] = {
|
|||
.get_fcn = _get_fcn_gobject,
|
||||
.set_fcn = _set_fcn_nmc,
|
||||
.set_data = { .set_nmc = nmc_property_con_set_slave_type, },
|
||||
.values_static = con_valid_slave_types,
|
||||
},
|
||||
{
|
||||
.property_name = N_ (NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES),
|
||||
|
|
@ -10014,12 +9998,14 @@ static const NmcPropertyInfo properties_setting_connection[] = {
|
|||
"'true','yes','on' to set the connection as metered\n"
|
||||
"'false','no','off' to set the connection as not metered\n"
|
||||
"'unknown' to let NetworkManager choose a value using some heuristics\n"),
|
||||
.values_static = VALUES_STATIC ("yes", "no", "unknown"),
|
||||
},
|
||||
{
|
||||
.property_name = N_ (NM_SETTING_CONNECTION_LLDP),
|
||||
.get_fcn = _get_fcn_nmc,
|
||||
.get_data = { .get_nmc = nmc_property_connection_get_lldp, },
|
||||
.set_fcn = _set_fcn_connection_lldp,
|
||||
.values_static = VALUES_STATIC ("default", "disable", "enable-rx"),
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -73,6 +73,8 @@ struct _NmcPropertyInfo {
|
|||
} remove_data;
|
||||
|
||||
const char *describe_message;
|
||||
|
||||
const char *const*values_static;
|
||||
};
|
||||
|
||||
struct _NmcSettingInfo {
|
||||
|
|
@ -104,7 +106,7 @@ void nmc_setting_connection_connect_handlers (NMSettingConnection *setting, NMCo
|
|||
|
||||
char **nmc_setting_get_valid_properties (NMSetting *setting);
|
||||
char *nmc_setting_get_property_desc (NMSetting *setting, const char *prop);
|
||||
const char **nmc_setting_get_property_allowed_values (NMSetting *setting, const char *prop);
|
||||
const char *const*nmc_setting_get_property_allowed_values (NMSetting *setting, const char *prop);
|
||||
char *nmc_setting_get_property (NMSetting *setting,
|
||||
const char *prop,
|
||||
GError **error);
|
||||
|
|
|
|||
|
|
@ -677,7 +677,7 @@ finish:
|
|||
* Returns: a newly allocated string. Caller must free it with g_free().
|
||||
*/
|
||||
char *
|
||||
nmc_util_strv_for_display (const char **strv, gboolean brackets)
|
||||
nmc_util_strv_for_display (const char *const*strv, gboolean brackets)
|
||||
{
|
||||
GString *result;
|
||||
guint i = 0;
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ char *nmc_get_user_input (const char *ask_str);
|
|||
int nmc_string_to_arg_array (const char *line, const char *delim, gboolean unquote,
|
||||
char ***argv, int *argc);
|
||||
const char *nmc_string_is_valid (const char *input, const char **allowed, GError **error);
|
||||
char * nmc_util_strv_for_display (const char **strv, gboolean brackets);
|
||||
char * nmc_util_strv_for_display (const char *const*strv, gboolean brackets);
|
||||
char **nmc_strsplit_set (const char *str, const char *delimiter, int max_tokens);
|
||||
int nmc_string_screen_width (const char *start, const char *end);
|
||||
void set_val_str (NmcOutputField fields_array[], guint32 index, char *value);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue