The function nmc_print() receives a list of "targets". These are essentially
the rows that should be printed (while the "fields" list represents the columns).
When filling the cells with values, it calles repeatedly get_fcn() on the
column descriptors (fields), by passing each row (target).
The caller must be well aware that the fields and targets are
compatible. For example, in some cases the targets are NMDevice
instances and the target type must correspond to what get_fcn()
expects.
Add another user-data pointer that is passed on along with the
targets. That is useful, if we have a list of targets/rows, but
pass in additional data that applies to all rows alike.
It is still unused.
The property getter for certain properties tries to return
a strv array.
In this case, the result should be identical, whether an
empty strv array or NULL is returned.
Let _ip_config_get_routes() return %NULL if there are no routes.
This should have no practical difference, but it actually exposes
a bug in "cli/common/utils.c", which was previously hidden by
not commonly returning %NULL. This bug will be fixed in the
next commit.
The reasons are:
- I want to locate all implmenetations of the get_fcn() handler. By
consistently using this macro, you can just grep for the macro and
find them all.
- all implementations should follow the same style. This macro
enforces the same names for arguments and avoids copy&paste.
- if we are going to add or change an argument, it becomes easier.
That's because we can easily identify all implementation and can
change arguments in one place.
Functions like nmc_find_connection() and nmc_find_active_connection()
can easily find multiple matching results. For example, the
"connection.id" in NetworkManager is not enforced to be unique,
so if the user adds multiple connections with the same name,
they should be all selected.
The previous API had a @pos argument, that allowed to iterate over
the results. Change that, to return all matches in a GPtrArray.
Also, extend connection-show and other places, to anticipate that
a connection might be active multiple times in any moment.
This basically replaces the (NMMetaTermColor, NMMetaTermFormat) combo
with NMMetaColor that describes the colored element semantically as
opposed to storing the raw attributes.
A (currently static) paletted is used to translate the semantic color
code to the actual ANSI controle sequence. This matches what
terminal-colors.d(5) schemes use, making it convenient to implement
customizable palettes.
'help' is completed without considering other alternatives:
# nmcli connection modify h<TAB>
help
After the patch:
# nmcli connection modify h<TAB>
help
home-wifi
Fixes: 29bb6ae4fe
Makes sense in order for the user to know that they're actually typing
the password (edited just to illustrate the point, the actual output was
shamefully messy and perhaps needs fixing too):
$ nmcli c up Wrathmosphere
Passwords or encryption keys are required to access the wireless network 'Wrathmosphere'.
Password (802-1x.password): *********
History is probably even not useful at all outside the interactive edit
mode, but that is another story. This just avoids awkward surprises,
such as:
https://bugzilla.gnome.org/show_bug.cgi?id=791200
Next we will use siphash24() instead of the glib version g_direct_hash() or
g_str_hash(). Hence, the "nm-utils/nm-hash-utils.h" header becomes very
fundamental and will be needed basically everywhere.
Instead of requiring the users to include them, let it be included via
"nm-default.h" header.
We want to support large number of routes. Reduce the number
of copies, by adding internal accessor functions.
Also, work around a complaint from coverity:
46. NetworkManager-1.9.2/libnm-core/nm-utils.c:1987:
dereference: Dereferencing a null pointer "names".
Replace the usage of g_str_hash() with our own nm_str_hash().
GLib's g_str_hash() uses djb2 hashing function, just like we
do at the moment. The only difference is, that we use a diffrent
seed value.
Note, that we initialize the hash seed with random data (by calling
getrandom() or reading /dev/urandom). That is a change compared to
before.
This change of the hashing function and accessing the random pool
might be undesired for libnm/libnm-core. Hence, the change is not
done there as it possibly changes behavior for public API. Maybe
we should do that later though.
At this point, there isn't much of a change. This patch becomes
interesting, if we decide to use a different hashing algorithm.
In a later commit we'll add a new generic client function used by
nmcli and nmtui. nm-client-utils.c seems the right place for it, so
move the file to the base library that is used by both clients.
While at it, also put in that file some functions that will be needed
by nmtui.
The INT signal can arrive after a new line has been processed in
nmc_readline_helper(). In such case, the handler gets uninstalled by
readline_cb() and nmc_seen_sigint() returns TRUE. However it's an
error to call rl_callback_read_char() without handler, don't do it.
Fixes the following:
"readline: readline_callback_read_char() called with no handler!"
#0 __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1 __GI_abort () at abort.c:90
#2 rl_callback_read_char () at ../callback.c:116
#3 nmc_readline_helper (prompt=prompt@entry=0x2aa0d229080 "nmcli> ") at clients/cli/common.c:1387
#4 nmc_readline (prompt_fmt=prompt_fmt@entry=0x2aa0036ac9e "%s") at clients/cli/common.c:1448
#5 do_connection_edit (connection=0x2aa0d215440, nmc=0x2aa00391298 <nm_cli>) at clients/cli/connections.c:7072
Fixes: 995229181chttps://bugzilla.redhat.com/show_bug.cgi?id=1458311
The show-secret property is basically a part of the current
configuration, relevant during printing. It will be passed
on to nmc_print(), and hence must be part of NmcConfig.
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
Options dependant on specific commands (e.g., nmcli connection show
--active) are now allowed to be processed by the next_arg() function.
This would allow autocompletion to expand options belonging to specific
command first, and then global ones.
Note that global options ("--ask" and "--show-secrets") will be auto-completed
everywhere but only if at least a '-' is passed. Command specific ones
(--temporary, --active, --order) will be auto-completed only after the command
they belongs to but without requiring the user to pass a heading '-'.
Example:
'nmcli connection show -a'
will expand '-a' into '--active', but
'nmcli connection add -a`
will expand '-a' into '--ask' (as it is a global option)
This commit fixes also autocompletion for:
nmcli connection modify --temporary
We should not violate the global data to track the output data
while it is constructed and printed.
Most of the time, we actually clear the output data anyway --
either before constructing it, or after printing it.
In some cases we didn't, but I think that is a bug. It's really
hard to keep track of this.
The output data should belong to a certain scope and get destroyed
afterwards. Passing it around is very confusing. Don't do that.
To better understand which part of the code have side effects,
split print_data() in a part that mutilates the input array
and a part that only prints.
The NmCli structure is passed around everywhere and contains all
the state of the program. It is very hard to follow which parts
are used where.
Split out more configuration options to a NmcConfig field. This field
is mostly immutable, and modified at particular places that now can be
easily found.
Otherwise, changing the structure is difficult because it all depends
on the order (and you don't immdiately see which field is used where).
Also, drop the name_l10n field.
These functions are only used by nm-meta-setting-desc.c. Make them internal.
Unfortunately, they are part of "common.h" which cannot be used without
the rest of nmcli. Still todo.
Shift argc and argc manually between argument ant its value and use
next_arg() between arguments everywhere. Whill be useful to parse global
arguments.