Commit Graph

782 Commits

Author SHA1 Message Date
Thomas Haller
a78ba1c33a shared: add nm_strcmp_with_data()
It is like strcmp(), but has a signature suitable for GCompareDataFunc.

This is necessary with nm_utils_ptrarray_find_binary_search()
to search a sorted strv array.

The fault is here really C, which doesn't allow inline static functions.
So, you need all kinds of slightly different flavors for the same
callbacks (with or without user-data).

Note that glib2 internally just casts strcmp() to GCompareDataFunc ([1]),
relying on the fact how arguments are passed to the function and
ignoring the additional user-data argument. But I find that really
ugly and probably not permissible in general C. Dunno whether POSIX
would guarantee for this to work. I'd rather not do such function
pointer casts.

[1] 0c0cf59858/glib/garray.c (L1792)
2019-07-25 10:42:06 +02:00
Thomas Haller
3c0161a385 shared: add nm_utils_clock_gettime_*() util
Using clock_gettime() directly is a bit inconvenient. We usually
want to combine the fields of struct timespec into one timestamp
(for example, in unit nanoseconds).

Add a helper function to do that.
2019-07-23 12:19:22 +02:00
Thomas Haller
d5ad315f11 shared: suppress -Werror=stringop-overflow= warning in nm_strndup_a()
nm_strndup_a() uses strncpy() because we want the behavior of clearing out
the memory after the first NUL byte. But that can cause a compiler warning:

    CC       src/settings/plugins/keyfile/libNetworkManager_la-nms-keyfile-utils.lo
  In file included from ../../shared/nm-default.h:279,
                   from ../../src/settings/plugins/keyfile/nms-keyfile-utils.c:20:
  In function ‘_nm_strndup_a_step’,
      inlined from ‘nms_keyfile_loaded_uuid_is_filename’ at ../../src/settings/plugins/keyfile/nms-keyfile-utils.c:65:9:
  ../../shared/nm-glib-aux/nm-macros-internal.h:1661:3: error: ‘strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
   1661 |   strncpy (s, str, len);
        |   ^~~~~~~~~~~~~~~~~~~~~
  ../../src/settings/plugins/keyfile/nms-keyfile-utils.c: In function ‘nms_keyfile_loaded_uuid_is_filename’:
  ../../src/settings/plugins/keyfile/nms-keyfile-utils.c:48:8: note: length computed here
     48 |  len = strlen (filename);
        |        ^~~~~~~~~~~~~~~~~

It's true that the len argument of _nm_strndup_a_step() depends on the
string length of the source string. But in this case it's safe, because
we checked that the destination buffer is exactly the right size too.
By that reasoning we should use memcpy() or strcpy(), but both are
unsuitable. That is because we want nm_strndup_a() to behave like
strndup(), which means we need to handle cases where the len argument
is larger than the string length of the source string. That is, we want
always to return a buffer of size len+1, but we want to copy only the
characters up to the first NUL byte, and clear out the rest. That's what
strncpy() does for us.

Silence the warning.
2019-07-16 10:48:38 +02:00
Thomas Haller
a9b15bde3c shared: add NM_CMP_DIRECT_STRCMP() macro 2019-07-10 12:43:06 +02:00
Thomas Haller
6d30021fee shared: optimize nm_utils_error_set() for string literals
If there is only one argument, we can assume this is a plain string.

That is especially the case, because g_set_error() is G_GNUC_PRINTF()
and would warn if this would be a format string with missing parameters.

This is for convenience. Previously, one was compelled to explicitly
choose between nm_utils_error_set_literal() and nm_utils_error_set().
Now, it automatically chooses.

Note that there are a few things that won't work, like

  nm_utils_error_set (error, code, "bogus %u escape");

But that's good. You get a compiler warning (as you used to)
and it's clear in this case you really need
nm_utils_error_set_literal().
2019-07-10 12:43:06 +02:00
Thomas Haller
7f75a1b5f5 shared: add nm_pdirect_hash()/nm_pdirect_equal()
This follows a pointer to a pointer and compares them. In a sense
it's like nm_pstr_*(), which follow a pointer to a string. However,
these functions use direct pointer comparison.

