summaryrefslogtreecommitdiff
path: root/shared/nm-utils
Commit message (Collapse)AuthorAgeFilesLines
* all: SPDX header conversionLubomir Rintel2019-09-108-119/+8
| | | | | $ find * -type f |xargs perl contrib/scripts/spdx.pl $ git rm contrib/scripts/spdx.pl
* shared/tests: add nmtst_keyfile_get_num_keys() helperThomas Haller2019-08-271-0/+23
|
* build: fix meson warning about path separator in targetBeniamino Galvani2019-08-051-0/+22
| | | | | | | | | | Fix the following: WARNING: Target "nm-utils/tests/test-shared-general" has a path separator in its name. This is not supported, it can cause unexpected failures and will become a hard error in the future. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/217
* libnm: add nm_connection_to_dbus_full() with options argumentThomas Haller2019-06-281-1/+1
| | | | No options are implemented yet.
* shared/tests: add test for nm_utils_bin2hexstr_full()Thomas Haller2019-06-191-0/+82
|
* all: drop empty first line from sourcesThomas Haller2019-06-113-3/+0
| | | | git ls-files -z -- ':(exclude)src/settings/plugins/keyfile/tests/keyfiles' | xargs -0 -n1 sed -i '1 { /^$/d }'
* all: drop emacs file variables from source filesThomas Haller2019-06-117-7/+0
| | | | | | | | | | | | | | | | | | | | | | We no longer add these. If you use Emacs, configure it yourself. Also, due to our "smart-tab" usage the editor anyway does a subpar job handling our tabs. However, on the upside every user can choose whatever tab-width he/she prefers. If "smart-tabs" are used properly (like we do), every tab-width will work. No manual changes, just ran commands: F=($(git grep -l -e '-\*-')) sed '1 { /\/\* *-\*- *[mM]ode.*\*\/$/d }' -i "${F[@]}" sed '1,4 { /^\(#\|--\|dnl\) *-\*- [mM]ode/d }' -i "${F[@]}" Check remaining lines with: git grep -e '-\*-' The ultimate purpose of this is to cleanup our files and eventually use SPDX license identifiers. For that, first get rid of the boilerplate lines.
* shared: add nmtst_get_rand_uint() helperThomas Haller2019-06-111-0/+7
|
* tests/trivial: rename nmtst_get_rand_int() to nmtst_get_rand_uint32()Thomas Haller2019-06-112-8/+8
| | | | | | | | nmtst_get_rand_int() was originally named that way, because it calls g_rand_int(). But I think if a function returns an uint32, it should also be named that way. Rename.
* shared/utils: add nmtst_assert_setting_dbus_roundtrip() utilThomas Haller2019-05-231-0/+35
|
* shared/tests: add nmtst_assert_setting_is_equal() utilThomas Haller2019-05-231-0/+28
|
* shared/tests: add nmtst_variant_from_string() utilThomas Haller2019-05-231-0/+19
|
* shared: implement _nm_utils_monotonic_timestamp_initialized() in ↵Thomas Haller2019-05-221-14/+0
| | | | "nm-logging-stub.c"
* shared/tests: add tests for libnm-core-auxThomas Haller2019-04-251-1/+0
| | | | | | | | | | These tests cannot (easily) be under "shared/nm-libnm-core-aux/tests" because libnm/libnm-core requires code under shared while "nm-libnm-core-aux" requires libnm/libnm-core. With autotools that is not problem, but with meson we include sub directories in a particular order and there is no way to foward declare stuff (AFAIK). To avoid the circular dependency, add the tests to "clients/common/tests", which is always built last.
* shared: move most of "shared/nm-utils" to "shared/nm-glib-aux"Thomas Haller2019-04-1826-11119/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | From the files under "shared/nm-utils" we build an internal library that provides glib-based helper utilities. Move the files of that basic library to a new subdirectory "shared/nm-glib-aux" and rename the helper library "libnm-core-base.la" to "libnm-glib-aux.la". Reasons: - the name "utils" is overused in our code-base. Everything's an "utils". Give this thing a more distinct name. - there were additional files under "shared/nm-utils", which are not part of this internal library "libnm-utils-base.la". All the files that are part of this library should be together in the same directory, but files that are not, should not be there. - the new name should better convey what this library is and what is isn't: it's a set of utilities and helper functions that extend glib with funcitonality that we commonly need. There are still some files left under "shared/nm-utils". They have less a unifying propose to be in their own directory, so I leave them there for now. But at least they are separate from "shared/nm-glib-aux", which has a very clear purpose.
* shared: move udev helper to separate directory "shared/nm-udev-aux"Thomas Haller2019-04-182-339/+0
| | | | | | | | We built (among others) two libraries from the sources in "shared/nm-utils": "libnm-utils-base.la" and "libnm-utils-udev.la". It's confusing. Instead use directories so there is a direct correspondence between these internal libraries and the source files.
* shared: split C-only helper "shared/nm-std-aux" utils out of "shared/nm-utils"Thomas Haller2019-04-185-377/+3
| | | | | | | | | | | | | "shared/nm-utils" contains general purpose utility functions that only depend on glib (and extend glib with some helper functions). We will also add code that does not use glib, hence it would be good if the part of "shared/nm-utils" that does not depend on glib, could be used by these future projects. Also, we use the term "utils" everywhere. While that covers the purpose and content well, having everything called "nm-something-utils" is not great. Instead, call this "nm-std-aux", inspired by "c-util/c-stdaux".
* shared: remove unused _nm_utils_escape_plain()/_nm_utils_escape_spaces() APIThomas Haller2019-04-182-92/+0
| | | | | | | ... and the "unescape" variants. This is replaced by nm_utils_escaped_tokens_split() and nm_utils_escaped_tokens_escape*() API.
* shared: add nm_utils_escaped_tokens_escape_gstr_assert()Thomas Haller2019-04-171-0/+33
|
* shared: remove unused nm_utils_str_simpletokens_extract_next()Thomas Haller2019-04-172-55/+0
| | | | | | | | | | | | | This can be replaced by nm_utils_escaped_tokens_split(). Note that nm_utils_escaped_tokens_split() does not behave exactly the same. For example, nm_utils_str_simpletokens_extract_next() would remove all backslashes and leave only the following character. nm_utils_escaped_tokens_split() instead only strips backslashes that preceed a delimiter, whitespace or another backslash. But we should have one preferred way of tokenizing, and I find this preferable, because it allows for most backslashes to appear verbatim.
* shared: add nm_utils_escaped_tokens_escape()Thomas Haller2019-04-172-0/+107
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* shared: add NM_UTILS_STRSPLIT_SET_FLAGS_ESCAPED to nm_utils_strsplit_set_full()Thomas Haller2019-04-172-1/+53
| | | | | | | | | | | | | | | | | | | | | Add a new flag that will remove escape characters after splitting the string. This implements a special kind of backslash escaping. It's not C escape sequences (like '\n' or '\020'), but simply to take the special character following the backslash verbatim. Note that the backslash is only considered special, if it's followed by a delimiter, another backslash, or a whitespace (in combination with %NM_UTILS_STRSPLIT_SET_FLAGS_STRSTRIP). The main purpose of this form of escaping is nmcli's list options, like $ 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' It's a contrieved example, but the list options are a list of IP addresses, rules, etc. They implement their own syntax for one element, and are concatenated by ','. To support that one element may have arbitrary characters (including the delimiter and whitespaces), nmcli employs a tokenization with this special kind of escaping.
* shared: add NM_UTILS_STRSPLIT_SET_FLAGS_STRSTRIP to nm_utils_strsplit_set_full()Thomas Haller2019-04-172-17/+66
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This will essentially call g_strstrip() on each token. There are some specialties: - if the resulting word is empty after stripping, then according to %NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY, the empty token will be removed. If that results in an empty string array, %NULL will be returned. - if %NM_UTILS_STRSPLIT_SET_FLAGS_ALLOW_ESCAPING is set, then whitespace that is backslash escaped is not removed. Since this is a post-operation that happens after tokeninzing, it could be done as a separate function. And we already have this function: _nm_utils_unescape_plain() and _nm_utils_unescape_spaces(). However, that is ugly for several reasons: - the stripping should be part of the tokenizing, you shouldn't need several steps. - nm_utils_strsplit_set_full() returns a "const char **" which indicates the strings must not be freed. However, it is perfectly valid to modify the string inplace. Hence, the post-op function would need to cast the strings to "char *", which seems ugly (although we do that on many places, and it's guaranteed to work). - _nm_utils_unescape_plain()/_nm_utils_unescape_spaces() is indeed already used together with nm_utils_strsplit_set_full(). However, it requires to initialize the cb_lookup buffer twice. I would expect that initializing the cb_lookup buffer is a large portion of what the function does already (for short strings). This issue will be solved in the next commit by adding yet another flag which allows to unescape.
* all: goodbye libnm-glibLubomir Rintel2019-04-161-8/+0
| | | | | | | | | | | | | | | | | | | | | | | This removes libnm-glib, libnm-glib-vpn, and libnm-util for good. The it has been replaced with libnm since NetworkManager 1.0, disabled by default since 1.12 and no up-to-date distributions ship it for years now. Removing the libraries allows us to: * Remove the horrible hacks that were in place to deal with accidental use of both the new and old library in a single process. * Relief the translators of maintenance burden of similar yet different strings. * Get rid of known bad code without chances of ever getting fixed (libnm-glib/nm-object.c and libnm-glib/nm-object-cache.c) * Generally lower the footprint of the releases and our workspace If there are some really really legacy users; they can just build libnm-glib and friends from the NetworkManager-1.16 distribution. The D-Bus API is stable and old libnm-glib will keep working forever. https://github.com/NetworkManager/NetworkManager/pull/308
* shared: add nm_auto_clear_variant_builderThomas Haller2019-04-121-0/+2
|
* shared: pre-calculate number of tokens in nm_utils_strsplit_set_full()Thomas Haller2019-04-101-44/+66
| | | | | | | | | | | | | | Instead of growing the buffer for the tokens (and reallocating), do one pre-run over the string and count the delimiters. This way we know how much space we need and we don't need to reallocate. Interestingly, this is notably slower than the previous implementation, because previously if would not bother determining the right number of tokens but just over-allocate with a reasonable guess of 8 and grow the buffer exponentially. Still, I like this better because while it may be slower in common scenarios, it allocates the exact number of buffer space.
* shared: add NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY flag for ↵Thomas Haller2019-04-102-17/+55
| | | | | | | | | | | | nm_utils_strsplit_set_full() Previously, nm_utils_strsplit_set_full() would always remove empty tokens. Add a flag NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY to avoid that. This makes nm_utils_strsplit_set_full() return the same result as g_strsplit_set() and a direct replacement for it -- except for "", where we return %NULL.
* shared: refactor allowed-escaped handling in nm_utils_strsplit_set_full()Thomas Haller2019-04-101-28/+21
| | | | | | | Drop the next_char() and is_delimiter() macros. They are difficult to understand, because they both have a state-variable (escaped). Instead, the state of whether we handle an escape or not, shall only depend on the current line of code.
* shared: refactor lookup of delimiter tables in nm_utils_strsplit_set_full()Thomas Haller2019-04-101-15/+21
|
* all: don't accept %NULL as delimiters for nm_utils_strsplit_set()Thomas Haller2019-04-101-3/+4
| | | | | | | | | | | | | | | | | | | The caller should make a conscious decision which delimiters to use. Unfortunately, there is a variety of different demiters in use. This should be unitfied and the callers should use one of a few specific set of delimiters. This could be unified by (re)using a define as delimiters, like strv = nm_utils_strsplit_set_full (value, MULTILIST_WITH_ESCAPE_CHARS, NM_UTILS_STRSPLIT_SET_FLAGS_ALLOW_ESCAPING); where MULTILIST_WITH_ESCAPE_CHARS has a particular meaning that should be reused for similar uses. However, leaving the delimiter at NULL is not good because it's unclear who wants that default behavior (and what the default should be). Don't allow that. There are almost no callers that relied on this default anyway.
* shared: add flags argument to nm_utils_strsplit_set()Thomas Haller2019-04-102-11/+28
| | | | | | It will be useful to extend nm_utils_strsplit_set() with various flavors and subtly different behaviors. Add a flags argument to support these.
* shared: cleanup _nm_utils_ascii_str_to_bool()Thomas Haller2019-04-041-18/+14
| | | | | | | | Previously, this would re-implement what nm_strstrip_avoid_copy() was doing. Use nm_strstrip_avoid_copy_a() instead, which avoids the code duplication and the heap allocation in common cases.
* shared: add nm_strstrip_avoid_copy_a() helperThomas Haller2019-04-042-0/+80
|
* shared: move nm_memdup(), nm_strndup_a(), and nm_strdup_int() to ↵Thomas Haller2019-04-042-112/+112
| | | | | | | | | | | | | | "nm-macros-internal.h" The main difference between "shared/nm-utils/nm-macros-internal.h" and "shared/nm-utils/nm-shared-utils.h" is that the former is header-only while the latter has a source file as well. Apart from that, both headers are included everywhere. The next commit will add nm_strstrip_avoid_copy_a() to "nm-macros-internal.h" header, which will use nm_strndup_a(). Hence, also nm_strndup_a() should be in "nm-macros-internal.h".
* shared/trivial: rename variables in nm_strndup_a() and ↵Thomas Haller2019-04-042-18/+18
| | | | | | | | | nm_str_skip_leading_spaces() macros "_str" is a very tempting name for a temporary variable. Rename the variable in nm_strndup_a() macro, so that other macros can call these (more general) macros (and still use the name "_str").
* shared: add nm_auto_unref_gmainloop cleanup macroThomas Haller2019-04-041-0/+3
|
* Revert "all: goodbye libnm-glib"Lubomir Rintel2019-04-031-0/+8
| | | | | | We need this for a little little longer :( This reverts commit 1de8383ad9fdfc8f552117e5d109bdfa7005634b.
* shared: better implement compat version of explicit_bzero()Thomas Haller2019-04-021-6/+13
| | | | | | | | | | | If we don't have explicit_bzero(), try a bit harder and use a volatile pointer. This is also what libsecret's egg_secure_clear() does [1]. However, for us this is less important, because commonly we expect glibc to provide a useable explicit_bzero(). [1] https://gitlab.gnome.org/GNOME/libsecret/blob/b5442654d483e959ac9ecd3a3fb9eebc8d9d8399/egg/egg-secure-memory.c#L1352
* shared: add nm_utils_str_simpletokens_extract_next()Thomas Haller2019-03-272-0/+55
|
* shared: add nm_ip_addr_is_null() helperThomas Haller2019-03-271-0/+10
|
* shared: add _nm_utils_escape_plain() APIThomas Haller2019-03-252-12/+40
|
* all: consider all ASCII spaces for _nm_utils_escape_spaces() and unescapeThomas Haller2019-03-251-9/+5
|
* shared: add NM_ASCII_SPACES macroThomas Haller2019-03-251-0/+3
|
* shared: add "strip" argument to _nm_utils_unescape_spaces()Thomas Haller2019-03-252-5/+21
| | | | | | | | | | | It's usually not necessary, because _nm_utils_unescape_spaces() gets called after nm_utils_strsplit_set(), which already removes the non-escaped spaces. Still, for completeness, this should be here. Also, because with this the function is useful for individual options (not delimiter separate list values), to support automatically dropping leading or trailing whitespace, but also support escaping them.
* cli: avoid unnecessary string clones for stripping whitespace for property ↵Thomas Haller2019-03-251-0/+2
| | | | values
* shared: don't implement nm_utils_parse_inaddr() based on ↵Thomas Haller2019-03-251-1/+9
| | | | | | | | | nm_utils_parse_inaddr_bin() nm_utils_parse_inaddr() is trivial enough to reimplement it, instead of calling nm_utils_parse_inaddr_bin(). Calling nm_utils_parse_inaddr_bin() involves several things that don't matter for nm_utils_parse_inaddr() -- like assigning out_addr_family or returning the binary address.
* shared: add _nm_utils_strv_cmp_n() and _nm_utils_strv_equal()Thomas Haller2019-03-243-0/+208
|
* shared/tests: add parentheses around arguments of NMTST_SWAP() macroThomas Haller2019-03-241-5/+6
|
* all: goodbye libnm-glibLubomir Rintel2019-03-191-8/+0
| | | | | | | | | | | | | | | | | | | | | | | This removes libnm-glib, libnm-glib-vpn, and libnm-util for good. The it has been replaced with libnm since NetworkManager 1.0, disabled by default since 1.12 and no up-to-date distributions ship it for years now. Removing the libraries allows us to: * Remove the horrible hacks that were in place to deal with accidental use of both the new and old library in a single process. * Relief the translators of maintenance burden of similar yet different strings. * Get rid of known bad code without chances of ever getting fixed (libnm-glib/nm-object.c and libnm-glib/nm-object-cache.c) * Generally lower the footprint of the releases and our workspace If there are some really really legacy users; they can just build libnm-glib and friends from the NetworkManager-1.16 distribution. The D-Bus API is stable and old libnm-glib will keep working forever. https://github.com/NetworkManager/NetworkManager/pull/308
* shared: add nm_hash_obfuscate_ptr() helperThomas Haller2019-03-131-1/+26
|