all: merge branch 'th/jansson'

This commit is contained in:
Thomas Haller 2017-11-09 17:40:32 +01:00
commit 931910b7de
6 changed files with 81 additions and 38 deletions

View file

@ -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.*

View file

@ -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 \

View file

@ -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);
}

View file

@ -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__ */

View file

@ -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))))
#endif
/*****************************************************************************/
#if JANSSON_VERSION_HEX < 0x020400
#warning "requires at least libjansson 2.4"
#endif
typedef struct {
char *name;
char *connection_uuid;

View file

@ -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"