The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Functions | Variables
sbuff.c File Reference

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>
+ Include dependency graph for sbuff.c:

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_tfr_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
 

Detailed Description

A generic string buffer structure for string printing and parsing.

Definition in file sbuff.c.

Macro Definition Documentation

◆ CHECK_SBUFF_INIT

#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)

Definition at line 47 of file sbuff.c.

◆ CONSTRAINED_END

#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.

Parameters
[in]_sbuffto constrain.
[in]_maxmaximum amount to advance.
[in]_usedhow much we've advanced so far.
Returns
a temporary end pointer.

Definition at line 473 of file sbuff.c.

◆ FILL_OR_GOTO_DONE

#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.

Parameters
[in]_outsbuff to write to.
[in]_insbuff to copy from.
[in]_lenmaximum amount to copy.

Definition at line 464 of file sbuff.c.

◆ SBUFF_PARSE_FLOAT_DEF

#define SBUFF_PARSE_FLOAT_DEF (   _name,
  _type,
  _func,
  _max_char 
)

Used to define a number parsing functions for floats.

Parameters
[in]_nameFunction suffix.
[in]_typeOutput type.
[in]_funcParsing function to use.
[in]_max_charMaximum digits that can be used to represent an integer. Can't use stringify because of width modifiers like 'u' used in <stdint.h>.

Definition at line 1289 of file sbuff.c.

◆ SBUFF_PARSE_INT_DEF

#define SBUFF_PARSE_INT_DEF (   _name,
  _type,
  _min,
  _max,
  _max_char,
  _base 
)

Used to define a number parsing functions for signed integers.

Parameters
[in]_nameFunction suffix.
[in]_typeOutput type.
[in]_minvalue.
[in]_maxvalue.
[in]_max_charMaximum digits that can be used to represent an integer. Can't use stringify because of width modifiers like 'u' used in <stdint.h>.
[in]_baseto use.

Definition at line 1138 of file sbuff.c.

◆ SBUFF_PARSE_UINT_DEF

#define SBUFF_PARSE_UINT_DEF (   _name,
  _type,
  _max,
  _max_char,
  _base 
)

Used to define a number parsing functions for signed integers.

Parameters
[in]_nameFunction suffix.
[in]_typeOutput type.
[in]_maxvalue.
[in]_max_charMaximum digits that can be used to represent an integer. Can't use stringify because of width modifiers like 'u' used in <stdint.h>.
[in]_baseof the number being parsed, 8, 10, 16 etc...

Definition at line 1205 of file sbuff.c.

Function Documentation

◆ _fr_sbuff_move_marker_to_marker()

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.

Note
Do not call this function directly use fr_sbuff_move
Parameters
[in]outmarker to copy data to.
[in]inmarker to copy data from.
[in]lenMaximum length of string to copy.
Returns
The amount of data copied.

Definition at line 1380 of file sbuff.c.

+ Here is the call graph for this function:

◆ _fr_sbuff_move_marker_to_sbuff()

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.

Note
Do not call this function directly use fr_sbuff_move
Parameters
[in]outsbuff to copy data to.
[in]inmarker to copy data from.
[in]lenMaximum length of string to copy.
Returns
The amount of data copied.

Definition at line 1360 of file sbuff.c.

+ Here is the call graph for this function:

◆ _fr_sbuff_move_sbuff_to_marker()

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.

Note
Do not call this function directly use fr_sbuff_move
Parameters
[in]outmarker to copy data to.
[in]insbuff to copy data from.
[in]lenMaximum length of string to copy.
Returns
The amount of data copied.

Definition at line 1400 of file sbuff.c.

+ Here is the call graph for this function:

◆ _fr_sbuff_move_sbuff_to_sbuff()

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.

Note
Do not call this function directly use fr_sbuff_move

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).

Parameters
[in]outsbuff to copy data to.
[in]insbuff to copy data from.
[in]lenMaximum length of string to copy.
Returns
The amount of data copied.

Definition at line 1340 of file sbuff.c.

+ Here is the call graph for this function:

◆ _sbuff_scratch_free()

