The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
try.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: 83165a2ff6bbd6f255532b77af0a7a5e69b697d9 $
19 *
20 * @file unlang/try.c
21 * @brief Unlang "try" keyword evaluation.
22 *
23 * @copyright 2023 Network RADIUS SAS (legal@networkradius.com)
24 */
25RCSID("$Id: 83165a2ff6bbd6f255532b77af0a7a5e69b697d9 $")
26
27#include "unlang_priv.h"
28#include "try_priv.h"
29#include "catch_priv.h"
30
32{
33 /*
34 * When this frame finishes, jump ahead to the appropriate "catch".
35 *
36 * All of the magic is done in the compile phase.
37 */
39
41}
42
44{
47 unlang_t *c;
48 CONF_ITEM *next;
49
50 /*
51 * The transaction is empty, ignore it.
52 */
53 if (!cf_item_next(cs, NULL)) {
54 cf_log_err(cs, "'try' sections cannot be empty");
55 print_url:
57 return NULL;
58 }
59
60 if (cf_section_name2(cs) != NULL) {
61 cf_log_err(cs, "Unexpected argument to 'try' section");
62 goto print_url;
63 }
64
65 next = cf_item_next(cf_parent(cs), ci);
66 while (next && cf_item_is_data(next)) next = cf_item_next(cf_parent(cs), next);
67
68 if (!next || !cf_item_is_section(next) ||
69 (strcmp(cf_section_name1(cf_item_to_section(next)), "catch") != 0)) {
70 cf_log_err(cs, "'try' sections must be followed by a 'catch'");
71 goto print_url;
72 }
73
75 if (!g) return NULL;
76
78 c->debug_name = c->name = cf_section_name1(cs);
79
81}
82
83
85{
87 .name = "try",
88 .type = UNLANG_TYPE_TRY,
90
91 .compile = unlang_compile_try,
92 .interpret = unlang_try,
93
94 .unlang_size = sizeof(unlang_try_t),
95 .unlang_name = "unlang_try_t",
96 });
97}
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
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
Declarations for the "catch" keyword.
Common header for all CONF_* types.
Definition cf_priv.h:49
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition cf_util.c:1184
char const * cf_section_name1(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition cf_util.c:1170
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:683
bool cf_item_is_data(CONF_ITEM const *ci)
Determine if CONF_ITEM is CONF_DATA.
Definition cf_util.c:645
bool cf_item_is_section(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_SECTION.
Definition cf_util.c:617
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:289
#define cf_parent(_cf)
Definition cf_util.h:101
#define cf_item_next(_parent, _curr)
Definition cf_util.h:92
unlang_t * unlang_compile_children(unlang_group_t *g, unlang_compile_ctx_t *unlang_ctx_in)
Definition compile.c:1324
unlang_group_t * unlang_group_allocate(unlang_t *parent, CONF_SECTION *cs, unlang_type_t type)
Definition compile.c:456
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
static TALLOC_CTX * unlang_ctx
Definition base.c:71
void unlang_register(unlang_op_t *op)
Register an operation with the interpreter.
Definition base.c:56
@ RLM_MODULE_NOT_SET
Error resolving rcode (should not be returned by modules).
Definition rcode.h:52
static unlang_action_t unlang_try(UNUSED unlang_result_t *p_result, request_t *request, unlang_stack_frame_t *frame)
Definition try.c:31
static unlang_t * unlang_compile_try(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_ITEM const *ci)
Definition try.c:43
void unlang_try_init(void)
Definition try.c:84
Declaration for unlang try.
#define UNLANG_NEXT_SIBLING
Definition unlang_priv.h:98
char const * debug_name
Printed in log messages when the node is executed.
static unlang_t * unlang_group_to_generic(unlang_group_t const *p)
char const * name
Unknown...
@ UNLANG_TYPE_TRY
try / catch blocks
Definition unlang_priv.h:75
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_OP_FLAG_DEBUG_BRACES
Print debug braces.
Generic representation of a grouping.
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.
static fr_slen_t parent
Definition pair.h:839
#define DOC_KEYWORD_REF(_x)
Definition version.h:89