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
00047 #if !defined(__SYMBIAN32__) && !defined(TELIUM)
00048 #include <new>
00049 #endif
00050
00051 #include "rtxsrc/rtxMemory.h"
00052 #include "rtxsrc/rtxDiag.h"
00053 #include "rtxsrc/rtxError.h"
00054 #include "rtxsrc/rtxMemBuf.h"
00055 #include "rtsrc/asn1CppEvtHndlr.h"
00056 #include "rtsrc/ASN1Context.h"
00057 #include "rtxsrc/OSRTMsgBuf.h"
00058
00059
00060
00062 #define ASN1TRY try
00063
00069 #define ASN1RTLTHROW(stat) exit (-1)
00070
00076 #define ASN1THROW(ex) exit (-1)
00077
00086 #define ASN1CATCH(exType,ex,body) if (0) { body; }
00087
00117 class EXTRTCLASS ASN1MessageBuffer : public OSRTMessageBuffer
00118 {
00119 protected:
00120
00128 EXTRTMETHOD ASN1MessageBuffer (Type bufferType);
00129
00138 EXTRTMETHOD ASN1MessageBuffer (Type bufferType, OSRTContext* pContext);
00139
00145 virtual int setStatus (int stat) {
00146 getContext()->setStatus (stat);
00147 return stat;
00148 }
00149
00150 public:
00155 virtual ~ASN1MessageBuffer () {}
00156
00165 virtual void addEventHandler (Asn1NamedEventHandler* pEventHandler) {
00166 Asn1NamedEventHandler::addEventHandler
00167 (getCtxtPtr(), pEventHandler);
00168 }
00169
00170 #ifndef __SYMBIAN32__
00171
00182 virtual ASN1BMPString* CStringToBMPString
00183 (const char* cstring, ASN1BMPString* pBMPString,
00184 Asn116BitCharSet* pCharSet = 0);
00185 #endif
00186
00190 virtual void* getAppInfo () { return 0; }
00191
00202 virtual EXTRTMETHOD int initBuffer (OSRTMEMBUF& membuf);
00203
00214 virtual EXTRTMETHOD int initBuffer (OSUNICHAR* unistr);
00215
00226 using OSRTMessageBuffer::initBuffer;
00227 virtual int initBuffer (const OSUTF8CHAR* ) { return RTERR_NOTSUPP; }
00228
00241 virtual OSBOOL isA (Type ) { return FALSE; }
00242
00250 virtual void removeEventHandler (Asn1NamedEventHandler* pEventHandler) {
00251 Asn1NamedEventHandler::removeEventHandler
00252 (getCtxtPtr(), pEventHandler);
00253 }
00254
00259 virtual void resetErrorInfo () {
00260 OSRTMessageBuffer::resetErrorInfo ();
00261 }
00262
00266 virtual void setAppInfo (void* ) { }
00267
00275 virtual void setErrorHandler (Asn1ErrorHandler* pErrorHandler) {
00276 Asn1ErrorHandler::setErrorHandler
00277 (getCtxtPtr(), pErrorHandler);
00278 }
00279
00290 EXTRTMETHOD int setRunTimeKey (const OSOCTET* key, OSSIZE keylen);
00291
00292
00293
00294
00295 inline OSOCTET* GetMsgCopy () { return getMsgCopy(); }
00296 inline const OSOCTET* GetMsgPtr() { return getMsgPtr(); }
00297 inline void PrintErrorInfo() { printErrorInfo(); }
00298
00299 } ;
00315 class EXTRTCLASS ASN1CType {
00316 protected:
00323 OSRTCtxtPtr mpContext;
00324
00329 OSRTMessageBufferIF* mpMsgBuf;
00330
00335 EXTRTMETHOD ASN1CType ();
00336
00343 EXTRTMETHOD ASN1CType (OSRTContext& ctxt);
00344
00345 EXTRTMETHOD int setMsgBuf
00346 (OSRTMessageBufferIF& msgBuf, OSBOOL initBuf=FALSE);
00347
00358 EXTRTMETHOD int setRunTimeKey (const OSOCTET* key, OSSIZE keylen);
00359
00360 public:
00370 EXTRTMETHOD ASN1CType (OSRTMessageBufferIF& msgBuf);
00371
00379 EXTRTMETHOD ASN1CType (const ASN1CType& orig);
00380
00385 virtual ~ASN1CType () {}
00386
00395 inline void append (OSRTDList& llist, void* pdata) {
00396 if (0 == rtxDListAppend (getCtxtPtr(), &llist, pdata))
00397 LOG_RTERR (getCtxtPtr(), RTERR_NOMEM);
00398 }
00399
00406 inline OSRTCtxtPtr getContext () {
00407 return mpContext;
00408 }
00409
00414 inline OSCTXT* getCtxtPtr () {
00415 return (!mpContext.isNull ()) ? mpContext->getPtr() : 0;
00416 }
00417
00434 char* getErrorText (char* textbuf = (char*)0, OSSIZE bufsize = 0);
00435
00449 inline int getStatus () const {
00450 return (!mpContext.isNull()) ? mpContext->getStatus() : 0;
00451 }
00452
00463 inline void* memAlloc (OSSIZE numocts) {
00464 if (mpContext.isNull ()) return 0;
00465 return mpContext->memAlloc (numocts);
00466 }
00467
00479 inline void* memAllocZ (OSSIZE numocts) {
00480 if (mpContext.isNull ()) return 0;
00481 return mpContext->memAllocZ (numocts);
00482 }
00483
00490 inline void memFreeAll () {
00491 if (!mpContext.isNull ())
00492 mpContext->memFreeAll ();
00493 }
00494
00504 inline void* memRealloc (void* ptr, OSSIZE numocts) {
00505 if (mpContext.isNull ()) return 0;
00506 return mpContext->memRealloc (ptr, numocts);
00507 }
00508
00514 inline void memReset () {
00515 if (!mpContext.isNull ())
00516 mpContext->memReset ();
00517 }
00518
00527 inline void memFreePtr (void* ptr) {
00528 if (!mpContext.isNull ())
00529 mpContext->memFreePtr (ptr);
00530 }
00531
00536 inline void printErrorInfo () {
00537 if (!mpContext.isNull ())
00538 mpContext->printErrorInfo ();
00539 }
00540
00545 inline void resetError () {
00546 if (!mpContext.isNull ())
00547 mpContext->resetErrorInfo ();
00548 }
00549
00556 inline OSBOOL setDiag (OSBOOL value) {
00557 return getContext()->setDiag (value);
00558 }
00559
00568 virtual EXTRTMETHOD int Encode ();
00569
00581 virtual EXTRTMETHOD int Decode (OSBOOL free = FALSE);
00582
00593 virtual int EncodeTo (OSRTMessageBufferIF& )
00594 { return ASN_E_NOTPDU; }
00595
00609 virtual int DecodeFrom (OSRTMessageBufferIF& , OSBOOL free = TRUE)
00610 { OS_UNUSED_ARG(free); return ASN_E_NOTPDU; }
00611 } ;
00625 struct EXTRTCLASS ASN1TDynBitStr : public ASN1DynBitStr {
00629 ASN1TDynBitStr () { data = 0; numbits = 0; }
00630
00638 ASN1TDynBitStr (OSUINT32 _numbits, const OSOCTET* _data) {
00639 numbits = _numbits;
00640 data = _data;
00641 }
00642
00649 ASN1TDynBitStr (ASN1DynBitStr& _bs) {
00650 numbits = _bs.numbits;
00651 data = _bs.data;
00652 }
00653 } ;
00654
00659 struct EXTRTCLASS ASN1TBitStr32 : public ASN1BitStr32 {
00663 ASN1TBitStr32 () { numbits = 0; }
00664
00672 ASN1TBitStr32 (OSUINT32 _numbits, const OSOCTET* _data) {
00673 numbits = _numbits;
00674 size_t sz = ((_numbits-1) / 8) + 1;
00675 OSCRTLSAFEMEMCPY (data, sizeof(data), _data, sz);
00676 }
00677
00684 ASN1TBitStr32 (ASN1BitStr32& _bs) {
00685 numbits = _bs.numbits;
00686 OSCRTLSAFEMEMCPY (data, sizeof(data), _bs.data, sizeof(_bs.data));
00687 }
00688 } ;
00689
00690
00691 #include "rtsrc/ASN1TOctStr.h"
00692
00697 struct EXTRTCLASS ASN1TBMPString : public ASN1BMPString {
00701 inline ASN1TBMPString () {
00702 nchars = 0;
00703 data = 0;
00704 }
00705 } ;
00706
00711 struct EXTRTCLASS ASN1TUniversalString : public ASN1UniversalString {
00715 inline ASN1TUniversalString () {
00716 nchars = 0;
00717 data = 0;
00718 }
00719 } ;
00720
00725 struct EXTRTCLASS ASN1TOpenType : public ASN1OpenType {
00729 inline ASN1TOpenType () {
00730 numocts = 0;
00731 data = 0;
00732 }
00733 } ;
00734
00740 struct EXTRTCLASS Asn1TObject : public Asn1Object {
00744 inline Asn1TObject () {
00745 encoded.numocts = 0;
00746 encoded.data = 0;
00747 decoded = 0;
00748 index =0;
00749 }
00750 } ;
00751
00752 typedef Asn1TObject ASN1TObject;
00753
00754
00755 #include "rtsrc/ASN1TObjId.h"
00756
00762 struct EXTRTCLASS ASN1TObjId64 : public ASN1OID64 {
00766 inline ASN1TObjId64 () { numids = 0; }
00767
00775 EXTRTMETHOD ASN1TObjId64 (OSOCTET _numids, const OSINT64* _subids);
00776
00782 EXTRTMETHOD ASN1TObjId64 (const ASN1OID64& oid);
00783
00789 EXTRTMETHOD ASN1TObjId64 (const ASN1TObjId64& oid);
00790
00796 EXTRTMETHOD void operator= (const ASN1OID64& rhs);
00797
00803 EXTRTMETHOD void operator= (const ASN1TObjId64& rhs);
00804 } ;
00805
00810 struct EXTRTCLASS ASN1TSeqExt : public OSRTDList {
00814 inline ASN1TSeqExt () {
00815 rtxDListInit (this);
00816 }
00817 } ;
00818
00824 struct EXTRTCLASS ASN1TPDU {
00825 protected:
00832 OSRTCtxtPtr mpContext;
00833
00834 public:
00852 inline void setContext (OSRTContext* ctxt) {
00853 if (mpContext.isNull()) mpContext = ctxt;
00854 else if (ctxt == 0) mpContext = 0;
00855 }
00856 } ;
00857
00862 struct EXTRTCLASS ASN1TSeqOfList : public OSRTDList {
00866 inline ASN1TSeqOfList () {
00867 rtxDListInit (this);
00868 }
00869 } ;
00870
00876 struct EXTRTCLASS ASN1TPDUSeqOfList : public ASN1TSeqOfList, public ASN1TPDU {
00880 ASN1TPDUSeqOfList () {}
00881 } ;
00882
00887 #endif