ASN1C C/C++ Common Runtime  ASN1C v7.5.x
rtxContext.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2021 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 
149 #define OSNOWHITESPACE 0x00400000 /* Turn off indentation whitesapce */
150 
151 struct OSCTXT;
158 typedef int (*OSFreeCtxtAppInfoPtr)(struct OSCTXT* pctxt);
159 
166 typedef int (*OSResetCtxtAppInfoPtr)(struct OSCTXT* pctxt);
167 
175 typedef void (*OSFreeCtxtGlobalPtr)(struct OSCTXT* pctxt);
176 
177 /* Alias for __cdecl modifier; if __cdecl keyword is not supported,
178  * redefine it as empty macro. */
179 
180 #if !defined(OSCDECL)
181 #if defined(_MSC_VER) || defined(__BORLANDC__)
182 #define OSCDECL __cdecl
183 #else
184 #define OSCDECL
185 #endif
186 #endif /* OSCDECL */
187 
188 #define pLicInfo pli709
189 
197 typedef struct OSCTXT { /* run-time context block */
198  void* pMemHeap; /* internal message memory heap */
199  OSRTBuffer buffer; /* data buffer */
200  OSRTBufSave savedInfo; /* saved buffer info */
201  OSRTErrInfoList errInfo; /* run-time error info */
202  OSUINT32 initCode; /* code double word to indicate init */
203  OSRTFLAGS flags; /* flag bits */
204  OSOCTET level; /* nesting level */
205  OSOCTET state; /* encode/decode process state */
206  OSOCTET diagLevel; /* diagnostic trace level */
207  OSOCTET lastChar; /* last char/byte written or read */
208 #ifndef _NO_STREAM
209  struct OSRTSTREAM* pStream; /* Stream */
210 #else
211  void* pStream; /* Stream placeholder */
212 #endif /* _NO_STREAM */
213  struct OSRTPrintStream *pPrintStrm; /* Print Stream */
214  OSRTDList elemNameStack; /* element name stack */
215 #ifndef _OS_NOPATTERN
216  OSRTDList regExpCache; /* compiled regular expression cache */
217 #endif
218 
227 
228  const OSOCTET* key; /* pointer to run-time key data */
229  OSSIZE keylen; /* run-time key length */
230  OSVoidPtr pXMLInfo; /* XML specific info */
231  OSVoidPtr pASN1Info; /* ASN.1 specific info */
232  OSVoidPtr pLicInfo; /* License specific info */
233  OSVoidPtr pUserData; /* User defined data */
234  OSVoidPtr pGlobalData; /* Global constant data */
235  struct OS3GPPSecParams* p3gppSec; /* 3GPP Security parameters */
236  OSFreeCtxtGlobalPtr gblFreeFunc; /* Global free function */
237  OSVoidPtr ssl; /* SSL stack endpoint */
238  struct OSRTDiagBitFieldList* pBitFldList; /* Bit field trace list */
239  OSUINT16 indent; /* total # of spaces to indent. Used by
240  print-to-stream, JSON encoding, and possibly
241  others. */
242  OSUINT16 version; /* Protocol version */
243 } OSCTXT;
244 
245 #define OSRT_GET_FIRST_ERROR_INFO(pctxt) \
246 (((pctxt)->errInfo.list.head == 0) ? (OSRTErrInfo*)0 : \
247 (OSRTErrInfo*)((pctxt)->errInfo.list.head->data))
248 
249 #define OSRT_GET_LAST_ERROR_INFO(pctxt) \
250 (((pctxt)->errInfo.list.tail == 0) ? (OSRTErrInfo*)0 : \
251 (OSRTErrInfo*)((pctxt)->errInfo.list.tail->data))
252 
256 #ifndef _NO_STREAM
257 
258 #define OSRTISSTREAM(pctxt) \
259 ((pctxt)->pStream != 0 && !((pctxt)->flags & OSDISSTRM))
260 
261 #define OSRTISBUFSTREAM(pctxt) \
262 (OSRTISSTREAM(pctxt) && (0 != ((pctxt)->pStream->flags & OSRTSTRMF_BUFFERED)))
263 
264 #else /* _NO_STREAM */
265 
266 #define OSRTISSTREAM(pctxt) FALSE
267 #define OSRTISBUFSTREAM(pctxt) FALSE
268 
269 #endif /* _NO_STREAM */
270 
271 #define OSRTBUFCUR(pctxt) (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]
272 #define OSRTBUFPTR(pctxt) &(pctxt)->buffer.data[(pctxt)->buffer.byteIndex]
273 #define OSRTBUFFER(pctxt) (pctxt)->buffer.data
274 #define OSRTBUFSIZE(pctxt) (pctxt)->buffer.size
275 
276 #define OSRTBUFSAVE(pctxt) { \
277 (pctxt)->savedInfo.byteIndex = (pctxt)->buffer.byteIndex; \
278 (pctxt)->savedInfo.flags = (pctxt)->flags; }
279 
280 #define OSRTBUFSAVE2(pctxt,pSavedBuf) { \
281 (pSavedBuf)->byteIndex = (pctxt)->buffer.byteIndex; \
282 (pSavedBuf)->bitOffset = (pctxt)->buffer.bitOffset; \
283 (pSavedBuf)->flags = (pctxt)->flags; }
284 
285 #define OSRTBUFRESTORE(pctxt) { \
286 (pctxt)->buffer.byteIndex = (pctxt)->savedInfo.byteIndex; \
287 (pctxt)->flags = (pctxt)->savedInfo.flags; }
288 
289 #define OSRTBUFRESTORE2(pctxt,pSavedBuf) { \
290 (pctxt)->buffer.byteIndex = (pSavedBuf)->byteIndex; \
291 (pctxt)->buffer.bitOffset = (pSavedBuf)->bitOffset; \
292 (pctxt)->flags = (pSavedBuf)->flags; }
293 
294 #define OSRTBYTEALIGNED(pctxt) \
295 ((pctxt)->buffer.bitOffset == 8 || (pctxt)->buffer.bitOffset == 0)
296 
297 /* Pointers to C Run-Time memory allocation functions */
298 
299 typedef void *(OSCDECL *OSMallocFunc ) (OSSIZE size);
300 typedef void *(OSCDECL *OSReallocFunc) (void *ptr, OSSIZE size);
301 typedef void (OSCDECL *OSFreeFunc ) (void *ptr);
302 
303 #ifdef __cplusplus
304 extern "C" {
305 #endif
306 
331 #ifndef rtxInitContext
332 EXTERNRT int rtxInitContext (OSCTXT* pctxt);
333 #endif
334 
349 EXTERNRT int rtxInitContextExt (OSCTXT* pctxt,
350  OSMallocFunc malloc_func,
351  OSReallocFunc realloc_func,
352  OSFreeFunc free_func);
353 
374 EXTERNRT int rtxInitThreadContext (OSCTXT* pctxt, const OSCTXT* pSrcCtxt);
375 
390 EXTERNRT int rtxInitContextUsingKey
391 (OSCTXT* pctxt, const OSOCTET* key, OSSIZE keylen);
392 
411 EXTERNRT int rtxInitContextBuffer
412 (OSCTXT* pctxt, OSOCTET* bufaddr, OSSIZE bufsiz);
413 
437 EXTERNRT int rtxCtxtSetBufPtr
438 (OSCTXT* pctxt, OSOCTET* bufaddr, OSSIZE bufsiz);
439 
451 #define rtxCtxtGetMsgPtr(pctxt) (pctxt)->buffer.data
452 
462 #define rtxCtxtGetMsgLen(pctxt) (pctxt)->buffer.byteIndex
463 
471 EXTERNRT OSSIZE rtxCtxtGetBitOffset (OSCTXT* pctxt);
472 
482 EXTERNRT int rtxCtxtSetBitOffset (OSCTXT* pctxt, OSSIZE offset);
483 
491 EXTERNRT OSSIZE rtxCtxtGetIOByteCount (OSCTXT* pctxt);
492 
502 EXTERNRT int rtxCheckContext (OSCTXT* pctxt);
503 
511 EXTERNRT void rtxFreeContext (OSCTXT* pctxt);
512 
522 EXTERNRT void rtxCopyContext (OSCTXT* pdest, OSCTXT* psrc);
523 
530 EXTERNRT void rtxCtxtSetFlag (OSCTXT* pctxt, OSUINT32 mask);
531 
539 EXTERNRT void rtxCtxtClearFlag (OSCTXT* pctxt, OSUINT32 mask);
540 
547 #define rtxCtxtTestFlag(pctxt,mask) (((pctxt)->flags & mask) != 0)
548 
563 EXTERNRT int rtxCtxtPushArrayElemName
564 (OSCTXT* pctxt, const OSUTF8CHAR* elemName, OSSIZE idx);
565 
578 EXTERNRT int rtxCtxtPushElemName (OSCTXT* pctxt, const OSUTF8CHAR* elemName);
579 
594 EXTERNRT int rtxCtxtPushElemNameCopy
595 (OSCTXT* pctxt, const OSUTF8CHAR* elemName);
596 
611 EXTERNRT int rtxCtxtPushTypeName (OSCTXT* pctxt, const OSUTF8CHAR* typeName);
612 
623 EXTERNRT OSBOOL rtxCtxtPopArrayElemName (OSCTXT* pctxt);
624 
632 EXTERNRT const OSUTF8CHAR* rtxCtxtPopElemName (OSCTXT* pctxt);
633 
641 EXTERNRT void rtxCtxtPopElemNameCopy (OSCTXT* pctxt);
642 
651 EXTERNRT const OSUTF8CHAR* rtxCtxtPopTypeName (OSCTXT* pctxt);
652 
660 #define rtxCtxtPeekElemName(pctxt) \
661 (((pctxt)->elemNameStack.count > 0) ? \
662  (const OSUTF8CHAR*)(pctxt)->elemNameStack.tail->data : (const OSUTF8CHAR*)0)
663 
664 
673 EXTERNRT OSBOOL rtxCtxtContainerHasRemBits(OSCTXT* pctxt);
674 
686 EXTERNRT OSBOOL rtxCtxtContainerEnd(OSCTXT* pctxt);
687 
696 EXTERNRT OSSIZE rtxCtxtGetContainerRemBits(OSCTXT* pctxt);
697 
711 EXTERNRT int rtxCtxtPushContainerBytes(OSCTXT* pctxt, OSSIZE bytes);
712 
726 EXTERNRT int rtxCtxtPushContainerBits(OSCTXT* pctxt, OSSIZE bits);
727 
728 
738 EXTERNRT void rtxCtxtPopContainer(OSCTXT* pctxt);
739 
747 EXTERNRT void rtxCtxtPopAllContainers(OSCTXT* pctxt);
748 
749 EXTERNRT int rtxPreInitContext (OSCTXT* pctxt);
750 EXTERNRT void rtxCtxtSetMemHeap (OSCTXT* pctxt, OSCTXT* pSrcCtxt);
751 
761 EXTERNRT void rtxMemHeapSetFlags (OSCTXT* pctxt, OSUINT32 flags);
762 
771 EXTERNRT void rtxMemHeapClearFlags (OSCTXT* pctxt, OSUINT32 flags);
772 
776 #define rtxByteAlign(pctxt) \
777 if ((pctxt)->buffer.bitOffset != 8) { \
778 (pctxt)->buffer.byteIndex++; (pctxt)->buffer.bitOffset = 8; }
779 
789 EXTERNRT int rtxMarkPos (OSCTXT* pctxt, OSSIZE* ppos);
790 
800 EXTERNRT int rtxResetToPos (OSCTXT* pctxt, OSSIZE pos);
801 
813 EXTERNRT const char* rtxCtxtGetExpDateStr
814 (OSCTXT* pctxt, char* buf, OSSIZE bufsiz);
815 
829 #define rtxCtxtSetProtocolVersion(pctxt,value) (pctxt)->version = value
830 
839 EXTERNRT void rtxLicenseClose(void);
840 
841 
842 #define rtxMarkBitPos(pctxt,ppos,pbitoff) \
843 (*(pbitoff) = (OSUINT8) (pctxt)->buffer.bitOffset, rtxMarkPos (pctxt, ppos))
844 
845 #define rtxResetToBitPos(pctxt,pos,bitoff) \
846 ((pctxt)->buffer.bitOffset = (OSUINT8) bitoff, rtxResetToPos (pctxt, pos))
847 
848 #ifndef _COMPACT
849 #define RTXCTXTPUSHARRAYELEMNAME(pctxt,name,idx) \
850 rtxCtxtPushArrayElemName(pctxt,OSUTF8(name),idx)
851 
852 #define RTXCTXTPOPARRAYELEMNAME(pctxt) \
853 rtxCtxtPopArrayElemName(pctxt)
854 
855 #define RTXCTXTPUSHELEMNAME(pctxt,name) \
856 rtxCtxtPushElemName(pctxt,OSUTF8(name))
857 
858 #define RTXCTXTPOPELEMNAME(pctxt) \
859 rtxCtxtPopElemName(pctxt)
860 
861 #define RTXCTXTPUSHTYPENAME(pctxt,name) \
862 rtxCtxtPushTypeName(pctxt,OSUTF8(name))
863 
864 #define RTXCTXTPOPTYPENAME(pctxt) \
865 rtxCtxtPopTypeName(pctxt)
866 #else
867 #define RTXCTXTPUSHARRAYELEMNAME(pctxt,name,idx)
868 #define RTXCTXTPOPARRAYELEMNAME(pctxt)
869 #define RTXCTXTPUSHELEMNAME(pctxt,name)
870 #define RTXCTXTPOPELEMNAME(pctxt)
871 #define RTXCTXTPUSHTYPENAME(pctxt,name)
872 #define RTXCTXTPOPTYPENAME(pctxt)
873 #endif
874 
875 #ifdef __cplusplus
876 }
877 #endif
878 
881 #endif
int(* OSResetCtxtAppInfoPtr)(struct OSCTXT *pctxt)
Definition: rtxContext.h:166
Definition: rtxContext.h:80
void(* OSFreeCtxtGlobalPtr)(struct OSCTXT *pctxt)
Definition: rtxContext.h:175
void rtxCtxtPopAllContainers(OSCTXT *pctxt)
int rtxCtxtPushContainerBytes(OSCTXT *pctxt, OSSIZE bytes)
void rtxFreeContext(OSCTXT *pctxt)
OSBOOL rtxCtxtPopArrayElemName(OSCTXT *pctxt)
OSRTStack containerEndIndexStack
Definition: rtxContext.h:226
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:197
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:158
void rtxCtxtPopContainer(OSCTXT *pctxt)
int rtxInitContext(OSCTXT *pctxt)