The purpose is when you hash a key that has as first field a pointer
value (and then compare them by pointer equality).
2019-07-10 12:43:06 +02:00
Beniamino Galvani
106c156b0f n-dhcp4: client/probe: fix memory leak
The probe takes a reference to the current lease and so it must
release it upon destruction.

Signed-off-by: Beniamino Galvani <bgalvani@redhat.com>

https://github.com/nettools/n-dhcp4/pull/1
2019-07-05 11:09:28 +02:00
Beniamino Galvani
46f81e18f7 n-dhcp4: client/connection: fix memory leak
Free the request when the connection gets destroyed.

Signed-off-by: Beniamino Galvani <bgalvani@redhat.com>

https://github.com/nettools/n-dhcp4/pull/1
2019-07-05 11:09:03 +02:00
Beniamino Galvani
0280fd1a80 shared: add nm_sd_dns_name_to_wire_format()
Add nm_sd_dns_name_to_wire_format() based on systemd utilities to
convert a name into its wire format according to RFC 1035 section
3.1. It will be used to build the content of the DHCP FQDN option.
2019-07-05 11:04:32 +02:00
Beniamino Galvani
7d3098ff90 systemd: add dns-domain utils to systemd static library
dns-domain.c contains useful functions for manipulating DNS names.
Add it to the systemd static library we build in shared/, similarly to
what we already do for other utility files that were originally in
src/systemd/src/basic/.
2019-07-05 11:04:32 +02:00
Tom Gundersen
314134a445 n-dhcp4: avoid {net,linux}/if.h clashes on old distros
In particular, avoid including linux/netdevice.h from headers. This is
not a problem on newer distros, but required for CentOS 7.6.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-07-05 11:04:32 +02:00
Tom Gundersen
d797611df5 shared/n-dhcp4: avoid c_min() macro to work with old GCC
This is required for the CI to pass, as CentOS has a too old version
of GCC. Ideally this patch should be dropped.
2019-07-05 11:04:32 +02:00
Tom Gundersen
6adade6f21 dhcp: add nettools dhcp4 client
This is inspired by the existing systemd integration, with a few differences:

* This parses the WPAD option, which systemd requested, but did not use.
* We hook into the DAD handling, only making use of the configured address
  once DAD has completed successfully, and declining the lease if it fails.

There are still many areas of possible improvement. In particular, we need
to ensure the parsing of all options are compliant, as n-dhcp4 treats all
options as opaque, unlike sd-dhcp4. We probably also need to look at how
to handle failures and retries (in particular if we decline a lease).

We need to query the current MTU at client startu, as well as the hardware
broadcast address. Both these are provided by the kernel over netlink, so
it should simply be a matter of hooking that up with NM's netlink layer.

Contribution under LGPL2.0+, in addition to stated licenses.
2019-07-05 11:04:32 +02:00
Beniamino Galvani
be8f7b5a5d systemd: merge branch systemd into master 2019-07-05 09:13:53 +02:00
Beniamino Galvani
55c47d4efa systemd: update code from upstream (2019-07-04)
This is a direct dump from systemd git.

======

SYSTEMD_DIR=../systemd
COMMIT=52d8bcd131e7f3c9b7629412302e1ea46ddb70ca

(
  cd "$SYSTEMD_DIR"
  git checkout "$COMMIT"
  git reset --hard
  git clean -fdx
)

git ls-files -z :/src/systemd/src/ \
                :/shared/systemd/src/ \
                :/shared/nm-utils/unaligned.h | \
  xargs -0 rm -f

nm_copy_sd_shared() {
    mkdir -p "./shared/systemd/$(dirname "$1")"
    cp "$SYSTEMD_DIR/$1" "./shared/systemd/$1"
}

nm_copy_sd_core() {
    mkdir -p "./src/systemd/$(dirname "$1")"
    cp "$SYSTEMD_DIR/$1" "./src/systemd/$1"
}

nm_copy_sd_nmutils() {
    mkdir -p "./shared/nm-utils/"
    cp "$SYSTEMD_DIR/$1" "./shared/nm-utils/${1##*/}"
}

