The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
module_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: 1db004302cc4620d69a8ece0a5fdbb22f1ca6a86 $
20 *
21 * @file lib/server/module_ctx.h
22 * @brief Temporary argument structures for module calls.
23 *
24 * These get used in various places where we may not want to include
25 * the full module.h.
26 *
27 * @copyright 2021 Arran Cudbard-bell <a.cudbardb@freeradius.org>
28 */
29RCSIDH(module_ctx_h, "$Id: 1db004302cc4620d69a8ece0a5fdbb22f1ca6a86 $")
30
31#include <freeradius-devel/util/event.h>
32
33#ifdef __cplusplus
34extern "C" {
35#endif
37
38/** Temporary structure to hold arguments for module calls
39 *
40 */
41typedef struct {
42 module_instance_t const *mi; //!< Instance of the module being instantiated.
43 void *thread; //!< Thread specific instance data.
44 void *env_data; //!< Per call environment data.
45 void *rctx; //!< Resume ctx that a module previously set.
47
48/** Temporary structure to hold arguments for instantiation calls
49 */
50typedef struct {
51 module_instance_t *mi; //!< Instance of the module being instantiated.
53
54/** Temporary structure to hold arguments for detach calls
55 */
56typedef struct {
57 module_instance_t *mi; //!< Module instance to detach.
59
60/** Temporary structure to hold arguments for thread_instantiation calls
61 *
62 */
63typedef struct {
64 module_instance_t const *mi; //!< Instance of the module being instantiated.
65 ///< Must come first to allow cast between
66 ///< module_inst_ctx.
67 void *thread; //!< Thread instance data.
68 fr_event_list_t *el; //!< Event list to register any IO handlers
69 ///< and timers against.
71
72DIAG_OFF(unused-function)
73/** Allocate a module calling ctx on the heap based on an instance ctx
74 *
75 */
76static module_ctx_t *module_ctx_from_inst(TALLOC_CTX *ctx, module_inst_ctx_t const *mctx)
77{
78 module_ctx_t *nmctx;
79
80 nmctx = talloc_zero(ctx, module_ctx_t);
81 if (unlikely(!nmctx)) return NULL;
82 nmctx->mi = mctx->mi;
83
84 return nmctx;
85}
86
87/** Allocate a module calling ctx on the heap based on an instance ctx
88 *
89 */
91{
92 module_ctx_t *nmctx;
93
94 nmctx = talloc_zero(ctx, module_ctx_t);
95 if (unlikely(!nmctx)) return NULL;
96 nmctx->mi = mctx->mi;
97 nmctx->thread = mctx->thread;
98
99 return nmctx;
100}
101
102/** Duplicate a stack based module_ctx_t on the heap
103 *
104 */
105static module_ctx_t *module_ctx_dup(TALLOC_CTX *ctx, module_ctx_t const *mctx)
106{
107 module_ctx_t *nmctx;
108
109 nmctx = talloc_zero(ctx, module_ctx_t);
110 if (unlikely(!nmctx)) return NULL;
111 memcpy(nmctx, mctx, sizeof(*nmctx));
112
113 return nmctx;
114}
115DIAG_ON(unused-function)
116
117/** Wrapper to create a module_ctx_t as a compound literal
118 *
119 * This is used so that the compiler will flag any uses of (module_ctx_t)
120 * which don't set the required fields. Additional arguments should be added
121 * to this macro whenever the module_ctx_t fields are altered.
122 *
123 * @param[in] _mi of the module being called.
124 * @param[in] _thread instance of the module being called.
125 * @param[in] _env_data Call environment data.
126 * @param[in] _rctx Resume ctx (if any).
127 */
128#define MODULE_CTX(_mi, _thread, _env_data, _rctx) &(module_ctx_t){ .mi = _mi, .thread = _thread, .env_data = _env_data, .rctx = _rctx }
129
130/** Wrapper to create a module_ctx_t as a compound literal from a module_inst_ctx_t
131 *
132 * This is used so that the compiler will flag any uses of (module_ctx_t)
133 * which don't set the required fields. Additional arguments should be added
134 * to this macro whenever the module_ctx_t fields are altered.
135 *
136 * @param[in] _mctx to copy fields from.
137 */
138#define MODULE_CTX_FROM_INST(_mctx) &(module_ctx_t){ .mi = (_mctx)->mi }
139
140/** Wrapper to create a module_ctx_t as a compound literal from a module_inst_ctx_t
141 *
142 * This is used so that the compiler will flag any uses of (module_ctx_t)
143 * which don't set the required fields. Additional arguments should be added
144 * to this macro whenever the module_ctx_t fields are altered.
145 *
146 * @param[in] _mctx to copy fields from.
147 */
148#define MODULE_CTX_FROM_THREAD_INST(_mctx) &(module_ctx_t){ .mi = (_mctx)->mi, .thread = (_mctx)->thread, .env_data = (_mctx)->env_data }
149
150/** Wrapper to create a module_inst_ctx_t as a compound literal
151 *
152 * This is used so that the compiler will flag any uses of (module_inst_ctx_t)
153 * which don't set the required fields. Additional arguments should be added
154 * to this macro whenever the module_inst_ctx_t fields are altered.
155 *
156 * @param[in] _mi of the module being called..
157 */
158#define MODULE_INST_CTX(_mi) &(module_inst_ctx_t){ .mi = _mi }
159
160/** Wrapper to create a module_detach_ctx_t as a compound literal
161 *
162 * @param[in] _mi of the module being called..
163 */
164#define MODULE_DETACH_CTX(_mi) &(module_detach_ctx_t){ .mi = _mi }
165
166/** Wrapper to create a module_thread_inst_ctx_t as a compound literal
167 *
168 * This is used so that the compiler will flag any uses of (module_thread_inst_ctx_t)
169 * which don't set the required fields. Additional arguments should be added
170 * to this macro whenever the module_thread_inst_ctx_t fields are altered.
171 *
172 * @param[in] _mi of the module being called.
173 * @param[in] _thread instance of the module being called.
174 * @param[in] _el Thread specific event list.
175 */
176#define MODULE_THREAD_INST_CTX(_mi, _thread, _el) &(module_thread_inst_ctx_t){ .mi = _mi, .thread = _thread, .el = _el }
177
178/** Wrapper to create a module_inst_ctx_t as a comound listeral from a module_thread_ctx_t
179 *
180 * Extract the module_instance_t from a module_thread_inst_ctx_t.
181 *
182 * @param[in] _mctx to extract module_thread_inst_ctx_t from.
183 */
184#define MODULE_THREAD_INST_CTX_FROM_INST_CTX(_mctx) &(module_ctx_t){ .mi = (_mctx)->mi }
185
186#ifdef __cplusplus
187}
188#endif
#define DIAG_ON(_x)
Definition build.h:458
#define RCSIDH(h, id)
Definition build.h:484
#define unlikely(_x)
Definition build.h:381
#define DIAG_OFF(_x)
Definition build.h:457
Stores all information relating to an event list.
Definition event.c:411
void * env_data
Per call environment data.
Definition module_ctx.h:44
module_instance_t const * mi
Instance of the module being instantiated.
Definition module_ctx.h:42
void * thread
Thread specific instance data.
Definition module_ctx.h:43
void * rctx
Resume ctx that a module previously set.
Definition module_ctx.h:45
fr_event_list_t * el
Event list to register any IO handlers and timers against.
Definition module_ctx.h:68
module_instance_t * mi
Module instance to detach.
Definition module_ctx.h:57
void * thread
Thread instance data.
Definition module_ctx.h:67
module_instance_t const * mi
Instance of the module being instantiated.
Definition module_ctx.h:64
static module_ctx_t * module_ctx_from_thread_inst(TALLOC_CTX *ctx, module_thread_inst_ctx_t const *mctx)
Allocate a module calling ctx on the heap based on an instance ctx.
Definition module_ctx.h:90
static module_ctx_t * module_ctx_from_inst(TALLOC_CTX *ctx, module_inst_ctx_t const *mctx)
Allocate a module calling ctx on the heap based on an instance ctx.
Definition module_ctx.h:76
static module_ctx_t * module_ctx_dup(TALLOC_CTX *ctx, module_ctx_t const *mctx)
Duplicate a stack based module_ctx_t on the heap.
Definition module_ctx.h:105
module_instance_t * mi
Instance of the module being instantiated.
Definition module_ctx.h:51
Temporary structure to hold arguments for module calls.
Definition module_ctx.h:41
Temporary structure to hold arguments for detach calls.
Definition module_ctx.h:56
Temporary structure to hold arguments for instantiation calls.
Definition module_ctx.h:50
Temporary structure to hold arguments for thread_instantiation calls.
Definition module_ctx.h:63
Module instance data.
Definition module.h:265