![]() |
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. | |
#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. | |
#define | SBUFF_PARSE_FLOAT_DEF(_name, _type, _func, _max_char) |
Used to define a number parsing functions for floats. | |
#define | SBUFF_PARSE_INT_DEF(_name, _type, _min, _max, _max_char, _base) |
Used to define a number parsing functions for signed integers. | |
#define | SBUFF_PARSE_UINT_DEF(_name, _type, _max, _max_char, _base) |
Used to define a number parsing functions for signed integers. | |
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. | |
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. | |
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. | |
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. | |
static int | _sbuff_scratch_free (void *arg) |
Free the scratch buffer used for printf. | |
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. | |
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. | |
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. | |
char * | fr_sbuff_adv_to_chr (fr_sbuff_t *sbuff, size_t len, char c) |
Wind position to first instance of specified char. | |
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. | |
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. | |
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. | |
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. | |
bool | fr_sbuff_eof_file (fr_sbuff_t *sbuff) |
Accessor function for the EOF state of the file extendor. | |
size_t | fr_sbuff_extend_file (fr_sbuff_extend_status_t *status, fr_sbuff_t *sbuff, size_t extension) |
Refresh the buffer with more data from the file. | |
size_t | fr_sbuff_extend_talloc (fr_sbuff_extend_status_t *status, fr_sbuff_t *sbuff, size_t extension) |
Reallocate the current buffer. | |
ssize_t | fr_sbuff_in_bstrcpy_buffer (fr_sbuff_t *sbuff, char const *str) |
Copy bytes into the sbuff up to the first \0. | |
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. | |
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. | |
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. | |
ssize_t | fr_sbuff_in_sprintf (fr_sbuff_t *sbuff, char const *fmt,...) |
Print using a fmt string to an sbuff. | |
ssize_t | fr_sbuff_in_strcpy (fr_sbuff_t *sbuff, char const *str) |
Copy bytes into the sbuff up to the first \0. | |
ssize_t | fr_sbuff_in_vsprintf (fr_sbuff_t *sbuff, char const *fmt, va_list ap) |
Print using a fmt string to an sbuff. | |
bool | fr_sbuff_is_terminal (fr_sbuff_t *in, fr_sbuff_term_t const *tt) |
Efficient terminal string search. | |
bool | fr_sbuff_next_if_char (fr_sbuff_t *sbuff, char c) |
Return true if the current char matches, and if it does, advance. | |
bool | fr_sbuff_next_unless_char (fr_sbuff_t *sbuff, char c) |
Return true and advance if the next char does not match. | |
fr_slen_t | fr_sbuff_out_bool (bool *out, fr_sbuff_t *in) |
See if the string contains a truth value. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
size_t | fr_sbuff_shift (fr_sbuff_t *sbuff, size_t shift, bool move_end) |
Shift the contents of the sbuff, returning the number of bytes we managed to shift. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
static char const * | sbuff_print_char (char c) |
Print a char in a friendly format. | |
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. | |
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. | |
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 1417 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 1397 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 1437 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 1377 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 1779 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 1714 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 1745 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 1958 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 1913 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 1994 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 2047 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 1854 of file sbuff.c.
bool fr_sbuff_eof_file | ( | fr_sbuff_t * | sbuff | ) |
size_t fr_sbuff_extend_file | ( | fr_sbuff_extend_status_t * | status, |
fr_sbuff_t * | sbuff, | ||
size_t | extension | ||
) |
size_t fr_sbuff_extend_talloc | ( | fr_sbuff_extend_status_t * | status, |
fr_sbuff_t * | sbuff, | ||
size_t | extension | ||
) |
Reallocate the current buffer.
[in] | status | Extend status. |
[in] | sbuff | to be extended. |
[in] | extension | How many additional bytes should be allocated in the buffer. |
Definition at line 357 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 1504 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 1482 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 1622 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 1697 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 1597 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 1456 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 1564 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 2154 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 2090 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 2111 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 1111 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 725 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 763 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 864 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 937 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 456 of file sbuff.c.
size_t fr_sbuff_shift | ( | fr_sbuff_t * | sbuff, |
size_t | shift, | ||
bool | move_end | ||
) |
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. |
[in] | move_end | If the buffer is used for reading, then this should be true so we cannot read passed the end of valid data. |
Definition at line 197 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 542 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 647 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 421 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 |