00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00028 #ifndef _RTXCONTEXT_H_
00029 #define _RTXCONTEXT_H_
00030
00031 #include "rtxsrc/rtxDList.h"
00032 #include "rtxsrc/rtxStack.h"
00033
00034 #define OSRTENCBUFSIZ 1024
00035
00040
00041
00042 #define OSRTERRSTKSIZ 8
00043 #define OSRTMAXERRPRM 5
00044
00052 typedef struct {
00053 const OSUTF8CHAR* module;
00054 OSINT32 lineno;
00055 } OSRTErrLocn;
00056
00067 typedef struct {
00068 OSRTErrLocn stack[OSRTERRSTKSIZ];
00069 OSINT16 status;
00070 OSUINT8 stkx;
00071 OSUINT8 parmcnt;
00072 OSUTF8CHAR* parms[OSRTMAXERRPRM];
00073 OSUTF8CHAR* elemName;
00074 } OSRTErrInfo;
00075
00076 typedef struct {
00077 OSRTDList list;
00078 OSRTErrInfo reserved;
00079 OSRTDListNode reservedNode;
00080 } OSRTErrInfoList;
00081
00090 typedef struct {
00091 OSOCTET* data;
00092 OSSIZE byteIndex;
00093 OSSIZE size;
00094 OSINT16 bitOffset;
00095 OSBOOL dynamic;
00096 OSBOOL aligned;
00097 } OSRTBuffer;
00098
00099 typedef OSUINT32 OSRTFLAGS;
00100
00107 typedef struct {
00108 OSSIZE byteIndex;
00109 OSINT16 bitOffset;
00110 OSRTFLAGS flags;
00111 } OSRTBufSave;
00112
00113
00117 typedef struct {
00118 OSSIZE byteIndex;
00119 OSINT16 bitOffset;
00120 } OSBufferIndex;
00121
00122
00123
00124
00125
00126 #define OSDIAG 0x80000000
00127 #define OSTRACE 0x40000000
00128 #define OSDISSTRM 0x20000000
00129 #define OSNOSTRMBACKOFF 0x08000000
00130 #define OS3GMOBORIG 0x04000000
00131
00132
00133
00134
00135
00136
00137
00138 #define OSCONTCLOSED 0x02000000
00139
00140
00141 struct OSCTXT;
00148 typedef int (*OSFreeCtxtAppInfoPtr)(struct OSCTXT* pctxt);
00149
00156 typedef int (*OSResetCtxtAppInfoPtr)(struct OSCTXT* pctxt);
00157
00165 typedef void (*OSFreeCtxtGlobalPtr)(struct OSCTXT* pctxt);
00166
00167
00168
00169
00170 #if !defined(OSCDECL)
00171 #if defined(_MSC_VER) || defined(__BORLANDC__)
00172 #define OSCDECL __cdecl
00173 #else
00174 #define OSCDECL
00175 #endif
00176 #endif
00177
00185 typedef struct OSCTXT {
00186 void* pMemHeap;
00187 OSRTBuffer buffer;
00188 OSRTBufSave savedInfo;
00189 OSRTErrInfoList errInfo;
00190 OSUINT32 initCode;
00191 OSRTFLAGS flags;
00192 OSOCTET level;
00193 OSOCTET state;
00194 OSOCTET diagLevel;
00195 OSOCTET lastChar;
00196 #ifndef _NO_STREAM
00197 struct OSRTSTREAM* pStream;
00198 struct OSRTPrintStream *pPrintStrm;
00199 #endif
00200 OSRTDList elemNameStack;
00201 OSRTDList regExpCache;
00202
00211 OSRTStack containerEndIndexStack;
00212
00213 const OSOCTET* key;
00214 OSSIZE keylen;
00215 OSVoidPtr pXMLInfo;
00216 OSVoidPtr pASN1Info;
00217 OSVoidPtr pEXIInfo;
00218 OSVoidPtr pUserData;
00219 OSVoidPtr pGlobalData;
00220 struct OS3GPPSecParams* p3gppSec;
00221 OSFreeCtxtGlobalPtr gblFreeFunc;
00222 OSVoidPtr ssl;
00223 struct OSRTDiagBitFieldList* pBitFldList;
00224 OSUINT16 indent;
00225 OSUINT16 version;
00226 } OSCTXT;
00227
00228 #define OSRT_GET_FIRST_ERROR_INFO(pctxt) \
00229 (((pctxt)->errInfo.list.head == 0) ? (OSRTErrInfo*)0 : \
00230 (OSRTErrInfo*)((pctxt)->errInfo.list.head->data))
00231
00232 #define OSRT_GET_LAST_ERROR_INFO(pctxt) \
00233 (((pctxt)->errInfo.list.tail == 0) ? (OSRTErrInfo*)0 : \
00234 (OSRTErrInfo*)((pctxt)->errInfo.list.tail->data))
00235
00239 #ifndef _NO_STREAM
00240
00241 #define OSRTISSTREAM(pctxt) \
00242 ((pctxt)->pStream != 0 && !((pctxt)->flags & OSDISSTRM))
00243
00244 #else
00245
00246 #define OSRTISSTREAM(pctxt) FALSE
00247
00248 #endif
00249
00250 #define OSRTBUFCUR(pctxt) (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]
00251 #define OSRTBUFPTR(pctxt) &(pctxt)->buffer.data[(pctxt)->buffer.byteIndex]
00252 #define OSRTBUFFER(pctxt) (pctxt)->buffer.data
00253 #define OSRTBUFSIZE(pctxt) (pctxt)->buffer.size
00254
00255 #define OSRTBUFSAVE(pctxt) { \
00256 (pctxt)->savedInfo.byteIndex = (pctxt)->buffer.byteIndex; \
00257 (pctxt)->savedInfo.flags = (pctxt)->flags; }
00258
00259 #define OSRTBUFSAVE2(pctxt,pSavedBuf) { \
00260 (pSavedBuf)->byteIndex = (pctxt)->buffer.byteIndex; \
00261 (pSavedBuf)->bitOffset = (pctxt)->buffer.bitOffset; \
00262 (pSavedBuf)->flags = (pctxt)->flags; }
00263
00264 #define OSRTBUFRESTORE(pctxt) { \
00265 (pctxt)->buffer.byteIndex = (pctxt)->savedInfo.byteIndex; \
00266 (pctxt)->flags = (pctxt)->savedInfo.flags; }
00267
00268 #define OSRTBUFRESTORE2(pctxt,pSavedBuf) { \
00269 (pctxt)->buffer.byteIndex = (pSavedBuf)->byteIndex; \
00270 (pctxt)->buffer.bitOffset = (pSavedBuf)->bitOffset; \
00271 (pctxt)->flags = (pSavedBuf)->flags; }
00272
00273 #define OSRTBYTEALIGNED(pctxt) \
00274 ((pctxt)->buffer.bitOffset == 8 || (pctxt)->buffer.bitOffset == 0)
00275
00276
00277
00278 typedef void *(OSCDECL *OSMallocFunc ) (OSSIZE size);
00279 typedef void *(OSCDECL *OSReallocFunc) (void *ptr, OSSIZE size);
00280 typedef void (OSCDECL *OSFreeFunc ) (void *ptr);
00281
00282 #ifdef __cplusplus
00283 extern "C" {
00284 #endif
00285
00310 #ifndef rtxInitContext
00311 EXTERNRT int rtxInitContext (OSCTXT* pctxt);
00312 #endif
00313
00328 EXTERNRT int rtxInitContextExt (OSCTXT* pctxt,
00329 OSMallocFunc malloc_func,
00330 OSReallocFunc realloc_func,
00331 OSFreeFunc free_func);
00332
00353 EXTERNRT int rtxInitThreadContext (OSCTXT* pctxt, const OSCTXT* pSrcCtxt);
00354
00373 EXTERNRT int rtxInitContextBuffer
00374 (OSCTXT* pctxt, OSOCTET* bufaddr, OSSIZE bufsiz);
00375
00399 EXTERNRT int rtxCtxtSetBufPtr
00400 (OSCTXT* pctxt, OSOCTET* bufaddr, OSSIZE bufsiz);
00401
00413 #define rtxCtxtGetMsgPtr(pctxt) (pctxt)->buffer.data
00414
00424 #define rtxCtxtGetMsgLen(pctxt) (pctxt)->buffer.byteIndex
00425
00433 EXTERNRT OSSIZE rtxCtxtGetBitOffset (OSCTXT* pctxt);
00434
00444 EXTERNRT int rtxCtxtSetBitOffset (OSCTXT* pctxt, OSSIZE offset);
00445
00453 EXTERNRT OSSIZE rtxCtxtGetIOByteCount (OSCTXT* pctxt);
00454
00464 EXTERNRT int rtxCheckContext (OSCTXT* pctxt);
00465
00473 EXTERNRT void rtxFreeContext (OSCTXT* pctxt);
00474
00484 EXTERNRT void rtxCopyContext (OSCTXT* pdest, OSCTXT* psrc);
00485
00492 EXTERNRT void rtxCtxtSetFlag (OSCTXT* pctxt, OSUINT32 mask);
00493
00501 EXTERNRT void rtxCtxtClearFlag (OSCTXT* pctxt, OSUINT32 mask);
00502
00509 #define rtxCtxtTestFlag(pctxt,mask) (((pctxt)->flags & mask) != 0)
00510
00525 EXTERNRT int rtxCtxtPushArrayElemName
00526 (OSCTXT* pctxt, const OSUTF8CHAR* elemName, OSSIZE idx);
00527
00540 EXTERNRT int rtxCtxtPushElemName (OSCTXT* pctxt, const OSUTF8CHAR* elemName);
00541
00556 EXTERNRT int rtxCtxtPushTypeName (OSCTXT* pctxt, const OSUTF8CHAR* typeName);
00557
00568 EXTERNRT OSBOOL rtxCtxtPopArrayElemName (OSCTXT* pctxt);
00569
00577 EXTERNRT const OSUTF8CHAR* rtxCtxtPopElemName (OSCTXT* pctxt);
00578
00587 EXTERNRT const OSUTF8CHAR* rtxCtxtPopTypeName (OSCTXT* pctxt);
00588
00596 #define rtxCtxtPeekElemName(pctxt) \
00597 (((pctxt)->elemNameStack.count > 0) ? \
00598 (const OSUTF8CHAR*)(pctxt)->elemNameStack.tail->data : (const OSUTF8CHAR*)0)
00599
00600
00609 EXTERNRT OSSIZE rtxCtxtGetContainerRemBits(OSCTXT* pctxt);
00610
00624 EXTERNRT int rtxCtxtPushContainerBytes(OSCTXT* pctxt, OSSIZE bytes);
00625
00639 EXTERNRT int rtxCtxtPushContainerBits(OSCTXT* pctxt, OSSIZE bits);
00640
00641
00651 EXTERNRT void rtxCtxtPopContainer(OSCTXT* pctxt);
00652
00660 EXTERNRT void rtxCtxtPopAllContainers(OSCTXT* pctxt);
00661
00662
00663 EXTERNRT int rtxPreInitContext (OSCTXT* pctxt);
00664
00674 EXTERNRT void rtxMemHeapSetFlags (OSCTXT* pctxt, OSUINT32 flags);
00675
00684 EXTERNRT void rtxMemHeapClearFlags (OSCTXT* pctxt, OSUINT32 flags);
00685
00689 #define rtxByteAlign(pctxt) \
00690 if ((pctxt)->buffer.bitOffset != 8) { \
00691 (pctxt)->buffer.byteIndex++; (pctxt)->buffer.bitOffset = 8; }
00692
00702 EXTERNRT int rtxMarkPos (OSCTXT* pctxt, OSSIZE* ppos);
00703
00713 EXTERNRT int rtxResetToPos (OSCTXT* pctxt, OSSIZE pos);
00714
00728 #define rtxCtxtSetProtocolVersion(pctxt,value) (pctxt)->version = value
00729
00730 #define rtxMarkBitPos(pctxt,ppos,pbitoff) \
00731 (*(pbitoff) = (OSUINT8) (pctxt)->buffer.bitOffset, rtxMarkPos (pctxt, ppos))
00732
00733 #define rtxResetToBitPos(pctxt,pos,bitoff) \
00734 ((pctxt)->buffer.bitOffset = (OSUINT8) bitoff, rtxResetToPos (pctxt, pos))
00735
00736 #ifndef _COMPACT
00737 #define RTXCTXTPUSHARRAYELEMNAME(pctxt,name,idx) \
00738 rtxCtxtPushArrayElemName(pctxt,OSUTF8(name),idx)
00739
00740 #define RTXCTXTPOPARRAYELEMNAME(pctxt) \
00741 rtxCtxtPopArrayElemName(pctxt)
00742
00743 #define RTXCTXTPUSHELEMNAME(pctxt,name) \
00744 rtxCtxtPushElemName(pctxt,OSUTF8(name))
00745
00746 #define RTXCTXTPOPELEMNAME(pctxt) \
00747 rtxCtxtPopElemName(pctxt)
00748
00749 #define RTXCTXTPUSHTYPENAME(pctxt,name) \
00750 rtxCtxtPushTypeName(pctxt,OSUTF8(name))
00751
00752 #define RTXCTXTPOPTYPENAME(pctxt) \
00753 rtxCtxtPopTypeName(pctxt)
00754 #else
00755 #define RTXCTXTPUSHARRAYELEMNAME(pctxt,name,idx)
00756 #define RTXCTXTPOPARRAYELEMNAME(pctxt)
00757 #define RTXCTXTPUSHELEMNAME(pctxt,name)
00758 #define RTXCTXTPOPELEMNAME(pctxt)
00759 #define RTXCTXTPUSHTYPENAME(pctxt,name)
00760 #define RTXCTXTPOPTYPENAME(pctxt)
00761 #endif
00762
00763 #ifdef __cplusplus
00764 }
00765 #endif
00766
00769 #endif