All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions
cursor.c File Reference

Functions to iterate over collections of VALUE_PAIRs. More...

#include <freeradius-devel/libradius.h>
+ Include dependency graph for cursor.c:

Go to the source code of this file.

Functions

void fr_cursor_copy (vp_cursor_t *out, vp_cursor_t *in)
 Copy a cursor. More...
 
VALUE_PAIRfr_cursor_current (vp_cursor_t *cursor)
 Return the VALUE_PAIR the cursor current points to. More...
 
void fr_cursor_end (vp_cursor_t *cursor)
 Moves cursor past the last attribute to the end. More...
 
VALUE_PAIRfr_cursor_first (vp_cursor_t *cursor)
 Rewind cursor to the start of the list. More...
 
void fr_cursor_free (vp_cursor_t *cursor)
 Free the current pair and all pairs after it. More...
 
VALUE_PAIRfr_cursor_init (vp_cursor_t *cursor, VALUE_PAIR *const *const_vp)
 Setup a cursor to iterate over attribute pairs. More...
 
void fr_cursor_insert (vp_cursor_t *cursor, VALUE_PAIR *vp)
 Insert a single VALUE_PAIR at the end of the list. More...
 
VALUE_PAIRfr_cursor_last (vp_cursor_t *cursor)
 Wind cursor to the last pair in the list. More...
 
void fr_cursor_merge (vp_cursor_t *cursor, VALUE_PAIR *add)
 Merges multiple VALUE_PAIR into the cursor. More...
 
VALUE_PAIRfr_cursor_next (vp_cursor_t *cursor)
 Advanced the cursor to the next VALUE_PAIR. More...
 
VALUE_PAIRfr_cursor_next_by_da (vp_cursor_t *cursor, fr_dict_attr_t const *da, int8_t tag)
 Iterate over attributes of a given DA in the pairlist. More...
 
VALUE_PAIRfr_cursor_next_by_num (vp_cursor_t *cursor, unsigned int vendor, unsigned int attr, int8_t tag)
 Iterate over a collection of VALUE_PAIRs of a given type in the pairlist. More...
 
VALUE_PAIRfr_cursor_next_peek (vp_cursor_t *cursor)
 Return the next VALUE_PAIR without advancing the cursor. More...
 
VALUE_PAIRfr_cursor_remove (vp_cursor_t *cursor)
 Remove the current pair. More...
 
VALUE_PAIRfr_cursor_replace (vp_cursor_t *cursor, VALUE_PAIR *new)
 Replace the current pair. More...
 
static VALUE_PAIRfr_cursor_update (vp_cursor_t *cursor, VALUE_PAIR *vp)
 Internal function to update cursor state. More...
 

Detailed Description

Functions to iterate over collections of VALUE_PAIRs.

Id:
cccbec4a5eaa03fe6118d2bea22da21931e7d07a
Note
Do not modify collections of VALUE_PAIRs pointed to be a cursor with none fr_cursor_* functions, during the lifetime of that cursor.
Author
Arran Cudbard-Bell a.cud.nosp@m.bard.nosp@m.b@fre.nosp@m.erad.nosp@m.ius.o.nosp@m.rg

Definition in file cursor.c.

Function Documentation

void fr_cursor_copy ( vp_cursor_t out,
vp_cursor_t in 
)

Copy a cursor.

Parameters
inCursor to copy.
outWhere to copy the cursor to.

Definition at line 95 of file cursor.c.

VALUE_PAIR* fr_cursor_current ( vp_cursor_t cursor)

Return the VALUE_PAIR the cursor current points to.

Parameters
cursorto operate on.
Returns
the VALUE_PAIR the cursor currently points to.

Definition at line 304 of file cursor.c.

+ Here is the caller graph for this function:

void fr_cursor_end ( vp_cursor_t cursor)

Moves cursor past the last attribute to the end.

Primarily useful for setting up the cursor for freeing attributes added during the execution of a function, which later errors out, requiring only the attribute(s) that it added to be freed, and the attributes already present in the list to remain untouched.

int my_cursor_insert_func(vp_cursor_t *cursor)
{
fr_cursor_end(cursor);
fr_cursor_insert(cursor, fr_pair_alloc_by_num(NULL, 0, PW_MESSAGE_AUTHENTICATOR));
if (bad_thing) {
fr_cursor_free(cursor);
return -1;
}
return 0;
}
Parameters
cursorto operate on.

Definition at line 164 of file cursor.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

VALUE_PAIR* fr_cursor_first ( vp_cursor_t cursor)

Rewind cursor to the start of the list.

Parameters
cursorto operate on.
Returns
VALUE_PAIR at the start of the list.

Definition at line 105 of file cursor.c.

+ Here is the caller graph for this function:

void fr_cursor_free ( vp_cursor_t cursor)

Free the current pair and all pairs after it.

Note
Use fr_cursor_remove and talloc_free to free single pairs.

Will move the cursor back one, then free the current pair and all VALUE_PAIRs after it.

