NetworkManager/shared/nm-utils
Thomas Haller 0cc5fe78b3 shared: add nm_utils_escaped_tokens_escape()
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 e206e3d4d8)
2019-04-17 11:27:10 +02:00
..
tests shared: add nm_strstrip_avoid_copy_a() helper 2019-04-04 21:01:15 +02:00
c-list-util.c shared: implement c_list_sort() as non-recursive merge-sort 2018-01-03 16:41:47 +01:00
c-list-util.h shared: add c_list_length_is() helper 2019-03-13 09:03:58 +01:00
nm-c-list.h shared: add nm_c_list_move_*() helpers 2019-02-18 15:00:10 +01:00
nm-compat.c all: avoid g_memdup() 2018-09-07 11:24:17 +02:00
nm-compat.h shared/compat: add compat for nm_setting_vpn_get_data_keys() and nm_setting_vpn_get_secret_keys() 2017-11-23 14:44:25 +01:00
nm-dedup-multi.c all: use nm_c_list_move_*() helpers 2019-02-18 15:00:10 +01:00
nm-dedup-multi.h Fix typos 2018-09-30 21:14:55 +02:00
nm-enum-utils.c all: don't use gchar/gshort/gint/glong but C types 2018-07-11 12:02:06 +02:00
nm-enum-utils.h all: don't use gchar/gshort/gint/glong but C types 2018-07-11 12:02:06 +02:00
nm-errno.c shared: add nm_strerror_native() to replace strerror() and g_strerror() 2019-02-12 08:50:28 +01:00
nm-errno.h shared: fix nm_errno_from_native() for negative input 2019-02-12 09:13:29 +01:00
nm-glib.h shared/nm-glib: add our own g_steal_pointer() macro to shadow the one from glib 2019-02-21 07:22:36 +01:00
nm-hash-utils.c all: fix misspellings 2019-01-24 17:19:44 +01:00
nm-hash-utils.h shared: add nm_hash_obfuscate_ptr() helper 2019-03-13 09:03:58 +01:00
nm-io-utils.c cli/wireguard: add import functionality for WireGuard 2019-03-07 17:54:25 +01:00
nm-io-utils.h shared: move file-get-contents and file-set-contents helper to shared/ 2018-09-04 07:38:30 +02:00
nm-jansson.h shared: add nm_auto_decref_json 2019-02-17 19:39:07 +01:00
nm-logging-fwd.h logging: make nm-logging thread-safe 2019-02-05 08:18:08 +01:00
nm-macros-internal.h shared: add nm_auto_clear_variant_builder 2019-04-12 11:07:25 +02:00
nm-obj.h all: replace "it's" with "its" where needed 2018-04-18 14:14:07 +02:00
nm-random-utils.c Fix typos 2018-09-30 21:14:55 +02:00
nm-random-utils.h shared: split random and hash utils 2017-10-17 20:02:59 +02:00
nm-secret-utils.c shared: better implement compat version of explicit_bzero() 2019-04-02 19:30:33 +02:00
nm-secret-utils.h shared: add nm_utils_memeqzero_secret() 2019-03-07 17:54:25 +01:00
nm-shared-utils.c shared: add nm_utils_escaped_tokens_escape() 2019-04-17 11:27:10 +02:00
nm-shared-utils.h shared: add nm_utils_escaped_tokens_escape() 2019-04-17 11:27:10 +02:00
nm-test-utils.h Revert "all: goodbye libnm-glib" 2019-04-03 08:52:38 +02:00
nm-time-utils.c shared: thread safe initialization of nm_utils_get_monotonic_timestamp*() 2018-11-28 16:13:04 +01:00
nm-time-utils.h shared: move nm_utils_get_monotonic_timestamp*() to shared/nm-utils. 2018-10-18 12:16:55 +02:00
nm-udev-utils.c udev: remove unneeded NULL checks 2018-12-12 14:18:53 +01:00
nm-udev-utils.h udev: add and use nm_udev_utils_property_decode() function 2017-03-22 12:41:06 +01:00
nm-vpn-editor-plugin-call.h shared: include "gsystem-local-alloc.h" from "nm-glib.h" 2016-06-16 10:45:54 +02:00
nm-vpn-plugin-macros.h shared: add nm_utils_syslog_coerce_from_nm() util 2016-09-19 15:35:33 +02:00
nm-vpn-plugin-utils.c shared/vpn-plugin-utils: load the editor from the same place as plugin 2018-10-24 15:12:43 +02:00
nm-vpn-plugin-utils.h shared: add "nm-utils/nm-vpn-plugin-utils.h" 2016-06-16 10:45:54 +02:00
unaligned.h systemd: update code from upstream (2018-11-23) 2018-11-23 10:53:12 +01:00