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 /** Failure reasons */
23 typedef enum {
41 
42 /** Allocate an encoder/decoder ctx
43  *
44  * @param[out] out Where the decoder context should be written.
45  * @param[in] ctx to allocate the test point context in.
46  * @return proto or pair encoder or decoder ctx.
47  */
48 typedef int (*fr_test_point_ctx_alloc_t)(void **out, TALLOC_CTX *ctx);
49 
50 /** A generic interface for decoding packets to fr_pair_ts
51  *
52  * A decoding function should decode a single top level packet from wire format.
53  *
54  * @param[in] ctx to allocate new pairs in.
55  * @param[in] list where new VPs will be added
56  * @param[in] data to decode.
57  * @param[in] data_len The length of the incoming data.
58  * @param[in] decode_ctx Any decode specific data such as secrets or configurable.
59  * @return
60  * - <= 0 on error. May be the offset (as a negative value) where the error occurred.
61  * - > 0 on success. How many bytes were decoded.
62  */
63 typedef ssize_t (*fr_tp_proto_decode_t)(TALLOC_CTX *ctx, fr_pair_list_t *list,
64  uint8_t const *data, size_t data_len, void *decode_ctx);
65 
66 /** A generic interface for encoding fr_pair_ts to packets
67  *
68  * An encoding function should encode multiple VPs to a wire format packet
69  *
70  * @param[in] ctx to allocate any data in
71  * @param[in] vps vps to encode
72  * @param[in] data buffer where data can be written
73  * @param[in] data_len The length of the buffer, i.e. maximum packet length
74  * @param[in] encode_ctx Any enccode specific data such as secrets or configurable.
75  * @return
76  * - <= 0 on error. May be the offset (as a negative value) where the error occurred.
77  * - > 0 on success. How many bytes were encoded
78  */
79 typedef ssize_t (*fr_tp_proto_encode_t)(TALLOC_CTX *ctx, fr_pair_list_t *vps,
80  uint8_t *data, size_t data_len, void *encode_ctx);
81 
82 /** Entry point for protocol decoders
83  *
84  */
85 typedef struct {
86  fr_test_point_ctx_alloc_t test_ctx; //!< Allocate a test ctx for the encoder.
87  fr_tp_proto_decode_t func; //!< Decoder for proto layer.
89 
90 /** Entry point for protocol encoders
91  *
92  */
93 typedef struct {
94  fr_test_point_ctx_alloc_t test_ctx; //!< Allocate a test ctx for the encoder.
95  fr_tp_proto_encode_t func; //!< Encoder for proto layer.
96  fr_dcursor_eval_t eval; //!< Evaluation function to filter
97  ///< attributes to encode.
99 
100 /** Entry point for pair decoders
101  *
102  */
103 typedef struct {
104  fr_test_point_ctx_alloc_t test_ctx; //!< Allocate a test ctx for the encoder.
105  fr_pair_decode_t func; //!< Decoder for pairs.
107 
108 /** Entry point for pair encoders
109  *
110  */
111 typedef struct {
112  fr_test_point_ctx_alloc_t test_ctx; //!< Allocate a test ctx for the encoder.
113  fr_pair_encode_t func; //!< Encoder for pairs.
114  fr_dcursor_iter_t next_encodable; //!< Iterator to use to select attributes
115  ///< to encode.
116  fr_dcursor_eval_t eval; //!< Evaluation function to filter
117  ///< 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:112
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:129
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:104
fr_tp_proto_decode_t func
Decoder for proto layer.
Definition: test_point.h:87
int(* fr_test_point_ctx_alloc_t)(void **out, TALLOC_CTX *ctx)
Allocate an encoder/decoder ctx.
Definition: test_point.h:48
fr_dcursor_eval_t eval
Evaluation function to filter attributes to encode.
Definition: test_point.h:96
fr_dcursor_eval_t eval
Evaluation function to filter attributes to encode.
Definition: test_point.h:116
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:79
fr_test_point_ctx_alloc_t test_ctx
Allocate a test ctx for the encoder.
Definition: test_point.h:112
fr_dcursor_iter_t next_encodable
Iterator to use to select attributes to encode.
Definition: test_point.h:114
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:63
fr_tp_proto_encode_t func
Encoder for proto layer.
Definition: test_point.h:95
fr_test_point_ctx_alloc_t test_ctx
Allocate a test ctx for the encoder.
Definition: test_point.h:94
fr_pair_decode_t func
Decoder for pairs.
Definition: test_point.h:105
fr_pair_encode_t func
Encoder for pairs.
Definition: test_point.h:113
decode_fail_t
Failure reasons.
Definition: test_point.h:23
@ DECODE_FAIL_UNKNOWN
Definition: test_point.h:38
@ DECODE_FAIL_INVALID_ATTRIBUTE
Definition: test_point.h:30
@ DECODE_FAIL_ATTRIBUTE_UNDERFLOW
Definition: test_point.h:34
@ DECODE_FAIL_MIN_LENGTH_FIELD
Definition: test_point.h:26
@ DECODE_FAIL_HEADER_OVERFLOW
Definition: test_point.h:28
@ DECODE_FAIL_ATTRIBUTE_TOO_SHORT
Definition: test_point.h:31
@ DECODE_FAIL_MA_INVALID
Definition: test_point.h:37
@ DECODE_FAIL_ATTRIBUTE_OVERFLOW
Definition: test_point.h:32
@ DECODE_FAIL_TOO_MANY_ATTRIBUTES
Definition: test_point.h:35
@ DECODE_FAIL_NONE
Definition: test_point.h:24
@ DECODE_FAIL_MIN_LENGTH_PACKET
Definition: test_point.h:25
@ DECODE_FAIL_MIN_LENGTH_MISMATCH
Definition: test_point.h:27
@ DECODE_FAIL_MA_INVALID_LENGTH
Definition: test_point.h:33
@ DECODE_FAIL_MAX
Definition: test_point.h:39
@ DECODE_FAIL_MA_MISSING
Definition: test_point.h:36
@ DECODE_FAIL_UNKNOWN_PACKET_CODE
Definition: test_point.h:29
fr_test_point_ctx_alloc_t test_ctx
Allocate a test ctx for the encoder.
Definition: test_point.h:86
Entry point for pair decoders.
Definition: test_point.h:103
Entry point for pair encoders.
Definition: test_point.h:111
Entry point for protocol decoders.
Definition: test_point.h:85
Entry point for protocol encoders.
Definition: test_point.h:93
AVP manipulation and search API.
Protocol encoder/decoder support functions.
static fr_slen_t data
Definition: value.h:1265
static size_t char ** out
Definition: value.h:997