The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Functions | Variables
types.c File Reference

Boxed value structures and functions to manipulate them. More...

#include <freeradius-devel/util/strerror.h>
#include <freeradius-devel/util/types.h>
#include <freeradius-devel/util/value.h>
+ Include dependency graph for types.c:

Go to the source code of this file.

Macros

#define ARRAY_BEG(_type)   { [_type] = true,
 
#define ARRAY_END(_type)   [_type] = true }
 
#define ARRAY_MID(_type)   [_type] = true,
 
#define O(_x)   [FR_TYPE_ ## _x] = true
 
#define O(_x)   [FR_TYPE_ ## _x] = FR_TYPE_ ## _x
 

Functions

void ** fr_type_array_alloc (TALLOC_CTX *ctx, fr_type_t type, size_t count)
 Allocate an array of a given type. More...
 
bool fr_type_cast (fr_type_t dst, fr_type_t src)
 Return if we're allowed to cast the types. More...
 
fr_type_t fr_type_promote (fr_type_t a, fr_type_t b)
 Return the promoted type. More...
 

Variables

bool const fr_type_fixed_size [FR_TYPE_MAX+1] = FR_TYPE_FIXED_SIZE_DEF(ARRAY_BEG, ARRAY_MID, ARRAY_END)
 
bool const fr_type_integer [FR_TYPE_MAX+1] = FR_TYPE_INTEGER_DEF(ARRAY_BEG, ARRAY_MID, ARRAY_END)
 
bool const fr_type_integer_except_bool [FR_TYPE_MAX+1] = FR_TYPE_INTEGER_EXCEPT_BOOL_DEF(ARRAY_BEG, ARRAY_MID, ARRAY_END)
 
bool const fr_type_ip [FR_TYPE_MAX+1] = FR_TYPE_IP_DEF(ARRAY_BEG, ARRAY_MID, ARRAY_END)
 
bool const fr_type_leaf [FR_TYPE_MAX+1] = FR_TYPE_LEAF_DEF(ARRAY_BEG, ARRAY_MID, ARRAY_END)
 
bool const fr_type_non_leaf [FR_TYPE_MAX+1] = FR_TYPE_NON_LEAF_DEF(ARRAY_BEG, ARRAY_MID, ARRAY_END)
 
bool const fr_type_numeric [FR_TYPE_MAX+1] = FR_TYPE_NUMERIC_DEF(ARRAY_BEG, ARRAY_MID, ARRAY_END)
 
bool const fr_type_quoted [FR_TYPE_MAX+1] = FR_TYPE_QUOTED_DEF(ARRAY_BEG, ARRAY_MID, ARRAY_END)
 
bool const fr_type_signed [FR_TYPE_MAX+1] = FR_TYPE_SIGNED_DEF(ARRAY_BEG, ARRAY_MID, ARRAY_END)
 
bool const fr_type_structural [FR_TYPE_MAX+1] = FR_TYPE_STRUCTURAL_DEF(ARRAY_BEG, ARRAY_MID, ARRAY_END)
 
bool const fr_type_structural_except_vsa [FR_TYPE_MAX+1] = FR_TYPE_STRUCTURAL_EXCEPT_VSA_DEF(ARRAY_BEG, ARRAY_MID, ARRAY_END)
 
fr_table_num_ordered_t const fr_type_table []
 Map data types to names representing those types. More...
 
size_t fr_type_table_len = NUM_ELEMENTS(fr_type_table)
 
static size_t const fr_type_to_c_size []
 Table of all the direct mappings between types and C type sizes. More...
 
static char const * fr_type_to_c_type []
 Table of all the direct mappings between types and C types. More...
 
bool const fr_type_variable_size [FR_TYPE_MAX+1] = FR_TYPE_VARIABLE_SIZE_DEF(ARRAY_BEG, ARRAY_MID, ARRAY_END)
 
static const bool type_cast_table [FR_TYPE_MAX][FR_TYPE_MAX]
 
static const bool type_is_number [FR_TYPE_MAX]
 
static fr_type_t type_promote_table [FR_TYPE_MAX][FR_TYPE_MAX]
 promote (a,b) -> a or b a/b are not octets / string a and b are both FR_TYPE_VALUE More...
 

Detailed Description

Boxed value structures and functions to manipulate them.

Definition in file types.c.

Macro Definition Documentation

◆ ARRAY_BEG

#define ARRAY_BEG (   _type)    { [_type] = true,

Definition at line 167 of file types.c.

◆ ARRAY_END

#define ARRAY_END (   _type)    [_type] = true }

Definition at line 169 of file types.c.

◆ ARRAY_MID

