Commit graph

139 commits

Author SHA1 Message Date
Thomas Haller 1b9d60f985 nm-glib: remove G_GNUC_EXTENSION
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.
2016-06-17 12:25:15 +02:00
Lubomir Rintel 45d6baac4d shared: backport g_strv_contains() 2016-06-17 12:22:37 +02:00
Thomas Haller af507cd089 shared: add also "shared/nm-utils/nm-vpn-plugin-macros.h"
It has the very similar purpose as "nm-utils/nm-vpn-plugin-utils.[ch]", except
that is is header-only.
2016-06-16 18:06:16 +02:00
Thomas Haller 89d32944af tests: fix checking NM_ASSERT_NO_MSG define in "nm-test-utils.h"
"nm-test-utils.h" may also be used by the VPN plugins, there
we have no NM_ASSERT_NO_MSG define.
2016-06-16 11:04:51 +02:00
Thomas Haller 3bcec4067f shared: include "nm-glib.h" from "nm-macros-internal.h"
"nm-glib.h" is our most basic header. "nm-macros-internal.h" extends
on that. Thus, let "nm-macros-internal.h" include "nm-glib.h".
2016-06-16 10:45:54 +02:00
Thomas Haller 037462e902 shared: include "gsystem-local-alloc.h" from "nm-glib.h"
"nm-glib.h" is the most basic header, the one we cannot do without.
("nm-default.h", is already more generic, the one which every common
source file in NetworkManager repository should include).

Let "gsystem-local-alloc.h" be included by "nm-glib.h" and nowhere
else.
2016-06-16 10:45:54 +02:00
Thomas Haller 5d55492bac shared: add "nm-utils/nm-vpn-plugin-utils.h"
This file is only used by plugins and copied between them.

It's purpose is to contain general utility functions that are
only relevant for implementing NetworkManager's VPN plugins.

In principle the utility functions could be part of libnm, however,
there are a few problems with that:
  - if they are part of libnm, adding and using a new utility function
    requires the plugin to bump the required libnm version. Since you
    usally can work around/reimplement utility functions, this results
    in not using the API from libnm, not adding the API to libnm,
    and reimplementing it over and over in the plugin.
  - plugins compile both against libnm and libnm-glib. Thus, either
    the utility function would also be needed in libnm-glib, or again,
    it is not usable by the plugin.

We must avoid that the utility functions diverge and no local
modifications to these files should be made in the plugin.
Instead, one special location of the utility functions shall be
extended and re-imported (copied) to the plugin as needed.

Add the files to NetworkManager's repository. Although they are not
needed for NetworkManager itself, they are a different API provided
by NetworkManager. An API that is reused and shared by copying the files
around.
2016-06-16 10:45:54 +02:00
Thomas Haller 4b288136e1 shared: move shared files to subdirectory "shared/nm-utils/"
The "shared" directory contains files that are possibly used by all components
of NetworkManager repository.

Some of these files are even copied as-is to other projects (VPN plugins, nm-applet)
and used there without modification. Move those files to a separate directory.
By moving them to a common directory, it is clearer that they belong
together. Also, you can easier compare the copied versions to their
original via

  $ diff -r ./shared/nm-utils/ /path/to/nm-vpn-plugin/shared/nm-utils/
2016-06-16 10:45:53 +02:00
Thomas Haller cf34211c90 libnm/vpn: add nm_vpn_editor_plugin_load_vt()
Let VPN plugins return a virtual function table to extend
the API while bypassing libnm. This allows to add and use
new functionality to VPN plugins without updating libnm.

The actual definitions are in a header-only file
"nm-vpn-editor-plugin-call.h", which can be copied to the
caller/plugin.
2016-06-15 15:01:12 +02:00
Thomas Haller e108f1cfaf shared: add nm_strcmp_p() utils macro 2016-06-15 10:32:31 +02:00
Thomas Haller 00f58adb16 build: remove assertion messages in non-debug build
Assertions like g_assert*() and g_return_*() contain the stringified
test expression. This string ends up in the binary and increases its
size.

We usually don't have failing assertions. These string are a waste,
instead the file and line number shall suffice.

