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

Functions to convert strings to integers and vice versa. More...

#include <freeradius-devel/util/table.h>
#include <freeradius-devel/util/misc.h>
#include <string.h>
+ Include dependency graph for table.c:

Go to the source code of this file.

Macros

#define ELEM_LEN(_offset)   (*((fr_table_elem_t const *)(_offset))).len
 
#define ELEM_STR(_offset)   (*((fr_table_elem_t const *)(_offset))).str
 
#define TABLE_IDX(_table, _idx, _element_size)   (((uint8_t const *)(_table)) + ((_idx) * (_element_size)))
 
#define TABLE_TYPE_STR_FUNC(_func, _our_table_type, _our_name, _our_def_type, _our_return_type)
 Create type specific string to value functions. More...
 
#define TABLE_TYPE_STR_LEN_FUNC(_func, _our_table_type, _our_name, _our_def_type, _our_return_type)
 Create type specific string to value functions with an input string length argument. More...
 
#define TABLE_TYPE_STR_MATCH_LEN_FUNC(_func, _our_table_type, _our_name, _our_def_type, _our_return_type)
 
#define TABLE_TYPE_VALUE_FUNC(_our_table_type, _our_name, _our_value_type)
 
#define TABLE_TYPE_VALUE_INDEX_BIT_FIELD_FUNC(_our_table_type, _our_name, _our_value_type)
 
#define TABLE_TYPE_VALUE_INDEX_FUNC(_our_table_type, _our_name, _our_value_type)
 

Functions

char const * _fr_table_ptr_by_str_value (fr_table_ptr_sorted_t const *table, size_t table_len, char const *str_val, char const *def)
 Brute force search a sorted or ordered ptr table, assuming the pointers are strings. More...
 
static void const * table_sorted_value_by_str (void const *table, size_t table_len, size_t element_size, char const *name)
 Convert a string to a value using a lexicographically sorted table. More...
 
 TABLE_TYPE_STR_FUNC (TABLE_TYPE_STR_FUNC(table_ordered_value_by_str, fr_table_num_ordered_t const *, fr_table_ordered_num_by_str, int, int)
 
 TABLE_TYPE_STR_FUNC (TABLE_TYPE_STR_FUNC(table_sorted_value_by_str, fr_table_num_sorted_t const *, fr_table_sorted_num_by_str, int, int)
 
 TABLE_TYPE_STR_LEN_FUNC (TABLE_TYPE_STR_LEN_FUNC(table_ordered_value_by_substr, fr_table_num_ordered_t const *, fr_table_ordered_num_by_substr, int, int)
 
 TABLE_TYPE_STR_LEN_FUNC (TABLE_TYPE_STR_LEN_FUNC(table_sorted_value_by_substr, fr_table_num_sorted_t const *, fr_table_sorted_num_by_substr, int, int)
 
 TABLE_TYPE_STR_MATCH_LEN_FUNC (TABLE_TYPE_STR_MATCH_LEN_FUNC(table_sorted_value_by_longest_prefix, fr_table_num_sorted_t const *, fr_table_sorted_num_by_longest_prefix, int, int)
 

Detailed Description

Functions to convert strings to integers and vice versa.

Definition in file table.c.

Macro Definition Documentation

◆ ELEM_LEN

#define ELEM_LEN (   _offset)    (*((fr_table_elem_t const *)(_offset))).len

Definition at line 33 of file table.c.

◆ ELEM_STR

#define ELEM_STR (   _offset)    (*((fr_table_elem_t const *)(_offset))).str

Definition at line 32 of file table.c.

◆ TABLE_IDX

#define TABLE_IDX (   _table,
  _idx,
  _element_size 
)    (((uint8_t const *)(_table)) + ((_idx) * (_element_size)))

Definition at line 31 of file table.c.

◆ TABLE_TYPE_STR_FUNC

#define TABLE_TYPE_STR_FUNC (   _func,
  _our_table_type,
  _our_name,
  _our_def_type,
  _our_return_type 
)
Value:
_our_return_type _our_name(_our_table_type table, size_t table_len, char const *name, _our_def_type def) \
{ \
_our_return_type ret; \
_our_table_type found; \
found = (_our_table_type)_func(table, table_len, sizeof(((_our_table_type)0)[0]), name); \
if (!found) { \
memcpy(&ret, &def, sizeof(ret)); \
return ret; \
} \
memcpy(&ret, &found->value, sizeof(ret)); \
return ret; \
}
static char const * name

Create type specific string to value functions.

Parameters
[in]_funcused for searching.
[in]_our_table_typethat we'll be searching in.
[in]_our_nameThe function that we'll be creating.
[in]_our_def_typeThe type of the default value.
[in]_our_return_typeWhat we return.

Definition at line 61 of file table.c.

◆ TABLE_TYPE_STR_LEN_FUNC

#define TABLE_TYPE_STR_LEN_FUNC (   _func,
  _our_table_type,
  _our_name,
  _our_def_type,
  _our_return_type 
)
Value:
_our_return_type _our_name(_our_table_type table, size_t table_len, char const *name, ssize_t name_len, _our_def_type def) \
{ \
_our_return_type ret; \
_our_table_type found; \
found = (_our_table_type)_func(table, table_len, sizeof(((_our_table_type)0)[0]), name, name_len); \
if (!found) { \
memcpy(&ret, &def, sizeof(ret)); \
return ret; \
} \
memcpy(&ret, &found->value, sizeof(ret)); \
return ret; \
}
long int ssize_t
Definition: merged_model.c:24

Create type specific string to value functions with an input string length argument.

Parameters
[in]_funcused for searching.
[in]_our_table_typethat we'll be searching in.
[in]_our_nameThe function that we'll be creating.
[in]_our_def_typeThe type of the default value.
[in]_our_return_typeWhat we return.

Definition at line 83 of file table.c.

◆ TABLE_TYPE_STR_MATCH_LEN_FUNC

#define TABLE_TYPE_STR_MATCH_LEN_FUNC (   _func,
  _our_table_type,
  _our_name,
  _our_def_type,
  _our_return_type 
)
Value:
_our_return_type _our_name(size_t *match_len, _our_table_type table, size_t table_len, char const *name, ssize_t name_len, _our_def_type def) \
{ \
_our_return_type ret; \
_our_table_type found; \
found = (_our_table_type)_func(match_len, table, table_len, sizeof(((_our_table_type)0)[0]), name, name_len); \
if (!found) { \
memcpy(&ret, &def, sizeof(ret)); \
return ret; \
} \
memcpy(&ret, &found->value, sizeof(ret)); \
return ret; \
}

Definition at line 97 of file table.c.

◆ TABLE_TYPE_VALUE_FUNC

#define TABLE_TYPE_VALUE_FUNC (   _our_table_type,
  _our_name,
  _our_value_type 
)
Value:
char const *_our_name(_our_table_type table, size_t table_len, _our_value_type value, char const *def) \
{ \
size_t i; \
for (i = 0; i < table_len; i++) if (table[i].value == value) return table[i].name.str; \
return def; \
}
Test enumeration values.
Definition: dict_test.h:92

