The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
module.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, or (at your option)
6  * 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 Foundation,
15  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16  */
17 
18 /**
19  * $Id: 929f3725556da79bb51bf820a62180981c06a9d4 $
20  *
21  * @file unlang/module.h
22  *
23  * @brief Functions to allow modules to push resumption frames onto the stack
24  * and inform the interpreter about the conditions they need to be
25  * resumed under (usually an I/O event or timer event).
26  *
27  * @copyright 2016-2019 The FreeRADIUS server project
28  */
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <freeradius-devel/server/module_rlm.h>
34 #include <freeradius-devel/server/rcode.h>
35 #include <freeradius-devel/unlang/subrequest.h>
36 #include <freeradius-devel/unlang/tmpl.h>
37 
38 /** A callback when the the timeout occurs
39  *
40  * Used when a module needs wait for an event.
41  * Typically the callback is set, and then the module returns unlang_module_yield().
42  *
43  * @note The callback is automatically removed on unlang_interpret_mark_runnable(), i.e. if an event
44  * on a registered FD occurs before the timeout event fires.
45  *
46  * @param[in] mctx calling context for the module.
47  * Contains global, thread-specific, and call-specific data for a module.
48  * @param[in] request the request.
49  * @param[in] fired the time the timeout event actually fired.
50  */
51 typedef void (*unlang_module_timeout_t)(module_ctx_t const *mctx, request_t *request, fr_time_t fired);
52 
53 /** A callback when the FD is ready for reading
54  *
55  * Used when a module needs to read from an FD. Typically the callback is set, and then the
56  * module returns unlang_module_yield().
57  *
58  * @note The callback is automatically removed on unlang_interpret_mark_runnable(), so
59  *
60  * @param[in] mctx calling context for the module.
61  * Contains global, thread-specific, and call-specific data for a module.
62  * @param[in] request the current request.
63  * @param[in] fd the file descriptor.
64  */
65 typedef void (*unlang_module_fd_event_t)(module_ctx_t const *mctx, request_t *request, int fd);
66 
67 /** A callback when the request gets a fr_signal_t.
68  *
69  * A module may call unlang_yeild(), but still need to do something on FR_SIGNAL_DUP. If so, it's
70  * set here.
71  *
72  * @note The callback is automatically removed on unlang_interpret_mark_runnable().
73  *
74  * @param[in] mctx calling context for the module.
75  * Contains global, thread-specific, and call-specific data for a module.
76  * @param[in] request The current request.
77  * @param[in] action which is signalling the request.
78  */
79 typedef void (*unlang_module_signal_t)(module_ctx_t const *mctx, request_t *request, fr_signal_t action);
80 
82  void const *rctx, fr_time_t when);
83 
84 int unlang_module_timeout_delete(request_t *request, void const *ctx);
85 
86 int unlang_module_fd_add(request_t *request,
90  void const *rctx, int fd);
91 
92 int unlang_module_fd_delete(request_t *request, void const *rctx, int fd);
93 
94 int unlang_module_push(rlm_rcode_t *p_result, request_t *request,
95  module_instance_t *module_instance, module_method_t method, bool top_frame)
96  CC_HINT(warn_unused_result) CC_HINT(nonnull(2,3,4));
97 
99 
101  request_t *request, CONF_SECTION *subcs,
102  rlm_rcode_t default_rcode,
103  module_method_t resume,
104  unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx);
105 
106 unlang_action_t unlang_module_yield_to_xlat(TALLOC_CTX *ctx, bool *p_success, fr_value_box_list_t *out,
107  request_t *request, xlat_exp_head_t const *xlat,
108  module_method_t resume,
109  unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx);
110 
111 unlang_action_t unlang_module_yield_to_tmpl(TALLOC_CTX *ctx, fr_value_box_list_t *out,
112  request_t *request, tmpl_t const *vpt,
114  module_method_t resume,
115  unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx);
116 
118  module_method_t resume,
119  unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx);
120 
121 #ifdef __cplusplus
122 }
123 #endif
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition: action.h:35
va_list args
Definition: acutest.h:770
A section grouping multiple CONF_PAIR.
Definition: cf_priv.h:89
Temporary structure to hold arguments for module calls.
Definition: module_ctx.h:41
rlm_rcode_t
Return codes indicating the result of the module call.
Definition: rcode.h:40
unlang_action_t(* module_method_t)(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Module section callback.
Definition: module.h:69
Per instance data.
Definition: module.h:169
static fr_slen_t vpt
Definition: tmpl.h:1260
fr_signal_t
Definition: signal.h:48
"server local" time.
Definition: time.h:69
unlang_action_t unlang_module_yield_to_section(rlm_rcode_t *p_result, request_t *request, CONF_SECTION *subcs, rlm_rcode_t default_rcode, module_method_t resume, unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx)
Definition: module.c:516
int unlang_module_set_resume(request_t *request, module_method_t resume)
Change the resume function of a module.
Definition: module.c:400
int unlang_module_fd_add(request_t *request, unlang_module_fd_event_t read, unlang_module_fd_event_t write, unlang_module_fd_event_t error, void const *rctx, int fd)
Set a callback for the request.
Definition: module.c:245
int unlang_module_timeout_delete(request_t *request, void const *ctx)
Delete a previously set timeout callback.
Definition: module.c:176
int unlang_module_fd_delete(request_t *request, void const *rctx, int fd)
Delete a previously set file descriptor callback.
Definition: module.c:302
void(* unlang_module_fd_event_t)(module_ctx_t const *mctx, request_t *request, int fd)
A callback when the FD is ready for reading.
Definition: module.h:65
void(* unlang_module_signal_t)(module_ctx_t const *mctx, request_t *request, fr_signal_t action)
A callback when the request gets a fr_signal_t.
Definition: module.h:79
unlang_action_t unlang_module_yield(request_t *request, module_method_t resume, unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx)
Yield a request back to the interpreter from within a module.
Definition: module.c:575
unlang_action_t unlang_module_yield_to_xlat(TALLOC_CTX *ctx, bool *p_success, fr_value_box_list_t *out, request_t *request, xlat_exp_head_t const *xlat, module_method_t resume, unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx)
Push a pre-compiled xlat and resumption state onto the stack for evaluation.
Definition: module.c:449
int unlang_module_push(rlm_rcode_t *p_result, request_t *request, module_instance_t *module_instance, module_method_t method, bool top_frame)
Push a module or submodule onto the stack for evaluation.
Definition: module.c:325
int unlang_module_timeout_add(request_t *request, unlang_module_timeout_t callback, void const *rctx, fr_time_t when)
Set a timeout for the request.
Definition: module.c:128
unlang_action_t unlang_module_yield_to_tmpl(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt, unlang_tmpl_args_t *args, module_method_t resume, unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx)
Push a pre-compiled tmpl and resumption state onto the stack for evaluation.
Definition: module.c:496
void(* unlang_module_timeout_t)(module_ctx_t const *mctx, request_t *request, fr_time_t fired)
A callback when the the timeout occurs.
Definition: module.h:51
Arguments for evaluating different types of tmpls.
Definition: tmpl.h:47
int nonnull(2, 5))
static size_t char ** out
Definition: value.h:984