The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
base.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: fc841c11f4fbd9733ee4b58675dd33431bc2560d $
19 *
20 * @file unlang/base.c
21 * @brief Base, utility functions for the unlang library.
22 *
23 * @copyright 2019 The FreeRADIUS server project
24 */
25RCSID("$Id: fc841c11f4fbd9733ee4b58675dd33431bc2560d $")
26
27#include "unlang_priv.h"
28
29/** Different operations the interpreter can execute
30 */
32
33/** Return whether a section has unlang data associated with it
34 *
35 * @param[in] cs to check.
36 * @return
37 * - true if it has data.
38 * - false if it doesn't have data.
39 */
41{
42 return (cf_data_find(cs, unlang_group_t, NULL) != NULL);
43}
44
45/** Register an operation with the interpreter
46 *
47 * The main purpose of this registration API is to avoid intermixing the xlat,
48 * condition, map APIs with the interpreter, i.e. the callbacks needed for that
49 * functionality can be in their own source files, and we don't need to include
50 * supporting types and function declarations in the interpreter.
51 *
52 * Later, this could potentially be used to register custom operations for modules.
53 *
54 * The reason why there's a function instead of accessing the unlang_op array
55 * directly, is because 'type' really needs to go away, as needing to add ops to
56 * the unlang_type_t enum breaks the pluggable module model. If there's no
57 * explicit/consistent type values we need to enumerate the operations ourselves.
58 *
59 * @param[in] type Operation identifier. Used to map compiled unlang code
60 * to operations.
61 * @param[in] op unlang_op to register.
62 */
64{
65 fr_assert(type < UNLANG_TYPE_MAX); /* Unlang max isn't a valid type */
66
67 memcpy(&unlang_ops[type], op, sizeof(unlang_ops[type]));
68}
69
70static TALLOC_CTX *unlang_ctx = NULL;
71
72static int _unlang_global_free(UNUSED void *uctx)
73{
75 TALLOC_FREE(unlang_ctx);
76
77 return 0;
78}
79
80static int _unlang_global_init(UNUSED void *uctx)
81{
82 unlang_ctx = talloc_init("unlang");
83 if (!unlang_ctx) return -1;
84
85 /*
86 * Explicitly initialise the xlat tree, and perform dictionary lookups.
87 */
88 if (xlat_global_init() < 0) {
89 fail:
90 TALLOC_FREE(unlang_ctx);
91
92 memset(unlang_ops, 0, sizeof(unlang_ops));
93 return -1;
94 }
95
97
98 /*
99 * Operations which can fail, and which require cleanup.
100 */
101 if (unlang_subrequest_op_init() < 0) goto fail;
102
103 /*
104 * Register operations for the default keywords. The
105 * operations listed below cannot fail, and do not
106 * require cleanup.
107 */
129
130 return 0;
131}
132
134{
135 int ret;
136 fr_atexit_global_once_ret(&ret, _unlang_global_init, _unlang_global_free, NULL);
137 return ret;
138}
#define RCSID(id)
Definition build.h:483
#define UNUSED
Definition build.h:315
void unlang_call_init(void)
Definition call.c:249
void unlang_caller_init(void)
Definition caller.c:55
void unlang_catch_init(void)
Definition catch.c:114
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
#define cf_data_find(_cf, _type, _name)
Definition cf_util.h:244
void unlang_compile_init(TALLOC_CTX *ctx)
Definition compile.c:5113
void unlang_condition_init(void)
Definition condition.c:103
void unlang_detach_init(void)
Initialise subrequest ops.
Definition detach.c:54
void unlang_foreach_init(TALLOC_CTX *ctx)
Definition foreach.c:693
void unlang_function_init(void)
Definition function.c:337
void unlang_group_init(void)
Definition group.c:46
int unlang_interpret_init_global(TALLOC_CTX *ctx)
Definition interpret.c:1794
void unlang_register(int type, unlang_op_t *op)
Register an operation with the interpreter.
Definition base.c:63
static int _unlang_global_free(UNUSED void *uctx)
Definition base.c:72
unlang_op_t unlang_ops[UNLANG_TYPE_MAX]
Different operations the interpreter can execute.
Definition base.c:31
bool unlang_section(CONF_SECTION *cs)
Return whether a section has unlang data associated with it.
Definition base.c:40
static TALLOC_CTX * unlang_ctx
Definition base.c:70
int unlang_global_init(void)
Definition base.c:133
static int _unlang_global_init(UNUSED void *uctx)
Definition base.c:80
void unlang_map_init(void)
Definition map.c:381
void unlang_limit_init(void)
Definition limit.c:124
void unlang_load_balance_init(void)
void unlang_parallel_init(void)
Definition parallel.c:493
#define fr_assert(_expr)
Definition rad_assert.h:38
void unlang_return_init(void)
Definition return.c:43
void unlang_module_init(void)
Definition module.c:931
fr_aka_sim_id_type_t type
int unlang_subrequest_op_init(void)
Initialise subrequest ops.
Definition subrequest.c:295
void unlang_subrequest_op_free(void)
Definition subrequest.c:313
void unlang_switch_init(void)
Definition switch.c:142
void unlang_timeout_init(void)
Definition timeout.c:140
void unlang_tmpl_init(void)
Definition tmpl.c:330
void unlang_transaction_init(void)
void unlang_try_init(void)
Definition try.c:42
void unlang_edit_init(void)
Definition edit.c:1731
int xlat_global_init(void)
@ UNLANG_TYPE_MAX
Definition unlang_priv.h:77
Generic representation of a grouping.
An unlang operation.