aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/collections
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstrongswan/collections')
-rw-r--r--src/libstrongswan/collections/enumerator.c29
-rw-r--r--src/libstrongswan/collections/enumerator.h23
2 files changed, 22 insertions, 30 deletions
diff --git a/src/libstrongswan/collections/enumerator.c b/src/libstrongswan/collections/enumerator.c
index cdf05d5e8..52c9e1cd5 100644
--- a/src/libstrongswan/collections/enumerator.c
+++ b/src/libstrongswan/collections/enumerator.c
@@ -518,9 +518,9 @@ enumerator_t *enumerator_create_nested(enumerator_t *outer,
*/
typedef struct {
enumerator_t public;
- enumerator_t *unfiltered;
+ enumerator_t *orig;
void *data;
- bool (*filter)(void *data, ...);
+ bool (*filter)(void*,enumerator_t*,va_list);
void (*destructor)(void *data);
} filter_enumerator_t;
@@ -531,35 +531,28 @@ METHOD(enumerator_t, destroy_filter, void,
{
this->destructor(this->data);
}
- this->unfiltered->destroy(this->unfiltered);
+ this->orig->destroy(this->orig);
free(this);
}
METHOD(enumerator_t, enumerate_filter, bool,
filter_enumerator_t *this, va_list args)
{
- void *i1, *i2, *i3, *i4, *i5;
- void *o1, *o2, *o3, *o4, *o5;
+ bool result = FALSE;
- /* FIXME: what happens if there are less than five arguments is not defined */
- VA_ARGS_VGET(args, o1, o2, o3, o4, o5);
-
- while (this->unfiltered->enumerate(this->unfiltered, &i1, &i2, &i3, &i4, &i5))
+ if (this->filter(this->data, this->orig, args))
{
- if (this->filter(this->data, &i1, o1, &i2, o2, &i3, o3, &i4, o4, &i5, o5))
- {
- return TRUE;
- }
+ result = TRUE;
}
- return FALSE;
+ return result;
}
/*
* Described in header
*/
-enumerator_t *enumerator_create_filter(enumerator_t *unfiltered,
- bool (*filter)(void *data, ...),
- void *data, void (*destructor)(void *data))
+enumerator_t *enumerator_create_filter(enumerator_t *orig,
+ bool (*filter)(void *data, enumerator_t *orig, va_list args),
+ void *data, void (*destructor)(void *data))
{
filter_enumerator_t *this;
@@ -569,7 +562,7 @@ enumerator_t *enumerator_create_filter(enumerator_t *unfiltered,
.venumerate = _enumerate_filter,
.destroy = _destroy_filter,
},
- .unfiltered = unfiltered,
+ .orig = orig,
.filter = filter,
.data = data,
.destructor = destructor,
diff --git a/src/libstrongswan/collections/enumerator.h b/src/libstrongswan/collections/enumerator.h
index e4b0547ba..99f8847e4 100644
--- a/src/libstrongswan/collections/enumerator.h
+++ b/src/libstrongswan/collections/enumerator.h
@@ -189,25 +189,24 @@ enumerator_t *enumerator_create_nested(enumerator_t *outer,
void *data, void (*destructor)(void *data));
/**
- * Creates an enumerator which filters output of another enumerator.
+ * Creates an enumerator which filters/maps output of another enumerator.
*
- * The filter function receives the user supplied "data" followed by a
- * unfiltered enumeration item, followed by an output pointer where to write
- * the filtered data. Then the next input/output pair follows.
- * It returns TRUE to deliver the
- * values to the caller of enumerate(), FALSE to filter this enumeration.
+ * The filter function receives the user supplied "data" followed by the
+ * original enumerator, followed by the arguments passed to the outer
+ * enumerator. It returns TRUE to deliver the values assigned to these
+ * arguments to the caller of enumerate() and FALSE to end the enumeration.
+ * Filtering items is simple as the filter function may just skip enumerated
+ * items from the original enumerator.
*
- * The variable argument list of enumeration values is limit to 5.
- *
- * @param unfiltered unfiltered enumerator to wrap, gets destroyed
+ * @param orig original enumerator to wrap, gets destroyed
* @param filter filter function
* @param data user data to supply to filter
* @param destructor destructor function to clean up data after use
* @return the filtered enumerator
*/
-enumerator_t *enumerator_create_filter(enumerator_t *unfiltered,
- bool (*filter)(void *data, ...),
- void *data, void (*destructor)(void *data));
+enumerator_t *enumerator_create_filter(enumerator_t *orig,
+ bool (*filter)(void *data, enumerator_t *orig, va_list args),
+ void *data, void (*destructor)(void *data));
/**
* Create an enumerator wrapper which does a cleanup on destroy.