XBinder  Version 2.6.x
rtxBuffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2018 Objective Systems, Inc.
3  *
4  * This software is furnished under a license and may be used and copied
5  * only in accordance with the terms of such license and with the
6  * inclusion of the above copyright notice. This software or any other
7  * copies thereof may not be provided or otherwise made available to any
8  * other person. No title to and ownership of the software is hereby
9  * transferred.
10  *
11  * The information in this software is subject to change without notice
12  * and should not be construed as a commitment by Objective Systems, Inc.
13  *
14  * PROPRIETARY NOTICE
15  *
16  * This software is an unpublished work subject to a confidentiality agreement
17  * and is protected by copyright and trade secret law. Unauthorized copying,
18  * redistribution or other use of this work is prohibited.
19  *
20  * The above notice of copyright on this source code product does not indicate
21  * any actual or intended publication of such source code.
22  *
23  *****************************************************************************/
29 #ifndef _RTXBUFFER_H_
30 #define _RTXBUFFER_H_
31 
32 #include "rtxsrc/rtxContext.h"
33 #include "rtxsrc/rtxSList.h"
34 
35 /* reserve octets to enable short backoffs */
36 #define MIN_STREAM_BACKOFF 0
37 
41 typedef struct _OSRTBufLocDescr {
42  OSSIZE numocts;
43  OSSIZE offset;
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 
51 EXTERNRT int rtxCheckBuffer (OSCTXT* pctxt, size_t nbytes);
52 
65 EXTERNRT int rtxCheckOutputBuffer (OSCTXT* pctxt, size_t nbytes);
66 
67 
77 EXTERNRT OSBOOL rtxIsOutputBufferFlushable(OSCTXT* pctxt);
78 
79 
92 EXTERNRT int rtxFlushOutputBuffer(OSCTXT* pctxt);
93 
94 
107 EXTERNRT int rtxExpandOutputBuffer (OSCTXT* pctxt, size_t nbytes);
108 
109 EXTERNRT int rtxCheckInputBuffer (OSCTXT* pctxt, size_t nbytes);
110 
111 EXTERNRT int rtxCopyAsciiText (OSCTXT* pctxt, const char* text);
112 
113 EXTERNRT int rtxCopyUTF8Text (OSCTXT* pctxt, const OSUTF8CHAR* text);
114 
115 EXTERNRT int rtxCopyUnicodeText (OSCTXT* pctxt, const OSUNICHAR* text);
116 
129 EXTERNRT int rtxReadBytesSafe
130 (OSCTXT* pctxt, OSOCTET* buffer, size_t bufsize, size_t nocts);
131 
141 EXTERNRT int rtxReadBytes (OSCTXT* pctxt, OSOCTET* pdata, size_t nocts);
142 
159 EXTERNRT int rtxReadBytesDynamic
160 (OSCTXT* pctxt, OSOCTET** ppdata, size_t nocts, OSBOOL* pMemAlloc);
161 
170 EXTERNRT int rtxWriteBytes
171 (OSCTXT* pctxt, const OSOCTET* pdata, size_t nocts);
172 
173 
202 EXTERNRT OSBOOL rtxCanonicalSort (OSOCTET* refPoint, OSRTSList* pList,
203  OSBOOL normal);
204 
205 
218 EXTERNRT int rtxEncCanonicalSort (OSCTXT* pctxt,
219  OSCTXT* pMemCtxt,
220  OSRTSList* pList);
221 
226 EXTERNRT void rtxGetBufLocDescr (OSCTXT *pctxt, OSRTBufLocDescr* pDescr);
227 
240 EXTERNRT void rtxAddBufLocDescr (OSCTXT *pctxt, OSRTSList* pElemList,
241  OSRTBufLocDescr* pDescr);
242 
243 /* Macros */
244 
245 #define OSRTPUTCHAR(pctxt,ch) rtxWriteBytes (pctxt, (OSOCTET*)&ch, 1)
246 
247 #define OSRTPUTCHARREV(pctxt,ch) \
248 (pctxt)->buffer.data[--(pctxt)->buffer.byteIndex]=(OSOCTET)ch;
249 
250 #define OSRTZTERM(pctxt) \
251 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]=(OSOCTET)0;
252 
253 #define OSRTSAFEZTERM(pctxt) \
254 do { \
255 if (rtxCheckOutputBuffer (pctxt, 1) == 0) \
256 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]=(OSOCTET)0; \
257 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
258 } while (0)
259 
260 #define OSRTSAFEPUTCHAR(pctxt,ch) \
261 do { \
262 if (rtxCheckOutputBuffer (pctxt, 1) == 0) \
263 (pctxt)->lastChar= \
264 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex++]=(OSOCTET)ch; \
265 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
266 } while (0)
267 
268 #define OSRTSAFEPUTCHAR1(pctxt,ch,stat) \
269 do { \
270 OSOCTET b = (OSOCTET)ch; \
271 rtxWriteBytes (pctxt, &b, 1); \
272 } while (0)
273 
274 #if 0
275 #define OSRTSAFEPUTCHAR2(pctxt,ch,prealloc) \
276 do { \
277 if (rtxCheckOutputBuffer (pctxt, ((prealloc > 1)?prealloc:1)) == 0) \
278 (pctxt)->lastChar= \
279 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex++]=(OSOCTET)ch; \
280 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
281 } while (0)
282 #endif
283 
284 #define OSRTMEMCPY(pctxt,bdata,len) \
285 do { \
286 OSCRTLSAFEMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], \
287  (pctxt)->buffer.size-(pctxt)->buffer.byteIndex, bdata, len); \
288 (pctxt)->buffer.byteIndex += len; \
289 (pctxt)->lastChar = (pctxt)->buffer.data[(pctxt)->buffer.byteIndex-1]; \
290 } while (0)
291 
292 #define OSRTMEMCPYREV(pctxt,bdata,len) \
293 do { \
294 (pctxt)->buffer.byteIndex -= len; \
295 OSCRTLSAFEMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], \
296  (pctxt)->buffer.size-(pctxt)->buffer.byteIndex, bdata, len); \
297 } while (0)
298 
299 #define OSRTSAFEMEMCPY(pctxt,bdata,len) \
300 do { \
301 if (rtxCheckOutputBuffer (pctxt, len) == 0) { \
302 OSCRTLMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], bdata, len); \
303 (pctxt)->buffer.byteIndex += len; \
304 (pctxt)->lastChar = (pctxt)->buffer.data[(pctxt)->buffer.byteIndex-1]; } \
305 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
306 } while (0)
307 
308 #define OSRTSAFEMEMCPY1(pctxt,bdata,len,stat) \
309 do { \
310 if (rtxCheckOutputBuffer (pctxt, len) == 0) { \
311 OSCRTLMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], bdata, len); \
312 (pctxt)->buffer.byteIndex += len; \
313 (pctxt)->lastChar = (pctxt)->buffer.data[(pctxt)->buffer.byteIndex-1]; \
314 stat = 0; } \
315 else stat = RTERR_BUFOVFLW; \
316 } while (0)
317 
318 #define OSRTGETBUFUTF8LEN(pctxt) \
319 rtxCalcUTF8Len (OSRTBUFPTR (pctxt), OSRTBUFSIZE (pctxt))
320 
321 #define OSRTCHKBUFUTF8LEN(pctxt,lower,upper,stat) \
322 do { size_t nchars = OSRTGETBUFUTF8LEN (pctxt); \
323 stat = (nchars >= lower && nchars <= upper) ? 0 : RTERR_CONSVIO; } while(0)
324 
325 #define OSRTENDOFBUF(pctxt) ((pctxt)->buffer.byteIndex >= (pctxt)->buffer.size)
326 
327 #ifdef __cplusplus
328 }
329 #endif
330 
331 #endif
EXTERNRT int rtxReadBytes(OSCTXT *pctxt, OSOCTET *pdata, size_t nocts)
This function reads bytes from the currently open stream or memory buffer.
EXTERNRT int rtxFlushOutputBuffer(OSCTXT *pctxt)
This function flushes the buffer to a stream.
EXTERNRT int rtxEncCanonicalSort(OSCTXT *pctxt, OSCTXT *pMemCtxt, OSRTSList *pList)
Encode the encodings held in pMemCtxt into pctxt, first sorting them as required for canonical BER (a...
Buffer location descriptor.
Definition: rtxBuffer.h:41
EXTERNRT int rtxCheckOutputBuffer(OSCTXT *pctxt, size_t nbytes)
This function checks to ensure that the output buffer has sufficient space to hold an additional nbyt...
EXTERNRT int rtxExpandOutputBuffer(OSCTXT *pctxt, size_t nbytes)
This function attempts to ensure the output buffer has at least the given number of bytes available...
EXTERNRT int rtxWriteBytes(OSCTXT *pctxt, const OSOCTET *pdata, size_t nocts)
This function writes bytes to the currently open stream or memory buffer.
Common run-time context definitions.
EXTERNRT int rtxReadBytesDynamic(OSCTXT *pctxt, OSOCTET **ppdata, size_t nocts, OSBOOL *pMemAlloc)
This function reads bytes from the currently open stream or memory buffer.
EXTERNRT OSBOOL rtxIsOutputBufferFlushable(OSCTXT *pctxt)
This function returns true if the context buffer can be flushed to a stream by calling rtxFlushOutput...
struct _OSRTBufLocDescr OSRTBufLocDescr
Buffer location descriptor.
EXTERNRT void rtxGetBufLocDescr(OSCTXT *pctxt, OSRTBufLocDescr *pDescr)
Set the buffer location description&#39;s offset (pDescr->offset) to the current position in pCtxt&#39;s buff...
EXTERNRT OSBOOL rtxCanonicalSort(OSOCTET *refPoint, OSRTSList *pList, OSBOOL normal)
Sort a list of buffer locations, referring to component encodings, by comparing the referenced encodi...
EXTERNRT 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 stati...
EXTERNRT void rtxAddBufLocDescr(OSCTXT *pctxt, OSRTSList *pElemList, OSRTBufLocDescr *pDescr)
Create a new Asn1BufLocDescr for an element just encoded and append it to pElemList.
Run-time context structure.
Definition: rtxContext.h:185