diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2017-06-22 15:01:30 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2017-06-22 15:01:30 +0200 |
commit | bfb4c248b65de09058ee19d5b0a521827c095daa (patch) | |
tree | 83a82a8f6d11fd03b4cb0695d727899ddd039629 | |
parent | a84facb90c8ed7214e2aeba1ce54909c00a82b2c (diff) | |
parent | f545ed486e4df7f1508f62a0e0a35c8f92550937 (diff) | |
download | NetworkManager-bfb4c248b65de09058ee19d5b0a521827c095daa.tar.gz |
cli: merge branch 'bg/cli-ask-fixes-rh1464001'
Fix some regressions in nmcli.
https://bugzilla.redhat.com/show_bug.cgi?id=1464001
-rw-r--r-- | clients/cli/connections.c | 117 | ||||
-rw-r--r-- | clients/common/nm-meta-setting-access.c | 13 | ||||
-rw-r--r-- | clients/common/nm-meta-setting-desc.c | 48 | ||||
-rw-r--r-- | clients/common/nm-meta-setting-desc.h | 2 |
4 files changed, 123 insertions, 57 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c index f2f4adecf7..84f80741c9 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -4595,47 +4595,81 @@ again: goto again; } -static void -questionnaire_mandatory (NmCli *nmc, NMConnection *connection) +static NMMetaSettingType +connection_get_base_meta_setting_type (NMConnection *connection) { - NMMetaSettingType s; + const char *connection_type; + NMSetting *base_setting; + const NMMetaSettingInfoEditor *editor; - for (s = 0; s < _NM_META_SETTING_TYPE_NUM; s++) { - const NMMetaPropertyInfo *const*property_infos; - guint p; + connection_type = nm_connection_get_connection_type (connection); + nm_assert (connection_type); + base_setting = nm_connection_get_setting_by_name (connection, connection_type); + nm_assert (base_setting); + editor = nm_meta_setting_info_editor_find_by_setting (base_setting); + nm_assert (editor); - property_infos = nm_meta_setting_infos_editor[s].properties; - if (!property_infos) - continue; - for (p = 0; property_infos[p]; p++) { - const NMMetaPropertyInfo *property_info = property_infos[p]; + return editor - nm_meta_setting_infos_editor; +} - if (_meta_property_needs_bond_hack (property_info)) { - guint i; +static void +questionnaire_mandatory_ask_setting (NmCli *nmc, NMConnection *connection, NMMetaSettingType type) +{ + const NMMetaSettingInfoEditor *editor; + const NMMetaPropertyInfo *property_info; + guint p; - for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { - const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; + editor = &nm_meta_setting_infos_editor[type]; + if (!editor->properties) + return; - if (!option_relevant (connection, (const NMMetaAbstractInfo *) bi)) - continue; - if ( (bi->base.inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) - || (_dynamic_options_get ((const NMMetaAbstractInfo *) bi) & PROPERTY_INF_FLAG_ENABLED)) - ask_option (nmc, connection, (const NMMetaAbstractInfo *) bi); - } - } else { - if (!property_info->is_cli_option) - continue; + for (p = 0; editor->properties[p]; p++) { + property_info = editor->properties[p]; - if (!option_relevant (connection, (const NMMetaAbstractInfo *) property_info)) + if (_meta_property_needs_bond_hack (property_info)) { + guint i; + + for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { + const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; + + if (!option_relevant (connection, (const NMMetaAbstractInfo *) bi)) continue; - if ( (property_info->inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) - || (_dynamic_options_get ((const NMMetaAbstractInfo *) property_info) & PROPERTY_INF_FLAG_ENABLED)) - ask_option (nmc, connection, (const NMMetaAbstractInfo *) property_info); + if ( (bi->base.inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) + || (_dynamic_options_get ((const NMMetaAbstractInfo *) bi) & PROPERTY_INF_FLAG_ENABLED)) + ask_option (nmc, connection, (const NMMetaAbstractInfo *) bi); } + } else { + if (!property_info->is_cli_option) + continue; + + if (!option_relevant (connection, (const NMMetaAbstractInfo *) property_info)) + continue; + if ( (property_info->inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) + || (_dynamic_options_get ((const NMMetaAbstractInfo *) property_info) & PROPERTY_INF_FLAG_ENABLED)) + ask_option (nmc, connection, (const NMMetaAbstractInfo *) property_info); } } } +static void +questionnaire_mandatory (NmCli *nmc, NMConnection *connection) +{ + NMMetaSettingType s, base; + + /* First ask connection properties */ + questionnaire_mandatory_ask_setting (nmc, connection, NM_META_SETTING_TYPE_CONNECTION); + + /* Ask properties of the base setting */ + base = connection_get_base_meta_setting_type (connection); + questionnaire_mandatory_ask_setting (nmc, connection, base); + + /* Remaining settings */ + for (s = 0; s < _NM_META_SETTING_TYPE_NUM; s++) { + if (!NM_IN_SET (s, NM_META_SETTING_TYPE_CONNECTION, base)) + questionnaire_mandatory_ask_setting (nmc, connection, s); + } +} + static gboolean want_provide_opt_args (const char *type, int num) { @@ -4659,33 +4693,44 @@ want_provide_opt_args (const char *type, int num) static gboolean questionnaire_one_optional (NmCli *nmc, NMConnection *connection) { - NMMetaSettingType s; + NMMetaSettingType base; gs_unref_ptrarray GPtrArray *infos = NULL; - guint i; + guint i, j; gboolean already_confirmed = FALSE; NMMetaSettingType s_asking = NM_META_SETTING_TYPE_UNKNOWN; + NMMetaSettingType settings[_NM_META_SETTING_TYPE_NUM]; + + base = connection_get_base_meta_setting_type (connection); + + i = 0; + settings[i++] = NM_META_SETTING_TYPE_CONNECTION; + settings[i++] = base; + for (j = 0; j < _NM_META_SETTING_TYPE_NUM; j++) { + if (!NM_IN_SET (j, NM_META_SETTING_TYPE_CONNECTION, base)) + settings[i++] = j; + } infos = g_ptr_array_new (); /* Find first setting with relevant options and count them. */ again: - for (s = 0; s < _NM_META_SETTING_TYPE_NUM; s++) { + for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { const NMMetaPropertyInfo *const*property_infos; guint p; if ( s_asking != NM_META_SETTING_TYPE_UNKNOWN - && s != s_asking) + && settings[i] != s_asking) continue; - property_infos = nm_meta_setting_infos_editor[s].properties; + property_infos = nm_meta_setting_infos_editor[settings[i]].properties; if (!property_infos) continue; for (p = 0; property_infos[p]; p++) { const NMMetaPropertyInfo *property_info = property_infos[p]; if (_meta_property_needs_bond_hack (property_info)) { - for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { - const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; + for (j = 0; j < nm_meta_property_typ_data_bond.nested_len; j++) { + const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[j]; if (!option_relevant (connection, (const NMMetaAbstractInfo *) bi)) continue; @@ -4700,7 +4745,7 @@ again: } } if (infos->len) { - s_asking = s; + s_asking = settings[i]; break; } } diff --git a/clients/common/nm-meta-setting-access.c b/clients/common/nm-meta-setting-access.c index 7a0cefde9d..f6038e1f1b 100644 --- a/clients/common/nm-meta-setting-access.c +++ b/clients/common/nm-meta-setting-access.c @@ -294,13 +294,18 @@ nm_meta_abstract_info_complete (const NMMetaAbstractInfo *abstract_info, if (*out_to_free) { char **v = *out_to_free; - for (i =0, j = 0; v[i]; i++) { + for (i = 0, j = 0; v[i]; i++) { if (strncmp (v[i], text, text_len) != 0) continue; v[j++] = v[i]; } - v[j++] = NULL; - return (const char *const*) *out_to_free; + if (j) + v[j++] = NULL; + else { + g_free (v); + v = NULL; + } + return (const char *const*) v; } else { const char *const*v = values; char **r; @@ -312,6 +317,8 @@ nm_meta_abstract_info_complete (const NMMetaAbstractInfo *abstract_info, } if (j == i) return values; + else if (!j) + return NULL; r = g_new (char *, j + 1); v = values; diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index 39d958c9f5..7c620a1c61 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -1759,7 +1759,12 @@ _complete_fcn_vpn_service_type (ARGS_COMPLETE_FCN) values[j] = values[i]; j++; } - values[j++] = NULL; + if (j) + values[j++] = NULL; + else { + g_free (values); + values = NULL; + } } return (const char *const*) (*out_to_free = values); } @@ -2378,7 +2383,12 @@ _complete_fcn_connection_type (ARGS_COMPLETE_FCN) result[j++] = g_strdup (v); } } - result[j++] = NULL; + if (j) + result[j++] = NULL; + else { + g_free (result); + result = NULL; + } return (const char *const*) (*out_to_free = result); } @@ -2526,10 +2536,14 @@ _complete_fcn_connection_master (ARGS_COMPLETE_FCN) if (v && (!text || strncmp (text, v, text_len) == 0)) result[j++] = g_strdup (v); } - result[j++] = NULL; + if (j) + result[j++] = NULL; + else { + g_free (result); + result = NULL; + } - *out_to_free = NULL; - return (const char *const*) result; + return (const char *const*) (*out_to_free = result); } static gboolean @@ -4980,6 +4994,18 @@ static const NMMetaPropertyInfo *const property_infos_CONNECTION[] = { PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_STABLE_ID, .property_type = &_pt_gobject_string, ), +[_NM_META_PROPERTY_TYPE_CONNECTION_TYPE] = + PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_TYPE, + .is_cli_option = TRUE, + .property_alias = "type", + .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, + .prompt = NM_META_TEXT_PROMPT_CON_TYPE, + .property_type = DEFINE_PROPERTY_TYPE ( + .get_fcn = _get_fcn_gobject, + .set_fcn = _set_fcn_connection_type, + .complete_fcn = _complete_fcn_connection_type, + ), + ), PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_INTERFACE_NAME, .is_cli_option = TRUE, .property_alias = "ifname", @@ -4991,18 +5017,6 @@ static const NMMetaPropertyInfo *const property_infos_CONNECTION[] = { .complete_fcn = _complete_fcn_gobject_devices, ), ), -[_NM_META_PROPERTY_TYPE_CONNECTION_TYPE] = - PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_TYPE, - .is_cli_option = TRUE, - .property_alias = "type", - .inf_flags = NM_META_PROPERTY_INF_FLAG_REQD, - .prompt = NM_META_TEXT_PROMPT_CON_TYPE, - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_gobject, - .set_fcn = _set_fcn_connection_type, - .complete_fcn = _complete_fcn_connection_type, - ), - ), PROPERTY_INFO_WITH_DESC (NM_SETTING_CONNECTION_AUTOCONNECT, .is_cli_option = TRUE, .property_alias = "autoconnect", diff --git a/clients/common/nm-meta-setting-desc.h b/clients/common/nm-meta-setting-desc.h index 5d6cfbbc8d..c1fd902210 100644 --- a/clients/common/nm-meta-setting-desc.h +++ b/clients/common/nm-meta-setting-desc.h @@ -277,7 +277,7 @@ typedef enum { enum { _NM_META_PROPERTY_TYPE_VPN_SERVICE_TYPE = 0, - _NM_META_PROPERTY_TYPE_CONNECTION_TYPE = 4, + _NM_META_PROPERTY_TYPE_CONNECTION_TYPE = 3, }; #define nm_meta_property_info_connection_type (nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_CONNECTION].properties[_NM_META_PROPERTY_TYPE_CONNECTION_TYPE]) |