cli: merge branch 'bg/cli-ask-fixes-rh1464001'

Fix some regressions in nmcli.

https://bugzilla.redhat.com/show_bug.cgi?id=1464001
This commit is contained in:
Beniamino Galvani 2017-06-22 15:01:30 +02:00
commit bfb4c248b6
4 changed files with 128 additions and 62 deletions

View file

@ -4595,44 +4595,78 @@ again:
goto again;
}
static NMMetaSettingType
connection_get_base_meta_setting_type (NMConnection *connection)
{
const char *connection_type;
NMSetting *base_setting;
const NMMetaSettingInfoEditor *editor;
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);
return editor - nm_meta_setting_infos_editor;
}
static void
questionnaire_mandatory_ask_setting (NmCli *nmc, NMConnection *connection, NMMetaSettingType type)
{
const NMMetaSettingInfoEditor *editor;
const NMMetaPropertyInfo *property_info;
guint p;
editor = &nm_meta_setting_infos_editor[type];
if (!editor->properties)
return;
for (p = 0; editor->properties[p]; p++) {
property_info = editor->properties[p];
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 ( (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;
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++) {
const NMMetaPropertyInfo *const*property_infos;
guint p;
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];
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 ( (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);
}
}
if (!NM_IN_SET (s, NM_META_SETTING_TYPE_CONNECTION, base))
questionnaire_mandatory_ask_setting (nmc, connection, s);
}
}
@ -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;
}
}

View file

@ -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;

View file

@ -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",

View file

@ -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])