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>
Go to the source code of this file.
|
#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) |
|
|
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) |
|
Functions to convert strings to integers and vice versa.
- Copyright
- 2019 The FreeRADIUS server project
-
2019 Arran Cudbard-Bell (a.cud.nosp@m.bard.nosp@m.b@fre.nosp@m.erad.nosp@m.ius.o.nosp@m.rg)
Definition in file table.c.
◆ ELEM_LEN
◆ ELEM_STR
◆ TABLE_IDX
#define TABLE_IDX |
( |
|
_table, |
|
|
|
_idx, |
|
|
|
_element_size |
|
) |
| (((uint8_t const *)(_table)) + ((_idx) * (_element_size))) |
◆ 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; \
}
Create type specific string to value functions.
- Parameters
-
[in] | _func | used for searching. |
[in] | _our_table_type | that we'll be searching in. |
[in] | _our_name | The function that we'll be creating. |
[in] | _our_def_type | The type of the default value. |
[in] | _our_return_type | What 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; \
}
Create type specific string to value functions with an input string length argument.
- Parameters
-
[in] | _func | used for searching. |
[in] | _our_table_type | that we'll be searching in. |
[in] | _our_name | The function that we'll be creating. |
[in] | _our_def_type | The type of the default value. |
[in] | _our_return_type | What 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; \
}
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) \
{ \
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 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.
◆ _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] | table | to search in. |
[in] | table_len | Number of elements in the table. |
[in] | str_val | to compare against the ptr field. |
[in] | def | default value. |
Definition at line 42 of file table.c.
◆ 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] | table | to search in. |
[in] | table_len | The number of elements in the table. |
[in] | element_size | Size of elements in the table. |
[in] | name | to resolve to a value. |
- Returns
- value of matching entry.
- NULL if no matching entries.
Definition at line 145 of file table.c.
◆ TABLE_TYPE_STR_FUNC() [1/2]
◆ TABLE_TYPE_STR_FUNC() [2/2]
◆ TABLE_TYPE_STR_LEN_FUNC() [1/2]
◆ TABLE_TYPE_STR_LEN_FUNC() [2/2]
◆ TABLE_TYPE_STR_MATCH_LEN_FUNC()