Commit graph

1158 commits

Author SHA1 Message Date
Thomas Haller
ba42189bb9
all: add trailing semicolon to NM_UTILS_LOOKUP_DEFINE()/NM_GOBJECT_PROPERTIES_DEFINE*() 2020-07-19 12:12:58 +02:00
Thomas Haller
b17e3cf707
all: add trailing semicolon to NM_AUTO_DEFINE_FCN_*() uses 2020-07-19 12:01:56 +02:00
Thomas Haller
8bd2673484
shared: add _NM_DUMMY_STRUCT_FOR_TRAILING_SEMICOLON define
Will be used next.
2020-07-19 11:37:23 +02:00
Thomas Haller
e4877b9ca2
shared: make nm_utils_strdup_reset() self-assignment safe
There is no need to write code that has such trivial flaws.

  val = g_strdup ("aaaa");
  nm_utils_strdup_reset (&val, &val[1]);
2020-07-19 11:31:17 +02:00
Thomas Haller
4168c19e04
shared: move nm_close(), nm_auto_close, nm_steal_fd(), nm_steal_int() to nm-std-aux 2020-07-12 13:05:13 +02:00
Thomas Haller
f78e0bf246
shared: assert that nm_utils_strsplit_set_full() returns non-empty strv array 2020-07-10 13:12:40 +02:00
Thomas Haller
ca7bb15591
shared: cleanup dlopening libjansson depending on configure options
- assert that WITH_JANSSON and JANSSON_SONAME are defined consistently.
  This check ensures that we can check at compile time that nm_json_vt()
  will always fail (because JANSSON_SONAME) is undefined.
  That is interesting, because this means you can do a compile time
  for !WITH_JANSSON, and know if nm_json_vt() will *never* succeed.
  With that, we could let the linker know when the code is unused
  and remove all uses of nm_json_vt(), without using the traditional
  conditional compilation with "#if WITH_JANSSON". But of course, we
  currently don't do this micro optimization to remove defunct code.

- drop the "mode" helper variable and pass the flags directly to
  dlopen().
2020-07-09 12:57:15 +02:00
Thomas Haller
18692faa9f
shared: drop unused code from "shared/nm-glib-aux/nm-jansson.h" 2020-07-09 12:57:15 +02:00
Thomas Haller
7054b11328
all: bump libjansson dependency to 2.7
jansson 2.7 was released October 2014. It's also in Ubuntu 16.06.
Other distros (like CentOS 7.5 and Debian Stretch/9) have both newer
versions.

Bump the requirement, simply because our CI does not use such old version
so it's not clear whether it works at all.
2020-07-09 12:57:15 +02:00
Thomas Haller
ae5e8fc26b
shared/tests: add test for checking "nm-json-aux.h"
Our "nm-json-aux.h" redefines various things from <jansson.h> header.

Add a unit test that checks that what we redefine exactly matches what
libjansson would provide, so that they are compatible.
2020-07-09 12:57:15 +02:00
Thomas Haller
57de0c27a7
shared,libnm: rename nm_json_aux_gstr_*() API to nm_json_gstr_*() 2020-07-09 11:47:06 +02:00
Thomas Haller
4a7da1ca4b
shared: merge nm-glib-aux/nm-json.[hc] into nm-json-aux.[hc]
They serve a similar purpose.

Previously, nm-json-aux.h contained the virtual function table for accessing
the dynamically loaded libjansson. But there is no reason why our own
helper functions from nm-json.h cannot be there too.
2020-07-09 11:47:06 +02:00
Thomas Haller
3814467b88
libnm,shared: move nm-json.[hc] to shared/nm-glib-aux
nm-json.[hc] uses libjansson, but only loads it at runtime with dlopen. There
is no more run compile time dependency. Move it to shared, so that it can be
(theoretically) used by other components.

Also, drop the conditional compilation. Granted, if you don't build with
libjansson enabled, then the JANSSON_SONAME define is unset and the code
will fail to load at runtime (which is fine). However, we can still build
against our JSON wrappers. The code savings of conditional build are minimal
so drop it.
2020-07-09 11:47:05 +02:00
Beniamino Galvani
4599be093e libnm-core: don't print value for no-value attributes 2020-07-08 09:43:06 +02:00
Beniamino Galvani
ee946ca27d libnm-core: pass variant-attribute-spec to format function
The output of nm_utils_format_variant_attributes() must be accepted by
nm_utils_parse_variant_attributes(), producing the initial attributes.

