ASN1C C/C++ Common Runtime  ASN1C v7.6.x
Classes | Macros | Typedefs | Functions
Context Message Buffer Read/Write Functions

Classes

struct  _OSRTBufLocDescr
 

Macros

#define OSRTPUTCHAR(pctxt, ch)   rtxWriteBytes (pctxt, (OSOCTET*)&ch, 1)
 
#define OSRTPUTCHARREV(pctxt, ch)   (pctxt)->buffer.data[--(pctxt)->buffer.byteIndex]=(OSOCTET)ch;
 
#define OSRTZTERM(pctxt)   (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]=(OSOCTET)0;
 
#define OSRTSAFEZTERM(pctxt)
 
#define OSRTSAFEPUTCHAR(pctxt, ch)
 
#define OSRTSAFEPUTCHAR_ZTERM(pctxt, ch)
 
#define OSRTSAFEPUTCHAR1(pctxt, ch, stat)
 
#define OSRTMEMCPY(pctxt, bdata, len)
 
#define OSRTMEMCPYREV(pctxt, bdata, len)
 
#define OSRTSAFEMEMCPY(pctxt, bdata, len)
 
#define OSRTSAFEMEMCPY1(pctxt, bdata, len, stat)
 
#define OSRTGETBUFUTF8LEN(pctxt)   rtxCalcUTF8Len (OSRTBUFPTR (pctxt), OSRTBUFSIZE (pctxt))
 
#define OSRTCHKBUFUTF8LEN(pctxt, lower, upper, stat)
 
#define OSRTENDOFBUF(pctxt)   ((pctxt)->buffer.byteIndex >= (pctxt)->buffer.size)
 
#define OSRTByteAlign(pctxt)
 

Typedefs

typedef struct _OSRTBufLocDescr OSRTBufLocDescr
 

Functions

int rtxCheckBuffer (OSCTXT *pctxt, size_t nbytes)
 
int rtxCheckOutputBuffer (OSCTXT *pctxt, size_t nbytes)
 
OSBOOL rtxIsOutputBufferFlushable (OSCTXT *pctxt)
 
int rtxFlushOutputBuffer (OSCTXT *pctxt)
 
int rtxExpandOutputBuffer (OSCTXT *pctxt, size_t nbytes)
 
int rtxCheckInputBuffer (OSCTXT *pctxt, size_t nbytes)
 
int rtxCopyAsciiText (OSCTXT *pctxt, const char *text)
 
int rtxCopyUTF8Text (OSCTXT *pctxt, const OSUTF8CHAR *text)
 
int rtxCopyUnicodeText (OSCTXT *pctxt, const OSUNICHAR *text)
 
int rtxLoadInputBuffer (OSCTXT *pctxt, OSSIZE nbytes)
 
int rtxPeekByte (OSCTXT *pctxt, OSOCTET *pbyte)
 
int rtxPeekBytes (OSCTXT *pctxt, OSOCTET *pdata, OSSIZE bufsize, OSSIZE nocts, OSSIZE *pactual)
 
int rtxReadBytesSafe (OSCTXT *pctxt, OSOCTET *buffer, size_t bufsize, size_t nocts)
 
int rtxReadBytes (OSCTXT *pctxt, OSOCTET *pdata, size_t nocts)
 
int rtxReadBytesDynamic (OSCTXT *pctxt, OSOCTET **ppdata, size_t nocts, OSBOOL *pMemAlloc)
 
int rtxWriteBytes (OSCTXT *pctxt, const OSOCTET *pdata, size_t nocts)
 
int rtxWriteIndent (OSCTXT *pctxt)
 
void rtxIndentDecr (OSCTXT *pctxt)
 
void rtxIndentIncr (OSCTXT *pctxt)
 
void rtxIndentReset (OSCTXT *pctxt)
 
size_t rtxGetIndentLevels (OSCTXT *pctxt)
 
OSBOOL rtxCanonicalSort (OSOCTET *refPoint, OSRTSList *pList, OSBOOL normal)
 
int rtxEncCanonicalSort (OSCTXT *pctxt, OSCTXT *pMemCtxt, OSRTSList *pList)
 