It reduces the striped size of the NetworkManager binary from 2500k
to 2392k, that is -108k, -4.3%.

This changes

 - "g_assert (1 == 2);"
   from: NetworkManager:ERROR:source.c:347:some_function: assertion failed: (1 == 2)
   to:   NetworkManager:ERROR:source.c:347:<unknown-fcn>: assertion failed: (<dropped>)

 - "g_return_if_fail (1 == 2);"
   from: (process:21024): NetworkManager-CRITICAL **: some_function: assertion '1 == 2' failed
   to:   (process:21024): NetworkManager-CRITICAL **: ((source.c:347)): assertion '<dropped>' failed

When doing a non-debug build, those string are now removed. Debug-builds
can be enabled by setting --with-more-assert=$LEVEL to larger then zero.

https://bugzilla.gnome.org/show_bug.cgi?id=767296
2016-06-09 12:03:39 +02:00
Thomas Haller fa973afa19 tests: add macro NMTST_G_RETURN_MSG for expecting g_return*() failures
A failure to g_return*() by default prints a g_critical() with stringifing the
condition. Add a macro NMTST_G_RETURN_MSG() that reproduces that line to more
accurately match the failure message.
2016-06-09 12:03:39 +02:00
Thomas Haller 348e505b3a macros: add macro _nm_printf() for function attribute 2016-06-05 12:22:01 +02:00
Thomas Haller 8e54cfdb27 all: move NM_AUTH_PERMISSION_* defines to "nm-common-macros.h" header 2016-06-01 19:06:35 +02:00
Thomas Haller ed551a4633 shared: add "nm-common-macros.h" header
Shared headers are all project-wide and internal API.
Currently we have the following:

General purpose:

  - shared/gsystem-local-alloc.h: header-only, allocation macros
  - shared/nm-dbus-compat.h: header-only, D-Bus related defines
  - shared/nm-glib.h: header-only, glib compatibility defines
  - shared/nm-macros-internal.h: header-only, utils
  - shared/nm-shared-utils.[hc]: source and header, utils
  - shared/nm-test*.[hc]: source and header, libnm testing utils

Special to NetworkManager repository:

  - shared/nm-version-macros.h.in: header-only, version macros
  - shared/nm-default.h: header-only, default-include

Now we add "shared/nm-common-macros.h" which is header-only, but non
general purpose.

I am running low on good names, considering all the shared/core/macros
utils headers. Still, I think "nm-common-macros.h" is appropriate.
2016-06-01 19:06:35 +02:00
Thomas Haller a2c843499c all/tests: split core part out of "nm-test-utils.h"
A large part of "nm-test-utils.h" is only relevant for tests inside "src/"
directory, as they are helpers related to NetworkManager core part.

Split this part out of "nm-test-utils.h" header.
2016-05-17 16:48:52 +02:00
Thomas Haller 5847e70fd6 shared: add _nm_pure/_nm_const define for __attribute__ ((pure))/((const)) 2016-05-16 13:09:02 +02:00
Thomas Haller b871106e25 macros: define NM_MORE_ASSERTS is not defined
In NetworkManager's configure script we have --with-more-asserts
option which always defines NM_MORE_ASSERTS in config.h.

When reusing the header file outside of NetworkManager, the
NM_MORE_ASSERTS define might be unset. Define it in that case
to avoid compiler warnings about undefined preprocessor define.
2016-05-14 23:11:59 +02:00
Thomas Haller ba90c9601c all: replace nm_unauto() by g_steal_pointer()
They do essentially the same.
2016-05-12 14:28:44 +02:00
Thomas Haller 5d1c4ca6c4 nm-glib: backport g_steal_pointer() from glib-2.44 2016-05-12 14:25:36 +02:00
Thomas Haller ee29228277 shared: add define _nm_unused for __attribute__((unused))
This is both supported by clang and gcc. Using it is nicer then
casting the (void), which requires an additional line of code.
2016-05-12 09:59:09 +02:00
Thomas Haller fbf4904ae0 nmtst: allow non-boolean argument to nmtst_assert_success()
Reimplement nmtst_assert_success() as a macro which allows non-boolean @success
arguments.
2016-05-09 11:04:51 +02:00
Thomas Haller 05478e4f4c utils: refactor _nm_utils_ascii_str_to_int64()
To allow for trailing whitespace, we don't need to copy and trunacate
the input string. g_ascii_strtoll() conveniently returns the location via
the endptr argument.
2016-05-03 11:52:39 +02:00
Thomas Haller 6bf022359f core/trivial: rename "source" field of addresses and routes
The "source" field of NMPlatformIPRoute (now "rt_source") maps to the
protocol field of the route. The source of NMPlatformIPAddress (now
"addr_source") has no direct equivalent in the kernel.

