lib: import new JSON iteration macro

Save a few lines when iterating over JSON objects using the new
JSON_FOREACH macro.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
This commit is contained in:
Rafael Zalamena 2018-05-22 10:48:18 -03:00
parent e7e81aefe4
commit 8519fe88c9
2 changed files with 15 additions and 0 deletions

View File

@ -43,6 +43,7 @@ ForEachMacros:
- SPLAY_FOREACH
- FOR_ALL_INTERFACES
- FOR_ALL_INTERFACES_ADDRESSES
- JSON_FOREACH
# zebra
- RE_DEST_FOREACH_ROUTE
- RE_DEST_FOREACH_ROUTE_SAFE

View File

@ -23,6 +23,20 @@
#if defined(HAVE_JSON_C_JSON_H)
#include <json-c/json.h>
/*
* FRR style JSON iteration.
* Usage: JSON_FOREACH(...) { ... }
*/
#define JSON_FOREACH(jo, joi, join) \
/* struct json_object *jo; */ \
/* struct json_object_iterator joi; */ \
/* struct json_object_iterator join; */ \
for ((joi) = json_object_iter_begin((jo)), \
(join) = json_object_iter_end((jo)); \
json_object_iter_equal(&(joi), &(join)) == 0; \
json_object_iter_next(&(joi)))
#else
#include <json/json.h>