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: 7c23080f3bb85fed1da6574e3a327ff4b491671a $
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: 7c23080f3bb85fed1da6574e3a327ff4b491671a $")
26
27#include "unlang_priv.h"
28#include "catch_priv.h"
29
31{
32 unlang_t *unlang;
33
35
36 for (unlang = frame->instruction->next;
37 unlang != NULL;
38 unlang = unlang->next) {
39 if (unlang->type == UNLANG_TYPE_CATCH) continue;
40
41 break;
42 }
43
44 return frame_set_next(frame, unlang);
45}
46
48{
49#ifndef NDEBUG
51
52 fr_assert(c->catching[*p_result]);
53#endif
54
55 /*
56 * Skip over any "catch" statementa after this one.
57 */
59
60 return unlang_interpret_push_children(p_result, request, frame->result, UNLANG_NEXT_SIBLING);
61}
62
63
64/** Skip ahead to a particular "catch" instruction.
65 *
66 */
68{
69 unlang_t *unlang;
70
72
73 /*
74 * 'try' at the end of a block without 'catch' should have been caught by the compiler.
75 */
76 fr_assert(frame->instruction->next);
77
78 for (unlang = frame->instruction->next;
79 unlang != NULL;
80 unlang = unlang->next) {
81 unlang_catch_t const *c;
82
83 if (unlang->type != UNLANG_TYPE_CATCH) {
84 not_caught:
85 RDEBUG3("No catch section for %s",
86 fr_table_str_by_value(mod_rcode_table, *p_result, "<invalid>"));
87 return frame_set_next(frame, unlang);
88 }
89
90 c = unlang_generic_to_catch(unlang);
91 if (c->catching[*p_result]) break;
92 }
93 if (!unlang) goto not_caught;
94
95 return frame_set_next(frame, unlang);
96}
97
99{
101 &(unlang_op_t){
102 .name = "catch",
103 .interpret = unlang_catch,
105 });
106}
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(rlm_rcode_t *p_result, request_t *request, unlang_stack_frame_t *frame)
Definition catch.c:47
static unlang_action_t catch_skip_to_next(UNUSED rlm_rcode_t *p_result, UNUSED request_t *request, unlang_stack_frame_t *frame)
Definition catch.c:30
void unlang_catch_init(void)
Definition catch.c:98
unlang_action_t unlang_interpret_skip_to_catch(rlm_rcode_t *p_result, request_t *request, unlang_stack_frame_t *frame)
Skip ahead to a particular "catch" instruction.
Definition catch.c:67
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
unlang_action_t unlang_interpret_push_children(UNUSED rlm_rcode_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:239
#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
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
Definition table.h:772
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.
rlm_rcode_t result
The result from executing the instruction.
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.