mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-04-28 17:01:51 +00:00
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:
parent
e7e81aefe4
commit
8519fe88c9
@ -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
|
||||
|
14
lib/json.h
14
lib/json.h
@ -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>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user