void rtxGetBufLocDescr (OSCTXT *pctxt, OSRTBufLocDescr *pDescr)
 
void rtxAddBufLocDescr (OSCTXT *pctxt, OSRTSList *pElemList, OSRTBufLocDescr *pDescr)
 

Detailed Description

The context message buffer can be written to, or read from, using various functions.

Macro Definition Documentation

◆ OSRTByteAlign

#define OSRTByteAlign (   pctxt)
Value:
if ((pctxt)->buffer.bitOffset != 8) { \
(pctxt)->buffer.byteIndex++; \
(pctxt)->buffer.bitOffset = 8; } \

◆ OSRTCHKBUFUTF8LEN

#define OSRTCHKBUFUTF8LEN (   pctxt,
  lower,
  upper,
  stat 
)
Value:
do { size_t nchars = OSRTGETBUFUTF8LEN (pctxt); \
stat = (nchars >= lower && nchars <= upper) ? 0 : RTERR_CONSVIO; } while(0)
#define RTERR_CONSVIO
Definition: rtxErrCodes.h:185

◆ OSRTMEMCPY

#define OSRTMEMCPY (   pctxt,
  bdata,
  len 
)
Value:
do { \
OSCRTLSAFEMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], \
(pctxt)->buffer.size-(pctxt)->buffer.byteIndex, bdata, len); \
(pctxt)->buffer.byteIndex += len; \
(pctxt)->lastChar = (pctxt)->buffer.data[(pctxt)->buffer.byteIndex-1]; \
} while (0)

◆ OSRTMEMCPYREV

#define OSRTMEMCPYREV (   pctxt,
  bdata,
  len 
)
Value:
do { \
(pctxt)->buffer.byteIndex -= len; \
OSCRTLSAFEMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], \
(pctxt)->buffer.size-(pctxt)->buffer.byteIndex, bdata, len); \
} while (0)

◆ OSRTSAFEMEMCPY

#define OSRTSAFEMEMCPY (   pctxt,
  bdata,
  len 
)
Value:
do { \
if (rtxCheckOutputBuffer (pctxt, len) == 0) { \
OSCRTLMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], bdata, len); \
(pctxt)->buffer.byteIndex += len; \
(pctxt)->lastChar = (pctxt)->buffer.data[(pctxt)->buffer.byteIndex-1]; } \
else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
} while (0)
int rtxCheckOutputBuffer(OSCTXT *pctxt, size_t nbytes)
#define RTERR_BUFOVFLW
Definition: rtxErrCodes.h:60

◆ OSRTSAFEMEMCPY1

#define OSRTSAFEMEMCPY1 (   pctxt,
  bdata,
  len,
  stat 
)
Value:
do { \
if (rtxCheckOutputBuffer (pctxt, len) == 0) { \
OSCRTLMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], bdata, len); \
(pctxt)->buffer.byteIndex += len; \
(pctxt)->lastChar = (pctxt)->buffer.data[(pctxt)->buffer.byteIndex-1]; \
stat = 0; } \
else stat = RTERR_BUFOVFLW; \
} while (0)
int rtxCheckOutputBuffer(OSCTXT *pctxt, size_t nbytes)
#define RTERR_BUFOVFLW
Definition: rtxErrCodes.h:60

◆ OSRTSAFEPUTCHAR

#define OSRTSAFEPUTCHAR (   pctxt,
  ch 
)
Value:
do { \
if (rtxCheckOutputBuffer (pctxt, 1) == 0) \
(pctxt)->lastChar= \
(pctxt)->buffer.data[(pctxt)->buffer.byteIndex++]=(OSOCTET)ch; \
else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
} while (0)
int rtxCheckOutputBuffer(OSCTXT *pctxt, size_t nbytes)
#define RTERR_BUFOVFLW
Definition: rtxErrCodes.h:60

◆ OSRTSAFEPUTCHAR1

#define OSRTSAFEPUTCHAR1 (   pctxt,
  ch,
  stat 
)
Value:
do { \
OSOCTET b = (OSOCTET)ch; \
rtxWriteBytes (pctxt, &b, 1); \
} while (0)

