The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
map_proc.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17 
18 /**
19  * $Id: 9a83cda76547c661cf50dd9bc488b6f8d6c442ef $
20  *
21  * @file lib/server/map_proc.h
22  * @brief Structures and prototypes for map functions
23  *
24  * @copyright 2015 The FreeRADIUS server project
25  * @copyright 2015 Arran Cudbard-bell (a.cudbardb@freeradius.org)
26  */
27 RCSIDH(map_proc_h, "$Id: 9a83cda76547c661cf50dd9bc488b6f8d6c442ef $")
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 typedef struct map_proc map_proc_t;
34 typedef struct map_proc_inst map_proc_inst_t;
35 
36 #ifdef __cplusplus
37 }
38 #endif
39 
40 #include <freeradius-devel/server/cf_util.h>
41 #include <freeradius-devel/server/tmpl.h>
42 #include <freeradius-devel/server/map.h>
43 #include <freeradius-devel/util/value.h>
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 /** Function to evaluate the src string and map the result to server attributes
50  *
51  * @param[out] p_result Result of applying the map:
52  * - #RLM_MODULE_NOOP - If no data available for given src, or no mappings matched available data.
53  * - #RLM_MODULE_UPDATED - If new pairs were added to the request.
54  * - #RLM_MODULE_FAIL - If an error occurred performing the mapping.
55  * @param[in] mod_inst Instance of the module that registered the map_proc.
56  * @param[in] proc_inst Map proc data created by #map_proc_instantiate_t.
57  * @param[in] request The current request.
58  * @param[in,out] result Input data for the map processor. May be consumed by the
59  * map processor.
60  * @param[in] maps Head of the list of maps to process.
61  * @return one of UNLANG_ACTION_*
62  */
63 typedef unlang_action_t (*map_proc_func_t)(rlm_rcode_t *p_result, void const *mod_inst, void *proc_inst, request_t *request,
64  fr_value_box_list_t *result, map_list_t const *maps);
65 
66 /** Allocate new instance data for a map processor
67  *
68  * @param[in] cs #CONF_SECTION representing this instance of a map processor.
69  * @param[in] mod_inst Module instance that registered the #map_proc_t.
70  * @param[in] proc_inst Structure to populate. Allocated by #map_proc_instantiate.
71  * @param[in] src template.
72  * @param[in] maps Head of the list of maps to process.
73  * @return
74  * - 0 on success.
75  * - -1 on failure.
76  */
77 typedef int (*map_proc_instantiate_t)(CONF_SECTION *cs, void const *mod_inst, void *proc_inst,
78  tmpl_t const *src, map_list_t const *maps);
79 
81 
82 map_proc_t *map_proc_find(char const *name);
83 
84 int map_proc_register(TALLOC_CTX *ctx, void const *mod_inst, char const *name,
85  map_proc_func_t evaluate,
86  map_proc_instantiate_t instantiate, size_t inst_size, fr_value_box_safe_for_t safe_for);
87 
88 int map_proc_unregister(char const *name);
89 
90 map_proc_inst_t *map_proc_instantiate(TALLOC_CTX *ctx, map_proc_t const *proc,
91  CONF_SECTION *cs, tmpl_t const *src, map_list_t const *maps);
92 
93 unlang_action_t map_proc(rlm_rcode_t *p_result, request_t *request, map_proc_inst_t const *inst, fr_value_box_list_t *src);
94 
95 #ifdef __cplusplus
96 }
97 #endif
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition: action.h:35
#define RCSIDH(h, id)
Definition: build.h:482
A section grouping multiple CONF_PAIR.
Definition: cf_priv.h:101
int(* map_proc_instantiate_t)(CONF_SECTION *cs, void const *mod_inst, void *proc_inst, tmpl_t const *src, map_list_t const *maps)
Allocate new instance data for a map processor.
Definition: map_proc.h:77
map_proc_t * map_proc_find(char const *name)
Find a map processor by name.
Definition: map_proc.c:87
unlang_action_t map_proc(rlm_rcode_t *p_result, request_t *request, map_proc_inst_t const *inst, fr_value_box_list_t *src)
Evaluate a set of maps using the specified map processor.
Definition: map_proc.c:247
int map_proc_unregister(char const *name)
Unregister a map processor by name.
Definition: map_proc.c:183
map_proc_inst_t * map_proc_instantiate(TALLOC_CTX *ctx, map_proc_t const *proc, CONF_SECTION *cs, tmpl_t const *src, map_list_t const *maps)
Create a new map proc instance.
Definition: map_proc.c:210
unlang_action_t(* map_proc_func_t)(rlm_rcode_t *p_result, void const *mod_inst, void *proc_inst, request_t *request, fr_value_box_list_t *result, map_list_t const *maps)
Function to evaluate the src string and map the result to server attributes.
Definition: map_proc.h:63
int map_proc_register(TALLOC_CTX *ctx, void const *mod_inst, char const *name, map_proc_func_t evaluate, map_proc_instantiate_t instantiate, size_t inst_size, fr_value_box_safe_for_t safe_for)
Register a map processor.
Definition: map_proc.c:131
fr_value_box_safe_for_t map_proc_literals_safe_for(map_proc_t const *proc)
Definition: map_proc.c:75
map_proc_t const * proc
Map processor.
Definition: map_proc_priv.h:54
tmpl_t const * src
Evaluated to provide source value for map processor.
Definition: map_proc_priv.h:55
map_list_t const * maps
Head of the map list.
Definition: map_proc_priv.h:56
Map processor registration.
Definition: map_proc_priv.h:39
Map processor instance.
Definition: map_proc_priv.h:53
rlm_rcode_t
Return codes indicating the result of the module call.
Definition: rcode.h:40
static char const * name
static int instantiate(module_inst_ctx_t const *mctx)
Definition: rlm_rest.c:1302
eap_aka_sim_process_conf_t * inst
uintptr_t fr_value_box_safe_for_t
Escaping that's been applied to a value box.
Definition: value.h:155