ASN1C C/C++ Common Runtime  ASN1C v7.7.x
asn1CppTypes.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1997-2023 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 _ASN1CPPTYPES_H_
29 #define _ASN1CPPTYPES_H_
30 
31 /* Symbian and Telium systems don't have new */
32 #if !defined(__SYMBIAN32__) && !defined(TELIUM)
33 #include <new>
34 #endif
35 
36 #include "rtxsrc/rtxMemory.h"
37 #include "rtxsrc/rtxDiag.h"
38 #include "rtxsrc/rtxError.h"
39 #include "rtxsrc/rtxMemBuf.h"
41 #include "rtsrc/asn1CppRawEvtHndlr.h"
42 #include "rtsrc/ASN1Context.h"
43 #include "rtxsrc/OSRTMsgBuf.h"
44 
45 // for compatibilty only
46 
48 #define ASN1TRY try
49 
55 #define ASN1RTLTHROW(stat) exit (-1)
56 
62 #define ASN1THROW(ex) exit (-1)
63 
72 #define ASN1CATCH(exType,ex,body) if (0) { body; }
73 
103 class EXTRTCLASS ASN1MessageBuffer : public OSRTMessageBuffer
104 {
105  protected:
106 
114  EXTRTMETHOD ASN1MessageBuffer (Type bufferType);
115 
124  EXTRTMETHOD ASN1MessageBuffer (Type bufferType, OSRTContext* pContext);
125 
131  virtual int setStatus (int stat) {
132  getContext()->setStatus (stat);
133  return stat;
134  }
135 
136  public:
141  virtual ~ASN1MessageBuffer () {}
142 
151  virtual void addEventHandler (Asn1NamedEventHandler* pEventHandler) {
153  (getCtxtPtr(), pEventHandler);
154  }
155 
160  void addRawEventHandler(Asn1RawEventHandler* pHandler) {
161  pHandler->addEventHandler(getCtxtPtr());
162  }
163 
164 #if !defined(__SYMBIAN32__) && !defined(_V2X)
165 
176  ASN1BMPString* CStringToBMPString
177  (const char* cstring, ASN1BMPString* pBMPString,
178  Asn116BitCharSet* pCharSet = 0);
179 #endif
180 
184  virtual void* getAppInfo () { return 0; }
185 
196  virtual EXTRTMETHOD int initBuffer (OSRTMEMBUF& membuf);
197 
208  virtual EXTRTMETHOD int initBuffer (OSUNICHAR* unistr);
209 
221  virtual int initBuffer (const OSUTF8CHAR* /*str*/) { return RTERR_NOTSUPP; }
222 
234  virtual OSBOOL isA (Type /*bufferType*/) { return FALSE; }
235 
243  virtual void removeEventHandler (Asn1NamedEventHandler* pEventHandler) {
245  (getCtxtPtr(), pEventHandler);
246  }
247 
250  { Asn1RawEventHandler::removeEventHandler(getCtxtPtr()); }
251 
256  virtual void resetErrorInfo () {
258  }
259 
263  virtual void setAppInfo (void* /*pAppInfo*/) { }
264 
272  virtual void setErrorHandler (Asn1ErrorHandler* pErrorHandler) {
274  (getCtxtPtr(), pErrorHandler);
275  }
276 
287  EXTRTMETHOD int setRunTimeKey (const OSOCTET* key, OSSIZE keylen);
288 
294  inline size_t getBitOffset () {
295  return rtxCtxtGetBitOffset (getCtxtPtr());
296  }
297 
298  // The following are deprecated method definitions maintained for
299  // backward compatibility only..
300 
301  inline OSOCTET* GetMsgCopy () { return getMsgCopy(); }
302  inline const OSOCTET* GetMsgPtr() { return getMsgPtr(); }
303  inline void PrintErrorInfo() { printErrorInfo(); }
304 
305 } ;
321 class EXTRTCLASS ASN1CType {
322  protected:
330 
335  OSRTMessageBufferIF* mpMsgBuf;
336 
341  EXTRTMETHOD ASN1CType ();
342 
349  EXTRTMETHOD ASN1CType (OSRTContext& ctxt);
350 
351  EXTRTMETHOD int setMsgBuf
352  (OSRTMessageBufferIF& msgBuf, OSBOOL initBuf=FALSE);
353 
364  EXTRTMETHOD int setRunTimeKey (const OSOCTET* key, OSSIZE keylen);
365 
366  public:
376  EXTRTMETHOD ASN1CType (OSRTMessageBufferIF& msgBuf);
377 
385  EXTRTMETHOD ASN1CType (const ASN1CType& orig);
386 
391  virtual ~ASN1CType () {}
392 
401  inline void append (OSRTDList& llist, void* pdata) {
402  if (0 == rtxDListAppend (getCtxtPtr(), &llist, pdata))
403  LOG_RTERR (getCtxtPtr(), RTERR_NOMEM);
404  }
405 
413  return mpContext;
414  }
415 
420  inline OSCTXT* getCtxtPtr () {
421  return (!mpContext.isNull ()) ? mpContext->getPtr() : 0;
422  }
423 
440  char* getErrorText (char* textbuf = (char*)0, OSSIZE bufsize = 0);
441 
455  inline int getStatus () const {
456  return (!mpContext.isNull()) ? mpContext->getStatus() : 0;
457  }
458 
469  inline void* memAlloc (OSSIZE numocts) {
470  if (mpContext.isNull ()) return 0;
471  return mpContext->memAlloc (numocts);
472  }
473 
485  inline void* memAllocZ (OSSIZE numocts) {
486  if (mpContext.isNull ()) return 0;
487  return mpContext->memAllocZ (numocts);
488  }
489 
496  inline void memFreeAll () {
497  if (!mpContext.isNull ())
498  mpContext->memFreeAll ();
499  }
500 
510  inline void* memRealloc (void* ptr, OSSIZE numocts) {
511  if (mpContext.isNull ()) return 0;
512  return mpContext->memRealloc (ptr, numocts);
513  }
514 
520  inline void memReset () {
521  if (!mpContext.isNull ())
522  mpContext->memReset ();
523  }
524 
533  inline void memFreePtr (void* ptr) {
534  if (!mpContext.isNull ())
535  mpContext->memFreePtr (ptr);
536  }
537 
542  inline void printErrorInfo () {
543  if (!mpContext.isNull ())
544  mpContext->printErrorInfo ();
545  }
546 
551  inline void resetError () {
552  if (!mpContext.isNull ())
553  mpContext->resetErrorInfo ();
554  }
555 
562  inline OSBOOL setDiag (OSBOOL value) {
563  return getContext()->setDiag (value);
564  }
565 
574  virtual EXTRTMETHOD int Encode ();
575 
587  virtual EXTRTMETHOD int Decode (OSBOOL free = FALSE);
588 
598  virtual int EncodeTo (OSRTMessageBufferIF& /*msgBuf*/)
599  { return ASN_E_NOTPDU; }
600 
614  virtual int DecodeFrom (OSRTMessageBufferIF& /*msgBuf*/, OSBOOL free = TRUE)
615  { OS_UNUSED_ARG(free); return ASN_E_NOTPDU; }
616 
617 
625  virtual void MemFree() {}
626 } ;
640 struct EXTRTCLASS ASN1TDynBitStr : public ASN1DynBitStr {
644  ASN1TDynBitStr () { data = 0; numbits = 0; }
645 
653  ASN1TDynBitStr (OSUINT32 _numbits, const OSOCTET* _data) {
654  numbits = _numbits;
655  data = _data;
656  }
657 
665  numbits = _bs.numbits;
666  data = _bs.data;
667  }
668 } ;
669 
673 struct EXTRTCLASS ASN1TDynBitStr64 : public ASN1DynBitStr64 {
677  ASN1TDynBitStr64 () { data = 0; numbits = 0; }
678 
686  ASN1TDynBitStr64 (OSSIZE _numbits, const OSOCTET* _data) {
687  numbits = _numbits;
688  data = _data;
689  }
690 
698  numbits = _bs.numbits;
699  data = _bs.data;
700  }
701 } ;
702 
707 struct EXTRTCLASS ASN1TBitStr32 : public ASN1BitStr32 {
711  ASN1TBitStr32 () { numbits = 0; }
712 
720  ASN1TBitStr32 (OSUINT32 _numbits, const OSOCTET* _data) {
721  numbits = _numbits;
722  size_t sz = _numbits / 8;
723  if ( _numbits % 8 > 0 ) sz += 1;
724  OSCRTLSAFEMEMCPY (data, sizeof(data), _data, sz);
725  }
726 
734  numbits = _bs.numbits;
735  OSCRTLSAFEMEMCPY (data, sizeof(data), _bs.data, sizeof(_bs.data));
736  }
737 } ;
738 
739 /* Dynamic octet string */
740 #include "rtsrc/ASN1TOctStr.h"
741 #include "rtsrc/ASN1TOctStr64.h"
742 
747 struct EXTRTCLASS ASN1TBMPString : public ASN1BMPString {
751  inline ASN1TBMPString () {
752  nchars = 0;
753  data = 0;
754  }
755 } ;
756 
761 struct EXTRTCLASS ASN1TUniversalString : public ASN1UniversalString {
766  nchars = 0;
767  data = 0;
768  }
769 } ;
770 
775 struct EXTRTCLASS ASN1TOpenType : public ASN1OpenType {
779  inline ASN1TOpenType () {
780  numocts = 0;
781  data = 0;
782  }
783 } ;
784 
790 struct EXTRTCLASS Asn1TObject : public Asn1Object {
794  inline Asn1TObject () {
795  encoded.numocts = 0;
796  encoded.data = 0;
797  decoded = 0;
798  index =0;
799  }
800 } ;
801 
802 typedef Asn1TObject ASN1TObject;
803 
804 /* Object identifier */
805 #include "rtsrc/ASN1TObjId.h"
806 
811 struct EXTRTCLASS ASN1TSeqExt : public OSRTDList {
815  inline ASN1TSeqExt () {
816  rtxDListInit (this);
817  }
818 } ;
819 
825 struct EXTRTCLASS ASN1TPDU {
826  protected:
834 
835  public:
853  inline void setContext (OSRTContext* ctxt) {
854  if (mpContext.isNull()) mpContext = ctxt;
855  else if (ctxt == 0) mpContext = 0;
856  }
857 
862  virtual ~ASN1TPDU() {}
863 } ;
864 
869 struct EXTRTCLASS ASN1TSeqOfList : public OSRTDList {
873  inline ASN1TSeqOfList () {
874  rtxDListInit (this);
875  }
876 } ;
877 
883 struct EXTRTCLASS ASN1TPDUSeqOfList : public ASN1TSeqOfList, public ASN1TPDU {
888 } ;
889 
894 #endif
static EXTRTMETHOD void setErrorHandler(OSCTXT *pCtxt, Asn1ErrorHandler *pHandler)
Definition: asn1CppTypes.h:673
OSBOOL setDiag(OSBOOL value)
Definition: asn1CppTypes.h:562
Definition: asn1type.h:1005
ASN1TBitStr32()
Definition: asn1CppTypes.h:711
ASN1TSeqExt()
Definition: asn1CppTypes.h:815
ASN1TDynBitStr()
Definition: asn1CppTypes.h:644
int setStatus(int stat)
virtual ~ASN1CType()
Definition: asn1CppTypes.h:391
class EXTRTCLASS ASN1MessageBuffer
Definition: asn1CppEvtHndlr.h:545
static EXTRTMETHOD void removeEventHandler(OSCTXT *pCtxt, Asn1NamedEventHandler *pHandler)
void memFreeAll()
Definition: asn1CppTypes.h:496
Definition: asn1type.h:497
virtual void resetErrorInfo()
Definition: OSRTMsgBuf.h:205
ASN1TDynBitStr(ASN1DynBitStr &_bs)
Definition: asn1CppTypes.h:664
void * memAllocZ(size_t numocts)
Definition: OSRTContext.h:208
void memReset()
Definition: OSRTContext.h:251
ASN1TBitStr32(ASN1BitStr32 &_bs)
Definition: asn1CppTypes.h:733
virtual void setErrorHandler(Asn1ErrorHandler *pErrorHandler)
Definition: asn1CppTypes.h:272
virtual void printErrorInfo()
Definition: OSRTMsgBuf.h:197
Definition: asn1type.h:967
virtual OSRTCtxtPtr getContext()
Definition: OSRTMsgBuf.h:94
ASN1TBMPString()
Definition: asn1CppTypes.h:751
ASN1TOpenType()
Definition: asn1CppTypes.h:779
void rtxDListInit(OSRTDList *pList)
OSRTCtxtPtr getContext()
Definition: asn1CppTypes.h:412
Definition: rtxDList.h:64
void resetErrorInfo()
Definition: OSRTContext.h:267
int getStatus() const
Definition: asn1CppTypes.h:455
Definition: asn1CppTypes.h:883
virtual void removeEventHandler(Asn1NamedEventHandler *pEventHandler)
Definition: asn1CppTypes.h:243
void memFreePtr(void *ptr)
Definition: asn1CppTypes.h:533
OSRTCtxtPtr mpContext
Definition: asn1CppTypes.h:329
Asn1TObject()
Definition: asn1CppTypes.h:794
virtual void * getAppInfo()
Definition: asn1CppTypes.h:184
virtual int EncodeTo(OSRTMessageBufferIF &)
Definition: asn1CppTypes.h:598
Definition: asn1CppTypes.h:707
#define OS_UNUSED_ARG(arg)
Definition: asn1CppEvtHndlr.h:63
Definition: asn1CppTypes.h:103
Definition: asn1CppTypes.h:321
Definition: asn1CppTypes.h:825
virtual ~ASN1MessageBuffer()
Definition: asn1CppTypes.h:141
ASN1TUniversalString()
Definition: asn1CppTypes.h:765
virtual void resetErrorInfo()
Definition: asn1CppTypes.h:256
OSRTDListNode * rtxDListAppend(struct OSCTXT *pctxt, OSRTDList *pList, void *pData)
Definition: asn1type.h:1095
virtual void addEventHandler(Asn1NamedEventHandler *pEventHandler)
Definition: asn1CppTypes.h:151
Definition: asn1CppTypes.h:790
Definition: OSRTContext.h:310
ASN1TBitStr32(OSUINT32 _numbits, const OSOCTET *_data)
Definition: asn1CppTypes.h:720
OSCTXT * getCtxtPtr()
Definition: asn1CppTypes.h:420
void * memAlloc(OSSIZE numocts)
Definition: asn1CppTypes.h:469
void * memAllocZ(OSSIZE numocts)
Definition: asn1CppTypes.h:485
void printErrorInfo()
Definition: asn1CppTypes.h:542
#define ASN_E_NOTPDU
Definition: asn1ErrCodes.h:125
Definition: asn1CppTypes.h:747
Definition: asn1CppTypes.h:640
void memReset()
Definition: asn1CppTypes.h:520
void setContext(OSRTContext *ctxt)
Definition: asn1CppTypes.h:853
virtual int DecodeFrom(OSRTMessageBufferIF &, OSBOOL free=TRUE)
Definition: asn1CppTypes.h:614
void append(OSRTDList &llist, void *pdata)
Definition: asn1CppTypes.h:401
Definition: asn1CppTypes.h:869
OSRTMessageBufferIF * mpMsgBuf
Definition: asn1CppTypes.h:335
virtual int setStatus(int stat)
Definition: asn1CppTypes.h:131
virtual const OSOCTET * getMsgPtr()
Definition: OSRTMsgBuf.h:149
void addRawEventHandler(Asn1RawEventHandler *pHandler)
Definition: asn1CppTypes.h:160
ASN1TDynBitStr64(ASN1DynBitStr64 &_bs)
Definition: asn1CppTypes.h:697
Definition: asn1type.h:1017
Definition: asn1type.h:491
void memFreeAll()
Definition: OSRTContext.h:218
Definition: rtxMemBuf.h:48
OSSIZE rtxCtxtGetBitOffset(OSCTXT *pctxt)
Definition: OSRTContext.h:64
Definition: OSRTMsgBuf.h:46
void printErrorInfo()
Definition: OSRTContext.h:259
Definition: asn1CppTypes.h:775
#define RTERR_NOMEM
Definition: rtxErrCodes.h:135
virtual OSOCTET * getMsgCopy()
Definition: OSRTMsgBuf.h:141
OSCTXT * getPtr()
Definition: OSRTContext.h:109
Definition: asn1type.h:484
void resetError()
Definition: asn1CppTypes.h:551
#define RTERR_NOTSUPP
Definition: rtxErrCodes.h:528
Definition: asn1CppEvtHndlr.h:555
ASN1TDynBitStr64(OSSIZE _numbits, const OSOCTET *_data)
Definition: asn1CppTypes.h:686
static EXTRTMETHOD void addEventHandler(OSCTXT *pCtxt, Asn1NamedEventHandler *pHandler)
void memFreePtr(void *ptr)
Definition: OSRTContext.h:230
ASN1TDynBitStr(OSUINT32 _numbits, const OSOCTET *_data)
Definition: asn1CppTypes.h:653
OSBOOL isNull() const
Definition: OSRTContext.h:394
Definition: asn1CppEvtHndlr.h:75
virtual ~ASN1TPDU()
Definition: asn1CppTypes.h:862
virtual EXTRTMETHOD int initBuffer(OSOCTET *pMsgBuf, size_t msgBufLen)
OSRTCtxtPtr mpContext
Definition: asn1CppTypes.h:833
Definition: rtxContext.h:198
Definition: asn1type.h:977
#define LOG_RTERR(pctxt, stat)
Definition: rtxError.h:79
void removeRawEventHandler()
Definition: asn1CppTypes.h:249
ASN1TDynBitStr64()
Definition: asn1CppTypes.h:677
virtual void MemFree()
Definition: asn1CppTypes.h:625
int getStatus() const
Definition: OSRTContext.h:124
virtual OSCTXT * getCtxtPtr()
Definition: OSRTMsgBuf.h:102
virtual OSBOOL isA(Type)
Definition: asn1CppTypes.h:234
void * memRealloc(void *ptr, OSSIZE numocts)
Definition: asn1CppTypes.h:510
Definition: asn1CppTypes.h:811
Definition: asn1CppTypes.h:761
ASN1TPDUSeqOfList()
Definition: asn1CppTypes.h:887
size_t getBitOffset()
Definition: asn1CppTypes.h:294
void * memRealloc(void *ptr, size_t numocts)
Definition: OSRTContext.h:243
void * memAlloc(size_t numocts)
Definition: OSRTContext.h:195
ASN1TSeqOfList()
Definition: asn1CppTypes.h:873
virtual void setAppInfo(void *)
Definition: asn1CppTypes.h:263