◆ OSRTSAFEPUTCHAR_ZTERM

#define OSRTSAFEPUTCHAR_ZTERM (   pctxt,
  ch 
)
Value:
do { \
if (rtxCheckOutputBuffer (pctxt, 2) == 0) { \
(pctxt)->lastChar= \
(pctxt)->buffer.data[(pctxt)->buffer.byteIndex++]=(OSOCTET)ch; \
(pctxt)->buffer.data[(pctxt)->buffer.byteIndex]=(OSOCTET)0; } \
else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
} while (0)
int rtxCheckOutputBuffer(OSCTXT *pctxt, size_t nbytes)
#define RTERR_BUFOVFLW
Definition: rtxErrCodes.h:60

◆ OSRTSAFEZTERM

#define OSRTSAFEZTERM (   pctxt)
Value:
do { \
if (rtxCheckOutputBuffer (pctxt, 1) == 0) \
(pctxt)->buffer.data[(pctxt)->buffer.byteIndex]=(OSOCTET)0; \
else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
} while (0)
int rtxCheckOutputBuffer(OSCTXT *pctxt, size_t nbytes)
#define RTERR_BUFOVFLW
Definition: rtxErrCodes.h:60

Typedef Documentation

◆ OSRTBufLocDescr

Buffer location descriptor

Function Documentation

◆ rtxAddBufLocDescr()

void rtxAddBufLocDescr ( OSCTXT pctxt,
OSRTSList pElemList,
OSRTBufLocDescr pDescr 
)

Create a new Asn1BufLocDescr for an element just encoded and append it to pElemList.

Parameters
pctxtPointer to context where data has been encoded.
pElemListList of Asn1BufLocDescr to which a new entry will be added.
pDescrPointer to Asn1BufLocDescr whose offset indicates the start of the element just encoded. The new Asn1BufLocDescr that is added will have the same offset and will have numocts determined by this offset and pctxt's current buffer position.

◆ rtxCanonicalSort()

OSBOOL rtxCanonicalSort ( OSOCTET *  refPoint,
OSRTSList pList,
OSBOOL  normal 
)

Sort a list of buffer locations, referring to component encodings, by comparing the referenced encodings as octet strings.

The sorting can be used with canonical-BER (CER), distinguished-BER (DER), and canonical-XER (XER).

Encoding into the buffer may be done as a normal encoding (start to end) or as a reverse encoding (end to start). This affects the parameters as described below.

Parameters
refPointReference point in the buffer for the buffer locations. For normal encoding, refPoint is the start of the buffer; for reverse encoding, refPoint is the end of the buffer.
pListList of OSRTBufLocDescr, each of which locates the start of an encoded component. The offsets for the locations are relative to refPoint. If normal is TRUE, this function orders the list from least to greatest. Otherwise, it is ordered from greatest to least.
normalTRUE for normal encoding; FALSE for reverse encoding. This tells the function whether to add or substract offsets from refPoint to locate the component encodings and also how to order the list.
Returns
TRUE if any changes to pList were made; FALSE otherwise (meaning the list was already in the desired order).

◆ rtxCheckInputBuffer()

int rtxCheckInputBuffer ( OSCTXT pctxt,
size_t  nbytes 
)

Ensures the given number of bytes are available in the context buffer.

If a stream is attached to the context and is being buffered by the context buffer, this may read from the stream to fill the buffer. Thus this function may alter the context buffer byteIndex and size. Any bytes read from the stream will be sent to the capture buffer, if there is one.

Returns
0 on success, or less than zero on failure. RTERR_ENDOFBUF or RTERR_ENDOFFILE (depending on whether the source is a stream or not) is returned if the requested number of bytes are not available in the input.

◆ rtxCheckOutputBuffer()

int rtxCheckOutputBuffer ( OSCTXT pctxt,
size_t  nbytes 
)

This function checks to ensure that the output buffer has sufficient space to hold an additional nbytes full bytes (if there is a partially filled byte, it is treated as though full). Dynamic buffers are resized if the check fails, while static buffers induce a buffer overflow error. This function may return RTERR_NOMEM if reallocating the dynamic buffer fails.

