The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
A generic buffer structure for string printing and parsing strings. More...
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <freeradius-devel/util/atexit.h>
#include <freeradius-devel/util/strerror.h>
#include <freeradius-devel/util/table.h>
#include <freeradius-devel/util/talloc.h>
Go to the source code of this file.
Data Structures | |
struct | fr_sbuff_ptr_s |
union | fr_sbuff_ptr_s.__unnamed138__ |
struct | fr_sbuff_s |
union | fr_sbuff_s.__unnamed140__ |
union | fr_sbuff_s.__unnamed142__ |
union | fr_sbuff_s.__unnamed144__ |
union | fr_sbuff_s.__unnamed146__ |
struct | fr_sbuff_term_elem_t |
Terminal element with pre-calculated lengths. More... | |
struct | fr_sbuff_term_t |
Set of terminal elements. More... | |
struct | fr_sbuff_uctx_file_t |
File sbuff extension structure. More... | |
struct | fr_sbuff_uctx_talloc_t |
Talloc sbuff extension structure. More... | |
struct | fr_sbuff_unescape_rules_t |
Set of parsing rules for *unescape_until functions. More... | |
Typedefs | |
typedef bool(* | fr_sbuff_eof_t) (fr_sbuff_t *sbuff) |
For a given extension function, returns whether it is at EOF. | |
typedef size_t(* | fr_sbuff_extend_t) (fr_sbuff_extend_status_t *status, fr_sbuff_t *sbuff, size_t req_extension) |
Extension callback. | |
typedef struct fr_sbuff_ptr_s | fr_sbuff_marker_t |
typedef struct fr_sbuff_s | fr_sbuff_t |
typedef ssize_t | fr_slen_t |
Represents number of bytes parsed or location of parse error. | |
Enumerations | |
enum | fr_sbuff_extend_status_t { FR_SBUFF_FLAG_EXTENDED = 0x01 , FR_SBUFF_FLAG_EXTEND_ERROR = 0x02 } |
Whether the buffer is currently extendable and whether it was extended. More... | |
A generic buffer structure for string printing and parsing strings.
Because doing manual length checks is error prone and a waste of everyones time.
Definition in file sbuff.h.
struct fr_sbuff_ptr_s |
Data Fields | ||
---|---|---|
union fr_sbuff_ptr_s.__unnamed138__ | __unnamed__ | |
fr_sbuff_marker_t * | next | Next m in the list. |
fr_sbuff_t * | parent | Owner of the marker. |
union fr_sbuff_ptr_s.__unnamed138__ |
struct fr_sbuff_s |
Data Fields | ||
---|---|---|
union fr_sbuff_s.__unnamed140__ | __unnamed__ | |
union fr_sbuff_s.__unnamed142__ | __unnamed__ | |
union fr_sbuff_s.__unnamed144__ | __unnamed__ | |
union fr_sbuff_s.__unnamed146__ | __unnamed__ | |
uint8_t | adv_parent:1 | If true, advance the parent. |
fr_sbuff_eof_t | eof | Function to determine if the buffer is at EOF. |
char const * | err | Where the last error occurred. |
fr_sbuff_extend_t | extend | Function to re-populate or extend the buffer. |
uint8_t | is_const:1 | Can't be modified. |
fr_sbuff_marker_t * | m | Pointers to update if the underlying buffer changes. |
fr_sbuff_t * | parent | sbuff this sbuff was copied from. |
size_t | shifted | How many bytes this sbuff has been shifted since its creation. |
void * | uctx | Extend uctx data. |
union fr_sbuff_s.__unnamed140__ |
union fr_sbuff_s.__unnamed142__ |
union fr_sbuff_s.__unnamed144__ |
union fr_sbuff_s.__unnamed146__ |
struct fr_sbuff_term_elem_t |
struct fr_sbuff_term_t |
Set of terminal elements.
The elements MUST be listed in sorted order. If the inputs are not sorted, then all kinds of things will break.
Definition at line 161 of file merged_model.c.
Data Fields | ||
---|---|---|
fr_sbuff_term_elem_t * | elem | A sorted list of terminal strings. |
size_t | len | Length of the list. |
struct fr_sbuff_uctx_file_t |
File sbuff extension structure.
Holds the data necessary for creating dynamically extensible file buffers.
Data Fields | ||
---|---|---|
char * | buff_end | The true end of the buffer. |
bool | eof | are we at EOF? |
FILE * | file | FILE * we're reading from. |
size_t | max | Maximum number of bytes to read. |
size_t | shifted | How much we've read from this file. |
struct fr_sbuff_uctx_talloc_t |
struct fr_sbuff_unescape_rules_t |
Set of parsing rules for *unescape_until functions.
Definition at line 163 of file merged_model.c.
Data Fields | ||
---|---|---|
char | chr | Character at the start of an escape sequence. |
bool | do_hex |
Process hex sequences i.e. \x<hex><hex>. |
bool | do_oct |
Process oct sequences i.e. \<oct><oct><oct>. |
char const * | name | Name for rule set to aid we debugging. |
bool | skip[UINT8_MAX+1] |
Characters that are escaped, but left in the output along with the escape character. This is useful where we need to interpret escape sequences for parsing, but where the string will be passed off to a 3rd party library which will need to interpret the same sequences. |
char | subs[UINT8_MAX+1] |
Special characters and their substitutions. Indexed by the printable representation i.e. 'n' for |
#define _fr_sbuff_out_size | ( | _err, | |
_out, | |||
_in | |||
) | size_t * : fr_sbuff_out_size(_err, (size_t *)_out, _in, true), |
#define _fr_sbuff_out_ssize | ( | _err, | |
_out, | |||
_in | |||
) | ssize_t * : fr_sbuff_out_ssize(_err, (ssize_t *)_out, _in, true), |
#define FR_SBUFF | ( | _sbuff_or_marker | ) |
#define FR_SBUFF_ABS | ( | _sbuff_or_marker | ) |
#define fr_sbuff_adv_past_blank | ( | _sbuff, | |
_len, | |||
_tt | |||
) | fr_sbuff_adv_past_allowed(_sbuff, _len, sbuff_char_blank, _tt) |
#define fr_sbuff_adv_past_str_literal | ( | _sbuff, | |
_needle | |||
) | fr_sbuff_adv_past_str(_sbuff, _needle, sizeof(_needle) - 1) |
#define fr_sbuff_adv_past_strcase_literal | ( | _sbuff, | |
_needle | |||
) | fr_sbuff_adv_past_strcase(_sbuff, _needle, sizeof(_needle) - 1) |
#define fr_sbuff_adv_past_whitespace | ( | _sbuff, | |
_len, | |||
_tt | |||
) | fr_sbuff_adv_past_allowed(_sbuff, _len, sbuff_char_whitespace, _tt) |
#define fr_sbuff_adv_past_zeros | ( | _sbuff, | |
_len, | |||
_tt | |||
) | fr_sbuff_adv_past_allowed(_sbuff, _len, sbuff_char_class_zero, _tt) |
#define fr_sbuff_adv_to_str_literal | ( | _sbuff, | |
_len, | |||
_needle | |||
) | fr_sbuff_adv_to_str(_sbuff, _len, _needle, sizeof(_needle) - 1) |
#define fr_sbuff_adv_to_strcase_literal | ( | _sbuff, | |
_len, | |||
_needle | |||
) | fr_sbuff_adv_to_strcase(_sbuff, _len, _needle, sizeof(_needle) - 1) |
#define fr_sbuff_advance | ( | _sbuff_or_marker, | |
_len | |||
) | fr_sbuff_set(_sbuff_or_marker, (fr_sbuff_current(_sbuff_or_marker) + (_len))) |
#define FR_SBUFF_ADVANCE_RETURN | ( | _sbuff, | |
_len | |||
) | FR_SBUFF_RETURN(fr_sbuff_advance, _sbuff, _len) |
#define fr_sbuff_ahead | ( | _sbuff_or_marker | ) |
#define fr_sbuff_as_percent_s | ( | _sbuff | ) | (int) fr_sbuff_remaining(_sbuff), fr_sbuff_current(_sbuff) |
#define fr_sbuff_behind | ( | _sbuff_or_marker | ) |
#define FR_SBUFF_BIND_CURRENT | ( | _sbuff_or_marker | ) |
#define FR_SBUFF_BIND_CURRENT_ABS | ( | _sbuff_or_marker | ) |
#define fr_sbuff_buff | ( | _sbuff_or_marker | ) |
#define fr_sbuff_char | ( | _sbuff_or_marker, | |
_eob | |||
) | (fr_sbuff_current(_sbuff_or_marker) >= fr_sbuff_end(_sbuff_or_marker) ? _eob : *fr_sbuff_current(_sbuff_or_marker)) |
#define FR_SBUFF_CHECK_REMAINING_RETURN | ( | _sbuff, | |
_len | |||
) | if ((_len) > fr_sbuff_remaining(_sbuff)) return -((_len) - fr_sbuff_remaining(_sbuff)) |
#define fr_sbuff_current | ( | _sbuff_or_marker | ) |
#define fr_sbuff_diff | ( | _a, | |
_b | |||
) | ((ssize_t)(fr_sbuff_current(_a) - fr_sbuff_current(_b))) |
#define fr_sbuff_end | ( | _sbuff_or_marker | ) |
#define fr_sbuff_error | ( | _sbuff_or_marker | ) | _fr_sbuff_error(fr_sbuff_ptr(_sbuff_or_marker), fr_sbuff_current(_sbuff_or_marker)) |
#define FR_SBUFF_ERROR_RETURN | ( | _sbuff_or_marker | ) | return fr_sbuff_error(_sbuff_or_marker) |
#define fr_sbuff_extend | ( | _sbuff_or_marker | ) | fr_sbuff_extend_lowat(NULL, _sbuff_or_marker, 1) |
#define fr_sbuff_extend_lowat | ( | _status, | |
_sbuff_or_marker, | |||
_lowat | |||
) |
#define FR_SBUFF_EXTEND_LOWAT_OR_RETURN | ( | _sbuff, | |
_len | |||
) |
#define FR_SBUFF_IN | ( | _start, | |
_len_or_end | |||
) |
#define FR_SBUFF_IN_BSTRCPY_BUFFER_RETURN | ( | ... | ) | FR_SBUFF_RETURN(fr_sbuff_in_bstrcpy_buffer, ##__VA_ARGS__) |
#define FR_SBUFF_IN_BSTRNCPY_RETURN | ( | ... | ) | FR_SBUFF_RETURN(fr_sbuff_in_bstrncpy, ##__VA_ARGS__) |
#define fr_sbuff_in_char | ( | _sbuff, | |
... | |||
) | fr_sbuff_in_bstrncpy(_sbuff, ((char []){ __VA_ARGS__ }), sizeof((char []){ __VA_ARGS__ })) |
#define FR_SBUFF_IN_CHAR_RETURN | ( | _sbuff, | |
... | |||
) | FR_SBUFF_RETURN(fr_sbuff_in_bstrncpy, _sbuff, ((char []){ __VA_ARGS__ }), sizeof((char []){ __VA_ARGS__ })) |
#define FR_SBUFF_IN_ESCAPE_BUFFER_RETURN | ( | ... | ) | FR_SBUFF_RETURN(fr_sbuff_in_escape_buffer, ##__VA_ARGS__) |
#define FR_SBUFF_IN_ESCAPE_RETURN | ( | ... | ) | FR_SBUFF_RETURN(fr_sbuff_in_escape, ##__VA_ARGS__) |
#define FR_SBUFF_IN_SPRINTF_RETURN | ( | ... | ) | FR_SBUFF_RETURN(fr_sbuff_in_sprintf, ##__VA_ARGS__) |
#define fr_sbuff_in_strcpy_literal | ( | _sbuff, | |
_str | |||
) | fr_sbuff_in_bstrncpy(_sbuff, _str, sizeof(_str) - 1) |
#define FR_SBUFF_IN_STRCPY_LITERAL_RETURN | ( | _sbuff, | |
_str | |||
) | FR_SBUFF_RETURN(fr_sbuff_in_bstrncpy, _sbuff, _str, sizeof(_str) - 1) |
#define FR_SBUFF_IN_STRCPY_RETURN | ( | ... | ) | FR_SBUFF_RETURN(fr_sbuff_in_strcpy, ##__VA_ARGS__) |
#define fr_sbuff_in_table_str | ( | _slen, | |
_sbuff, | |||
_table, | |||
_number, | |||
_def | |||
) | _slen = fr_sbuff_in_strcpy(_sbuff, fr_table_str_by_value(_table, _number, _def)) |
#define FR_SBUFF_IN_TABLE_STR_RETURN | ( | _sbuff, | |
_table, | |||
_number, | |||
_def | |||
) |
#define FR_SBUFF_IN_VSPRINTF_RETURN | ( | ... | ) | FR_SBUFF_RETURN(fr_sbuff_in_vsprintf, ##__VA_ARGS__) |
#define fr_sbuff_init_in | ( | _out, | |
_start, | |||
_len_or_end | |||
) |
#define fr_sbuff_init_out | ( | _out, | |
_start, | |||
_len_or_end | |||
) |
#define fr_sbuff_is_alnum | ( | _sbuff_or_marker | ) | SBUFF_IS_GENERIC(_sbuff_or_marker, alnum) |
#define fr_sbuff_is_alpha | ( | _sbuff_or_marker | ) | SBUFF_IS_GENERIC(_sbuff_or_marker, alpha) |
#define fr_sbuff_is_char | ( | _sbuff_or_marker, | |
_c | |||
) |
#define fr_sbuff_is_digit | ( | _sbuff_or_marker | ) | SBUFF_IS_GENERIC(_sbuff_or_marker, digit) |
#define fr_sbuff_is_hex | ( | _sbuff_or_marker | ) | SBUFF_IS_GENERIC(_sbuff_or_marker, hex) |
#define fr_sbuff_is_lower | ( | _sbuff_or_marker | ) | SBUFF_IS_GENERIC(_sbuff_or_marker, lower) |
#define fr_sbuff_is_space | ( | _sbuff_or_marker | ) | SBUFF_IS_GENERIC(_sbuff_or_marker, space) |
#define fr_sbuff_is_str_literal | ( | _sbuff, | |
_str | |||
) | fr_sbuff_is_str(_sbuff, _str, sizeof(_str) - 1) |
#define fr_sbuff_is_upper | ( | _sbuff_or_marker | ) | SBUFF_IS_GENERIC(_sbuff_or_marker, upper) |
#define fr_sbuff_len | ( | _sbuff_or_marker | ) | ((size_t)(fr_sbuff_end(_sbuff_or_marker) - fr_sbuff_buff(_sbuff_or_marker))) |
#define fr_sbuff_move | ( | _out, | |
_in, | |||
_len | |||
) |
#define fr_sbuff_out | ( | _err, | |
_out, | |||
_in | |||
) |
#define FR_SBUFF_OUT | ( | _start, | |
_len_or_end | |||
) |
#define fr_sbuff_out_by_longest_prefix | ( | _match_len, | |
_out, | |||
_table, | |||
_sbuff, | |||
_def | |||
) |
#define fr_sbuff_ptr | ( | _sbuff_or_marker | ) |
#define fr_sbuff_remaining | ( | _sbuff_or_marker | ) |
#define FR_SBUFF_REPARSE | ( | _sbuff_or_marker | ) |
#define FR_SBUFF_RETURN | ( | _func, | |
_sbuff, | |||
... | |||
) |
#define fr_sbuff_set | ( | _dst, | |
_src | |||
) |
#define FR_SBUFF_SET_RETURN | ( | _dst, | |
_src | |||
) | return fr_sbuff_set(_dst, _src) |
#define fr_sbuff_shifted | ( | _sbuff_or_marker | ) |
#define fr_sbuff_start | ( | _sbuff_or_marker | ) |
#define fr_sbuff_switch | ( | _sbuff_or_marker, | |
_eob | |||
) | switch (fr_sbuff_char(_sbuff_or_marker, _eob)) |
#define FR_SBUFF_TALLOC_THREAD_LOCAL | ( | _out, | |
_init, | |||
_max | |||
) |
#define FR_SBUFF_TERM | ( | _str | ) |
Initialise a terminal structure with a single string.
[in] | _str | terminal string. |
#define FR_SBUFF_TERMS | ( | ... | ) |
Initialise a terminal structure with a list of sorted strings.
Strings must be lexicographically sorted.
[in] | ... | Lexicographically sorted list of terminal strings. |
#define fr_sbuff_used | ( | _sbuff_or_marker | ) |
#define fr_sbuff_used_total | ( | _sbuff_or_marker | ) | ((size_t)((fr_sbuff_current(_sbuff_or_marker) + fr_sbuff_shifted(_sbuff_or_marker)) - fr_sbuff_start(_sbuff_or_marker))) |
#define fr_sbuff_was_extended | ( | _status | ) | (_status & FR_SBUFF_FLAG_EXTENDED) |
#define SBUFF_CHAR_CLASS_ALPHA |
#define SBUFF_CHAR_CLASS_ALPHA_NUM |
#define SBUFF_CHAR_CLASS_HEX |
#define SBUFF_CHAR_CLASS_NUM |
#define SBUFF_CHAR_CLASS_SYMBOLS |
#define SBUFF_CHAR_UNPRINTABLES_EXTENDED |
#define SBUFF_CHAR_UNPRINTABLES_LOW |
#define SBUFF_IS_FUNC | ( | _name, | |
_test | |||
) |
#define SBUFF_IS_GENERIC | ( | _sbuff_or_marker, | |
_name | |||
) |
#define SBUFF_OUT_TALLOC_ERR_FUNC_DEF | ( | _func, | |
_in, | |||
_len, | |||
... | |||
) |
#define SBUFF_OUT_TALLOC_FUNC_DEF | ( | _func, | |
_in, | |||
_len, | |||
... | |||
) |
#define SBUFF_OUT_TALLOC_FUNC_NO_LEN_DEF | ( | _func, | |
... | |||
) |
typedef bool(* fr_sbuff_eof_t) (fr_sbuff_t *sbuff) |
typedef size_t(* fr_sbuff_extend_t) (fr_sbuff_extend_status_t *status, fr_sbuff_t *sbuff, size_t req_extension) |
typedef struct fr_sbuff_ptr_s fr_sbuff_marker_t |
typedef struct fr_sbuff_s fr_sbuff_t |
Represents number of bytes parsed or location of parse error.
Number of bytes parsed will be >= 0.
If a parse error occurs the value will be the negative offset of the error -1. i.e. offset 0 will be -1.
This is to disambiguate between 0 bytes parsed and error at offset 0.
Whether the buffer is currently extendable and whether it was extended.