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

A generic data buffer structure for encoding and decoding. More...

#include <freeradius-devel/util/dbuff.h>
#include <freeradius-devel/util/syserror.h>
+ Include dependency graph for dbuff.c:

Go to the source code of this file.

Macros

#define CHECK_DBUFF_INIT(_sbuff)   do { if (!(_sbuff)->extend && (unlikely(!(_sbuff)->buff) || unlikely(!(_sbuff)->start) || unlikely(!(_sbuff)->end) || unlikely(!(_sbuff)->p))) return 0; } while (0)
 
#define FR_DBUFF_MOVE_DEF(_out_type, _in_type)
 

Functions

size_t _fr_dbuff_extend_fd (fr_dbuff_t *dbuff, size_t extension)
 Refresh the buffer with more data from the file. More...
 
int fr_dbuff_reset_talloc (fr_dbuff_t *dbuff)
 Reset a talloced buffer to its initial length, clearing any data stored. More...
 
size_t fr_dbuff_shift (fr_dbuff_t *dbuff, size_t shift)
 Shift the contents of the dbuff, returning the number of bytes we managed to shift. More...
 
int fr_dbuff_trim_talloc (fr_dbuff_t *dbuff, size_t len)
 Trim a talloced dbuff to the minimum length required to represent the contained string. More...
 
void fr_dbuff_update (fr_dbuff_t *dbuff, uint8_t *new_buff, size_t new_len)
 Update all markers and pointers in the set of dbuffs to point to new_buff. More...
 

Variables

size_t y
 

Detailed Description

A generic data buffer structure for encoding and decoding.

Because doing manual length checks is error prone and a waste of everyone's time.

Definition in file dbuff.c.

Macro Definition Documentation

◆ CHECK_DBUFF_INIT

#define CHECK_DBUFF_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 32 of file dbuff.c.

◆ FR_DBUFF_MOVE_DEF

#define FR_DBUFF_MOVE_DEF (   _out_type,
  _in_type 
)
Value:
size_t _fr_dbuff_move_##_in_type##_to_##_out_type(fr_##_out_type##_t *out, fr_##_in_type##_t *in, size_t len) \
{ \
size_t ext_len, to_copy, remaining = len; \
while (remaining > 0) { \
to_copy = remaining; \
ext_len = fr_dbuff_extend_lowat(NULL, in, to_copy); \
if (ext_len < to_copy) to_copy = ext_len; \
ext_len = fr_dbuff_extend_lowat(NULL, out, to_copy); \
if (ext_len < to_copy) to_copy = ext_len; \
if (to_copy == 0) break; \
to_copy = _fr_dbuff_safecpy(fr_dbuff_current(out), fr_dbuff_end(out), \
fr_dbuff_advance(out, (size_t)fr_dbuff_advance(in, to_copy)); \
remaining -= to_copy; \
} \
return len - remaining; \
}
#define fr_dbuff_advance(_dbuff_or_marker, _len)
Advance 'current' position in dbuff or marker by _len bytes.
Definition: dbuff.h:1067
#define fr_dbuff_current(_dbuff_or_marker)
Return the 'current' position of a dbuff or marker.
Definition: dbuff.h:906
#define fr_dbuff_extend_lowat(_status, _dbuff_or_marker, _lowat)
Extend if we're below _lowat.
Definition: dbuff.h:655
#define fr_dbuff_end(_dbuff_or_marker)
Return the current 'end' position of a dbuff or marker.
Definition: dbuff.h:933
static fr_slen_t in
Definition: dict.h:645
break
Definition: rlm_securid.c:421
return
Definition: module.c:186
static size_t char ** out
Definition: value.h:984

Function Documentation

◆ _fr_dbuff_extend_fd()

size_t _fr_dbuff_extend_fd ( fr_dbuff_t dbuff,
size_t  extension 
)

Refresh the buffer with more data from the file.

Check for errors

Definition at line 175 of file dbuff.c.

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

◆ fr_dbuff_reset_talloc()

int fr_dbuff_reset_talloc ( fr_dbuff_t dbuff)

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

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

Definition at line 332 of file dbuff.c.

+ Here is the call graph for this function:

◆ fr_dbuff_shift()

size_t fr_dbuff_shift ( fr_dbuff_t dbuff,
size_t  shift 
)

Shift the contents of the dbuff, returning the number of bytes we managed to shift.

Parameters
[in]dbuffto shift.
[in]shiftthe number of bytes to shift (not necessarily the amount actually shifted, because one can't move pointers outside the buffer)
Returns
  • 0 the shift failed due to constraining pointers.
  • >0 the number of bytes we managed to shift pointers in the dbuff.

Definition at line 116 of file dbuff.c.

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

◆ fr_dbuff_trim_talloc()

int fr_dbuff_trim_talloc ( fr_dbuff_t dbuff,
size_t  len 
)

Trim a talloced dbuff to the minimum length required to represent the contained string.

Parameters
[in]dbuffto 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 297 of file dbuff.c.

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

◆ fr_dbuff_update()

void fr_dbuff_update ( fr_dbuff_t dbuff,
uint8_t new_buff,
size_t  new_len 
)

Update all markers and pointers in the set of dbuffs to point to new_buff.

This function should be used if the underlying buffer is realloced.

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

Definition at line 79 of file dbuff.c.

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

Variable Documentation

◆ y

size_t y
Initial value:
{
return x < y ? x : y
size_t y
Definition: dbuff.c:67

Definition at line 66 of file dbuff.c.