The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Functions to iterate over a sets and subsets of items stored in dlists. More...
#include <freeradius-devel/build.h>
#include <freeradius-devel/missing.h>
#include <freeradius-devel/util/dlist.h>
#include <freeradius-devel/util/talloc.h>
#include <stddef.h>
#include <stdbool.h>
Go to the source code of this file.
Data Structures | |
struct | fr_dcursor_s |
struct | fr_dcursor_stack_t |
Macros | |
#define | FR_DCURSOR(_name) _name ## _dcursor_t |
Expands to the type name used for the dcursor wrapper structure. More... | |
#define | FR_DCURSOR_COPY(_name) _name ## _copy_t |
Expands to the type name used for the dcursor copy function type. More... | |
#define | FR_DCURSOR_DLIST_TYPES(_name, _list_name, _element_type) |
Define type specific wrapper structs for dcursors. More... | |
#define | FR_DCURSOR_EVAL(_name) _name ## _eval_t |
Expands to the type name used for the dcursor evaluator type. More... | |
#define | FR_DCURSOR_FUNCS(_name, _list_name, _element_type) |
Define type specific wrapper functions for dcursors. More... | |
#define | fr_dcursor_init(_cursor, _head) |
Initialise a cursor. More... | |
#define | FR_DCURSOR_INSERT(_name) _name ## _insert_t |
Expands to the type name used for the dcursor insert function type. More... | |
#define | FR_DCURSOR_ITER(_name) _name ## _iter_t |
Expands to the type name used for the dcursor iterator type. More... | |
#define | fr_dcursor_iter_init(_cursor, _head, _iter, _peek, _uctx) |
Initialise a cursor with a custom iterator. More... | |
#define | fr_dcursor_iter_mod_init(_cursor, _list, _iter, _peek, _iter_uctx, _insert, _remove, _mod_uctx) |
Initialise a cursor with a custom iterator. More... | |
#define | fr_dcursor_reinit(_cursor, _head) |
re-initialise a cursor, changing its list More... | |
#define | FR_DCURSOR_REMOVE(_name) _name ## _remove_t |
Expands to the type name used for the dcursor remove function type. More... | |
#define | VALIDATE(_item) do { if (cursor->dlist->type && (_item)) _talloc_get_type_abort(_item, cursor->dlist->type, __location__); } while (0) |
Typedefs | |
typedef void(* | fr_dcursor_copy_t) (fr_dcursor_t *out, fr_dcursor_t const *in) |
Copy callback for duplicating complex dcursor state. More... | |
typedef bool(* | fr_dcursor_eval_t) (void const *item, void const *uctx) |
Type of evaluation functions to pass to the fr_dcursor_filter_*() functions. More... | |
typedef int(* | fr_dcursor_insert_t) (fr_dlist_head_t *list, void *to_insert, void *uctx) |
Callback for performing additional actions on insert. More... | |
typedef void *(* | fr_dcursor_iter_t) (fr_dlist_head_t *list, void *to_eval, void *uctx) |
Callback for implementing custom iterators. More... | |
typedef int(* | fr_dcursor_remove_t) (fr_dlist_head_t *list, void *to_delete, void *uctx) |
Callback for performing additional actions on removal. More... | |
typedef struct fr_dcursor_s | fr_dcursor_t |
Functions | |
static void * | _fr_dcursor_init (fr_dcursor_t *cursor, fr_dlist_head_t const *head, fr_dcursor_iter_t iter, fr_dcursor_iter_t peek, void const *iter_uctx, fr_dcursor_insert_t insert, fr_dcursor_remove_t remove, void const *mod_uctx, bool is_const) |
Setup a cursor to iterate over attribute items in dlists. More... | |
static void | _fr_dcursor_list_reinit (fr_dcursor_t *cursor, fr_dlist_head_t const *head, bool is_const) |
CC_NO_UBSAN (function) static inline void *dcursor_next(fr_dcursor_t *cursor | |
Internal function to get the next item. More... | |
static void * | dcursor_current_set (fr_dcursor_t *cursor, void *current) |
If current is set to a NULL pointer, we record that fact. More... | |
static int | fr_dcursor_append (fr_dcursor_t *cursor, void *v) |
Insert a single item at the end of the list. More... | |
static void | fr_dcursor_copy (fr_dcursor_t *out, fr_dcursor_t const *in) |
Copy cursor parameters and state. More... | |
static void | fr_dcursor_copy_iter (fr_dcursor_t *out, fr_dcursor_t const *in) |
Copy a read-only iterator from a parent to a child cursor. More... | |
static void * | fr_dcursor_current (fr_dcursor_t *cursor) |
Return the item the cursor current points to. More... | |
return | fr_dcursor_filter_next (cursor, eval, uctx) |
static void | fr_dcursor_free_item (fr_dcursor_t *cursor) |
talloc_free the current item More... | |
static void | fr_dcursor_free_list (fr_dcursor_t *cursor) |
Free the current item and all items after it. More... | |
static void * | fr_dcursor_head (fr_dcursor_t *cursor) |
Rewind cursor to the start of the list. More... | |
static int | fr_dcursor_insert (fr_dcursor_t *cursor, void *v) |
Insert directly after the current item. More... | |
void * | fr_dcursor_intersect_head (fr_dcursor_t *a, fr_dcursor_t *b) |
Return the first item matching the iterator in cursor a and cursor b. More... | |
void * | fr_dcursor_intersect_next (fr_dcursor_t *a, fr_dcursor_t *b) |
Return the next item matching the iterator in cursor a and cursor b. More... | |
static void * | fr_dcursor_list_next_peek (fr_dcursor_t *cursor) |
Returns the next list item without advancing the cursor. More... | |
static void | fr_dcursor_merge (fr_dcursor_t *cursor, fr_dcursor_t *to_append) |
Moves items from one cursor to another. More... | |
static void * | fr_dcursor_next (fr_dcursor_t *cursor) |
Advanced the cursor to the next item. More... | |
static void * | fr_dcursor_next_peek (fr_dcursor_t *cursor) |
Return the next iterator item without advancing the cursor. More... | |
static int | fr_dcursor_prepend (fr_dcursor_t *cursor, void *v) |
Insert a single item at the start of the list. More... | |
static void * | fr_dcursor_remove (fr_dcursor_t *cursor) |
Remove the current item. More... | |
static void * | fr_dcursor_replace (fr_dcursor_t *cursor, void *r) |
Replace the current item. More... | |
static void * | fr_dcursor_set_current (fr_dcursor_t *cursor, void *item) |
Set the cursor to a specified item. More... | |
static fr_dcursor_stack_t * | fr_dcursor_stack_alloc (TALLOC_CTX *ctx, uint8_t depth) |
Allocate a stack of cursors for traversing trees. More... | |
static void * | fr_dcursor_tail (fr_dcursor_t *cursor) |
Wind cursor to the tail item in the list. More... | |
if (!iter) | |
if (eval(item, uctx)) return item | |
VALIDATE (current) | |
VALIDATE (next) | |
while ((item=fr_dcursor_current(cursor)) &&!eval(item, uctx)) | |
while (item &&!eval(item, uctx)) | |
Variables | |
fr_dcursor_iter_t void * | current |
do | |
fr_dcursor_eval_t | eval |
return | item = fr_dcursor_head(cursor) |
fr_dcursor_iter_t | iter |
next = iter(cursor->dlist, current, cursor->iter_uctx) | |
fr_dcursor_eval_t void const * | uctx |
Functions to iterate over a sets and subsets of items stored in dlists.
Definition in file dcursor.h.
struct fr_dcursor_s |
Data Fields | ||
---|---|---|
bool | at_end | We're at the end of the list. |
fr_dcursor_copy_t | copy | Copy dcursor state. |
void * | current | The current item in the dlist. |
fr_dlist_head_t * | dlist | Head of the doubly linked list being iterated over. |
fr_dcursor_insert_t | insert | Callback function on insert. |
bool | is_const | The list we're iterating over is immutable. |
fr_dcursor_iter_t | iter | Iterator function. |
void * | iter_uctx | to pass to iterator function. |
void * | mod_uctx | to pass to modification functions. |
fr_dcursor_iter_t | peek |
Distinct "peek" function. This is sometimes necessary for iterators with complex state. |
fr_dcursor_remove_t | remove | Callback function on delete. |
struct fr_dcursor_stack_t |
Data Fields | ||
---|---|---|
fr_dcursor_t | cursor[] | Stack of cursors. |
uint8_t | depth | Which cursor is currently in use. |
#define FR_DCURSOR | ( | _name | ) | _name ## _dcursor_t |
#define FR_DCURSOR_COPY | ( | _name | ) | _name ## _copy_t |
#define FR_DCURSOR_DLIST_TYPES | ( | _name, | |
_list_name, | |||
_element_type | |||
) |
Define type specific wrapper structs for dcursors.
[in] | _name | Prefix we add to type-specific structures. |
[in] | _list_name | The identifier used for type qualifying dlists. Should be the same as that use for |
[in] | _element_type | Type of element in the dlists. |
#define FR_DCURSOR_EVAL | ( | _name | ) | _name ## _eval_t |
#define FR_DCURSOR_FUNCS | ( | _name, | |
_list_name, | |||
_element_type | |||
) |
Define type specific wrapper functions for dcursors.
[in] | _name | Prefix we add to type-specific dcursor functions. |
[in] | _list_name | Prefix for type-specific dlist used by this dcursor. |
[in] | _element_type | Type of structure that'll be inserted into the dlist and returned by the dcursor. |
#define fr_dcursor_init | ( | _cursor, | |
_head | |||
) |
Initialise a cursor.
[in] | _cursor | to initialise. |
[in] | _head | of item list. |
#define FR_DCURSOR_INSERT | ( | _name | ) | _name ## _insert_t |
#define FR_DCURSOR_ITER | ( | _name | ) | _name ## _iter_t |
#define fr_dcursor_iter_init | ( | _cursor, | |
_head, | |||
_iter, | |||
_peek, | |||
_uctx | |||
) |
Initialise a cursor with a custom iterator.
[in] | _cursor | to initialise. |
[in] | _head | of item list. |
[in] | _iter | function. |
[in] | _peek | function. If NULL _iter will be used for peeking. |
[in] | _uctx | _iter function _uctx. |
#define fr_dcursor_iter_mod_init | ( | _cursor, | |
_list, | |||
_iter, | |||
_peek, | |||
_iter_uctx, | |||
_insert, | |||
_remove, | |||
_mod_uctx | |||
) |
Initialise a cursor with a custom iterator.
[in] | _cursor | to initialise. |
[in] | _list | to iterate over. |
[in] | _iter | function. |
[in] | _peek | function. If NULL _iter will be used for peeking. |
[in] | _iter_uctx | _iter function _uctx. |
[in] | _insert | function. |
[in] | _remove | function. |
[in] | _mod_uctx | _insert and _remove function _uctx. |
#define fr_dcursor_reinit | ( | _cursor, | |
_head | |||
) |
re-initialise a cursor, changing its list
[in] | _cursor | to re-initialise. |
[in] | _head | of item list. |
#define FR_DCURSOR_REMOVE | ( | _name | ) | _name ## _remove_t |
typedef void(* fr_dcursor_copy_t) (fr_dcursor_t *out, fr_dcursor_t const *in) |
Type of evaluation functions to pass to the fr_dcursor_filter_*() functions.
[in] | item | the item to be evaluated |
[in] | uctx | context that may assist with evaluation |
typedef int(* fr_dcursor_insert_t) (fr_dlist_head_t *list, void *to_insert, void *uctx) |
Callback for performing additional actions on insert.
[in] | list | head of the dlist. |
[in] | to_insert | The item being inserted into the cursor. |
[in] | uctx | passed to fr_dcursor_init. |
typedef void*(* fr_dcursor_iter_t) (fr_dlist_head_t *list, void *to_eval, void *uctx) |
Callback for implementing custom iterators.
[in] | list | head of the dlist. |
[in] | to_eval | the next item in the list. Iterator should check to see if it matches the iterator's filter, and if it doesn't iterate over the items until one is found that does. |
[in] | uctx | passed to fr_dcursor_init. |
typedef int(* fr_dcursor_remove_t) (fr_dlist_head_t *list, void *to_delete, void *uctx) |
Callback for performing additional actions on removal.
[in] | list | head of the dlist. |
[in] | to_delete | The item being removed from the cursor. |
[in] | uctx | passed to fr_dcursor_init. |
typedef struct fr_dcursor_s fr_dcursor_t |
|
inlinestatic |
Setup a cursor to iterate over attribute items in dlists.
[in] | cursor | Where to initialise the cursor (uses existing structure). |
[in] | head | of dlist. |
[in] | iter | Iterator callback. |
[in] | peek | Iterator callback that should not modify iterator state. |
[in] | iter_uctx | to pass to iterator function. |
[in] | insert | Callback for inserts. |
[in] | remove | Callback for removals. |
[in] | mod_uctx | to pass to modification functions. |
[in] | is_const | Don't allow modification of the underlying list. |
Definition at line 759 of file dcursor.h.
|
inlinestatic |
CC_NO_UBSAN | ( | function | ) |
Internal function to get the next item.
Return the next item, starting with the current item, that satisfies an evaluation function.
Return the first item that satisfies an evaluation function.
Return the next item, skipping the current item, that satisfies an evaluation function.
[in] | cursor | to operate on. |
[in] | iter | function. |
[in] | current | attribute. |
[in] | cursor | to operate on |
[in] | eval | evaluation function |
[in] | uctx | context for the evaluation function |
[in] | cursor | to operate on |
[in] | eval | evaluation function |
[in] | uctx | context for the evaluation function |
|
inlinestatic |
|
inlinestatic |
Insert a single item at the end of the list.
[in] | cursor | to operate on. |
[in] | v | to insert. |
Definition at line 406 of file dcursor.h.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Insert directly after the current item.
[in] | cursor | to operate on. |
[in] | v | Item to insert. |
Definition at line 435 of file dcursor.h.
void* fr_dcursor_intersect_head | ( | fr_dcursor_t * | a, |
fr_dcursor_t * | b | ||
) |
Return the first item matching the iterator in cursor a and cursor b.
If a and b are not currently set to the same item, b will be reset, and wound to the item before a's current item.
[in] | a | First cursor. |
[in] | b | Second cursor. |
Definition at line 47 of file dcursor.c.
void* fr_dcursor_intersect_next | ( | fr_dcursor_t * | a, |
fr_dcursor_t * | b | ||
) |
Return the next item matching the iterator in cursor a and cursor b.
If a and b are not currently set to the same item, b will be reset, and wound to the item before a's current item.
The purpose of this function is to return items that match both iterators.
[in] | a | First cursor. |
[in] | b | Second cursor. |
Definition at line 76 of file dcursor.c.
|
inlinestatic |
Returns the next list item without advancing the cursor.
[in] | cursor | to operator on. |
|
inlinestatic |
Moves items from one cursor to another.
Move multiple items from one cursor to another.
[in] | cursor | to operate on. |
[in] | to_append | Items to append. |
Definition at line 520 of file dcursor.h.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Insert a single item at the start of the list.
Insert a void at the start of the list.
cursor | to operate on. |
v | to insert. |
Definition at line 376 of file dcursor.h.
|
inlinestatic |
Remove the current item.
The current item will be set to the one after the item being removed. An example check and remove loop:
[in] | cursor | to remove the current item from. |
Definition at line 480 of file dcursor.h.
|
inlinestatic |
Replace the current item.
After replacing the current item, the cursor will be rewound, and the next item selected by the iterator function will become current.
[in] | cursor | to replace the current item in. |
[in] | r | item to insert. |
Definition at line 610 of file dcursor.h.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
VALIDATE | ( | current | ) |
VALIDATE | ( | next | ) |
while | ( | (item=fr_dcursor_current(cursor)) &&!eval(item, uctx) | ) |
while | ( | item &&! | evalitem, uctx | ) |
fr_dcursor_iter_t void* current |
do |
fr_dcursor_eval_t eval |
return item = fr_dcursor_head(cursor) |
fr_dcursor_iter_t iter |
fr_dcursor_eval_t void const * uctx |