nm_copy_sd_core "src/libsystemd-network/arp-util.c"
nm_copy_sd_core "src/libsystemd-network/arp-util.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-identifier.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-identifier.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-lease-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-network.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-option.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-packet.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-protocol.h"
nm_copy_sd_core "src/libsystemd-network/dhcp6-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp6-lease-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp6-network.c"
nm_copy_sd_core "src/libsystemd-network/dhcp6-option.c"
nm_copy_sd_core "src/libsystemd-network/dhcp6-protocol.h"
nm_copy_sd_core "src/libsystemd-network/lldp-internal.h"
nm_copy_sd_core "src/libsystemd-network/lldp-neighbor.c"
nm_copy_sd_core "src/libsystemd-network/lldp-neighbor.h"
nm_copy_sd_core "src/libsystemd-network/lldp-network.c"
nm_copy_sd_core "src/libsystemd-network/lldp-network.h"
nm_copy_sd_core "src/libsystemd-network/network-internal.c"
nm_copy_sd_core "src/libsystemd-network/network-internal.h"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp-client.c"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp-lease.c"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp6-client.c"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp6-lease.c"
nm_copy_sd_core "src/libsystemd-network/sd-ipv4acd.c"
nm_copy_sd_core "src/libsystemd-network/sd-ipv4ll.c"
nm_copy_sd_core "src/libsystemd-network/sd-lldp.c"
nm_copy_sd_core "src/libsystemd/sd-event/event-source.h"
nm_copy_sd_core "src/libsystemd/sd-event/event-util.c"
nm_copy_sd_core "src/libsystemd/sd-event/event-util.h"
nm_copy_sd_core "src/libsystemd/sd-event/sd-event.c"
nm_copy_sd_core "src/libsystemd/sd-id128/id128-util.c"
nm_copy_sd_core "src/libsystemd/sd-id128/id128-util.h"
nm_copy_sd_core "src/libsystemd/sd-id128/sd-id128.c"
nm_copy_sd_core "src/shared/dns-domain.c"
nm_copy_sd_core "src/shared/dns-domain.h"
nm_copy_sd_core "src/systemd/_sd-common.h"
nm_copy_sd_core "src/systemd/sd-dhcp-client.h"
nm_copy_sd_core "src/systemd/sd-dhcp-lease.h"
nm_copy_sd_core "src/systemd/sd-dhcp6-client.h"
nm_copy_sd_core "src/systemd/sd-dhcp6-lease.h"
nm_copy_sd_core "src/systemd/sd-event.h"
nm_copy_sd_core "src/systemd/sd-id128.h"
nm_copy_sd_core "src/systemd/sd-ipv4acd.h"
nm_copy_sd_core "src/systemd/sd-ipv4ll.h"
nm_copy_sd_core "src/systemd/sd-lldp.h"
nm_copy_sd_core "src/systemd/sd-ndisc.h"
nm_copy_sd_nmutils "src/basic/unaligned.h"
nm_copy_sd_shared "src/basic/alloc-util.c"
nm_copy_sd_shared "src/basic/alloc-util.h"
nm_copy_sd_shared "src/basic/async.h"
nm_copy_sd_shared "src/basic/env-file.c"
nm_copy_sd_shared "src/basic/env-file.h"
nm_copy_sd_shared "src/basic/env-util.c"
nm_copy_sd_shared "src/basic/env-util.h"
nm_copy_sd_shared "src/basic/errno-util.h"
nm_copy_sd_shared "src/basic/escape.c"
nm_copy_sd_shared "src/basic/escape.h"
nm_copy_sd_shared "src/basic/ether-addr-util.c"
nm_copy_sd_shared "src/basic/ether-addr-util.h"
nm_copy_sd_shared "src/basic/extract-word.c"
nm_copy_sd_shared "src/basic/extract-word.h"
nm_copy_sd_shared "src/basic/fd-util.c"
nm_copy_sd_shared "src/basic/fd-util.h"
nm_copy_sd_shared "src/basic/fileio.c"
nm_copy_sd_shared "src/basic/fileio.h"
nm_copy_sd_shared "src/basic/format-util.c"
nm_copy_sd_shared "src/basic/format-util.h"
nm_copy_sd_shared "src/basic/fs-util.c"
nm_copy_sd_shared "src/basic/fs-util.h"
nm_copy_sd_shared "src/basic/hash-funcs.c"
nm_copy_sd_shared "src/basic/hash-funcs.h"
nm_copy_sd_shared "src/basic/hashmap.c"
nm_copy_sd_shared "src/basic/hashmap.h"
nm_copy_sd_shared "src/basic/hexdecoct.c"
nm_copy_sd_shared "src/basic/hexdecoct.h"
nm_copy_sd_shared "src/basic/hostname-util.c"
nm_copy_sd_shared "src/basic/hostname-util.h"
nm_copy_sd_shared "src/basic/in-addr-util.c"
nm_copy_sd_shared "src/basic/in-addr-util.h"
nm_copy_sd_shared "src/basic/io-util.c"
nm_copy_sd_shared "src/basic/io-util.h"
nm_copy_sd_shared "src/basic/list.h"
nm_copy_sd_shared "src/basic/log.h"
nm_copy_sd_shared "src/basic/macro.h"
nm_copy_sd_shared "src/basic/memory-util.c"
nm_copy_sd_shared "src/basic/memory-util.h"
nm_copy_sd_shared "src/basic/mempool.c"
nm_copy_sd_shared "src/basic/mempool.h"
nm_copy_sd_shared "src/basic/missing_fcntl.h"
nm_copy_sd_shared "src/basic/missing_socket.h"
nm_copy_sd_shared "src/basic/missing_stat.h"
nm_copy_sd_shared "src/basic/missing_type.h"
nm_copy_sd_shared "src/basic/parse-util.c"
nm_copy_sd_shared "src/basic/parse-util.h"
nm_copy_sd_shared "src/basic/path-util.c"
nm_copy_sd_shared "src/basic/path-util.h"
nm_copy_sd_shared "src/basic/prioq.c"
nm_copy_sd_shared "src/basic/prioq.h"
nm_copy_sd_shared "src/basic/process-util.c"
nm_copy_sd_shared "src/basic/process-util.h"
nm_copy_sd_shared "src/basic/random-util.c"
nm_copy_sd_shared "src/basic/random-util.h"
nm_copy_sd_shared "src/basic/set.h"
nm_copy_sd_shared "src/basic/signal-util.h"
nm_copy_sd_shared "src/basic/siphash24.h"
nm_copy_sd_shared "src/basic/socket-util.c"
nm_copy_sd_shared "src/basic/socket-util.h"
nm_copy_sd_shared "src/basic/sort-util.h"
nm_copy_sd_shared "src/basic/sparse-endian.h"
nm_copy_sd_shared "src/basic/stat-util.c"
nm_copy_sd_shared "src/basic/stat-util.h"
nm_copy_sd_shared "src/basic/stdio-util.h"
nm_copy_sd_shared "src/basic/string-table.c"
nm_copy_sd_shared "src/basic/string-table.h"
nm_copy_sd_shared "src/basic/string-util.c"
nm_copy_sd_shared "src/basic/string-util.h"
nm_copy_sd_shared "src/basic/strv.c"
nm_copy_sd_shared "src/basic/strv.h"
nm_copy_sd_shared "src/basic/time-util.c"
nm_copy_sd_shared "src/basic/time-util.h"
nm_copy_sd_shared "src/basic/tmpfile-util.c"
nm_copy_sd_shared "src/basic/tmpfile-util.h"
nm_copy_sd_shared "src/basic/umask-util.h"
nm_copy_sd_shared "src/basic/utf8.c"
nm_copy_sd_shared "src/basic/utf8.h"
nm_copy_sd_shared "src/basic/util.c"
nm_copy_sd_shared "src/basic/util.h"
2019-07-04 18:13:17 +02:00
Thomas Haller
fe52a9467b shared: gracefully accept %NULL strings for NM_STR_HAS_PREFIX() and NM_STR_HAS_SUFFIX()
In case it wasn't obvious to a caller, allow %NULL as valid string
argument. Just be a bit more forgiving and fault-tolerant.
2019-07-04 17:11:24 +02:00
Thomas Haller
7c84227c93 shared: add nm_c_list_elem_free_steal() util 2019-07-02 17:52:53 +02:00
Thomas Haller
441dd1f3c8 libnm: add nm_connection_to_dbus_full() with options argument
No options are implemented yet.
2019-06-28 16:48:17 +02:00
Thomas Haller
b4fe51b5fa shared: add nm_utils_strv_dup() util 2019-06-28 16:48:17 +02:00
Thomas Haller
1d2df314cc shared: add nm_c_list_free_all() macro 2019-06-28 16:45:06 +02:00
Thomas Haller
b9587008fc shared: add nm_clear_error() and patch g_clear_error() to use this inlinable variant 2019-06-26 09:53:54 +02:00
Thomas Haller
03b8eb124e shared/glib: unconditionally redefine g_object_ref()/g_object_ref_sink() as typesafe macro 2019-06-26 09:53:54 +02:00
Thomas Haller
02ac5693d3 shared: add nm_utils_file_stat() util
A small convenience function to call stat(). The difference is that the
function returns an error code.
2019-06-26 09:53:54 +02:00
Thomas Haller
ec707f56c1 shared: add nm_utils_hashtable_same_keys() util 2019-06-26 09:53:54 +02:00
Thomas Haller
fcaf7994f2 shared: allow nm_c_list_move_*() API also to move from one list to another
Previously, nm_c_list_move_*() only allowed to move element inside the
same list. Relax that, it works just the same list to move the element
from one list into a different list.
2019-06-26 09:53:54 +02:00
Thomas Haller
f182d4fa20 shared/tests: add test for nm_utils_bin2hexstr_full() 2019-06-19 15:49:57 +02:00
Thomas Haller
637c785f4e shared: fix nm_utils_bin2hexstr_full() for buffers of length zero 2019-06-19 15:30:55 +02:00
Thomas Haller
1cc4a8b6a9 shared: add nm_utils_g_slist_strlist_cmp() util
Usually we avoid GSList, because I think it's not a great data type.
Anyway, our match-specs are just a GSList of strings, so we need some
API to handle them.
2019-06-17 12:12:02 +02:00
Lubomir Rintel
a26abc797c libnm-core: add ovs-dpdk setting 2019-06-14 12:10:20 +02:00
Thomas Haller
b1f5e971f3 shared: add nm_g_variant_ref_sink() util 2019-06-13 16:10:53 +02:00
Thomas Haller
5b721ba90d shared: add nm_c_list_elem_find_first() and minor cleanups of NMCListElem API 2019-06-13 16:10:53 +02:00
Thomas Haller
8b2d115f9d shared: add nm_utils_g_slist_find_str() util 2019-06-13 16:10:53 +02:00
Thomas Haller
87a73df959 all: drop empty first line from sources
git ls-files -z -- ':(exclude)src/settings/plugins/keyfile/tests/keyfiles' | xargs -0 -n1 sed -i '1 { /^$/d }'
2019-06-11 10:15:06 +02:00
Thomas Haller
c0e075c902 all: drop emacs file variables from source files
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.
2019-06-11 10:04:00 +02:00
Thomas Haller
98ec22d4be shared: add nmtst_get_rand_uint() helper 2019-06-11 08:25:10 +02:00
Thomas Haller
d7932ee5f1 tests/trivial: rename nmtst_get_rand_int() to nmtst_get_rand_uint32()
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.
2019-06-11 08:25:10 +02:00
Thomas Haller
7440c0c564 shared: use NM_MIN() in NM_CMP_FIELD_MEMCMP_LEN() macro
To avoid evaluating the argument more than once.
2019-06-11 08:25:10 +02:00
Thomas Haller
3d42b2f1fa shared: fix _NM_ENSURE_TYPE_CONST() for const pointers with clang
Clang 3.4.2-9.el7 on CentOS7.6 complains about missing generic type match:

    ../dispatcher/nm-dispatcher.c:243:2: error: controlling expression type 'const Request *const' (aka 'const struct Request *const') not compatible with any generic association type
            _LOG_R_D (request, "start running ordered scripts...");
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fixes: 17dc6a9da6 ('shared: add _NM_ENSURE_TYPE_CONST()')
2019-05-29 09:42:40 +02:00
Beniamino Galvani
d6a51ced40 ifcfg-rh: preserve existence of wired setting
Currently the plugin doesn't preserve the existence of a wired setting
because the writer saves only variables with non-default values and,
especially, the reader always creates the setting.