Parameters
pctxtPointer to a context structure.
nbytesThe requested capacity for the buffer.
Returns
0 on success, or less than zero on failure.

◆ rtxEncCanonicalSort()

int rtxEncCanonicalSort ( OSCTXT pctxt,
OSCTXT pMemCtxt,
OSRTSList pList 
)

Encode the encodings held in pMemCtxt into pctxt, first sorting them as required for canonical BER (and other encoding rules) by X.690 11.6.

Parameters
pctxtPointer to context structure into which the sorted encodings should be encoded.
pMemCtxtPointer to context structure which holds the unsorted encodings.
pListList of Asn1BufLocDescr, each of which locates an encoding in pMemCtxt's buffer, the whole being the encodings that are to be sorted.

◆ rtxExpandOutputBuffer()

int rtxExpandOutputBuffer ( OSCTXT pctxt,
size_t  nbytes 
)

This function attempts to ensure the output buffer has at least the given number of bytes available. A partially full byte in the buffer counts as being available. Dynamic buffers are resized, if necessary, while static buffers induce a buffer overflow error. This function may return RTERR_NOMEM if reallocating a dynamic buffer fails.

Parameters
pctxtPointer to a context structure.
nbytesThe requested capacity for the buffer.
Returns
0 on success, or less than zero on failure.

◆ rtxFlushOutputBuffer()

int rtxFlushOutputBuffer ( OSCTXT pctxt)

This function flushes the buffer to a stream. This function MUST only be called if rtxIsOutputBufferFlushable(pctxt) returns TRUE; the behavior is otherwise undefined. After a successful call, pctxt->buffer.byteIndex == 0. Note that pctxt->buffer.bitOffset is not changed - if there was a partial byte in the buffer before this call, there will be a partial by afterward.

Parameters
pctxtPointer to a context structure.
Returns
0 on success, or less than zero on failure.

◆ rtxGetBufLocDescr()

void rtxGetBufLocDescr ( OSCTXT pctxt,
OSRTBufLocDescr pDescr 
)

Set the buffer location description's offset (pDescr->offset) to the current position in pCtxt's buffer.

◆ rtxGetIndentLevels()

size_t rtxGetIndentLevels ( OSCTXT pctxt)

This returns the number of levels of indentation set in the given context. Currently, the indentation level in the context affects rtxPrintToStreamIndent (when used with a non-null OSCTXT), rtxWriteIndent, and rtJsonEncIndent, meaning it currently affects print-to-stream output, Abstract Syntax Notation output, and JSON (JER) output.

Parameters
pctxtPointer to context block structure.

◆ rtxIndentDecr()

void rtxIndentDecr ( OSCTXT pctxt)

This decreases the indentation level set in the given context by updating the indent member.

See also
rtxGetIndentLevels
Parameters
pctxtPointer to context block structure.

◆ rtxIndentIncr()

void rtxIndentIncr ( OSCTXT pctxt)

This increases the indentation level set in the given context by updating the indent member.

See also
rtxGetIndentLevels
Parameters
pctxtPointer to context block structure.

◆ rtxIndentReset()

void rtxIndentReset ( OSCTXT pctxt)

This resets the indentation level in the given context to zero.

See also
rtxGetIndentLevels
Parameters
pctxtPointer to context block structure.

◆ rtxIsOutputBufferFlushable()

OSBOOL rtxIsOutputBufferFlushable ( OSCTXT pctxt)

This function returns true if the context buffer can be flushed to a stream by calling rtxFlushOutputBuffer. This function is used to determine whether it is safe to call rtxFlushOutputBuffer.

Parameters
pctxtPointer to a context structure.
Returns
TRUE if the buffer can be flushed; FALSE is not.

◆ rtxLoadInputBuffer()

int rtxLoadInputBuffer ( OSCTXT pctxt,
OSSIZE  nbytes 
)

This is for meant for internal use by the runtime.

Read at least as many bytes from the context's input stream into the context buffer as necessary to make nbytes of data available in the context buffer.

Upon return, pctxt.buffer.byteIndex + nbytes <= pctxt.buffer.size OR EOF has been reached OR an error has been logged and is being returned.