static int _sbuff_scratch_free ( void *  arg)
static

Free the scratch buffer used for printf.

Definition at line 1488 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sbuff_adv_past_allowed()

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.

Parameters
[in]sbuffsbuff to search in.
[in]lenMaximum amount to advance by. Unconstrained if SIZE_MAX.
[in]allowedcharacter set.
[in]ttIf not NULL, stop if we find a terminal sequence.
Returns
how many bytes we advanced.

Definition at line 1736 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sbuff_adv_past_str()

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.

Parameters
[in]sbuffto search in.
[in]needleto search for.
[in]needle_lenof needle. If SIZE_MAX strlen is used to determine length of the needle.
Returns
how many bytes we advanced

Definition at line 1671 of file sbuff.c.

+ Here is the caller graph for this function:

◆ fr_sbuff_adv_past_strcase()

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.

Parameters
[in]sbuffto search in.
[in]needleto search for.
[in]needle_lenof needle. If SIZE_MAX strlen is used to determine length of the needle.
Returns
how many bytes we advanced

Definition at line 1702 of file sbuff.c.

+ Here is the caller graph for this function:

◆ fr_sbuff_adv_to_chr()

char* fr_sbuff_adv_to_chr ( fr_sbuff_t sbuff,
size_t  len,
char  c 
)

Wind position to first instance of specified char.

Parameters
[in,out]sbuffto search in.
[in]lenMaximum amount to advance by. Unconstrained if SIZE_MAX.
[in]cto search for.
Returns
  • NULL, no instances found.
  • The position of the first character.

Definition at line 1915 of file sbuff.c.

+ Here is the caller graph for this function:

◆ fr_sbuff_adv_to_chr_utf8()

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.

Parameters
[in,out]sbuffto search in.
[in]lenthe maximum number of characters to search in sbuff.
[in]chrto search for.
Returns
  • NULL, no instances found.
  • The position of the first character.

Definition at line 1870 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sbuff_adv_to_str()

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.

Parameters
[in,out]sbuffsbuff to search in.
[in]lenMaximum amount to advance by. Unconstrained if SIZE_MAX.
[in]needleto search for.
[in]needle_lenLength of the needle. SIZE_MAX to used strlen.
Returns
  • NULL, no instances found.
  • The position of the first character.

Definition at line 1951 of file sbuff.c.

+ Here is the caller graph for this function:

◆ fr_sbuff_adv_to_strcase()

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.

Parameters
[in,out]sbuffsbuff to search in.
[in]lenMaximum amount to advance by. Unconstrained if SIZE_MAX.
[in]needleto search for.
[in]needle_lenLength of the needle. SIZE_MAX to used strlen.
Returns
  • NULL, no instances found.
  • The position of the first character.

Definition at line 2004 of file sbuff.c.

+ Here is the caller graph for this function:

◆ fr_sbuff_adv_until()

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.

Parameters
[in]sbuffsbuff to search in.
[in]lenMaximum amount to advance by. Unconstrained if SIZE_MAX.
[in]ttToken terminals in the encompassing grammar.
[in]escape_chrIf not '\0', ignore characters in the tt set when prefixed with this escape character.
Returns
how many bytes we advanced.

Definition at line 1811 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sbuff_extend_file()

size_t fr_sbuff_extend_file ( fr_sbuff_t sbuff,
size_t  extension 
)

Refresh the buffer with more data from the file.

Check for errors

Definition at line 257 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sbuff_extend_talloc()

size_t fr_sbuff_extend_talloc ( fr_sbuff_t sbuff,
size_t  extension 
)

Reallocate the current buffer.

Parameters
[in]sbuffto be extended.
[in]extensionHow many additional bytes should be allocated in the buffer.
Returns
  • 0 the extension operation failed.
  • >0 the number of bytes the buffer was extended by.

Definition at line 336 of file sbuff.c.

+ Here is the call graph for this function:

◆ fr_sbuff_in_bstrcpy_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.

Parameters
[in]sbuffto copy into.
[in]strtalloced buffer to copy into sbuff.
Returns
  • >= 0 the number of bytes copied into the sbuff.
  • <0 the number of bytes required to complete the copy operation.

