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 _ASN1CPPTYPES_H_
00029 #define _ASN1CPPTYPES_H_
00030
00031
00032 #if !defined(__SYMBIAN32__) && !defined(TELIUM)
00033 #include <new>
00034 #endif
00035
00036 #include "rtxsrc/rtxMemory.h"
00037 #include "rtxsrc/rtxDiag.h"
00038 #include "rtxsrc/rtxError.h"
00039 #include "rtxsrc/rtxMemBuf.h"
00040 #include "rtsrc/asn1CppEvtHndlr64.h"
00041 #include "rtsrc/ASN1Context.h"
00042 #include "rtxsrc/OSRTMsgBuf.h"
00043
00044
00045
00047 #define ASN1TRY try
00048
00054 #define ASN1RTLTHROW(stat) exit (-1)
00055
00061 #define ASN1THROW(ex) exit (-1)
00062
00071 #define ASN1CATCH(exType,ex,body) if (0) { body; }
00072
00102 class EXTRTCLASS ASN1MessageBuffer : public OSRTMessageBuffer
00103 {
00104 protected:
00105
00113 EXTRTMETHOD ASN1MessageBuffer (Type bufferType);
00114
00123 EXTRTMETHOD ASN1MessageBuffer (Type bufferType, OSRTContext* pContext);
00124
00130 virtual int setStatus (int stat) {
00131 getContext()->setStatus (stat);
00132 return stat;
00133 }
00134
00135 public:
00140 virtual ~ASN1MessageBuffer () {}
00141
00150 virtual void addEventHandler (Asn1NamedEventHandler* pEventHandler) {
00151 Asn1NamedEventHandler::addEventHandler
00152 (getCtxtPtr(), pEventHandler);
00153 }
00154
00155 #ifndef __SYMBIAN32__
00156
00167 virtual ASN1BMPString* CStringToBMPString
00168 (const char* cstring, ASN1BMPString* pBMPString,
00169 Asn116BitCharSet* pCharSet = 0);
00170 #endif
00171
00175 virtual void* getAppInfo () { return 0; }
00176
00187 virtual EXTRTMETHOD int initBuffer (OSRTMEMBUF& membuf);
00188
00199 virtual EXTRTMETHOD int initBuffer (OSUNICHAR* unistr);
00200
00211 using OSRTMessageBuffer::initBuffer;
00212 virtual int initBuffer (const OSUTF8CHAR* ) { return RTERR_NOTSUPP; }
00213
00226 virtual OSBOOL isA (Type ) { return FALSE; }
00227
00235 virtual void removeEventHandler (Asn1NamedEventHandler* pEventHandler) {
00236 Asn1NamedEventHandler::removeEventHandler
00237 (getCtxtPtr(), pEventHandler);
00238 }
00239
00244 virtual void resetErrorInfo () {
00245 OSRTMessageBuffer::resetErrorInfo ();
00246 }
00247
00251 virtual void setAppInfo (void* ) { }
00252
00260 virtual void setErrorHandler (Asn1ErrorHandler* pErrorHandler) {
00261 Asn1ErrorHandler::setErrorHandler
00262 (getCtxtPtr(), pErrorHandler);
00263 }
00264
00275 EXTRTMETHOD int setRunTimeKey (const OSOCTET* key, OSSIZE keylen);
00276
00277
00278
00279
00280 inline OSOCTET* GetMsgCopy () { return getMsgCopy(); }
00281 inline const OSOCTET* GetMsgPtr() { return getMsgPtr(); }
00282 inline void PrintErrorInfo() { printErrorInfo(); }
00283
00284 } ;
00300 class EXTRTCLASS ASN1CType {
00301 protected:
00308 OSRTCtxtPtr mpContext;
00309
00314 OSRTMessageBufferIF* mpMsgBuf;
00315
00320 EXTRTMETHOD ASN1CType ();
00321
00328 EXTRTMETHOD ASN1CType (OSRTContext& ctxt);
00329
00330 EXTRTMETHOD int setMsgBuf
00331 (OSRTMessageBufferIF& msgBuf, OSBOOL initBuf=FALSE);
00332
00343 EXTRTMETHOD int setRunTimeKey (const OSOCTET* key, OSSIZE keylen);
00344
00345 public:
00355 EXTRTMETHOD ASN1CType (OSRTMessageBufferIF& msgBuf);
00356
00364 EXTRTMETHOD ASN1CType (const ASN1CType& orig);
00365
00370 virtual ~ASN1CType () {}
00371
00380 inline void append (OSRTDList& llist, void* pdata) {
00381 if (0 == rtxDListAppend (getCtxtPtr(), &llist, pdata))
00382 LOG_RTERR (getCtxtPtr(), RTERR_NOMEM);
00383 }
00384
00391 inline OSRTCtxtPtr getContext () {
00392 return mpContext;
00393 }
00394
00399 inline OSCTXT* getCtxtPtr () {
00400 return (!mpContext.isNull ()) ? mpContext->getPtr() : 0;
00401 }
00402
00419 char* getErrorText (char* textbuf = (char*)0, OSSIZE bufsize = 0);
00420
00434 inline int getStatus () const {
00435 return (!mpContext.isNull()) ? mpContext->getStatus() : 0;
00436 }
00437
00448 inline void* memAlloc (OSSIZE numocts) {
00449 if (mpContext.isNull ()) return 0;
00450 return mpContext->memAlloc (numocts);
00451 }
00452
00464 inline void* memAllocZ (OSSIZE numocts) {
00465 if (mpContext.isNull ()) return 0;
00466 return mpContext->memAllocZ (numocts);
00467 }
00468
00475 inline void memFreeAll () {
00476 if (!mpContext.isNull ())
00477 mpContext->memFreeAll ();
00478 }
00479
00489 inline void* memRealloc (void* ptr, OSSIZE numocts) {
00490 if (mpContext.isNull ()) return 0;
00491 return mpContext->memRealloc (ptr, numocts);
00492 }
00493
00499 inline void memReset () {
00500 if (!mpContext.isNull ())
00501 mpContext->memReset ();
00502 }
00503
00512 inline void memFreePtr (void* ptr) {
00513 if (!mpContext.isNull ())
00514 mpContext->memFreePtr (ptr);
00515 }
00516
00521 inline void printErrorInfo () {
00522 if (!mpContext.isNull ())
00523 mpContext->printErrorInfo ();
00524 }
00525
00530 inline void resetError () {
00531 if (!mpContext.isNull ())
00532 mpContext->resetErrorInfo ();
00533 }
00534
00541 inline OSBOOL setDiag (OSBOOL value) {
00542 return getContext()->setDiag (value);
00543 }
00544
00553 virtual EXTRTMETHOD int Encode ();
00554
00566 virtual EXTRTMETHOD int Decode (OSBOOL free = FALSE);
00567
00578 virtual int EncodeTo (OSRTMessageBufferIF& )
00579 { return ASN_E_NOTPDU; }
00580
00594 virtual int DecodeFrom (OSRTMessageBufferIF& , OSBOOL free = TRUE)
00595 { OS_UNUSED_ARG(free); return ASN_E_NOTPDU; }
00596 } ;
00610 struct EXTRTCLASS ASN1TDynBitStr : public ASN1DynBitStr {
00614 ASN1TDynBitStr () { data = 0; numbits = 0; }
00615
00623 ASN1TDynBitStr (OSUINT32 _numbits, const OSOCTET* _data) {
00624 numbits = _numbits;
00625 data = _data;
00626 }
00627
00634 ASN1TDynBitStr (ASN1DynBitStr& _bs) {
00635 numbits = _bs.numbits;
00636 data = _bs.data;
00637 }
00638 } ;
00639
00643 struct EXTRTCLASS ASN1TDynBitStr64 : public ASN1DynBitStr64 {
00647 ASN1TDynBitStr64 () { data = 0; numbits = 0; }
00648
00656 ASN1TDynBitStr64 (OSSIZE _numbits, const OSOCTET* _data) {
00657 numbits = _numbits;
00658 data = _data;
00659 }
00660
00667 ASN1TDynBitStr64 (ASN1DynBitStr64& _bs) {
00668 numbits = _bs.numbits;
00669 data = _bs.data;
00670 }
00671 } ;
00672
00677 struct EXTRTCLASS ASN1TBitStr32 : public ASN1BitStr32 {
00681 ASN1TBitStr32 () { numbits = 0; }
00682
00690 ASN1TBitStr32 (OSUINT32 _numbits, const OSOCTET* _data) {
00691 numbits = _numbits;
00692 size_t sz = ((_numbits-1) / 8) + 1;
00693 OSCRTLSAFEMEMCPY (data, sizeof(data), _data, sz);
00694 }
00695
00702 ASN1TBitStr32 (ASN1BitStr32& _bs) {
00703 numbits = _bs.numbits;
00704 OSCRTLSAFEMEMCPY (data, sizeof(data), _bs.data, sizeof(_bs.data));
00705 }
00706 } ;
00707
00708
00709 #include "rtsrc/ASN1TOctStr.h"
00710 #include "rtsrc/ASN1TOctStr64.h"
00711
00716 struct EXTRTCLASS ASN1TBMPString : public ASN1BMPString {
00720 inline ASN1TBMPString () {
00721 nchars = 0;
00722 data = 0;
00723 }
00724 } ;
00725
00730 struct EXTRTCLASS ASN1TUniversalString : public ASN1UniversalString {
00734 inline ASN1TUniversalString () {
00735 nchars = 0;
00736 data = 0;
00737 }
00738 } ;
00739
00744 struct EXTRTCLASS ASN1TOpenType : public ASN1OpenType {
00748 inline ASN1TOpenType () {
00749 numocts = 0;
00750 data = 0;
00751 }
00752 } ;
00753
00759 struct EXTRTCLASS Asn1TObject : public Asn1Object {
00763 inline Asn1TObject () {
00764 encoded.numocts = 0;
00765 encoded.data = 0;
00766 decoded = 0;
00767 index =0;
00768 }
00769 } ;
00770
00771 typedef Asn1TObject ASN1TObject;
00772
00773
00774 #include "rtsrc/ASN1TObjId.h"
00775
00781 struct EXTRTCLASS ASN1TObjId64 : public ASN1OID64 {
00785 inline ASN1TObjId64 () { numids = 0; }
00786
00794 EXTRTMETHOD ASN1TObjId64 (OSOCTET _numids, const OSINT64* _subids);
00795
00801 EXTRTMETHOD ASN1TObjId64 (const ASN1OID64& oid);
00802
00808 EXTRTMETHOD ASN1TObjId64 (const ASN1TObjId64& oid);
00809
00815 EXTRTMETHOD void operator= (const ASN1OID64& rhs);
00816
00822 EXTRTMETHOD void operator= (const ASN1TObjId64& rhs);
00823 } ;
00824
00829 struct EXTRTCLASS ASN1TSeqExt : public OSRTDList {
00833 inline ASN1TSeqExt () {
00834 rtxDListInit (this);
00835 }
00836 } ;
00837
00843 struct EXTRTCLASS ASN1TPDU {
00844 protected:
00851 OSRTCtxtPtr mpContext;
00852
00853 public:
00871 inline void setContext (OSRTContext* ctxt) {
00872 if (mpContext.isNull()) mpContext = ctxt;
00873 else if (ctxt == 0) mpContext = 0;
00874 }
00875
00880 virtual ~ASN1TPDU() {}
00881 } ;
00882
00887 struct EXTRTCLASS ASN1TSeqOfList : public OSRTDList {
00891 inline ASN1TSeqOfList () {
00892 rtxDListInit (this);
00893 }
00894 } ;
00895
00901 struct EXTRTCLASS ASN1TPDUSeqOfList : public ASN1TSeqOfList, public ASN1TPDU {
00905 ASN1TPDUSeqOfList () {}
00906 } ;
00907
00912 #endif