The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Functions
ext.c File Reference

'compositing' using talloced structures More...

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

Go to the source code of this file.

Functions

void * fr_ext_alloc_size (fr_ext_t const *def, void **chunk_p, int ext, size_t ext_len)
 Add a variable length extension to a talloc chunk. More...
 
void * fr_ext_copy (fr_ext_t const *def, TALLOC_CTX **chunk_dst, TALLOC_CTX const *chunk_src, int ext)
 Copy extension data from one attribute to another. More...
 
int fr_ext_copy_all (fr_ext_t const *def, TALLOC_CTX **chunk_dst, TALLOC_CTX const *chunk_src)
 Copy all the extensions from one attribute to another. More...
 
void fr_ext_debug (fr_ext_t const *def, char const *name, void const *chunk)
 Print out all extensions and hexdump their contents. More...
 
size_t fr_ext_len (fr_ext_t const *def, TALLOC_CTX const *chunk, int ext)
 Return the length of an extension. More...
 

Detailed Description

'compositing' using talloced structures

Definition in file ext.c.

Function Documentation

◆ fr_ext_alloc_size()

void* fr_ext_alloc_size ( fr_ext_t const *  def,
void **  chunk_p,
int  ext,
size_t  ext_len 
)

Add a variable length extension to a talloc chunk.

This is used to build a structure from a primary struct type and one or more extension structures. The memory for the composed structure is contiguous which has performance benefits, and means we don't have the overhead of talloc headers for each of the extensions.

Note
When a new extension is allocated its memory will be zeroed.
It is highly recommended to allocate composed structures within a talloc_pool to avoid the overhead of malloc+memcpy.
Parameters
[in]defExtension definitions.
[in,out]chunk_pThe chunk to add an extension for. Under certain circumstances the value of *chunk_p will be changed to point to a new memory block. All cached copies of the previous pointer should be updated.
[in]extto alloc.
[in]ext_lenThe length of the extension.
Returns
  • NULL if we failed allocating an extension.
  • A pointer to the extension we allocated.

Definition at line 55 of file ext.c.

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

◆ fr_ext_copy()

void* fr_ext_copy ( fr_ext_t const *  def,
TALLOC_CTX **  chunk_dst,
TALLOC_CTX const *  chunk_src,
int  ext 
)

Copy extension data from one attribute to another.

Parameters
[in]defExtension definitions.
[in,out]chunk_dstto copy extension to. Under certain circumstances the value of *chunk_dst will be changed to point to a new memory block. All cached copies of the previous pointer should be updated.
[in]chunk_srcto copy extension from.
[in]extto copy.
Returns
  • NULL if we failed to allocate an extension structure.
  • A pointer to the offset of the extension in da_out.

Definition at line 160 of file ext.c.

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

◆ fr_ext_copy_all()

int fr_ext_copy_all ( fr_ext_t const *  def,
TALLOC_CTX **  chunk_dst,
TALLOC_CTX const *  chunk_src 
)

Copy all the extensions from one attribute to another.

Parameters
[in]defExtension definitions.
[in,out]chunk_dstto copy extensions to. Under certain circumstances the value of *chunk_dst will be changed to point to a new memory block. All cached copies of the previous pointer should be updated.
[in]chunk_srcto copy extensions from.
Returns
  • 0 on success.
  • -1 if a copy operation failed.

Definition at line 245 of file ext.c.

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

◆ fr_ext_debug()

void fr_ext_debug ( fr_ext_t const *  def,
char const *  name,
void const *  chunk 
)

Print out all extensions and hexdump their contents.

This function is intended to be called from interactive debugging sessions only. It does not use the normal logging infrastructure.

Parameters
[in]defExtension definitions.
[in]namethe identifier of the structure being debugged i.e da->name.
[in]chunkto debug.

Definition at line 336 of file ext.c.

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

◆ fr_ext_len()

size_t fr_ext_len ( fr_ext_t const *  def,
TALLOC_CTX const *  chunk,
int  ext 
)

Return the length of an extension.

Parameters
[in]defExtension definitions.
[in]chunkto return extension length for.
[in]extto return length for.
Returns
  • 0 if no extension exists or is of zero length.
  • >0 the length of the extension.

Definition at line 128 of file ext.c.

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