All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions
map.c File Reference
#include <freeradius-devel/radiusd.h>
#include <freeradius-devel/rad_assert.h>
#include <ctype.h>
+ Include dependency graph for map.c:

Go to the source code of this file.

Macros

#define DEBUG_OVERWRITE(_old, _new)
 

Functions

int map_afrom_attr_str (TALLOC_CTX *ctx, vp_map_t **out, char const *vp_str, request_refs_t dst_request_def, pair_lists_t dst_list_def, request_refs_t src_request_def, pair_lists_t src_list_def)
 Convert a value pair string to valuepair map. More...
 
int map_afrom_cp (TALLOC_CTX *ctx, vp_map_t **out, CONF_PAIR *cp, request_refs_t dst_request_def, pair_lists_t dst_list_def, request_refs_t src_request_def, pair_lists_t src_list_def)
 Convert CONFIG_PAIR (which may contain refs) to vp_map_t. More...
 
int map_afrom_cs (vp_map_t **out, CONF_SECTION *cs, pair_lists_t dst_list_def, pair_lists_t src_list_def, map_validate_t validate, void *ctx, unsigned int max)
 Convert an 'update' config section into an attribute map. More...
 
int map_afrom_fields (TALLOC_CTX *ctx, vp_map_t **out, char const *lhs, FR_TOKEN lhs_type, FR_TOKEN op, char const *rhs, FR_TOKEN rhs_type, request_refs_t dst_request_def, pair_lists_t dst_list_def, request_refs_t src_request_def, pair_lists_t src_list_def)
 Convert strings to vp_map_t. More...
 
bool map_cast_from_hex (vp_map_t *map, FR_TOKEN rhs_type, char const *rhs)
 re-parse a map where the lhs is an unknown attribute. More...
 
int8_t map_cmp_by_lhs_attr (void const *a, void const *b)
 Compare map where LHS is TMPL_TYPE_ATTR. More...
 
void map_debug_log (REQUEST *request, vp_map_t const *map, VALUE_PAIR const *vp)
 
bool map_dst_valid (REQUEST *request, vp_map_t const *map)
 Check whether the destination of a map is currently valid. More...
 
static int map_exec_to_vp (TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, vp_map_t const *map)
 Process map which has exec as a src. More...
 
size_t map_snprint (char *out, size_t outlen, vp_map_t const *map)
 Print a map to a string. More...
 
void map_sort (vp_map_t **maps, fr_cmp_t cmp)
 Sort a linked list of vp_map_t using merge sort. More...
 
static vp_map_tmap_sort_merge (vp_map_t *a, vp_map_t *b, fr_cmp_t cmp)
 
static void map_sort_split (vp_map_t *source, vp_map_t **front, vp_map_t **back)
 
int map_to_request (REQUEST *request, vp_map_t const *map, radius_map_getvalue_t func, void *ctx)
 Convert vp_map_t to VALUE_PAIR (s) and add them to a REQUEST. More...
 
int map_to_vp (TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, vp_map_t const *map, UNUSED void *uctx)
 Convert a map to a VALUE_PAIR. More...
 

Macro Definition Documentation

#define DEBUG_OVERWRITE (   _old,
  _new 
)
Value:
do {\
char *old = fr_pair_value_asprint(request, _old, '"');\
char *new = fr_pair_value_asprint(request, _new, '"');\
RDEBUG3("--> overwriting '%s' with '%s'", old, new);\
talloc_free(old);\
talloc_free(new);\
}\
} while (0)
#define RINDENT()
Indent R* messages by one level.
Definition: log.h:265
#define RDEBUG_ENABLED3
True if request debug level 1-3 messages are enabled.
Definition: log.h:239
char * fr_pair_value_asprint(TALLOC_CTX *ctx, VALUE_PAIR const *vp, char quote)
Print one attribute value to a string.
Definition: pair.c:2123
#define REXDENT()
Exdent (unindent) R* messages by one level.
Definition: log.h:272
#define RDEBUG3(fmt,...)
Definition: log.h:245

Definition at line 989 of file map.c.

Function Documentation

