FreeRDP
stream.c File Reference
#include <winpr/config.h>
#include <winpr/assert.h>
#include <winpr/crt.h>
#include <winpr/stream.h>
#include "stream.h"
#include "../log.h"

Macros

#define STREAM_TAG   WINPR_TAG("wStream")
 
#define STREAM_ASSERT(cond)
 

Functions

BOOL Stream_EnsureCapacity (wStream *s, size_t size)
 
BOOL Stream_EnsureRemainingCapacity (wStream *s, size_t size)
 
wStreamStream_New (BYTE *buffer, size_t size)
 
wStreamStream_StaticConstInit (wStream *s, const BYTE *buffer, size_t size)
 
wStreamStream_StaticInit (wStream *s, BYTE *buffer, size_t size)
 
void Stream_EnsureValidity (wStream *s)
 
void Stream_Free (wStream *s, BOOL bFreeBuffer)
 
BOOL Stream_SetLength (wStream *_s, size_t _l)
 
BOOL Stream_SetPosition (wStream *_s, size_t _p)
 
void Stream_SealLength (wStream *_s)
 
size_t Stream_GetRemainingCapacity (const wStream *_s)
 
size_t Stream_GetRemainingLength (const wStream *_s)
 
BOOL Stream_Write_UTF16_String (wStream *s, const WCHAR *src, size_t length)
 
BOOL Stream_Read_UTF16_String (wStream *s, WCHAR *dst, size_t length)
 
BOOL Stream_CheckAndLogRequiredCapacityEx (const char *tag, DWORD level, wStream *s, size_t nmemb, size_t size, const char *fmt,...)
 
BOOL Stream_CheckAndLogRequiredCapacityExVa (const char *tag, DWORD level, wStream *s, size_t nmemb, size_t size, const char *fmt, va_list args)
 
BOOL Stream_CheckAndLogRequiredCapacityWLogExVa (wLog *log, DWORD level, wStream *s, size_t nmemb, size_t size, WINPR_FORMAT_ARG const char *fmt, va_list args)
 
BOOL Stream_CheckAndLogRequiredCapacityWLogEx (wLog *log, DWORD level, wStream *s, size_t nmemb, size_t size, WINPR_FORMAT_ARG const char *fmt,...)
 
BOOL Stream_CheckAndLogRequiredLengthEx (const char *tag, DWORD level, wStream *s, size_t nmemb, size_t size, WINPR_FORMAT_ARG const char *fmt,...)
 
BOOL Stream_CheckAndLogRequiredLengthExVa (const char *tag, DWORD level, wStream *s, size_t nmemb, size_t size, const char *fmt, va_list args)
 
BOOL Stream_CheckAndLogRequiredLengthWLogEx (wLog *log, DWORD level, wStream *s, size_t nmemb, size_t size, const char *fmt,...)
 
BOOL Stream_CheckAndLogRequiredLengthWLogExVa (wLog *log, DWORD level, wStream *s, size_t nmemb, size_t size, WINPR_FORMAT_ARG const char *fmt, va_list args)
 
SSIZE_T Stream_Write_UTF16_String_From_UTF8 (wStream *s, size_t dlen, const char *src, size_t length, BOOL fill)
 Writes a UTF-8 string UTF16 encoded to the stream. If the UTF-8 string is short, the remainig characters are filled up with '\0'. More...
 
char * Stream_Read_UTF16_String_As_UTF8 (wStream *s, size_t dlen, size_t *psize)
 Reads a WCHAR string from a stream and converts it to UTF-8 and returns a newly allocated string. More...
 
SSIZE_T Stream_Read_UTF16_String_As_UTF8_Buffer (wStream *s, size_t wcharLength, char *utfBuffer, size_t utfBufferCharLength)
 Reads a WCHAR string from a stream and converts it to UTF-8 and writes it to the supplied buffer. More...
 
BOOL Stream_SafeSeekEx (wStream *s, size_t size, const char *file, size_t line, const char *fkt)
 

Macro Definition Documentation

◆ STREAM_ASSERT

#define STREAM_ASSERT (   cond)
Value:
do \
{ \
if (!(cond)) \
{ \
WLog_FATAL(STREAM_TAG, "%s [%s:%s:%" PRIuz "]", #cond, __FILE__, __func__, \
(size_t)__LINE__); \
winpr_log_backtrace(STREAM_TAG, WLOG_FATAL, 20); \
abort(); \
} \
} while (0)
#define WLOG_FATAL
Definition: dsp_fdk_impl.c:37
#define STREAM_TAG
Definition: stream.c:30

◆ STREAM_TAG

#define STREAM_TAG   WINPR_TAG("wStream")

Function Documentation

◆ Stream_CheckAndLogRequiredCapacityEx()

