The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
A generic string buffer structure for string printing and parsing. More...
#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/syserror.h>
#include <freeradius-devel/util/atexit.h>
Go to the source code of this file.
Macros | |
#define | CHECK_SBUFF_INIT(_sbuff) do { if (!(_sbuff)->extend && (unlikely(!(_sbuff)->buff) || unlikely(!(_sbuff)->start) || unlikely(!(_sbuff)->end) || unlikely(!(_sbuff)->p))) return 0; } while (0) |
#define | CONSTRAINED_END(_sbuff, _max, _used) (((_max) - (_used)) > fr_sbuff_remaining(_sbuff) ? (_sbuff)->end : (_sbuff)->p + ((_max) - (_used))) |
Constrain end pointer to prevent advancing more than the amount the caller specified. More... | |
#define | FILL_OR_GOTO_DONE(_out, _in, _len) if (fr_sbuff_move(_out, _in, _len) < (size_t)(_len)) goto done |
Fill as much of the output buffer we can and break on partial copy. More... | |
#define | SBUFF_PARSE_FLOAT_DEF(_name, _type, _func, _max_char) |
Used to define a number parsing functions for floats. More... | |
#define | SBUFF_PARSE_INT_DEF(_name, _type, _min, _max, _max_char, _base) |
Used to define a number parsing functions for signed integers. More... | |
#define | SBUFF_PARSE_UINT_DEF(_name, _type, _max, _max_char, _base) |
Used to define a number parsing functions for signed integers. More... | |
Functions | |
size_t | _fr_sbuff_move_marker_to_marker (fr_sbuff_marker_t *out, fr_sbuff_marker_t *in, size_t len) |
Move data from one marker to another. More... | |
size_t | _fr_sbuff_move_marker_to_sbuff (fr_sbuff_t *out, fr_sbuff_marker_t *in, size_t len) |
Move data from a marker to an sbuff. More... | |
size_t | _fr_sbuff_move_sbuff_to_marker (fr_sbuff_marker_t *out, fr_sbuff_t *in, size_t len) |
Move data from an sbuff to a marker. More... | |
size_t | _fr_sbuff_move_sbuff_to_sbuff (fr_sbuff_t *out, fr_sbuff_t *in, size_t len) |
Move data from one sbuff to another. More... | |
static int | _sbuff_scratch_free (void *arg) |
Free the scratch buffer used for printf. More... | |
size_t | fr_sbuff_adv_past_allowed (fr_sbuff_t *sbuff, size_t len, bool const allowed[static UINT8_MAX+1], fr_sbuff_term_t const *tt) |
Wind position past characters in the allowed set. More... | |
size_t | fr_sbuff_adv_past_str (fr_sbuff_t *sbuff, char const *needle, size_t needle_len) |
Return true and advance past the end of the needle if needle occurs next in the sbuff. More... | |
size_t | fr_sbuff_adv_past_strcase (fr_sbuff_t *sbuff, char const *needle, size_t needle_len) |
Return true and advance past the end of the needle if needle occurs next in the sbuff. More... | |
char * | fr_sbuff_adv_to_chr (fr_sbuff_t *sbuff, size_t len, char c) |
Wind position to first instance of specified char. More... | |
char * | fr_sbuff_adv_to_chr_utf8 (fr_sbuff_t *sbuff, size_t len, char const *chr) |
Wind position to first instance of specified multibyte utf8 char. More... | |
char * | fr_sbuff_adv_to_str (fr_sbuff_t *sbuff, size_t len, char const *needle, size_t needle_len) |
Wind position to the first instance of the specified needle. More... | |
char * | fr_sbuff_adv_to_strcase (fr_sbuff_t *sbuff, size_t len, char const *needle, size_t needle_len) |
Wind position to the first instance of the specified needle. More... | |
size_t | fr_sbuff_adv_until (fr_sbuff_t *sbuff, size_t len, fr_sbuff_term_t const *tt, char escape_chr) |
Wind position until we hit a character in the terminal set. More... | |
size_t | fr_sbuff_extend_file (fr_sbuff_t *sbuff, size_t extension) |
Refresh the buffer with more data from the file. More... | |
size_t | fr_sbuff_extend_talloc (fr_sbuff_t *sbuff, size_t extension) |
Reallocate the current buffer. More... | |
ssize_t | fr_sbuff_in_bstrcpy_buffer (fr_sbuff_t *sbuff, char const *str) |
Copy bytes into the sbuff up to the first \0. More... | |
ssize_t | fr_sbuff_in_bstrncpy (fr_sbuff_t *sbuff, char const *str, size_t len) |
Copy bytes into the sbuff up to the first \0. More... | |
ssize_t | fr_sbuff_in_escape (fr_sbuff_t *sbuff, char const *in, size_t inlen, fr_sbuff_escape_rules_t const *e_rules) |
Print an escaped string to an sbuff. More... | |
ssize_t | fr_sbuff_in_escape_buffer (fr_sbuff_t *sbuff, char const *in, fr_sbuff_escape_rules_t const *e_rules) |
Print an escaped string to an sbuff taking a talloced buffer as input. More... | |
ssize_t | fr_sbuff_in_sprintf (fr_sbuff_t *sbuff, char const *fmt,...) |
Print using a fmt string to an sbuff. More... | |
ssize_t | fr_sbuff_in_strcpy (fr_sbuff_t *sbuff, char const *str) |
Copy bytes into the sbuff up to the first \0. More... | |
ssize_t | fr_sbuff_in_vsprintf (fr_sbuff_t *sbuff, char const *fmt, va_list ap) |
Print using a fmt string to an sbuff. More... | |
bool | fr_sbuff_is_terminal (fr_sbuff_t *in, fr_sbuff_term_t const *tt) |
Efficient terminal string search. More... | |
bool | fr_sbuff_next_if_char (fr_sbuff_t *sbuff, char c) |
Return true if the current char matches, and if it does, advance. More... | |
bool | fr_sbuff_next_unless_char (fr_sbuff_t *sbuff, char c) |
Return true and advance if the next char does not match. More... | |
fr_slen_t | fr_sbuff_out_bool (bool *out, fr_sbuff_t *in) |
See if the string contains a truth value. More... | |
size_t | fr_sbuff_out_bstrncpy (fr_sbuff_t *out, fr_sbuff_t *in, size_t len) |
Copy as many bytes as possible from a sbuff to a sbuff. More... | |
size_t | fr_sbuff_out_bstrncpy_allowed (fr_sbuff_t *out, fr_sbuff_t *in, size_t len, bool const allowed[static UINT8_MAX+1]) |
Copy as many allowed characters as possible from a sbuff to a sbuff. More... | |
ssize_t | fr_sbuff_out_bstrncpy_exact (fr_sbuff_t *out, fr_sbuff_t *in, size_t len) |
Copy exactly len bytes from a sbuff to a sbuff or fail. More... | |
size_t | fr_sbuff_out_bstrncpy_until (fr_sbuff_t *out, fr_sbuff_t *in, size_t len, fr_sbuff_term_t const *tt, fr_sbuff_unescape_rules_t const *u_rules) |
Copy as many allowed characters as possible from a sbuff to a sbuff. More... | |
size_t | fr_sbuff_out_unescape_until (fr_sbuff_t *out, fr_sbuff_t *in, size_t len, fr_sbuff_term_t const *tt, fr_sbuff_unescape_rules_t const *u_rules) |
Copy as many allowed characters as possible from a sbuff to a sbuff. More... | |
void | fr_sbuff_parse_rules_debug (fr_sbuff_parse_rules_t const *p_rules) |
int | fr_sbuff_reset_talloc (fr_sbuff_t *sbuff) |
Reset a talloced buffer to its initial length, clearing any data stored. More... | |
size_t | fr_sbuff_shift (fr_sbuff_t *sbuff, size_t shift) |
Shift the contents of the sbuff, returning the number of bytes we managed to shift. More... | |
void | fr_sbuff_terminal_debug (fr_sbuff_term_t const *tt) |
static void | fr_sbuff_terminal_idx_init (size_t *needle_len, uint8_t idx[static UINT8_MAX+1], fr_sbuff_term_t const *term) |
Populate a terminal index. More... | |
static bool | fr_sbuff_terminal_search (fr_sbuff_t *in, char const *p, uint8_t idx[static UINT8_MAX+1], fr_sbuff_term_t const *term, size_t needle_len) |
Efficient terminal string search. More... | |
fr_sbuff_term_t * | fr_sbuff_terminals_amerge (TALLOC_CTX *ctx, fr_sbuff_term_t const *a, fr_sbuff_term_t const *b) |
Merge two sets of terminal strings. More... | |
size_t | fr_sbuff_trim (fr_sbuff_t *sbuff, bool const to_trim[static UINT8_MAX+1]) |
Trim trailing characters from a string we're composing. More... | |
int | fr_sbuff_trim_talloc (fr_sbuff_t *sbuff, size_t len) |
Trim a talloced sbuff to the minimum length required to represent the contained string. More... | |
void | fr_sbuff_unescape_debug (fr_sbuff_unescape_rules_t const *escapes) |
void | fr_sbuff_update (fr_sbuff_t *sbuff, char *new_buff, size_t new_len) |
Update all markers and pointers in the set of sbuffs to point to new_buff. More... | |
static size_t | min (size_t x, size_t y) |
static ssize_t | safecpy (char *o_start, char *o_end, char const *i_start, char const *i_end) |
Copy function that allows overlapping memory ranges to be copied. More... | |
static char const * | sbuff_print_char (char c) |
Print a char in a friendly format. More... | |
static int | sbuff_scratch_init (TALLOC_CTX **out) |
static int8_t | terminal_cmp (fr_sbuff_term_elem_t const *a, fr_sbuff_term_elem_t const *b) |
Compare two terminal elements for ordering purposes. More... | |
Variables | |
bool const | sbuff_char_alpha_num [UINT8_MAX+1] = { SBUFF_CHAR_CLASS_ALPHA_NUM } |
bool const | sbuff_char_blank [UINT8_MAX+1] |
bool const | sbuff_char_class_float [UINT8_MAX+1] |
bool const | sbuff_char_class_hex [UINT8_MAX+1] = { SBUFF_CHAR_CLASS_HEX } |
bool const | sbuff_char_class_hostname [UINT8_MAX+1] |
bool const | sbuff_char_class_int [UINT8_MAX+1] |
bool const | sbuff_char_class_uint [UINT8_MAX+1] |
bool const | sbuff_char_class_zero [UINT8_MAX+1] |
bool const | sbuff_char_line_endings [UINT8_MAX+1] |
bool const | sbuff_char_whitespace [UINT8_MAX+1] |
bool const | sbuff_char_word [UINT8_MAX+1] |
fr_table_num_ordered_t const | sbuff_parse_error_table [] |
size_t | sbuff_parse_error_table_len = NUM_ELEMENTS(sbuff_parse_error_table) |
static _Thread_local char * | sbuff_scratch |
static _Thread_local bool | sbuff_scratch_freed |
When true, prevent use of the scratch space. More... | |
A generic string buffer structure for string printing and parsing.
Definition in file sbuff.c.
#define CONSTRAINED_END | ( | _sbuff, | |
_max, | |||
_used | |||
) | (((_max) - (_used)) > fr_sbuff_remaining(_sbuff) ? (_sbuff)->end : (_sbuff)->p + ((_max) - (_used))) |
#define FILL_OR_GOTO_DONE | ( | _out, | |
_in, | |||
_len | |||
) | if (fr_sbuff_move(_out, _in, _len) < (size_t)(_len)) goto done |
#define SBUFF_PARSE_FLOAT_DEF | ( | _name, | |
_type, | |||
_func, | |||
_max_char | |||
) |
Used to define a number parsing functions for floats.
[in] | _name | Function suffix. |
[in] | _type | Output type. |
[in] | _func | Parsing function to use. |
[in] | _max_char | Maximum digits that can be used to represent an integer. Can't use stringify because of width modifiers like 'u' used in <stdint.h>. |
#define SBUFF_PARSE_INT_DEF | ( | _name, | |
_type, | |||
_min, | |||
_max, | |||
_max_char, | |||
_base | |||
) |
Used to define a number parsing functions for signed integers.
[in] | _name | Function suffix. |
[in] | _type | Output type. |
[in] | _min | value. |
[in] | _max | value. |
[in] | _max_char | Maximum digits that can be used to represent an integer. Can't use stringify because of width modifiers like 'u' used in <stdint.h>. |
[in] | _base | to use. |
#define SBUFF_PARSE_UINT_DEF | ( | _name, | |
_type, | |||
_max, | |||
_max_char, | |||
_base | |||
) |
Used to define a number parsing functions for signed integers.
[in] | _name | Function suffix. |
[in] | _type | Output type. |
[in] | _max | value. |
[in] | _max_char | Maximum digits that can be used to represent an integer. Can't use stringify because of width modifiers like 'u' used in <stdint.h>. |
[in] | _base | of the number being parsed, 8, 10, 16 etc... |
size_t _fr_sbuff_move_marker_to_marker | ( | fr_sbuff_marker_t * | out, |
fr_sbuff_marker_t * | in, | ||
size_t | len | ||
) |
Move data from one marker to another.
[in] | out | marker to copy data to. |
[in] | in | marker to copy data from. |
[in] | len | Maximum length of string to copy. |
Definition at line 1393 of file sbuff.c.
size_t _fr_sbuff_move_marker_to_sbuff | ( | fr_sbuff_t * | out, |
fr_sbuff_marker_t * | in, | ||
size_t | len | ||
) |
Move data from a marker to an sbuff.
[in] | out | sbuff to copy data to. |
[in] | in | marker to copy data from. |
[in] | len | Maximum length of string to copy. |
Definition at line 1373 of file sbuff.c.
size_t _fr_sbuff_move_sbuff_to_marker | ( | fr_sbuff_marker_t * | out, |
fr_sbuff_t * | in, | ||
size_t | len | ||
) |
Move data from an sbuff to a marker.
[in] | out | marker to copy data to. |
[in] | in | sbuff to copy data from. |
[in] | len | Maximum length of string to copy. |
Definition at line 1413 of file sbuff.c.
size_t _fr_sbuff_move_sbuff_to_sbuff | ( | fr_sbuff_t * | out, |
fr_sbuff_t * | in, | ||
size_t | len | ||
) |
Move data from one sbuff to another.
Both in and out will be advanced by len, with len set to the shortest value between the user specified value, the number of bytes remaining in the input buffer (after extension), and the number of bytes remaining in the output buffer (after extension).
[in] | out | sbuff to copy data to. |
[in] | in | sbuff to copy data from. |
[in] | len | Maximum length of string to copy. |
Definition at line 1353 of file sbuff.c.
|
static |
size_t fr_sbuff_adv_past_allowed | ( | fr_sbuff_t * | sbuff, |
size_t | len, | ||
bool const | allowed[static UINT8_MAX+1], | ||
fr_sbuff_term_t const * | tt | ||
) |
Wind position past characters in the allowed set.
[in] | sbuff | sbuff to search in. |
[in] | len | Maximum amount to advance by. Unconstrained if SIZE_MAX. |
[in] | allowed | character set. |
[in] | tt | If not NULL, stop if we find a terminal sequence. |
Definition at line 1755 of file sbuff.c.
size_t fr_sbuff_adv_past_str | ( | fr_sbuff_t * | sbuff, |
char const * | needle, | ||
size_t | needle_len | ||
) |
Return true and advance past the end of the needle if needle occurs next in the sbuff.
[in] | sbuff | to search in. |
[in] | needle | to search for. |
[in] | needle_len | of needle. If SIZE_MAX strlen is used to determine length of the needle. |
Definition at line 1690 of file sbuff.c.
size_t fr_sbuff_adv_past_strcase | ( | fr_sbuff_t * | sbuff, |
char const * | needle, | ||
size_t | needle_len | ||
) |
Return true and advance past the end of the needle if needle occurs next in the sbuff.
This function is similar to fr_sbuff_adv_past_str but is case insensitive.
[in] | sbuff | to search in. |
[in] | needle | to search for. |
[in] | needle_len | of needle. If SIZE_MAX strlen is used to determine length of the needle. |
Definition at line 1721 of file sbuff.c.
char* fr_sbuff_adv_to_chr | ( | fr_sbuff_t * | sbuff, |
size_t | len, | ||
char | c | ||
) |
Wind position to first instance of specified char.
[in,out] | sbuff | to search in. |
[in] | len | Maximum amount to advance by. Unconstrained if SIZE_MAX. |
[in] | c | to search for. |
Definition at line 1934 of file sbuff.c.
char* fr_sbuff_adv_to_chr_utf8 | ( | fr_sbuff_t * | sbuff, |
size_t | len, | ||
char const * | chr | ||
) |
Wind position to first instance of specified multibyte utf8 char.
Only use this function if the search char could be multibyte, as there's a large performance penalty.
[in,out] | sbuff | to search in. |
[in] | len | the maximum number of characters to search in sbuff. |
[in] | chr | to search for. |
Definition at line 1889 of file sbuff.c.
char* fr_sbuff_adv_to_str | ( | fr_sbuff_t * | sbuff, |
size_t | len, | ||
char const * | needle, | ||
size_t | needle_len | ||
) |
Wind position to the first instance of the specified needle.
[in,out] | sbuff | sbuff to search in. |
[in] | len | Maximum amount to advance by. Unconstrained if SIZE_MAX. |
[in] | needle | to search for. |
[in] | needle_len | Length of the needle. SIZE_MAX to used strlen. |
Definition at line 1970 of file sbuff.c.
char* fr_sbuff_adv_to_strcase | ( | fr_sbuff_t * | sbuff, |
size_t | len, | ||
char const * | needle, | ||
size_t | needle_len | ||
) |
Wind position to the first instance of the specified needle.
[in,out] | sbuff | sbuff to search in. |
[in] | len | Maximum amount to advance by. Unconstrained if SIZE_MAX. |
[in] | needle | to search for. |
[in] | needle_len | Length of the needle. SIZE_MAX to used strlen. |
Definition at line 2023 of file sbuff.c.
size_t fr_sbuff_adv_until | ( | fr_sbuff_t * | sbuff, |
size_t | len, | ||
fr_sbuff_term_t const * | tt, | ||
char | escape_chr | ||
) |
Wind position until we hit a character in the terminal set.
[in] | sbuff | sbuff to search in. |
[in] | len | Maximum amount to advance by. Unconstrained if SIZE_MAX. |
[in] | tt | Token terminals in the encompassing grammar. |
[in] | escape_chr | If not '\0', ignore characters in the tt set when prefixed with this escape character. |
Definition at line 1830 of file sbuff.c.
size_t fr_sbuff_extend_file | ( | fr_sbuff_t * | sbuff, |
size_t | extension | ||
) |
size_t fr_sbuff_extend_talloc | ( | fr_sbuff_t * | sbuff, |
size_t | extension | ||
) |
Reallocate the current buffer.
[in] | sbuff | to be extended. |
[in] | extension | How many additional bytes should be allocated in the buffer. |
Definition at line 344 of file sbuff.c.
ssize_t fr_sbuff_in_bstrcpy_buffer | ( | fr_sbuff_t * | sbuff, |
char const * | str | ||
) |
Copy bytes into the sbuff up to the first \0.
[in] | sbuff | to copy into. |
[in] | str | talloced buffer to copy into sbuff. |
Definition at line 1480 of file sbuff.c.
ssize_t fr_sbuff_in_bstrncpy | ( | fr_sbuff_t * | sbuff, |
char const * | str, | ||
size_t | len | ||
) |
Copy bytes into the sbuff up to the first \0.
[in] | sbuff | to copy into. |
[in] | str | to copy into buffer. |
[in] | len | number of bytes to copy. |
Definition at line 1458 of file sbuff.c.
ssize_t fr_sbuff_in_escape | ( | fr_sbuff_t * | sbuff, |
char const * | in, | ||
size_t | inlen, | ||
fr_sbuff_escape_rules_t const * | e_rules | ||
) |
Print an escaped string to an sbuff.
[in] | sbuff | to print into. |
[in] | in | to escape. |
[in] | inlen | of string to escape. |
[in] | e_rules | Escaping rules. Used to escape special characters as data is written to the sbuff. May be NULL. |
Definition at line 1598 of file sbuff.c.
ssize_t fr_sbuff_in_escape_buffer | ( | fr_sbuff_t * | sbuff, |
char const * | in, | ||
fr_sbuff_escape_rules_t const * | e_rules | ||
) |
Print an escaped string to an sbuff taking a talloced buffer as input.
[in] | sbuff | to print into. |
[in] | in | to escape. |
[in] | e_rules | Escaping rules. Used to escape special characters as data is written to the sbuff. May be NULL. |
Definition at line 1673 of file sbuff.c.
ssize_t fr_sbuff_in_sprintf | ( | fr_sbuff_t * | sbuff, |
char const * | fmt, | ||
... | |||
) |
Print using a fmt string to an sbuff.
[in] | sbuff | to print into. |
[in] | fmt | string. |
[in] | ... | arguments for format string. |
Definition at line 1573 of file sbuff.c.
ssize_t fr_sbuff_in_strcpy | ( | fr_sbuff_t * | sbuff, |
char const * | str | ||
) |
Copy bytes into the sbuff up to the first \0.
[in] | sbuff | to copy into. |
[in] | str | to copy into buffer. |
Definition at line 1432 of file sbuff.c.
ssize_t fr_sbuff_in_vsprintf | ( | fr_sbuff_t * | sbuff, |
char const * | fmt, | ||
va_list | ap | ||
) |
Print using a fmt string to an sbuff.
[in] | sbuff | to print into. |
[in] | fmt | string. |
[in] | ap | arguments for format string. |
Definition at line 1540 of file sbuff.c.
bool fr_sbuff_is_terminal | ( | fr_sbuff_t * | in, |
fr_sbuff_term_t const * | tt | ||
) |
Efficient terminal string search.
Caller should ensure that a buffer extension of needle_len bytes has been requested before calling this function.
[in] | in | Sbuff to search in. |
[in] | tt | Token terminals in the encompassing grammar. |
Definition at line 2130 of file sbuff.c.
bool fr_sbuff_next_if_char | ( | fr_sbuff_t * | sbuff, |
char | c | ||
) |
Return true if the current char matches, and if it does, advance.
[in] | sbuff | to search for char in. |
[in] | c | char to search for. |
Definition at line 2066 of file sbuff.c.
bool fr_sbuff_next_unless_char | ( | fr_sbuff_t * | sbuff, |
char | c | ||
) |
Return true and advance if the next char does not match.
[in] | sbuff | to search for char in. |
[in] | c | char to search for. |
Definition at line 2087 of file sbuff.c.
fr_slen_t fr_sbuff_out_bool | ( | bool * | out, |
fr_sbuff_t * | in | ||
) |
See if the string contains a truth value.
[out] | out | Where to write boolean value. |
[in] | in | Where to search for a truth value. |
Definition at line 1087 of file sbuff.c.
size_t fr_sbuff_out_bstrncpy | ( | fr_sbuff_t * | out, |
fr_sbuff_t * | in, | ||
size_t | len | ||
) |
Copy as many bytes as possible from a sbuff to a sbuff.
Copy size is limited by available data in sbuff and space in output sbuff.
[out] | out | Where to copy to. |
[in] | in | Where to copy from. Will copy len bytes from current position in buffer. |
[in] | len | How many bytes to copy. If SIZE_MAX the entire buffer will be copied. |
Definition at line 700 of file sbuff.c.
size_t fr_sbuff_out_bstrncpy_allowed | ( | fr_sbuff_t * | out, |
fr_sbuff_t * | in, | ||
size_t | len, | ||
bool const | allowed[static UINT8_MAX+1] | ||
) |
Copy as many allowed characters as possible from a sbuff to a sbuff.
Copy size is limited by available data in sbuff and output buffer length.
As soon as a disallowed character is found the copy is stopped. The input sbuff will be left pointing at the first disallowed character.
[out] | out | Where to copy to. |
[in] | in | Where to copy from. Will copy len bytes from current position in buffer. |
[in] | len | How many bytes to copy. If SIZE_MAX the entire buffer will be copied. |
[in] | allowed | Characters to include the copy. |
ssize_t fr_sbuff_out_bstrncpy_exact | ( | fr_sbuff_t * | out, |
fr_sbuff_t * | in, | ||
size_t | len | ||
) |
Copy exactly len bytes from a sbuff to a sbuff or fail.
Copy size is limited by available data in sbuff, space in output sbuff, and length.
[out] | out | Where to copy to. |
[in] | in | Where to copy from. Will copy len bytes from current position in buffer. |
[in] | len | How many bytes to copy. If SIZE_MAX the entire buffer will be copied. |
Definition at line 738 of file sbuff.c.
size_t fr_sbuff_out_bstrncpy_until | ( | fr_sbuff_t * | out, |
fr_sbuff_t * | in, | ||
size_t | len, | ||
fr_sbuff_term_t const * | tt, | ||
fr_sbuff_unescape_rules_t const * | u_rules | ||
) |
Copy as many allowed characters as possible from a sbuff to a sbuff.
Copy size is limited by available data in sbuff and output buffer length.
As soon as a disallowed character is found the copy is stopped. The input sbuff will be left pointing at the first disallowed character.
[out] | out | Where to copy to. |
[in] | in | Where to copy from. Will copy len bytes from current position in buffer. |
[in] | len | How many bytes to copy. If SIZE_MAX the entire buffer will be copied. |
[in] | tt | Token terminals in the encompassing grammar. |
[in] | u_rules | If not NULL, ignore characters in the until set when prefixed with u_rules->chr. FIXME - Should actually evaluate u_rules fully. |
Definition at line 839 of file sbuff.c.
size_t fr_sbuff_out_unescape_until | ( | fr_sbuff_t * | out, |
fr_sbuff_t * | in, | ||
size_t | len, | ||
fr_sbuff_term_t const * | tt, | ||
fr_sbuff_unescape_rules_t const * | u_rules | ||
) |
Copy as many allowed characters as possible from a sbuff to a sbuff.
Copy size is limited by available data in sbuff and output buffer length.
As soon as a disallowed character is found the copy is stopped. The input sbuff will be left pointing at the first disallowed character.
This de-escapes characters as they're copied out of the sbuff.
[out] | out | Where to copy to. |
[in] | in | Where to copy from. Will copy len bytes from current position in buffer. |
[in] | len | How many bytes to copy. If SIZE_MAX the entire buffer will be copied. |
[in] | tt | Token terminal strings in the encompassing grammar. |
[in] | u_rules | for processing unescape sequences. |
Definition at line 912 of file sbuff.c.
void fr_sbuff_parse_rules_debug | ( | fr_sbuff_parse_rules_t const * | p_rules | ) |
int fr_sbuff_reset_talloc | ( | fr_sbuff_t * | sbuff | ) |
Reset a talloced buffer to its initial length, clearing any data stored.
[in] | sbuff | to reset. |
Definition at line 442 of file sbuff.c.
size_t fr_sbuff_shift | ( | fr_sbuff_t * | sbuff, |
size_t | shift | ||
) |
Shift the contents of the sbuff, returning the number of bytes we managed to shift.
[in] | sbuff | to shift. |
[in] | shift | the contents of the buffer this many bytes towards the start of the buffer. |
Definition at line 195 of file sbuff.c.
void fr_sbuff_terminal_debug | ( | fr_sbuff_term_t const * | tt | ) |
|
inlinestatic |
|
inlinestatic |
Efficient terminal string search.
Caller should ensure that a buffer extension of needle_len bytes has been requested before calling this function.
[in] | in | Sbuff to search in. |
[in] | p | Current position (may be ahead of in->p). |
[in] | idx | Fastpath index, populated by fr_sbuff_terminal_idx_init. |
[in] | term | terminals to search in. |
[in] | needle_len | Length of the longest needle. |
Definition at line 528 of file sbuff.c.
fr_sbuff_term_t* fr_sbuff_terminals_amerge | ( | TALLOC_CTX * | ctx, |
fr_sbuff_term_t const * | a, | ||
fr_sbuff_term_t const * | b | ||
) |
Merge two sets of terminal strings.
[in] | ctx | to allocate the new terminal array in. |
[in] | a | first set of terminals to merge. |
[in] | b | second set of terminals to merge. |
Definition at line 622 of file sbuff.c.
size_t fr_sbuff_trim | ( | fr_sbuff_t * | sbuff, |
bool const | to_trim[static UINT8_MAX+1] | ||
) |
int fr_sbuff_trim_talloc | ( | fr_sbuff_t * | sbuff, |
size_t | len | ||
) |
Trim a talloced sbuff to the minimum length required to represent the contained string.
[in] | sbuff | to trim. |
[in] | len | Length to trim to. Passing SIZE_MAX will result in the buffer being trimmed to the length of the content. |
Definition at line 407 of file sbuff.c.
void fr_sbuff_unescape_debug | ( | fr_sbuff_unescape_rules_t const * | escapes | ) |
void fr_sbuff_update | ( | fr_sbuff_t * | sbuff, |
char * | new_buff, | ||
size_t | new_len | ||
) |
Update all markers and pointers in the set of sbuffs to point to new_buff.
This function should be used if the underlying buffer is realloced.
[in] | sbuff | to update. |
[in] | new_buff | to assign to to sbuff. |
[in] | new_len | Length of the new buffer. |
Definition at line 156 of file sbuff.c.
|
inlinestatic |
Copy function that allows overlapping memory ranges to be copied.
[out] | o_start | start of output buffer. |
[in] | o_end | end of the output buffer. |
[in] | i_start | start of the input buffer. |
[in] | i_end | end of data to copy. |
Definition at line 123 of file sbuff.c.
|
static |
|
inlinestatic |
|
inlinestatic |
bool const sbuff_char_alpha_num[UINT8_MAX+1] = { SBUFF_CHAR_CLASS_ALPHA_NUM } |
bool const sbuff_char_class_hex[UINT8_MAX+1] = { SBUFF_CHAR_CLASS_HEX } |
fr_table_num_ordered_t const sbuff_parse_error_table[] |
size_t sbuff_parse_error_table_len = NUM_ELEMENTS(sbuff_parse_error_table) |
|
static |