From: Sam Hartman Date: Fri, 11 Jul 2014 19:03:12 +0000 (-0400) Subject: Back port jansson iterators X-Git-Url: http://www.project-moonshot.org/gitweb/?p=trust_router.git;a=commitdiff_plain;h=a168e745407c0e15c88224b0860240659f667524 Back port jansson iterators --- diff --git a/Makefile.am b/Makefile.am index 8747765..3e18e37 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,6 +4,7 @@ AM_CFLAGS = -Wall -Werror=missing-prototypes -Werror -Wno-parentheses SUBDIRS = gsscon common_srcs = common/tr_name.c \ common/tr_constraint.c \ + common/jansson_iterators.h \ common/tr_msg.c \ common/tr_dh.c \ common/tr_util.c diff --git a/common/jansson_iterators.h b/common/jansson_iterators.h new file mode 100644 index 0000000..c4e8a32 --- /dev/null +++ b/common/jansson_iterators.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2009-2013 Petri Lehtinen + * + * Jansson is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See LICENSE for details. + */ +/*See the LICENSE file in the jansson source distribution. + */ + +#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 + +#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 diff --git a/common/tr_constraint.c b/common/tr_constraint.c index da4155c..130fb9b 100644 --- a/common/tr_constraint.c +++ b/common/tr_constraint.c @@ -32,6 +32,7 @@ * */ #include +#include "jansson_iterators.h" #include #include