summaryrefslogtreecommitdiff
path: root/shared/nm-utils
Commit message (Collapse)AuthorAgeFilesLines
* shared: trigger -Wenum-conversion warning in NM_IN_SET*() macrosThomas Haller2017-03-161-6/+19
| | | | | and add NM_IN_SET*_TYPED() macros, which allow to explicitly select the type of "x".
* shared/trivial: minor style fixes in "nm-utils/nm-macros-internal.h"Thomas Haller2017-03-161-4/+6
|
* all: use "static inline" instead of "inline static"Thomas Haller2017-03-141-4/+4
|
* shared: add _NM_GET_PRIVATE_VOID() macroThomas Haller2017-03-101-1/+19
| | | | | | | | | | _NM_GET_PRIVATE() macro is used to implement a standard private-getter, but it requires that "self" is a pointer of either "const type *" or "type *". That is great in most cases, but sometimes we have predominatly self pointers of different type, so it would require a lot of casts. Add a different form _NM_GET_PRIVATE_VOID() where self pointer can be any non-const pointer and returns a non-const private pointer after casting.
* shared: add test utilities for IP routesBeniamino Galvani2017-03-061-0/+45
| | | | Add utility functions to check the value of a route attribute.
* all: use "static inline" keywords instead of "inline static"Thomas Haller2017-02-232-57/+57
| | | | | Use a consistent order of "static inline". This seems the prefered order in general, and we also use it more often already.
* shared: cleanup nm_strquote_a() and nm_sprintf_bufa()Thomas Haller2017-02-101-28/+25
| | | | | | | | - simplify nm_strquote_a(). - use '"' for quoting instad of '\''. - have nm_sprintf_bufa() evalute @n_elements only once.
* all: use NM_CACHED_QUARK_FCN() instead of G_DEFINE_QUARK()Thomas Haller2017-02-101-1/+1
| | | | | | | | | | | | | | | | | | I think NM_CACHED_QUARK_FCN() is better because: - the implementation is in our hand, meaning it is clear that putting a "static" before NM_CACHED_QUARK_FCN() is guaranteed to work -- without relying on G_DEFINE_QUARK() to be defined in a way that this works (in fact, we currently never do that and instead make all functions non-static). - it does not construct function names by appending "_quark". Thus you can grep for the entire function name and finding the place where it is implemented. - same with the stings, where the new macro doesn't stringify the argument, which is less surpising. Again, now you can grep for the string including the double quoting. (yes, I really use grep to understand the source-code)
* shared: add NM_CACHED_QUARK() and NM_CACHED_QUARK_FCN() macrosThomas Haller2017-02-101-0/+34
| | | | | | | | | | | | NM_CACHED_QUARK_FCN() is a replacement for G_DEFINE_QUARK(). G_DEFINE_QUARK() is mostly used to define GError quarks. As such, it always appends _quark() to the function name, which is unfavorable because it makes it harder to grep for the definition of the function. In general I think that macros that defined symbols by concatenating something should be avoided because that makes it harder to locate where the symbol was defined.
* shared: fix -Wtype-limits warning in nm_glib_check_version() macroThomas Haller2017-02-061-8/+11
| | | | | | | | | | | | | | | | | | | | Fix it by converting the macro to an inline function. It's anyway nicer. $ make src/src_libNetworkManagerBase_la-main-utils.lo CC src/src_libNetworkManagerBase_la-main-utils.lo In file included from ./shared/nm-utils/nm-macros-internal.h:29:0, from ./shared/nm-default.h:178, from src/main-utils.c:22: src/main-utils.c: In function ‘nm_main_utils_setup_signals’: ./shared/nm-utils/nm-glib.h:144:36: error: comparison of unsigned expression >= 0 is always true [-Werror=type-limits] && glib_micro_version >= (micro)))) ^ src/main-utils.c:82:6: note: in expansion of macro ‘nm_glib_check_version’ if (nm_glib_check_version (2, 36, 0)) { ^~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors Makefile:12312: recipe for target 'src/src_libNetworkManagerBase_la-main-utils.lo' failed
* shared: add nm_utils_strv_find_first() helperThomas Haller2017-02-042-0/+52
| | | | | Make _nm_utils_strv_find_first() accessible outside of libnm-core by copying it from "libnm-core/nm-core-internal.h" (and rename it).
* shared/tests: add nmtst_rand_perm_gslist() helperThomas Haller2017-01-201-0/+25
| | | | (cherry picked from commit 7b84c73331ef5642e3717e2333865c70e2244def)
* shared: add nm_offsetofend() macroThomas Haller2017-01-161-0/+2
|
* shared: add nm_str_realloc()Thomas Haller2017-01-091-0/+19
|
* shared: move nm_utils_strbuf_*() helper to shared/nm-utilsThomas Haller2017-01-052-0/+98
|
* shared: add nm_str_skip_leading_spaces() macroThomas Haller2016-12-251-0/+12
|
* libnm: add public macro NM_VERSION for the current build-time version of libnmThomas Haller2016-12-201-0/+1
|
* shared: add NM_AUTO_PROTECT_ERRNOThomas Haller2016-12-131-0/+7
| | | | | | | | | | | Similar to systemd's PROTECT_ERRNO. The difference it, that it doesn't treat the auto-variable as internal, so it is allowed to use it. E.g. if (!(fd = open (...)) { NM_AUTO_PROTECT_ERRNO (errno_saved); printf ("error: %s", g_strerror (errno_saved)); return FALSE; }
* shared: add nm_auto_close and nm_auto_fcloseThomas Haller2016-12-131-0/+26
| | | | | | | | We already have gs_fd_close, which however doesn't preserve errno and only checks for fd != -1. Add our own define. Downside is, we have to include stdio.h and errno.h, which effectively ends up to be included *everywhere*.
* shared: add nmtst_auto_unlinkfile cleanup macroThomas Haller2016-11-091-0/+42
|
* shared: add nmtst_file_get_contents()Thomas Haller2016-11-091-0/+14
|
* shared: add NM_STRCHAR_ALL() and NM_STRCHAR_ANY() macrosThomas Haller2016-11-091-0/+46
|
* shared: minor cleanup in _nm_utils_ascii_str_to_int64() using const pointerThomas Haller2016-11-021-2/+2
|
* shared: add nm_assert_se() macroThomas Haller2016-10-281-0/+2
| | | | | | | | We usually don't build NM with g_assert() disabled (G_DISABLE_ASSERT). But even if we would, there is no assertion macro that always evaluates the condition for possible side effects. I think that is a useful thing to have.
* shared: make nm_str_not_empty() inline function instead of macroThomas Haller2016-10-241-7/+5
| | | | | | | | | | | | | | | | | | | | | | It was a macro to pass on the non-const-ness of the argument, but that just doesn't make sense. That is a signature char *nm_str_not_empty (char *) does not make sense, because you cannot transfer ownership conditionally without additional checks to avoid a leak. Which makes this form is pointless. For example: char * foo (void) { char *s; s = _create_value (); return nm_str_not_empty (s); /* leaks "" */ }
* shared: add unaligned.hBeniamino Galvani2016-10-141-0/+129
| | | | | The file, imported from systemd sources, contains macros for accessing potentially unaligned data in a safe way (i.e. byte-wise).
* shared: re-define _G_BOOLEAN_EXPR() to allow nesting g_assert()Thomas Haller2016-10-111-0/+27
| | | | | | | | | | | | | g_assert() uses G_LIKELY(), which in turn uses _G_BOOLEAN_EXPR(). As glib's version of _G_BOOLEAN_EXPR() uses a local variable _g_boolean_var_, we cannot nest a G_LIKELY() inside a G_LIKELY(), or inside a g_assert(), or a g_assert() inside a g_assert(). Workaround that, by redefining the macro. I already encountered this problem before, when having a nm_assert() inside a ({...}) block, inside a g_assert(). Then I just avoided that combination, but this situation is quite easy to encounter.
* shared: add NM_DECIMAL_STR_MAX() macroThomas Haller2016-10-111-0/+14
|
* shared: assert against buffer length in nm_sprintf_buf()Thomas Haller2016-10-111-4/+8
|
* shared: add NMTST_UUID_INIT() macroThomas Haller2016-10-051-0/+4
|
* shared: add nm_clear_g_free()Thomas Haller2016-10-031-0/+21
|
* all: modify line separator comments to be 80 chars wideThomas Haller2016-10-033-17/+17
| | | | sed 's#^/\*\{5\}\*\+/$#/*****************************************************************************/#' $(git grep -l '\*\{5\}' | grep '\.[hc]$') -i
* shared: add test for NM_SET_OUT()Thomas Haller2016-09-261-0/+5
|
* core: add _nm_utils_array_find_binary_search()Thomas Haller2016-09-231-0/+13
| | | | Also add nm_cmp_uint32_p_with_data(). Will be used later.
* macros: simplify NM_IN_SET() and NM_IN_STRSET() macrosThomas Haller2016-09-221-78/+36
| | | | and support up to 16 arguments.
* shared: add nm_utils_syslog_coerce_from_nm() utilThomas Haller2016-09-191-0/+32
| | | | | | | | When a VPN plugin logs to syslog(), it should not use the syslog levels that were passed in by NetworkManager directly. Instead, it must map LOG_NOTICE to LOG_INFO and LOG_INFO to LOG_DEBUG. Add a utility function does gets that right.
* shared: add _NM_GET_PRIVATE() macroThomas Haller2016-09-081-0/+18
|
* shared: add NM_MIN()/NM_MAX() macros to replace glib's MIN()/MAX()Thomas Haller2016-09-081-0/+44
|
* shared: add helper macros nm_str_not_empty() and nm_strdup_not_empty()Thomas Haller2016-09-061-0/+16
|
* nm-glib.h: fix compatibility wrapper for g_variant_new_take_string()Thomas Haller2016-08-111-1/+10
| | | | | g_variant_new_from_bytes() is itself only available since 2.36, thus using it triggers a deprecation warning itself.
* nm-glib: add compatibility wrapper for g_variant_new_take_string()Thomas Haller2016-08-111-0/+23
|
* shared: add NM_VPN_PLUGIN_CONFIG_PROXY_PAC to "nm-vpn-plugin-macros.h" for ↵Thomas Haller2016-07-061-0/+4
| | | | | | | | | | | | | | | | VPN plugins Soon we will add proxy support where VPN plugins set a property NM_VPN_PLUGIN_CONFIG_PROXY_PAC. All a VPN plugin needs to make use of this new setting is the NM_VPN_PLUGIN_CONFIG_PROXY_PAC define. We don't want that older plugins (still compatible with libnm 1.2 API) require a new API only for this define. Define it instead in "shared/nm-utils/nm-vpn-plugin-macros.h" as fallback. https://mail.gnome.org/archives/networkmanager-list/2016-June/msg00154.html
* shared: add nm_strquote_a() helperThomas Haller2016-07-051-0/+29
|
* vpn: support option to preserve previous routing information on VPN config ↵Thomas Haller2016-07-041-0/+14
| | | | | | | | | | | | | | update On openvpn restart, the VPN helper script is invoked without full routing information. Thus, the routes will be dropped because the helper script cannot provide them on update. Add an option "preserve-route" which tells NetworkManager to preserve and reuse the previous configuration. https://bugzilla.redhat.com/show_bug.cgi?id=1231338 https://bugzilla.gnome.org/show_bug.cgi?id=750873
* dns: log DNS servers at TRACE levelBeniamino Galvani2016-06-281-0/+8
| | | | | | | Be more verbose at TRACE level and log the DNS servers associated to configurations. This will help to debug issues like [0]. [0] https://bugzilla.redhat.com/show_bug.cgi?id=1348887
* nm-glib: implement compatibility macro for g_strv_contains() differentlyThomas Haller2016-06-171-14/+7
| | | | | | Otherwise, deprecation warnings are not properly suppressed for g_return_if_fail (g_strv_contains (strv, str));
* nm-glib: remove G_GNUC_EXTENSIONThomas Haller2016-06-171-6/+6
| | | | | | | We use statement expressions all over the place without explicitly marking them. If that would be a problem, we'd have to change a *lot* of code. We simply require that as a mandatory feature from our compiler.
* shared: backport g_strv_contains()Lubomir Rintel2016-06-171-0/+30
|
* shared: add also "shared/nm-utils/nm-vpn-plugin-macros.h"Thomas Haller2016-06-161-0/+43
| | | | | It has the very similar purpose as "nm-utils/nm-vpn-plugin-utils.[ch]", except that is is header-only.
* tests: fix checking NM_ASSERT_NO_MSG define in "nm-test-utils.h"Thomas Haller2016-06-161-1/+1
| | | | | "nm-test-utils.h" may also be used by the VPN plugins, there we have no NM_ASSERT_NO_MSG define.