Usually used in conjunction with fr_cursor_end and fr_cursor_insert.

Parameters
cursorto free pairs in.

Definition at line 528 of file cursor.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

VALUE_PAIR* fr_cursor_init ( vp_cursor_t cursor,
VALUE_PAIR *const *  const_vp 
)

Setup a cursor to iterate over attribute pairs.

Parameters
cursorWhere to initialise the cursor (uses existing structure).
const_vpto start from.
Returns
the attribute pointed to by vp.

Definition at line 60 of file cursor.c.

+ Here is the caller graph for this function:

void fr_cursor_insert ( vp_cursor_t cursor,
VALUE_PAIR vp 
)

Insert a single VALUE_PAIR at the end of the list.

Note
Will not advance cursor position to new attribute, but will set cursor to this attribute, if it's the first one in the list.

Insert a VALUE_PAIR at the end of the list.

Parameters
cursorto operate on.
vpto insert.

Definition at line 321 of file cursor.c.

+ Here is the caller graph for this function:

VALUE_PAIR* fr_cursor_last ( vp_cursor_t cursor)

Wind cursor to the last pair in the list.

Parameters
cursorto operate on.
Returns
VALUE_PAIR at the end of the list.

Definition at line 126 of file cursor.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void fr_cursor_merge ( vp_cursor_t cursor,
VALUE_PAIR add 
)

Merges multiple VALUE_PAIR into the cursor.

Add multiple VALUE_PAIR from add to cursor.

Parameters
cursorto insert VALUE_PAIRs with
addone or more VALUE_PAIRs (may be NULL, which results in noop).

Definition at line 394 of file cursor.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

VALUE_PAIR* fr_cursor_next ( vp_cursor_t cursor)

Advanced the cursor to the next VALUE_PAIR.

Parameters
cursorto operate on.
Returns

Definition at line 263 of file cursor.c.

+ Here is the caller graph for this function:

VALUE_PAIR* fr_cursor_next_by_da ( vp_cursor_t cursor,
fr_dict_attr_t const *  da,
int8_t  tag 
)

Iterate over attributes of a given DA in the pairlist.

Find the next attribute of a given type. If no fr_cursor_next_by_* function has been called on a cursor before, or the previous call returned NULL, the search will start with the current attribute. Subsequent calls to fr_cursor_next_by_* functions will start the search from the previously matched attribute.

Note
fr_dict_attr_t pointers are compared, not the attribute numbers and vendors.
Parameters
cursorto operate on.
dato match.
tagto match. Either a tag number or TAG_ANY to match any tagged or untagged attribute, TAG_NONE to match attributes without tags.
Returns

Definition at line 237 of file cursor.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

VALUE_PAIR* fr_cursor_next_by_num ( vp_cursor_t cursor,
unsigned int  vendor,
unsigned int  attr,
int8_t  tag 
)

Iterate over a collection of VALUE_PAIRs of a given type in the pairlist.

Find the next attribute of a given type. If no fr_cursor_next_by_* function has been called on a cursor before, or the previous call returned NULL, the search will start with the current attribute. Subsequent calls to fr_cursor_next_by_* functions will start the search from the previously matched attribute.

Parameters
cursorto operate on.
attrnumber to match.
vendornumber to match (0 for none vendor attribute).
tagto match. Either a tag number or TAG_ANY to match any tagged or untagged attribute, TAG_NONE to match attributes without tags.
Returns

Definition at line 200 of file cursor.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

VALUE_PAIR* fr_cursor_next_peek ( vp_cursor_t cursor)

Return the next VALUE_PAIR without advancing the cursor.

Parameters
cursorto operate on.
Returns

Definition at line 294 of file cursor.c.

+ Here is the caller graph for this function:

VALUE_PAIR* fr_cursor_remove ( vp_cursor_t cursor)

Remove the current pair.

Todo:
this is really inefficient and should be fixed...

The current VP will be set to the one before the VP being removed, this is so the commonly used check and remove loop (below) works as expected.

for (vp = fr_cursor_init(&cursor, head);
vp;
vp = fr_cursor_next(&cursor) {
if (<condition>) {
vp = fr_cursor_remove(&cursor);
talloc_free(vp);
}
}
Parameters
cursorto remove the current pair from.
Returns

Definition at line 433 of file cursor.c.

+ Here is the caller graph for this function:

VALUE_PAIR* fr_cursor_replace ( vp_cursor_t cursor,
VALUE_PAIR new 
)

Replace the current pair.

Todo:
this is really inefficient and should be fixed...
Parameters
cursorto replace the current pair in.
newVALUE_PAIR to insert.
Returns

Definition at line 491 of file cursor.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static VALUE_PAIR* fr_cursor_update ( vp_cursor_t cursor,
VALUE_PAIR vp 
)
inlinestatic

Internal function to update cursor state.

Parameters
cursorto operate on.
vpto set current and found positions to.
Returns
value passed in as VALUE_PAIR.

Definition at line 38 of file cursor.c.

+ Here is the caller graph for this function: