ASN1C C/C++ Common Runtime  ASN1C v7.3.x
asn1CppTypes.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1997-2019 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"
40 #include "rtsrc/asn1CppEvtHndlr64.h"
41 #include "rtsrc/ASN1Context.h"
42 #include "rtxsrc/OSRTMsgBuf.h"
43 
44 // for compatibilty only
45 
47 #define ASN1TRY try
48 
54 #define ASN1RTLTHROW(stat) exit (-1)
55 
61 #define ASN1THROW(ex) exit (-1)
62 
71 #define ASN1CATCH(exType,ex,body) if (0) { body; }
72 
102 class EXTRTCLASS ASN1MessageBuffer : public OSRTMessageBuffer
103 {
104  protected:
105 
113  EXTRTMETHOD ASN1MessageBuffer (Type bufferType);
114 
123  EXTRTMETHOD ASN1MessageBuffer (Type bufferType, OSRTContext* pContext);
124 
130  virtual int setStatus (int stat) {
131  getContext()->setStatus (stat);
132  return stat;
133  }
134 
135  public:
140  virtual ~ASN1MessageBuffer () {}
141 
150  virtual void addEventHandler (Asn1NamedEventHandler* pEventHandler) {
152  (getCtxtPtr(), pEventHandler);
153  }
154 
155 #if !defined(__SYMBIAN32__) && !defined(_V2X)
156 
167  ASN1BMPString* CStringToBMPString
168  (const char* cstring, ASN1BMPString* pBMPString,
169  Asn116BitCharSet* pCharSet = 0);
170 #endif
171 
175  virtual void* getAppInfo () { return 0; }
176 
180  virtual size_t getMsgLen() { return 0; }
181 
192  virtual EXTRTMETHOD int initBuffer (OSRTMEMBUF& membuf);
193 
204  virtual EXTRTMETHOD int initBuffer (OSUNICHAR* unistr);
205 
217  virtual int initBuffer (const OSUTF8CHAR* /*str*/) { return RTERR_NOTSUPP; }
218 
230  virtual OSBOOL isA (Type /*bufferType*/) { return FALSE; }
231 
239  virtual void removeEventHandler (Asn1NamedEventHandler* pEventHandler) {
241  (getCtxtPtr(), pEventHandler);
242  }
243 
248  virtual void resetErrorInfo () {
250  }
251 
255  virtual void setAppInfo (void* /*pAppInfo*/) { }
256 
264  virtual void setErrorHandler (Asn1ErrorHandler* pErrorHandler) {
266  (getCtxtPtr(), pErrorHandler);
267  }
268 
279  EXTRTMETHOD int setRunTimeKey (const OSOCTET* key, OSSIZE keylen);
280 
286  inline size_t getBitOffset () {
287  return rtxCtxtGetBitOffset (getCtxtPtr());
288  }
289 
290  // The following are deprecated method definitions maintained for
291  // backward compatibility only..
292 
293  inline OSOCTET* GetMsgCopy () { return getMsgCopy(); }
294  inline const OSOCTET* GetMsgPtr() { return getMsgPtr(); }
295  inline void PrintErrorInfo() { printErrorInfo(); }
296 
297 } ;
313 class EXTRTCLASS ASN1CType {
314  protected:
322 
327  OSRTMessageBufferIF* mpMsgBuf;
328 
333  EXTRTMETHOD ASN1CType ();
334 
341  EXTRTMETHOD ASN1CType (OSRTContext& ctxt);
342 
343  EXTRTMETHOD int setMsgBuf
344  (OSRTMessageBufferIF& msgBuf, OSBOOL initBuf=FALSE);
345 
356  EXTRTMETHOD int setRunTimeKey (const OSOCTET* key, OSSIZE keylen);
357 
358  public:
368  EXTRTMETHOD ASN1CType (OSRTMessageBufferIF& msgBuf);
369 
377  EXTRTMETHOD ASN1CType (const ASN1CType& orig);
378 
383  virtual ~ASN1CType () {}
384 
393  inline void append (OSRTDList& llist, void* pdata) {
394  if (0 == rtxDListAppend (getCtxtPtr(), &llist, pdata))
395  LOG_RTERR (getCtxtPtr(), RTERR_NOMEM);
396  }
397 
405  return mpContext;
406  }
407 
412  inline OSCTXT* getCtxtPtr () {
413  return (!mpContext.isNull ()) ? mpContext->getPtr() : 0;
414  }
415 
432  char* getErrorText (char* textbuf = (char*)0, OSSIZE bufsize = 0);
433 
447  inline int getStatus () const {
448  return (!mpContext.isNull()) ? mpContext->getStatus() : 0;
449  }
450 
461  inline void* memAlloc (OSSIZE numocts) {
462  if (mpContext.isNull ()) return 0;
463  return mpContext->memAlloc (numocts);
464  }
465 
477  inline void* memAllocZ (OSSIZE numocts) {
478  if (mpContext.isNull ()) return 0;
479  return mpContext->memAllocZ (numocts);
480  }
481 
488  inline void memFreeAll () {
489  if (!mpContext.isNull ())
490  mpContext->memFreeAll ();
491  }
492 
502  inline void* memRealloc (void* ptr, OSSIZE numocts) {
503  if (mpContext.isNull ()) return 0;
504  return mpContext->memRealloc (ptr, numocts);
505  }
506 
512  inline void memReset () {
513  if (!mpContext.isNull ())
514  mpContext->memReset ();
515  }
516 
525  inline void memFreePtr (void* ptr) {
526  if (!mpContext.isNull ())
527  mpContext->memFreePtr (ptr);
528  }
529 
534  inline void printErrorInfo () {
535  if (!mpContext.isNull ())
536  mpContext->printErrorInfo ();
537  }
538 
543  inline void resetError () {
544  if (!mpContext.isNull ())
545  mpContext->resetErrorInfo ();
546  }
547 
554  inline OSBOOL setDiag (OSBOOL value) {
555  return getContext()->setDiag (value);
556  }
557 
566  virtual EXTRTMETHOD int Encode ();
567 
579  virtual EXTRTMETHOD int Decode (OSBOOL free = FALSE);
580 
591  virtual int EncodeTo (OSRTMessageBufferIF& /*msgBuf*/)
592  { return ASN_E_NOTPDU; }
593 
607  virtual int DecodeFrom (OSRTMessageBufferIF& /*msgBuf*/, OSBOOL free = TRUE)
608  { OS_UNUSED_ARG(free); return ASN_E_NOTPDU; }
609 } ;
623 struct EXTRTCLASS ASN1TDynBitStr : public ASN1DynBitStr {
627  ASN1TDynBitStr () { data = 0; numbits = 0; }
628 
636  ASN1TDynBitStr (OSUINT32 _numbits, const OSOCTET* _data) {
637  numbits = _numbits;
638  data = _data;
639  }
640 
648  numbits = _bs.numbits;
649  data = _bs.data;
650  }
651 } ;
652 
656 struct EXTRTCLASS ASN1TDynBitStr64 : public ASN1DynBitStr64 {
660  ASN1TDynBitStr64 () { data = 0; numbits = 0; }
661 
669  ASN1TDynBitStr64 (OSSIZE _numbits, const OSOCTET* _data) {
670  numbits = _numbits;
671  data = _data;
672  }
673 
681  numbits = _bs.numbits;
682  data = _bs.data;
683  }
684 } ;
685 
690 struct EXTRTCLASS ASN1TBitStr32 : public ASN1BitStr32 {
694  ASN1TBitStr32 () { numbits = 0; }
695 
703  ASN1TBitStr32 (OSUINT32 _numbits, const OSOCTET* _data) {
704  numbits = _numbits;
705  size_t sz = _numbits / 8;
706  if ( _numbits % 8 > 0 ) sz += 1;
707  OSCRTLSAFEMEMCPY (data, sizeof(data), _data, sz);
708  }
709 
717  numbits = _bs.numbits;
718  OSCRTLSAFEMEMCPY (data, sizeof(data), _bs.data, sizeof(_bs.data));
719  }
720 } ;
721 
722 /* Dynamic octet string */
723 #include "rtsrc/ASN1TOctStr.h"
724 #include "rtsrc/ASN1TOctStr64.h"
725 
730 struct EXTRTCLASS ASN1TBMPString : public ASN1BMPString {
734  inline ASN1TBMPString () {
735  nchars = 0;
736  data = 0;
737  }
738 } ;
739 
744 struct EXTRTCLASS ASN1TUniversalString : public ASN1UniversalString {
749  nchars = 0;
750  data = 0;
751  }
752 } ;
753 
758 struct EXTRTCLASS ASN1TOpenType : public ASN1OpenType {
762  inline ASN1TOpenType () {
763  numocts = 0;
764  data = 0;
765  }
766 } ;
767 
773 struct EXTRTCLASS Asn1TObject : public Asn1Object {
777  inline Asn1TObject () {
778  encoded.numocts = 0;
779  encoded.data = 0;
780  decoded = 0;
781  index =0;
782  }
783 } ;
784 
785 typedef Asn1TObject ASN1TObject;
786 
787 /* Object identifier */
788 #include "rtsrc/ASN1TObjId.h"
789 
794 struct EXTRTCLASS ASN1TSeqExt : public OSRTDList {
798  inline ASN1TSeqExt () {
799  rtxDListInit (this);
800  }
801 } ;
802 
808 struct EXTRTCLASS ASN1TPDU {
809  protected:
817 
818  public:
836  inline void setContext (OSRTContext* ctxt) {
837  if (mpContext.isNull()) mpContext = ctxt;
838  else if (ctxt == 0) mpContext = 0;
839  }
840 
845  virtual ~ASN1TPDU() {}
846 } ;
847 
852 struct EXTRTCLASS ASN1TSeqOfList : public OSRTDList {
856  inline ASN1TSeqOfList () {
857  rtxDListInit (this);
858  }
859 } ;
860 
866 struct EXTRTCLASS ASN1TPDUSeqOfList : public ASN1TSeqOfList, public ASN1TPDU {
871 } ;
872 
877 #endif
static EXTRTMETHOD void setErrorHandler(OSCTXT *pCtxt, Asn1ErrorHandler *pHandler)
Definition: asn1CppTypes.h:656
OSBOOL setDiag(OSBOOL value)
Definition: asn1CppTypes.h:554
Definition: asn1type.h:686
ASN1TBitStr32()
Definition: asn1CppTypes.h:694
ASN1TSeqExt()
Definition: asn1CppTypes.h:798
ASN1TDynBitStr()
Definition: asn1CppTypes.h:627
int setStatus(int stat)
virtual ~ASN1CType()
Definition: asn1CppTypes.h:383
static EXTRTMETHOD void removeEventHandler(OSCTXT *pCtxt, Asn1NamedEventHandler *pHandler)
void memFreeAll()
Definition: asn1CppTypes.h:488
Definition: asn1type.h:438
virtual void resetErrorInfo()
Definition: OSRTMsgBuf.h:200
ASN1TDynBitStr(ASN1DynBitStr &_bs)
Definition: asn1CppTypes.h:647
void * memAllocZ(size_t numocts)
Definition: OSRTContext.h:209
void memReset()
Definition: OSRTContext.h:252
ASN1TBitStr32(ASN1BitStr32 &_bs)
Definition: asn1CppTypes.h:716
virtual void setErrorHandler(Asn1ErrorHandler *pErrorHandler)
Definition: asn1CppTypes.h:264
virtual void printErrorInfo()
Definition: OSRTMsgBuf.h:192
Definition: asn1type.h:648
virtual OSRTCtxtPtr getContext()
Definition: OSRTMsgBuf.h:94
ASN1TBMPString()
Definition: asn1CppTypes.h:734
ASN1TOpenType()
Definition: asn1CppTypes.h:762
void rtxDListInit(OSRTDList *pList)
OSRTCtxtPtr getContext()
Definition: asn1CppTypes.h:404
Definition: rtxDList.h:64
void resetErrorInfo()
Definition: OSRTContext.h:268
int getStatus() const
Definition: asn1CppTypes.h:447
Definition: asn1CppTypes.h:866
virtual void removeEventHandler(Asn1NamedEventHandler *pEventHandler)
Definition: asn1CppTypes.h:239
void memFreePtr(void *ptr)
Definition: asn1CppTypes.h:525
OSRTCtxtPtr mpContext
Definition: asn1CppTypes.h:321
Asn1TObject()
Definition: asn1CppTypes.h:777
virtual void * getAppInfo()
Definition: asn1CppTypes.h:175
virtual int EncodeTo(OSRTMessageBufferIF &)
Definition: asn1CppTypes.h:591
Definition: asn1CppTypes.h:690
Definition: asn1CppTypes.h:102
Definition: asn1CppTypes.h:313
Definition: asn1CppTypes.h:808
virtual ~ASN1MessageBuffer()
Definition: asn1CppTypes.h:140
ASN1TUniversalString()
Definition: asn1CppTypes.h:748
virtual void resetErrorInfo()
Definition: asn1CppTypes.h:248
OSRTDListNode * rtxDListAppend(struct OSCTXT *pctxt, OSRTDList *pList, void *pData)
Definition: asn1type.h:776
virtual void addEventHandler(Asn1NamedEventHandler *pEventHandler)
Definition: asn1CppTypes.h:150
Definition: asn1CppTypes.h:773
Definition: OSRTContext.h:310
ASN1TBitStr32(OSUINT32 _numbits, const OSOCTET *_data)
Definition: asn1CppTypes.h:703
OSCTXT * getCtxtPtr()
Definition: asn1CppTypes.h:412
void * memAlloc(OSSIZE numocts)
Definition: asn1CppTypes.h:461
void * memAllocZ(OSSIZE numocts)
Definition: asn1CppTypes.h:477
void printErrorInfo()
Definition: asn1CppTypes.h:534
#define ASN_E_NOTPDU
Definition: asn1ErrCodes.h:123
Definition: asn1CppTypes.h:730
Definition: asn1CppTypes.h:623
void memReset()
Definition: asn1CppTypes.h:512
void setContext(OSRTContext *ctxt)
Definition: asn1CppTypes.h:836
virtual int DecodeFrom(OSRTMessageBufferIF &, OSBOOL free=TRUE)
Definition: asn1CppTypes.h:607
void append(OSRTDList &llist, void *pdata)
Definition: asn1CppTypes.h:393
virtual size_t getMsgLen()
Definition: asn1CppTypes.h:180
Definition: asn1CppTypes.h:852
OSRTMessageBufferIF * mpMsgBuf
Definition: asn1CppTypes.h:327
virtual int setStatus(int stat)
Definition: asn1CppTypes.h:130
virtual const OSOCTET * getMsgPtr()
Definition: OSRTMsgBuf.h:149
ASN1TDynBitStr64(ASN1DynBitStr64 &_bs)
Definition: asn1CppTypes.h:680
Definition: asn1type.h:698
#define OS_UNUSED_ARG(arg)
Definition: asn1CppEvtHndlr.h:55
Definition: asn1type.h:432
void memFreeAll()
Definition: OSRTContext.h:219
Definition: rtxMemBuf.h:48
OSSIZE rtxCtxtGetBitOffset(OSCTXT *pctxt)
Definition: OSRTContext.h:65
Definition: OSRTMsgBuf.h:46
void printErrorInfo()
Definition: OSRTContext.h:260
Definition: asn1CppTypes.h:758
#define RTERR_NOMEM
Definition: rtxErrCodes.h:135
class EXTRTCLASS ASN1MessageBuffer
Definition: asn1CppEvtHndlr.h:537
virtual OSOCTET * getMsgCopy()
Definition: OSRTMsgBuf.h:141
OSCTXT * getPtr()
Definition: OSRTContext.h:110
Definition: asn1type.h:425
void resetError()
Definition: asn1CppTypes.h:543
#define RTERR_NOTSUPP
Definition: rtxErrCodes.h:528
Definition: asn1CppEvtHndlr.h:547
ASN1TDynBitStr64(OSSIZE _numbits, const OSOCTET *_data)
Definition: asn1CppTypes.h:669
static EXTRTMETHOD void addEventHandler(OSCTXT *pCtxt, Asn1NamedEventHandler *pHandler)
void memFreePtr(void *ptr)
Definition: OSRTContext.h:231
ASN1TDynBitStr(OSUINT32 _numbits, const OSOCTET *_data)
Definition: asn1CppTypes.h:636
OSBOOL isNull() const
Definition: OSRTContext.h:394
Definition: asn1CppEvtHndlr.h:67
virtual ~ASN1TPDU()
Definition: asn1CppTypes.h:845
virtual EXTRTMETHOD int initBuffer(OSOCTET *pMsgBuf, size_t msgBufLen)
OSRTCtxtPtr mpContext
Definition: asn1CppTypes.h:816
Definition: rtxContext.h:185
Definition: asn1type.h:658
#define LOG_RTERR(pctxt, stat)
Definition: rtxError.h:79
ASN1TDynBitStr64()
Definition: asn1CppTypes.h:660
int getStatus() const
Definition: OSRTContext.h:125
virtual OSCTXT * getCtxtPtr()
Definition: OSRTMsgBuf.h:102
virtual OSBOOL isA(Type)
Definition: asn1CppTypes.h:230
void * memRealloc(void *ptr, OSSIZE numocts)
Definition: asn1CppTypes.h:502
Definition: asn1CppTypes.h:794
Definition: asn1CppTypes.h:744
ASN1TPDUSeqOfList()
Definition: asn1CppTypes.h:870
size_t getBitOffset()
Definition: asn1CppTypes.h:286
void * memRealloc(void *ptr, size_t numocts)
Definition: OSRTContext.h:244
void * memAlloc(size_t numocts)
Definition: OSRTContext.h:196
ASN1TSeqOfList()
Definition: asn1CppTypes.h:856
virtual void setAppInfo(void *)
Definition: asn1CppTypes.h:255