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: 30f8375e3102fa8fbf97605bc97963e520dd9395 $")
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  size_t num; //!< which attribute number we are looking at
57 };
58 
59 /** Maintains state between cursor calls
60  *
61  */
63  TALLOC_CTX *ctx; //!< Temporary allocations go here.
64  TALLOC_CTX *pool; //!< Temporary pool.
65  tmpl_t const *vpt; //!< tmpl we're evaluating.
66 
67  request_t *request; //!< Result of following the request references.
68 
69  fr_pair_list_t *list; //!< List within the request.
70 
71  fr_dlist_head_t nested; //!< Nested state. These are allocated when we
72  ///< need to maintain state between multiple
73  ///< cursor calls for a particular attribute
74  ///< reference.
75  ///< This forms a stack of tmpl_dcursor_nested_t
76  ///< and tracks where we are in evaluation at
77  ///< all levels.
78 
79  tmpl_dcursor_nested_t leaf; //!< Pre-allocated leaf state. We always need
80  ///< one of these so it doesn't make sense to
81  ///< allocate it later.
82 
83  tmpl_dcursor_build_t build; //!< Callback to build missing pairs.
84  void *uctx; //!< Context for building new pairs.
85 };
86 
88  fr_dcursor_t *cursor,
89  request_t *request, fr_pair_t *list, tmpl_t const *vpt,
90  tmpl_dcursor_build_t build, void *uctx);
91 
92 fr_pair_t *_tmpl_dcursor_init(int *err, TALLOC_CTX *ctx, tmpl_dcursor_ctx_t *cc,
93  fr_dcursor_t *cursor, request_t *request,
94  tmpl_t const *vpt, tmpl_dcursor_build_t build, void *uctx);
95 
97 
99 
100 #define tmpl_dcursor_init(_err, _ctx, _cc, _cursor, _request, _vpt) \
101  _tmpl_dcursor_init(_err, _ctx, _cc, _cursor, _request, _vpt, NULL, NULL)
102 
103 #define tmpl_dcursor_build_init(_err, _ctx, _cc, _cursor, _request, _vpt, _build, _uctx) \
104  _tmpl_dcursor_init(_err, _ctx, _cc, _cursor, _request, _vpt, _build, _uctx)
105 
#define RCSIDH(h, id)
Definition: build.h:482
#define UNUSED
Definition: build.h:313
fr_dcursor_eval_t void const * uctx
Definition: dcursor.h:546
static fr_slen_t err
Definition: dict.h:821
Head of a doubly linked list.
Definition: dlist.h:51
Entry in a doubly linked list.
Definition: dlist.h:41
long int ssize_t
Definition: merged_model.c:24
static fr_slen_t vpt
Definition: tmpl.h:1272
An element in a list of nested attribute references.
Definition: tmpl.h:439
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:385
TALLOC_CTX * ctx
Temporary allocations go here.
Definition: tmpl_dcursor.h:63
tmpl_dcursor_nested_t leaf
Pre-allocated leaf state.
Definition: tmpl_dcursor.h:79
tmpl_dcursor_build_t build
Callback to build missing pairs.
Definition: tmpl_dcursor.h:83
ssize_t tmpl_dcursor_print(fr_sbuff_t *out, tmpl_dcursor_ctx_t const *cc)
Definition: tmpl_dcursor.c:781
fr_pair_list_t * list
List within the request.
Definition: tmpl_dcursor.h:69
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:469
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:523
size_t num
which attribute number we are looking at
Definition: tmpl_dcursor.h:56
fr_dlist_head_t nested
Nested state.
Definition: tmpl_dcursor.h:71
tmpl_t const * vpt
tmpl we're evaluating.
Definition: tmpl_dcursor.h:65
void tmpl_dcursor_clear(tmpl_dcursor_ctx_t *cc)
Clear any temporary state allocations.
Definition: tmpl_dcursor.c:495
request_t * request
Result of following the request references.
Definition: tmpl_dcursor.h:67
TALLOC_CTX * pool
Temporary pool.
Definition: tmpl_dcursor.h:64
void * uctx
Context for building new pairs.
Definition: tmpl_dcursor.h:84
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:62
State for traversing an attribute reference.
Definition: tmpl_dcursor.h:44
static fr_slen_t parent
Definition: pair.h:851
static size_t char ** out
Definition: value.h:997