The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Lookup table functions. More...
#include <ctype.h>
#include <string.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
Go to the source code of this file.
Data Structures | |
struct | fr_table_elem_name_t |
struct | fr_table_num_indexed_bit_pos_t |
An element in a table indexed by bit position. More... | |
struct | fr_table_num_indexed_t |
An element in a table indexed by numeric value. More... | |
struct | fr_table_num_ordered_t |
An element in an arbitrarily ordered array of name to num mappings. More... | |
struct | fr_table_num_sorted_t |
An element in a lexicographically sorted array of name to num mappings. More... | |
struct | fr_table_ptr_ordered_t |
An element in an arbitrarily ordered array of name to ptr mappings. More... | |
struct | fr_table_ptr_sorted_t |
An element in a lexicographically sorted array of name to ptr mappings. More... | |
Macros | |
#define | ELEM_LEN(_offset) (*((fr_table_elem_name_t const *)(_offset))).len |
#define | ELEM_STR(_offset) (*((fr_table_elem_name_t const *)(_offset))).str |
#define | fr_table_max_needle_len(_table) |
#define | fr_table_str_by_str_value(_table, _str_value, _def) |
Brute force search a sorted or ordered ptr table, assuming the pointers are strings. More... | |
#define | fr_table_str_by_value(_table, _number, _def) |
Convert an integer to a string. More... | |
#define | fr_table_value_by_longest_prefix(_match_len, _table, _name, _name_len, _def) |
Find the longest string match using a sorted or ordered table. More... | |
#define | fr_table_value_by_str(_table, _name, _def) |
Convert a string to a value using a sorted or ordered table. More... | |
#define | fr_table_value_by_substr(_table, _name, _name_len, _def) |
Convert a partial string to a value using an ordered or sorted table. More... | |
#define | NAME_NUMBER_NOT_FOUND INT32_MIN |
Macro to use as dflt. More... | |
#define | TABLE_IDX(_table, _idx, _element_size) (((uint8_t const *)(_table)) + ((_idx) * (_element_size))) |
#define | TABLE_TYPE_NAME_FUNC(_func, _our_table_type, _our_name, _our_def_type, _our_return_type) |
Create a type-specific name-to-value function. More... | |
#define | TABLE_TYPE_NAME_FUNC_RPTR(_func, _our_table_type, _our_name, _our_def_type, _our_out_type) |
Create a type-specific name-to-value function. More... | |
#define | TABLE_TYPE_NAME_LEN_FUNC(_func, _our_table_type, _our_name, _our_def_type, _our_return_type) |
Create a type-specific name-to-value function that can perform substring matching with a 'name_len' argument. More... | |
#define | TABLE_TYPE_NAME_LEN_FUNC_RPTR(_func, _our_table_type, _our_name, _our_def_type, _our_out_type) |
Create a type-specific name-to-value function that can perform substring matching with a 'name_len' argument. More... | |
#define | TABLE_TYPE_NAME_MATCH_LEN_FUNC(_func, _our_table_type, _our_name, _our_def_type, _our_return_type) |
Create a type-specific name-to-value function that can perform substring matching with a 'name_len' argument, and passes back the length of the matched string. More... | |
#define | TABLE_TYPE_NAME_MATCH_LEN_FUNC_RPTR(_func, _our_table_type, _our_name, _our_def_type, _our_out_type) |
Create a type-specific name-to-value function that can perform substring matching with a 'name_len' argument, and passes back the length of the matched string. More... | |
#define | TABLE_TYPE_NEEDLE_LEN_FUNC(_our_table_type, _our_name) |
#define | TABLE_TYPE_VALUE_FUNC(_our_table_type, _our_name, _our_value_type) |
Create a type-specific value-to-name function. More... | |
#define | TABLE_TYPE_VALUE_INDEX_BIT_FIELD_FUNC(_our_table_type, _our_name, _our_value_type) |
Create a type-specific value-to-name function, which uses the highest bit set in the value as an index into the table. More... | |
#define | TABLE_TYPE_VALUE_INDEX_FUNC(_our_table_type, _our_name, _our_value_type) |
Create a type-specific value-to-name function, which uses the value as an index into the table. More... | |
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... | |
char const * | fr_table_indexed_str_by_bit_field (fr_table_num_indexed_bit_pos_t const *table, size_t table_len, uint64_t number, char const *def) |
char const * | fr_table_indexed_str_by_num (fr_table_num_indexed_t const *table, size_t table_len, unsigned int number, char const *def) |
int | fr_table_ordered_num_by_longest_prefix (size_t *match_len, fr_table_num_ordered_t const *table, size_t table_len, char const *name, ssize_t name_len, int def) |
int | fr_table_ordered_num_by_str (fr_table_num_ordered_t const *table, size_t table_len, char const *name, int def) |
int | fr_table_ordered_num_by_substr (fr_table_num_ordered_t const *table, size_t table_len, char const *name, ssize_t name_len, int def) |
void * | fr_table_ordered_ptr_by_longest_prefix (size_t *match_len, fr_table_ptr_ordered_t const *table, size_t table_len, char const *name, ssize_t name_len, void const *def) |
void * | fr_table_ordered_ptr_by_str (fr_table_ptr_ordered_t const *table, size_t table_len, char const *name, void const *def) |
void * | fr_table_ordered_ptr_by_substr (fr_table_ptr_ordered_t const *table, size_t table_len, char const *name, ssize_t name_len, void const *def) |
char const * | fr_table_ordered_str_by_num (fr_table_num_ordered_t const *table, size_t table_len, int number, char const *def) |
char const * | fr_table_ordered_str_by_ptr (fr_table_ptr_ordered_t const *table, size_t table_len, void const *ptr, char const *def) |
int | fr_table_sorted_num_by_longest_prefix (size_t *match_len, fr_table_num_sorted_t const *table, size_t table_len, char const *name, ssize_t name_len, int def) |
int | fr_table_sorted_num_by_str (fr_table_num_sorted_t const *table, size_t table_len, char const *name, int def) |
int | fr_table_sorted_num_by_substr (fr_table_num_sorted_t const *table, size_t table_len, char const *name, ssize_t name_len, int def) |
void * | fr_table_sorted_ptr_by_longest_prefix (size_t *match_len, fr_table_ptr_sorted_t const *table, size_t table_len, char const *name, ssize_t name_len, void const *def) |
void * | fr_table_sorted_ptr_by_str (fr_table_ptr_sorted_t const *table, size_t table_len, char const *name, void const *def) |
void * | fr_table_sorted_ptr_by_substr (fr_table_ptr_sorted_t const *table, size_t table_len, char const *name, ssize_t name_len, void const *def) |
char const * | fr_table_sorted_str_by_num (fr_table_num_sorted_t const *table, size_t table_len, int number, char const *def) |
char const * | fr_table_sorted_str_by_ptr (fr_table_ptr_sorted_t const *table, size_t table_len, void const *ptr, char const *def) |
static void const * | table_ordered_value_by_longest_prefix (size_t *match_len, void const *table, size_t table_len, size_t element_size, char const *name, ssize_t name_len) |
Find the longest string match using an arbitrarily ordered table. More... | |
static void const * | table_ordered_value_by_str (void const *table, size_t table_len, size_t element_size, char const *name) |
Convert a string to a value using an arbitrarily ordered table. More... | |
static void const * | table_ordered_value_by_substr (void const *table, size_t table_len, size_t element_size, char const *name, ssize_t name_len) |
Convert a string matching part of name to an integer using an arbitrarily ordered table. More... | |
static void const * | table_sorted_value_by_longest_prefix (size_t *match_len, void const *table, size_t table_len, size_t element_size, char const *name, ssize_t name_len) |
Find the longest string match using a lexicographically sorted table. 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... | |
static void const * | table_sorted_value_by_substr (void const *table, size_t table_len, size_t element_size, char const *name, ssize_t name_len) |
Convert a string matching part of name to an integer using a lexicographically sorted table. More... | |
Lookup table functions.
Definition in file table.h.
struct fr_table_elem_name_t |
struct fr_table_num_indexed_bit_pos_t |
An element in a table indexed by bit position.
i.e. if only the first bit is set in a bitfield, the entry at index 0 will be returned.
Data Fields | ||
---|---|---|
fr_table_elem_name_t | name | |
uint64_t | value |
struct fr_table_num_indexed_t |
An element in a table indexed by numeric value.
i.e. if the value is 0, we return the string mapped to the first element of the table.
Data Fields | ||
---|---|---|
fr_table_elem_name_t | name | |
unsigned int | value |
struct fr_table_num_ordered_t |
An element in an arbitrarily ordered array of name to num mappings.
Data Fields | ||
---|---|---|
fr_table_elem_name_t | name | |
int | value |
struct fr_table_num_sorted_t |
An element in a lexicographically sorted array of name to num mappings.
Data Fields | ||
---|---|---|
fr_table_elem_name_t | name | |
int | value |
struct fr_table_ptr_ordered_t |
An element in an arbitrarily ordered array of name to ptr mappings.
Data Fields | ||
---|---|---|
fr_table_elem_name_t | name | |
void const * | value |
struct fr_table_ptr_sorted_t |
An element in a lexicographically sorted array of name to ptr mappings.
Data Fields | ||
---|---|---|
fr_table_elem_name_t | name | |
void const * | value |
#define ELEM_LEN | ( | _offset | ) | (*((fr_table_elem_name_t const *)(_offset))).len |
#define ELEM_STR | ( | _offset | ) | (*((fr_table_elem_name_t const *)(_offset))).str |
#define fr_table_max_needle_len | ( | _table | ) |
#define fr_table_str_by_str_value | ( | _table, | |
_str_value, | |||
_def | |||
) |
Brute force search a sorted or ordered ptr table, assuming the pointers are strings.
[in] | _table | to search in. |
[in] | _str_value | to compare against the ptr field. |
[in] | _def | default value. |
#define fr_table_str_by_value | ( | _table, | |
_number, | |||
_def | |||
) |
Convert an integer to a string.
[in] | _table | to search in. |
[in] | _number | to resolve to a string. |
[in] | _def | Default string to return if there's no match. |
#define fr_table_value_by_longest_prefix | ( | _match_len, | |
_table, | |||
_name, | |||
_name_len, | |||
_def | |||
) |
Find the longest string match using a sorted or ordered table.
[out] | _match_len | How much of the input string matched. |
[in] | _table | to search in. |
[in] | _name | to resolve to a number. |
[in] | _name_len | The amount of name to match. |
[in] | _def | Default value if no entry matched. |
#define fr_table_value_by_str | ( | _table, | |
_name, | |||
_def | |||
) |
Convert a string to a value using a sorted or ordered table.
[in] | _table | to search in. |
[in] | _name | to resolve to a number. |
[in] | _def | Default value if no entry matched. |
#define fr_table_value_by_substr | ( | _table, | |
_name, | |||
_name_len, | |||
_def | |||
) |
Convert a partial string to a value using an ordered or sorted table.
[in] | _table | to search in. |
[in] | _name | to resolve to a number. |
[in] | _name_len | The amount of name to match. If < 0, the length of the name in the table element will be used as the maximum match length. |
[in] | _def | Default value if no entry matched. |
#define NAME_NUMBER_NOT_FOUND INT32_MIN |
#define TABLE_TYPE_NAME_FUNC | ( | _func, | |
_our_table_type, | |||
_our_name, | |||
_our_def_type, | |||
_our_return_type | |||
) |
Create a type-specific name-to-value function.
[in] | _func | Used for resolving the name portion of an array element to a value. Should be one of the following:
|
[in] | _our_table_type | C type of the table elements. |
[in] | _our_name | name of the search function to define. |
[in] | _our_def_type | C type of the default value. |
[in] | _our_return_type | C type of the return value, i.e. the value part of the element. |
#define TABLE_TYPE_NAME_FUNC_RPTR | ( | _func, | |
_our_table_type, | |||
_our_name, | |||
_our_def_type, | |||
_our_out_type | |||
) |
Create a type-specific name-to-value function.
[in] | _func | Used for resolving the name portion of an array element to a value. Should be one of the following:
|
[in] | _our_table_type | C type of the table elements. |
[in] | _our_name | name of the search function to define. |
[in] | _our_def_type | C type of the default value. |
[in] | _our_out_type | C type of the return/output value, i.e. the value part of the element. |
#define TABLE_TYPE_NAME_LEN_FUNC | ( | _func, | |
_our_table_type, | |||
_our_name, | |||
_our_def_type, | |||
_our_return_type | |||
) |
Create a type-specific name-to-value function that can perform substring matching with a 'name_len' argument.
[in] | _func | Used for resolving the name portion of an array element to a value. Should be one of the following:
|
[in] | _our_table_type | C type of the table elements. Must contain two fields, an fr_table_elem_name_t called name and an arbitraryily typed field called value. A pointer to thi |
[in] | _our_name | name of the search function to define. |
[in] | _our_def_type | C type of the default value. |
[in] | _our_return_type | C type of the return value, i.e. the value part of the element. |
#define TABLE_TYPE_NAME_LEN_FUNC_RPTR | ( | _func, | |
_our_table_type, | |||
_our_name, | |||
_our_def_type, | |||
_our_out_type | |||
) |
Create a type-specific name-to-value function that can perform substring matching with a 'name_len' argument.
[in] | _func | Used for resolving the name portion of an array element to a value. Should be one of the following:
|
[in] | _our_table_type | C type of the table elements. Must contain two fields, an fr_table_elem_name_t called name and an arbitraryily typed field called value. A pointer to thi |
[in] | _our_name | name of the search function to define. |
[in] | _our_def_type | C type of the default value. |
[in] | _our_out_type | C type of the return/output value, i.e. the value part of the element. |
#define TABLE_TYPE_NAME_MATCH_LEN_FUNC | ( | _func, | |
_our_table_type, | |||
_our_name, | |||
_our_def_type, | |||
_our_return_type | |||
) |
Create a type-specific name-to-value function that can perform substring matching with a 'name_len' argument, and passes back the length of the matched string.
[in] | _func | Used for resolving the name portion of an array element to a value. Should be one of the following:
|
[in] | _our_table_type | C type of the table elements. |
[in] | _our_name | name of the search function to define. |
[in] | _our_def_type | C type of the default value. |
[in] | _our_return_type | C type of the return value, i.e. the value part of the element. |
#define TABLE_TYPE_NAME_MATCH_LEN_FUNC_RPTR | ( | _func, | |
_our_table_type, | |||
_our_name, | |||
_our_def_type, | |||
_our_out_type | |||
) |
Create a type-specific name-to-value function that can perform substring matching with a 'name_len' argument, and passes back the length of the matched string.
[in] | _func | Used for resolving the name portion of an array element to a value. Should be one of the following:
|
[in] | _our_table_type | C type of the table elements. |
[in] | _our_name | name of the search function to define. |
[in] | _our_def_type | C type of the default value. |
[in] | _our_out_type | C type of the return/output value, i.e. the value part of the element. |
#define TABLE_TYPE_NEEDLE_LEN_FUNC | ( | _our_table_type, | |
_our_name | |||
) |
#define TABLE_TYPE_VALUE_FUNC | ( | _our_table_type, | |
_our_name, | |||
_our_value_type | |||
) |
Create a type-specific value-to-name function.
[in] | _our_table_type | C type of the table elements. |
[in] | _our_name | name of the search function to define. |
[in] | _our_return_type | C type of the value field of the table element. |
#define TABLE_TYPE_VALUE_INDEX_BIT_FIELD_FUNC | ( | _our_table_type, | |
_our_name, | |||
_our_value_type | |||
) |
Create a type-specific value-to-name function, which uses the highest bit set in the value as an index into the table.
[in] | _our_table_type | C type of the table elements. |
[in] | _our_name | name of the search function to define. |
[in] | _our_return_type | C type of the value field of the table element. |
#define TABLE_TYPE_VALUE_INDEX_FUNC | ( | _our_table_type, | |
_our_name, | |||
_our_value_type | |||
) |
Create a type-specific value-to-name function, which uses the value as an index into the table.
[in] | _our_table_type | C type of the table elements. |
[in] | _our_name | name of the search function to define. |
[in] | _our_return_type | C type of the value field of the table element. |
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.
[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 36 of file table.c.
char const* fr_table_indexed_str_by_bit_field | ( | fr_table_num_indexed_bit_pos_t const * | table, |
size_t | table_len, | ||
uint64_t | number, | ||
char const * | def | ||
) |
char const* fr_table_indexed_str_by_num | ( | fr_table_num_indexed_t const * | table, |
size_t | table_len, | ||
unsigned int | number, | ||
char const * | def | ||
) |
int fr_table_ordered_num_by_longest_prefix | ( | size_t * | match_len, |
fr_table_num_ordered_t const * | table, | ||
size_t | table_len, | ||
char const * | name, | ||
ssize_t | name_len, | ||
int | def | ||
) |
int fr_table_ordered_num_by_str | ( | fr_table_num_ordered_t const * | table, |
size_t | table_len, | ||
char const * | name, | ||
int | def | ||
) |
int fr_table_ordered_num_by_substr | ( | fr_table_num_ordered_t const * | table, |
size_t | table_len, | ||
char const * | name, | ||
ssize_t | name_len, | ||
int | def | ||
) |
void* fr_table_ordered_ptr_by_longest_prefix | ( | size_t * | match_len, |
fr_table_ptr_ordered_t const * | table, | ||
size_t | table_len, | ||
char const * | name, | ||
ssize_t | name_len, | ||
void const * | def | ||
) |
void* fr_table_ordered_ptr_by_str | ( | fr_table_ptr_ordered_t const * | table, |
size_t | table_len, | ||
char const * | name, | ||
void const * | def | ||
) |
void* fr_table_ordered_ptr_by_substr | ( | fr_table_ptr_ordered_t const * | table, |
size_t | table_len, | ||
char const * | name, | ||
ssize_t | name_len, | ||
void const * | def | ||
) |
char const* fr_table_ordered_str_by_num | ( | fr_table_num_ordered_t const * | table, |
size_t | table_len, | ||
int | number, | ||
char const * | def | ||
) |
char const* fr_table_ordered_str_by_ptr | ( | fr_table_ptr_ordered_t const * | table, |
size_t | table_len, | ||
void const * | ptr, | ||
char const * | def | ||
) |
int fr_table_sorted_num_by_longest_prefix | ( | size_t * | match_len, |
fr_table_num_sorted_t const * | table, | ||
size_t | table_len, | ||
char const * | name, | ||
ssize_t | name_len, | ||
int | def | ||
) |
int fr_table_sorted_num_by_str | ( | fr_table_num_sorted_t const * | table, |
size_t | table_len, | ||
char const * | name, | ||
int | def | ||
) |
int fr_table_sorted_num_by_substr | ( | fr_table_num_sorted_t const * | table, |
size_t | table_len, | ||
char const * | name, | ||
ssize_t | name_len, | ||
int | def | ||
) |
void* fr_table_sorted_ptr_by_longest_prefix | ( | size_t * | match_len, |
fr_table_ptr_sorted_t const * | table, | ||
size_t | table_len, | ||
char const * | name, | ||
ssize_t | name_len, | ||
void const * | def | ||
) |
void* fr_table_sorted_ptr_by_str | ( | fr_table_ptr_sorted_t const * | table, |
size_t | table_len, | ||
char const * | name, | ||
void const * | def | ||
) |
void* fr_table_sorted_ptr_by_substr | ( | fr_table_ptr_sorted_t const * | table, |
size_t | table_len, | ||
char const * | name, | ||
ssize_t | name_len, | ||
void const * | def | ||
) |
char const* fr_table_sorted_str_by_num | ( | fr_table_num_sorted_t const * | table, |
size_t | table_len, | ||
int | number, | ||
char const * | def | ||
) |
char const* fr_table_sorted_str_by_ptr | ( | fr_table_ptr_sorted_t const * | table, |
size_t | table_len, | ||
void const * | ptr, | ||
char const * | def | ||
) |
|
static |
Find the longest string match using an arbitrarily ordered table.
i.e. given name of "food", and table of f, foo, of - foo would be returned.
[out] | match_len | How much of the input string matched. |
[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 locate. |
[in] | name_len | the maximum amount of name that should be matched. |
|
static |
Convert a string to a value using an arbitrarily ordered table.
[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 number. |
Definition at line 367 of file table.h.
|
static |
Convert a string matching part of name to an integer using an arbitrarily ordered table.
[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 locate. |
[in] | name_len | the maximum amount of name that should be matched. If < 0, the length of the name in the table offsetent will be used as the maximum match length. |
Definition at line 443 of file table.h.
|
static |
Find the longest string match using a lexicographically sorted table.
Performs a binary search in the specified table, returning the longest offsetent which is a prefix of name.
i.e. given name of "food", and table of f, foo, of - foo would be returned.
[out] | match_len | How much of the input string matched. |
[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 locate. |
[in] | name_len | the maximum amount of name that should be matched. |
Definition at line 492 of file table.h.
|
static |
Convert a string to a value using a lexicographically sorted table.
[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. |
Definition at line 328 of file table.h.
|
static |
Convert a string matching part of name to an integer using a lexicographically sorted table.
[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 locate. |
[in] | name_len | the maximum amount of name that should be matched. If < 0, the length of the name in the table offsetent will be used as the maximum match length. |
Definition at line 395 of file table.h.