#define ARRAY_MID (   _type)    [_type] = true,

Definition at line 168 of file types.c.

◆ O [1/2]

#define O (   _x)    [FR_TYPE_ ## _x] = true

Definition at line 337 of file types.c.

◆ O [2/2]

#define O (   _x)    [FR_TYPE_ ## _x] = FR_TYPE_ ## _x

Definition at line 337 of file types.c.

Function Documentation

◆ fr_type_array_alloc()

void** fr_type_array_alloc ( TALLOC_CTX *  ctx,
fr_type_t  type,
size_t  count 
)

Allocate an array of a given type.

Parameters
[in]ctxto allocate array in.
[in]typearray to allocate.
[in]countThe number of elements to allocate.
Returns
  • NULL on error.
  • A new talloc array.

Definition at line 631 of file types.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_type_cast()

bool fr_type_cast ( fr_type_t  dst,
fr_type_t  src 
)

Return if we're allowed to cast the types.

Parameters
dstthe destination type we wish to cast to
srcthe source type we wish to cast to

Definition at line 283 of file types.c.

+ Here is the caller graph for this function:

◆ fr_type_promote()

fr_type_t fr_type_promote ( fr_type_t  a,
fr_type_t  b 
)

Return the promoted type.

We presume that the two types are compatible, as checked by calling fr_type_cast(). The main difference here is that the two types don't have any src / dst relationship. Instead, we just pick one which best suits any value-box comparisons

Note that this function can return a type which is not a or b.

Parameters
atype one
btype two
Returns
the promoted type

Definition at line 572 of file types.c.

+ Here is the call graph for this function:

Variable Documentation

◆ fr_type_fixed_size

Definition at line 178 of file types.c.

◆ fr_type_integer

Definition at line 172 of file types.c.

◆ fr_type_integer_except_bool

bool const fr_type_integer_except_bool[FR_TYPE_MAX+1] = FR_TYPE_INTEGER_EXCEPT_BOOL_DEF(ARRAY_BEG, ARRAY_MID, ARRAY_END)

Definition at line 171 of file types.c.

◆ fr_type_ip

Definition at line 176 of file types.c.

◆ fr_type_leaf

Definition at line 184 of file types.c.

◆ fr_type_non_leaf

Definition at line 185 of file types.c.

◆ fr_type_numeric

Definition at line 173 of file types.c.

◆ fr_type_quoted

Definition at line 180 of file types.c.

◆ fr_type_signed

Definition at line 174 of file types.c.

◆ fr_type_structural

Definition at line 183 of file types.c.

◆ fr_type_structural_except_vsa

bool const fr_type_structural_except_vsa[FR_TYPE_MAX+1] = FR_TYPE_STRUCTURAL_EXCEPT_VSA_DEF(ARRAY_BEG, ARRAY_MID, ARRAY_END)

Definition at line 182 of file types.c.

◆ fr_type_table

fr_table_num_ordered_t const fr_type_table[]

Map data types to names representing those types.

Definition at line 31 of file types.c.

◆ fr_type_table_len

size_t fr_type_table_len = NUM_ELEMENTS(fr_type_table)

Definition at line 84 of file types.c.

◆ fr_type_to_c_size

size_t const fr_type_to_c_size[]
static

Table of all the direct mappings between types and C type sizes.

Definition at line 130 of file types.c.

◆ fr_type_to_c_type

char const* fr_type_to_c_type[]
static

Table of all the direct mappings between types and C types.

Useful for setting talloc types correctly.

Definition at line 90 of file types.c.

◆ fr_type_variable_size

Definition at line 179 of file types.c.

◆ type_cast_table

const bool type_cast_table[FR_TYPE_MAX][FR_TYPE_MAX]
static

Definition at line 194 of file types.c.

◆ type_is_number

const bool type_is_number[FR_TYPE_MAX]
static
Initial value:
= {
O(BOOL), O(SIZE), O(FLOAT32), O(FLOAT64),
O(UINT8), O(UINT16), O(UINT32), O(UINT64),
O(INT8), O(INT16), O(INT32), O(INT64),
O(TIME_DELTA),
}
#define O(_x)
Definition: types.c:337

Definition at line 270 of file types.c.

◆ type_promote_table

fr_type_t type_promote_table[FR_TYPE_MAX][FR_TYPE_MAX]
static

promote (a,b) -> a or b a/b are not octets / string a and b are both FR_TYPE_VALUE

Note that this table can return a type which is not a or b.

Many lookups of table[a][b] will return b. Some will return a. Others will return a type which is compatible with both a and b.

Definition at line 348 of file types.c.