If the context buffer has not been created, this will create it. If the context buffer needs to be made larger, this will enlarge it or else log, and return, an error.

Parameters
pctxtA context with an attached stream using the context's buffer as a buffer for the stream.
Returns
0 or or negative error. EOF is not considered an error.

◆ rtxPeekByte()

int rtxPeekByte ( OSCTXT pctxt,
OSOCTET *  pbyte 
)

This function peeks at the next byte of input, if there is one before EOF. A return of 1 ensures the peeked byte can be skipped by incrementing pctxt->buffer.byteIndex.

Parameters
pbyteReceives the value of the peeked byte.
Returns
0 if there was no byte to peek at. 1 if there was a byte to peek at. <0 if there was an error.

◆ rtxPeekBytes()

int rtxPeekBytes ( OSCTXT pctxt,
OSOCTET *  pdata,
OSSIZE  bufsize,
OSSIZE  nocts,
OSSIZE *  pactual 
)

This function peeks at the next nocts bytes of input, peeking at fewer bytes if EOF is encountered first. A returned value (in *pactual) of n (>=0) ensures that n (or fewer) peeked bytes can be skipped by adding n (or less) to pctxt->buffer.byteIndex.

Parameters
pdataReceives the value of the peeked bytes.
bufsizeSize of pdata. If less than nocts, nocts will be adjusted accordingly.
noctsThe number of bytes to peek.
pactualReceives the actual number of bytes peeked.
Returns
0 for success <0 if there was an error.

◆ rtxReadBytes()

int rtxReadBytes ( OSCTXT pctxt,
OSOCTET *  pdata,
size_t  nocts 
)

This function reads bytes from the currently open stream or memory buffer.

Parameters
pctxtPointer to a context structure.
pdataPointer to byte array where bytes are to be copied.
noctsNumber of bytes (octets) to read.
Returns
Status of the operation: 0 if success, negative value if error.

◆ rtxReadBytesDynamic()

int rtxReadBytesDynamic ( OSCTXT pctxt,
OSOCTET **  ppdata,
size_t  nocts,
OSBOOL *  pMemAlloc 
)

This function reads bytes from the currently open stream or memory buffer. In this case the function MAY allocate memory to hold the read bytes. It will only do this if the requested number of bytes will not fit in the context buffer; othwerwise, a pointer to a location in the context buffer is returned. If memory was allocated, it should be freed using rtxMemFreePtr.

Parameters
pctxtPointer to a context structure.
ppdataPointer to byte buffer pointer.
noctsNumber of bytes (octets) to read.
pMemAllocPointer to boolean value which is set to true if memory was allocated to hold requested bytes.
Returns
Status of the operation: 0 if success, negative value if error.

◆ rtxReadBytesSafe()

int rtxReadBytesSafe ( OSCTXT pctxt,
OSOCTET *  buffer,
size_t  bufsize,
size_t  nocts 
)

This function safely reads bytes from the currently open stream or memory buffer into the given static buffer. This function is preferred over rtxReadBytes because it will detect buffer overflow.

Parameters
pctxtPointer to a context structure.
bufferStatic buffer into which bytes are to be read.
bufsizeSize of the static buffer.
noctsNumber of bytes (octets) to read.
Returns
Status of the operation: 0 if success, negative value if error.

◆ rtxWriteBytes()

int rtxWriteBytes ( OSCTXT pctxt,
const OSOCTET *  pdata,
size_t  nocts 
)

This function writes bytes to the currently open stream or memory buffer.

Parameters
pctxtPointer to a context structure.
pdataPointer to location where bytes are to be copied.
noctsNumber of bytes to read.
Returns
I/O byte count.

◆ rtxWriteIndent()

int rtxWriteIndent ( OSCTXT pctxt)

This function writes a newline followed by indentation whitespace to the buffer. The amount of indentation to add is determined by the indent member variable in the context structure.

If context flag OSNOWHITESPACE is set, this function will do nothing.

Parameters
pctxtPointer to context block structure.
Returns
Completion status of operation:
  • 0 = success,
  • negative return value is error.