The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
function.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: 30f27591bb7a3c021e805aa23a3115ca21280dc4 $
20 *
21 * @file unlang/function.h
22 * @brief Declarations for generic unlang functions.
23 *
24 * These are a useful alternative to module methods for library code.
25 * They're more light weight, and don't require instance data lookups
26 * to function.
27 *
28 * @copyright 2021 The FreeRADIUS server project
29 */
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35#include <freeradius-devel/server/rcode.h>
36#include <freeradius-devel/server/request.h>
37#include <freeradius-devel/server/signal.h>
38
39/** A generic function pushed by a module or xlat to functions deeper in the C call stack to create resumption points
40 *
41 * @param[in] p_result The module return code.
42 * @param[in] priority for the return code.
43 * @param[in] request The current request.
44 * @param[in,out] uctx Provided by whatever pushed the function. Is opaque to the
45 * interpreter, but should be usable by the function.
46 * All input (args) and output will be done using this structure.
47 * @return an #unlang_action_t.
48 */
49typedef unlang_action_t (*unlang_function_t)(rlm_rcode_t *p_result, int *priority, request_t *request, void *uctx);
50
51/** Function to call if the request was signalled
52 *
53 * @param[in] request The current request.
54 * @param[in] action We're being signalled with.
55 * @param[in,out] uctx Provided by whatever pushed the function. Is opaque to the
56 * interpreter, but should be usable by the function.
57 * All input (args) and output will be done using this structure.
58 */
59typedef void (*unlang_function_signal_t)(request_t *request, fr_signal_t action, void *uctx);
60
61int unlang_function_clear(request_t *request) CC_HINT(warn_unused_result);
62
63/** Set a new signal function for an existing function frame
64 *
65 * The function frame being modified must be at the top of the stack.
66 *
67 * @param[in] _request The current request.
68 * @param[in] _signal The signal function to set.
69 * @param[in] _sigmask Signals to block.
70 * @return
71 * - 0 on success.
72 * - -1 on failure.
73 */
74#define unlang_function_signal_set(_request, _signal, _sigmask) \
75 _unlang_function_signal_set(_request, _signal, _sigmask, STRINGIFY(_signal))
76int _unlang_function_signal_set(request_t *request, unlang_function_signal_t signal, fr_signal_t sigmask, char const *name)
77 CC_HINT(warn_unused_result);
78
79/** Set a new repeat function for an existing function frame
80 *
81 * The function frame being modified must be at the top of the stack.
82 *
83 * @param[in] _request The current request.
84 * @param[in] _repeat the repeat function to set.
85 * @return
86 * - 0 on success.
87 * - -1 on failure.
88 */
89#define unlang_function_repeat_set(_request, _repeat) \
90 _unlang_function_repeat_set(_request, _repeat, STRINGIFY(_repeat))
91int _unlang_function_repeat_set(request_t *request, unlang_function_t repeat, char const *name)
92 CC_HINT(warn_unused_result);
93
94/** Push a generic function onto the unlang stack
95 *
96 * These can be pushed by any other type of unlang op to allow a submodule or function
97 * deeper in the C call stack to establish a new resumption point.
98 *
99 * @param[in] _request The current request.
100 * @param[in] _func to call going up the stack.
101 * @param[in] _repeat function to call going back down the stack (may be NULL).
102 * This may be the same as func.
103 * @param[in] _signal function to call if the request is signalled.
104 * @param[in] _sigmask Signals to block.
105 * @param[in] _top_frame Return out of the unlang interpreter when popping this frame.
106 * @param[in] _uctx to pass to func(s).
107 * @return
108 * - UNLANG_ACTION_PUSHED_CHILD on success.
109 * - UNLANG_ACTION_FAIL on failure.
110 */
111#define unlang_function_push(_request, _func, _repeat, _signal, _sigmask, _top_frame, _uctx) \
112 _unlang_function_push(_request, \
113 _func, STRINGIFY(_func), \
114 _repeat, STRINGIFY(_repeat), \
115 _signal, _sigmask, STRINGIFY(_signal), \
116 _top_frame, _uctx)
118 unlang_function_t func, char const *func_name,
119 unlang_function_t repeat, char const *repeat_name,
120 unlang_function_signal_t signal, fr_signal_t sigmask, char const *signal_name,
121 bool top_frame, void *uctx)
122 CC_HINT(warn_unused_result);
123
124#ifdef __cplusplus
125}
126#endif
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
void(* unlang_function_signal_t)(request_t *request, fr_signal_t action, void *uctx)
Function to call if the request was signalled.
Definition function.h:59
int unlang_function_clear(request_t *request)
Clear pending repeat function calls, and remove the signal handler.
Definition function.c:160
unlang_action_t(* unlang_function_t)(rlm_rcode_t *p_result, int *priority, request_t *request, void *uctx)
A generic function pushed by a module or xlat to functions deeper in the C call stack to create resum...
Definition function.h:49
int _unlang_function_signal_set(request_t *request, unlang_function_signal_t signal, fr_signal_t sigmask, char const *name)
Set a new signal function for an existing function frame.
Definition function.c:194
int _unlang_function_repeat_set(request_t *request, unlang_function_t repeat, char const *name)
Set a new repeat function for an existing function frame.
Definition function.c:232
unlang_action_t _unlang_function_push(request_t *request, unlang_function_t func, char const *func_name, unlang_function_t repeat, char const *repeat_name, unlang_function_signal_t signal, fr_signal_t sigmask, char const *signal_name, bool top_frame, void *uctx)
Push a generic function onto the unlang stack.
Definition function.c:279
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:40
static char const * name
fr_signal_t
Signals that can be generated/processed by request signal handlers.
Definition signal.h:38