Definition at line 112 of file table.c.

◆ TABLE_TYPE_VALUE_INDEX_BIT_FIELD_FUNC

#define TABLE_TYPE_VALUE_INDEX_BIT_FIELD_FUNC (   _our_table_type,
  _our_name,
  _our_value_type 
)
Value:
char const *_our_name(_our_table_type table, size_t table_len, _our_value_type value, char const *def) \
{ \
uint8_t idx = fr_high_bit_pos(value); \
if (idx >= table_len) return def; \
return table[idx].name.str; \
}
static uint8_t fr_high_bit_pos(uint64_t num)
Find the highest order high bit in an unsigned 64 bit integer.
Definition: math.h:36

Definition at line 120 of file table.c.

◆ TABLE_TYPE_VALUE_INDEX_FUNC

#define TABLE_TYPE_VALUE_INDEX_FUNC (   _our_table_type,
  _our_name,
  _our_value_type 
)
Value:
char const *_our_name(_our_table_type table, size_t table_len, _our_value_type value, char const *def) \
{ \
if (value >= table_len) return def; \
return table[value].name.str; \
}

Definition at line 128 of file table.c.

Function Documentation

◆ _fr_table_ptr_by_str_value()

char const* _fr_table_ptr_by_str_value ( fr_table_ptr_sorted_t const *  table,
size_t  table_len,
char const *  str_val,
char const *  def 
)

Brute force search a sorted or ordered ptr table, assuming the pointers are strings.

Parameters
[in]tableto search in.
[in]table_lenNumber of elements in the table.
[in]str_valto compare against the ptr field.
[in]defdefault value.

Definition at line 42 of file table.c.

+ Here is the call graph for this function:

◆ table_sorted_value_by_str()

static void const* table_sorted_value_by_str ( void const *  table,
size_t  table_len,
size_t  element_size,
char const *  name 
)
static

Convert a string to a value using a lexicographically sorted table.

Parameters
[in]tableto search in.
[in]table_lenThe number of elements in the table.
[in]element_sizeSize of elements in the table.
[in]nameto resolve to a value.
Returns
  • value of matching entry.
  • NULL if no matching entries.

Definition at line 145 of file table.c.

+ Here is the call graph for this function:

◆ TABLE_TYPE_STR_FUNC() [1/2]

TABLE_TYPE_STR_FUNC ( TABLE_TYPE_STR_FUNC(  table_ordered_value_by_str,
fr_table_num_ordered_t const *  ,
fr_table_ordered_num_by_str  ,
int  ,
int   
)

Definition at line 204 of file table.c.

+ Here is the call graph for this function:

◆ TABLE_TYPE_STR_FUNC() [2/2]

TABLE_TYPE_STR_FUNC ( TABLE_TYPE_STR_FUNC(  table_sorted_value_by_str,
fr_table_num_sorted_t const *  ,
fr_table_sorted_num_by_str  ,
int  ,
int   
)

Definition at line 174 of file table.c.

+ Here is the call graph for this function:

◆ TABLE_TYPE_STR_LEN_FUNC() [1/2]

TABLE_TYPE_STR_LEN_FUNC ( TABLE_TYPE_STR_LEN_FUNC(  table_ordered_value_by_substr,
fr_table_num_ordered_t const *  ,
fr_table_ordered_num_by_substr  ,
int  ,
int   
)

Definition at line 305 of file table.c.

+ Here is the call graph for this function:

◆ TABLE_TYPE_STR_LEN_FUNC() [2/2]

TABLE_TYPE_STR_LEN_FUNC ( TABLE_TYPE_STR_LEN_FUNC(  table_sorted_value_by_substr,
fr_table_num_sorted_t const *  ,
fr_table_sorted_num_by_substr  ,
int  ,
int   
)

Definition at line 257 of file table.c.

+ Here is the call graph for this function:

◆ TABLE_TYPE_STR_MATCH_LEN_FUNC()

TABLE_TYPE_STR_MATCH_LEN_FUNC ( TABLE_TYPE_STR_MATCH_LEN_FUNC(  table_sorted_value_by_longest_prefix,
fr_table_num_sorted_t const *  ,
fr_table_sorted_num_by_longest_prefix  ,
int  ,
int   
)

Definition at line 391 of file table.c.