The latter has a special handling of some attributes, depending on the
input NMVariantAttributeSpec list. For example, if the
NMVariantAttributeSpec is a boolean with the 'no_value' flag, the
parser doesn't look for a value.

Pass the NMVariantAttributeSpec list to the format function so that it
can behave in the same way as the parse one.
2020-07-08 09:43:06 +02:00
Thomas Haller
6feab75447
shared: add nm_steal_pointer()/nm_clear_free() to "nm-std-aux.h"
There is the team of nm_auto*, nm_clear_pointer() and nm_steal_pointer().
These goes nicely together so that an autovariable owns a resource,
to free it (clear) and to transfer ownership (steal).

We have these also in glib, but we certainly also need it if we don't
have glib because that very much goes together with nm_auto*. Add it.
2020-07-07 22:32:35 +02:00
Thomas Haller
1d6e208c12
shared: move NM_AUTO_DEFINE_FCN*(), nm_auto_free and nm_clear_pointer() to "nm-std-aux.h" 2020-07-07 22:25:42 +02:00
Thomas Haller
4b63297d95
shared: drop definitions for bool/true/false from "nm-macros-internal.h"
Previously, we did not have a hard dependency on C99. Nowadays, we
actually build against C11, so we have <stdbool.h>. These definitions
are no longer necessary nor do we care about building against plain
C89.
2020-07-07 22:25:42 +02:00
Thomas Haller
1b9001f867
shared: include <stdbool.h> in "nm-std-aux.h" and fix glib-ism
For a long time already we build with gnu11/C11. We thus rely on having
<stdbool.h> around, which is C99. Use it.

Also fix "nm-std-aux.h" to not use TRUE/FALSE glib defines.
2020-07-07 22:25:19 +02:00
Thomas Haller
3b80c6c28f
shared: make NM_BOOLEAN_EXPR() macro composable and use it for _G_BOOLEAN_EXPR()
We redefine _G_BOOLEAN_EXPR(), so let it use NM_BOOLEAN_EXPR().

Also, we use G_LIKELY() (and thus NM_BOOLEAN_EXPR()) inside nm_assert(),
and we use nm_assert() in some macros. To be able to nest nm_assert()
calls, we need to create unique variable names for NM_BOOLEAN_EXPR().
2020-07-07 21:52:22 +02:00
Thomas Haller
f0deb24249
shared: move various basic helpers from "nm-macros-internal.h" to "nm-std-aux.h"
These are generally useful and independent of glib. Move them to
nm-std-aux, which has no glib dependency.
2020-07-07 21:33:25 +02:00
Yuri Chornoivan
4e33f8cd89
all: fix minor typos
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/565
2020-07-07 11:33:46 +02:00
Thomas Haller
4c52c69d66
nettools: reimport nettools' n-dhcp4
git subtree pull --prefix shared/n-dhcp4/ git@github.com:nettools/n-dhcp4.git master --squash
2020-07-07 11:15:26 +02:00
Thomas Haller
b9e458b184
shared: add NM_N_ELEMENTS() macro 2020-07-06 14:11:23 +02:00
Thomas Haller
d407c1271c
shared: move NM_SET_OUT() to "nm-std-aux.h" 2020-07-06 14:11:22 +02:00
Thomas Haller
220825836a
shared: move nm_utils_get_next_realloc_size() to nm-std-aux 2020-07-06 14:11:22 +02:00
Thomas Haller
19613016e2
shared: add "nm-std-aux/nm-std-utils.[hc]"
General purpose utilities for nm-std-aux. Contrary to
"nm-std-aux.h", this is not header only.
2020-07-06 14:11:22 +02:00
Thomas Haller
b109d63376
shared: add min/max macros to "nm-std-aux.h" 2020-07-06 11:45:37 +02:00
Thomas Haller
5361317f68
shared: add macros for declaration attribute to "nm-std-aux.h" 2020-07-06 11:45:37 +02:00
Thomas Haller
030d68aef7
shared: add nm_assert() to "nm-std-aux.h"
Having assertion macros that are disabled by default, is not
only useful for our glib code, but should also be available
for nm-std-aux. Move the macros.
2020-07-06 11:45:37 +02:00
Thomas Haller
5dd923cd86
shared: add "nm-std-aux/nm-std-aux.h" header
"nm-std-aux" is an utility library that has no glib depdencency. That
is the difference to "nm-glib-aux".
2020-07-06 11:10:43 +02:00
Sayed Shah
7337ab8959
all: fix typo in man pages
There should be a comma after 'Otherwise' and 'Currently'.

