The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
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.
 
bool fr_type_cast (fr_type_t dst, fr_type_t src)
 Return if we're allowed to cast the types.
 
fr_type_t fr_type_promote (fr_type_t a, fr_type_t b)
 Return the promoted type.
 
char const * fr_type_to_enum_str (fr_type_t t)
 Return the source-identifier name for a type (e.g.
 

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.
 
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.
 
static char const * fr_type_to_c_type []
 Table of all the direct mappings between types and C types.
 
static fr_table_num_indexed_t const fr_type_to_enum_str_table []
 Map each fr_type_t to the C identifier of its enum constant.
 
static size_t fr_type_to_enum_str_table_len = NUM_ELEMENTS(fr_type_to_enum_str_table)
 
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
 

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 236 of file types.c.

◆ ARRAY_END

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

Definition at line 238 of file types.c.

◆ ARRAY_MID

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

Definition at line 237 of file types.c.

◆ O [1/2]

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

Definition at line 256 of file types.c.

◆ O [2/2]

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

Definition at line 256 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 700 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 352 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 641 of file types.c.

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

◆ fr_type_to_enum_str()

char const * fr_type_to_enum_str ( fr_type_t  t)

Return the source-identifier name for a type (e.g.

"FR_TYPE_STRING").

Counterpart to fr_type_to_str() which returns the short config-file form ("string", "ipv4addr", ...). This is what tooling that wants to grep the v4 source tree by enum identifier should emit (radmod2json in particular).

Parameters
[in]ttype to look up.
Returns
the enum-identifier name, or "FR_TYPE_NULL" if t is out of range.

Definition at line 142 of file types.c.

+ Here is the caller graph for this function:

Variable Documentation

◆ fr_type_fixed_size

Definition at line 247 of file types.c.

◆ fr_type_integer

Definition at line 241 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 240 of file types.c.

◆ fr_type_ip

Definition at line 245 of file types.c.

◆ fr_type_leaf

Definition at line 253 of file types.c.

◆ fr_type_non_leaf

Definition at line 254 of file types.c.

◆ fr_type_numeric

Definition at line 242 of file types.c.

◆ fr_type_quoted

Definition at line 249 of file types.c.

◆ fr_type_signed

Definition at line 243 of file types.c.

◆ fr_type_structural

Definition at line 252 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 251 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 87 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 195 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 151 of file types.c.

◆ fr_type_to_enum_str_table

fr_table_num_indexed_t const fr_type_to_enum_str_table[]
static

Map each fr_type_t to the C identifier of its enum constant.

The complement of fr_type_table - that one maps to the short "string", "ipv4addr", "uint32" names used in dictionaries and conf files; this maps to the source-identical FR_TYPE_STRING / FR_TYPE_IPV4_ADDR / FR_TYPE_UINT32 forms, for tooling that wants to grep the v4 source tree by enum name (radmod2json, etc.).

Stored as fr_table_num_indexed_t so fr_table_str_by_value() can do the value->name look-up through v4's standard table machinery; the table is indexed directly by fr_type_t value (gaps return the default).

Definition at line 102 of file types.c.

◆ fr_type_to_enum_str_table_len

size_t fr_type_to_enum_str_table_len = NUM_ELEMENTS(fr_type_to_enum_str_table)
static

Definition at line 140 of file types.c.

◆ fr_type_variable_size

Definition at line 248 of file types.c.

◆ type_cast_table

const bool type_cast_table[FR_TYPE_MAX][FR_TYPE_MAX]
static

Definition at line 263 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:256

Definition at line 339 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 417 of file types.c.