BOOL Stream_CheckAndLogRequiredCapacityEx ( const char *  tag,
DWORD  level,
wStream s,
size_t  nmemb,
size_t  size,
const char *  fmt,
  ... 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Stream_CheckAndLogRequiredCapacityExVa()

BOOL Stream_CheckAndLogRequiredCapacityExVa ( const char *  tag,
DWORD  level,
wStream s,
size_t  nmemb,
size_t  size,
const char *  fmt,
va_list  args 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Stream_CheckAndLogRequiredCapacityWLogEx()

BOOL Stream_CheckAndLogRequiredCapacityWLogEx ( wLog *  log,
DWORD  level,
wStream s,
size_t  nmemb,
size_t  size,
WINPR_FORMAT_ARG const char *  fmt,
  ... 
)
Here is the call graph for this function:

◆ Stream_CheckAndLogRequiredCapacityWLogExVa()

BOOL Stream_CheckAndLogRequiredCapacityWLogExVa ( wLog *  log,
DWORD  level,
wStream s,
size_t  nmemb,
size_t  size,
WINPR_FORMAT_ARG const char *  fmt,
va_list  args 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Stream_CheckAndLogRequiredLengthEx()

BOOL Stream_CheckAndLogRequiredLengthEx ( const char *  tag,
DWORD  level,
wStream s,
size_t  nmemb,
size_t  size,
WINPR_FORMAT_ARG const char *  fmt,
  ... 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Stream_CheckAndLogRequiredLengthExVa()

BOOL Stream_CheckAndLogRequiredLengthExVa ( const char *  tag,
DWORD  level,
wStream s,
size_t  nmemb,
size_t  size,
const char *  fmt,
va_list  args 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Stream_CheckAndLogRequiredLengthWLogEx()

BOOL Stream_CheckAndLogRequiredLengthWLogEx ( wLog *  log,
DWORD  level,
wStream s,
size_t  nmemb,
size_t  size,
const char *  fmt,
  ... 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Stream_CheckAndLogRequiredLengthWLogExVa()

BOOL Stream_CheckAndLogRequiredLengthWLogExVa ( wLog *  log,
DWORD  level,
wStream s,
size_t  nmemb,
size_t  size,
WINPR_FORMAT_ARG const char *  fmt,
va_list  args 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Stream_EnsureCapacity()

BOOL Stream_EnsureCapacity ( wStream s,
size_t  size 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Stream_EnsureRemainingCapacity()

BOOL Stream_EnsureRemainingCapacity ( wStream s,
size_t  size 
)
Here is the call graph for this function:

◆ Stream_EnsureValidity()

void Stream_EnsureValidity ( wStream s)
Here is the caller graph for this function:

◆ Stream_Free()

void Stream_Free ( wStream s,
BOOL  bFreeBuffer 
)
Here is the call graph for this function:

◆ Stream_GetRemainingCapacity()

size_t Stream_GetRemainingCapacity ( const wStream _s)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Stream_GetRemainingLength()

size_t Stream_GetRemainingLength ( const wStream _s)
Here is the call graph for this function:

◆ Stream_New()

wStream* Stream_New ( BYTE buffer,
size_t  size 
)

◆ Stream_Read_UTF16_String()

BOOL Stream_Read_UTF16_String ( wStream s,
WCHAR *  dst,
size_t  length 
)
Here is the caller graph for this function:

◆ Stream_Read_UTF16_String_As_UTF8()

char* Stream_Read_UTF16_String_As_UTF8 ( wStream s,
size_t  wcharLength,
size_t *  pUtfCharLength 
)

Reads a WCHAR string from a stream and converts it to UTF-8 and returns a newly allocated string.

Parameters
sThe stream to read data from
wcharLengthThe number of WCHAR characters to read (NOT the size in bytes!)
pUtfCharLengthIgnored if NULL, otherwise will be set to the number of characters in the resulting UTF-8 string
Returns
A '\0' terminated UTF-8 encoded string or NULL for any failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Stream_Read_UTF16_String_As_UTF8_Buffer()

SSIZE_T Stream_Read_UTF16_String_As_UTF8_Buffer ( wStream s,
size_t  wcharLength,
char *  utfBuffer,
size_t  utfBufferCharLength 
)

Reads a WCHAR string from a stream and converts it to UTF-8 and writes it to the supplied buffer.

Parameters
sThe stream to read data from
wcharLengthThe number of WCHAR characters to read (NOT the size in bytes!)
utfBufferA pointer to a buffer holding the result string
utfBufferCharLengthThe size of the result buffer
Returns
The char length (strlen) of the result string or -1 for failure
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Stream_SafeSeekEx()

BOOL Stream_SafeSeekEx ( wStream s,
size_t  size,
const char *  file,
size_t  line,
const char *  fkt 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Stream_SealLength()

void Stream_SealLength ( wStream _s)
Here is the call graph for this function:

◆ Stream_SetLength()

BOOL Stream_SetLength ( wStream _s,
size_t  _l 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Stream_SetPosition()

BOOL Stream_SetPosition ( wStream _s,
size_t  _p 
)
Here is the call graph for this function:

◆ Stream_StaticConstInit()

wStream* Stream_StaticConstInit ( wStream s,
const BYTE buffer,
size_t  size 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Stream_StaticInit()

wStream* Stream_StaticInit ( wStream s,
BYTE buffer,
size_t  size 
)
Here is the caller graph for this function:

◆ Stream_Write_UTF16_String()

BOOL Stream_Write_UTF16_String ( wStream s,
const WCHAR *  src,
size_t  length 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Stream_Write_UTF16_String_From_UTF8()

SSIZE_T Stream_Write_UTF16_String_From_UTF8 ( wStream s,
size_t  wcharLength,
const char *  src,
size_t  length,
BOOL  fill 
)

Writes a UTF-8 string UTF16 encoded to the stream. If the UTF-8 string is short, the remainig characters are filled up with '\0'.

Parameters
sThe stream to write to
wcharLengththe length (in WCHAR characters) to write
srcThe source data buffer with the UTF-8 data
lengthThe length in bytes of the UTF-8 buffer
fillIf TRUE fill the unused parts of the wcharLength with 0

return number of used characters for success, /b -1 for failure

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