The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
catch.c
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/**
18 * $Id: 5aa85e517541afb8861b1483586ae9528f003280 $
19 *
20 * @file unlang/catch.c
21 * @brief Unlang "catch" keyword evaluation.
22 *
23 * @copyright 2023 Network RADIUS SAS (legal@networkradius.com)
24 */
25RCSID("$Id: 5aa85e517541afb8861b1483586ae9528f003280 $")
26
27#include <freeradius-devel/server/rcode.h>
28#include "unlang_priv.h"
29#include "catch_priv.h"
30
32{
33 unlang_t *unlang;
34
36
37 for (unlang = frame->instruction->next;
38 unlang != NULL;
39 unlang = unlang->next) {
40 if (unlang->type == UNLANG_TYPE_CATCH) continue;
41
42 break;
43 }
44
45 return frame_set_next(frame, unlang);
46}
47
49{
50#ifndef NDEBUG
52
53 fr_assert(!c->catching[p_result->rcode]);
54#endif
55
56 /*
57 * Skip over any "catch" statementa after this one.
58 */
60
62}
63
64
65/** Skip ahead to a particular "catch" instruction.
66 *
67 */
69{
70 unlang_t *unlang;
71 rlm_rcode_t rcode = unlang_interpret_rcode(request);
72
74
75 /*
76 * 'try' at the end of a block without 'catch' should have been caught by the compiler.
77 */
78 fr_assert(frame->instruction->next);
79
80 for (unlang = frame->instruction->next;
81 unlang != NULL;
82 unlang = unlang->next) {
83 unlang_catch_t const *c;
84
85 if (unlang->type != UNLANG_TYPE_CATCH) {
86 not_caught:
87 RDEBUG3("No catch section for %s",
88 fr_table_str_by_value(mod_rcode_table, rcode, "<invalid>"));
89 return frame_set_next(frame, unlang);
90 }
91
92 if (rcode >= RLM_MODULE_NUMCODES) continue;
93
94 c = unlang_generic_to_catch(unlang);
95 if (c->catching[rcode]) break;
96 }
97 if (!unlang) goto not_caught;
98
99 return frame_set_next(frame, unlang);
100}
101
103{
105 &(unlang_op_t){
106 .name = "catch",
107 .interpret = unlang_catch,
109 });
110}
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
#define RCSID(id)
Definition build.h:485
#define UNUSED
Definition build.h:317
static unlang_action_t unlang_catch(UNUSED unlang_result_t *p_result, request_t *request, unlang_stack_frame_t *frame)
Definition catch.c:48
unlang_action_t unlang_interpret_skip_to_catch(UNUSED unlang_result_t *p_result, request_t *request, unlang_stack_frame_t *frame)
Skip ahead to a particular "catch" instruction.
Definition catch.c:68
void unlang_catch_init(void)
Definition catch.c:102
static unlang_action_t catch_skip_to_next(UNUSED unlang_result_t *p_result, UNUSED request_t *request, unlang_stack_frame_t *frame)
Definition catch.c:31
Declarations for the "catch" keyword.
static unlang_catch_t const * unlang_generic_to_catch(unlang_t const *g)
Cast a generic structure to the catch keyword extension.
Definition catch_priv.h:50
bool catching[RLM_MODULE_NUMCODES]
Definition catch_priv.h:34
fr_table_num_sorted_t const mod_rcode_table[]
Definition compile.c:78
rlm_rcode_t unlang_interpret_rcode(request_t *request)
Get the last instruction result OR the last frame that was popped.
Definition interpret.c:1541
unlang_action_t unlang_interpret_push_children(unlang_result_t *p_result, request_t *request, rlm_rcode_t default_rcode, bool do_next_sibling)
Push the children of the current frame onto a new frame onto the stack.
Definition interpret.c:389
#define RDEBUG3(fmt,...)
Definition log.h:343
void unlang_register(int type, unlang_op_t *op)
Register an operation with the interpreter.
Definition base.c:63
#define fr_assert(_expr)
Definition rad_assert.h:38
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:40
@ RLM_MODULE_NOT_SET
Error resolving rcode (should not be returned by modules).
Definition rcode.h:52
@ RLM_MODULE_NUMCODES
How many valid return codes there are.
Definition rcode.h:51
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
Definition table.h:772
Private interpreter structures and functions.
unlang_t * next
Next node (executed on UNLANG_ACTION_EXECUTE_NEXT et al).
#define UNLANG_NEXT_SIBLING
Definition unlang_priv.h:98
@ UNLANG_TYPE_TRY
try / catch blocks
Definition unlang_priv.h:75
@ UNLANG_TYPE_CATCH
catch a previous try
Definition unlang_priv.h:76
static void frame_repeat(unlang_stack_frame_t *frame, unlang_process_t process)
Mark the current stack frame up for repeat, and set a new process function.
unlang_t const * instruction
The unlang node we're evaluating.
static unlang_action_t frame_set_next(unlang_stack_frame_t *frame, unlang_t *unlang)
@ UNLANG_OP_FLAG_DEBUG_BRACES
Print debug braces.
unlang_type_t type
The specialisation of this node.
An unlang operation.
A node in a graph of unlang_op_t (s) that we execute.
Our interpreter stack, as distinct from the C stack.