The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
proto.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 encoder/decoder support functions
19  *
20  * @file src/lib/util/proto.h
21  *
22  * @copyright 2015 The FreeRADIUS server project
23  */
24 RCSIDH(proto_h, "$Id: 5c8b72f7662da4006def57c31445e4e5b4664555 $")
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #include <freeradius-devel/build.h>
31 #include <freeradius-devel/missing.h>
32 #include <freeradius-devel/util/dict.h>
33 
34 #define CHECK_FREESPACE(_have, _need) \
35 do { \
36  if (unlikely((size_t)(_have) < (size_t)(_need))) return -((size_t)(_need) - (size_t)(_have)); \
37 } while (0);
38 
39 #ifndef NDEBUG
40 # define FR_PROTO_TRACE(_fmt, ...) if (fr_debug_lvl >= L_DBG_LVL_4) fr_proto_print(__FILE__, __LINE__, _fmt, ## __VA_ARGS__)
41 # define FR_PROTO_HEX_DUMP(_data, _data_len, _fmt, ...) if (fr_debug_lvl >= L_DBG_LVL_4) fr_proto_print_hex_data(__FILE__, __LINE__, _data, _data_len, _fmt, ## __VA_ARGS__)
42 # define FR_PROTO_HEX_MARKER(_data, _data_len, _slen, _fmt, ...) if (fr_debug_lvl >= L_DBG_LVL_4) fr_proto_print_hex_marker(__FILE__, __LINE__, _data, _data_len, _slen, _fmt, ## __VA_ARGS__)
43 # define FR_PROTO_STACK_PRINT(_stack, _depth) if (fr_debug_lvl >= L_DBG_LVL_4) fr_proto_da_stack_print(__FILE__, __LINE__, __FUNCTION__, _stack, _depth)
44 #else
45 # define FR_PROTO_TRACE(_fmt, ...)
46 # define FR_PROTO_HEX_DUMP(_data, _data_len, _fmt, ...)
47 # define FR_PROTO_HEX_MARKER(_data, _data_len, _slen, _fmt, ...)
48 # define FR_PROTO_STACK_PRINT(_x, _y)
49 #endif
50 
51 /** Structure for holding the stack of dictionary attributes being encoded
52  *
53  */
54 typedef struct {
55  uint8_t depth; //!< Deepest attribute in the stack.
56  fr_dict_attr_t const *da[FR_DICT_MAX_TLV_STACK + 1]; //!< The stack.
58 
59 void fr_proto_print(char const *file, int line, char const *fmt, ...) CC_HINT(format (printf, 3, 4));
60 
61 void fr_proto_print_hex_data(char const *file, int line, uint8_t const *data, size_t data_len, char const *fmt, ...);
62 
63 void fr_proto_print_hex_marker(char const *file, int line, uint8_t const *data, size_t data_len, ssize_t slen, char const *fmt, ...);
64 
65 void *fr_proto_next_encodable(fr_dlist_head_t *list, void *current, void *uctx);
66 
67 void fr_proto_da_stack_print(char const *file, int line, char const *func, fr_da_stack_t *da_stack, unsigned int depth);
68 
70 
72 
73 #ifdef __cplusplus
74 }
75 #endif
int const char * file
Definition: acutest.h:702
static int const char * fmt
Definition: acutest.h:573
int const char int line
Definition: acutest.h:702
#define RCSIDH(h, id)
Definition: build.h:445
#define FR_DICT_MAX_TLV_STACK
Maximum TLV stack size.
Definition: dict.h:384
Head of a doubly linked list.
Definition: dlist.h:51
static char * stack[MAX_STACK]
Definition: radmin.c:158
long int ssize_t
Definition: merged_model.c:24
unsigned char uint8_t
Definition: merged_model.c:30
static uint8_t depth(fr_minmax_heap_index_t i)
Definition: minmax_heap.c:83
static rc_request_t * current
Definition: radclient-ng.c:97
static fr_slen_t parent
Definition: pair.h:844
void fr_proto_da_stack_build(fr_da_stack_t *stack, fr_dict_attr_t const *da)
Build a complete DA stack from the da back to the root.
Definition: proto.c:118
void fr_proto_print(char const *file, int line, char const *fmt,...))
Definition: proto.c:27
void fr_proto_da_stack_print(char const *file, int line, char const *func, fr_da_stack_t *da_stack, unsigned int depth)
Definition: proto.c:73
void * fr_proto_next_encodable(fr_dlist_head_t *list, void *current, void *uctx)
Implements the default iterator to encode pairs belonging to a specific dictionary that are not inter...
Definition: proto.c:100
uint8_t depth
Deepest attribute in the stack.
Definition: proto.h:55
void fr_proto_print_hex_data(char const *file, int line, uint8_t const *data, size_t data_len, char const *fmt,...)
Definition: proto.c:42
void fr_proto_da_stack_build_partial(fr_da_stack_t *stack, fr_dict_attr_t const *parent, fr_dict_attr_t const *da)
Complete the DA stack for a child attribute.
Definition: proto.c:159
void fr_proto_print_hex_marker(char const *file, int line, uint8_t const *data, size_t data_len, ssize_t slen, char const *fmt,...)
Definition: proto.c:57
Structure for holding the stack of dictionary attributes being encoded.
Definition: proto.h:54
static fr_slen_t data
Definition: value.h:1259
int format(printf, 5, 0))