XBinder  Version 2.6.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 */
80 } OSRTErrInfoList;
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 
646 EXTERNRT OSBOOL rtxCtxtContainerEnd(OSCTXT* pctxt);
647 
656 EXTERNRT OSSIZE rtxCtxtGetContainerRemBits(OSCTXT* pctxt);
657 
671 EXTERNRT int rtxCtxtPushContainerBytes(OSCTXT* pctxt, OSSIZE bytes);
672 
686 EXTERNRT int rtxCtxtPushContainerBits(OSCTXT* pctxt, OSSIZE bits);
687 
688 
698 EXTERNRT void rtxCtxtPopContainer(OSCTXT* pctxt);
699 
707 EXTERNRT void rtxCtxtPopAllContainers(OSCTXT* pctxt);
708 
709 EXTERNRT int rtxPreInitContext (OSCTXT* pctxt);
710 EXTERNRT void rtxCtxtSetMemHeap (OSCTXT* pctxt, OSCTXT* pSrcCtxt);
711 
721 EXTERNRT void rtxMemHeapSetFlags (OSCTXT* pctxt, OSUINT32 flags);
722 
731 EXTERNRT void rtxMemHeapClearFlags (OSCTXT* pctxt, OSUINT32 flags);
732 
736 #define rtxByteAlign(pctxt) \
737 if ((pctxt)->buffer.bitOffset != 8) { \
738 (pctxt)->buffer.byteIndex++; (pctxt)->buffer.bitOffset = 8; }
739 
749 EXTERNRT int rtxMarkPos (OSCTXT* pctxt, OSSIZE* ppos);
750 
760 EXTERNRT int rtxResetToPos (OSCTXT* pctxt, OSSIZE pos);
761 
773 EXTERNRT const char* rtxCtxtGetExpDateStr
774 (OSCTXT* pctxt, char* buf, OSSIZE bufsiz);
775 
789 #define rtxCtxtSetProtocolVersion(pctxt,value) (pctxt)->version = value
790 
799 EXTERNRT void rtxLicenseClose(void);
800 
801 
802 #define rtxMarkBitPos(pctxt,ppos,pbitoff) \
803 (*(pbitoff) = (OSUINT8) (pctxt)->buffer.bitOffset, rtxMarkPos (pctxt, ppos))
804 
805 #define rtxResetToBitPos(pctxt,pos,bitoff) \
806 ((pctxt)->buffer.bitOffset = (OSUINT8) bitoff, rtxResetToPos (pctxt, pos))
807 
808 #ifndef _COMPACT
809 #define RTXCTXTPUSHARRAYELEMNAME(pctxt,name,idx) \
810 rtxCtxtPushArrayElemName(pctxt,OSUTF8(name),idx)
811 
812 #define RTXCTXTPOPARRAYELEMNAME(pctxt) \
813 rtxCtxtPopArrayElemName(pctxt)
814 
815 #define RTXCTXTPUSHELEMNAME(pctxt,name) \
816 rtxCtxtPushElemName(pctxt,OSUTF8(name))
817 
818 #define RTXCTXTPOPELEMNAME(pctxt) \
819 rtxCtxtPopElemName(pctxt)
820 
821 #define RTXCTXTPUSHTYPENAME(pctxt,name) \
822 rtxCtxtPushTypeName(pctxt,OSUTF8(name))
823 
824 #define RTXCTXTPOPTYPENAME(pctxt) \
825 rtxCtxtPopTypeName(pctxt)
826 #else
827 #define RTXCTXTPUSHARRAYELEMNAME(pctxt,name,idx)
828 #define RTXCTXTPOPARRAYELEMNAME(pctxt)
829 #define RTXCTXTPUSHELEMNAME(pctxt,name)
830 #define RTXCTXTPOPELEMNAME(pctxt)
831 #define RTXCTXTPUSHTYPENAME(pctxt,name)
832 #define RTXCTXTPOPTYPENAME(pctxt)
833 #endif
834 
835 #ifdef __cplusplus
836 }
837 #endif
838 
841 #endif
EXTERNRT const char * rtxCtxtGetExpDateStr(OSCTXT *pctxt, char *buf, OSSIZE bufsiz)
This function will get the license expiration date for a time-limited license.
EXTERNRT int rtxInitContext(OSCTXT *pctxt)
This function initializes an OSCTXT block.
int(* OSResetCtxtAppInfoPtr)(struct OSCTXT *pctxt)
OSRTResetCtxtAppInfoPtr is a pointer to pctxt->pAppInfo reset function, The pctxt->pAppInfo (pXMLInfo...
Definition: rtxContext.h:156
void(* OSFreeCtxtGlobalPtr)(struct OSCTXT *pctxt)
OSRTFreeCtxtGlobalPtr is a pointer to a memory free function.
Definition: rtxContext.h:165
EXTERNRT void rtxFreeContext(OSCTXT *pctxt)
This function frees all dynamic memory associated with a context.
EXTERNRT OSBOOL rtxCtxtContainerHasRemBits(OSCTXT *pctxt)
Return true iff there are bits remaining to be decoded in the current length-constrained container...
EXTERNRT OSBOOL rtxCtxtContainerEnd(OSCTXT *pctxt)
Return true if we are at the end of container - neither having more bits remaining nor having overrun...
OSRTStack containerEndIndexStack
Stack of OSBufferIndex, representing pointers to the end of currently open containers having length d...
Definition: rtxContext.h:214
EXTERNRT void rtxCtxtSetFlag(OSCTXT *pctxt, OSUINT32 mask)
This function is used to set a processing flag within the context structure.
EXTERNRT void rtxCtxtPopAllContainers(OSCTXT *pctxt)
Pop all containers from the container stack.
EXTERNRT OSBOOL rtxCtxtPopArrayElemName(OSCTXT *pctxt)
This function pops the last element name from the context stack.
This is the main list structure.
Definition: rtxDList.h:64
EXTERNRT void rtxMemHeapClearFlags(OSCTXT *pctxt, OSUINT32 flags)
This function clears memory heap flags.
EXTERNRT void rtxLicenseClose(void)
Finish with current license and free internal resources.
EXTERNRT int rtxInitContextUsingKey(OSCTXT *pctxt, const OSOCTET *key, OSSIZE keylen)
This function initializes a context using a run-time key.
EXTERNRT void rtxCtxtClearFlag(OSCTXT *pctxt, OSUINT32 mask)
This function is used to clear a processing flag within the context structure.
Structure to save the current message buffer state.
Definition: rtxContext.h:107
This structure can be used as an index into the buffer.
Definition: rtxContext.h:117
EXTERNRT const OSUTF8CHAR * rtxCtxtPopElemName(OSCTXT *pctxt)
This function pops the last element name from the context stack.
EXTERNRT OSSIZE rtxCtxtGetContainerRemBits(OSCTXT *pctxt)
Return the number of bits remaining to be decoded in the current length-constrained container...
EXTERNRT int rtxCtxtPushContainerBits(OSCTXT *pctxt, OSSIZE bits)
Notify the runtime layer of the start of decoding of a length-constrained container of a given length...
EXTERNRT int rtxInitThreadContext(OSCTXT *pctxt, const OSCTXT *pSrcCtxt)
This function initializes a context for use in a thread.
Run-time message buffer structure.
Definition: rtxContext.h:90
This structure is used to hold a single data item within the list.
Definition: rtxDList.h:52
EXTERNRT int rtxCheckContext(OSCTXT *pctxt)
This function verifies that the given context structure is initialized and ready for use...
Structure to hold information about a global PrintStream.
EXTERNRT int rtxCtxtSetBitOffset(OSCTXT *pctxt, OSSIZE offset)
This function sets the bit offset in the context to the given value.
EXTERNRT OSSIZE rtxCtxtGetIOByteCount(OSCTXT *pctxt)
This function returns the count of bytes either written to a stream or memory buffer.
EXTERNRT void rtxMemHeapSetFlags(OSCTXT *pctxt, OSUINT32 flags)
This function sets flags to a heap.
EXTERNRT void rtxCopyContext(OSCTXT *pdest, OSCTXT *psrc)
This function creates a copy of a context structure.
EXTERNRT int rtxCtxtPushContainerBytes(OSCTXT *pctxt, OSSIZE bytes)
Notify the runtime layer of the start of decoding of a length-constrained container of a given length...
Run-time error information structure.
Definition: rtxContext.h:67
EXTERNRT int rtxInitContextExt(OSCTXT *pctxt, OSMallocFunc malloc_func, OSReallocFunc realloc_func, OSFreeFunc free_func)
This function initializes an OSCTXT block.
EXTERNRT int rtxCtxtPushElemName(OSCTXT *pctxt, const OSUTF8CHAR *elemName)
This function is used to push an element name onto the context element name stack.
EXTERNRT int rtxCtxtPushTypeName(OSCTXT *pctxt, const OSUTF8CHAR *typeName)
This function is used to push a type name onto the context element name stack.
EXTERNRT OSSIZE rtxCtxtGetBitOffset(OSCTXT *pctxt)
This function returns the total bit offset to the current element in the context buffer.
EXTERNRT int rtxCtxtPushArrayElemName(OSCTXT *pctxt, const OSUTF8CHAR *elemName, OSSIZE idx)
This function is used to push an array element name onto the context element name stack...
Run-time context structure.
Definition: rtxContext.h:185
EXTERNRT int rtxInitContextBuffer(OSCTXT *pctxt, OSOCTET *bufaddr, OSSIZE bufsiz)
This function assigns a message buffer to a context block.
The stream control block.
Definition: rtxStream.h:176
EXTERNRT void rtxCtxtPopContainer(OSCTXT *pctxt)
Notify the runtime layer of the end of decoding of a length-constrained container of the given length...
Run-time error location structure.
Definition: rtxContext.h:52
Doubly-Linked List Utility Functions.
EXTERNRT const OSUTF8CHAR * rtxCtxtPopTypeName(OSCTXT *pctxt)
This function pops the type name from the context stack.
EXTERNRT int rtxCtxtSetBufPtr(OSCTXT *pctxt, OSOCTET *bufaddr, OSSIZE bufsiz)
This function is used to set the internal buffer pointer for in-memory encoding or decoding...
int(* OSFreeCtxtAppInfoPtr)(struct OSCTXT *pctxt)
OSRTFreeCtxtAppInfoPtr is a pointer to pctxt->pAppInfo free function, The pctxt->pAppInfo (pXMLInfo a...
Definition: rtxContext.h:148
EXTERNRT int rtxResetToPos(OSCTXT *pctxt, OSSIZE pos)
This function resets a message buffer or stream back to the given position.
EXTERNRT int rtxMarkPos(OSCTXT *pctxt, OSSIZE *ppos)
This function saves the current position in a message buffer or stream.