int map_afrom_attr_str ( TALLOC_CTX *  ctx,
vp_map_t **  out,
char const *  vp_str,
request_refs_t  dst_request_def,
pair_lists_t  dst_list_def,
request_refs_t  src_request_def,
pair_lists_t  src_list_def 
)

Convert a value pair string to valuepair map.

Takes a valuepair string with list and request qualifiers and converts it into a vp_map_t.

Parameters
ctxwhere to allocate the map.
outWhere to write the new map (must be freed with talloc_free()).
vp_strstring to parse.
dst_request_defto use if attribute isn't qualified.
dst_list_defto use if attribute isn't qualified.
src_request_defto use if attribute isn't qualified.
src_list_defto use if attribute isn't qualified.
Returns
  • 0 on success.
  • < 0 on error.

Definition at line 487 of file map.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int map_afrom_cp ( TALLOC_CTX *  ctx,
vp_map_t **  out,
CONF_PAIR cp,
request_refs_t  dst_request_def,
pair_lists_t  dst_list_def,
request_refs_t  src_request_def,
pair_lists_t  src_list_def 
)

Convert CONFIG_PAIR (which may contain refs) to vp_map_t.

Treats the left operand as an attribute reference

<request>.<list>.<attribute>

Treatment of left operand depends on quotation, barewords are treated as attribute references, double quoted values are treated as expandable strings, single quoted values are treated as literal strings.

Return must be freed with talloc_free

Parameters
[in]ctxfor talloc.
[in]outWhere to write the pointer to the new vp_map_t.
[in]cpto convert to map.
[in]dst_request_defThe default request to insert unqualified attributes into.
[in]dst_list_defThe default list to insert unqualified attributes into.
[in]src_request_defThe default request to resolve attribute references in.
[in]src_list_defThe default list to resolve unqualified attributes in.
Returns
  • vp_map_t if successful.
  • NULL on error.

Definition at line 207 of file map.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int map_afrom_cs ( vp_map_t **  out,
CONF_SECTION cs,
pair_lists_t  dst_list_def,
pair_lists_t  src_list_def,
map_validate_t  validate,
void *  ctx,
unsigned int  max 
)

Convert an 'update' config section into an attribute map.

Uses 'name2' of section to set default request and lists.

Parameters
[in]csthe update section
[out]outWhere to store the head of the map.
[in]dst_list_defThe default destination list, usually dictated by the section the module is being called in.
[in]src_list_defThe default source list, usually dictated by the section the module is being called in.
[in]validatemap using this callback (may be NULL).
[in]ctxto pass to callback.
[in]maxnumber of mappings to process.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 331 of file map.c.

+ Here is the call graph for this function:

int map_afrom_fields ( TALLOC_CTX *  ctx,
vp_map_t **  out,
char const *  lhs,
FR_TOKEN  lhs_type,
FR_TOKEN  op,
char const *  rhs,
FR_TOKEN  rhs_type,
request_refs_t  dst_request_def,
pair_lists_t  dst_list_def,
request_refs_t  src_request_def,
pair_lists_t  src_list_def 
)

Convert strings to vp_map_t.

Treatment of operands depends on quotation, barewords are treated as attribute references, double quoted values are treated as expandable strings, single quoted values are treated as literal strings.

Return must be freed with talloc_free

Parameters
[in]ctxfor talloc
[out]outWhere to store the head of the map.
[in]lhsof the operation
[in]lhs_typetype of the LHS string
[in]opthe operation to perform
[in]rhsof the operation
[in]rhs_typetype of the RHS string
[in]dst_request_defThe default request to insert unqualified attributes into.
[in]dst_list_defThe default list to insert unqualified attributes into.
[in]src_request_defThe default request to resolve attribute references in.
[in]src_list_defThe default list to resolve unqualified attributes in.
Returns
vp_map_t if successful or NULL on error.

Definition at line 434 of file map.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool map_cast_from_hex ( vp_map_t map,
FR_TOKEN  rhs_type,
char const *  rhs 
)

re-parse a map where the lhs is an unknown attribute.

Parameters
mapto process.
rhs_typequotation type around rhs.
rhsstring to re-parse.