As their use is different, they should have different names. Also,
the name "source" is used all over the place. Hence give the fields
a more distinct name.
2016-04-28 12:53:21 +02:00
Thomas Haller 186787744c shared: move nm_utils_ascii_str_to_bool() to shared/nm-shared-utils.h 2016-04-19 13:47:41 +02:00
Thomas Haller 9a1e0b97da shared: add _nm_packed macro for __attribute__((packed)) 2016-04-11 11:26:36 +02:00
Thomas Haller 2e6ec6d8ac nmtst: add nmtst_platform_ip4_address() util 2016-04-11 11:26:32 +02:00
Thomas Haller 0e78ce5ed6 nmtst: add nmtst_rand_buf() util 2016-04-11 11:22:50 +02:00
Lubomir Rintel 350d96a9ee release: bump version to 1.3.0 (development) 2016-04-05 22:22:58 +02:00
Lubomir Rintel f4b4e35c79 release: add version 1.4 macros 2016-04-05 22:22:58 +02:00
Thomas Haller 9152dec99f build: disable deprecation checks for internal compilation
For internal compilation we want to be able to use deprecated
API without warnings.

Define the version min/max macros to effectively disable deprecation
warnings.

However, don't do it via CFLAGS option in the makefiles, instead hack it
to "nm-default.h". After all, *every* source file that is for internal
compilation needs to include this header as first.
2016-04-05 22:22:58 +02:00
Thomas Haller 88655999df shared: add nm_g_object_set_property() 2016-03-26 12:10:54 +01:00
Thomas Haller 72216f7359 shared: move NM_UTILS_ERROR to shared-utils
NM_UTILS_ERROR is our way to say, that we don't care about
the GError domain and code. nmcli sometimes passes domain "1"
and code "0" to g_set_error(), which could be considered
a bug.

We usually don't care about the error but only about the error
message, so let's have a universally available error quark around.
2016-03-26 12:10:53 +01:00
Thomas Haller fafc90526b shared: move _nm_utils_ascii_str_to_int64() to "shared/nm-shared-utils.h"
_nm_utils_ascii_str_to_int64() was declared in libnm-core's internal
header "nm-core-internal.h" and thus available for libnm-core, libnm,
NetworkManager and related.

It also means, the function was not available in libnm-util, libnm-glib,
clients or dispatcher. So, we either reimplemented it (nmc_string_to_int_base)
or struggle with the awkward strtol* API.
2016-03-26 12:10:53 +01:00
Thomas Haller 5de30dd029 shared: include "nm-shared-utils.h"
Include it via "nm-default.h" to all projects.
2016-03-26 12:10:53 +01:00
Thomas Haller 330026db90 shared: add "nm-shared-utils" 2016-03-26 12:10:53 +01:00
Thomas Haller 3025bfc8b2 shared: add nm_auto_unset_gvalue macro 2016-03-26 12:10:53 +01:00
Thomas Haller 2c8ef153a1 nmtst: add nmtst_variant_new_vardict() function 2016-03-26 12:10:53 +01:00
Thomas Haller d45107c1de nmtst: fix memleak when using NMTST_VARIANT_DROP_SETTING() 2016-03-26 12:10:53 +01:00
Thomas Haller 2c11e23c34 shared: include <stdlib.h> in "nm-macros-internal.h"
"nm-macros-internal.h" uses free() for the "nm_auto_free"
macro. Thus, as long as that code is there, we anyway must
include <stdlib.h> along the line.

