The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
xlat_ctx.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  * $Id: abcd2266c4669fb3e24f544e29406e3eb6455616 $
20  *
21  * @file lib/unlang/xlat_ctx.h
22  * @brief xlat ephemeral argument passing structures
23  *
24  * @copyright 2021 Arran Cudbard-Bell <a.cudbardb@freeradius.org>
25  */
26 RCSIDH(xlat_ctx_h, "$Id: abcd2266c4669fb3e24f544e29406e3eb6455616 $")
27 
28 #include <freeradius-devel/server/module_ctx.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /* So we don't need to include xlat.h */
35 typedef struct xlat_exp_s xlat_exp_t;
36 typedef struct xlat_exp_head_s xlat_exp_head_t;
37 
38 /** An xlat calling ctx
39  *
40  * This provides optional arguments to xlat functions.
41  */
42 typedef struct {
43  void const *inst; //!< xlat instance data.
44  void *thread; //!< xlat threadinstance data.
45  module_ctx_t const *mctx; //!< Synthesised module calling ctx.
46  void *env_data; //!< Expanded call env data.
47  void *rctx; //!< Resume context.
48 } xlat_ctx_t;
49 
50 /** An xlat instantiation ctx
51  *
52  * This provides optional arguments to xlat functions.
53  */
54 typedef struct {
55  void *inst; //!< xlat instance data to populate.
56  xlat_exp_t *ex; //!< Tokenized expression to use in expansion.
57  module_inst_ctx_t const *mctx; //!< Synthesised module calling ctx.
58  void *uctx; //!< Passed to the registration function.
60 
61 /** An xlat thread instantiation ctx
62  *
63  * This provides optional arguments to xlat functions.
64  */
65 typedef struct {
66  void const *inst; //!< xlat instance data.
67  void *thread; //!< xlat thread instance data to populate.
68  xlat_exp_t const *ex; //!< Tokenized expression to use in expansion.
69  module_ctx_t const *mctx; //!< Synthesised module calling ctx.
70  fr_event_list_t *el; //!< To register any I/O handlers or timers against.
71  void *uctx; //!< Passed to the registration function.
73 
74 /** Wrapper to create a xlat_ctx_t as a compound literal
75  *
76  * This is used so that the compiler will flag any uses of (xlat_ctx_t)
77  * which don't set the required fields. Additional arguments should be added
78  * to this macro whenever the xlat_ctx_t fields are altered.
79  *
80  * @param[in] _inst Instance data of the module being called.
81  * @param[in] _thread Instance data of the thread being called.
82  * @param[in] _mctx Module ctx.
83  * @param[in] _env_data Expanded call env.
84  * @param[in] _rctx resume ctx data.
85  */
86 #define XLAT_CTX(_inst, _thread, _mctx, _env_data, _rctx) &(xlat_ctx_t){ .inst = _inst, .thread = _thread, \
87  .mctx = _mctx, .env_data = _env_data, .rctx = _rctx }
88 
89 /** Wrapper to create a xlat_inst_ctx_t as a compound literal
90  *
91  * This is used so that the compiler will flag any uses of (xlat_inst_ctx_t)
92  * which don't set the required fields. Additional arguments should be added
93  * to this macro whenever the xlat_inst_ctx_t fields are altered.
94  *
95  * @param[in] _inst Instance data of the module being called.
96  * @param[in] _ex xlat expression to be evaluated by the instantiation function.
97  * @param[in] _mctx The module_inst_ctx_t from the parent module (if any).
98  * @param[in] _uctx passed when the instantiation function was registered.
99  */
100 #define XLAT_INST_CTX(_inst, _ex, _mctx, _uctx) &(xlat_inst_ctx_t){ .inst = _inst, .ex = _ex, .mctx = _mctx, .uctx = _uctx }
101 
102 /** Wrapper to create a xlat_thread_inst_ctx_t as a compound literal
103  *
104  * This is used so that the compiler will flag any uses of (xlat_thread_inst_ctx_t)
105  * which don't set the required fields. Additional arguments should be added
106  * to this macro whenever the xlat_thread_inst_ctx_t fields are altered.
107  *
108  * @param[in] _inst Instance data of the module being called.
109  * @param[in] _thread Instance data of the thread being called.
110  * @param[in] _ex xlat expression to be evaluated by the instantiation function.
111  * @param[in] _mctx The module_inst_ctx_t from the parent module (if any).
112  * @param[in] _el To register any I/O handlers or timers against.
113  * @param[in] _uctx passed when the instantiation function was registered.
114  */
115 #define XLAT_THREAD_INST_CTX(_inst, _thread, _ex, _mctx, _el, _uctx) &(xlat_thread_inst_ctx_t){ .inst = _inst, .ex = _ex, .mctx = _mctx, .el = _el, .uctx = _uctx }
116 
117 #ifdef __cplusplus
118 }
119 #endif
#define RCSIDH(h, id)
Definition: build.h:445
Stores all information relating to an event list.
Definition: event.c:411
Temporary structure to hold arguments for module calls.
Definition: module_ctx.h:41
Temporary structure to hold arguments for instantiation calls.
Definition: module_ctx.h:51
void * rctx
Resume context.
Definition: xlat_ctx.h:47
void * thread
xlat threadinstance data.
Definition: xlat_ctx.h:44
module_inst_ctx_t const * mctx
Synthesised module calling ctx.
Definition: xlat_ctx.h:57
void const * inst
xlat instance data.
Definition: xlat_ctx.h:66
void * uctx
Passed to the registration function.
Definition: xlat_ctx.h:71
module_ctx_t const * mctx
Synthesised module calling ctx.
Definition: xlat_ctx.h:45
void * env_data
Expanded call env data.
Definition: xlat_ctx.h:46
xlat_exp_t const * ex
Tokenized expression to use in expansion.
Definition: xlat_ctx.h:68
void * inst
xlat instance data to populate.
Definition: xlat_ctx.h:55
void const * inst
xlat instance data.
Definition: xlat_ctx.h:43
fr_event_list_t * el
To register any I/O handlers or timers against.
Definition: xlat_ctx.h:70
module_ctx_t const * mctx
Synthesised module calling ctx.
Definition: xlat_ctx.h:69
xlat_exp_t * ex
Tokenized expression to use in expansion.
Definition: xlat_ctx.h:56
void * thread
xlat thread instance data to populate.
Definition: xlat_ctx.h:67
void * uctx
Passed to the registration function.
Definition: xlat_ctx.h:58
An xlat calling ctx.
Definition: xlat_ctx.h:42
An xlat instantiation ctx.
Definition: xlat_ctx.h:54
An xlat thread instantiation ctx.
Definition: xlat_ctx.h:65
An xlat expansion node.
Definition: xlat_priv.h:147