]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Add ucl_object_iterate_full function
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 10 Jan 2017 12:35:55 +0000 (12:35 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 10 Jan 2017 12:35:55 +0000 (12:35 +0000)
contrib/libucl/ucl.h
contrib/libucl/ucl_util.c

index 024f5dd8fd357f110e57d9ce5237ea6046c4eb03..ec93bd7e1dfd04fc6f688764c60981e5282dbef9 100644 (file)
@@ -831,10 +831,29 @@ UCL_EXTERN ucl_object_iter_t ucl_object_iterate_reset (ucl_object_iter_t it,
  * Get the next object from the `obj`. This fucntion iterates over arrays, objects
  * and implicit arrays
  * @param iter safe iterator
+ * @param expand_values expand explicit arrays and objects
  * @return the next object in sequence
  */
 UCL_EXTERN const ucl_object_t* ucl_object_iterate_safe (ucl_object_iter_t iter,
                bool expand_values);
+/**
+ * Iteration type enumerator
+ */
+enum ucl_iterate_type {
+       UCL_ITERATE_EXPLICIT = 1 << 0, /**< Iterate just explicit arrays and objects */
+       UCL_ITERATE_IMPLICIT = 1 << 1,  /**< Iterate just implicit arrays */
+       UCL_ITERATE_BOTH = (1 << 0) | (1 << 1),   /**< Iterate both explicit and implicit arrays*/
+};
+
+/**
+ * Get the next object from the `obj`. This fucntion iterates over arrays, objects
+ * and implicit arrays if needed
+ * @param iter safe iterator
+ * @param
+ * @return the next object in sequence
+ */
+UCL_EXTERN const ucl_object_t* ucl_object_iterate_full (ucl_object_iter_t iter,
+               enum ucl_iterate_type type);
 
 /**
  * Free memory associated with the safe iterator
index 1adb8c3b6d56a496ce3021d4ed44a24b149eb792..6691c8546641f1fc4eaa0b3f6b731ca5a37f89ea 100644 (file)
@@ -2478,6 +2478,13 @@ ucl_object_iterate_reset (ucl_object_iter_t it, const ucl_object_t *obj)
 
 const ucl_object_t*
 ucl_object_iterate_safe (ucl_object_iter_t it, bool expand_values)
+{
+       return ucl_object_iterate_full (it, expand_values ? UCL_ITERATE_BOTH :
+                       UCL_ITERATE_IMPLICIT);
+}
+
+const ucl_object_t*
+ucl_object_iterate_full (ucl_object_iter_t it, enum ucl_iterate_type type)
 {
        struct ucl_object_safe_iter *rit = UCL_SAFE_ITER (it);
        const ucl_object_t *ret = NULL;
@@ -2491,21 +2498,21 @@ ucl_object_iterate_safe (ucl_object_iter_t it, bool expand_values)
        if (rit->impl_it->type == UCL_OBJECT || rit->impl_it->type == UCL_ARRAY) {
                ret = ucl_object_iterate (rit->impl_it, &rit->expl_it, true);
 
-               if (ret == NULL) {
+               if (ret == NULL && (type & UCL_ITERATE_IMPLICIT)) {
                        /* Need to switch to another implicit object in chain */
                        rit->impl_it = rit->impl_it->next;
                        rit->expl_it = NULL;
-                       return ucl_object_iterate_safe (it, expand_values);
+                       return ucl_object_iterate_safe (it, type);
                }
        }
        else {
                /* Just iterate over the implicit array */
                ret = rit->impl_it;
                rit->impl_it = rit->impl_it->next;
-               if (expand_values) {
+               if (type & UCL_ITERATE_EXPLICIT) {
                        /* We flatten objects if need to expand values */
                        if (ret->type == UCL_OBJECT || ret->type == UCL_ARRAY) {
-                               return ucl_object_iterate_safe (it, expand_values);
+                               return ucl_object_iterate_safe (it, type);
                        }
                }
        }