Do it in "nm-macros-internal.h" to make the header self-contained.
2016-03-24 10:10:53 +01:00
Thomas Haller 0330a55851 shared: add nm_unauto() helper macro 2016-03-17 15:00:48 +01:00
Thomas Haller a50d28d4dd shared: add nm_assert_not_reached() 2016-03-17 15:00:48 +01:00
Thomas Haller b5c8d496c2 nmtst: add NMTST_DEBUG option "D" 2016-03-15 12:56:57 +01:00
Thomas Haller 4a00bcf5a6 shared: add nm_g_object_ref() and nm_g_object_unref() function 2016-03-13 12:31:04 +01:00
Thomas Haller 0cee9ef7b5 nmtst: add nmtst_main_loop_quit_on_notify function 2016-03-10 16:46:50 +01:00
Thomas Haller 3a09a7e991 nmtst: add nmtst_assert_variant_*() helper macros 2016-03-10 14:49:55 +01:00
Thomas Haller 2ff11525c6 nmtst: convert nmtst_assert_error() to a macro to preserve func:line information
Within the macro, the assertion print the proper location of where
the failure happens, instead of pointing to "nm-test-utils.h".
2016-03-04 17:01:41 +01:00
Thomas Haller 01b9b4104c all: clean-up usage of GError
Functions that take a GError** MUST fill it in on error. There is no
need to check whether error is NULL if the function it was passed to
had a failing return value.

Likewise, a proper GError must have a non-NULL message, so there's no
need to double-check that either.

Based-on-patch-by: Dan Winship <danw@gnome.org>
2016-03-03 18:54:20 +01:00
Thomas Haller 7871d850f5 shared: add NM_G_ERROR_MSG() 2016-03-03 18:54:20 +01:00
Thomas Haller 7f43e0a7b3 platform/trivial: rename NMPlatformIP6Address's "flags" field to "n_ifa_flags"
There are far too many "flags". Rename the "flags" to "n_ifa_flags"
which reminds to "ifa_flags" in 'struct ifaddrmsg', but with a
distinctive "n_" prefix.
2016-02-29 16:27:08 +01:00
Thomas Haller e18cdc10d3 platform: adjust type of IPv6 address flags to guint
Address flags inside 'struct ifaddrmsg' are uint8_t and they are
extended to uint32_t via IFA_FLAGS.

Change it to be guint32.
2016-02-29 16:27:08 +01:00
Thomas Haller 3a81c0f301 macros: add nm_auto() macro to cleanup functions 2016-02-29 14:08:00 +01:00
Thomas Haller 17779975c8 nm-glib: backport g_info() macro 2016-02-24 20:04:29 +01:00
Thomas Haller 4eb5ba8b02 macros: split macro NM_GOBJECT_PROPERTIES_DEFINE() in two
Sometimes we don't need the _notify() helper which results in a
unused-function warning.
2016-02-19 19:59:05 +01:00
Thomas Haller 8bace23beb all: cleanup includes and let "nm-default.h" include "config.h"
- All internal source files (except "examples", which are not internal)
  should include "config.h" first. As also all internal source
  files should include "nm-default.h", let "config.h" be included
  by "nm-default.h" and include "nm-default.h" as first in every
  source file.
  We already wanted to include "nm-default.h" before other headers
  because it might contains some fixes (like "nm-glib.h" compatibility)
  that is required first.

- After including "nm-default.h", we optinally allow for including the
  corresponding header file for the source file at hand. The idea
  is to ensure that each header file is self contained.

- Don't include "config.h" or "nm-default.h" in any header file
  (except "nm-sd-adapt.h"). Public headers anyway must not include
  these headers, and internal headers are never included after
  "nm-default.h", as of the first previous point.

- Include all internal headers with quotes instead of angle brackets.
  In practice it doesn't matter, because in our public headers we must
  include other headers with angle brackets. As we use our public
  headers also to compile our interal source files, effectively the
  result must be the same. Still do it for consistency.

- Except for <config.h> itself. Include it with angle brackets as suggested by
  https://www.gnu.org/software/autoconf/manual/autoconf.html#Configuration-Headers
