ASN1C C/C++ Common Runtime  ASN1C v7.4.x
asn1CppTypes.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1997-2020 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 
187  virtual EXTRTMETHOD int initBuffer (OSRTMEMBUF& membuf);
188 
199  virtual EXTRTMETHOD int initBuffer (OSUNICHAR* unistr);
200 
212  virtual int initBuffer (const OSUTF8CHAR* /*str*/) { return RTERR_NOTSUPP; }
213 
225  virtual OSBOOL isA (Type /*bufferType*/) { return FALSE; }
226 
234  virtual void removeEventHandler (Asn1NamedEventHandler* pEventHandler) {
236  (getCtxtPtr(), pEventHandler);
237  }
238 
243  virtual void resetErrorInfo () {
245  }
246 
250  virtual void setAppInfo (void* /*pAppInfo*/) { }
251 
259  virtual void setErrorHandler (Asn1ErrorHandler* pErrorHandler) {
261  (getCtxtPtr(), pErrorHandler);
262  }
263 
274  EXTRTMETHOD int setRunTimeKey (const OSOCTET* key, OSSIZE keylen);
275 
281  inline size_t getBitOffset () {
282  return rtxCtxtGetBitOffset (getCtxtPtr());
283  }
284 
285  // The following are deprecated method definitions maintained for
286  // backward compatibility only..
287 
288  inline OSOCTET* GetMsgCopy () { return getMsgCopy(); }
289  inline const OSOCTET* GetMsgPtr() { return getMsgPtr(); }
290  inline void PrintErrorInfo() { printErrorInfo(); }
291 
292 } ;
308 class EXTRTCLASS ASN1CType {
309  protected:
317 
322  OSRTMessageBufferIF* mpMsgBuf;
323 
328  EXTRTMETHOD ASN1CType ();
329 
336  EXTRTMETHOD ASN1CType (OSRTContext& ctxt);
337 
338  EXTRTMETHOD int setMsgBuf
339  (OSRTMessageBufferIF& msgBuf, OSBOOL initBuf=FALSE);
340 
351  EXTRTMETHOD int setRunTimeKey (const OSOCTET* key, OSSIZE keylen);
352 
353  public:
363  EXTRTMETHOD ASN1CType (OSRTMessageBufferIF& msgBuf);
364 
372  EXTRTMETHOD ASN1CType (const ASN1CType& orig);
373 
378  virtual ~ASN1CType () {}
379 
388  inline void append (OSRTDList& llist, void* pdata) {
389  if (0 == rtxDListAppend (getCtxtPtr(), &llist, pdata))
390  LOG_RTERR (getCtxtPtr(), RTERR_NOMEM);
391  }
392 
400  return mpContext;
401  }
402 
407  inline OSCTXT* getCtxtPtr () {
408  return (!mpContext.isNull ()) ? mpContext->getPtr() : 0;
409  }
410 
427  char* getErrorText (char* textbuf = (char*)0, OSSIZE bufsize = 0);
428 
442  inline int getStatus () const {
443  return (!mpContext.isNull()) ? mpContext->getStatus() : 0;
444  }
445 
456  inline void* memAlloc (OSSIZE numocts) {
457  if (mpContext.isNull ()) return 0;
458  return mpContext->memAlloc (numocts);
459  }
460 
472  inline void* memAllocZ (OSSIZE numocts) {
473  if (mpContext.isNull ()) return 0;
474  return mpContext->memAllocZ (numocts);
475  }
476 
483  inline void memFreeAll () {
484  if (!mpContext.isNull ())
485  mpContext->memFreeAll ();
486  }
487 
497  inline void* memRealloc (void* ptr, OSSIZE numocts) {
498  if (mpContext.isNull ()) return 0;
499  return mpContext->memRealloc (ptr, numocts);
500  }
501 
507  inline void memReset () {
508  if (!mpContext.isNull ())
509  mpContext->memReset ();
510  }
511 
520  inline void memFreePtr (void* ptr) {
521  if (!mpContext.isNull ())
522  mpContext->memFreePtr (ptr);
523  }
524 
529  inline void printErrorInfo () {
530  if (!mpContext.isNull ())
531  mpContext->printErrorInfo ();
532  }
533 
538  inline void resetError () {
539  if (!mpContext.isNull ())
540  mpContext->resetErrorInfo ();
541  }
542 
549  inline OSBOOL setDiag (OSBOOL value) {
550  return getContext()->setDiag (value);
551  }
552 
561  virtual EXTRTMETHOD int Encode ();
562 
574  virtual EXTRTMETHOD int Decode (OSBOOL free = FALSE);
575 
586  virtual int EncodeTo (OSRTMessageBufferIF& /*msgBuf*/)
587  { return ASN_E_NOTPDU; }
588 
602  virtual int DecodeFrom (OSRTMessageBufferIF& /*msgBuf*/, OSBOOL free = TRUE)
603  { OS_UNUSED_ARG(free); return ASN_E_NOTPDU; }
604 
605 
613  virtual void MemFree() {}
614 } ;
628 struct EXTRTCLASS ASN1TDynBitStr : public ASN1DynBitStr {
632  ASN1TDynBitStr () { data = 0; numbits = 0; }
633 
641  ASN1TDynBitStr (OSUINT32 _numbits, const OSOCTET* _data) {
642  numbits = _numbits;
643  data = _data;
644  }
645 
653  numbits = _bs.numbits;
654  data = _bs.data;
655  }
656 } ;
657 
661 struct EXTRTCLASS ASN1TDynBitStr64 : public ASN1DynBitStr64 {
665  ASN1TDynBitStr64 () { data = 0; numbits = 0; }
666 
674  ASN1TDynBitStr64 (OSSIZE _numbits, const OSOCTET* _data) {
675  numbits = _numbits;
676  data = _data;
677  }
678 
686  numbits = _bs.numbits;
687  data = _bs.data;
688  }
689 } ;
690 
695 struct EXTRTCLASS ASN1TBitStr32 : public ASN1BitStr32 {
699  ASN1TBitStr32 () { numbits = 0; }
700 
708  ASN1TBitStr32 (OSUINT32 _numbits, const OSOCTET* _data) {
709  numbits = _numbits;
710  size_t sz = _numbits / 8;
711  if ( _numbits % 8 > 0 ) sz += 1;
712  OSCRTLSAFEMEMCPY (data, sizeof(data), _data, sz);
713  }
714 
722  numbits = _bs.numbits;
723  OSCRTLSAFEMEMCPY (data, sizeof(data), _bs.data, sizeof(_bs.data));
724  }
725 } ;
726 
727 /* Dynamic octet string */
728 #include "rtsrc/ASN1TOctStr.h"
729 #include "rtsrc/ASN1TOctStr64.h"
730 
735 struct EXTRTCLASS ASN1TBMPString : public ASN1BMPString {
739  inline ASN1TBMPString () {
740  nchars = 0;
741  data = 0;
742  }
743 } ;
744 
749 struct EXTRTCLASS ASN1TUniversalString : public ASN1UniversalString {
754  nchars = 0;
755  data = 0;
756  }
757 } ;
758 
763 struct EXTRTCLASS ASN1TOpenType : public ASN1OpenType {
767  inline ASN1TOpenType () {
768  numocts = 0;
769  data = 0;
770  }
771 } ;
772 
778 struct EXTRTCLASS Asn1TObject : public Asn1Object {
782  inline Asn1TObject () {
783  encoded.numocts = 0;
784  encoded.data = 0;
785  decoded = 0;
786  index =0;
787  }
788 } ;
789 
790 typedef Asn1TObject ASN1TObject;
791 
792 /* Object identifier */
793 #include "rtsrc/ASN1TObjId.h"
794 
799 struct EXTRTCLASS ASN1TSeqExt : public OSRTDList {
803  inline ASN1TSeqExt () {
804  rtxDListInit (this);
805  }
806 } ;
807 
813 struct EXTRTCLASS ASN1TPDU {
814  protected:
822 
823  public:
841  inline void setContext (OSRTContext* ctxt) {
842  if (mpContext.isNull()) mpContext = ctxt;
843  else if (ctxt == 0) mpContext = 0;
844  }
845 
850  virtual ~ASN1TPDU() {}
851 } ;
852 
857 struct EXTRTCLASS ASN1TSeqOfList : public OSRTDList {
861  inline ASN1TSeqOfList () {
862  rtxDListInit (this);
863  }
864 } ;
865 
871 struct EXTRTCLASS ASN1TPDUSeqOfList : public ASN1TSeqOfList, public ASN1TPDU {
876 } ;
877 
882 #endif
static EXTRTMETHOD void setErrorHandler(OSCTXT *pCtxt, Asn1ErrorHandler *pHandler)
Definition: asn1CppTypes.h:661
OSBOOL setDiag(OSBOOL value)
Definition: asn1CppTypes.h:549
Definition: asn1type.h:946
ASN1TBitStr32()
Definition: asn1CppTypes.h:699
ASN1TSeqExt()
Definition: asn1CppTypes.h:803
ASN1TDynBitStr()
Definition: asn1CppTypes.h:632
int setStatus(int stat)
virtual ~ASN1CType()
Definition: asn1CppTypes.h:378
static EXTRTMETHOD void removeEventHandler(OSCTXT *pCtxt, Asn1NamedEventHandler *pHandler)
void memFreeAll()
Definition: asn1CppTypes.h:483
Definition: asn1type.h:438
virtual void resetErrorInfo()
Definition: OSRTMsgBuf.h:205
ASN1TDynBitStr(ASN1DynBitStr &_bs)
Definition: asn1CppTypes.h:652
void * memAllocZ(size_t numocts)
Definition: OSRTContext.h:208
void memReset()
Definition: OSRTContext.h:251
ASN1TBitStr32(ASN1BitStr32 &_bs)
Definition: asn1CppTypes.h:721
virtual void setErrorHandler(Asn1ErrorHandler *pErrorHandler)
Definition: asn1CppTypes.h:259
virtual void printErrorInfo()
Definition: OSRTMsgBuf.h:197
Definition: asn1type.h:908
virtual OSRTCtxtPtr getContext()
Definition: OSRTMsgBuf.h:94
ASN1TBMPString()
Definition: asn1CppTypes.h:739
ASN1TOpenType()
Definition: asn1CppTypes.h:767
void rtxDListInit(OSRTDList *pList)
OSRTCtxtPtr getContext()
Definition: asn1CppTypes.h:399
Definition: rtxDList.h:64
void resetErrorInfo()
Definition: OSRTContext.h:267
int getStatus() const
Definition: asn1CppTypes.h:442
Definition: asn1CppTypes.h:871
virtual void removeEventHandler(Asn1NamedEventHandler *pEventHandler)
Definition: asn1CppTypes.h:234
void memFreePtr(void *ptr)
Definition: asn1CppTypes.h:520
OSRTCtxtPtr mpContext
Definition: asn1CppTypes.h:316
Asn1TObject()
Definition: asn1CppTypes.h:782
virtual void * getAppInfo()
Definition: asn1CppTypes.h:175
virtual int EncodeTo(OSRTMessageBufferIF &)
Definition: asn1CppTypes.h:586
Definition: asn1CppTypes.h:695
Definition: asn1CppTypes.h:102
Definition: asn1CppTypes.h:308
Definition: asn1CppTypes.h:813
virtual ~ASN1MessageBuffer()
Definition: asn1CppTypes.h:140
ASN1TUniversalString()
Definition: asn1CppTypes.h:753
virtual void resetErrorInfo()
Definition: asn1CppTypes.h:243
OSRTDListNode * rtxDListAppend(struct OSCTXT *pctxt, OSRTDList *pList, void *pData)
Definition: asn1type.h:1036
virtual void addEventHandler(Asn1NamedEventHandler *pEventHandler)
Definition: asn1CppTypes.h:150
Definition: asn1CppTypes.h:778
Definition: OSRTContext.h:310
ASN1TBitStr32(OSUINT32 _numbits, const OSOCTET *_data)
Definition: asn1CppTypes.h:708
OSCTXT * getCtxtPtr()
Definition: asn1CppTypes.h:407
void * memAlloc(OSSIZE numocts)
Definition: asn1CppTypes.h:456
void * memAllocZ(OSSIZE numocts)
Definition: asn1CppTypes.h:472
void printErrorInfo()
Definition: asn1CppTypes.h:529
#define ASN_E_NOTPDU
Definition: asn1ErrCodes.h:125
Definition: asn1CppTypes.h:735
Definition: asn1CppTypes.h:628
void memReset()
Definition: asn1CppTypes.h:507
void setContext(OSRTContext *ctxt)
Definition: asn1CppTypes.h:841
virtual int DecodeFrom(OSRTMessageBufferIF &, OSBOOL free=TRUE)
Definition: asn1CppTypes.h:602
void append(OSRTDList &llist, void *pdata)
Definition: asn1CppTypes.h:388
Definition: asn1CppTypes.h:857
OSRTMessageBufferIF * mpMsgBuf
Definition: asn1CppTypes.h:322
virtual int setStatus(int stat)
Definition: asn1CppTypes.h:130
virtual const OSOCTET * getMsgPtr()
Definition: OSRTMsgBuf.h:149
ASN1TDynBitStr64(ASN1DynBitStr64 &_bs)
Definition: asn1CppTypes.h:685
Definition: asn1type.h:958
#define OS_UNUSED_ARG(arg)
Definition: asn1CppEvtHndlr.h:55
Definition: asn1type.h:432
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:763
#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:109
Definition: asn1type.h:425
void resetError()
Definition: asn1CppTypes.h:538
#define RTERR_NOTSUPP
Definition: rtxErrCodes.h:528
Definition: asn1CppEvtHndlr.h:547
ASN1TDynBitStr64(OSSIZE _numbits, const OSOCTET *_data)
Definition: asn1CppTypes.h:674
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:641
OSBOOL isNull() const
Definition: OSRTContext.h:394
Definition: asn1CppEvtHndlr.h:67
virtual ~ASN1TPDU()
Definition: asn1CppTypes.h:850
virtual EXTRTMETHOD int initBuffer(OSOCTET *pMsgBuf, size_t msgBufLen)
OSRTCtxtPtr mpContext
Definition: asn1CppTypes.h:821
Definition: rtxContext.h:189
Definition: asn1type.h:918
#define LOG_RTERR(pctxt, stat)
Definition: rtxError.h:79
ASN1TDynBitStr64()
Definition: asn1CppTypes.h:665
virtual void MemFree()
Definition: asn1CppTypes.h:613
int getStatus() const
Definition: OSRTContext.h:124
virtual OSCTXT * getCtxtPtr()
Definition: OSRTMsgBuf.h:102
virtual OSBOOL isA(Type)
Definition: asn1CppTypes.h:225
void * memRealloc(void *ptr, OSSIZE numocts)
Definition: asn1CppTypes.h:497
Definition: asn1CppTypes.h:799
Definition: asn1CppTypes.h:749
ASN1TPDUSeqOfList()
Definition: asn1CppTypes.h:875
size_t getBitOffset()
Definition: asn1CppTypes.h:281
void * memRealloc(void *ptr, size_t numocts)
Definition: OSRTContext.h:243
void * memAlloc(size_t numocts)
Definition: OSRTContext.h:195
ASN1TSeqOfList()
Definition: asn1CppTypes.h:861
virtual void setAppInfo(void *)
Definition: asn1CppTypes.h:250