ASN1C C/C++ Common Runtime  ASN1C v7.7.x
rtxContext.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2023 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 
337 #ifndef rtxInitContext
338 EXTERNRT int rtxInitContext (OSCTXT* pctxt);
339 #endif
340 
355 EXTERNRT int rtxInitContextExt (OSCTXT* pctxt,
356  OSMallocFunc malloc_func,
357  OSReallocFunc realloc_func,
358  OSFreeFunc free_func);
359 
380 EXTERNRT int rtxInitThreadContext (OSCTXT* pctxt, const OSCTXT* pSrcCtxt);
381 
396 EXTERNRT int rtxInitContextUsingKey
397 (OSCTXT* pctxt, const OSOCTET* key, OSSIZE keylen);
398 
417 EXTERNRT int rtxInitContextBuffer
418 (OSCTXT* pctxt, OSOCTET* bufaddr, OSSIZE bufsiz);
419 
443 EXTERNRT int rtxCtxtSetBufPtr
444 (OSCTXT* pctxt, OSOCTET* bufaddr, OSSIZE bufsiz);
445 
457 #define rtxCtxtGetMsgPtr(pctxt) (pctxt)->buffer.data
458 
468 #define rtxCtxtGetMsgLen(pctxt) (pctxt)->buffer.byteIndex
469 
477 EXTERNRT OSSIZE rtxCtxtGetBitOffset (OSCTXT* pctxt);
478 
488 EXTERNRT int rtxCtxtSetBitOffset (OSCTXT* pctxt, OSSIZE offset);
489 
497 EXTERNRT OSSIZE rtxCtxtGetIOByteCount (OSCTXT* pctxt);
498 
508 EXTERNRT int rtxCheckContext (OSCTXT* pctxt);
509 
517 EXTERNRT void rtxFreeContext (OSCTXT* pctxt);
518 
528 EXTERNRT void rtxCopyContext (OSCTXT* pdest, OSCTXT* psrc);
529 
536 EXTERNRT void rtxCtxtSetFlag (OSCTXT* pctxt, OSUINT32 mask);
537 
545 EXTERNRT void rtxCtxtClearFlag (OSCTXT* pctxt, OSUINT32 mask);
546 
553 #define rtxCtxtTestFlag(pctxt,mask) (((pctxt)->flags & mask) != 0)
554 
569 EXTERNRT int rtxCtxtPushArrayElemName
570 (OSCTXT* pctxt, const OSUTF8CHAR* elemName, OSSIZE idx);
571 
584 EXTERNRT int rtxCtxtPushElemName (OSCTXT* pctxt, const OSUTF8CHAR* elemName);
585 
600 EXTERNRT int rtxCtxtPushElemNameCopy
601 (OSCTXT* pctxt, const OSUTF8CHAR* elemName);
602 
617 EXTERNRT int rtxCtxtPushTypeName (OSCTXT* pctxt, const OSUTF8CHAR* typeName);
618 
629 EXTERNRT OSBOOL rtxCtxtPopArrayElemName (OSCTXT* pctxt);
630 
638 EXTERNRT const OSUTF8CHAR* rtxCtxtPopElemName (OSCTXT* pctxt);
639 
647 EXTERNRT void rtxCtxtPopElemNameCopy (OSCTXT* pctxt);
648 
657 EXTERNRT const OSUTF8CHAR* rtxCtxtPopTypeName (OSCTXT* pctxt);
658 
666 #define rtxCtxtPeekElemName(pctxt) \
667 (((pctxt)->elemNameStack.count > 0) ? \
668  (const OSUTF8CHAR*)(pctxt)->elemNameStack.tail->data : (const OSUTF8CHAR*)0)
669 
670 
679 EXTERNRT OSBOOL rtxCtxtContainerHasRemBits(OSCTXT* pctxt);
680 
692 EXTERNRT OSBOOL rtxCtxtContainerEnd(OSCTXT* pctxt);
693 
702 EXTERNRT OSSIZE rtxCtxtGetContainerRemBits(OSCTXT* pctxt);
703 
717 EXTERNRT int rtxCtxtPushContainerBytes(OSCTXT* pctxt, OSSIZE bytes);
718 
732 EXTERNRT int rtxCtxtPushContainerBits(OSCTXT* pctxt, OSSIZE bits);
733 
734 
744 EXTERNRT void rtxCtxtPopContainer(OSCTXT* pctxt);
745 
753 EXTERNRT void rtxCtxtPopAllContainers(OSCTXT* pctxt);
754 
755 EXTERNRT int rtxPreInitContext (OSCTXT* pctxt);
756 EXTERNRT void rtxCtxtSetMemHeap (OSCTXT* pctxt, OSCTXT* pSrcCtxt);
757 
767 EXTERNRT void rtxMemHeapSetFlags (OSCTXT* pctxt, OSUINT32 flags);
768 
777 EXTERNRT void rtxMemHeapClearFlags (OSCTXT* pctxt, OSUINT32 flags);
778 
782 #define rtxByteAlign(pctxt) \
783 if ((pctxt)->buffer.bitOffset != 8) { \
784 (pctxt)->buffer.byteIndex++; (pctxt)->buffer.bitOffset = 8; }
785 
795 EXTERNRT int rtxCtxtMarkBitPos (OSCTXT* pctxt, OSSIZE* ppos);
796 
806 EXTERNRT int rtxCtxtResetToBitPos (OSCTXT* pctxt, OSSIZE pos);
807 
820 EXTERNRT int rtxMarkPos (OSCTXT* pctxt, OSSIZE* ppos);
821 
831 EXTERNRT int rtxResetToPos (OSCTXT* pctxt, OSSIZE pos);
832 
844 EXTERNRT const char* rtxCtxtGetExpDateStr
845 (OSCTXT* pctxt, char* buf, OSSIZE bufsiz);
846 
860 #define rtxCtxtSetProtocolVersion(pctxt,value) (pctxt)->version = value
861 
870 EXTERNRT void rtxLicenseClose(void);
871 
872 
873 #define rtxMarkBitPos(pctxt,ppos,pbitoff) \
874 (*(pbitoff) = (OSUINT8) (pctxt)->buffer.bitOffset, rtxMarkPos (pctxt, ppos))
875 
876 #define rtxResetToBitPos(pctxt,pos,bitoff) \
877 ((pctxt)->buffer.bitOffset = (OSUINT8) bitoff, rtxResetToPos (pctxt, pos))
878 
879 #ifndef _COMPACT
880 #define RTXCTXTPUSHARRAYELEMNAME(pctxt,name,idx) \
881 rtxCtxtPushArrayElemName(pctxt,OSUTF8(name),idx)
882 
883 #define RTXCTXTPOPARRAYELEMNAME(pctxt) \
884 rtxCtxtPopArrayElemName(pctxt)
885 
886 #define RTXCTXTPUSHELEMNAME(pctxt,name) \
887 rtxCtxtPushElemName(pctxt,OSUTF8(name))
888 
889 #define RTXCTXTPOPELEMNAME(pctxt) \
890 rtxCtxtPopElemName(pctxt)
891 
892 #define RTXCTXTPUSHTYPENAME(pctxt,name) \
893 rtxCtxtPushTypeName(pctxt,OSUTF8(name))
894 
895 #define RTXCTXTPOPTYPENAME(pctxt) \
896 rtxCtxtPopTypeName(pctxt)
897 #else
898 #define RTXCTXTPUSHARRAYELEMNAME(pctxt,name,idx)
899 #define RTXCTXTPOPARRAYELEMNAME(pctxt)
900 #define RTXCTXTPUSHELEMNAME(pctxt,name)
901 #define RTXCTXTPOPELEMNAME(pctxt)
902 #define RTXCTXTPUSHTYPENAME(pctxt,name)
903 #define RTXCTXTPOPTYPENAME(pctxt)
904 #endif
905 
906 #ifdef __cplusplus
907 }
908 #endif
909 
912 #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)