Definition at line 1467 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sbuff_in_bstrncpy()

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.

Parameters
[in]sbuffto copy into.
[in]strto copy into buffer.
[in]lennumber of bytes to copy.
Returns
  • >= 0 the number of bytes copied into the sbuff.
  • <0 the number of bytes required to complete the copy operation.

Definition at line 1445 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sbuff_in_escape()

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.

Parameters
[in]sbuffto print into.
[in]into escape.
[in]inlenof string to escape.
[in]e_rulesEscaping rules. Used to escape special characters as data is written to the sbuff. May be NULL.
Returns
  • >= 0 the number of bytes printed into the sbuff.
  • <0 the number of bytes required to complete the print operation.

Definition at line 1579 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sbuff_in_escape_buffer()

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.

Parameters
[in]sbuffto print into.
[in]into escape.
[in]e_rulesEscaping rules. Used to escape special characters as data is written to the sbuff. May be NULL.
Returns
  • >= 0 the number of bytes printed into the sbuff.
  • <0 the number of bytes required to complete the print operation.

Definition at line 1654 of file sbuff.c.

+ Here is the call graph for this function:

◆ fr_sbuff_in_sprintf()

ssize_t fr_sbuff_in_sprintf ( fr_sbuff_t sbuff,
char const *  fmt,
  ... 
)

Print using a fmt string to an sbuff.

Parameters
[in]sbuffto print into.
[in]fmtstring.
[in]...arguments for format string.
Returns
  • >= 0 the number of bytes printed into the sbuff.
  • <0 the number of bytes required to complete the print operation.

Definition at line 1554 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sbuff_in_strcpy()

ssize_t fr_sbuff_in_strcpy ( fr_sbuff_t sbuff,
char const *  str 
)

Copy bytes into the sbuff up to the first \0.

Parameters
[in]sbuffto copy into.
[in]strto copy into buffer.
Returns
  • >= 0 the number of bytes copied into the sbuff.
  • <0 the number of bytes required to complete the copy operation.

Definition at line 1419 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sbuff_in_vsprintf()

ssize_t fr_sbuff_in_vsprintf ( fr_sbuff_t sbuff,
char const *  fmt,
va_list  ap 
)

Print using a fmt string to an sbuff.

Parameters
[in]sbuffto print into.
[in]fmtstring.
[in]aparguments for format string.
Returns
  • >= 0 the number of bytes printed into the sbuff.
  • <0 the number of bytes required to complete the print operation.

Definition at line 1521 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sbuff_is_terminal()

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.

Parameters
[in]inSbuff to search in.
[in]ttToken terminals in the encompassing grammar.
Returns
  • true if found.
  • false if not.

Definition at line 2111 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sbuff_next_if_char()

bool fr_sbuff_next_if_char ( fr_sbuff_t sbuff,
char  c 
)

Return true if the current char matches, and if it does, advance.

Parameters
[in]sbuffto search for char in.
[in]cchar to search for.
Returns
  • true and advance if the next character matches.
  • false and don't advance if the next character doesn't match.

Definition at line 2047 of file sbuff.c.

+ Here is the caller graph for this function:

◆ fr_sbuff_next_unless_char()

bool fr_sbuff_next_unless_char ( fr_sbuff_t sbuff,
char  c 
)

Return true and advance if the next char does not match.

Parameters
[in]sbuffto search for char in.
[in]cchar to search for.
Returns
  • true and advance unless the character matches.
  • false and don't advance if the next character matches.

Definition at line 2068 of file sbuff.c.

+ Here is the caller graph for this function:

◆ fr_sbuff_out_bool()

fr_slen_t fr_sbuff_out_bool ( bool out,
fr_sbuff_t in 
)

See if the string contains a truth value.

Parameters
[out]outWhere to write boolean value.
[in]inWhere to search for a truth value.
Returns
  • >0 the number of bytes consumed.
  • -1 no bytes copied, was not a truth value.

Definition at line 1074 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sbuff_out_bstrncpy()

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.

