33 #include <freeradius-devel/unlang/xlat_ctx.h>
34 #include <freeradius-devel/unlang/xlat.h>
35 #include <freeradius-devel/unlang/xlat_func.h>
36 #include <freeradius-devel/server/module_ctx.h>
37 #include <freeradius-devel/io/pair.h>
38 #include <freeradius-devel/util/talloc.h>
39 #include <freeradius-devel/build.h>
42 # define XLAT_DEBUG RDEBUG3
44 # define XLAT_DEBUG(...)
51 # error _CONST can only be defined in the local header
209 if (!
head)
return NULL;
220 #define xlat_exp_foreach(_list_head, _iter) fr_dlist_foreach(&((_list_head)->dlist), xlat_exp_t, _iter)
246 if (!
head)
return NULL;
271 #define xlat_exp_head_alloc(_ctx) _xlat_exp_head_alloc(NDEBUG_LOCATION_EXP _ctx)
274 #define xlat_exp_set_type(_node, _type) _xlat_exp_set_type(NDEBUG_LOCATION_EXP _node, _type)
277 #define xlat_exp_alloc_null(_ctx) _xlat_exp_alloc_null(NDEBUG_LOCATION_EXP _ctx)
280 #define xlat_exp_alloc(_ctx, _type, _in, _inlen) _xlat_exp_alloc(NDEBUG_LOCATION_EXP _ctx, _type, _in, _inlen)
311 fr_value_box_list_t *result,
xlat_func_t resume,
void *rctx);
316 void *env_data, fr_value_box_list_t *result) CC_HINT(
nonnull(1,2,3,4));
334 fr_value_box_list_t *
in);
static int const char * fmt
#define NDEBUG_LOCATION_ARGS
Pass caller information to the function.
fr_dcursor_eval_t void const * uctx
static void * fr_dlist_next(fr_dlist_head_t const *list_head, void const *ptr)
Get the next item in a list.
static void * fr_dlist_head(fr_dlist_head_t const *list_head)
Return the HEAD item of a list or NULL if the list is empty.
static int fr_dlist_insert_tail(fr_dlist_head_t *list_head, void *ptr)
Insert an item into the tail of a list.
Head of a doubly linked list.
Entry in a doubly linked list.
ssize_t(* fr_pair_decode_t)(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, void *decode_ctx)
A generic interface for decoding fr_pair_ts.
Temporary structure to hold arguments for instantiation calls.
static decode_fail_t decode(TALLOC_CTX *ctx, fr_pair_list_t *reply, uint8_t *response_code, udp_handle_t *h, request_t *request, udp_request_t *u, uint8_t const request_authenticator[static RADIUS_AUTH_VECTOR_LENGTH], uint8_t *data, size_t data_len)
Decode response packet data, extracting relevant information and validating the packet.
Optional arguments passed to vp_tmpl functions.
fr_aka_sim_id_type_t type
int(* xlat_thread_detach_t)(xlat_thread_inst_ctx_t const *xctx)
xlat thread detach callback
int(* xlat_detach_t)(xlat_inst_ctx_t const *xctx)
xlat detach callback
void(* xlat_func_signal_t)(xlat_ctx_t const *xctx, request_t *request, fr_signal_t action)
A callback when the request gets a fr_signal_t.
bool can_purify
if the xlat has a pure function with pure arguments.
xlat_action_t(* xlat_func_t)(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
xlat callback function
#define XLAT_VERIFY(_node)
bool pure
has no external side effects, true for BOX, LITERAL, and some functions
bool needs_resolving
Needs pass2 resolution.
int(* xlat_thread_instantiate_t)(xlat_thread_inst_ctx_t const *xctx)
Allocate new thread instance data for an xlat instance.
bool constant
xlat is just tmpl_attr_tail_data, or XLAT_BOX
bool impure_func
xlat contains an impure function
int(* xlat_instantiate_t)(xlat_inst_ctx_t const *xctx)
Allocate new instance data for an xlat instance.
Definition for a single argument consumend by an xlat function.
Flags that control resolution and evaluation.
Instance data for an xlat expansion node.
Thread specific instance data for xlat expansion node.
static size_t char fr_sbuff_t size_t inlen
uintptr_t fr_value_box_safe_for_t
Escaping that's been applied to a value box.
static size_t char ** out
int(* xlat_purify_t)(xlat_exp_t *xlat, void *inst, request_t *request)
Custom function purify the result of an xlat function.
int(* xlat_resolve_t)(xlat_exp_t *xlat, void *inst, xlat_res_rules_t const *xr_rules)
Custom function to perform resolution of arguments.
fr_slen_t(* xlat_print_t)(fr_sbuff_t *in, xlat_exp_t const *self, void *inst, fr_sbuff_escape_rules_t const *e_rules)
Custom function to print xlat debug.
xlat_input_type_t input_type
The input type used inferred from the bracketing style.
char const * name
Name of xlat function.
char const * thread_inst_type
C type of thread instance structure.
static xlat_exp_t * xlat_exp_next(xlat_exp_head_t const *head, xlat_exp_t const *node)
xlat_flags_t flags
Flags that control resolution and evaluation.
fr_type_t return_type
Function is guaranteed to return one or more boxes of this type.
module_inst_ctx_t * mctx
Original module instantiation ctx if this xlat was registered by a module.
bool const xlat_func_chars[UINT8_MAX+1]
int xlat_tokenize_expansion(xlat_exp_head_t *head, fr_sbuff_t *in, tmpl_rules_t const *t_rules)
int xlat_decode_value_box_list(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, void *decode_ctx, fr_pair_decode_t decode, fr_value_box_list_t *in)
Decode all of the value boxes into the output cursor.
fr_rb_node_t func_node
Entry in the xlat function tree.
xlat_exp_t * _xlat_exp_alloc_null(NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx)
Allocate an xlat node with no name, and no type set.
void xlat_signal(xlat_func_signal_t signal, xlat_exp_t const *exp, request_t *request, void *rctx, fr_signal_t action)
Signal an xlat function.
fr_dict_t const * dict
Records the namespace this xlat call was created in.
bool ephemeral
Instance data is ephemeral (not inserted) into the instance tree.
xlat_func_t func
async xlat function (async unsafe).
xlat_instantiate_t instantiate
Instantiation function.
size_t thread_inst_size
Size of the thread instance data to pre-allocate.
xlat_detach_t detach
Destructor for when xlat instances are freed.
xlat_action_t xlat_frame_eval_resume(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_exp_head_t const **child, request_t *request, xlat_exp_head_t const *head, xlat_exp_t const **in, fr_value_box_list_t *result, xlat_func_t resume, void *rctx)
Call an xlat's resumption method.
xlat_flags_t flags
Flags that control resolution and evaluation.
char const *_CONST file
File where the xlat was allocated.
int line
Line where the xlat was allocated.
int xlat_register_expressions(void)
void * thread_uctx
uctx to pass to instantiation functions.
call_env_method_t const * call_env_method
Optional tmpl expansions performed before calling the xlat.
size_t inst_size
Size of instance data to pre-allocate.
int(* xlat_walker_t)(xlat_exp_t *exp, void *uctx)
Walker callback for xlat_walk()
fr_token_t quote
Type of quoting around XLAT_GROUP types.
@ XLAT_ONE_LETTER
Special "one-letter" expansion.
@ XLAT_TMPL
xlat attribute
@ XLAT_VIRTUAL_UNRESOLVED
virtual attribute needs resolution during pass2.
@ XLAT_VIRTUAL
virtual attribute
@ XLAT_GROUP
encapsulated string of xlats
@ XLAT_FUNC_UNRESOLVED
func needs resolution during pass2.
@ XLAT_INVALID
Bad expansion.
void xlat_exp_set_name(xlat_exp_t *node, char const *fmt, size_t len)
Set the format string for an xlat node.
fr_dict_attr_t const * attr_expr_bool_enum
xlat_arg_parser_t const * args
Definition of args consumed.
size_t len
Length of the output string.
xlat_resolve_t resolve
function to call when resolving
xlat_exp_t * _xlat_exp_alloc(NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx, xlat_type_t type, char const *in, size_t inlen)
Allocate an xlat node.
static void xlat_flags_merge(xlat_flags_t *parent, xlat_flags_t const *child)
Merge flags from child to parent.
char const * out
Output data.
xlat_exp_head_t * _xlat_exp_head_alloc(NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx)
void xlat_exp_set_name_buffer(xlat_exp_t *node, char const *fmt)
Set the format string for an xlat node, copying from a talloc'd buffer.
xlat_thread_instantiate_t thread_instantiate
Thread instantiation function.
xlat_thread_inst_t * thread_inst
Thread specific instance.
fr_dict_attr_t const * attr_cast_base
xlat_inst_t * inst
Instance data for the xlat_t.
fr_token_t token
for expressions
char const * inst_type
C type of instance structure.
static xlat_exp_t * xlat_exp_head(xlat_exp_head_t const *head)
xlat_t const * func
The xlat expansion to expand format with.
xlat_input_type_t input_type
Type of input used.
xlat_action_t xlat_frame_eval(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_exp_head_t const **child, request_t *request, xlat_exp_head_t const *head, xlat_exp_t const **in)
Converts xlat nodes to value boxes.
char const *_CONST fmt
The original format string (a talloced buffer).
ssize_t xlat_print_node(fr_sbuff_t *out, xlat_exp_head_t const *head, xlat_exp_t const *node, fr_sbuff_escape_rules_t const *e_rules, char c)
uint64_t id
Identifier unique to each permanent xlat node.
int unlang_xlat_push_node(TALLOC_CTX *ctx, bool *p_success, fr_value_box_list_t *out, request_t *request, xlat_exp_t *node)
Push a pre-compiled xlat onto the stack for evaluation.
int xlat_purify_list(xlat_exp_head_t *head, request_t *request)
xlat_type_t _CONST type
type of this expansion.
fr_value_box_safe_for_t return_safe_for
Escaped value to set in output boxes.
char const *_CONST file
File where the xlat was allocated.
xlat_thread_detach_t thread_detach
Destructor for when xlat thread instance data is freed.
void xlat_eval_free(void)
xlat_purify_t purify
function to call when purifying the node.
int xlat_eval_walk(xlat_exp_head_t *head, xlat_walker_t walker, xlat_type_t type, void *uctx)
Walk over all xlat nodes (depth first) in a xlat expansion, calling a callback.
xlat_flags_t flags
various flags
xlat_print_t print
function to call when printing
fr_dict_attr_t const * attr_module_return_code
int line
Line where the xlat was allocated.
static int xlat_exp_insert_tail(xlat_exp_head_t *head, xlat_exp_t *node)
fr_dict_attr_t const * xlat_time_res_attr(char const *res)
void xlat_exp_set_name_buffer_shallow(xlat_exp_t *node, char const *fmt)
Set the format string for an xlat node from a pre-existing buffer.
xlat_exp_head_t * args
arguments to the function call
void * uctx
uctx to pass to instantiation functions.
fr_dlist_t mi_entry
Entry in the list of functions registered to a module instance.
xlat_action_t xlat_frame_eval_repeat(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_exp_head_t const **child, request_t *request, xlat_exp_head_t const *head, xlat_exp_t const **in, void *env_data, fr_value_box_list_t *result))
Process the result of a previous nested expansion.
xlat_t * xlat_func_find(char const *name, ssize_t namelen)
void unlang_xlat_init(void)
Register xlat operation with the interpreter.
bool instantiated
temporary flag until we fix more things
void _xlat_exp_set_type(NDEBUG_LOCATION_ARGS xlat_exp_t *node, xlat_type_t type)
Set the type of an xlat node.