Commit graph

150 commits

Author SHA1 Message Date
Thomas Haller
a7e1fa48fd
shared: add nm_g_variant_new_ay_inaddr() helper 2020-10-30 11:58:44 +01:00
Thomas Haller
6e44842dc6
shared: introduce opaque type NMUtilsUserData for nm_utils_user_data_pack()
This makes the usage slightly more type safe.
2020-10-22 17:38:08 +02:00
Thomas Haller
a9ffb5b73e
shared: enforce trailing semicolon after NM_UTILS_FLAGS2STR_DEFINE(),NM_UTILS_ENUM2STR_DEFINE() 2020-10-19 16:43:47 +02:00
Thomas Haller
8b25e4ecfe
shared: add nm_g_ptr_array_ref() and similar helpers 2020-10-13 13:39:01 +02:00
Thomas Haller
28bbe2a798
shared,platform: take pointer to NMEtherAddr in NM_ETHER_ADDR_FORMAT_VAL() macro
It seems nicer to require a pointer than the plain struct.
2020-10-13 12:56:25 +02:00
Thomas Haller
251ba8ea44
shared: automatically cast strv argument for nm_utils_strv_equal()/nm_utils_strv_cmp_n()
It's cumbersome if we always need to cast our arguments for
the strv helper functions. Depending on the situation, we often
have a "char **" or a "const char *const*" argument.

Use NM_CAST_STRV_CC() macros instead. This macro uses C11's _Generic()
and casts types that are presumed to be safe. This tends to be less
typing and more type-safe, because you don't need an explicit C cast
(which would overrule any warning that the compiler might have for you).
2020-10-12 22:20:01 +02:00
Thomas Haller
cbcfc58794
all/trivial: rename _nm_utils_strv_equal()/_nm_utils_strv_cmp_n() to have no leading underscore
The underscore somehow indicated that these would be an internal
function. Which they are in the sense that they are in "shared/nm-glib-aux/".
But they part of our internal helper functions, and in our code base
their use is no discouraged or "private.

Also, next I'll replace the function call with a macro, so, I will
have a need for the underscore name.

Rename.
2020-10-12 22:18:26 +02:00
Thomas Haller
3cab307fa7
shared: enforce trailing semicolon after NM_UTILS_STRING_TABLE_LOOKUP_DEFINE() 2020-10-08 17:01:26 +02:00
Thomas Haller
f7f979cda6
shared: add nm_ether_addr_to_string() helper 2020-10-01 17:35:14 +02:00
Thomas Haller
c36eedf4d8
shared: add ether_addr field of type NMEtherAddr to NMIPAddr union 2020-10-01 17:35:13 +02:00
Thomas Haller
d9ca728005
shared: add nm_ether_addr_cmp()/nm_ether_addr_equal() helpers 2020-09-30 09:49:20 +02:00
Thomas Haller
f37dd5d394
shared: move NM_CMP*() macros to "nm-std-aux.h"
I would need these macros earlier in "nm-glib-aux/nm-shared-utils.h",
so it would be sufficient to just move them.

