The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
interpret.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: e4083bc482e7c622ee2fb7dfc130d0b3982535d3 $
20 *
21 * @file unlang/interpret.h
22 * @brief Declarations for the unlang interpreter.
23 *
24 * @copyright 2019 The FreeRADIUS server project
25 */
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#include <freeradius-devel/server/cf_util.h>
32#include <freeradius-devel/server/request.h>
33#include <freeradius-devel/unlang/action.h>
34
35#define UNLANG_TOP_FRAME (true)
36#define UNLANG_SUB_FRAME (false)
37
38#define UNLANG_STACK_MAX (64) //!< The maximum depth of the stack.
39#define UNLANG_FRAME_PRE_ALLOC (128) //!< How much memory we pre-alloc for each frame.
40
41#define UNLANG_REQUEST_RUNNING (true)
42#define UNLANG_REQUEST_RESUME (false)
43
44/** Interpreter handle
45 *
46 */
48
49/** Signal the owner of the interpreter that this request should be initialised and executed
50 *
51 * This is called once per request, when it's about to start executing.
52 */
53typedef void (*unlang_request_init_t)(request_t *request, void *uctx);
54
55/** Signal the owner of the interpreter that this request completed processing
56 *
57 * This is called once per request, when the interpret is about to stop processing it.
58 */
59typedef void (*unlang_request_done_t)(request_t *request, rlm_rcode_t rcode, void *uctx);
60
61/** Stop a request from running
62 *
63 * This is called whenever a request has been signalled to stop
64 */
65typedef void (*unlang_request_stop_t)(request_t *request, void *uctx);
66
67/** Signal the owner of the interpreter that a request has yielded
68 *
69 * This is called whenever a request has given control back to the interpreter.
70 */
71typedef void (*unlang_request_yield_t)(request_t *request, void *uctx);
72
73/** Signal the owner of the interpreter that a request is ready to be resumed
74 *
75 * This is called any time a yielded request has resumed.
76 */
77typedef void (*unlang_request_resume_t)(request_t *request, void *uctx);
78
79/** Signal the owner of the interpreter that a request is now runnable
80 *
81 * This is called any time a yielded request has been marked runnable.
82 */
83typedef void (*unlang_request_runnable_t)(request_t *request, void *uctx);
84
85/** Signal the owner of the interpreter that a request is now runnable
86 *
87 * This is called any time a yielded request has been marked runnable.
88 */
89typedef bool (*unlang_request_scheduled_t)(request_t const *request, void *uctx);
90
91/** External functions provided by the owner of the interpret
92 *
93 * These functions allow the event loop to signal the caller when a given
94 * request is ready to run for the first time, and when it should be resumed
95 * and passed back to #unlang_interpret to continue execution.
96 *
97 * This is the cleanest way to separate the interpret and the code that's
98 * managing requests.
99 *
100 * Test harnesses (for example) need to perform far less initialisation and
101 * request management than FeeRADIUS worker threads.
102 */
103typedef struct {
104 /*
105 * There's no init_external as this is done
106 * before the external request is handed off
107 * to the interpreter.
108 */
109 unlang_request_init_t init_internal; //!< Function called to initialise an internal request.
110
111 unlang_request_done_t done_external; //!< Function called when a external request completes.
112 unlang_request_done_t done_internal; //!< Function called when an internal request completes.
113 unlang_request_done_t done_detached; //!< Function called when a detached request completes.
114
115 unlang_request_init_t detach; //!< Function called when a request is detached.
116 unlang_request_stop_t stop; //!< function called when a request is signalled to stop.
117 unlang_request_yield_t yield; //!< Function called when a request yields.
118 unlang_request_resume_t resume; //!< Function called when a request is resumed.
119 unlang_request_runnable_t mark_runnable; //!< Function called when a request needs to be
120 ///< added back to the runnable queue.
121 unlang_request_scheduled_t scheduled; //!< Function to check if a request is already
122 ///< scheduled.
124
126 rlm_rcode_t default_action, bool top_frame)
127 CC_HINT(warn_unused_result);
128
129int unlang_interpret_push_instruction(request_t *request, void *instruction,
130 rlm_rcode_t default_rcode, bool top_frame)
131 CC_HINT(warn_unused_result);
132
134 fr_event_list_t *el, unlang_request_func_t *func, void *uctx);
135
137
139
141
143
145
147
148rlm_rcode_t unlang_interpret(request_t *request, bool running) CC_HINT(hot);
149
151
152void *unlang_interpret_stack_alloc(TALLOC_CTX *ctx);
153
154bool unlang_request_is_scheduled(request_t const *request);
155
156bool unlang_request_is_cancelled(request_t const *request);
157
158bool unlang_request_is_done(request_t const *request);
159
161
163
165
166void unlang_interpret_signal(request_t *request, fr_signal_t action);
167
169
171
173
174TALLOC_CTX *unlang_interpret_frame_talloc_ctx(request_t *request);
175
176int unlang_interpret_init_global(TALLOC_CTX *ctx);
177#ifdef __cplusplus
178}
179#endif
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
unlang_request_stop_t stop
function called when a request is signalled to stop.
Definition interpret.h:116
rlm_rcode_t unlang_interpret(request_t *request, bool running)
Run the interpreter for a current request.
Definition interpret.c:771
bool unlang_request_is_done(request_t const *request)
Return whether a request has been marked done.
Definition interpret.c:1333
void unlang_interpet_frame_discard(request_t *request)
Discard the bottom most frame on the request's stack.
Definition interpret.c:1741
int unlang_interpret_push_instruction(request_t *request, void *instruction, rlm_rcode_t default_rcode, bool top_frame)
Push an instruction onto the request stack for later interpretation.
Definition interpret.c:1019
void unlang_interpret_request_done(request_t *request)
Indicate to the caller of the interpreter that this request is complete.
Definition interpret.c:1076
void unlang_interpret_set(request_t *request, unlang_interpret_t *intp)
Set a specific interpreter for a request.
Definition interpret.c:1749
unlang_interpret_t * unlang_interpret_get(request_t *request)
Get the interpreter set for a request.
Definition interpret.c:1758
rlm_rcode_t unlang_interpret_stack_result(request_t *request)
Get the current rcode for the frame.
Definition interpret.c:1294
unlang_request_done_t done_internal
Function called when an internal request completes.
Definition interpret.h:112
int unlang_interpret_stack_depth(request_t *request)
Return the depth of the request's stack.
Definition interpret.c:1279
void unlang_interpret_mark_runnable(request_t *request)
Mark a request as resumable.
Definition interpret.c:1363
TALLOC_CTX * unlang_interpret_frame_talloc_ctx(request_t *request)
Get a talloc_ctx which is valid only for this frame.
Definition interpret.c:1407
unlang_interpret_t * unlang_interpret_init(TALLOC_CTX *ctx, fr_event_list_t *el, unlang_request_func_t *func, void *uctx)
Initialize a unlang compiler / interpret.
Definition interpret.c:1707
bool unlang_request_is_scheduled(request_t const *request)
Return whether a request is currently scheduled.
Definition interpret.c:1316
int unlang_interpret_init_global(TALLOC_CTX *ctx)
Definition interpret.c:1798
unlang_interpret_t * unlang_interpret_get_thread_default(void)
Get the default interpreter for this thread.
Definition interpret.c:1791
unlang_request_resume_t resume
Function called when a request is resumed.
Definition interpret.h:118
void * unlang_interpret_stack_alloc(TALLOC_CTX *ctx)
Allocate a new unlang stack.
Definition interpret.c:1050
bool(* unlang_request_scheduled_t)(request_t const *request, void *uctx)
Signal the owner of the interpreter that a request is now runnable.
Definition interpret.h:89
unlang_request_done_t done_external
Function called when a external request completes.
Definition interpret.h:111
void unlang_interpret_set_thread_default(unlang_interpret_t *intp)
Set the default interpreter for this thread.
Definition interpret.c:1780
unlang_request_init_t detach
Function called when a request is detached.
Definition interpret.h:115
unlang_request_runnable_t mark_runnable
Function called when a request needs to be added back to the runnable queue.
Definition interpret.h:119
bool unlang_request_is_cancelled(request_t const *request)
Return whether a request has been cancelled.
Definition interpret.c:1326
unlang_request_yield_t yield
Function called when a request yields.
Definition interpret.h:117
void unlang_interpret_signal(request_t *request, fr_signal_t action)
Send a signal (usually stop) to a request.
Definition interpret.c:1200
void(* unlang_request_done_t)(request_t *request, rlm_rcode_t rcode, void *uctx)
Signal the owner of the interpreter that this request completed processing.
Definition interpret.h:59
void(* unlang_request_resume_t)(request_t *request, void *uctx)
Signal the owner of the interpreter that a request is ready to be resumed.
Definition interpret.h:77
int unlang_interpret_push_section(request_t *request, CONF_SECTION *cs, rlm_rcode_t default_action, bool top_frame)
Push a configuration section onto the request stack for later interpretation.
Definition interpret.c:996
unlang_request_done_t done_detached
Function called when a detached request completes.
Definition interpret.h:113
void(* unlang_request_yield_t)(request_t *request, void *uctx)
Signal the owner of the interpreter that a request has yielded.
Definition interpret.h:71
bool unlang_interpret_is_resumable(request_t *request)
Check if a request as resumable.
Definition interpret.c:1345
rlm_rcode_t unlang_interpret_synchronous(fr_event_list_t *el, request_t *request)
Execute an unlang section synchronously.
void(* unlang_request_init_t)(request_t *request, void *uctx)
Signal the owner of the interpreter that this request should be initialised and executed.
Definition interpret.h:53
void unlang_interpret_stack_result_set(request_t *request, rlm_rcode_t code)
Overwrite the current stack rcode.
Definition interpret.c:1306
unlang_request_scheduled_t scheduled
Function to check if a request is already scheduled.
Definition interpret.h:121
void(* unlang_request_stop_t)(request_t *request, void *uctx)
Stop a request from running.
Definition interpret.h:65
void(* unlang_request_runnable_t)(request_t *request, void *uctx)
Signal the owner of the interpreter that a request is now runnable.
Definition interpret.h:83
unlang_request_init_t init_internal
Function called to initialise an internal request.
Definition interpret.h:109
fr_event_list_t * unlang_interpret_event_list(request_t *request)
Get the event list for the current interpreter.
Definition interpret.c:1768
External functions provided by the owner of the interpret.
Definition interpret.h:103
Stores all information relating to an event list.
Definition event.c:411
unsigned char bool
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:40
fr_signal_t
Signals that can be generated/processed by request signal handlers.
Definition signal.h:38
static fr_event_list_t * el