2016-02-19 17:53:25 +01:00
Thomas Haller 6d5e55870a shared: fix nm_sprintf_buf() macro to allow plain string
Use non-portable gcc extension to allow for zero variadic
arguments so that you can pass a plain string as argument.
2016-02-19 01:42:29 +01:00
Thomas Haller 6dc431b0c9 shared: move definition of "bool" to nm-macros-internal.h
"nm-default.h" should only include all the relevant header files based
on NETWORKMANAGER_COMPILATION. It should not contain definitions on
it's own.

Move the definition of "bool" to "nm-macros-internal.h".
2016-02-16 20:18:25 +01:00
Thomas Haller c66ee23f73 macros: add nm_auto_free macro
Similar to gs_free to cleanup pointers with free(). Note that
g_free() and free() cannot be used interchangably.
2016-02-16 14:13:25 +01:00
Thomas Haller dec3a7e58d shared: add nm_streq() and nm_streq0() macro
Using strcmp() to test for string equality is a well known pattern.
However the inverse logic still is still hard to grasp especially in
more complex expressions.

nm_streq() should is an alternative to use strcmp(). And there is a counterpart
nm_streq0() which is based on g_strcmp0().

Kernel and systemd have also similar streq() macros.

https://mail.gnome.org/archives/networkmanager-list/2016-February/msg00047.html
2016-02-15 23:47:14 +01:00
Thomas Haller 3d734b30a2 nmtst: drop deprecated test helper macro ASSERT()
It's no longer used.
2016-02-15 14:27:45 +01:00
Thomas Haller b4cced2cea nmtst: add nmtst_assert_connection_verify() and don't normalize connection in assert
It is ugly that nmtst_assert_connection_verifies_after_normalization() would
normalize the argument and modify it. An assertion should not have side-effects.
2016-02-15 14:26:26 +01:00
Thomas Haller 78f558c706 nmtst: add nmtst_assert_no_success() macro 2016-02-14 23:48:00 +01:00
Thomas Haller e663b88c59 all/trivial: rename STRLEN() macro to NM_STRLEN()
We should not have defines/macros in header files without a nm/NM
prefix. STRLEN() was one of the few offenders.

https://mail.gnome.org/archives/networkmanager-list/2016-February/msg00048.html
2016-02-14 11:34:42 +01:00
Thomas Haller 2c2d9d2e4c build: cleanup default includes
- "gsystem-local-alloc.h" and <gio/gio.h> are already included via
  "nm-default.h". No need to include them separately.

- include "nm-macros-internal.h" via "nm-default.h" and drop all
  explict includes.

- in the modified files, ensure that we always include "config.h"
  and "nm-default.h" first. As second, include the header file
  for the current source file (if applicable). Then follow external
  includes and finally internal nm includes.

- include nm headers inside source code files with quotes

- internal header files don't need to include default headers.
  They can savely assume that "nm-default.h" is already included
  and with it glib, nm-glib.h, nm-macros-internal.h, etc.
2016-02-12 15:36:01 +01:00
Lubomir Rintel 4c3e69f9e9 test: use g_assert_not_reached () instead of asserting FALSE
It's declared as never returning, making do a better at understanding control
flow. Otherwise it makes a poor guess:

  In file included from test-crypto.c:37:
  ../../shared/nm-test-utils.h:1344:3: error: variable 'family' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
                  g_assert (FALSE);
                  ^~~~~~~~~~~~~~~~