https://bugzilla.redhat.com/show_bug.cgi?id=1852452

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/560
2020-07-03 10:48:04 +02:00
Thomas Haller
e2bd722358
shared: refactor nm_utils_parse_next_line() and add tests
- add unit test for nm_utils_parse_next_line()

- as line delimiter also accept "\r\n" and "\r" (beside "\n", "\0" and
  EOF).

- fix returning lines with embedded "\0" characters. The line ends
  on the first "\n" or "\0", whatever comes first. The code before
  didn't ensure that with:

     line_end = memchr (line_start, '\n', *inout_len);
     if (!line_end)
         line_end = memchr (line_start, '\0', *inout_len);
2020-07-03 10:34:27 +02:00
Thomas Haller
e7357419cd
shared: add nm_str_buf_finalize_to_gbytes() helper 2020-07-03 10:34:26 +02:00
Beniamino Galvani
edf7003660
version: add 1.28 macros 2020-06-30 11:29:04 +02:00
Antonio Cardace
aa5959a595
nm-shared-utils: add util to parse out lines from a string
https://bugzilla.redhat.com/show_bug.cgi?id=1821787
2020-06-26 16:47:56 +02:00
Thomas Haller
45b346554a
shared: add nm_str_buf_reset() helper 2020-06-26 09:29:53 +02:00
Thomas Haller
d83908b6a1
shared: add nm_utils_escaped_tokens_escape_strbuf*() helpers 2020-06-26 09:29:53 +02:00
Thomas Haller
a5a5656582
shared: add nm_utils_escaped_tokens_escape_unnecessary() util 2020-06-26 09:29:53 +02:00
Thomas Haller
5222f1b5ff
shared: add nm_str_buf_append_required_delimiter() 2020-06-26 09:29:52 +02:00
Thomas Haller
85e27b1f9c
shared: add nm_str_buf_append_c_hex() helper 2020-06-26 09:29:52 +02:00
Thomas Haller
069be33fbd
shared: add nm_hexchar() helper 2020-06-26 09:29:52 +02:00
Thomas Haller
d53abfd989
shared: add nm_str_buf_append0() and nm_str_buf_append_len0() helper
These are basically nm_str_buf_append()/nm_str_buf_append_len() and
nm_str_buf_get_str() in one.
2020-06-26 09:29:52 +02:00
Thomas Haller
506f95ecaf
shared: add NM_UTILS_GET_NEXT_REALLOC_SIZE_32 and _40 macros 2020-06-26 09:29:51 +02:00
Thomas Haller
de4df9f529
shared: return non-const pointer from nm_str_buf_get_str()
It's more convenient in certain cases. The user is allowed
to modified the content of the returned buffer.
2020-06-26 09:29:51 +02:00
Thomas Haller
081650eb67
shared: avoid copying empty string in nm_str_buf_append_printf() 2020-06-25 22:46:27 +02:00
Thomas Haller
10779d545a
shared: add nm_utils_strsplit_quoted()
We want to parse "/proc/cmdline". That is space separated with support
for quoting and escaping. Our implementation becomes part of stable
behavior, and we should interpret the kernel command line the same way
as the system does. That means, our implementation should match
systemd's.
2020-06-23 00:42:37 +02:00
Thomas Haller
2a6ecf2128
tests: add nmtst_extract_first_word_all() for testing
We usually don't want to use internal API of systemd for our own
purposes. Here, we will use it to check our implementation against
systemd's. Add an accessor to extract_first_word() for testing.
2020-06-22 23:09:05 +02:00
Thomas Haller
a2142e884b
shared: add nm_str_buf_append_c_repeated() helper 2020-06-22 21:33:59 +02:00
Thomas Haller
c6809df4cd
shared: make NM_STR_BUF_INIT() an inline function
In the previous form, NM_STR_BUF_INIT() was a macro. That makes sense,
however it's not really possible to make that a macro without evaluating
the reservation length multiple times. That means,

    NMStrBuf strbuf = NM_STR_BUF_INIT (nmtst_get_rand_uint32 () % 100, FALSE);

leads to a crash. That is unfortunate, so instead make it an inline
function that returns a NMStrBut struct. Usually, we avoid functions
that returns structs, but here we do it.
2020-06-22 21:20:03 +02:00