ASN1C C/C++ Common Runtime  ASN1C v7.8.x
rtxContext.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2022 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  *****************************************************************************/
28 #ifndef _RTXCONTEXT_H_
29 #define _RTXCONTEXT_H_
30 
31 #include "rtxsrc/rtxDList.h"
32 #include "rtxsrc/rtxStack.h"
33 
34 #define OSRTENCBUFSIZ 1024 /* dynamic encode buffer extent size */
35 
40 /* run-time error info structures */
41 
42 #define OSRTERRSTKSIZ 8 /* error stack size */
43 #define OSRTMAXERRPRM 5 /* maximum error parameters */
44 
52 typedef struct {
53  const OSUTF8CHAR* module;
54  OSINT32 lineno;
55 } OSRTErrLocn;
56 
67 typedef struct {
68  OSRTErrLocn stack[OSRTERRSTKSIZ];
69  OSINT16 status;
70  OSUINT8 stkx;
71  OSUINT8 parmcnt;
72  OSUTF8CHAR* parms[OSRTMAXERRPRM];
73  OSUTF8CHAR* elemName;
74  OSBOOL fatal; /* true if fatal error; false is non-fatal.
75  Non-fatal errors do not prevent an operation
76  from continuing, but are genuine errors.
77  */
78 } OSRTErrInfo;
79 
80 typedef struct {
81  OSRTDList list; /* list of errors */
82  OSRTErrInfo reserved; /* error info elem, used if nomem to alloc */
83  OSRTDListNode reservedNode; /* node placeholder for errInfo elem */
85 
94 typedef struct {
95  OSOCTET* data; /* pointer to start of data buffer */
96  OSSIZE byteIndex; /* byte index */
97  OSSIZE size; /* current buffer size */
98  OSINT16 bitOffset; /* current bit offset (8 - 1) */
99  OSBOOL dynamic; /* is buffer dynamic? */
100  OSBOOL aligned; /* is buffer byte aligned? */
101 } OSRTBuffer;
102 
103 typedef OSUINT32 OSRTFLAGS;
104 
111 typedef struct {
112  OSSIZE byteIndex; /* byte index */
113  OSINT16 bitOffset; /* current bit offset (8 - 1) */
114  OSRTFLAGS flags; /* flag bits */
115 } OSRTBufSave;
116 
117 
121 typedef struct {
122  OSSIZE byteIndex;
123  OSINT16 bitOffset; /*8..1*/
124 } OSBufferIndex;
125 
126 
127 /* OSRTCTXT flag mask values : bits 32 - 16 are for common flags, bits */
128 /* 15 - 0 are reserved for application specific flags */
129 
130 #define OSDIAG 0x80000000 /* diagnostic tracing enabled */
131 #define OSTRACE 0x40000000 /* tracing enabled */
132 #define OSDISSTRM 0x20000000 /* disable stream encode/decode */
133 #define OSNOSTRMBACKOFF 0x08000000 /* stream mark/reset funcs is not used */
134 #define OS3GMOBORIG 0x04000000 /* 3G mobile-originated (net to MS) */
135 /*
136 OSCONTCLOSED: Flag indicating nothing more should be encoded to the current
137 container. This is set when a variable length field whose encoding space is
138 determined by the container is encoded.
139 Used by 3GPP encoders.
140 */
141 #define OSCONTCLOSED 0x02000000 /* 3G container closed. */
142 #define OSRESERVED1 0x01000000 /* reserved */
143 #define OSBUFSYSALLOC 0x00800000 /* ctxt buf allocated using sys alloc */
144 #define OSLICCHECKIN 0x00400000 /* check in ifloat license on free */
145 
150 #define OSNOWHITESPACE 0x00400000 /* Turn off indentation whitesapce */
151 
152 struct OSCTXT;
159 typedef int (*OSFreeCtxtAppInfoPtr)(struct OSCTXT* pctxt);
160 
167 typedef int (*OSResetCtxtAppInfoPtr)(struct OSCTXT* pctxt);
168 
176 typedef void (*OSFreeCtxtGlobalPtr)(struct OSCTXT* pctxt);
177 
178 /* Alias for __cdecl modifier; if __cdecl keyword is not supported,
179  * redefine it as empty macro. */
180 
181 #if !defined(OSCDECL)
182 #if defined(_MSC_VER) || defined(__BORLANDC__)
183 #define OSCDECL __cdecl
184 #else
185 #define OSCDECL
186 #endif
187 #endif /* OSCDECL */
188 
189 #define pLicInfo pli709
190 
198 typedef struct OSCTXT { /* run-time context block */
199  void* pMemHeap; /* internal message memory heap */
200  OSRTBuffer buffer; /* data buffer */
201  OSRTBufSave savedInfo; /* saved buffer info */
202  OSRTErrInfoList errInfo; /* run-time error info */
203  OSUINT32 initCode; /* code double word to indicate init */
204  OSRTFLAGS flags; /* flag bits */
205  OSOCTET level; /* nesting level */
206  OSOCTET state; /* encode/decode process state */
207  OSOCTET diagLevel; /* diagnostic trace level */
208  OSOCTET lastChar; /* last char/byte written or read */
209 #ifndef _NO_STREAM
210  struct OSRTSTREAM* pStream; /* Stream */
211 #else
212  void* pStream; /* Stream placeholder */
213 #endif /* _NO_STREAM */
214  struct OSRTPrintStream *pPrintStrm; /* Print Stream */
215  OSRTDList elemNameStack; /* element name stack */
216 #ifndef _OS_NOPATTERN
217  OSRTDList regExpCache; /* compiled regular expression cache */
218 #endif
219 
228 
229  const OSOCTET* key; /* pointer to run-time key data */
230  OSSIZE keylen; /* run-time key length */
231  OSVoidPtr pXMLInfo; /* XML specific info */
232  OSVoidPtr pEXIInfo; /* EXI specific info */
233  OSVoidPtr pASN1Info; /* ASN.1 specific info */
234  OSVoidPtr pLicInfo; /* License specific info */
235  OSVoidPtr pUserData; /* User defined data */
236  OSVoidPtr pGlobalData; /* Global constant data */
237  struct OS3GPPSecParams* p3gppSec; /* 3GPP Security parameters */
238  OSFreeCtxtGlobalPtr gblFreeFunc; /* Global free function */
239  OSVoidPtr ssl; /* SSL stack endpoint */
240  struct OSRTDiagBitFieldList* pBitFldList; /* Bit field trace list */
241  OSUINT16 indent; /* total # of spaces to indent. Used by
242  print-to-stream, JSON encoding, and possibly
243  others. */
244  OSUINT16 version; /* Protocol version */
245 } OSCTXT;
246 
247 #define OSRT_GET_FIRST_ERROR_INFO(pctxt) \
248 (((pctxt)->errInfo.list.head == 0) ? (OSRTErrInfo*)0 : \
249 (OSRTErrInfo*)((pctxt)->errInfo.list.head->data))
250 
251 #define OSRT_GET_LAST_ERROR_INFO(pctxt) \
252 (((pctxt)->errInfo.list.tail == 0) ? (OSRTErrInfo*)0 : \
253 (OSRTErrInfo*)((pctxt)->errInfo.list.tail->data))
254 
258 #ifndef _NO_STREAM
259 
260 #define OSRTISSTREAM(pctxt) \
261 ((pctxt)->pStream != 0 && !((pctxt)->flags & OSDISSTRM))
262 
263 #define OSRTISBUFSTREAM(pctxt) \
264 (OSRTISSTREAM(pctxt) && (0 != ((pctxt)->pStream->flags & OSRTSTRMF_BUFFERED)))
265 
266 #else /* _NO_STREAM */
267 
268 #define OSRTISSTREAM(pctxt) FALSE
269 #define OSRTISBUFSTREAM(pctxt) FALSE
270 
271 #endif /* _NO_STREAM */
272 
273 #define OSRTBUFCUR(pctxt) (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]
274 #define OSRTBUFPTR(pctxt) &(pctxt)->buffer.data[(pctxt)->buffer.byteIndex]
275 #define OSRTBUFFER(pctxt) (pctxt)->buffer.data
276 #define OSRTBUFSIZE(pctxt) (pctxt)->buffer.size
277 
278 #define OSRTBUFSAVE(pctxt) { \
279 (pctxt)->savedInfo.byteIndex = (pctxt)->buffer.byteIndex; \
280 (pctxt)->savedInfo.flags = (pctxt)->flags; }
281 
282 #define OSRTBUFSAVE2(pctxt,pSavedBuf) { \
283 (pSavedBuf)->byteIndex = (pctxt)->buffer.byteIndex; \
284 (pSavedBuf)->bitOffset = (pctxt)->buffer.bitOffset; \
285 (pSavedBuf)->flags = (pctxt)->flags; }
286 
287 #define OSRTBUFRESTORE(pctxt) { \
288 (pctxt)->buffer.byteIndex = (pctxt)->savedInfo.byteIndex; \
289 (pctxt)->flags = (pctxt)->savedInfo.flags; }
290 
291 #define OSRTBUFRESTORE2(pctxt,pSavedBuf) { \
292 (pctxt)->buffer.byteIndex = (pSavedBuf)->byteIndex; \
293 (pctxt)->buffer.bitOffset = (pSavedBuf)->bitOffset; \
294 (pctxt)->flags = (pSavedBuf)->flags; }
295 
296 #define OSRTBYTEALIGNED(pctxt) \
297 ((pctxt)->buffer.bitOffset == 8 || (pctxt)->buffer.bitOffset == 0)
298 
299 /* Pointers to C Run-Time memory allocation functions */
300 
301 typedef void *(OSCDECL *OSMallocFunc ) (OSSIZE size);
302 typedef void *(OSCDECL *OSReallocFunc) (void *ptr, OSSIZE size);
303 typedef void (OSCDECL *OSFreeFunc ) (void *ptr);
304 
305 #ifdef __cplusplus
306 extern "C" {
307 #endif
308 
338 #ifndef rtxInitContext
339 EXTERNRT int rtxInitContext (OSCTXT* pctxt);
340 #endif
341 
356 EXTERNRT int rtxInitContextExt (OSCTXT* pctxt,
357  OSMallocFunc malloc_func,
358  OSReallocFunc realloc_func,
359  OSFreeFunc free_func);
360 
381 EXTERNRT int rtxInitThreadContext (OSCTXT* pctxt, const OSCTXT* pSrcCtxt);
382 
397 EXTERNRT int rtxInitContextUsingKey
398 (OSCTXT* pctxt, const OSOCTET* key, OSSIZE keylen);
399 
418 EXTERNRT int rtxInitContextBuffer
419 (OSCTXT* pctxt, OSOCTET* bufaddr, OSSIZE bufsiz);
420 
444 EXTERNRT int rtxCtxtSetBufPtr
445 (OSCTXT* pctxt, OSOCTET* bufaddr, OSSIZE bufsiz);
446 
458 #define rtxCtxtGetMsgPtr(pctxt) (pctxt)->buffer.data
459 
469 #define rtxCtxtGetMsgLen(pctxt) (pctxt)->buffer.byteIndex
470 
478 EXTERNRT OSSIZE rtxCtxtGetBitOffset (OSCTXT* pctxt);
479 
489 EXTERNRT int rtxCtxtSetBitOffset (OSCTXT* pctxt, OSSIZE offset);
490 
498 EXTERNRT OSSIZE rtxCtxtGetIOByteCount (OSCTXT* pctxt);
499 
509 EXTERNRT int rtxCheckContext (OSCTXT* pctxt);
510 
518 EXTERNRT void rtxFreeContext (OSCTXT* pctxt);
519 
529 EXTERNRT void rtxCopyContext (OSCTXT* pdest, OSCTXT* psrc);
530 
537 EXTERNRT void rtxCtxtSetFlag (OSCTXT* pctxt, OSUINT32 mask);
538 
546 EXTERNRT void rtxCtxtClearFlag (OSCTXT* pctxt, OSUINT32 mask);
547 
554 #define rtxCtxtTestFlag(pctxt,mask) (((pctxt)->flags & mask) != 0)
555 
570 EXTERNRT int rtxCtxtPushArrayElemName
571 (OSCTXT* pctxt, const OSUTF8CHAR* elemName, OSSIZE idx);
572 
585 EXTERNRT int rtxCtxtPushElemName (OSCTXT* pctxt, const OSUTF8CHAR* elemName);
586 
601 EXTERNRT int rtxCtxtPushElemNameCopy
602 (OSCTXT* pctxt, const OSUTF8CHAR* elemName);
603 
618 EXTERNRT int rtxCtxtPushTypeName (OSCTXT* pctxt, const OSUTF8CHAR* typeName);
619 
630 EXTERNRT OSBOOL rtxCtxtPopArrayElemName (OSCTXT* pctxt);
631 
639 EXTERNRT const OSUTF8CHAR* rtxCtxtPopElemName (OSCTXT* pctxt);
640 
648 EXTERNRT void rtxCtxtPopElemNameCopy (OSCTXT* pctxt);
649 
658 EXTERNRT const OSUTF8CHAR* rtxCtxtPopTypeName (OSCTXT* pctxt);
659 
667 #define rtxCtxtPeekElemName(pctxt) \
668 (((pctxt)->elemNameStack.count > 0) ? \
669  (const OSUTF8CHAR*)(pctxt)->elemNameStack.tail->data : (const OSUTF8CHAR*)0)
670 
671 
680 EXTERNRT OSBOOL rtxCtxtContainerHasRemBits(OSCTXT* pctxt);
681 
693 EXTERNRT OSBOOL rtxCtxtContainerEnd(OSCTXT* pctxt);
694 
703 EXTERNRT OSSIZE rtxCtxtGetContainerRemBits(OSCTXT* pctxt);
704 
718 EXTERNRT int rtxCtxtPushContainerBytes(OSCTXT* pctxt, OSSIZE bytes);
719 
733 EXTERNRT int rtxCtxtPushContainerBits(OSCTXT* pctxt, OSSIZE bits);
734 
735 
745 EXTERNRT void rtxCtxtPopContainer(OSCTXT* pctxt);
746 
754 EXTERNRT void rtxCtxtPopAllContainers(OSCTXT* pctxt);
755 
756 EXTERNRT int rtxPreInitContext (OSCTXT* pctxt);
757 EXTERNRT void rtxCtxtSetMemHeap (OSCTXT* pctxt, OSCTXT* pSrcCtxt);
758 
768 EXTERNRT void rtxMemHeapSetFlags (OSCTXT* pctxt, OSUINT32 flags);
769 
778 EXTERNRT void rtxMemHeapClearFlags (OSCTXT* pctxt, OSUINT32 flags);
779 
783 #define rtxByteAlign(pctxt) \
784 if ((pctxt)->buffer.bitOffset != 8) { \
785 (pctxt)->buffer.byteIndex++; (pctxt)->buffer.bitOffset = 8; }
786 
796 EXTERNRT int rtxCtxtMarkBitPos (OSCTXT* pctxt, OSSIZE* ppos);
797 
807 EXTERNRT int rtxCtxtResetToBitPos (OSCTXT* pctxt, OSSIZE pos);
808 
821 EXTERNRT int rtxMarkPos (OSCTXT* pctxt, OSSIZE* ppos);
822 
832 EXTERNRT int rtxResetToPos (OSCTXT* pctxt, OSSIZE pos);
833 
845 EXTERNRT const char* rtxCtxtGetExpDateStr
846 (OSCTXT* pctxt, char* buf, OSSIZE bufsiz);
847 
861 #define rtxCtxtSetProtocolVersion(pctxt,value) (pctxt)->version = value
862 
871 EXTERNRT void rtxLicenseClose(void);
872 
873 
874 #define rtxMarkBitPos(pctxt,ppos,pbitoff) \
875 (*(pbitoff) = (OSUINT8) (pctxt)->buffer.bitOffset, rtxMarkPos (pctxt, ppos))
876 
877 #define rtxResetToBitPos(pctxt,pos,bitoff) \
878 ((pctxt)->buffer.bitOffset = (OSUINT8) bitoff, rtxResetToPos (pctxt, pos))
879 
880 #ifndef _COMPACT
881 #define RTXCTXTPUSHARRAYELEMNAME(pctxt,name,idx) \
882 rtxCtxtPushArrayElemName(pctxt,OSUTF8(name),idx)
883 
884 #define RTXCTXTPOPARRAYELEMNAME(pctxt) \
885 rtxCtxtPopArrayElemName(pctxt)
886 
887 #define RTXCTXTPUSHELEMNAME(pctxt,name) \
888 rtxCtxtPushElemName(pctxt,OSUTF8(name))
889 
890 #define RTXCTXTPOPELEMNAME(pctxt) \
891 rtxCtxtPopElemName(pctxt)
892 
893 #define RTXCTXTPUSHTYPENAME(pctxt,name) \
894 rtxCtxtPushTypeName(pctxt,OSUTF8(name))
895 
896 #define RTXCTXTPOPTYPENAME(pctxt) \
897 rtxCtxtPopTypeName(pctxt)
898 #else
899 #define RTXCTXTPUSHARRAYELEMNAME(pctxt,name,idx)
900 #define RTXCTXTPOPARRAYELEMNAME(pctxt)
901 #define RTXCTXTPUSHELEMNAME(pctxt,name)
902 #define RTXCTXTPOPELEMNAME(pctxt)
903 #define RTXCTXTPUSHTYPENAME(pctxt,name)
904 #define RTXCTXTPOPTYPENAME(pctxt)
905 #endif
906 
907 #ifdef __cplusplus
908 }
909 #endif
910 
913 #endif
int(* OSResetCtxtAppInfoPtr)(struct OSCTXT *pctxt)
Definition: rtxContext.h:167
Definition: rtxContext.h:80
void(* OSFreeCtxtGlobalPtr)(struct OSCTXT *pctxt)
Definition: rtxContext.h:176
void rtxCtxtPopAllContainers(OSCTXT *pctxt)
int rtxCtxtPushContainerBytes(OSCTXT *pctxt, OSSIZE bytes)
void rtxFreeContext(OSCTXT *pctxt)
OSBOOL rtxCtxtPopArrayElemName(OSCTXT *pctxt)
int rtxCtxtMarkBitPos(OSCTXT *pctxt, OSSIZE *ppos)
OSRTStack containerEndIndexStack
Definition: rtxContext.h:227
void rtxCtxtPopElemNameCopy(OSCTXT *pctxt)
const OSUTF8CHAR * rtxCtxtPopElemName(OSCTXT *pctxt)
Definition: rtxDList.h:64
void rtxMemHeapClearFlags(OSCTXT *pctxt, OSUINT32 flags)
int rtxCtxtSetBufPtr(OSCTXT *pctxt, OSOCTET *bufaddr, OSSIZE bufsiz)
int rtxInitThreadContext(OSCTXT *pctxt, const OSCTXT *pSrcCtxt)
int rtxCtxtPushElemName(OSCTXT *pctxt, const OSUTF8CHAR *elemName)
int rtxInitContextUsingKey(OSCTXT *pctxt, const OSOCTET *key, OSSIZE keylen)
void rtxMemHeapSetFlags(OSCTXT *pctxt, OSUINT32 flags)
Definition: rtxContext.h:111
Definition: rtxContext.h:121
int rtxCtxtPushTypeName(OSCTXT *pctxt, const OSUTF8CHAR *typeName)
int rtxCtxtPushArrayElemName(OSCTXT *pctxt, const OSUTF8CHAR *elemName, OSSIZE idx)
int rtxCheckContext(OSCTXT *pctxt)
const OSUTF8CHAR * rtxCtxtPopTypeName(OSCTXT *pctxt)
Definition: rtxContext.h:94
const char * rtxCtxtGetExpDateStr(OSCTXT *pctxt, char *buf, OSSIZE bufsiz)
int rtxCtxtResetToBitPos(OSCTXT *pctxt, OSSIZE pos)
Definition: rtxDList.h:52
OSSIZE rtxCtxtGetIOByteCount(OSCTXT *pctxt)
Definition: rtxPrintStream.h:51
void rtxCopyContext(OSCTXT *pdest, OSCTXT *psrc)
int rtxInitContextBuffer(OSCTXT *pctxt, OSOCTET *bufaddr, OSSIZE bufsiz)
int rtxCtxtPushElemNameCopy(OSCTXT *pctxt, const OSUTF8CHAR *elemName)
OSSIZE rtxCtxtGetBitOffset(OSCTXT *pctxt)
void rtxCtxtClearFlag(OSCTXT *pctxt, OSUINT32 mask)
Definition: rtxContext.h:67
int rtxMarkPos(OSCTXT *pctxt, OSSIZE *ppos)
OSSIZE rtxCtxtGetContainerRemBits(OSCTXT *pctxt)
int rtxCtxtSetBitOffset(OSCTXT *pctxt, OSSIZE offset)
Definition: rtxContext.h:198
Definition: rtxStream.h:184
Definition: rtxStack.h:48
void rtxCtxtSetFlag(OSCTXT *pctxt, OSUINT32 mask)
int rtxCtxtPushContainerBits(OSCTXT *pctxt, OSSIZE bits)
void rtxLicenseClose(void)
OSBOOL rtxCtxtContainerEnd(OSCTXT *pctxt)
int rtxResetToPos(OSCTXT *pctxt, OSSIZE pos)
Definition: rtxContext.h:52
int rtxInitContextExt(OSCTXT *pctxt, OSMallocFunc malloc_func, OSReallocFunc realloc_func, OSFreeFunc free_func)
OSBOOL rtxCtxtContainerHasRemBits(OSCTXT *pctxt)
int(* OSFreeCtxtAppInfoPtr)(struct OSCTXT *pctxt)
Definition: rtxContext.h:159
void rtxCtxtPopContainer(OSCTXT *pctxt)
int rtxInitContext(OSCTXT *pctxt)