ASN1C C/C++ Common Runtime  ASN1C v7.4.x
rtxContext.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  *****************************************************************************/
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 
145 struct OSCTXT;
152 typedef int (*OSFreeCtxtAppInfoPtr)(struct OSCTXT* pctxt);
153 
160 typedef int (*OSResetCtxtAppInfoPtr)(struct OSCTXT* pctxt);
161 
169 typedef void (*OSFreeCtxtGlobalPtr)(struct OSCTXT* pctxt);
170 
171 /* Alias for __cdecl modifier; if __cdecl keyword is not supported,
172  * redefine it as empty macro. */
173 
174 #if !defined(OSCDECL)
175 #if defined(_MSC_VER) || defined(__BORLANDC__)
176 #define OSCDECL __cdecl
177 #else
178 #define OSCDECL
179 #endif
180 #endif /* OSCDECL */
181 
189 typedef struct OSCTXT { /* run-time context block */
190  void* pMemHeap; /* internal message memory heap */
191  OSRTBuffer buffer; /* data buffer */
192  OSRTBufSave savedInfo; /* saved buffer info */
193  OSRTErrInfoList errInfo; /* run-time error info */
194  OSUINT32 initCode; /* code double word to indicate init */
195  OSRTFLAGS flags; /* flag bits */
196  OSOCTET level; /* nesting level */
197  OSOCTET state; /* encode/decode process state */
198  OSOCTET diagLevel; /* diagnostic trace level */
199  OSOCTET lastChar; /* last char/byte written or read */
200 #ifndef _NO_STREAM
201  struct OSRTSTREAM* pStream; /* Stream */
202 #else
203  void* pStream; /* Stream placeholder */
204 #endif /* _NO_STREAM */
205  struct OSRTPrintStream *pPrintStrm; /* Print Stream */
206  OSRTDList elemNameStack; /* element name stack */
207 #ifndef _OS_NOPATTERN
208  OSRTDList regExpCache; /* compiled regular expression cache */
209 #endif
210 
219 
220  const OSOCTET* key; /* pointer to run-time key data */
221  OSSIZE keylen; /* run-time key length */
222  OSVoidPtr pXMLInfo; /* XML specific info */
223  OSVoidPtr pASN1Info; /* ASN.1 specific info */
224  OSVoidPtr pLicInfo; /* License specific info */
225  OSVoidPtr pUserData; /* User defined data */
226  OSVoidPtr pGlobalData; /* Global constant data */
227  struct OS3GPPSecParams* p3gppSec; /* 3GPP Security parameters */
228  OSFreeCtxtGlobalPtr gblFreeFunc; /* Global free function */
229  OSVoidPtr ssl; /* SSL stack endpoint */
230  struct OSRTDiagBitFieldList* pBitFldList; /* Bit field trace list */
231  OSUINT16 indent; /* total # of spaces to indent. Used by
232  print-to-stream, JSON encoding, and possibly
233  others. */
234  OSUINT16 version; /* Protocol version */
235 } OSCTXT;
236 
237 #define OSRT_GET_FIRST_ERROR_INFO(pctxt) \
238 (((pctxt)->errInfo.list.head == 0) ? (OSRTErrInfo*)0 : \
239 (OSRTErrInfo*)((pctxt)->errInfo.list.head->data))
240 
241 #define OSRT_GET_LAST_ERROR_INFO(pctxt) \
242 (((pctxt)->errInfo.list.tail == 0) ? (OSRTErrInfo*)0 : \
243 (OSRTErrInfo*)((pctxt)->errInfo.list.tail->data))
244 
248 #ifndef _NO_STREAM
249 
250 #define OSRTISSTREAM(pctxt) \
251 ((pctxt)->pStream != 0 && !((pctxt)->flags & OSDISSTRM))
252 
253 #define OSRTISBUFSTREAM(pctxt) \
254 (OSRTISSTREAM(pctxt) && (0 != ((pctxt)->pStream->flags & OSRTSTRMF_BUFFERED)))
255 
256 #else /* _NO_STREAM */
257 
258 #define OSRTISSTREAM(pctxt) FALSE
259 #define OSRTISBUFSTREAM(pctxt) FALSE
260 
261 #endif /* _NO_STREAM */
262 
263 #define OSRTBUFCUR(pctxt) (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]
264 #define OSRTBUFPTR(pctxt) &(pctxt)->buffer.data[(pctxt)->buffer.byteIndex]
265 #define OSRTBUFFER(pctxt) (pctxt)->buffer.data
266 #define OSRTBUFSIZE(pctxt) (pctxt)->buffer.size
267 
268 #define OSRTBUFSAVE(pctxt) { \
269 (pctxt)->savedInfo.byteIndex = (pctxt)->buffer.byteIndex; \
270 (pctxt)->savedInfo.flags = (pctxt)->flags; }
271 
272 #define OSRTBUFSAVE2(pctxt,pSavedBuf) { \
273 (pSavedBuf)->byteIndex = (pctxt)->buffer.byteIndex; \
274 (pSavedBuf)->bitOffset = (pctxt)->buffer.bitOffset; \
275 (pSavedBuf)->flags = (pctxt)->flags; }
276 
277 #define OSRTBUFRESTORE(pctxt) { \
278 (pctxt)->buffer.byteIndex = (pctxt)->savedInfo.byteIndex; \
279 (pctxt)->flags = (pctxt)->savedInfo.flags; }
280 
281 #define OSRTBUFRESTORE2(pctxt,pSavedBuf) { \
282 (pctxt)->buffer.byteIndex = (pSavedBuf)->byteIndex; \
283 (pctxt)->buffer.bitOffset = (pSavedBuf)->bitOffset; \
284 (pctxt)->flags = (pSavedBuf)->flags; }
285 
286 #define OSRTBYTEALIGNED(pctxt) \
287 ((pctxt)->buffer.bitOffset == 8 || (pctxt)->buffer.bitOffset == 0)
288 
289 /* Pointers to C Run-Time memory allocation functions */
290 
291 typedef void *(OSCDECL *OSMallocFunc ) (OSSIZE size);
292 typedef void *(OSCDECL *OSReallocFunc) (void *ptr, OSSIZE size);
293 typedef void (OSCDECL *OSFreeFunc ) (void *ptr);
294 
295 #ifdef __cplusplus
296 extern "C" {
297 #endif
298 
323 #ifndef rtxInitContext
324 EXTERNRT int rtxInitContext (OSCTXT* pctxt);
325 #endif
326 
341 EXTERNRT int rtxInitContextExt (OSCTXT* pctxt,
342  OSMallocFunc malloc_func,
343  OSReallocFunc realloc_func,
344  OSFreeFunc free_func);
345 
366 EXTERNRT int rtxInitThreadContext (OSCTXT* pctxt, const OSCTXT* pSrcCtxt);
367 
382 EXTERNRT int rtxInitContextUsingKey
383 (OSCTXT* pctxt, const OSOCTET* key, OSSIZE keylen);
384 
403 EXTERNRT int rtxInitContextBuffer
404 (OSCTXT* pctxt, OSOCTET* bufaddr, OSSIZE bufsiz);
405 
429 EXTERNRT int rtxCtxtSetBufPtr
430 (OSCTXT* pctxt, OSOCTET* bufaddr, OSSIZE bufsiz);
431 
443 #define rtxCtxtGetMsgPtr(pctxt) (pctxt)->buffer.data
444 
454 #define rtxCtxtGetMsgLen(pctxt) (pctxt)->buffer.byteIndex
455 
463 EXTERNRT OSSIZE rtxCtxtGetBitOffset (OSCTXT* pctxt);
464 
474 EXTERNRT int rtxCtxtSetBitOffset (OSCTXT* pctxt, OSSIZE offset);
475 
483 EXTERNRT OSSIZE rtxCtxtGetIOByteCount (OSCTXT* pctxt);
484 
494 EXTERNRT int rtxCheckContext (OSCTXT* pctxt);
495 
503 EXTERNRT void rtxFreeContext (OSCTXT* pctxt);
504 
514 EXTERNRT void rtxCopyContext (OSCTXT* pdest, OSCTXT* psrc);
515 
522 EXTERNRT void rtxCtxtSetFlag (OSCTXT* pctxt, OSUINT32 mask);
523 
531 EXTERNRT void rtxCtxtClearFlag (OSCTXT* pctxt, OSUINT32 mask);
532 
539 #define rtxCtxtTestFlag(pctxt,mask) (((pctxt)->flags & mask) != 0)
540 
555 EXTERNRT int rtxCtxtPushArrayElemName
556 (OSCTXT* pctxt, const OSUTF8CHAR* elemName, OSSIZE idx);
557 
570 EXTERNRT int rtxCtxtPushElemName (OSCTXT* pctxt, const OSUTF8CHAR* elemName);
571 
586 EXTERNRT int rtxCtxtPushElemNameCopy
587 (OSCTXT* pctxt, const OSUTF8CHAR* elemName);
588 
603 EXTERNRT int rtxCtxtPushTypeName (OSCTXT* pctxt, const OSUTF8CHAR* typeName);
604 
615 EXTERNRT OSBOOL rtxCtxtPopArrayElemName (OSCTXT* pctxt);
616 
624 EXTERNRT const OSUTF8CHAR* rtxCtxtPopElemName (OSCTXT* pctxt);
625 
633 EXTERNRT void rtxCtxtPopElemNameCopy (OSCTXT* pctxt);
634 
643 EXTERNRT const OSUTF8CHAR* rtxCtxtPopTypeName (OSCTXT* pctxt);
644 
652 #define rtxCtxtPeekElemName(pctxt) \
653 (((pctxt)->elemNameStack.count > 0) ? \
654  (const OSUTF8CHAR*)(pctxt)->elemNameStack.tail->data : (const OSUTF8CHAR*)0)
655 
656 
665 EXTERNRT OSBOOL rtxCtxtContainerHasRemBits(OSCTXT* pctxt);
666 
678 EXTERNRT OSBOOL rtxCtxtContainerEnd(OSCTXT* pctxt);
679 
688 EXTERNRT OSSIZE rtxCtxtGetContainerRemBits(OSCTXT* pctxt);
689 
703 EXTERNRT int rtxCtxtPushContainerBytes(OSCTXT* pctxt, OSSIZE bytes);
704 
718 EXTERNRT int rtxCtxtPushContainerBits(OSCTXT* pctxt, OSSIZE bits);
719 
720 
730 EXTERNRT void rtxCtxtPopContainer(OSCTXT* pctxt);
731 
739 EXTERNRT void rtxCtxtPopAllContainers(OSCTXT* pctxt);
740 
741 EXTERNRT int rtxPreInitContext (OSCTXT* pctxt);
742 EXTERNRT void rtxCtxtSetMemHeap (OSCTXT* pctxt, OSCTXT* pSrcCtxt);
743 
753 EXTERNRT void rtxMemHeapSetFlags (OSCTXT* pctxt, OSUINT32 flags);
754 
763 EXTERNRT void rtxMemHeapClearFlags (OSCTXT* pctxt, OSUINT32 flags);
764 
768 #define rtxByteAlign(pctxt) \
769 if ((pctxt)->buffer.bitOffset != 8) { \
770 (pctxt)->buffer.byteIndex++; (pctxt)->buffer.bitOffset = 8; }
771 
781 EXTERNRT int rtxMarkPos (OSCTXT* pctxt, OSSIZE* ppos);
782 
792 EXTERNRT int rtxResetToPos (OSCTXT* pctxt, OSSIZE pos);
793 
805 EXTERNRT const char* rtxCtxtGetExpDateStr
806 (OSCTXT* pctxt, char* buf, OSSIZE bufsiz);
807 
821 #define rtxCtxtSetProtocolVersion(pctxt,value) (pctxt)->version = value
822 
831 EXTERNRT void rtxLicenseClose(void);
832 
833 
834 #define rtxMarkBitPos(pctxt,ppos,pbitoff) \
835 (*(pbitoff) = (OSUINT8) (pctxt)->buffer.bitOffset, rtxMarkPos (pctxt, ppos))
836 
837 #define rtxResetToBitPos(pctxt,pos,bitoff) \
838 ((pctxt)->buffer.bitOffset = (OSUINT8) bitoff, rtxResetToPos (pctxt, pos))
839 
840 #ifndef _COMPACT
841 #define RTXCTXTPUSHARRAYELEMNAME(pctxt,name,idx) \
842 rtxCtxtPushArrayElemName(pctxt,OSUTF8(name),idx)
843 
844 #define RTXCTXTPOPARRAYELEMNAME(pctxt) \
845 rtxCtxtPopArrayElemName(pctxt)
846 
847 #define RTXCTXTPUSHELEMNAME(pctxt,name) \
848 rtxCtxtPushElemName(pctxt,OSUTF8(name))
849 
850 #define RTXCTXTPOPELEMNAME(pctxt) \
851 rtxCtxtPopElemName(pctxt)
852 
853 #define RTXCTXTPUSHTYPENAME(pctxt,name) \
854 rtxCtxtPushTypeName(pctxt,OSUTF8(name))
855 
856 #define RTXCTXTPOPTYPENAME(pctxt) \
857 rtxCtxtPopTypeName(pctxt)
858 #else
859 #define RTXCTXTPUSHARRAYELEMNAME(pctxt,name,idx)
860 #define RTXCTXTPOPARRAYELEMNAME(pctxt)
861 #define RTXCTXTPUSHELEMNAME(pctxt,name)
862 #define RTXCTXTPOPELEMNAME(pctxt)
863 #define RTXCTXTPUSHTYPENAME(pctxt,name)
864 #define RTXCTXTPOPTYPENAME(pctxt)
865 #endif
866 
867 #ifdef __cplusplus
868 }
869 #endif
870 
873 #endif
int(* OSResetCtxtAppInfoPtr)(struct OSCTXT *pctxt)
Definition: rtxContext.h:160
Definition: rtxContext.h:80
void(* OSFreeCtxtGlobalPtr)(struct OSCTXT *pctxt)
Definition: rtxContext.h:169
void rtxCtxtPopAllContainers(OSCTXT *pctxt)
int rtxCtxtPushContainerBytes(OSCTXT *pctxt, OSSIZE bytes)
void rtxFreeContext(OSCTXT *pctxt)
OSBOOL rtxCtxtPopArrayElemName(OSCTXT *pctxt)
OSRTStack containerEndIndexStack
Definition: rtxContext.h:218
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:189
Definition: rtxStream.h:176
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:152
void rtxCtxtPopContainer(OSCTXT *pctxt)
int rtxInitContext(OSCTXT *pctxt)