Definition at line 57 of file map.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int8_t map_cmp_by_lhs_attr ( void const *  a,
void const *  b 
)

Compare map where LHS is TMPL_TYPE_ATTR.

Compares maps by lhs->tmpl_da, lhs->tmpl_tag, lhs->tmpl_num

Note
both map->lhs must be TMPL_TYPE_ATTR.
Parameters
afirst map.
bsecond map.

Definition at line 543 of file map.c.

+ Here is the call graph for this function:

void map_debug_log ( REQUEST request,
vp_map_t const *  map,
VALUE_PAIR const *  vp 
)

Definition at line 1543 of file map.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool map_dst_valid ( REQUEST request,
vp_map_t const *  map 
)

Check whether the destination of a map is currently valid.

Parameters
requestThe current request.
mapto check.
Returns
  • true if the map resolves to a request and list.
  • false.

Definition at line 1473 of file map.c.

+ Here is the call graph for this function:

static int map_exec_to_vp ( TALLOC_CTX *  ctx,
VALUE_PAIR **  out,
REQUEST request,
vp_map_t const *  map 
)
static

Process map which has exec as a src.

Evaluate maps which specify exec as a src. This may be used by various sorts of update sections, and so has been broken out into it's own function.

Parameters
[in,out]ctxto allocate new VALUE_PAIR (s) in.
[out]outWhere to write the VALUE_PAIR (s).
[in]requeststructure (used only for talloc).
[in]mapthe map. The LHS (dst) must be TMPL_TYPE_ATTR or TMPL_TYPE_LIST. The RHS (src) must be TMPL_TYPE_EXEC.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 668 of file map.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t map_snprint ( char *  out,
size_t  outlen,
vp_map_t const *  map 
)

Print a map to a string.

Parameters
[out]outBuffer to write string to.
[in]outlenSize of the output buffer.
[in]mapto print.
Returns
  • The number of bytes written to the out buffer.
  • A number >= outlen if truncation has occurred.

Definition at line 1494 of file map.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void map_sort ( vp_map_t **  maps,
fr_cmp_t  cmp 
)

Sort a linked list of vp_map_t using merge sort.

Parameters
[in,out]mapsList of vp_map_t to sort.
[in]cmpto sort with

Definition at line 631 of file map.c.

+ Here is the call graph for this function:

static vp_map_t* map_sort_merge ( vp_map_t a,
vp_map_t b,
fr_cmp_t  cmp 
)
static

Definition at line 605 of file map.c.

+ Here is the caller graph for this function:

static void map_sort_split ( vp_map_t source,
vp_map_t **  front,
vp_map_t **  back 
)
static

Definition at line 570 of file map.c.

+ Here is the caller graph for this function:

int map_to_request ( REQUEST request,
vp_map_t const *  map,
radius_map_getvalue_t  func,
void *  ctx 
)

Convert vp_map_t to VALUE_PAIR (s) and add them to a REQUEST.

Takes a single vp_map_t, resolves request and list identifiers to pointers in the current request, then attempts to retrieve module specific value(s) using callback, and adds the resulting values to the correct request/list.

Parameters
requestThe current request.
mapspecifying destination attribute and location and src identifier.
functo retrieve module specific values and convert them to VALUE_PAIR.
ctxto be passed to func.
Returns
  • -1 if the operation failed.
  • -2 in the source attribute wasn't valid.
  • 0 on success.

Definition at line 1019 of file map.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int map_to_vp ( TALLOC_CTX *  ctx,
VALUE_PAIR **  out,
REQUEST request,
vp_map_t const *  map,
UNUSED void *  uctx 
)

Convert a map to a VALUE_PAIR.

Parameters
[in,out]ctxto allocate VALUE_PAIR (s) in.
[out]outWhere to write the VALUE_PAIR (s), which may be NULL if not found
[in]requestThe current request.
[in]mapthe map. The LHS (dst) has to be TMPL_TYPE_ATTR or TMPL_TYPE_LIST.
[in]uctxunused.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 748 of file map.c.

+ Here is the call graph for this function: