The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
test_point.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 #include <freeradius-devel/util/dcursor.h>
18 #include <freeradius-devel/util/pair.h>
19 #include "proto.h"
20 #include "pair.h"
21 
22 /** Allocate an encoder/decoder ctx
23  *
24  * @param[out] out Where the decoder context should be written.
25  * @param[in] ctx to allocate the test point context in.
26  * @return proto or pair encoder or decoder ctx.
27  */
28 typedef int (*fr_test_point_ctx_alloc_t)(void **out, TALLOC_CTX *ctx);
29 
30 /** A generic interface for decoding packets to fr_pair_ts
31  *
32  * A decoding function should decode a single top level packet from wire format.
33  *
34  * @param[in] ctx to allocate new pairs in.
35  * @param[in] list where new VPs will be added
36  * @param[in] data to decode.
37  * @param[in] data_len The length of the incoming data.
38  * @param[in] decode_ctx Any decode specific data such as secrets or configurable.
39  * @return
40  * - <= 0 on error. May be the offset (as a negative value) where the error occurred.
41  * - > 0 on success. How many bytes were decoded.
42  */
43 typedef ssize_t (*fr_tp_proto_decode_t)(TALLOC_CTX *ctx, fr_pair_list_t *list,
44  uint8_t const *data, size_t data_len, void *decode_ctx);
45 
46 /** A generic interface for encoding fr_pair_ts to packets
47  *
48  * An encoding function should encode multiple VPs to a wire format packet
49  *
50  * @param[in] ctx to allocate any data in
51  * @param[in] vps vps to encode
52  * @param[in] data buffer where data can be written
53  * @param[in] data_len The length of the buffer, i.e. maximum packet length
54  * @param[in] encode_ctx Any enccode specific data such as secrets or configurable.
55  * @return
56  * - <= 0 on error. May be the offset (as a negative value) where the error occurred.
57  * - > 0 on success. How many bytes were encoded
58  */
59 typedef ssize_t (*fr_tp_proto_encode_t)(TALLOC_CTX *ctx, fr_pair_list_t *vps,
60  uint8_t *data, size_t data_len, void *encode_ctx);
61 
62 /** Entry point for protocol decoders
63  *
64  */
65 typedef struct {
66  fr_test_point_ctx_alloc_t test_ctx; //!< Allocate a test ctx for the encoder.
67  fr_tp_proto_decode_t func; //!< Decoder for proto layer.
69 
70 /** Entry point for protocol encoders
71  *
72  */
73 typedef struct {
74  fr_test_point_ctx_alloc_t test_ctx; //!< Allocate a test ctx for the encoder.
75  fr_tp_proto_encode_t func; //!< Encoder for proto layer.
76  fr_dcursor_eval_t eval; //!< Evaluation function to filter
77  ///< attributes to encode.
79 
80 /** Entry point for pair decoders
81  *
82  */
83 typedef struct {
84  fr_test_point_ctx_alloc_t test_ctx; //!< Allocate a test ctx for the encoder.
85  fr_pair_decode_t func; //!< Decoder for pairs.
87 
88 /** Entry point for pair encoders
89  *
90  */
91 typedef struct {
92  fr_test_point_ctx_alloc_t test_ctx; //!< Allocate a test ctx for the encoder.
93  fr_pair_encode_t func; //!< Encoder for pairs.
94  fr_dcursor_iter_t next_encodable; //!< Iterator to use to select attributes
95  ///< to encode.
96  fr_dcursor_eval_t eval; //!< Evaluation function to filter
97  ///< attributes to encode.
bool(* fr_dcursor_eval_t)(void const *item, void const *uctx)
Type of evaluation functions to pass to the fr_dcursor_filter_*() functions.
Definition: dcursor.h:91
void *(* fr_dcursor_iter_t)(fr_dlist_head_t *list, void *to_eval, void *uctx)
Callback for implementing custom iterators.
Definition: dcursor.h:51
ssize_t(* fr_pair_encode_t)(fr_dbuff_t *out, fr_dcursor_t *cursor, void *encode_ctx)
Generic interface for encoding one or more fr_pair_ts.
Definition: pair.h:113
ssize_t(* fr_pair_decode_t)(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)
A generic interface for decoding fr_pair_ts.
Definition: pair.h:130
long int ssize_t
Definition: merged_model.c:24
unsigned char uint8_t
Definition: merged_model.c:30
static fr_internal_encode_ctx_t encode_ctx
fr_test_point_ctx_alloc_t test_ctx
Allocate a test ctx for the encoder.
Definition: test_point.h:84
fr_tp_proto_decode_t func
Decoder for proto layer.
Definition: test_point.h:67
int(* fr_test_point_ctx_alloc_t)(void **out, TALLOC_CTX *ctx)
Allocate an encoder/decoder ctx.
Definition: test_point.h:28
fr_dcursor_eval_t eval
Evaluation function to filter attributes to encode.
Definition: test_point.h:76
fr_dcursor_eval_t eval
Evaluation function to filter attributes to encode.
Definition: test_point.h:96
ssize_t(* fr_tp_proto_encode_t)(TALLOC_CTX *ctx, fr_pair_list_t *vps, uint8_t *data, size_t data_len, void *encode_ctx)
A generic interface for encoding fr_pair_ts to packets.
Definition: test_point.h:59
fr_test_point_ctx_alloc_t test_ctx
Allocate a test ctx for the encoder.
Definition: test_point.h:92
fr_dcursor_iter_t next_encodable
Iterator to use to select attributes to encode.
Definition: test_point.h:94
ssize_t(* fr_tp_proto_decode_t)(TALLOC_CTX *ctx, fr_pair_list_t *list, uint8_t const *data, size_t data_len, void *decode_ctx)
A generic interface for decoding packets to fr_pair_ts.
Definition: test_point.h:43
fr_tp_proto_encode_t func
Encoder for proto layer.
Definition: test_point.h:75
fr_test_point_ctx_alloc_t test_ctx
Allocate a test ctx for the encoder.
Definition: test_point.h:74
fr_pair_decode_t func
Decoder for pairs.
Definition: test_point.h:85
fr_pair_encode_t func
Encoder for pairs.
Definition: test_point.h:93
fr_test_point_ctx_alloc_t test_ctx
Allocate a test ctx for the encoder.
Definition: test_point.h:66
Entry point for pair decoders.
Definition: test_point.h:83
Entry point for pair encoders.
Definition: test_point.h:91
Entry point for protocol decoders.
Definition: test_point.h:65
Entry point for protocol encoders.
Definition: test_point.h:73
AVP manipulation and search API.
Protocol encoder/decoder support functions.
static fr_slen_t data
Definition: value.h:1259
static size_t char ** out
Definition: value.h:984