mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-24 18:20:07 +01:00
This escapes strings so that they can be concatenated with a delimiter
and without loss tokenized with nm_utils_escaped_tokens_split().
Note that this is similar to _nm_utils_escape_plain() and
_nm_utils_escape_spaces(). The difference is that
nm_utils_escaped_tokens_escape() also escapes the last trailing
whitespace. That means, if delimiters contains all NM_ASCII_SPACES, then
it is identical to _nm_utils_escape_spaces(). Otherwise, the trailing
space is treated specially. That is, because
nm_utils_escaped_tokens_split() uses NM_UTILS_STRSPLIT_SET_FLAGS_STRSTRIP,
to strip leading and trailing whitespace. To still express a trailing
whitespace, the last whitespace must be escaped. Note that
NM_UTILS_STRSPLIT_SET_FLAGS_STRSTRIP also honors escaping any whitespace
(not only at the last position), but when escaping we don't need to
escape them, because unescaped (non-trailing) whitespace are taken just
fine.
The pair nm_utils_escaped_tokens_split() and
nm_utils_escaped_tokens_escape() are proposed as default way of
tokenizing a list of items. For example, with
$ nmcli connection modify "$PROFILE" +ipv4.routing-rules 'priority 5 from 192.168.7.5/32 table 5, priority 6 iif a\, from 192.168.7.5/32 table 6'
Here we implement a to/from string function to handle one item
(nm_ip_routing_rule_{from,to}_string()). When such elements are combined with ',',
then we need to support an additional layer of escaping on top of that.
The advantage is that the indvidual to/from string functions are agnostic
to this second layer of escaping/tokenizing that nmcli employs to handle
a list of these items.
The disadvantage is that we possibly get multiple layers of backslash
escapings. That is only mitigated by the fact that nm_utils_escaped_tokens_*()
supports a syntax for which *most* characters don't need any special escaping.
Only delimiters, backslash, and the trailing space needs escaping, and
these are cases are expected to be few.
(cherry picked from commit
|
||
|---|---|---|
| .. | ||
| tests | ||
| c-list-util.c | ||
| c-list-util.h | ||
| nm-c-list.h | ||
| nm-compat.c | ||
| nm-compat.h | ||
| nm-dedup-multi.c | ||
| nm-dedup-multi.h | ||
| nm-enum-utils.c | ||
| nm-enum-utils.h | ||
| nm-errno.c | ||
| nm-errno.h | ||
| nm-glib.h | ||
| nm-hash-utils.c | ||
| nm-hash-utils.h | ||
| nm-io-utils.c | ||
| nm-io-utils.h | ||
| nm-jansson.h | ||
| nm-logging-fwd.h | ||
| nm-macros-internal.h | ||
| nm-obj.h | ||
| nm-random-utils.c | ||
| nm-random-utils.h | ||
| nm-secret-utils.c | ||
| nm-secret-utils.h | ||
| nm-shared-utils.c | ||
| nm-shared-utils.h | ||
| nm-test-utils.h | ||
| nm-time-utils.c | ||
| nm-time-utils.h | ||
| nm-udev-utils.c | ||
| nm-udev-utils.h | ||
| nm-vpn-editor-plugin-call.h | ||
| nm-vpn-plugin-macros.h | ||
| nm-vpn-plugin-utils.c | ||
| nm-vpn-plugin-utils.h | ||
| unaligned.h | ||