The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
uri.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 /** Functions for dealing with URIs
19  *
20  * @file src/lib/util/uri.c
21  *
22  * @copyright 2021 The FreeRADIUS server project
23  */
24 RCSIDH(uri_h, "$Id: ec9fc03acb9a451983a99f3c9873e5dc70ad3671 $")
25 
26 #include <freeradius-devel/util/value.h>
27 #include <freeradius-devel/util/sbuff.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /** A function used to escape an argument passed to an xlat
34  *
35  * @param[in,out] vb to escape
36  * @param[in] uctx a "context" for the escaping
37  * @return
38  * - 0 on success.
39  * - -1 on failure.
40  */
41 typedef int (*fr_uri_escape_func_t)(fr_value_box_t *vb, void *uctx);
42 
43 /** Definition for a single part of a URI
44  *
45  */
46 typedef struct {
47  char const *name; //!< Name of this part of the URI
48  fr_sbuff_term_t const *terminals; //!< Characters that mark the end of this part.
49  uint8_t const part_adv[UINT8_MAX + 1]; //!< How many parts to advance for a specific terminal
50  size_t extra_skip; //!< How many additional characters to skip after
51  ///< the terminal
52  fr_value_box_safe_for_t safe_for; //!< What type of value is safe for this part
53  fr_uri_escape_func_t func; //!< Function to use to escape tainted values
55 
56 /** uctx to pass to fr_uri_escape
57  *
58  * @note Should not be passed to fr_uri_escape_list. That takes the uctx to pass to the fr_uri_escape_func_t directly.
59  */
60 typedef struct {
61  fr_uri_part_t const *uri_part; //!< Start of the uri parts array. Will be updated
62  ///< as boxes are escaped.
63  void *uctx; //!< to pass to fr_uri_escape_func_t.
65 
66 #define XLAT_URI_PART_TERMINATOR { .name = NULL, .terminals = NULL, .safe_for = 0, .func = NULL }
67 
68 int fr_uri_escape_list(fr_value_box_list_t *uri, fr_uri_part_t const *uri_parts, void *uctx);
69 
70 int fr_uri_escape(fr_value_box_t *uri_vb, void *uctx);
71 
72 int fr_uri_has_scheme(fr_value_box_list_t *uri, fr_table_num_sorted_t const *schemes, size_t schemes_len, int def);
73 
74 #ifdef __cplusplus
75 }
76 #endif
#define RCSIDH(h, id)
Definition: build.h:482
fr_dcursor_eval_t void const * uctx
Definition: dcursor.h:546
unsigned char uint8_t
Definition: merged_model.c:30
#define UINT8_MAX
Definition: merged_model.c:32
Set of terminal elements.
Definition: merged_model.c:161
An element in a lexicographically sorted array of name to num mappings.
Definition: table.h:49
fr_sbuff_term_t const * terminals
Characters that mark the end of this part.
Definition: uri.h:48
int(* fr_uri_escape_func_t)(fr_value_box_t *vb, void *uctx)
A function used to escape an argument passed to an xlat.
Definition: uri.h:41
size_t extra_skip
How many additional characters to skip after the terminal.
Definition: uri.h:50
fr_uri_part_t const * uri_part
Start of the uri parts array.
Definition: uri.h:61
fr_uri_escape_func_t func
Function to use to escape tainted values.
Definition: uri.h:53
int fr_uri_escape_list(fr_value_box_list_t *uri, fr_uri_part_t const *uri_parts, void *uctx)
Parse a list of value boxes representing a URI.
Definition: uri.c:141
fr_value_box_safe_for_t safe_for
What type of value is safe for this part.
Definition: uri.h:52
int fr_uri_escape(fr_value_box_t *uri_vb, void *uctx)
Escapes an individual value box that's part of a URI, advancing the pointer to uri_parts.
Definition: uri.c:45
char const * name
Name of this part of the URI.
Definition: uri.h:47
int fr_uri_has_scheme(fr_value_box_list_t *uri, fr_table_num_sorted_t const *schemes, size_t schemes_len, int def)
Searches for a matching scheme in the table of schemes, using a list of value boxes representing the ...
Definition: uri.c:168
void * uctx
to pass to fr_uri_escape_func_t.
Definition: uri.h:63
uctx to pass to fr_uri_escape
Definition: uri.h:60
Definition for a single part of a URI.
Definition: uri.h:46
uintptr_t fr_value_box_safe_for_t
Escaping that's been applied to a value box.
Definition: value.h:155