2016-02-12 09:05:27 +01:00
Beniamino Galvani 8682bb7f5f nmtst: introduce nmtst_setting_ip_config_add_{address,route} helpers 2016-02-11 21:57:09 +01:00
Dan Williams 1fd91056d4 build: define g_assert_cmpmem() for glib < 2.46
Fixes: b73c0e2f6d
2016-02-11 12:40:18 -06:00
Thomas Haller dc394a6537 macros: add NM_IN_STRSET()
Add macro similar to NM_IN_SET() that checks for C strings.
NULL values are allowed and handled as one would expect.
2016-02-11 17:54:38 +01:00
Thomas Haller 1211b5b631 macros: simplify NM_IN_SET() macro
Also fix NM_IN_SET_SE() to guaranteed return 0 or 1.
2016-02-11 17:54:38 +01:00
Dan Williams 80d9a43a25 tests: get rid of FAIL macro 2016-02-11 09:50:29 -06:00
Thomas Haller c1470a353c nmtst: drop details argument from add-test helper 2016-02-10 00:15:41 +01:00
Thomas Haller 03ec751402 nmtst: fix nmtst_test_data_unpack() macro
Fixes: e6244814eb
2016-02-09 10:51:33 +01:00
Thomas Haller e6244814eb nmtst: add nmtst_add_test_func() helper to schedule tests with arguments 2016-02-03 15:27:52 +01:00
Thomas Haller 9fda0817ab nmtst: don't use G_STRLOC in test functions
Instead pass separate values for file and line. Otherwise, we create
a unique string for each occurance.
2016-02-03 13:34:38 +01:00
Thomas Haller 123747963a nmtst: improve test macros FAIL() and ASSERT()
Fail only printed a message to stderr and exited.
Instead, print it with g_error(), which also breaks
in the debugger and produces a core-dump.

Also, it constructed the message based on an unchecked
format string and constructed a format string dynamically.
Just don't do that.

Also add a comment that these macros are discouraged because
they are cumbersome to write (requiring a test-name and a failure
message).
2016-02-03 12:41:35 +01:00
Thomas Haller 0bedc637ed build: add "shared" files to EXTRA_DIST 2016-01-27 11:51:17 +01:00
Thomas Haller f427909bf8 shared: add NM_GOBJECT_PROPERTIES_DEFINE()
Helper macros to define GObject property enum,
the obj_properties array, and a _notify() function.

We should move away from invoking property changed notifications by
string, as we already do for signals. This macro simplifies the
implementation of establishes a pattern for naming and usage.
2016-01-19 21:20:36 +01:00
Beniamino Galvani f96abc8be5 core: always use gulong to store signal handler ids
We inconsistently use gulong,guint,int types to store signal handler
id, but the type returned by g_signal_connect() is a gulong.

This has no practical consequences because a int/guint is enough to
store the value, however it is better to use a consistent type, also
because nm_clear_g_signal_handler() accepts a pointer to the signal id
and thus it must be always called with the same pointer type.
2016-01-06 21:25:55 +01:00
Thomas Haller 142ea41cae libnm/tests: add test code driving python test service 2015-12-26 16:43:49 +01:00
Thomas Haller 570d24b88c libnm/tests: add dbus-glib support to "nm-test-libnm-utils" 2015-12-26 16:43:49 +01:00
Thomas Haller 5edd265c0b libnm/tests: add nmtstc_nm_remote_settings_new() 2015-12-26 16:43:49 +01:00
Thomas Haller 56880fbe69 libnm/tests: add nmtstc_nm_client_new() 2015-12-26 16:43:49 +01:00
Thomas Haller bdfcf02da3 libnm/tests: add NMTSTC_SERVICE_INFO_SETUP() macro 2015-12-26 16:43:49 +01:00
Thomas Haller f354d5f0fc nmtst: enable connection utility functions for libnm-glib/libnm-utils library 2015-12-25 20:36:43 +01:00
Thomas Haller 9a11577e63 nmtst: add nmtst_uuid_generate() 2015-12-25 20:36:43 +01:00
Thomas Haller c2bafa6153 nmtst: add nmtst_find_all_indexes() 2015-12-25 20:36:43 +01:00
Thomas Haller 766f31507b nmtst: add nmtst_main_loop_run() 2015-12-25 20:36:43 +01:00
Thomas Haller c7d4d67d53 include: remove trailing semicolon from _Pragma() call 2015-12-24 11:42:37 +01:00
Thomas Haller db80ec05ab build: rename directory "include" to "shared"
Up to now, the "include" directory contained (only) header files that were
used project-wide by libs, core, clients, et al.

Since the directory now also contains a non-header file, the "include"
name is misleading. Instead of adding yet another directory that is
project-wide, with non-header-only content, rename the "include"
directory to "shared".
2015-12-24 11:42:37 +01:00