All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
map.h
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 #ifndef _FR_MAP_H
17 #define _FR_MAP_H
18 /**
19  * $Id: 66c30103539142f7e342223308530d577d1b07fd $
20  *
21  * @file include/map.h
22  * @brief Structures and prototypes for maps
23  *
24  * @copyright 2015 The FreeRADIUS server project
25  * @copyright 2015 Arran Cudbard-bell <a.cudbardb@freeradius.org>
26  */
27 RCSIDH(map_h, "$Id: 66c30103539142f7e342223308530d577d1b07fd $")
28 
29 #include <freeradius-devel/conffile.h>
30 #include <freeradius-devel/tmpl.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /** Value pair map
37  *
38  * Value pair maps contain a pair of templates, that describe a src attribute
39  * or value, and a destination attribute.
40  *
41  * Neither src or dst need to be an FR attribute, and their type can be inferred
42  * from whether map->da is NULL (not FR).
43  *
44  * @see vp_tmpl_t
45  */
46 typedef struct vp_map {
47  vp_tmpl_t *lhs; //!< Typically describes the attribute to add, modify or compare.
48  vp_tmpl_t *rhs; //!< Typically describes a literal value or a src attribute to copy or compare.
49 
50  FR_TOKEN op; //!< The operator that controls insertion of the dst attribute.
51 
52  CONF_ITEM *ci; //!< Config item that the map was created from. Mainly used for
53  //!< logging validation errors.
54 
55  struct vp_map *next; //!< The next valuepair map.
56 } vp_map_t;
57 
58 #ifndef WITH_VERIFY_PTR
59 # define VERIFY_MAP(_x) rad_assert((_x)->lhs)
60 #else
61 # define VERIFY_MAP(_x) do { \
62  VERIFY_TMPL((_x)->lhs); \
63  if ((_x)->rhs) VERIFY_TMPL((_x)->rhs); \
64 } while (0)
65 #endif
66 
67 typedef int (*map_validate_t)(vp_map_t *map, void *ctx);
68 typedef int (*radius_map_getvalue_t)(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request,
69  vp_map_t const *map, void *uctx);
70 
71 int map_afrom_cp(TALLOC_CTX *ctx, vp_map_t **out, CONF_PAIR *cp,
72  request_refs_t dst_request_def, pair_lists_t dst_list_def,
73  request_refs_t src_request_def, pair_lists_t src_list_def);
74 
75 int map_afrom_fields(TALLOC_CTX *ctx, vp_map_t **out, char const *lhs, FR_TOKEN lhs_type,
76  FR_TOKEN op, char const *rhs, FR_TOKEN rhs_type,
77  request_refs_t dst_request_def, pair_lists_t dst_list_def,
78  request_refs_t src_request_def, pair_lists_t src_list_def);
79 
80 int map_afrom_cs(vp_map_t **out, CONF_SECTION *cs,
81  pair_lists_t dst_list_def, pair_lists_t src_list_def,
82  map_validate_t validate, void *ctx, unsigned int max) CC_HINT(nonnull(1, 2));
83 
84 int map_afrom_attr_str(TALLOC_CTX *ctx, vp_map_t **out, char const *raw,
85  request_refs_t dst_request_def, pair_lists_t dst_list_def,
86  request_refs_t src_request_def, pair_lists_t src_list_def);
87 
88 int8_t map_cmp_by_lhs_attr(void const *a, void const *b);
89 
90 void map_sort(vp_map_t **maps, fr_cmp_t cmp);
91 
92 int map_to_vp(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request,
93  vp_map_t const *map, void *uctx) CC_HINT(nonnull (2,3,4));
94 
95 int map_to_request(REQUEST *request, vp_map_t const *map,
96  radius_map_getvalue_t func, void *ctx);
97 
98 bool map_dst_valid(REQUEST *request, vp_map_t const *map);
99 
100 size_t map_snprint(char *out, size_t outlen, vp_map_t const *map);
101 
102 void map_debug_log(REQUEST *request, vp_map_t const *map,
103  VALUE_PAIR const *vp) CC_HINT(nonnull(1, 2));
104 
105 bool map_cast_from_hex(vp_map_t *map, FR_TOKEN rhs_type, char const *rhs);
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif /* _FR_MAP_H */
int8_t(* fr_cmp_t)(void const *a, void const *b)
Definition: pair.h:227
size_t map_snprint(char *out, size_t outlen, vp_map_t const *map)
Print a map to a string.
Definition: map.c:1494
int(* radius_map_getvalue_t)(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, vp_map_t const *map, void *uctx)
Definition: map.h:68
#define RCSIDH(h, id)
Definition: build.h:136
void map_debug_log(REQUEST *request, vp_map_t const *map, VALUE_PAIR const *vp) CC_HINT(nonnull(1
int 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.
Definition: map.c:1019
int8_t map_cmp_by_lhs_attr(void const *a, void const *b)
Compare map where LHS is TMPL_TYPE_ATTR.
Definition: map.c:543
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.
Definition: map.c:207
struct vp_map vp_map_t
Value pair map.
vp_tmpl_t * lhs
Typically describes the attribute to add, modify or compare.
Definition: map.h:47
vp_tmpl_t * rhs
Typically describes a literal value or a src attribute to copy or compare.
Definition: map.h:48
#define CC_HINT(_x)
Definition: build.h:71
static expr_map_t map[]
Definition: rlm_expr.c:169
struct vp_map * next
The next valuepair map.
Definition: map.h:55
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) CC_HINT(nonnull(1
Stores an attribute, a value and various bits of other data.
Definition: pair.h:112
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.
Definition: map.c:434
Configuration AVP similar to a VALUE_PAIR.
Definition: conffile.c:82
void map_sort(vp_map_t **maps, fr_cmp_t cmp)
Sort a linked list of vp_map_t using merge sort.
Definition: map.c:631
int(* map_validate_t)(vp_map_t *map, void *ctx)
Definition: map.h:67
void 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.
Definition: map.c:57
int int map_afrom_attr_str(TALLOC_CTX *ctx, vp_map_t **out, char const *raw, 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.
Definition: map.c:487
FR_TOKEN op
The operator that controls insertion of the dst attribute.
Definition: map.h:50
bool map_dst_valid(REQUEST *request, vp_map_t const *map)
Check whether the destination of a map is currently valid.
Definition: map.c:1473
enum pair_lists pair_lists_t
int map_to_vp(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, vp_map_t const *map, void *uctx) CC_HINT(nonnull(2
enum fr_token FR_TOKEN
Definition: pair.c:37
Value pair map.
Definition: map.h:46
A source or sink of value data.
Definition: tmpl.h:187
enum requests request_refs_t
CONF_ITEM * ci
Config item that the map was created from.
Definition: map.h:52