suricata
util-buffer.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  MemBuffer_
 

Macros

#define MEMBUFFER_BUFFER(mem_buffer)   (mem_buffer)->buffer
 Get the MemBuffers underlying buffer. More...
 
#define MEMBUFFER_OFFSET(mem_buffer)   (mem_buffer)->offset
 Get the MemBuffers current offset. More...
 
#define MEMBUFFER_SIZE(mem_buffer)   (mem_buffer)->size
 Get the MemBuffers current size. More...
 

Typedefs

typedef struct MemBuffer_ MemBuffer
 

Functions

MemBufferMemBufferCreateNew (uint32_t size)
 
int MemBufferExpand (MemBuffer **buffer, uint32_t expand_by)
 expand membuffer by size of 'expand_by' More...
 
void MemBufferFree (MemBuffer *buffer)
 
void MemBufferPrintToFP (MemBuffer *buffer, FILE *fp)
 Write a buffer to the file pointer. More...
 
size_t MemBufferPrintToFPAsString (MemBuffer *b, FILE *fp)
 Write a buffer to the file pointer as a printable char string. More...
 
void MemBufferPrintToFPAsHex (MemBuffer *b, FILE *fp)
 Write a buffer in hex format. More...
 
uint32_t MemBufferWriteRaw (MemBuffer *dst, const uint8_t *raw, const uint32_t raw_len)
 Write a raw buffer to the MemBuffer dst. More...
 
void MemBufferWriteString (MemBuffer *dst, const char *fmt,...) ATTR_FMT_PRINTF(2
 Write a string buffer to the Membuffer dst. More...
 

Detailed Description

Macro Definition Documentation

◆ MEMBUFFER_BUFFER

#define MEMBUFFER_BUFFER (   mem_buffer)    (mem_buffer)->buffer

Get the MemBuffers underlying buffer.

Definition at line 52 of file util-buffer.h.

◆ MEMBUFFER_OFFSET

#define MEMBUFFER_OFFSET (   mem_buffer)    (mem_buffer)->offset

Get the MemBuffers current offset.

Definition at line 57 of file util-buffer.h.

◆ MEMBUFFER_SIZE

#define MEMBUFFER_SIZE (   mem_buffer)    (mem_buffer)->size

Get the MemBuffers current size.

Definition at line 62 of file util-buffer.h.

Typedef Documentation

◆ MemBuffer

typedef struct MemBuffer_ MemBuffer

Function Documentation

◆ MemBufferCreateNew()

MemBuffer* MemBufferCreateNew ( uint32_t  size)

Definition at line 32 of file util-buffer.c.

References MAX_LIMIT, SC_EINVAL, SC_ENOMEM, sc_errno, SC_OK, SCCalloc, SCLogWarning, and unlikely.

Referenced by CreateEveThreadCtx(), JsonLogThreadInit(), LogHttpLogThreadInit(), LogStatsLogThreadInit(), and LogTcpDataLogThreadInit().

Here is the caller graph for this function:

◆ MemBufferExpand()

int MemBufferExpand ( MemBuffer **  buffer,
uint32_t  expand_by 
)

expand membuffer by size of 'expand_by'

If expansion failed, buffer will still be valid.

Return values
result0 ok, -1 expansion failed

Definition at line 60 of file util-buffer.c.

References MAX_LIMIT, SCLogDebug, SCLogWarning, SCRealloc, MemBuffer_::size, and unlikely.

Referenced by OutputJSONMemBufferCallback().

Here is the caller graph for this function:

◆ MemBufferFree()

void MemBufferFree ( MemBuffer buffer)

Definition at line 81 of file util-buffer.c.

References SCFree.

Referenced by CreateEveThreadCtx(), FreeEveThreadCtx(), JsonLogThreadInit(), LogHttpLogThreadDeinit(), LogStatsLogThreadDeinit(), and LogTcpDataLogThreadDeinit().

Here is the caller graph for this function:

◆ MemBufferPrintToFP()

void MemBufferPrintToFP ( MemBuffer buffer,
FILE *  fp 
)

Write a buffer to the file pointer.

   Accepted buffers can contain both printable and non-printable
   characters.  Printable characters are written in the printable
   format and the non-printable chars are written in hex codes
   using the |XX| format.

   For example this would be the kind of output in the file -
   onetwo|EF|three|ED|five
Parameters
bufferPointer to the src MemBuffer instance to write.
fpPointer to the file instance to write to.

Definition at line 86 of file util-buffer.c.

References MemBuffer_::buffer, and MemBuffer_::offset.

◆ MemBufferPrintToFPAsHex()

void MemBufferPrintToFPAsHex ( MemBuffer b,
FILE *  fp 
)

Write a buffer in hex format.

Parameters
bPointer to the src MemBuffer instance to write.
fpPointer to the file instance to write to.

Definition at line 101 of file util-buffer.c.

References MemBuffer_::buffer, and MEMBUFFER_OFFSET.

◆ MemBufferPrintToFPAsString()

size_t MemBufferPrintToFPAsString ( MemBuffer b,
FILE *  fp 
)

Write a buffer to the file pointer as a printable char string.

Parameters
bPointer to the src MemBuffer instance to write.
fpPointer to the file instance to write to.
Return values
size_tbytes written by fwrite()

Definition at line 96 of file util-buffer.c.

References MEMBUFFER_BUFFER, and MEMBUFFER_OFFSET.

◆ MemBufferWriteRaw()

uint32_t MemBufferWriteRaw ( MemBuffer dst,
const uint8_t *  raw,
const uint32_t  raw_len 
)

Write a raw buffer to the MemBuffer dst.

   When we say raw buffer it indicates a buffer that need not be
   purely a string buffer.  It can be a pure string buffer or not or
   a mixture of both.  Hence we don't accept any format strings.

   If the remaining space on the buffer is lesser than the length of
   the buffer to write, it is truncated to fit into the empty space.

   Also after every write a '\0' is appended.  This would indicate
   that the total available space to write in the buffer is
   MemBuffer->size - 1 and not Membuffer->size.  The reason we
   append the '\0' is for supporting writing pure string buffers
   as well, that can later be used by other string handling funcs.
Parameters
raw_bufferThe buffer to write.
raw_buffer_lenLength of the above buffer.
Return values
write_lenBytes written. If less than raw_len, the buffer is full.

Definition at line 110 of file util-buffer.c.

References dst, and SCLogDebug.

Referenced by OutputJSONBuffer(), and OutputJSONMemBufferCallback().

Here is the caller graph for this function:

◆ MemBufferWriteString()

void MemBufferWriteString ( MemBuffer dst,
const char *  fmt,
  ... 
)

Write a string buffer to the Membuffer dst.

   This function takes a format string and arguments for the format
   string like sprintf.

   An example usage of this is -
   MemBufferWriteString(mem_buffer_instance, \"%d - %s\", 10, \"one\");
Parameters
dstThe dst MemBuffer instance.
formatThe format string.
...Variable arguments.