Commit ecec03c8 authored by Thomas Haller's avatar Thomas Haller

cli: merge branch 'th/cli-meta-3'

parents 8b52e506 275ab5fb
...@@ -1314,8 +1314,8 @@ split_required_fields_for_con_show (const char *input, ...@@ -1314,8 +1314,8 @@ split_required_fields_for_con_show (const char *input,
else if (!strcasecmp (*iter, CON_SHOW_DETAIL_GROUP_ACTIVE)) else if (!strcasecmp (*iter, CON_SHOW_DETAIL_GROUP_ACTIVE))
group_active = TRUE; group_active = TRUE;
else { else {
char *allowed1 = nmc_get_allowed_fields ((const NMMetaAbstractInfo *const*) nm_meta_setting_infos_editor_p (), NULL); char *allowed1 = nm_meta_abstract_infos_get_names_str ((const NMMetaAbstractInfo *const*) nm_meta_setting_infos_editor_p (), NULL);
char *allowed2 = nmc_get_allowed_fields ((const NMMetaAbstractInfo *const*) nmc_fields_con_active_details_groups, NULL); char *allowed2 = nm_meta_abstract_infos_get_names_str ((const NMMetaAbstractInfo *const*) nmc_fields_con_active_details_groups, NULL);
g_set_error (error, NMCLI_ERROR, 0, _("invalid field '%s'; allowed fields: %s and %s, or %s,%s"), g_set_error (error, NMCLI_ERROR, 0, _("invalid field '%s'; allowed fields: %s and %s, or %s,%s"),
*iter, allowed1, allowed2, CON_SHOW_DETAIL_GROUP_PROFILE, CON_SHOW_DETAIL_GROUP_ACTIVE); *iter, allowed1, allowed2, CON_SHOW_DETAIL_GROUP_PROFILE, CON_SHOW_DETAIL_GROUP_ACTIVE);
g_free (allowed1); g_free (allowed1);
...@@ -2907,7 +2907,7 @@ get_valid_properties_string (const NMMetaSettingValidPartItem *const*array, ...@@ -2907,7 +2907,7 @@ get_valid_properties_string (const NMMetaSettingValidPartItem *const*array,
gchar *new; gchar *new;
const char *arg_name; const char *arg_name;
arg_name = setting_info->properties[j].property_name; arg_name = setting_info->properties[j]->property_name;
/* If required, expand the alias too */ /* If required, expand the alias too */
if (!postfix && setting_info->alias) { if (!postfix && setting_info->alias) {
...@@ -3319,7 +3319,7 @@ _meta_property_needs_bond_hack (const NMMetaPropertyInfo *property_info) ...@@ -3319,7 +3319,7 @@ _meta_property_needs_bond_hack (const NMMetaPropertyInfo *property_info)
if (!property_info) if (!property_info)
g_return_val_if_reached (FALSE); g_return_val_if_reached (FALSE);
return property_info->property_typ_data return property_info->property_typ_data
&& property_info->property_typ_data->subtype.nested.data == &nm_meta_property_typ_data_bond; && property_info->property_typ_data->nested == &nm_meta_property_typ_data_bond;
} }
...@@ -3353,28 +3353,16 @@ _meta_abstract_get (const NMMetaAbstractInfo *abstract_info, ...@@ -3353,28 +3353,16 @@ _meta_abstract_get (const NMMetaAbstractInfo *abstract_info,
const char **out_prompt, const char **out_prompt,
const char **out_def_hint) const char **out_def_hint)
{ {
/* _meta_property_needs_bond_hack () */ const NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info;
if (abstract_info->meta_type == &nm_meta_type_nested_property_info) {
const NMMetaNestedPropertyTypeInfo *info = (const NMMetaNestedPropertyTypeInfo *) abstract_info;
NM_SET_OUT (out_setting_info, info->parent_info->setting_info);
NM_SET_OUT (out_setting_name, info->parent_info->setting_info->general->setting_name);
NM_SET_OUT (out_property_name, info->parent_info->property_name);
NM_SET_OUT (out_option, info->field_name);
NM_SET_OUT (out_inf_flags, info->inf_flags);
NM_SET_OUT (out_prompt, info->prompt);
NM_SET_OUT (out_def_hint, info->def_hint);
} else {
const NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info;
NM_SET_OUT (out_setting_info, info->setting_info); NM_SET_OUT (out_option, info->property_alias);
NM_SET_OUT (out_setting_name, info->setting_info->general->setting_name); NM_SET_OUT (out_setting_info, info->setting_info);
NM_SET_OUT (out_property_name, info->property_name); NM_SET_OUT (out_setting_name, info->setting_info->general->setting_name);
NM_SET_OUT (out_option, info->property_alias); NM_SET_OUT (out_property_name, info->property_name);
NM_SET_OUT (out_inf_flags, info->inf_flags); NM_SET_OUT (out_option, info->property_alias);
NM_SET_OUT (out_prompt, info->prompt); NM_SET_OUT (out_inf_flags, info->inf_flags);
NM_SET_OUT (out_def_hint, info->def_hint); NM_SET_OUT (out_prompt, info->prompt);
} NM_SET_OUT (out_def_hint, info->def_hint);
} }
static const OptionInfo *_meta_abstract_get_option_info (const NMMetaAbstractInfo *abstract_info); static const OptionInfo *_meta_abstract_get_option_info (const NMMetaAbstractInfo *abstract_info);
...@@ -3397,11 +3385,11 @@ enable_options (const gchar *setting_name, const gchar *property, const gchar * ...@@ -3397,11 +3385,11 @@ enable_options (const gchar *setting_name, const gchar *property, const gchar *
guint i; guint i;
for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) {
const NMMetaNestedPropertyTypeInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
if ( bi->inf_flags & NM_META_PROPERTY_INF_FLAG_DONT_ASK if ( bi->base.inf_flags & NM_META_PROPERTY_INF_FLAG_DONT_ASK
&& bi->field_name && bi->base.property_alias
&& g_strv_contains (opts, bi->field_name)) && g_strv_contains (opts, bi->base.property_alias))
_dynamic_options_set ((const NMMetaAbstractInfo *) bi, PROPERTY_INF_FLAG_ENABLED, PROPERTY_INF_FLAG_ENABLED); _dynamic_options_set ((const NMMetaAbstractInfo *) bi, PROPERTY_INF_FLAG_ENABLED, PROPERTY_INF_FLAG_ENABLED);
} }
return; return;
...@@ -3446,7 +3434,9 @@ disable_options (const gchar *setting_name, const gchar *property) ...@@ -3446,7 +3434,9 @@ disable_options (const gchar *setting_name, const gchar *property)
setting_info = nm_meta_setting_info_editor_find_by_name (setting_name, FALSE); setting_info = nm_meta_setting_info_editor_find_by_name (setting_name, FALSE);
if (!setting_info) if (!setting_info)
g_return_if_reached (); g_return_if_reached ();
property_infos = nm_property_infos_for_setting_type (setting_info->general->meta_type); property_infos = setting_info->properties;
if (!property_infos)
return;
} }
for (p = 0; property_infos[p]; p++) { for (p = 0; property_infos[p]; p++) {
...@@ -3456,7 +3446,7 @@ disable_options (const gchar *setting_name, const gchar *property) ...@@ -3456,7 +3446,7 @@ disable_options (const gchar *setting_name, const gchar *property)
guint i; guint i;
for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) {
const NMMetaNestedPropertyTypeInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
_dynamic_options_set ((const NMMetaAbstractInfo *) bi, PROPERTY_INF_FLAG_DISABLED, PROPERTY_INF_FLAG_DISABLED); _dynamic_options_set ((const NMMetaAbstractInfo *) bi, PROPERTY_INF_FLAG_DISABLED, PROPERTY_INF_FLAG_DISABLED);
} }
...@@ -3482,7 +3472,9 @@ reset_options (void) ...@@ -3482,7 +3472,9 @@ reset_options (void)
const NMMetaPropertyInfo *const*property_infos; const NMMetaPropertyInfo *const*property_infos;
guint p; guint p;
property_infos = nm_property_infos_for_setting_type (s); property_infos = nm_meta_setting_infos_editor[s].properties;
if (!property_infos)
continue;
for (p = 0; property_infos[p]; p++) { for (p = 0; property_infos[p]; p++) {
const NMMetaPropertyInfo *property_info = property_infos[p]; const NMMetaPropertyInfo *property_info = property_infos[p];
...@@ -3490,7 +3482,7 @@ reset_options (void) ...@@ -3490,7 +3482,7 @@ reset_options (void)
guint i; guint i;
for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) {
const NMMetaNestedPropertyTypeInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
_dynamic_options_set ((const NMMetaAbstractInfo *) bi, PROPERTY_INF_FLAG_ALL, 0); _dynamic_options_set ((const NMMetaAbstractInfo *) bi, PROPERTY_INF_FLAG_ALL, 0);
} }
...@@ -4062,7 +4054,9 @@ complete_property_name (NmCli *nmc, NMConnection *connection, ...@@ -4062,7 +4054,9 @@ complete_property_name (NmCli *nmc, NMConnection *connection,
if (!nm_connection_get_setting_by_name (connection, nm_meta_setting_infos_editor[s].general->setting_name)) if (!nm_connection_get_setting_by_name (connection, nm_meta_setting_infos_editor[s].general->setting_name))
continue; continue;
property_infos = nm_property_infos_for_setting_type (s); property_infos = nm_meta_setting_infos_editor[s].properties;
if (!property_infos)
continue;
for (p = 0; property_infos[p]; p++) { for (p = 0; property_infos[p]; p++) {
const NMMetaPropertyInfo *property_info = property_infos[p]; const NMMetaPropertyInfo *property_info = property_infos[p];
...@@ -4070,12 +4064,12 @@ complete_property_name (NmCli *nmc, NMConnection *connection, ...@@ -4070,12 +4064,12 @@ complete_property_name (NmCli *nmc, NMConnection *connection,
guint i; guint i;
for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) {
const NMMetaNestedPropertyTypeInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
if ( !bi->field_name if ( !bi->base.property_alias
|| !g_str_has_prefix (bi->field_name, prefix)) || !g_str_has_prefix (bi->base.property_alias, prefix))
continue; continue;
g_print ("%s\n", bi->field_name); g_print ("%s\n", bi->base.property_alias);
} }
} else { } else {
if (!property_info->is_cli_option) if (!property_info->is_cli_option)
...@@ -4256,7 +4250,9 @@ nmc_read_connection_properties (NmCli *nmc, ...@@ -4256,7 +4250,9 @@ nmc_read_connection_properties (NmCli *nmc,
type_settings, slv_settings, NULL)) type_settings, slv_settings, NULL))
continue; continue;
property_infos = nm_property_infos_for_setting_type (s); property_infos = nm_meta_setting_infos_editor[s].properties;
if (!property_infos)
continue;
for (p = 0; property_infos[p]; p++) { for (p = 0; property_infos[p]; p++) {
const NMMetaPropertyInfo *property_info = property_infos[p]; const NMMetaPropertyInfo *property_info = property_infos[p];
...@@ -4264,9 +4260,9 @@ nmc_read_connection_properties (NmCli *nmc, ...@@ -4264,9 +4260,9 @@ nmc_read_connection_properties (NmCli *nmc,
guint i; guint i;
for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) {
const NMMetaNestedPropertyTypeInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
if (!nm_streq0 (bi->field_name, option)) if (!nm_streq0 (bi->base.property_alias, option))
continue; continue;
if (chosen) { if (chosen) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
...@@ -4420,7 +4416,9 @@ nmcli_con_add_tab_completion (const char *text, int start, int end) ...@@ -4420,7 +4416,9 @@ nmcli_con_add_tab_completion (const char *text, int start, int end)
const NMMetaPropertyInfo *const*property_infos; const NMMetaPropertyInfo *const*property_infos;
guint p; guint p;
property_infos = nm_property_infos_for_setting_type (s); property_infos = nm_meta_setting_infos_editor[s].properties;
if (!property_infos)
continue;
for (p = 0; property_infos[p]; p++) { for (p = 0; property_infos[p]; p++) {
const NMMetaPropertyInfo *property_info = property_infos[p]; const NMMetaPropertyInfo *property_info = property_infos[p];
...@@ -4428,10 +4426,10 @@ nmcli_con_add_tab_completion (const char *text, int start, int end) ...@@ -4428,10 +4426,10 @@ nmcli_con_add_tab_completion (const char *text, int start, int end)
guint i; guint i;
for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) {
const NMMetaNestedPropertyTypeInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
if ( bi->prompt if ( bi->base.prompt
&& g_str_has_prefix (rl_prompt, bi->prompt)) { && g_str_has_prefix (rl_prompt, bi->base.prompt)) {
goto next; goto next;
} }
} }
...@@ -4513,7 +4511,9 @@ questionnaire_mandatory (NmCli *nmc, NMConnection *connection) ...@@ -4513,7 +4511,9 @@ questionnaire_mandatory (NmCli *nmc, NMConnection *connection)
const NMMetaPropertyInfo *const*property_infos; const NMMetaPropertyInfo *const*property_infos;
guint p; guint p;
property_infos = nm_property_infos_for_setting_type (s); property_infos = nm_meta_setting_infos_editor[s].properties;
if (!property_infos)
continue;
for (p = 0; property_infos[p]; p++) { for (p = 0; property_infos[p]; p++) {
const NMMetaPropertyInfo *property_info = property_infos[p]; const NMMetaPropertyInfo *property_info = property_infos[p];
...@@ -4521,11 +4521,11 @@ questionnaire_mandatory (NmCli *nmc, NMConnection *connection) ...@@ -4521,11 +4521,11 @@ questionnaire_mandatory (NmCli *nmc, NMConnection *connection)
guint i; guint i;
for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) {
const NMMetaNestedPropertyTypeInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
if (!option_relevant (connection, (const NMMetaAbstractInfo *) bi)) if (!option_relevant (connection, (const NMMetaAbstractInfo *) bi))
continue; continue;
if ( (bi->inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) if ( (bi->base.inf_flags & NM_META_PROPERTY_INF_FLAG_REQD)
|| (_dynamic_options_get ((const NMMetaAbstractInfo *) bi) & PROPERTY_INF_FLAG_ENABLED)) || (_dynamic_options_get ((const NMMetaAbstractInfo *) bi) & PROPERTY_INF_FLAG_ENABLED))
ask_option (nmc, connection, (const NMMetaAbstractInfo *) bi); ask_option (nmc, connection, (const NMMetaAbstractInfo *) bi);
} }
...@@ -4584,13 +4584,15 @@ again: ...@@ -4584,13 +4584,15 @@ again:
&& s != s_asking) && s != s_asking)
continue; continue;
property_infos = nm_property_infos_for_setting_type (s); property_infos = nm_meta_setting_infos_editor[s].properties;
if (!property_infos)
continue;
for (p = 0; property_infos[p]; p++) { for (p = 0; property_infos[p]; p++) {
const NMMetaPropertyInfo *property_info = property_infos[p]; const NMMetaPropertyInfo *property_info = property_infos[p];
if (_meta_property_needs_bond_hack (property_info)) { if (_meta_property_needs_bond_hack (property_info)) {
for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) {
const NMMetaNestedPropertyTypeInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
if (!option_relevant (connection, (const NMMetaAbstractInfo *) bi)) if (!option_relevant (connection, (const NMMetaAbstractInfo *) bi))
continue; continue;
...@@ -4755,7 +4757,9 @@ read_properties: ...@@ -4755,7 +4757,9 @@ read_properties:
const NMMetaPropertyInfo *const*property_infos; const NMMetaPropertyInfo *const*property_infos;
guint p; guint p;
property_infos = nm_property_infos_for_setting_type (s); property_infos = nm_meta_setting_infos_editor[s].properties;
if (!property_infos)
continue;
for (p = 0; property_infos[p]; p++) { for (p = 0; property_infos[p]; p++) {
const NMMetaPropertyInfo *property_info = property_infos[p]; const NMMetaPropertyInfo *property_info = property_infos[p];
...@@ -4763,12 +4767,12 @@ read_properties: ...@@ -4763,12 +4767,12 @@ read_properties:
guint i; guint i;
for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) {
const NMMetaNestedPropertyTypeInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
if (!option_relevant (connection, (const NMMetaAbstractInfo *) bi)) if (!option_relevant (connection, (const NMMetaAbstractInfo *) bi))
continue; continue;
if (bi->inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) { if (bi->base.inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) {
g_string_printf (nmc->return_text, _("Error: '%s' argument is required."), bi->field_name); g_string_printf (nmc->return_text, _("Error: '%s' argument is required."), bi->base.property_alias);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto finish; goto finish;
} }
......
...@@ -77,7 +77,7 @@ complete_field_setting (GHashTable *h, NMMetaSettingType setting_type) ...@@ -77,7 +77,7 @@ complete_field_setting (GHashTable *h, NMMetaSettingType setting_type)
for (i = 0; i < setting_info->properties_num; i++) { for (i = 0; i < setting_info->properties_num; i++) {
g_hash_table_add (h, g_strdup_printf ("%s.%s", g_hash_table_add (h, g_strdup_printf ("%s.%s",
setting_info->general->setting_name, setting_info->general->setting_name,
setting_info->properties[i].property_name)); setting_info->properties[i]->property_name));
} }
} }
......
...@@ -56,19 +56,11 @@ _meta_type_nmc_generic_info_get_nested (const NMMetaAbstractInfo *abstract_info, ...@@ -56,19 +56,11 @@ _meta_type_nmc_generic_info_get_nested (const NMMetaAbstractInfo *abstract_info,
gpointer *out_to_free) gpointer *out_to_free)
{ {
const NmcMetaGenericInfo *info; const NmcMetaGenericInfo *info;
guint n;
info = (const NmcMetaGenericInfo *) abstract_info; info = (const NmcMetaGenericInfo *) abstract_info;
if (out_len) {
n = 0;
if (info->nested) {
for (; info->nested[n]; n++) {
}
}
*out_len = n;
}
*out_to_free = NULL; *out_to_free = NULL;
NM_SET_OUT (out_len, NM_PTRARRAY_LEN (info->nested));
return (const NMMetaAbstractInfo *const*) info->nested; return (const NMMetaAbstractInfo *const*) info->nested;
} }
...@@ -764,224 +756,10 @@ nmc_free_output_field_values (NmcOutputField fields_array[]) ...@@ -764,224 +756,10 @@ nmc_free_output_field_values (NmcOutputField fields_array[])
/*****************************************************************************/ /*****************************************************************************/
typedef struct {
guint idx;
gsize self_offset_plus_1;
gsize sub_offset_plus_1;
} OutputSelectionItem;
static NmcOutputSelection *
_output_selection_pack (const NMMetaAbstractInfo *const* fields_array,
GArray *array,
GString *str)
{
NmcOutputSelection *result;
guint i;
guint len;
len = array ? array->len : 0;
/* re-organize the collected output data in one buffer that can be freed using
* g_free(). This makes allocation more complicated, but saves us from special
* handling for free. */
result = g_malloc0 (sizeof (NmcOutputSelection) + (len * sizeof (NmcOutputSelectionItem)) + (str ? str->len : 0));
*((guint *) &result->num) = len;
if (len > 0) {
char *pdata = &((char *) result)[sizeof (NmcOutputSelection) + (len * sizeof (NmcOutputSelectionItem))];
if (str)
memcpy (pdata, str->str, str->len);
for (i = 0; i < len; i++) {
const OutputSelectionItem *a = &g_array_index (array, OutputSelectionItem, i);
NmcOutputSelectionItem *p = (NmcOutputSelectionItem *) &result->items[i];
p->info = fields_array[a->idx];
p->idx = a->idx;
if (a->self_offset_plus_1 > 0)
p->self_selection = &pdata[a->self_offset_plus_1 - 1];
if (a->sub_offset_plus_1 > 0)
p->sub_selection = &pdata[a->sub_offset_plus_1 - 1];
}
}
return result;
}
static gboolean
_output_selection_select_one (const NMMetaAbstractInfo *const* fields_array,
const char *fields_prefix,
const char *fields_str,
gboolean validate_nested,
GArray **p_array,
GString **p_str,
GError **error)
{
guint i, j;
const char *i_name;
const char *right;
gboolean found = FALSE;
const NMMetaAbstractInfo *fields_array_failure = NULL;
gs_free char *fields_str_clone = NULL;
nm_assert (fields_str);
nm_assert (p_array);
nm_assert (p_str);
nm_assert (!error || !*error);
right = strchr (fields_str, '.');
if (right) {
fields_str_clone = g_strdup (fields_str);
fields_str_clone[right - fields_str] = '\0';
i_name = fields_str_clone;
right = &fields_str_clone[right - fields_str + 1];
} else
i_name = fields_str;
if (!fields_array)
goto not_found;
for (i = 0; fields_array[i]; i++) {
const NMMetaAbstractInfo *fi = fields_array[i];
if (g_ascii_strcasecmp (i_name, nm_meta_abstract_info_get_name (fi, FALSE)) != 0)
continue;
if (!right || !validate_nested) {
found = TRUE;
break;
}
if (fi->meta_type == &nm_meta_type_setting_info_editor) {
const NMMetaSettingInfoEditor *fi_s = (const NMMetaSettingInfoEditor *) fi;
for (j = 0; j < fi_s->properties_num; j++) {
if (g_ascii_strcasecmp (right, fi_s->properties[j].property_name) == 0) {
found = TRUE;
break;
}
}
} else if (fi->meta_type == &nmc_meta_type_generic_info) {
const NmcMetaGenericInfo *fi_g = (const NmcMetaGenericInfo *) fi;
for (j = 0; fi_g->nested && fi_g->nested[j]; j++) {
if (g_ascii_strcasecmp (right, nm_meta_abstract_info_get_name ((const NMMetaAbstractInfo *) fi_g->nested[j], FALSE)) == 0) {
found = TRUE;
break;
}
}
}
fields_array_failure = fields_array[i];
break;
}
if (!found) {
not_found:
if ( !right
&& !fields_prefix
&& ( !g_ascii_strcasecmp (i_name, "all")
|| !g_ascii_strcasecmp (i_name, "common")))
g_set_error (error, NMCLI_ERROR, 0, _("field '%s' has to be alone"), i_name);
else {
gs_free char *allowed_fields = NULL;
if (fields_array_failure) {
gs_free char *p = NULL;
if (fields_prefix) {
p = g_strdup_printf ("%s.%s", fields_prefix,
nm_meta_abstract_info_get_name (fields_array_failure, FALSE));
}
allowed_fields = nmc_get_allowed_fields_nested (fields_array_failure, p);
} else
allowed_fields = nmc_get_allowed_fields (fields_array, NULL);
g_set_error (error, NMCLI_ERROR, 1, _("invalid field '%s%s%s%s%s'; %s%s%s"),
fields_prefix ?: "", fields_prefix ? "." : "",
i_name, right ? "." : "", right ?: "",
NM_PRINT_FMT_QUOTED (allowed_fields, "allowed fields: ", allowed_fields, "", "no fields"));
}
return FALSE;
}
{
GString *str;
OutputSelectionItem s = {
.idx = i,
};
if (!*p_str)
*p_str = g_string_sized_new (64);
str = *p_str;
s.self_offset_plus_1 = str->len + 1;
if (fields_prefix) {
g_string_append (str, fields_prefix);
g_string_append_c (str, '.');
}
g_string_append_len (str, i_name, strlen (i_name) + 1);
if (right) {
s.sub_offset_plus_1 = str->len + 1;
g_string_append_len (str, right, strlen (right) + 1);
}
if (!*p_array)
*p_array = g_array_new (FALSE, FALSE, sizeof (OutputSelectionItem));
g_array_append_val (*p_array, s);
}
return TRUE;
}
static NmcOutputSelection *
_output_selection_create_all (const NMMetaAbstractInfo *const* fields_array)
{
gs_unref_array GArray *array = NULL;
guint i;
if (fields_array) {
array = g_array_new (FALSE, FALSE, sizeof (OutputSelectionItem));
for (i = 0; fields_array[i]; i++) {
OutputSelectionItem s = {
.idx = i,
};
g_array_append_val (array, s);
}
}
return _output_selection_pack (fields_array, array, NULL);
}
static NmcOutputSelection *
_output_selection_create_one (const NMMetaAbstractInfo *const* fields_array,
const char *fields_prefix,
const char *fields_str, /* one field selector (contains not commas) and is alrady stripped of spaces. */
gboolean validate_nested,
GError **error)
{
gs_unref_array GArray *array = NULL;
nm_auto_free_gstring GString *str = NULL;
g_return_val_if_fail (!error || !*error, NULL);
nm_assert (fields_str && !strchr (fields_str, ','));
if (!_output_selection_select_one (fields_array,
fields_prefix,
fields_str,
validate_nested,
&array,
&str,
error))
return NULL;
return _output_selection_pack (fields_array, array, str);
}