The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
tmpl_dcursor.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17 
18 
19 #include <freeradius-devel/server/tmpl.h>
20 #include <freeradius-devel/util/dcursor.h>
21 
22 RCSIDH(tmpl_dcursor_t, "$Id: 957d77248c54c0a7cec4c978cb433a8afd358fd9 $")
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
30 
31 /** Callback function for populating missing pair
32  *
33  * @param[in] parent to allocate the new pair in.
34  * @param[in] cursor to append the pair to.
35  * @param[in] da of the attribute to create.
36  * @param[in] uctx context data.
37  * @return newly allocated pair.
38  */
39 typedef fr_pair_t *(*tmpl_dcursor_build_t)(fr_pair_t *parent, fr_dcursor_t *cursor, fr_dict_attr_t const *da, void *uctx);
40 
41 /** State for traversing an attribute reference
42  *
43  */
45  fr_dlist_t entry; //!< Entry in the dlist that forms the evaluation stack.
46  tmpl_attr_t const *ar; //!< Attribute reference this state
47  ///< entry is associated with. Mainly for debugging.
48  TALLOC_CTX *list_ctx; //!< Track where we should be allocating attributes.
49 
50  bool seen; //!< Whether we've seen an attribute at this level of
51  ///< evaluation already. This is mainly used where
52  ///< the build cursor is used.
53 
54  fr_dcursor_t cursor; //!< Cursor to track where we are in the list in case
55  ///< we're doing counts.
56 };
57 
58 /** Maintains state between cursor calls
59  *
60  */
62  TALLOC_CTX *ctx; //!< Temporary allocations go here.
63  TALLOC_CTX *pool; //!< Temporary pool.
64  tmpl_t const *vpt; //!< tmpl we're evaluating.
65 
66  request_t *request; //!< Result of following the request references.
67 
68  fr_pair_list_t *list; //!< List within the request.
69 
70  fr_dlist_head_t nested; //!< Nested state. These are allocated when we
71  ///< need to maintain state between multiple
72  ///< cursor calls for a particular attribute
73  ///< reference.
74  ///< This forms a stack of tmpl_dcursor_nested_t
75  ///< and tracks where we are in evaluation at
76  ///< all levels.
77 
78  tmpl_dcursor_nested_t leaf; //!< Pre-allocated leaf state. We always need
79  ///< one of these so it doesn't make sense to
80  ///< allocate it later.
81 
82  tmpl_dcursor_build_t build; //!< Callback to build missing pairs.
83  void *uctx; //!< Context for building new pairs.
84 };
85 
87  fr_dcursor_t *cursor,
88  request_t *request, fr_pair_t *list, tmpl_t const *vpt,
89  tmpl_dcursor_build_t build, void *uctx);
90 
91 fr_pair_t *_tmpl_dcursor_init(int *err, TALLOC_CTX *ctx, tmpl_dcursor_ctx_t *cc,
92  fr_dcursor_t *cursor, request_t *request,
93  tmpl_t const *vpt, tmpl_dcursor_build_t build, void *uctx);
94 
96 
98 
99 #define tmpl_dcursor_init(_err, _ctx, _cc, _cursor, _request, _vpt) \
100  _tmpl_dcursor_init(_err, _ctx, _cc, _cursor, _request, _vpt, NULL, NULL)
101 
102 #define tmpl_dcursor_build_init(_err, _ctx, _cc, _cursor, _request, _vpt, _build, _uctx) \
103  _tmpl_dcursor_init(_err, _ctx, _cc, _cursor, _request, _vpt, _build, _uctx)
#define RCSIDH(h, id)
Definition: build.h:445
#define UNUSED
Definition: build.h:313
static fr_slen_t err
Definition: dict.h:645
Head of a doubly linked list.
Definition: dlist.h:51
Entry in a doubly linked list.
Definition: dlist.h:41
static fr_slen_t vpt
Definition: tmpl.h:1260
An element in a list of nested attribute references.
Definition: tmpl.h:427
Stores an attribute, a value and various bits of other data.
Definition: pair.h:68
fr_pair_t * tmpl_dcursor_init_relative(int *err, TALLOC_CTX *ctx, tmpl_dcursor_ctx_t *cc, fr_dcursor_t *cursor, request_t *request, fr_pair_t *list, tmpl_t const *vpt, tmpl_dcursor_build_t build, void *uctx)
Initialise a fr_dcursor_t at the specified point in a pair tree.
Definition: tmpl_dcursor.c:309
TALLOC_CTX * ctx
Temporary allocations go here.
Definition: tmpl_dcursor.h:62
tmpl_dcursor_nested_t leaf
Pre-allocated leaf state.
Definition: tmpl_dcursor.h:78
tmpl_dcursor_build_t build
Callback to build missing pairs.
Definition: tmpl_dcursor.h:82
fr_pair_list_t * list
List within the request.
Definition: tmpl_dcursor.h:68
fr_pair_t * _tmpl_dcursor_init(int *err, TALLOC_CTX *ctx, tmpl_dcursor_ctx_t *cc, fr_dcursor_t *cursor, request_t *request, tmpl_t const *vpt, tmpl_dcursor_build_t build, void *uctx)
Initialise a fr_dcursor_t to the fr_pair_t specified by a tmpl_t.
Definition: tmpl_dcursor.c:393
fr_dcursor_t cursor
Cursor to track where we are in the list in case we're doing counts.
Definition: tmpl_dcursor.h:54
fr_dlist_t entry
Entry in the dlist that forms the evaluation stack.
Definition: tmpl_dcursor.h:45
fr_pair_t *(* tmpl_dcursor_build_t)(fr_pair_t *parent, fr_dcursor_t *cursor, fr_dict_attr_t const *da, void *uctx)
Callback function for populating missing pair.
Definition: tmpl_dcursor.h:39
bool seen
Whether we've seen an attribute at this level of evaluation already.
Definition: tmpl_dcursor.h:50
fr_pair_t * tmpl_dcursor_pair_build(fr_pair_t *parent, fr_dcursor_t *cursor, fr_dict_attr_t const *da, UNUSED void *uctx)
Simple pair building callback for use with tmpl_dcursors.
Definition: tmpl_dcursor.c:447
fr_dlist_head_t nested
Nested state.
Definition: tmpl_dcursor.h:70
tmpl_t const * vpt
tmpl we're evaluating.
Definition: tmpl_dcursor.h:64
void tmpl_dcursor_clear(tmpl_dcursor_ctx_t *cc)
Clear any temporary state allocations.
Definition: tmpl_dcursor.c:419
request_t * request
Result of following the request references.
Definition: tmpl_dcursor.h:66
TALLOC_CTX * pool
Temporary pool.
Definition: tmpl_dcursor.h:63
void * uctx
Context for building new pairs.
Definition: tmpl_dcursor.h:83
TALLOC_CTX * list_ctx
Track where we should be allocating attributes.
Definition: tmpl_dcursor.h:48
tmpl_attr_t const * ar
Attribute reference this state entry is associated with.
Definition: tmpl_dcursor.h:46
Maintains state between cursor calls.
Definition: tmpl_dcursor.h:61
State for traversing an attribute reference.
Definition: tmpl_dcursor.h:44
static fr_slen_t parent
Definition: pair.h:844