ASN1C C/C++ Common Runtime  ASN1C v7.6.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 pASN1Info; /* ASN.1 specific info */
233  OSVoidPtr pLicInfo; /* License specific info */
234  OSVoidPtr pUserData; /* User defined data */
235  OSVoidPtr pGlobalData; /* Global constant data */
236  struct OS3GPPSecParams* p3gppSec; /* 3GPP Security parameters */
237  OSFreeCtxtGlobalPtr gblFreeFunc; /* Global free function */
238  OSVoidPtr ssl; /* SSL stack endpoint */
239  struct OSRTDiagBitFieldList* pBitFldList; /* Bit field trace list */
240  OSUINT16 indent; /* total # of spaces to indent. Used by
241  print-to-stream, JSON encoding, and possibly
242  others. */
243  OSUINT16 version; /* Protocol version */
244 } OSCTXT;
245 
246 #define OSRT_GET_FIRST_ERROR_INFO(pctxt) \
247 (((pctxt)->errInfo.list.head == 0) ? (OSRTErrInfo*)0 : \
248 (OSRTErrInfo*)((pctxt)->errInfo.list.head->data))
249 
250 #define OSRT_GET_LAST_ERROR_INFO(pctxt) \
251 (((pctxt)->errInfo.list.tail == 0) ? (OSRTErrInfo*)0 : \
252 (OSRTErrInfo*)((pctxt)->errInfo.list.tail->data))
253 
257 #ifndef _NO_STREAM
258 
259 #define OSRTISSTREAM(pctxt) \
260 ((pctxt)->pStream != 0 && !((pctxt)->flags & OSDISSTRM))
261 
262 #define OSRTISBUFSTREAM(pctxt) \
263 (OSRTISSTREAM(pctxt) && (0 != ((pctxt)->pStream->flags & OSRTSTRMF_BUFFERED)))
264 
265 #else /* _NO_STREAM */
266 
267 #define OSRTISSTREAM(pctxt) FALSE
268 #define OSRTISBUFSTREAM(pctxt) FALSE
269 
270 #endif /* _NO_STREAM */
271 
272 #define OSRTBUFCUR(pctxt) (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]
273 #define OSRTBUFPTR(pctxt) &(pctxt)->buffer.data[(pctxt)->buffer.byteIndex]
274 #define OSRTBUFFER(pctxt) (pctxt)->buffer.data
275 #define OSRTBUFSIZE(pctxt) (pctxt)->buffer.size
276 
277 #define OSRTBUFSAVE(pctxt) { \
278 (pctxt)->savedInfo.byteIndex = (pctxt)->buffer.byteIndex; \
279 (pctxt)->savedInfo.flags = (pctxt)->flags; }
280 
281 #define OSRTBUFSAVE2(pctxt,pSavedBuf) { \
282 (pSavedBuf)->byteIndex = (pctxt)->buffer.byteIndex; \
283 (pSavedBuf)->bitOffset = (pctxt)->buffer.bitOffset; \
284 (pSavedBuf)->flags = (pctxt)->flags; }
285 
286 #define OSRTBUFRESTORE(pctxt) { \
287 (pctxt)->buffer.byteIndex = (pctxt)->savedInfo.byteIndex; \
288 (pctxt)->flags = (pctxt)->savedInfo.flags; }
289 
290 #define OSRTBUFRESTORE2(pctxt,pSavedBuf) { \
291 (pctxt)->buffer.byteIndex = (pSavedBuf)->byteIndex; \
292 (pctxt)->buffer.bitOffset = (pSavedBuf)->bitOffset; \
293 (pctxt)->flags = (pSavedBuf)->flags; }
294 
295 #define OSRTBYTEALIGNED(pctxt) \
296 ((pctxt)->buffer.bitOffset == 8 || (pctxt)->buffer.bitOffset == 0)
297 
298 /* Pointers to C Run-Time memory allocation functions */
299 
300 typedef void *(OSCDECL *OSMallocFunc ) (OSSIZE size);
301 typedef void *(OSCDECL *OSReallocFunc) (void *ptr, OSSIZE size);
302 typedef void (OSCDECL *OSFreeFunc ) (void *ptr);
303 
304 #ifdef __cplusplus
305 extern "C" {
306 #endif
307 
332 #ifndef rtxInitContext
333 EXTERNRT int rtxInitContext (OSCTXT* pctxt);
334 #endif
335 
350 EXTERNRT int rtxInitContextExt (OSCTXT* pctxt,
351  OSMallocFunc malloc_func,
352  OSReallocFunc realloc_func,
353  OSFreeFunc free_func);
354 
375 EXTERNRT int rtxInitThreadContext (OSCTXT* pctxt, const OSCTXT* pSrcCtxt);
376 
391 EXTERNRT int rtxInitContextUsingKey
392 (OSCTXT* pctxt, const OSOCTET* key, OSSIZE keylen);
393 
412 EXTERNRT int rtxInitContextBuffer
413 (OSCTXT* pctxt, OSOCTET* bufaddr, OSSIZE bufsiz);
414 
438 EXTERNRT int rtxCtxtSetBufPtr
439 (OSCTXT* pctxt, OSOCTET* bufaddr, OSSIZE bufsiz);
440 
452 #define rtxCtxtGetMsgPtr(pctxt) (pctxt)->buffer.data
453 
463 #define rtxCtxtGetMsgLen(pctxt) (pctxt)->buffer.byteIndex
464 
472 EXTERNRT OSSIZE rtxCtxtGetBitOffset (OSCTXT* pctxt);
473 
483 EXTERNRT int rtxCtxtSetBitOffset (OSCTXT* pctxt, OSSIZE offset);
484 
492 EXTERNRT OSSIZE rtxCtxtGetIOByteCount (OSCTXT* pctxt);
493 
503 EXTERNRT int rtxCheckContext (OSCTXT* pctxt);
504 
512 EXTERNRT void rtxFreeContext (OSCTXT* pctxt);
513 
523 EXTERNRT void rtxCopyContext (OSCTXT* pdest, OSCTXT* psrc);
524 
531 EXTERNRT void rtxCtxtSetFlag (OSCTXT* pctxt, OSUINT32 mask);
532 
540 EXTERNRT void rtxCtxtClearFlag (OSCTXT* pctxt, OSUINT32 mask);
541 
548 #define rtxCtxtTestFlag(pctxt,mask) (((pctxt)->flags & mask) != 0)
549 
564 EXTERNRT int rtxCtxtPushArrayElemName
565 (OSCTXT* pctxt, const OSUTF8CHAR* elemName, OSSIZE idx);
566 
579 EXTERNRT int rtxCtxtPushElemName (OSCTXT* pctxt, const OSUTF8CHAR* elemName);
580 
595 EXTERNRT int rtxCtxtPushElemNameCopy
596 (OSCTXT* pctxt, const OSUTF8CHAR* elemName);
597 
612 EXTERNRT int rtxCtxtPushTypeName (OSCTXT* pctxt, const OSUTF8CHAR* typeName);
613 
624 EXTERNRT OSBOOL rtxCtxtPopArrayElemName (OSCTXT* pctxt);
625 
633 EXTERNRT const OSUTF8CHAR* rtxCtxtPopElemName (OSCTXT* pctxt);
634 
642 EXTERNRT void rtxCtxtPopElemNameCopy (OSCTXT* pctxt);
643 
652 EXTERNRT const OSUTF8CHAR* rtxCtxtPopTypeName (OSCTXT* pctxt);
653 
661 #define rtxCtxtPeekElemName(pctxt) \
662 (((pctxt)->elemNameStack.count > 0) ? \
663  (const OSUTF8CHAR*)(pctxt)->elemNameStack.tail->data : (const OSUTF8CHAR*)0)
664 
665 
674 EXTERNRT OSBOOL rtxCtxtContainerHasRemBits(OSCTXT* pctxt);
675 
687 EXTERNRT OSBOOL rtxCtxtContainerEnd(OSCTXT* pctxt);
688 
697 EXTERNRT OSSIZE rtxCtxtGetContainerRemBits(OSCTXT* pctxt);
698 
712 EXTERNRT int rtxCtxtPushContainerBytes(OSCTXT* pctxt, OSSIZE bytes);
713 
727 EXTERNRT int rtxCtxtPushContainerBits(OSCTXT* pctxt, OSSIZE bits);
728 
729 
739 EXTERNRT void rtxCtxtPopContainer(OSCTXT* pctxt);
740 
748 EXTERNRT void rtxCtxtPopAllContainers(OSCTXT* pctxt);
749 
750 EXTERNRT int rtxPreInitContext (OSCTXT* pctxt);
751 EXTERNRT void rtxCtxtSetMemHeap (OSCTXT* pctxt, OSCTXT* pSrcCtxt);
752 
762 EXTERNRT void rtxMemHeapSetFlags (OSCTXT* pctxt, OSUINT32 flags);
763 
772 EXTERNRT void rtxMemHeapClearFlags (OSCTXT* pctxt, OSUINT32 flags);
773 
777 #define rtxByteAlign(pctxt) \
778 if ((pctxt)->buffer.bitOffset != 8) { \
779 (pctxt)->buffer.byteIndex++; (pctxt)->buffer.bitOffset = 8; }
780 
790 EXTERNRT int rtxMarkPos (OSCTXT* pctxt, OSSIZE* ppos);
791 
801 EXTERNRT int rtxResetToPos (OSCTXT* pctxt, OSSIZE pos);
802 
814 EXTERNRT const char* rtxCtxtGetExpDateStr
815 (OSCTXT* pctxt, char* buf, OSSIZE bufsiz);
816 
830 #define rtxCtxtSetProtocolVersion(pctxt,value) (pctxt)->version = value
831 
840 EXTERNRT void rtxLicenseClose(void);
841 
842 
843 #define rtxMarkBitPos(pctxt,ppos,pbitoff) \
844 (*(pbitoff) = (OSUINT8) (pctxt)->buffer.bitOffset, rtxMarkPos (pctxt, ppos))
845 
846 #define rtxResetToBitPos(pctxt,pos,bitoff) \
847 ((pctxt)->buffer.bitOffset = (OSUINT8) bitoff, rtxResetToPos (pctxt, pos))
848 
849 #ifndef _COMPACT
850 #define RTXCTXTPUSHARRAYELEMNAME(pctxt,name,idx) \
851 rtxCtxtPushArrayElemName(pctxt,OSUTF8(name),idx)
852 
853 #define RTXCTXTPOPARRAYELEMNAME(pctxt) \
854 rtxCtxtPopArrayElemName(pctxt)
855 
856 #define RTXCTXTPUSHELEMNAME(pctxt,name) \
857 rtxCtxtPushElemName(pctxt,OSUTF8(name))
858 
859 #define RTXCTXTPOPELEMNAME(pctxt) \
860 rtxCtxtPopElemName(pctxt)
861 
862 #define RTXCTXTPUSHTYPENAME(pctxt,name) \
863 rtxCtxtPushTypeName(pctxt,OSUTF8(name))
864 
865 #define RTXCTXTPOPTYPENAME(pctxt) \
866 rtxCtxtPopTypeName(pctxt)
867 #else
868 #define RTXCTXTPUSHARRAYELEMNAME(pctxt,name,idx)
869 #define RTXCTXTPOPARRAYELEMNAME(pctxt)
870 #define RTXCTXTPUSHELEMNAME(pctxt,name)
871 #define RTXCTXTPOPELEMNAME(pctxt)
872 #define RTXCTXTPUSHTYPENAME(pctxt,name)
873 #define RTXCTXTPOPTYPENAME(pctxt)
874 #endif
875 
876 #ifdef __cplusplus
877 }
878 #endif
879 
882 #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)
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)
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)