Parameters
[out]outWhere to copy to.
[in]inWhere to copy from. Will copy len bytes from current position in buffer.
[in]lenHow many bytes to copy. If SIZE_MAX the entire buffer will be copied.
Returns
  • 0 no bytes copied.
  • >0 the number of bytes copied.

Definition at line 691 of file sbuff.c.

+ Here is the caller graph for this function:

◆ fr_sbuff_out_bstrncpy_allowed()

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.

Parameters
[out]outWhere to copy to.
[in]inWhere to copy from. Will copy len bytes from current position in buffer.
[in]lenHow many bytes to copy. If SIZE_MAX the entire buffer will be copied.
[in]allowedCharacters to include the copy.
Returns
  • 0 no bytes copied.
  • >0 the number of bytes copied.

Definition at line 780 of file sbuff.c.

◆ fr_sbuff_out_bstrncpy_exact()

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.

Parameters
[out]outWhere to copy to.
[in]inWhere to copy from. Will copy len bytes from current position in buffer.
[in]lenHow many bytes to copy. If SIZE_MAX the entire buffer will be copied.
Returns
  • 0 no bytes copied, no token found of sufficient length in input buffer.
  • >0 the number of bytes copied.
  • <0 the number of additional output bytes we would have needed to complete the copy.

Definition at line 729 of file sbuff.c.

+ Here is the call graph for this function:

◆ fr_sbuff_out_bstrncpy_until()

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.

Parameters
[out]outWhere to copy to.
[in]inWhere to copy from. Will copy len bytes from current position in buffer.
[in]lenHow many bytes to copy. If SIZE_MAX the entire buffer will be copied.
[in]ttToken terminals in the encompassing grammar.
[in]u_rulesIf not NULL, ignore characters in the until set when prefixed with u_rules->chr. FIXME - Should actually evaluate u_rules fully.
Returns
  • 0 no bytes copied.
  • >0 the number of bytes copied.

Definition at line 826 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sbuff_out_unescape_until()

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.

Parameters
[out]outWhere to copy to.
[in]inWhere to copy from. Will copy len bytes from current position in buffer.
[in]lenHow many bytes to copy. If SIZE_MAX the entire buffer will be copied.
[in]ttToken terminal strings in the encompassing grammar.
[in]u_rulesfor processing unescape sequences.
Returns
  • 0 no bytes copied.
  • >0 the number of bytes written to out.

Definition at line 899 of file sbuff.c.

+ Here is the call graph for this function:

◆ fr_sbuff_parse_rules_debug()

void fr_sbuff_parse_rules_debug ( fr_sbuff_parse_rules_t const *  p_rules)

Definition at line 2218 of file sbuff.c.

+ Here is the call graph for this function:

◆ fr_sbuff_reset_talloc()

int fr_sbuff_reset_talloc ( fr_sbuff_t sbuff)

Reset a talloced buffer to its initial length, clearing any data stored.

Parameters
[in]sbuffto reset.
Returns
  • 0 on success.
  • -1 on failure - markers present pointing past the end of string data.

Definition at line 434 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sbuff_shift()

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.

Parameters
[in]sbuffto shift.
[in]shiftthe contents of the buffer this many bytes towards the start of the buffer.
Returns
  • 0 the shift failed due to constraining pointers.
  • >0 the number of bytes we managed to shift pointers in the sbuff. memmove should be used to move the existing contents of the buffer, and fill the free space at the end of the buffer with additional data.

Definition at line 187 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sbuff_terminal_debug()

void fr_sbuff_terminal_debug ( fr_sbuff_term_t const *  tt)

Definition at line 2209 of file sbuff.c.

+ Here is the caller graph for this function:

◆ fr_sbuff_terminal_idx_init()

static void fr_sbuff_terminal_idx_init ( size_t needle_len,
uint8_t  idx[static UINT8_MAX+1],
fr_sbuff_term_t const *  term 
)
inlinestatic

Populate a terminal index.

Parameters
[out]needle_lenthe longest needle. Will not be set if the terminal array is empty.
[out]idxto populate.
[in]termTerminals to populate the index with.

