The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
fr_pair_t template functions More...
#include <freeradius-devel/server/exec.h>
#include <freeradius-devel/server/exec_legacy.h>
#include <freeradius-devel/server/tmpl.h>
#include <freeradius-devel/server/tmpl_dcursor.h>
#include <freeradius-devel/server/client.h>
#include <freeradius-devel/unlang/call.h>
#include <freeradius-devel/util/atexit.h>
#include <freeradius-devel/util/dlist.h>
#include <freeradius-devel/util/proto.h>
#include <freeradius-devel/util/value.h>
#include <freeradius-devel/util/edit.h>
#include <freeradius-devel/util/token.h>
#include <freeradius-devel/util/types.h>
#include <talloc.h>
Go to the source code of this file.
Macros | |
#define | _TMPL_PRIVATE 1 |
Functions | |
static int | _tmpl_global_free (UNUSED void *uctx) |
static int | _tmpl_global_init (UNUSED void *uctx) |
ssize_t | _tmpl_to_atype (TALLOC_CTX *ctx, void *out, request_t *request, tmpl_t const *vpt, xlat_escape_legacy_t escape, void const *escape_ctx, fr_type_t dst_type) |
Expand a template to a string, allocing a new buffer to hold the string. | |
ssize_t | _tmpl_to_type (void *out, uint8_t *buff, size_t bufflen, request_t *request, tmpl_t const *vpt, xlat_escape_legacy_t escape, void const *escape_ctx, fr_type_t dst_type) |
Expand a tmpl_t to a string writing the result to a buffer. | |
if (!vpt->rules.escape.func &&vpt->rules.escape.safe_for) | |
if ((!did_concat &&tmpl_escape_pre_concat(vpt))||tmpl_escape_post_concat(vpt)) | |
int | pair_append_by_tmpl_parent (TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, tmpl_t const *vpt, bool skip_list) |
Allocate and insert a leaf vp from a tmpl_t, building the parent vps if needed. | |
int | tmpl_copy_pair_children (TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, tmpl_t const *vpt) |
Copy children of pairs matching a tmpl_t in the current request_t. | |
int | tmpl_copy_pairs (TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, tmpl_t const *vpt) |
Copy pairs matching a tmpl_t in the current request_t. | |
int | tmpl_eval (TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt) |
Gets the value of a tmpl. | |
int | tmpl_eval_cast_in_place (fr_value_box_list_t *list, request_t *request, tmpl_t const *vpt) |
Casts a value or list of values according to the tmpl. | |
static void * | tmpl_eval_escape_uctx_alloc (request_t *request, tmpl_escape_t const *escape) |
Allocate a uctx for an escaping function. | |
static void | tmpl_eval_escape_uctx_free (tmpl_escape_t const *escape, void *uctx) |
Free a uctx for an escaping function. | |
int | tmpl_eval_pair (TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt) |
Gets the value of a real or virtual attribute. | |
fr_type_t | tmpl_expanded_type (tmpl_t const *vpt) |
Return the native data type of the expression. | |
int | tmpl_find_or_add_vp (fr_pair_t **out, request_t *request, tmpl_t const *vpt) |
Returns the first VP matching a tmpl_t, or if no VPs match, creates a new one. | |
int | tmpl_find_vp (fr_pair_t **out, request_t *request, tmpl_t const *vpt) |
Returns the first VP matching a tmpl_t. | |
int | tmpl_global_init (void) |
TALLOC_CTX * | tmpl_list_ctx (request_t *request, fr_dict_attr_t const *list) |
Return the correct TALLOC_CTX to alloc fr_pair_t in, for a list. | |
fr_pair_list_t * | tmpl_list_head (request_t *request, fr_dict_attr_t const *list) |
Resolve attribute fr_pair_list_t value to an attribute list. | |
fr_packet_t * | tmpl_packet_ptr (request_t *request, fr_dict_attr_t const *list) |
Resolve a list to the fr_packet_t holding the HEAD pointer for a fr_pair_t list. | |
int | tmpl_request_ptr (request_t **context, FR_DLIST_HEAD(tmpl_request_list) const *rql) |
Resolve a tmpl_request_ref_t to a request_t. | |
int | tmpl_value_list_insert_tail (fr_value_box_list_t *list, fr_value_box_t *box, tmpl_t const *vpt) |
Insert a value-box to a list, with casting. | |
VALUE_BOX_LIST_VERIFY (list) | |
Variables | |
static fr_dict_t const * | dict_freeradius |
static fr_dict_t const * | dict_radius |
goto | success |
fr_dict_attr_t const * | tmpl_attr_unspec |
Placeholder attribute for uses of unspecified attribute references. | |
fr_dict_autoload_t | tmpl_dict [] |
fr_pair_t template functions
Definition in file tmpl_eval.c.
#define _TMPL_PRIVATE 1 |
Definition at line 29 of file tmpl_eval.c.
|
static |
Definition at line 1458 of file tmpl_eval.c.
|
static |
Definition at line 1467 of file tmpl_eval.c.
ssize_t _tmpl_to_atype | ( | TALLOC_CTX * | ctx, |
void * | out, | ||
request_t * | request, | ||
tmpl_t const * | vpt, | ||
xlat_escape_legacy_t | escape, | ||
void const * | escape_ctx, | ||
fr_type_t | dst_type | ||
) |
Expand a template to a string, allocing a new buffer to hold the string.
The intended use of tmpl_expand and tmpl_aexpand is for modules to easily convert a tmpl_t provided by the conf parser, into a usable value. The value returned should be raw and undoctored for FR_TYPE_STRING and FR_TYPE_OCTETS types, and the printable (string) version of the data for all others.
This function will always duplicate values, whereas tmpl_expand may return a pointer to an existing buffer.
ctx | to allocate new buffer in. |
out | Where to write pointer to the new buffer. |
request | Current request. |
vpt | to expand. Must be one of the following types: |
escape | xlat escape function (only used for TMPL_TYPE_XLAT_UNRESOLVED_* types). |
escape_ctx | xlat escape function data (only used for TMPL_TYPE_XLAT_UNRESOLVED_* types). |
dst_type | FR_TYPE_* matching out pointer. |
Definition at line 563 of file tmpl_eval.c.
ssize_t _tmpl_to_type | ( | void * | out, |
uint8_t * | buff, | ||
size_t | bufflen, | ||
request_t * | request, | ||
tmpl_t const * | vpt, | ||
xlat_escape_legacy_t | escape, | ||
void const * | escape_ctx, | ||
fr_type_t | dst_type | ||
) |
Expand a tmpl_t to a string writing the result to a buffer.
The intended use of tmpl_expand and tmpl_aexpand is for modules to easily convert a tmpl_t provided by the conf parser, into a usable value. The value returned should be raw and undoctored for FR_TYPE_STRING and FR_TYPE_OCTETS types, and the printable (string) version of the data for all others.
Depending what arguments are passed, either copies the value to buff, or writes a pointer to a string buffer to out. This allows the most efficient access to the value resolved by the tmpl_t, avoiding unnecessary string copies.
[out] | out | Where to write a pointer to the string buffer. On return may point to buff if buff was used to store the value. Otherwise will point to a fr_value_box_t buffer, or the name of the template. Must not be NULL. |
[out] | buff | Expansion buffer, may be NULL except for the following types: |
[in] | bufflen | Length of expansion buffer. Must be >= 2. |
[in] | request | Current request. |
[in] | vpt | to expand. Must be one of the following types: |
[in] | escape | xlat escape function (only used for xlat types). |
[in] | escape_ctx | xlat escape function data. |
dst_type | FR_TYPE_* matching out pointer. |
Definition at line 284 of file tmpl_eval.c.
if | ( | (!did_concat &&tmpl_escape_pre_concat(vpt))||tmpl_escape_post_concat(vpt) | ) |
int pair_append_by_tmpl_parent | ( | TALLOC_CTX * | ctx, |
fr_pair_t ** | out, | ||
fr_pair_list_t * | list, | ||
tmpl_t const * | vpt, | ||
bool | skip_list | ||
) |
Allocate and insert a leaf vp from a tmpl_t, building the parent vps if needed.
This is the simple case - just add a vp at the first place where the parents exist, or create the parents, with no attempt to handle filters.
It is functionally equivalent to fr_pair_append_by_da_parent() but uses a tmpl_t to build the nested structure rather than a fr_dict_attr_t.
[in] | ctx | to allocate new pair(s) in |
[out] | out | Leaf pair we allocated. |
[in] | list | to insert into. |
[in] | vpt | tmpl representing the attribute to add. |
[in] | skip_list | skip list attr ref at the head of the tmpl. |
Definition at line 974 of file tmpl_eval.c.
int tmpl_copy_pair_children | ( | TALLOC_CTX * | ctx, |
fr_pair_list_t * | out, | ||
request_t * | request, | ||
tmpl_t const * | vpt | ||
) |
Copy children of pairs matching a tmpl_t in the current request_t.
ctx | to allocate new fr_pair_t in. |
out | Where to write the copied fr_pair_t (s). |
request | The current request_t. |
vpt | specifying the fr_pair_t type or list to copy. Must be one of the following types: |
Definition at line 841 of file tmpl_eval.c.
int tmpl_copy_pairs | ( | TALLOC_CTX * | ctx, |
fr_pair_list_t * | out, | ||
request_t * | request, | ||
tmpl_t const * | vpt | ||
) |
Copy pairs matching a tmpl_t in the current request_t.
ctx | to allocate new fr_pair_t in. |
out | Where to write the copied fr_pair_t (s). |
request | The current request_t. |
vpt | specifying the fr_pair_t type or list to copy. Must be one of the following types: |
Definition at line 798 of file tmpl_eval.c.
int tmpl_eval | ( | TALLOC_CTX * | ctx, |
fr_value_box_list_t * | out, | ||
request_t * | request, | ||
tmpl_t const * | vpt | ||
) |
Gets the value of a tmpl.
The result is returned "raw". The caller must do any escaping it desires.
[in] | ctx | to allocate boxed value, and buffers in. |
[out] | out | Where to write the boxed value. |
[in] | request | The current request. |
[in] | vpt | Representing the tmpl |
Definition at line 1221 of file tmpl_eval.c.
Casts a value or list of values according to the tmpl.
[in,out] | list | Where to write the boxed value. |
[in] | request | The current request. |
[in] | vpt | Representing the attribute. |
Definition at line 1349 of file tmpl_eval.c.
|
inlinestatic |
Allocate a uctx for an escaping function.
[in] | request | The current request. |
[in] | escape | Describing how to escape tmpl data. |
Definition at line 1293 of file tmpl_eval.c.
|
inlinestatic |
Free a uctx for an escaping function.
[in] | escape | Describing how to escape tmpl data. |
[in] | uctx | The uctx to free. |
Definition at line 1324 of file tmpl_eval.c.
int tmpl_eval_pair | ( | TALLOC_CTX * | ctx, |
fr_value_box_list_t * | out, | ||
request_t * | request, | ||
tmpl_t const * | vpt | ||
) |
Gets the value of a real or virtual attribute.
[in] | ctx | to allocate boxed value, and buffers in. |
[out] | out | Where to write the boxed value. |
[in] | request | The current request. |
[in] | vpt | Representing the attribute. |
Definition at line 1077 of file tmpl_eval.c.
Return the native data type of the expression.
[in] | vpt | to determine the type of. |
Definition at line 209 of file tmpl_eval.c.
Returns the first VP matching a tmpl_t, or if no VPs match, creates a new one.
[out] | out | where to write the retrieved or created vp. |
[in] | request | The current request_t. |
[in] | vpt | specifying the fr_pair_t type to retrieve or create. Must be TMPL_TYPE_ATTR. |
Definition at line 918 of file tmpl_eval.c.
Returns the first VP matching a tmpl_t.
[out] | out | where to write the retrieved vp. |
[in] | request | The current request_t. |
[in] | vpt | specifying the fr_pair_t type to find. Must be one of the following types: |
Definition at line 889 of file tmpl_eval.c.
int tmpl_global_init | ( | void | ) |
Definition at line 1485 of file tmpl_eval.c.
TALLOC_CTX * tmpl_list_ctx | ( | request_t * | request, |
fr_dict_attr_t const * | list | ||
) |
Return the correct TALLOC_CTX to alloc fr_pair_t in, for a list.
Allocating new fr_pair_t in the context of a request_t is usually wrong. fr_pair_t should be allocated in the context of a fr_packet_t, so that if the fr_packet_t is freed before the request_t, the associated fr_pair_t lists are freed too.
[in] | request | containing the target lists. |
[in] | list | fr_pair_list_t value to resolve to TALLOC_CTX. |
Definition at line 116 of file tmpl_eval.c.
fr_pair_list_t * tmpl_list_head | ( | request_t * | request, |
fr_dict_attr_t const * | list | ||
) |
Resolve attribute fr_pair_list_t value to an attribute list.
The value returned is a pointer to the pointer of the HEAD of a fr_pair_t list in the request_t. If the head of the list changes, the pointer will still be valid.
[in] | request | containing the target lists. |
[in] | list | fr_pair_list_t value to resolve to fr_pair_t list. Will be NULL if list name couldn't be resolved. |
Definition at line 76 of file tmpl_eval.c.
fr_packet_t * tmpl_packet_ptr | ( | request_t * | request, |
fr_dict_attr_t const * | list | ||
) |
Resolve a list to the fr_packet_t holding the HEAD pointer for a fr_pair_t list.
Returns a pointer to the fr_packet_t that holds the HEAD pointer of a given list, for the current request_t.
[in] | request | To resolve list in. |
[in] | list | fr_pair_list_t value to resolve to fr_packet_t. |
Definition at line 146 of file tmpl_eval.c.
int tmpl_request_ptr | ( | request_t ** | context, |
FR_DLIST_HEAD(tmpl_request_list) const * | rql | ||
) |
Resolve a tmpl_request_ref_t to a request_t.
Sometimes request_t structs may be chained to each other, as is the case when internally proxying EAP. This function resolves a tmpl_request_ref_t to a request_t higher in the chain than the current request_t.
[in,out] | context | request_t to start resolving from, and where to write a pointer to the resolved request_t back to. |
[in] | rql | list of request qualifiers to follow. |
Definition at line 169 of file tmpl_eval.c.
int tmpl_value_list_insert_tail | ( | fr_value_box_list_t * | list, |
fr_value_box_t * | box, | ||
tmpl_t const * | vpt | ||
) |
Insert a value-box to a list, with casting.
list | to append to |
box | box to cast / append |
vpt | tmpl with cast. |
Definition at line 1052 of file tmpl_eval.c.
VALUE_BOX_LIST_VERIFY | ( | list | ) |
|
static |
Definition at line 48 of file tmpl_eval.c.
|
static |
Definition at line 49 of file tmpl_eval.c.
goto success |
Definition at line 1455 of file tmpl_eval.c.
fr_dict_attr_t const * tmpl_attr_unspec |
Placeholder attribute for uses of unspecified attribute references.
Definition at line 61 of file tmpl_eval.c.
fr_dict_autoload_t tmpl_dict |
Definition at line 52 of file tmpl_eval.c.