All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
xlat.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_XLAT_H
17 #define _FR_XLAT_H
18 /**
19  * $Id: 8b404dad2c9c5805403ee869a985c96689b90a56 $
20  *
21  * @file include/xlat.h
22  * @brief xlat expansion parsing and evaluation API.
23  *
24  * @copyright 2015 The FreeRADIUS server project
25  */
26 RCSIDH(xlat_h, "$Id: 8b404dad2c9c5805403ee869a985c96689b90a56 $")
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <freeradius-devel/conffile.h>
33 
34 typedef struct xlat_exp xlat_exp_t;
35 
36 typedef size_t (*xlat_escape_t)(REQUEST *request, char *out, size_t outlen, char const *in, void *arg);
37 
38 /** xlat callback function
39  *
40  * Should write the result of expanding the fmt string to the output buffer.
41  *
42  * If a outlen > 0 was provided to #xlat_register, out will point to a talloced
43  * buffer of that size, which the result should be written to.
44  *
45  * If outlen is 0, then the function should allocate its own buffer, in the
46  * context of the request.
47  *
48  * @param[in,out] out Where to write either a pointer to a new buffer, or data to an existing buffer.
49  * @param[in] outlen Length of pre-allocated buffer, or 0 if function should allocate its own buffer.
50  * @param[in] mod_inst Instance data provided by the module that registered the xlat.
51  * @param[in] xlat_inst Instance data created by the xlat instantiation function.
52  * @param[in] request The current request.
53  * @param[in] fmt string to expand.
54  */
55 typedef ssize_t (*xlat_func_t)(char **out, size_t outlen,
56  void const *mod_inst, void const *xlat_inst,
57  REQUEST *request, char const *fmt);
58 
59 /** Allocate new instance data for an xlat instance
60  *
61  * @param[out] xlat_inst Structure to populate. Allocated by #map_proc_instantiate.
62  * @param[in] mod_inst Module instance that registered the #xlat_func_t.
63  * @param[in] fmt string to base instantiation around.
64  * @return
65  * - 0 on success.
66  * - -1 on failure.
67  */
68 typedef int (*xlat_instantiate_t)(void *xlat_inst, void *mod_inst, char const *fmt);
69 
70 ssize_t radius_xlat(char *out, size_t outlen, REQUEST *request, char const *fmt, xlat_escape_t escape,
71  void *escape_ctx)
72  CC_HINT(nonnull (1 ,3 ,4));
73 
74 ssize_t radius_xlat_struct(char *out, size_t outlen, REQUEST *request, xlat_exp_t const *xlat,
75  xlat_escape_t escape, void *ctx)
76  CC_HINT(nonnull (1 ,3 ,4));
77 
78 ssize_t radius_axlat(char **out, REQUEST *request, char const *fmt, xlat_escape_t escape, void *escape_ctx)
79  CC_HINT(nonnull (1, 2, 3));
80 
81 ssize_t radius_axlat_struct(char **out, REQUEST *request, xlat_exp_t const *xlat, xlat_escape_t escape,
82  void *ctx)
83  CC_HINT(nonnull (1, 2, 3));
84 
85 ssize_t xlat_tokenize(TALLOC_CTX *ctx, char *fmt, xlat_exp_t **head, char const **error);
86 
87 size_t xlat_snprint(char *buffer, size_t bufsize, xlat_exp_t const *node);
88 
89 #define XLAT_DEFAULT_BUF_LEN 2048
90 
91 int xlat_register(void *mod_inst, char const *name,
92  xlat_func_t func, xlat_escape_t escape,
93  xlat_instantiate_t instantiate, size_t inst_size,
94  size_t buf_len);
95 
96 void xlat_unregister(void *mod_inst, char const *name, xlat_func_t func);
97 void xlat_unregister_module(void *instance);
99 ssize_t xlat_fmt_to_ref(uint8_t const **out, REQUEST *request, char const *fmt);
100 void xlat_free(void);
101 
102 #ifdef __cplusplus
103 }
104 #endif
105 #endif /* FR_XLAT_H */
ssize_t ssize_t ssize_t radius_axlat(char **out, REQUEST *request, char const *fmt, xlat_escape_t escape, void *escape_ctx) CC_HINT(nonnull(1
#define RCSIDH(h, id)
Definition: build.h:136
ssize_t ssize_t ssize_t ssize_t radius_axlat_struct(char **out, REQUEST *request, xlat_exp_t const *xlat, xlat_escape_t escape, void *ctx) CC_HINT(nonnull(1
int xlat_register(void *mod_inst, char const *name, xlat_func_t func, xlat_escape_t escape, xlat_instantiate_t instantiate, size_t inst_size, size_t buf_len)
Register an xlat function.
Definition: xlat.c:717
static char const * name
#define CC_HINT(_x)
Definition: build.h:71
ssize_t(* xlat_func_t)(char **out, size_t outlen, void const *mod_inst, void const *xlat_inst, REQUEST *request, char const *fmt)
xlat callback function
Definition: xlat.h:55
size_t(* xlat_escape_t)(REQUEST *request, char *out, size_t outlen, char const *in, void *arg)
Definition: xlat.h:36
int(* xlat_instantiate_t)(void *xlat_inst, void *mod_inst, char const *fmt)
Allocate new instance data for an xlat instance.
Definition: xlat.h:68
Definition: xlat.c:60
ssize_t ssize_t radius_xlat_struct(char *out, size_t outlen, REQUEST *request, xlat_exp_t const *xlat, xlat_escape_t escape, void *ctx) CC_HINT(nonnull(1
void xlat_unregister_module(void *instance)
Definition: xlat.c:877
ssize_t radius_xlat(char *out, size_t outlen, REQUEST *request, char const *fmt, xlat_escape_t escape, void *escape_ctx) CC_HINT(nonnull(1
void xlat_free(void)
De-register all xlat functions, used mainly for debugging.
Definition: xlat.c:1147
ssize_t xlat_fmt_to_ref(uint8_t const **out, REQUEST *request, char const *fmt)
Crappy temporary function to add attribute ref support to xlats.
Definition: xlat.c:1125
bool xlat_register_redundant(CONF_SECTION *cs)
Definition: xlat.c:1041
ssize_t ssize_t ssize_t ssize_t ssize_t xlat_tokenize(TALLOC_CTX *ctx, char *fmt, xlat_exp_t **head, char const **error)
Definition: xlat.c:1784
char const * fmt
The format string.
Definition: xlat.c:61
xlat_t const * xlat
The xlat expansion to expand format with.
Definition: xlat.c:71
void xlat_unregister(void *mod_inst, char const *name, xlat_func_t func)
size_t xlat_snprint(char *buffer, size_t bufsize, xlat_exp_t const *node)
Definition: xlat.c:1659