Definition at line 484 of file sbuff.c.

+ Here is the caller graph for this function:

◆ fr_sbuff_terminal_search()

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 
)
inlinestatic

Efficient terminal string search.

Caller should ensure that a buffer extension of needle_len bytes has been requested before calling this function.

Parameters
[in]inSbuff to search in.
[in]pCurrent position (may be ahead of in->p).
[in]idxFastpath index, populated by fr_sbuff_terminal_idx_init.
[in]termterminals to search in.
[in]needle_lenLength of the longest needle.
Returns
  • true if found.
  • false if not.

Definition at line 519 of file sbuff.c.

+ Here is the caller graph for this function:

◆ fr_sbuff_terminals_amerge()

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.

Parameters
[in]ctxto allocate the new terminal array in.
[in]afirst set of terminals to merge.
[in]bsecond set of terminals to merge.
Returns
A new set of de-duplicated and sorted terminals.

Definition at line 613 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sbuff_trim()

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.

Parameters
[in]sbuffto trim trailing characters from.
[in]to_trimCharset to trim.
Returns
how many chars we removed.

Definition at line 2087 of file sbuff.c.

+ Here is the caller graph for this function:

◆ fr_sbuff_trim_talloc()

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.

Parameters
[in]sbuffto trim.
[in]lenLength to trim to. Passing SIZE_MAX will result in the buffer being trimmed to the length of the content.
Returns
  • 0 on success.
  • -1 on failure - markers present pointing past the end of string data.

Definition at line 399 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sbuff_unescape_debug()

void fr_sbuff_unescape_debug ( fr_sbuff_unescape_rules_t const *  escapes)

Definition at line 2188 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_sbuff_update()

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.

Parameters
[in]sbuffto update.
[in]new_buffto assign to to sbuff.
[in]new_lenLength of the new buffer.

Definition at line 148 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ min()

static size_t min ( size_t  x,
size_t  y 
)
inlinestatic

Definition at line 135 of file sbuff.c.

+ Here is the caller graph for this function:

◆ safecpy()

static ssize_t safecpy ( char *  o_start,
char *  o_end,
char const *  i_start,
char const *  i_end 
)
inlinestatic

Copy function that allows overlapping memory ranges to be copied.

Parameters
[out]o_startstart of output buffer.
[in]o_endend of the output buffer.
[in]i_startstart of the input buffer.
[in]i_endend of data to copy.
Returns
  • >0 the number of bytes copied.
  • 0 invalid args.
  • <0 the number of bytes we'd need to complete the copy.

Definition at line 115 of file sbuff.c.

+ Here is the caller graph for this function:

◆ sbuff_print_char()

static char const* sbuff_print_char ( char  c)
static

Print a char in a friendly format.

Definition at line 2142 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sbuff_scratch_init()

static int sbuff_scratch_init ( TALLOC_CTX **  out)
inlinestatic

Definition at line 1493 of file sbuff.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ terminal_cmp()

static int8_t terminal_cmp ( fr_sbuff_term_elem_t const *  a,
fr_sbuff_term_elem_t const *  b 
)
inlinestatic

Compare two terminal elements for ordering purposes.

Parameters
[in]afirst terminal to compare.
[in]bsecond terminal to compare.
Returns
CMP(a,b)

Definition at line 589 of file sbuff.c.

+ Here is the caller graph for this function:

Variable Documentation

◆ sbuff_char_alpha_num

bool const sbuff_char_alpha_num[UINT8_MAX+1] = { SBUFF_CHAR_CLASS_ALPHA_NUM }

Definition at line 87 of file sbuff.c.

◆ sbuff_char_blank

bool const sbuff_char_blank[UINT8_MAX+1]
Initial value:
= {
['\t'] = true, [' '] = true,
}

Definition at line 100 of file sbuff.c.

◆ sbuff_char_class_float

bool const sbuff_char_class_float[UINT8_MAX+1]
Initial value:
= {
['-'] = true, ['+'] = true, ['e'] = true, ['E'] = true, ['.'] = true,
}
#define SBUFF_CHAR_CLASS_NUM

