ASN1C C/C++ Common Runtime  ASN1C v7.3.x
rtxContext.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2019 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 } OSRTErrInfo;
75 
76 typedef struct {
77  OSRTDList list; /* list of errors */
78  OSRTErrInfo reserved; /* error info elem, used if nomem to alloc */
79  OSRTDListNode reservedNode; /* node placeholder for errInfo elem */
81 
90 typedef struct {
91  OSOCTET* data; /* pointer to start of data buffer */
92  OSSIZE byteIndex; /* byte index */
93  OSSIZE size; /* current buffer size */
94  OSINT16 bitOffset; /* current bit offset (8 - 1) */
95  OSBOOL dynamic; /* is buffer dynamic? */
96  OSBOOL aligned; /* is buffer byte aligned? */
97 } OSRTBuffer;
98 
99 typedef OSUINT32 OSRTFLAGS;
100 
107 typedef struct {
108  OSSIZE byteIndex; /* byte index */
109  OSINT16 bitOffset; /* current bit offset (8 - 1) */
110  OSRTFLAGS flags; /* flag bits */
111 } OSRTBufSave;
112 
113 
117 typedef struct {
118  OSSIZE byteIndex;
119  OSINT16 bitOffset; /*8..1*/
120 } OSBufferIndex;
121 
122 
123 /* OSRTCTXT flag mask values : bits 32 - 16 are for common flags, bits */
124 /* 15 - 0 are reserved for application specific flags */
125 
126 #define OSDIAG 0x80000000 /* diagnostic tracing enabled */
127 #define OSTRACE 0x40000000 /* tracing enabled */
128 #define OSDISSTRM 0x20000000 /* disable stream encode/decode */
129 #define OSNOSTRMBACKOFF 0x08000000 /* stream mark/reset funcs is not used */
130 #define OS3GMOBORIG 0x04000000 /* 3G mobile-originated (net to MS) */
131 /*
132 OSCONTCLOSED: Flag indicating nothing more should be encoded to the current
133 container. This is set when a variable length field whose encoding space is
134 determined by the container is encoded.
135 Used by 3GPP encoders.
136 */
137 #define OSCONTCLOSED 0x02000000 /* 3G container closed. */
138 #define OSRESERVED1 0x01000000 /* reserved */
139 #define OSBUFSYSALLOC 0x00800000 /* ctxt buf allocated using sys alloc */
140 
141 struct OSCTXT;
148 typedef int (*OSFreeCtxtAppInfoPtr)(struct OSCTXT* pctxt);
149 
156 typedef int (*OSResetCtxtAppInfoPtr)(struct OSCTXT* pctxt);
157 
165 typedef void (*OSFreeCtxtGlobalPtr)(struct OSCTXT* pctxt);
166 
167 /* Alias for __cdecl modifier; if __cdecl keyword is not supported,
168  * redefine it as empty macro. */
169 
170 #if !defined(OSCDECL)
171 #if defined(_MSC_VER) || defined(__BORLANDC__)
172 #define OSCDECL __cdecl
173 #else
174 #define OSCDECL
175 #endif
176 #endif /* OSCDECL */
177 
185 typedef struct OSCTXT { /* run-time context block */
186  void* pMemHeap; /* internal message memory heap */
187  OSRTBuffer buffer; /* data buffer */
188  OSRTBufSave savedInfo; /* saved buffer info */
189  OSRTErrInfoList errInfo; /* run-time error info */
190  OSUINT32 initCode; /* code double word to indicate init */
191  OSRTFLAGS flags; /* flag bits */
192  OSOCTET level; /* nesting level */
193  OSOCTET state; /* encode/decode process state */
194  OSOCTET diagLevel; /* diagnostic trace level */
195  OSOCTET lastChar; /* last char/byte written or read */
196 #ifndef _NO_STREAM
197  struct OSRTSTREAM* pStream; /* Stream */
198 #else
199  void* pStream; /* Stream placeholder */
200 #endif /* _NO_STREAM */
201  struct OSRTPrintStream *pPrintStrm; /* Print Stream */
202  OSRTDList elemNameStack; /* element name stack */
203 #ifndef _OS_NOPATTERN
204  OSRTDList regExpCache; /* compiled regular expression cache */
205 #endif
206 
215 
216  const OSOCTET* key; /* pointer to run-time key data */
217  OSSIZE keylen; /* run-time key length */
218  OSVoidPtr pXMLInfo; /* XML specific info */
219  OSVoidPtr pASN1Info; /* ASN.1 specific info */
220  OSVoidPtr pLicInfo; /* License specific info */
221  OSVoidPtr pUserData; /* User defined data */
222  OSVoidPtr pGlobalData; /* Global constant data */
223  struct OS3GPPSecParams* p3gppSec; /* 3GPP Security parameters */
224  OSFreeCtxtGlobalPtr gblFreeFunc; /* Global free function */
225  OSVoidPtr ssl; /* SSL stack endpoint */
226  struct OSRTDiagBitFieldList* pBitFldList; /* Bit field trace list */
227  OSUINT16 indent; /* total # of spaces to indent. Used by
228  print-to-stream, JSON encoding, and possibly
229  others. */
230  OSUINT16 version; /* Protocol version */
231 } OSCTXT;
232 
233 #define OSRT_GET_FIRST_ERROR_INFO(pctxt) \
234 (((pctxt)->errInfo.list.head == 0) ? (OSRTErrInfo*)0 : \
235 (OSRTErrInfo*)((pctxt)->errInfo.list.head->data))
236 
237 #define OSRT_GET_LAST_ERROR_INFO(pctxt) \
238 (((pctxt)->errInfo.list.tail == 0) ? (OSRTErrInfo*)0 : \
239 (OSRTErrInfo*)((pctxt)->errInfo.list.tail->data))
240 
244 #ifndef _NO_STREAM
245 
246 #define OSRTISSTREAM(pctxt) \
247 ((pctxt)->pStream != 0 && !((pctxt)->flags & OSDISSTRM))
248 
249 #define OSRTISBUFSTREAM(pctxt) \
250 (OSRTISSTREAM(pctxt) && (0 != ((pctxt)->pStream->flags & OSRTSTRMF_BUFFERED)))
251 
252 #else /* _NO_STREAM */
253 
254 #define OSRTISSTREAM(pctxt) FALSE
255 #define OSRTISBUFSTREAM(pctxt) FALSE
256 
257 #endif /* _NO_STREAM */
258 
259 #define OSRTBUFCUR(pctxt) (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]
260 #define OSRTBUFPTR(pctxt) &(pctxt)->buffer.data[(pctxt)->buffer.byteIndex]
261 #define OSRTBUFFER(pctxt) (pctxt)->buffer.data
262 #define OSRTBUFSIZE(pctxt) (pctxt)->buffer.size
263 
264 #define OSRTBUFSAVE(pctxt) { \
265 (pctxt)->savedInfo.byteIndex = (pctxt)->buffer.byteIndex; \
266 (pctxt)->savedInfo.flags = (pctxt)->flags; }
267 
268 #define OSRTBUFSAVE2(pctxt,pSavedBuf) { \
269 (pSavedBuf)->byteIndex = (pctxt)->buffer.byteIndex; \
270 (pSavedBuf)->bitOffset = (pctxt)->buffer.bitOffset; \
271 (pSavedBuf)->flags = (pctxt)->flags; }
272 
273 #define OSRTBUFRESTORE(pctxt) { \
274 (pctxt)->buffer.byteIndex = (pctxt)->savedInfo.byteIndex; \
275 (pctxt)->flags = (pctxt)->savedInfo.flags; }
276 
277 #define OSRTBUFRESTORE2(pctxt,pSavedBuf) { \
278 (pctxt)->buffer.byteIndex = (pSavedBuf)->byteIndex; \
279 (pctxt)->buffer.bitOffset = (pSavedBuf)->bitOffset; \
280 (pctxt)->flags = (pSavedBuf)->flags; }
281 
282 #define OSRTBYTEALIGNED(pctxt) \
283 ((pctxt)->buffer.bitOffset == 8 || (pctxt)->buffer.bitOffset == 0)
284 
285 /* Pointers to C Run-Time memory allocation functions */
286 
287 typedef void *(OSCDECL *OSMallocFunc ) (OSSIZE size);
288 typedef void *(OSCDECL *OSReallocFunc) (void *ptr, OSSIZE size);
289 typedef void (OSCDECL *OSFreeFunc ) (void *ptr);
290 
291 #ifdef __cplusplus
292 extern "C" {
293 #endif
294 
319 #ifndef rtxInitContext
320 EXTERNRT int rtxInitContext (OSCTXT* pctxt);
321 #endif
322 
337 EXTERNRT int rtxInitContextExt (OSCTXT* pctxt,
338  OSMallocFunc malloc_func,
339  OSReallocFunc realloc_func,
340  OSFreeFunc free_func);
341 
362 EXTERNRT int rtxInitThreadContext (OSCTXT* pctxt, const OSCTXT* pSrcCtxt);
363 
378 EXTERNRT int rtxInitContextUsingKey
379 (OSCTXT* pctxt, const OSOCTET* key, OSSIZE keylen);
380 
399 EXTERNRT int rtxInitContextBuffer
400 (OSCTXT* pctxt, OSOCTET* bufaddr, OSSIZE bufsiz);
401 
425 EXTERNRT int rtxCtxtSetBufPtr
426 (OSCTXT* pctxt, OSOCTET* bufaddr, OSSIZE bufsiz);
427 
439 #define rtxCtxtGetMsgPtr(pctxt) (pctxt)->buffer.data
440 
450 #define rtxCtxtGetMsgLen(pctxt) (pctxt)->buffer.byteIndex
451 
459 EXTERNRT OSSIZE rtxCtxtGetBitOffset (OSCTXT* pctxt);
460 
470 EXTERNRT int rtxCtxtSetBitOffset (OSCTXT* pctxt, OSSIZE offset);
471 
479 EXTERNRT OSSIZE rtxCtxtGetIOByteCount (OSCTXT* pctxt);
480 
490 EXTERNRT int rtxCheckContext (OSCTXT* pctxt);
491 
499 EXTERNRT void rtxFreeContext (OSCTXT* pctxt);
500 
510 EXTERNRT void rtxCopyContext (OSCTXT* pdest, OSCTXT* psrc);
511 
518 EXTERNRT void rtxCtxtSetFlag (OSCTXT* pctxt, OSUINT32 mask);
519 
527 EXTERNRT void rtxCtxtClearFlag (OSCTXT* pctxt, OSUINT32 mask);
528 
535 #define rtxCtxtTestFlag(pctxt,mask) (((pctxt)->flags & mask) != 0)
536 
551 EXTERNRT int rtxCtxtPushArrayElemName
552 (OSCTXT* pctxt, const OSUTF8CHAR* elemName, OSSIZE idx);
553 
566 EXTERNRT int rtxCtxtPushElemName (OSCTXT* pctxt, const OSUTF8CHAR* elemName);
567 
582 EXTERNRT int rtxCtxtPushElemNameCopy
583 (OSCTXT* pctxt, const OSUTF8CHAR* elemName);
584 
599 EXTERNRT int rtxCtxtPushTypeName (OSCTXT* pctxt, const OSUTF8CHAR* typeName);
600 
611 EXTERNRT OSBOOL rtxCtxtPopArrayElemName (OSCTXT* pctxt);
612 
620 EXTERNRT const OSUTF8CHAR* rtxCtxtPopElemName (OSCTXT* pctxt);
621 
629 EXTERNRT void rtxCtxtPopElemNameCopy (OSCTXT* pctxt);
630 
639 EXTERNRT const OSUTF8CHAR* rtxCtxtPopTypeName (OSCTXT* pctxt);
640 
648 #define rtxCtxtPeekElemName(pctxt) \
649 (((pctxt)->elemNameStack.count > 0) ? \
650  (const OSUTF8CHAR*)(pctxt)->elemNameStack.tail->data : (const OSUTF8CHAR*)0)
651 
652 
661 EXTERNRT OSBOOL rtxCtxtContainerHasRemBits(OSCTXT* pctxt);
662 
674 EXTERNRT OSBOOL rtxCtxtContainerEnd(OSCTXT* pctxt);
675 
684 EXTERNRT OSSIZE rtxCtxtGetContainerRemBits(OSCTXT* pctxt);
685 
699 EXTERNRT int rtxCtxtPushContainerBytes(OSCTXT* pctxt, OSSIZE bytes);
700 
714 EXTERNRT int rtxCtxtPushContainerBits(OSCTXT* pctxt, OSSIZE bits);
715 
716 
726 EXTERNRT void rtxCtxtPopContainer(OSCTXT* pctxt);
727 
735 EXTERNRT void rtxCtxtPopAllContainers(OSCTXT* pctxt);
736 
737 EXTERNRT int rtxPreInitContext (OSCTXT* pctxt);
738 EXTERNRT void rtxCtxtSetMemHeap (OSCTXT* pctxt, OSCTXT* pSrcCtxt);
739 
749 EXTERNRT void rtxMemHeapSetFlags (OSCTXT* pctxt, OSUINT32 flags);
750 
759 EXTERNRT void rtxMemHeapClearFlags (OSCTXT* pctxt, OSUINT32 flags);
760 
764 #define rtxByteAlign(pctxt) \
765 if ((pctxt)->buffer.bitOffset != 8) { \
766 (pctxt)->buffer.byteIndex++; (pctxt)->buffer.bitOffset = 8; }
767 
777 EXTERNRT int rtxMarkPos (OSCTXT* pctxt, OSSIZE* ppos);
778 
788 EXTERNRT int rtxResetToPos (OSCTXT* pctxt, OSSIZE pos);
789 
801 EXTERNRT const char* rtxCtxtGetExpDateStr
802 (OSCTXT* pctxt, char* buf, OSSIZE bufsiz);
803 
817 #define rtxCtxtSetProtocolVersion(pctxt,value) (pctxt)->version = value
818 
827 EXTERNRT void rtxLicenseClose(void);
828 
829 
830 #define rtxMarkBitPos(pctxt,ppos,pbitoff) \
831 (*(pbitoff) = (OSUINT8) (pctxt)->buffer.bitOffset, rtxMarkPos (pctxt, ppos))
832 
833 #define rtxResetToBitPos(pctxt,pos,bitoff) \
834 ((pctxt)->buffer.bitOffset = (OSUINT8) bitoff, rtxResetToPos (pctxt, pos))
835 
836 #ifndef _COMPACT
837 #define RTXCTXTPUSHARRAYELEMNAME(pctxt,name,idx) \
838 rtxCtxtPushArrayElemName(pctxt,OSUTF8(name),idx)
839 
840 #define RTXCTXTPOPARRAYELEMNAME(pctxt) \
841 rtxCtxtPopArrayElemName(pctxt)
842 
843 #define RTXCTXTPUSHELEMNAME(pctxt,name) \
844 rtxCtxtPushElemName(pctxt,OSUTF8(name))
845 
846 #define RTXCTXTPOPELEMNAME(pctxt) \
847 rtxCtxtPopElemName(pctxt)
848 
849 #define RTXCTXTPUSHTYPENAME(pctxt,name) \
850 rtxCtxtPushTypeName(pctxt,OSUTF8(name))
851 
852 #define RTXCTXTPOPTYPENAME(pctxt) \
853 rtxCtxtPopTypeName(pctxt)
854 #else
855 #define RTXCTXTPUSHARRAYELEMNAME(pctxt,name,idx)
856 #define RTXCTXTPOPARRAYELEMNAME(pctxt)
857 #define RTXCTXTPUSHELEMNAME(pctxt,name)
858 #define RTXCTXTPOPELEMNAME(pctxt)
859 #define RTXCTXTPUSHTYPENAME(pctxt,name)
860 #define RTXCTXTPOPTYPENAME(pctxt)
861 #endif
862 
863 #ifdef __cplusplus
864 }
865 #endif
866 
869 #endif
int(* OSResetCtxtAppInfoPtr)(struct OSCTXT *pctxt)
Definition: rtxContext.h:156
Definition: rtxContext.h:76
void(* OSFreeCtxtGlobalPtr)(struct OSCTXT *pctxt)
Definition: rtxContext.h:165
void rtxCtxtPopAllContainers(OSCTXT *pctxt)
int rtxCtxtPushContainerBytes(OSCTXT *pctxt, OSSIZE bytes)
void rtxFreeContext(OSCTXT *pctxt)
OSBOOL rtxCtxtPopArrayElemName(OSCTXT *pctxt)
OSRTStack containerEndIndexStack
Definition: rtxContext.h:214
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:107
Definition: rtxContext.h:117
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:90
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:185
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:148
void rtxCtxtPopContainer(OSCTXT *pctxt)
int rtxInitContext(OSCTXT *pctxt)