00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00038
00043 #ifndef _ASN1CPPTYPES_H_
00044 #define _ASN1CPPTYPES_H_
00045
00046 #ifndef __SYMBIAN32__
00047 #include <new>
00048 #endif
00049
00050 #include "rtxsrc/rtxMemory.h"
00051 #include "rtxsrc/rtxDiag.h"
00052 #include "rtxsrc/rtxError.h"
00053 #include "rtxsrc/rtxMemBuf.h"
00054 #include "rtsrc/asn1CppEvtHndlr.h"
00055 #include "rtsrc/ASN1Context.h"
00056 #include "rtxsrc/OSRTMsgBuf.h"
00057
00058
00059 #define ASN1TRY try
00060 #define ASN1RTLTHROW(stat) exit (-1)
00061 #define ASN1THROW(ex) exit (-1)
00062 #define ASN1CATCH(exType,ex,body) if (0) { body; }
00063
00093 class EXTRTCLASS ASN1MessageBuffer : public OSRTMessageBuffer
00094 {
00095 protected:
00096
00104 EXTRTMETHOD ASN1MessageBuffer (Type bufferType);
00105
00114 EXTRTMETHOD ASN1MessageBuffer (Type bufferType, OSRTContext* pContext);
00115
00121 virtual int setStatus (int stat) {
00122 getContext()->setStatus (stat);
00123 return stat;
00124 }
00125
00126 public:
00131 virtual ~ASN1MessageBuffer () {}
00132
00141 virtual void addEventHandler (Asn1NamedEventHandler* pEventHandler) {
00142 Asn1NamedEventHandler::addEventHandler
00143 (getCtxtPtr(), pEventHandler);
00144 }
00145
00146 #ifndef __SYMBIAN32__
00147
00158 virtual ASN1BMPString* CStringToBMPString
00159 (const char* cstring, ASN1BMPString* pBMPString,
00160 Asn116BitCharSet* pCharSet = 0);
00161 #endif
00162
00166 virtual void* getAppInfo () { return 0; }
00167
00178 virtual EXTRTMETHOD int initBuffer (OSRTMEMBUF& membuf);
00179
00190 virtual EXTRTMETHOD int initBuffer (OSUNICHAR* unistr);
00191
00202 virtual int initBuffer (const OSUTF8CHAR* ) { return RTERR_NOTSUPP; }
00203
00216 virtual OSBOOL isA (Type ) { return FALSE; }
00217
00225 virtual void removeEventHandler (Asn1NamedEventHandler* pEventHandler) {
00226 Asn1NamedEventHandler::removeEventHandler
00227 (getCtxtPtr(), pEventHandler);
00228 }
00229
00234 virtual void resetErrorInfo () {
00235 OSRTMessageBuffer::resetErrorInfo ();
00236 }
00237
00241 virtual void setAppInfo (void* ) { }
00242
00250 virtual void setErrorHandler (Asn1ErrorHandler* pErrorHandler) {
00251 Asn1ErrorHandler::setErrorHandler
00252 (getCtxtPtr(), pErrorHandler);
00253 }
00254
00265 EXTRTMETHOD int setRunTimeKey (const OSOCTET* key, size_t keylen);
00266
00267
00268
00269
00270 inline OSOCTET* GetMsgCopy () { return getMsgCopy(); }
00271 inline const OSOCTET* GetMsgPtr() { return getMsgPtr(); }
00272 inline void PrintErrorInfo() { printErrorInfo(); }
00273
00274 } ;
00290 class EXTRTCLASS ASN1CType {
00291 protected:
00298 OSRTCtxtPtr mpContext;
00299
00304 OSRTMessageBufferIF* mpMsgBuf;
00305
00310 EXTRTMETHOD ASN1CType ();
00311
00318 EXTRTMETHOD ASN1CType (OSRTContext& ctxt);
00319
00320 EXTRTMETHOD int setMsgBuf (OSRTMessageBufferIF& msgBuf, OSBOOL initBuf=FALSE);
00321
00332 EXTRTMETHOD int setRunTimeKey (const OSOCTET* key, size_t keylen);
00333
00334 public:
00344 EXTRTMETHOD ASN1CType (OSRTMessageBufferIF& msgBuf);
00345
00353 EXTRTMETHOD ASN1CType (const ASN1CType& orig);
00354
00359 virtual ~ASN1CType () {}
00360
00369 inline void append (OSRTDList& llist, void* pdata) {
00370 if (0 == rtxDListAppend (getCtxtPtr(), &llist, pdata))
00371 LOG_RTERR (getCtxtPtr(), RTERR_NOMEM);
00372 }
00373
00380 inline OSRTCtxtPtr getContext () {
00381 return mpContext;
00382 }
00383
00388 inline OSCTXT* getCtxtPtr () {
00389 return (!mpContext.isNull ()) ? mpContext->getPtr() : 0;
00390 }
00391
00405 inline int getStatus () const {
00406 return (!mpContext.isNull()) ? mpContext->getStatus() : 0;
00407 }
00408
00419 inline void* memAlloc (size_t numocts) {
00420 if (mpContext.isNull ()) return 0;
00421 return mpContext->memAlloc (numocts);
00422 }
00423
00430 inline void memFreeAll () {
00431 if (!mpContext.isNull ())
00432 mpContext->memFreeAll ();
00433 }
00434
00444 inline void* memRealloc (void* ptr, size_t numocts) {
00445 if (mpContext.isNull ()) return 0;
00446 return mpContext->memRealloc (ptr, numocts);
00447 }
00448
00454 inline void memReset () {
00455 if (!mpContext.isNull ())
00456 mpContext->memReset ();
00457 }
00458
00467 inline void memFreePtr (void* ptr) {
00468 if (!mpContext.isNull ())
00469 mpContext->memFreePtr (ptr);
00470 }
00471
00476 inline void printErrorInfo () {
00477 if (!mpContext.isNull ())
00478 mpContext->printErrorInfo ();
00479 }
00480
00485 inline void resetError () {
00486 if (!mpContext.isNull ())
00487 mpContext->resetErrorInfo ();
00488 }
00489
00496 inline OSBOOL setDiag (OSBOOL value) {
00497 return getContext()->setDiag (value);
00498 }
00499
00508 virtual EXTRTMETHOD int Encode ();
00509
00518 virtual EXTRTMETHOD int Decode ();
00519
00530 virtual int EncodeTo (OSRTMessageBufferIF& )
00531 { return ASN_E_NOTPDU; }
00532
00543 virtual int DecodeFrom (OSRTMessageBufferIF& )
00544 { return ASN_E_NOTPDU; }
00545 } ;
00559 struct EXTRTCLASS ASN1TDynBitStr : public ASN1DynBitStr {
00563 ASN1TDynBitStr () { data = 0; numbits = 0; }
00564
00572 ASN1TDynBitStr (OSUINT32 _numbits, const OSOCTET* _data) {
00573 numbits = _numbits;
00574 data = _data;
00575 }
00576
00583 ASN1TDynBitStr (ASN1DynBitStr& _bs) {
00584 numbits = _bs.numbits;
00585 data = _bs.data;
00586 }
00587 } ;
00588
00593 struct EXTRTCLASS ASN1TBitStr32 : public ASN1BitStr32 {
00597 ASN1TBitStr32 () { numbits = 0; }
00598
00606 ASN1TBitStr32 (OSUINT32 _numbits, const OSOCTET* _data) {
00607 numbits = _numbits;
00608 OSCRTLMEMCPY (data, _data, sizeof(data));
00609 }
00610
00617 ASN1TBitStr32 (ASN1BitStr32& _bs) {
00618 numbits = _bs.numbits;
00619 OSCRTLMEMCPY (data, _bs.data, sizeof(data));
00620 }
00621 } ;
00622
00623
00624 #include "rtsrc/ASN1TOctStr.h"
00625
00630 struct EXTRTCLASS ASN1TBMPString : public ASN1BMPString {
00634 inline ASN1TBMPString () {
00635 nchars = 0;
00636 data = 0;
00637 }
00638 } ;
00639
00644 struct EXTRTCLASS ASN1TUniversalString : public ASN1UniversalString {
00648 inline ASN1TUniversalString () {
00649 nchars = 0;
00650 data = 0;
00651 }
00652 } ;
00653
00658 struct EXTRTCLASS ASN1TOpenType : public ASN1OpenType {
00662 inline ASN1TOpenType () {
00663 numocts = 0;
00664 data = 0;
00665 }
00666 } ;
00667
00673 struct EXTRTCLASS Asn1TObject : public Asn1Object {
00677 inline Asn1TObject () {
00678 encoded.numocts = 0;
00679 encoded.data = 0;
00680 decoded = 0;
00681 index =0;
00682 }
00683 } ;
00684
00685 typedef Asn1TObject ASN1TObject;
00686
00687
00688 #include "rtsrc/ASN1TObjId.h"
00689
00695 struct EXTRTCLASS ASN1TObjId64 : public ASN1OID64 {
00696 inline ASN1TObjId64 () { numids = 0; }
00697 EXTRTMETHOD ASN1TObjId64 (OSOCTET _numids, const OSINT64* _subids);
00698 EXTRTMETHOD ASN1TObjId64 (const ASN1OID64& oid);
00699 EXTRTMETHOD ASN1TObjId64 (const ASN1TObjId64& oid);
00700 EXTRTMETHOD void operator= (const ASN1OID64& rhs);
00701 EXTRTMETHOD void operator= (const ASN1TObjId64& rhs);
00702 } ;
00703
00708 struct EXTRTCLASS ASN1TSeqExt : public OSRTDList {
00712 inline ASN1TSeqExt () {
00713 rtxDListInit (this);
00714 }
00715 } ;
00716
00722 struct EXTRTCLASS ASN1TPDU {
00723 protected:
00730 OSRTCtxtPtr mpContext;
00731
00732 public:
00750 inline void setContext (OSRTContext* ctxt) {
00751 if (mpContext.isNull()) mpContext = ctxt;
00752 else if (ctxt == 0) mpContext = 0;
00753 }
00754 } ;
00755
00760 struct EXTRTCLASS ASN1TSeqOfList : public OSRTDList {
00764 inline ASN1TSeqOfList () {
00765 rtxDListInit (this);
00766 }
00767 } ;
00768
00774 struct EXTRTCLASS ASN1TPDUSeqOfList : public ASN1TSeqOfList, public ASN1TPDU {
00778 ASN1TPDUSeqOfList () {}
00779 } ;
00780
00785 #endif