Back port jansson iterators
[trust_router.git] / common / jansson_iterators.h
diff --git a/common/jansson_iterators.h b/common/jansson_iterators.h
new file mode 100644 (file)
index 0000000..c4e8a32
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2009-2013 Petri Lehtinen <petri@digip.org>
+ *
+ * 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