ASN1C C/C++ Common Runtime  ASN1C v7.2.x
rtxContext.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2018 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; /* Print Stream indent */
228  OSUINT16 version; /* Protocol version */
229 } OSCTXT;
230 
231 #define OSRT_GET_FIRST_ERROR_INFO(pctxt) \
232 (((pctxt)->errInfo.list.head == 0) ? (OSRTErrInfo*)0 : \
233 (OSRTErrInfo*)((pctxt)->errInfo.list.head->data))
234 
235 #define OSRT_GET_LAST_ERROR_INFO(pctxt) \
236 (((pctxt)->errInfo.list.tail == 0) ? (OSRTErrInfo*)0 : \
237 (OSRTErrInfo*)((pctxt)->errInfo.list.tail->data))
238 
242 #ifndef _NO_STREAM
243 
244 #define OSRTISSTREAM(pctxt) \
245 ((pctxt)->pStream != 0 && !((pctxt)->flags & OSDISSTRM))
246 
247 #define OSRTISBUFSTREAM(pctxt) \
248 (OSRTISSTREAM(pctxt) && (0 != ((pctxt)->pStream->flags & OSRTSTRMF_BUFFERED)))
249 
250 #else /* _NO_STREAM */
251 
252 #define OSRTISSTREAM(pctxt) FALSE
253 #define OSRTISBUFSTREAM(pctxt) FALSE
254 
255 #endif /* _NO_STREAM */
256 
257 #define OSRTBUFCUR(pctxt) (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]
258 #define OSRTBUFPTR(pctxt) &(pctxt)->buffer.data[(pctxt)->buffer.byteIndex]
259 #define OSRTBUFFER(pctxt) (pctxt)->buffer.data
260 #define OSRTBUFSIZE(pctxt) (pctxt)->buffer.size
261 
262 #define OSRTBUFSAVE(pctxt) { \
263 (pctxt)->savedInfo.byteIndex = (pctxt)->buffer.byteIndex; \
264 (pctxt)->savedInfo.flags = (pctxt)->flags; }
265 
266 #define OSRTBUFSAVE2(pctxt,pSavedBuf) { \
267 (pSavedBuf)->byteIndex = (pctxt)->buffer.byteIndex; \
268 (pSavedBuf)->bitOffset = (pctxt)->buffer.bitOffset; \
269 (pSavedBuf)->flags = (pctxt)->flags; }
270 
271 #define OSRTBUFRESTORE(pctxt) { \
272 (pctxt)->buffer.byteIndex = (pctxt)->savedInfo.byteIndex; \
273 (pctxt)->flags = (pctxt)->savedInfo.flags; }
274 
275 #define OSRTBUFRESTORE2(pctxt,pSavedBuf) { \
276 (pctxt)->buffer.byteIndex = (pSavedBuf)->byteIndex; \
277 (pctxt)->buffer.bitOffset = (pSavedBuf)->bitOffset; \
278 (pctxt)->flags = (pSavedBuf)->flags; }
279 
280 #define OSRTBYTEALIGNED(pctxt) \
281 ((pctxt)->buffer.bitOffset == 8 || (pctxt)->buffer.bitOffset == 0)
282 
283 /* Pointers to C Run-Time memory allocation functions */
284 
285 typedef void *(OSCDECL *OSMallocFunc ) (OSSIZE size);
286 typedef void *(OSCDECL *OSReallocFunc) (void *ptr, OSSIZE size);
287 typedef void (OSCDECL *OSFreeFunc ) (void *ptr);
288 
289 #ifdef __cplusplus
290 extern "C" {
291 #endif
292 
317 #ifndef rtxInitContext
318 EXTERNRT int rtxInitContext (OSCTXT* pctxt);
319 #endif
320 
335 EXTERNRT int rtxInitContextExt (OSCTXT* pctxt,
336  OSMallocFunc malloc_func,
337  OSReallocFunc realloc_func,
338  OSFreeFunc free_func);
339 
360 EXTERNRT int rtxInitThreadContext (OSCTXT* pctxt, const OSCTXT* pSrcCtxt);
361 
376 EXTERNRT int rtxInitContextUsingKey
377 (OSCTXT* pctxt, const OSOCTET* key, OSSIZE keylen);
378 
397 EXTERNRT int rtxInitContextBuffer
398 (OSCTXT* pctxt, OSOCTET* bufaddr, OSSIZE bufsiz);
399 
423 EXTERNRT int rtxCtxtSetBufPtr
424 (OSCTXT* pctxt, OSOCTET* bufaddr, OSSIZE bufsiz);
425 
437 #define rtxCtxtGetMsgPtr(pctxt) (pctxt)->buffer.data
438 
448 #define rtxCtxtGetMsgLen(pctxt) (pctxt)->buffer.byteIndex
449 
457 EXTERNRT OSSIZE rtxCtxtGetBitOffset (OSCTXT* pctxt);
458 
468 EXTERNRT int rtxCtxtSetBitOffset (OSCTXT* pctxt, OSSIZE offset);
469 
477 EXTERNRT OSSIZE rtxCtxtGetIOByteCount (OSCTXT* pctxt);
478 
488 EXTERNRT int rtxCheckContext (OSCTXT* pctxt);
489 
497 EXTERNRT void rtxFreeContext (OSCTXT* pctxt);
498 
508 EXTERNRT void rtxCopyContext (OSCTXT* pdest, OSCTXT* psrc);
509 
516 EXTERNRT void rtxCtxtSetFlag (OSCTXT* pctxt, OSUINT32 mask);
517 
525 EXTERNRT void rtxCtxtClearFlag (OSCTXT* pctxt, OSUINT32 mask);
526 
533 #define rtxCtxtTestFlag(pctxt,mask) (((pctxt)->flags & mask) != 0)
534 
549 EXTERNRT int rtxCtxtPushArrayElemName
550 (OSCTXT* pctxt, const OSUTF8CHAR* elemName, OSSIZE idx);
551 
564 EXTERNRT int rtxCtxtPushElemName (OSCTXT* pctxt, const OSUTF8CHAR* elemName);
565 
580 EXTERNRT int rtxCtxtPushTypeName (OSCTXT* pctxt, const OSUTF8CHAR* typeName);
581 
592 EXTERNRT OSBOOL rtxCtxtPopArrayElemName (OSCTXT* pctxt);
593 
601 EXTERNRT const OSUTF8CHAR* rtxCtxtPopElemName (OSCTXT* pctxt);
602 
611 EXTERNRT const OSUTF8CHAR* rtxCtxtPopTypeName (OSCTXT* pctxt);
612 
620 #define rtxCtxtPeekElemName(pctxt) \
621 (((pctxt)->elemNameStack.count > 0) ? \
622  (const OSUTF8CHAR*)(pctxt)->elemNameStack.tail->data : (const OSUTF8CHAR*)0)
623 
624 
633 EXTERNRT OSBOOL rtxCtxtContainerHasRemBits(OSCTXT* pctxt);
634 
643 EXTERNRT OSSIZE rtxCtxtGetContainerRemBits(OSCTXT* pctxt);
644 
658 EXTERNRT int rtxCtxtPushContainerBytes(OSCTXT* pctxt, OSSIZE bytes);
659 
673 EXTERNRT int rtxCtxtPushContainerBits(OSCTXT* pctxt, OSSIZE bits);
674 
675 
685 EXTERNRT void rtxCtxtPopContainer(OSCTXT* pctxt);
686 
694 EXTERNRT void rtxCtxtPopAllContainers(OSCTXT* pctxt);
695 
696 EXTERNRT int rtxPreInitContext (OSCTXT* pctxt);
697 EXTERNRT void rtxCtxtSetMemHeap (OSCTXT* pctxt, OSCTXT* pSrcCtxt);
698 
708 EXTERNRT void rtxMemHeapSetFlags (OSCTXT* pctxt, OSUINT32 flags);
709 
718 EXTERNRT void rtxMemHeapClearFlags (OSCTXT* pctxt, OSUINT32 flags);
719 
723 #define rtxByteAlign(pctxt) \
724 if ((pctxt)->buffer.bitOffset != 8) { \
725 (pctxt)->buffer.byteIndex++; (pctxt)->buffer.bitOffset = 8; }
726 
736 EXTERNRT int rtxMarkPos (OSCTXT* pctxt, OSSIZE* ppos);
737 
747 EXTERNRT int rtxResetToPos (OSCTXT* pctxt, OSSIZE pos);
748 
760 EXTERNRT const char* rtxCtxtGetExpDateStr
761 (OSCTXT* pctxt, char* buf, OSSIZE bufsiz);
762 
776 #define rtxCtxtSetProtocolVersion(pctxt,value) (pctxt)->version = value
777 
786 EXTERNRT void rtxLicenseClose(void);
787 
788 
789 #define rtxMarkBitPos(pctxt,ppos,pbitoff) \
790 (*(pbitoff) = (OSUINT8) (pctxt)->buffer.bitOffset, rtxMarkPos (pctxt, ppos))
791 
792 #define rtxResetToBitPos(pctxt,pos,bitoff) \
793 ((pctxt)->buffer.bitOffset = (OSUINT8) bitoff, rtxResetToPos (pctxt, pos))
794 
795 #ifndef _COMPACT
796 #define RTXCTXTPUSHARRAYELEMNAME(pctxt,name,idx) \
797 rtxCtxtPushArrayElemName(pctxt,OSUTF8(name),idx)
798 
799 #define RTXCTXTPOPARRAYELEMNAME(pctxt) \
800 rtxCtxtPopArrayElemName(pctxt)
801 
802 #define RTXCTXTPUSHELEMNAME(pctxt,name) \
803 rtxCtxtPushElemName(pctxt,OSUTF8(name))
804 
805 #define RTXCTXTPOPELEMNAME(pctxt) \
806 rtxCtxtPopElemName(pctxt)
807 
808 #define RTXCTXTPUSHTYPENAME(pctxt,name) \
809 rtxCtxtPushTypeName(pctxt,OSUTF8(name))
810 
811 #define RTXCTXTPOPTYPENAME(pctxt) \
812 rtxCtxtPopTypeName(pctxt)
813 #else
814 #define RTXCTXTPUSHARRAYELEMNAME(pctxt,name,idx)
815 #define RTXCTXTPOPARRAYELEMNAME(pctxt)
816 #define RTXCTXTPUSHELEMNAME(pctxt,name)
817 #define RTXCTXTPOPELEMNAME(pctxt)
818 #define RTXCTXTPUSHTYPENAME(pctxt,name)
819 #define RTXCTXTPOPTYPENAME(pctxt)
820 #endif
821 
822 #ifdef __cplusplus
823 }
824 #endif
825 
828 #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
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)
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)
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)