However, when I already move them, move them to "nm-std-aux/nm-std-aux.h"
because they don't need a glib dependency.
2020-09-30 09:48:26 +02:00
Thomas Haller
88071abb43
all: unify comment style for SPDX-License-Identifier tag
Our coding style recommends C style comments (/* */) instead of C++
(//). Also, systemd (which we partly fork) uses C style comments for
the SPDX-License-Identifier.

Unify the style.

  $ sed -i '1 s#// SPDX-License-Identifier: \([^ ]\+\)$#/* SPDX-License-Identifier: \1 */#' -- $(git ls-files -- '*.[hc]' '*.[hc]pp')
2020-09-29 16:50:53 +02:00
Thomas Haller
740b092fda
format: replace tabs for indentation in code comments
sed -i \
     -e 's/^'$'\t'' \*/     */g' \
     -e 's/^'$'\t\t'' \*/         */g' \
     -e 's/^'$'\t\t\t'' \*/             */g' \
     -e 's/^'$'\t\t\t\t'' \*/                 */g' \
     -e 's/^'$'\t\t\t\t\t'' \*/                     */g' \
     -e 's/^'$'\t\t\t\t\t\t'' \*/                         */g' \
     -e 's/^'$'\t\t\t\t\t\t\t'' \*/                             */g' \
     $(git ls-files -- '*.[hc]')
2020-09-28 16:07:52 +02:00
Antonio Cardace
328fb90f3e
all: reformat all with new clang-format style
Run:

    ./contrib/scripts/nm-code-format.sh -i
    ./contrib/scripts/nm-code-format.sh -i

Yes, it needs to run twice because the first run doesn't yet produce the
final result.

Signed-off-by: Antonio Cardace <acardace@redhat.com>
2020-09-28 16:07:51 +02:00
Thomas Haller
39b52d0fd0
shared: add nm_utils_uid_to_name()/nm_utils_name_to_uid() helpers
These are inspired by systemd.

We should replace our calls to getpwuid() and getpwnam() with
their thread safe variants.

We run possibly multiple threads (e.g. helper threads from GDBus and
GResolver). It's hard to be sure that they don't also access the
functions.
2020-09-25 21:03:27 +02:00
Thomas Haller
dea59122e7
shared: move nm_utils_hwaddr_ntoa_buf() to shared/ as _nm_utils_hwaddr_ntoa()
The name is better as it mirrors nm_utils_hwaddr_aton(). Also, move
it to shared/ so it can be reused (and inlined).
2020-09-23 13:57:37 +02:00
Thomas Haller
74c03da086
shared: move _nm_utils_hwaddr_aton() to shared/
_nm_utils_hwaddr_aton() is only a wrapper around nm_utils_hexstr2bin_full().
But it abstracts the "right" parameters for what we consider a valid MAC
address and what not. As such, this function is useful.

Move it to "shared/" and replace the dupicate macro hwaddr_aton() with
it.
2020-09-23 13:57:04 +02:00
Thomas Haller
e8dd19bb01
shared: extend nm_utils_hexstr2bin_full() to require hexdigits in pairs
nm_utils_hexstr2bin_full() is our general hexstr to binary parsing
method. It uses (either mandatory or optional) delimiters. Before,
if delimiters are in use, it would accept individual hexdigits.
E.g. "a:b" would be accepted as "0a:0b:.

Add an argument that prevents accepting such single digits.
2020-09-22 17:40:41 +02:00
Thomas Haller
479de883b3
shared: add m_g_variant_singleton_u_0()
We anyway cache our variants for the properties of NMDBusObject instances.
If such a variant is well known to be always the same, there is no need
to allocate a new instance every time. In particular, because GVariant
is an immutable and ref counted type.

Add a singleton getter for a "u" variant with numeric value 0.
2020-09-18 15:26:37 +02:00
Thomas Haller
348ab39f6d
shared: add nm_utils_hashtable_{equal,cmp}() helper function 2020-09-11 10:45:40 +02:00
Thomas Haller
ff37c961ff
shared: fix out of bounds for nm_g_array_append_new() macro
Fixes: fb6e9795b7 ('shared: add nm_g_array_append_new() helper')
2020-09-11 10:45:40 +02:00
Thomas Haller
aed61588fd
shared: add nm_utils_bin2hexstr_a() macro 2020-09-03 11:39:39 +02:00
Thomas Haller
265a5879ae
shared: add nm_g_timeout_source_new_seconds() 2020-09-03 11:39:39 +02:00
Thomas Haller
fc66ad70d5
shared: add nm_g_hash_table_contains() helper 2020-09-03 11:39:39 +02:00
Beniamino Galvani
418d20acc9 shared: add nm_strvarray_remove_first()
Co-authored-by: Thomas Haller <thaller@redhat.com>
2020-08-26 17:08:00 +02:00
Thomas Haller
2e0cd52474
shared: add nm_utils_strv_dup_packed() util 2020-08-25 09:54:11 +02:00
Thomas Haller
c25f4d947a
shared: enforce compatible C-type argument for nm_utils_strv_dup()
Use a macro that uses NM_CAST_STRV_CC() to cast the strv argument. Note that
NM_CAST_STRV_CC() uses C11's _Generic() to check whether the argument is
of a valid type.
2020-08-25 08:54:36 +02:00
Beniamino Galvani
8113069062 shared: add nm_is_ascii()
glib's is{alnum,alpha,ascii,...}() functions perform the check based
on the current locale. Probably using isascii() would be fine anyway,
but add a NM version that just checks that the upper bit is zero.
2020-08-24 16:51:53 +02:00
Sayed Shah
f5db085cd3 shared: add a struct and definition for MAC address
This is a shared util which adds an array of 6 bytes and also add define statements
for how to format the MAC address
2020-08-20 13:27:32 -04:00
Thomas Haller
5da502a1e1
shared,core: extend nm_utils_is_specific_hostname() and move to shared
nm_utils_is_specific_hostname() is basically to check whether the
hostname is localhost (and also handle "(null)").

In that sense, it's similar to systemd's is_localhost(). Extend or
variant to

  - be case insensitive (like is_localhost()).

  - accept more variants of localhost/localdomain names as special.
2020-08-05 12:47:55 +02:00
Thomas Haller
00c6823ecc
shared: add nm_strcmp_ascii_case_with_data() helper 2020-08-05 10:22:11 +02:00
Thomas Haller
3c846baa83
shared: add nm_strv_ptrarray_get_unsafe() helper
It's called "unsafe" because the returned pointer array is not
NULL terminated. This is due to a limitation of GPtrArray which
doesn't support that. If you want a NULL terminated strv array,
use a GArray based API, like nm_strvarray_*().
2020-08-05 10:22:10 +02:00
Thomas Haller
443859f71f
shared: add NM_CMP_DIRECT_UNSAFE() macro 2020-07-31 08:53:04 +02:00
Thomas Haller
d550eef02d
shared: add nm_strv_ptrarray_cmp() helper 2020-07-31 08:53:03 +02:00
Thomas Haller
684b0ec061
shared: add nm_g_ptr_array_pdata() helper 2020-07-31 08:53:03 +02:00
Thomas Haller
a8517423c7
shared: add nm_strv_ptrarray_clone() helper 2020-07-24 16:03:15 +02:00
Thomas Haller
c470cbf705
shared: add nm_copy_func_g_strdup() helper 2020-07-24 16:03:15 +02:00
Thomas Haller
66d4af6daf
shared: add compat function nm_g_ptr_array_copy() for older glib
This is not in "nm-glib.h", because it's not a complete replacement.
In glib before 2.62, it's not possible to implement g_ptr_array_copy()
as glib provides it, because the element_free_func is not accessible.

So, instead add our own implemented, which follows glib's version as
much as it can.
2020-07-24 16:03:15 +02:00
Thomas Haller
fb6e9795b7
shared: add nm_g_array_append_new() helper 2020-07-23 15:29:23 +02:00
Thomas Haller
99296d4c6c
shared: add nm_strv_ptrarray_ensure() and nm_strv_ptrarray_find_first() helpers 2020-07-23 15:29:23 +02:00
Thomas Haller
56a0aa06ac
shared: move addr-family helpers to "nm-std-aux.h"
Handling address families is something we do all over the place.
Move some simple helper code to "nm-std-aux.h".
2020-07-23 15:29:23 +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
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
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
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
220825836a
shared: move nm_utils_get_next_realloc_size() to nm-std-aux 2020-07-06 14:11:22 +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
a5a5656582
shared: add nm_utils_escaped_tokens_escape_unnecessary() util 2020-06-26 09:29:53 +02:00
Thomas Haller
069be33fbd
shared: add nm_hexchar() helper 2020-06-26 09:29:52 +02:00