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: 68b2eee6bf0a6d57a1aa753797553b03fdf389dc $
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.h>
34 #include <freeradius-devel/server/module_rlm.h>
35 #include <freeradius-devel/server/rcode.h>
36 #include <freeradius-devel/unlang/subrequest.h>
37 #include <freeradius-devel/unlang/tmpl.h>
38 
39 /** A callback when a retry happens
40  *
41  * Used when a module needs wait for an event.
42  * Typically the callback is set, and then the module returns unlang_module_yield().
43  *
44  * @note The callback is automatically removed on unlang_interpret_mark_runnable(), i.e. if an event
45  * on a registered FD occurs before the timeout event fires.
46  *
47  * @param[in] mctx calling context for the module.
48  * Contains global, thread-specific, and call-specific data for a module.
49  * @param[in] request the request.
50  * @param[in] retry retry status. "now" is in retry->updated
51  */
52 typedef void (*unlang_module_retry_t)(module_ctx_t const *mctx, request_t *request, fr_retry_t const *retry);
53 
54 /** A callback when the FD is ready for reading
55  *
56  * Used when a module needs to read from an FD. Typically the callback is set, and then the
57  * module returns unlang_module_yield().
58  *
59  * @note The callback is automatically removed on unlang_interpret_mark_runnable(), so
60  *
61  * @param[in] mctx calling context for the module.
62  * Contains global, thread-specific, and call-specific data for a module.
63  * @param[in] request the current request.
64  * @param[in] fd the file descriptor.
65  */
66 typedef void (*unlang_module_fd_event_t)(module_ctx_t const *mctx, request_t *request, int fd);
67 
68 /** A callback when the request gets a fr_signal_t.
69  *
70  * A module may call unlang_yeild(), but still need to do something on FR_SIGNAL_DUP. If so, it's
71  * set here.
72  *
73  * @note The callback is automatically removed on unlang_interpret_mark_runnable().
74  *
75  * @param[in] mctx calling context for the module.
76  * Contains global, thread-specific, and call-specific data for a module.
77  * @param[in] request The current request.
78  * @param[in] action which is signalling the request.
79  */
80 typedef void (*unlang_module_signal_t)(module_ctx_t const *mctx, request_t *request, fr_signal_t action);
81 
82 int unlang_module_push(rlm_rcode_t *p_result, request_t *request,
83  module_instance_t *module_instance, module_method_t method, bool top_frame)
84  CC_HINT(warn_unused_result) CC_HINT(nonnull(2,3,4));
85 
87 
89  request_t *request, CONF_SECTION *subcs,
90  rlm_rcode_t default_rcode,
91  module_method_t resume,
92  unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx);
93 
94 unlang_action_t unlang_module_yield_to_xlat(TALLOC_CTX *ctx, bool *p_success, fr_value_box_list_t *out,
95  request_t *request, xlat_exp_head_t const *xlat,
96  module_method_t resume,
97  unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx);
98 
99 unlang_action_t unlang_module_yield_to_tmpl(TALLOC_CTX *ctx, fr_value_box_list_t *out,
100  request_t *request, tmpl_t const *vpt,
102  module_method_t resume,
103  unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx);
104 
105 void unlang_module_retry_now(module_ctx_t const *mctx, request_t *request) CC_HINT(nonnull);
106 
108  unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx,
109  fr_retry_config_t const *retry_cfg);
110 
112  module_method_t resume,
113  unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx);
114 
115 #ifdef __cplusplus
116 }
117 #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:101
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:68
Module instance data.
Definition: module.h:265
static fr_slen_t vpt
Definition: tmpl.h:1272
fr_signal_t
Definition: signal.h:48
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:248
int unlang_module_set_resume(request_t *request, module_method_t resume)
Change the resume function of a module.
Definition: module.c:132
void(* unlang_module_retry_t)(module_ctx_t const *mctx, request_t *request, fr_retry_t const *retry)
A callback when a retry happens.
Definition: module.h:52
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:66
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:80
unlang_action_t unlang_module_yield_to_retry(request_t *request, module_method_t resume, unlang_module_retry_t retry_cb, unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx, fr_retry_config_t const *retry_cfg)
Yield a request back to the interpreter, with retries.
Definition: module.c:361
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:419
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:181
void unlang_module_retry_now(module_ctx_t const *mctx, request_t *request)
Run the retry handler.
Definition: module.c:292
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:53
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:228
Arguments for evaluating different types of tmpls.
Definition: tmpl.h:47
int nonnull(2, 5))
static size_t char ** out
Definition: value.h:997