Definition at line 62 of file sbuff.c.

◆ sbuff_char_class_hex

bool const sbuff_char_class_hex[UINT8_MAX+1] = { SBUFF_CHAR_CLASS_HEX }

Definition at line 86 of file sbuff.c.

◆ sbuff_char_class_hostname

bool const sbuff_char_class_hostname[UINT8_MAX+1]
Initial value:
= {
['.'] = true,
[':'] = true,
['-'] = true,
['/'] = true,
['['] = true,
[']'] = true,
['_'] = true,
['*'] = true,
}
#define SBUFF_CHAR_CLASS_ALPHA_NUM

Definition at line 74 of file sbuff.c.

◆ sbuff_char_class_int

bool const sbuff_char_class_int[UINT8_MAX+1]
Initial value:
= {
['+'] = true, ['-'] = true
}

Definition at line 57 of file sbuff.c.

◆ sbuff_char_class_uint

bool const sbuff_char_class_uint[UINT8_MAX+1]
Initial value:
= {
['+'] = true
}

Definition at line 52 of file sbuff.c.

◆ sbuff_char_class_zero

bool const sbuff_char_class_zero[UINT8_MAX+1]
Initial value:
= {
['0'] = true
}

Definition at line 67 of file sbuff.c.

◆ sbuff_char_line_endings

bool const sbuff_char_line_endings[UINT8_MAX+1]
Initial value:
= {
['\n'] = true, ['\r'] = true
}

Definition at line 96 of file sbuff.c.

◆ sbuff_char_whitespace

bool const sbuff_char_whitespace[UINT8_MAX+1]
Initial value:
= {
['\t'] = true, ['\n'] = true, ['\r'] = true, ['\f'] = true, ['\v'] = true, [' '] = true,
}

Definition at line 92 of file sbuff.c.

◆ sbuff_char_word

bool const sbuff_char_word[UINT8_MAX+1]
Initial value:
= {
['-'] = true, ['_'] = true,
}

Definition at line 88 of file sbuff.c.

◆ sbuff_parse_error_table

fr_table_num_ordered_t const sbuff_parse_error_table[]
Initial value:
= {
{ L("ok"), FR_SBUFF_PARSE_OK },
{ L("token not found"), FR_SBUFF_PARSE_ERROR_NOT_FOUND },
{ L("trailing data"), FR_SBUFF_PARSE_ERROR_TRAILING },
{ L("token format invalid"), FR_SBUFF_PARSE_ERROR_FORMAT },
{ L("out of space"), FR_SBUFF_PARSE_ERROR_OUT_OF_SPACE },
{ L("integer overflow"), FR_SBUFF_PARSE_ERROR_NUM_OVERFLOW },
{ L("integer underflow"), FR_SBUFF_PARSE_ERROR_NUM_UNDERFLOW }
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207
@ FR_SBUFF_PARSE_ERROR_NUM_OVERFLOW
Integer type would overflow.
Definition: merged_model.c:52
@ FR_SBUFF_PARSE_ERROR_NUM_UNDERFLOW
Integer type would underflow.
Definition: merged_model.c:53
@ FR_SBUFF_PARSE_ERROR_NOT_FOUND
String does not contain a token matching the output type.
Definition: merged_model.c:47
@ FR_SBUFF_PARSE_ERROR_FORMAT
Format of data was invalid.
Definition: merged_model.c:50
@ FR_SBUFF_PARSE_OK
No error.
Definition: merged_model.c:46
@ FR_SBUFF_PARSE_ERROR_OUT_OF_SPACE
No space available in output buffer.
Definition: merged_model.c:51
@ FR_SBUFF_PARSE_ERROR_TRAILING
Trailing characters found.
Definition: merged_model.c:49

Definition at line 35 of file sbuff.c.

◆ sbuff_parse_error_table_len

size_t sbuff_parse_error_table_len = NUM_ELEMENTS(sbuff_parse_error_table)

Definition at line 44 of file sbuff.c.

◆ sbuff_scratch

_Thread_local char* sbuff_scratch
static

Definition at line 30 of file sbuff.c.