The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
decode.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 /** Protocol decoder support functions
19  *
20  * @file src/lib/util/decode.h
21  *
22  * @copyright 2022 Network RADIUS SAS (legal@networkradius.com)
23  */
24 RCSIDH(decode_h, "$Id: 702cdf5a800c628fcb4ae46a781a3e027b9cdaa4 $")
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #include <freeradius-devel/util/pair.h>
31 #include <freeradius-devel/util/dns.h>
32 
33 /** Decode a value from the network into an output #fr_pair_list_t
34  *
35  * @param[in] ctx context to alloc new attributes in.
36  * @param[out] out Where to write the decoded options.
37  * @param[in] parent of sub TLVs.
38  * @param[in] data to parse.
39  * @param[in] data_len of the data to parse
40  * @param[in] decode_ctx ctx for decode function.
41  * @return
42  * <= 0 on error
43  * bytes successfully decoded on success (<= data_len)
44  */
45 typedef ssize_t (*fr_pair_decode_value_t)(TALLOC_CTX *ctx, fr_pair_list_t *out,
46  fr_dict_attr_t const *parent,
47  uint8_t const *data, size_t const data_len, void *decode_ctx);
48 
49 typedef bool (*fr_pair_tlvs_verify_t)(uint8_t const *data, size_t const data_len);
50 
51 #define PROTO_DECODE_FUNC(_name) static ssize_t decode_ ## _name(TALLOC_CTX *ctx, fr_pair_list_t *out, \
52  fr_dict_attr_t const *parent, \
53  uint8_t const *data, size_t const data_len, void *decode_ctx)
54 
56  uint8_t const *data, size_t data_len, void *decode_ctx, fr_pair_decode_value_t decode_value) CC_HINT(nonnull(1,2,3,4,7));
57 
59  uint8_t const *data, size_t data_len) CC_HINT(nonnull);
60 
62  fr_dict_attr_t const *parent,
63  uint8_t const *data, size_t const data_len,
64  void *decode_ctx, fr_pair_decode_value_t decode_tlv, fr_pair_tlvs_verify_t verify_tlvs,
65  bool nested) CC_HINT(nonnull(1,2,3,4,7));
66 
68  fr_dict_attr_t const *parent, uint8_t const *start,
69  uint8_t const *data, size_t const data_len, fr_dns_labels_t *lb, bool exact);
70 
71 #ifdef __cplusplus
72 }
73 #endif
#define RCSIDH(h, id)
Definition: build.h:482
bool(* fr_pair_tlvs_verify_t)(uint8_t const *data, size_t const data_len)
Definition: decode.h:49
ssize_t fr_pair_array_from_network(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, void *decode_ctx, fr_pair_decode_value_t decode_value))
Decode an array of values from the network.
Definition: decode.c:41
ssize_t(* fr_pair_decode_value_t)(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t const data_len, void *decode_ctx)
Decode a value from the network into an output fr_pair_list_t.
Definition: decode.h:45
ssize_t fr_pair_tlvs_from_network(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t const data_len, void *decode_ctx, fr_pair_decode_value_t decode_tlv, fr_pair_tlvs_verify_t verify_tlvs, bool nested))
Decode a list of pairs from the network.
Definition: decode.c:148
ssize_t fr_pair_dns_labels_from_network(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *start, uint8_t const *data, size_t const data_len, fr_dns_labels_t *lb, bool exact)
Decode a DNS label or a list of DNS labels from the network.
Definition: decode.c:237
ssize_t fr_pair_raw_from_network(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len)
Create a "raw" pair from the network data.
Definition: decode.c:79
long int ssize_t
Definition: merged_model.c:24
unsigned char bool
Definition: merged_model.c:19
unsigned char uint8_t
Definition: merged_model.c:30
static bool verify_tlvs(uint8_t const *data, size_t data_len)
Definition: decode.c:41
#define decode_value
Definition: decode.c:410
static fr_slen_t parent
Definition: pair.h:851
static fr_slen_t data
Definition: value.h:1265
int nonnull(2, 5))
static size_t char ** out
Definition: value.h:997