ASN1C C/C++ Common Runtime  ASN1C v7.4.x
rtxBuffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2020 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 
38 
50 typedef struct _OSRTBufLocDescr {
51  OSSIZE numocts;
52  OSSIZE offset;
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 
60 EXTERNRT int rtxCheckBuffer (OSCTXT* pctxt, size_t nbytes);
61 
74 EXTERNRT int rtxCheckOutputBuffer (OSCTXT* pctxt, size_t nbytes);
75 
76 
86 EXTERNRT OSBOOL rtxIsOutputBufferFlushable(OSCTXT* pctxt);
87 
88 
101 EXTERNRT int rtxFlushOutputBuffer(OSCTXT* pctxt);
102 
103 
116 EXTERNRT int rtxExpandOutputBuffer (OSCTXT* pctxt, size_t nbytes);
117 
118 EXTERNRT int rtxCheckInputBuffer (OSCTXT* pctxt, size_t nbytes);
119 
120 EXTERNRT int rtxCopyAsciiText (OSCTXT* pctxt, const char* text);
121 
122 EXTERNRT int rtxCopyUTF8Text (OSCTXT* pctxt, const OSUTF8CHAR* text);
123 
124 EXTERNRT int rtxCopyUnicodeText (OSCTXT* pctxt, const OSUNICHAR* text);
125 
138 EXTERNRT int rtxReadBytesSafe
139 (OSCTXT* pctxt, OSOCTET* buffer, size_t bufsize, size_t nocts);
140 
150 EXTERNRT int rtxReadBytes (OSCTXT* pctxt, OSOCTET* pdata, size_t nocts);
151 
168 EXTERNRT int rtxReadBytesDynamic
169 (OSCTXT* pctxt, OSOCTET** ppdata, size_t nocts, OSBOOL* pMemAlloc);
170 
179 EXTERNRT int rtxWriteBytes
180 (OSCTXT* pctxt, const OSOCTET* pdata, size_t nocts);
181 
182 
211 EXTERNRT OSBOOL rtxCanonicalSort (OSOCTET* refPoint, OSRTSList* pList,
212  OSBOOL normal);
213 
214 
215 #ifndef _NO_STREAM
216 
228 EXTERNRT int rtxEncCanonicalSort (OSCTXT* pctxt,
229  OSCTXT* pMemCtxt,
230  OSRTSList* pList);
231 
236 EXTERNRT void rtxGetBufLocDescr (OSCTXT *pctxt, OSRTBufLocDescr* pDescr);
237 
250 EXTERNRT void rtxAddBufLocDescr (OSCTXT *pctxt, OSRTSList* pElemList,
251  OSRTBufLocDescr* pDescr);
252 #endif /* _NO_STREAM */
253 
254 /* Macros */
255 
256 #define OSRTPUTCHAR(pctxt,ch) rtxWriteBytes (pctxt, (OSOCTET*)&ch, 1)
257 
258 #define OSRTPUTCHARREV(pctxt,ch) \
259 (pctxt)->buffer.data[--(pctxt)->buffer.byteIndex]=(OSOCTET)ch;
260 
261 #define OSRTZTERM(pctxt) \
262 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]=(OSOCTET)0;
263 
264 #define OSRTSAFEZTERM(pctxt) \
265 do { \
266 if (rtxCheckOutputBuffer (pctxt, 1) == 0) \
267 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]=(OSOCTET)0; \
268 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
269 } while (0)
270 
271 #define OSRTSAFEPUTCHAR(pctxt,ch) \
272 do { \
273 if (rtxCheckOutputBuffer (pctxt, 1) == 0) \
274 (pctxt)->lastChar= \
275 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex++]=(OSOCTET)ch; \
276 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
277 } while (0)
278 
279 /* Put character into buffer and terminate buffer with null character.
280  Execute return LOG_RTERRNEW if there is not room in the buffer and
281  the buffer cannot be expanded to make room.
282 */
283 #define OSRTSAFEPUTCHAR_ZTERM(pctxt,ch) \
284 do { \
285 if (rtxCheckOutputBuffer (pctxt, 2) == 0) { \
286 (pctxt)->lastChar= \
287 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex++]=(OSOCTET)ch; \
288 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]=(OSOCTET)0; } \
289 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
290 } while (0)
291 
292 
293 #define OSRTSAFEPUTCHAR1(pctxt,ch,stat) \
294 do { \
295 OSOCTET b = (OSOCTET)ch; \
296 rtxWriteBytes (pctxt, &b, 1); \
297 } while (0)
298 
299 #if 0
300 #define OSRTSAFEPUTCHAR2(pctxt,ch,prealloc) \
301 do { \
302 if (rtxCheckOutputBuffer (pctxt, ((prealloc > 1)?prealloc:1)) == 0) \
303 (pctxt)->lastChar= \
304 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex++]=(OSOCTET)ch; \
305 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
306 } while (0)
307 #endif
308 
309 #define OSRTMEMCPY(pctxt,bdata,len) \
310 do { \
311 OSCRTLSAFEMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], \
312  (pctxt)->buffer.size-(pctxt)->buffer.byteIndex, bdata, len); \
313 (pctxt)->buffer.byteIndex += len; \
314 (pctxt)->lastChar = (pctxt)->buffer.data[(pctxt)->buffer.byteIndex-1]; \
315 } while (0)
316 
317 #define OSRTMEMCPYREV(pctxt,bdata,len) \
318 do { \
319 (pctxt)->buffer.byteIndex -= len; \
320 OSCRTLSAFEMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], \
321  (pctxt)->buffer.size-(pctxt)->buffer.byteIndex, bdata, len); \
322 } while (0)
323 
324 #define OSRTSAFEMEMCPY(pctxt,bdata,len) \
325 do { \
326 if (rtxCheckOutputBuffer (pctxt, len) == 0) { \
327 OSCRTLMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], bdata, len); \
328 (pctxt)->buffer.byteIndex += len; \
329 (pctxt)->lastChar = (pctxt)->buffer.data[(pctxt)->buffer.byteIndex-1]; } \
330 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
331 } while (0)
332 
333 #define OSRTSAFEMEMCPY1(pctxt,bdata,len,stat) \
334 do { \
335 if (rtxCheckOutputBuffer (pctxt, len) == 0) { \
336 OSCRTLMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], bdata, len); \
337 (pctxt)->buffer.byteIndex += len; \
338 (pctxt)->lastChar = (pctxt)->buffer.data[(pctxt)->buffer.byteIndex-1]; \
339 stat = 0; } \
340 else stat = RTERR_BUFOVFLW; \
341 } while (0)
342 
343 #define OSRTGETBUFUTF8LEN(pctxt) \
344 rtxCalcUTF8Len (OSRTBUFPTR (pctxt), OSRTBUFSIZE (pctxt))
345 
346 #define OSRTCHKBUFUTF8LEN(pctxt,lower,upper,stat) \
347 do { size_t nchars = OSRTGETBUFUTF8LEN (pctxt); \
348 stat = (nchars >= lower && nchars <= upper) ? 0 : RTERR_CONSVIO; } while(0)
349 
350 #define OSRTENDOFBUF(pctxt) ((pctxt)->buffer.byteIndex >= (pctxt)->buffer.size)
351 
357 #ifdef __cplusplus
358 }
359 #endif
360 
361 #endif
int rtxWriteBytes(OSCTXT *pctxt, const OSOCTET *pdata, size_t nocts)
int rtxReadBytes(OSCTXT *pctxt, OSOCTET *pdata, size_t nocts)
void rtxGetBufLocDescr(OSCTXT *pctxt, OSRTBufLocDescr *pDescr)
int rtxCheckOutputBuffer(OSCTXT *pctxt, size_t nbytes)
struct _OSRTBufLocDescr OSRTBufLocDescr
Definition: rtxSList.h:68
Definition: rtxBuffer.h:50
int rtxFlushOutputBuffer(OSCTXT *pctxt)
void rtxAddBufLocDescr(OSCTXT *pctxt, OSRTSList *pElemList, OSRTBufLocDescr *pDescr)
int rtxReadBytesDynamic(OSCTXT *pctxt, OSOCTET **ppdata, size_t nocts, OSBOOL *pMemAlloc)
OSBOOL rtxCanonicalSort(OSOCTET *refPoint, OSRTSList *pList, OSBOOL normal)
int rtxEncCanonicalSort(OSCTXT *pctxt, OSCTXT *pMemCtxt, OSRTSList *pList)
OSBOOL rtxIsOutputBufferFlushable(OSCTXT *pctxt)
int rtxExpandOutputBuffer(OSCTXT *pctxt, size_t nbytes)
int rtxReadBytesSafe(OSCTXT *pctxt, OSOCTET *buffer, size_t bufsize, size_t nocts)
Definition: rtxContext.h:189