diff options
author | Thomas Haller <thaller@redhat.com> | 2017-11-09 17:40:32 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-11-09 17:40:32 +0100 |
commit | 931910b7de1dd4fd09b7a020d5f687c60f468328 (patch) | |
tree | 1b2b7c7576beef33aad5b49de5a6b02fd760cb4c | |
parent | 85cc5db7a4cb6dd1df97a471ead833beed0f7b68 (diff) | |
parent | 595aaf0f3edcc2111207aa0321921e9217fc8b59 (diff) | |
download | NetworkManager-931910b7de1dd4fd09b7a020d5f687c60f468328.tar.gz |
all: merge branch 'th/jansson'
-rw-r--r-- | .travis.yml | 2 | ||||
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | libnm-core/nm-utils.c | 16 | ||||
-rw-r--r-- | shared/nm-utils/nm-jansson.h | 71 | ||||
-rw-r--r-- | src/devices/ovs/nm-ovsdb.c | 25 | ||||
-rw-r--r-- | src/devices/team/nm-device-team.c | 2 |
6 files changed, 80 insertions, 37 deletions
diff --git a/.travis.yml b/.travis.yml index 0bcda1ded9..77b623bdab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,7 @@ addons: coverity_scan: project: name: NetworkManager/NetworkManager - build_command_prepend: sh autogen.sh --with-systemd-logind=no --enable-more-warnings=no + build_command_prepend: sh autogen.sh --with-systemd-logind=no --enable-more-warnings=no --disable-ovs build_command: make -j4 branch_pattern: .*coverity.* diff --git a/Makefile.am b/Makefile.am index 6599d939c0..af1d445d86 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4566,6 +4566,7 @@ EXTRA_DIST += \ shared/nm-utils/c-list-util.h \ shared/nm-utils/gsystem-local-alloc.h \ shared/nm-utils/nm-glib.h \ + shared/nm-utils/nm-jansson.h \ shared/nm-utils/nm-obj.h \ shared/nm-utils/nm-macros-internal.h \ shared/nm-utils/nm-shared-utils.c \ diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index fadbcf342d..f2fa73248d 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -34,10 +34,7 @@ #include <sys/stat.h> #include <net/if.h> -#if WITH_JANSSON -#include <jansson.h> -#endif - +#include "nm-utils/nm-jansson.h" #include "nm-utils/nm-enum-utils.h" #include "nm-utils/nm-hash-utils.h" #include "nm-common-macros.h" @@ -4361,15 +4358,6 @@ nm_utils_is_json_object (const char *str, GError **error) return TRUE; } -/* json_object_foreach_safe() is only available since Jansson 2.8, - * reimplement it */ -#define _json_object_foreach_safe(object, n, key, value) \ - for (key = json_object_iter_key (json_object_iter (object)), \ - n = json_object_iter_next (object, json_object_iter_at (object, key)); \ - key && (value = json_object_iter_value (json_object_iter_at (object, key))); \ - key = json_object_iter_key (n), \ - n = json_object_iter_next (object, json_object_iter_at (object, key))) - gboolean _nm_utils_team_config_equal (const char *conf1, const char *conf2, @@ -4433,7 +4421,7 @@ _nm_utils_team_config_equal (const char *conf1, /* Only consider a given subset of nodes, others can change depending on * current state */ for (i = 0, json = json1; i < 2; i++, json = json2) { - _json_object_foreach_safe (json, tmp, key, value) { + json_object_foreach_safe (json, tmp, key, value) { if (!NM_IN_STRSET (key, "runner", "link_watch")) json_object_del (json, key); } diff --git a/shared/nm-utils/nm-jansson.h b/shared/nm-utils/nm-jansson.h new file mode 100644 index 0000000000..2b159e7872 --- /dev/null +++ b/shared/nm-utils/nm-jansson.h @@ -0,0 +1,71 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2018 Red Hat, Inc. + */ + +#ifndef __NM_JANSSON_H__ +#define __NM_JANSSON_H__ + +/* you need to include at least "config.h" first, possibly "nm-default.h". */ + +#if WITH_JANSSON + +#include <jansson.h> + +/* Added in Jansson v2.3 (released Jan 27 2012) */ +#ifndef json_object_foreach +#define json_object_foreach(object, key, value) \ + for(key = json_object_iter_key(json_object_iter(object)); \ + key && (value = json_object_iter_value(json_object_iter_at (object, key) )); \ + key = json_object_iter_key(json_object_iter_next(object, json_object_iter_at (object, key)))) +#endif + +/* Added in Jansson v2.4 (released Sep 23 2012), but travis.ci has v2.2. */ +#ifndef json_boolean +#define json_boolean(val) ((val) ? json_true() : json_false()) +#endif + +/* Added in Jansson v2.5 (released Sep 19 2013), but travis.ci has v2.2. */ +#ifndef json_array_foreach +#define json_array_foreach(array, index, value) \ + for(index = 0; \ + index < json_array_size(array) && (value = json_array_get(array, index)); \ + index++) +#endif + +/* Added in Jansson v2.8 */ +#ifndef json_object_foreach_safe +#if JANSSON_VERSION_HEX < 0x020300 +#define json_object_foreach_safe(object, n, key, value) \ + for (key = json_object_iter_key (json_object_iter (object)), \ + n = json_object_iter_next (object, json_object_iter_at (object, key)); \ + key && (value = json_object_iter_value (json_object_iter_at (object, key))); \ + key = json_object_iter_key (n), \ + n = json_object_iter_next (object, json_object_iter_at (object, key))) +#else +#define json_object_foreach_safe(object, n, key, value) \ + for(key = json_object_iter_key(json_object_iter(object)), \ + n = json_object_iter_next(object, json_object_key_to_iter(key)); \ + key && (value = json_object_iter_value(json_object_key_to_iter(key))); \ + key = json_object_iter_key(n), \ + n = json_object_iter_next(object, json_object_key_to_iter(key))) +#endif +#endif + +#endif /* WITH_JANSON */ + +#endif /* __NM_JANSSON_H__ */ diff --git a/src/devices/ovs/nm-ovsdb.c b/src/devices/ovs/nm-ovsdb.c index b44668c0d3..6d28bd2c55 100644 --- a/src/devices/ovs/nm-ovsdb.c +++ b/src/devices/ovs/nm-ovsdb.c @@ -22,37 +22,20 @@ #include "nm-ovsdb.h" #include <string.h> -#include <jansson.h> #include <gmodule.h> #include <gio/gunixsocketaddress.h> +#include "nm-utils/nm-jansson.h" #include "devices/nm-device.h" #include "platform/nm-platform.h" #include "nm-core-internal.h" -/* Added in Jansson v2.4 (released Sep 23 2012), but travis.ci has v2.2. */ -#ifndef json_boolean -#define json_boolean(val) ((val) ? json_true() : json_false()) -#endif - -/* Added in Jansson v2.5 (released Sep 19 2013), but travis.ci has v2.2. */ -#ifndef json_array_foreach -#define json_array_foreach(array, index, value) \ - for (index = 0; \ - index < json_array_size(array) && (value = json_array_get(array, index)); \ - index++) -#endif +/*****************************************************************************/ -/* Added in Jansson v2.3 (released Jan 27 2012) */ -#ifndef json_object_foreach -#define json_object_foreach(object, key, value) \ - for(key = json_object_iter_key(json_object_iter(object)); \ - key && (value = json_object_iter_value(json_object_key_to_iter(key))); \ - key = json_object_iter_key(json_object_iter_next(object, json_object_key_to_iter(key)))) +#if JANSSON_VERSION_HEX < 0x020400 +#warning "requires at least libjansson 2.4" #endif -/*****************************************************************************/ - typedef struct { char *name; char *connection_uuid; diff --git a/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c index 098cd4372e..3f23a52005 100644 --- a/src/devices/team/nm-device-team.c +++ b/src/devices/team/nm-device-team.c @@ -28,8 +28,8 @@ #include <sys/wait.h> #include <teamdctl.h> #include <stdlib.h> -#include <jansson.h> +#include "nm-utils/nm-jansson.h" #include "NetworkManagerUtils.h" #include "devices/nm-device-private.h" #include "platform/nm-platform.h" |