Fix this; now the writer writes HWADDR even if empty when the setting
is present; the reader creates the setting when at least one property
is found.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/166
https://bugzilla.redhat.com/show_bug.cgi?id=1703960
2019-05-28 09:53:00 +02:00
Thomas Haller
e1b824b871 shared: fix return in nm_value_type_to_variant()/nm_value_type_get_variant_type()
Fixes: 75703a2425 ('shared: add accessor functions for NMValueType')
2019-05-27 13:27:13 +02:00
Thomas Haller
17dc6a9da6 shared: add _NM_ENSURE_TYPE_CONST()
The sole purpose of this is more type-safe macros.

An alternative solution would be to define a function instead of a
macro. But if the function is unused (currently!) you get a compiler
warning (on some compilers even when marking the function as "static
inline", if it's in the source file). A workaround for that would be
to mark the function as _nm_unused, or to use a macro instead.

_NM_ENSURE_TYPE_CONST() is to aid the macro solution.
2019-05-27 12:01:09 +02:00
Tom Gundersen
e43b1791a3 Merge commit 'e23b3c9c3ac86b065eef002fa5c4321cc4a87df2' as 'shared/n-dhcp4'
Imported n-dhcp4 code with command:

  git subtree add --prefix shared/n-dhcp4/ git@github.com:nettools/n-dhcp4.git master --squash

To update the library use:

  git subtree pull --prefix shared/n-dhcp4/ git@github.com:nettools/n-dhcp4.git master --squash
2019-05-25 02:02:04 +02:00
Thomas Haller
e28bd1289b libnm: mark NMTeamLinkWatcher arguments as const in API
NMTeamLinkWatcher is immutable, meaning there is no way to change an
existing instance (aside increasing/decreasing the ref-count).

Hence, all API is implicitly const.

Still, mark the arguments as const.
2019-05-23 18:09:49 +02:00
Thomas Haller
b927287c7d shared/utils: add nmtst_assert_setting_dbus_roundtrip() util 2019-05-23 18:09:49 +02:00
Thomas Haller
892440c4ab shared/tests: add nmtst_assert_setting_is_equal() util 2019-05-23 18:09:49 +02:00
Thomas Haller
ae7f32e03b shared/tests: add nmtst_variant_from_string() util 2019-05-23 18:09:49 +02:00
Thomas Haller
5d3b033072 shared: add nm_utils_gvariant_vardict_filter*() helpers
Usually, such an operation does not make much sense. It's also not good
performance wise.

But for unit testing this becomes very interesting.
2019-05-23 18:09:49 +02:00
Thomas Haller
848a80598e shared: add JSON helper functions for NMValueType 2019-05-23 18:09:49 +02:00
Thomas Haller
75703a2425 shared: add accessor functions for NMValueType
"nm-value-type.h" is a header-only file, as it contains only small
accessors that should be inlined.

As such, the implementation of these functions is guarded by "#ifdef
NM_VALUE_TYPE_DEFINE_FUNCTIONS", so that one can use this header (and
NMValueType enum) with less overhead (at compile time).
2019-05-23 18:09:49 +02:00
Thomas Haller
e64fdeeaf6 shared: add "shared/nm-glib-aux/nm-value-type.h"
Glib has GValue which used for boxing value.

Add NMValueType enum, which has a similar purpose, but it's much more
limited.

- contrary to GValue, the type must be tracked separately from the
  user-data. That is, the "user-data" is only a pointer of appropriate
  type, and the knowledge of the actual NMValueType is kept separately.
  This will be used to have a static list of meta-data that knows the
  value types, but keeping the values independent of this type
  information. With GValue this would not be possible.

- the use case is much more limited. Just support basic integers,
  boolean and strings. Nothing fancy.

Note that we already do something similar at muliple places. See for
example NMVariantAttributeSpec and nm_utils_team_link_watcher_to_string().
These could/should instead use NMValueType.
2019-05-23 18:09:49 +02:00