ASN1C C/C++ Common Runtime  ASN1C v7.2.x
asn1CppTypes.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1997-2018 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 
231  virtual OSBOOL isA (Type /*bufferType*/) { return FALSE; }
232 
240  virtual void removeEventHandler (Asn1NamedEventHandler* pEventHandler) {
242  (getCtxtPtr(), pEventHandler);
243  }
244 
249  virtual void resetErrorInfo () {
251  }
252 
256  virtual void setAppInfo (void* /*pAppInfo*/) { }
257 
265  virtual void setErrorHandler (Asn1ErrorHandler* pErrorHandler) {
267  (getCtxtPtr(), pErrorHandler);
268  }
269 
280  EXTRTMETHOD int setRunTimeKey (const OSOCTET* key, OSSIZE keylen);
281 
287  inline size_t getBitOffset () {
288  return rtxCtxtGetBitOffset (getCtxtPtr());
289  }
290 
291  // The following are deprecated method definitions maintained for
292  // backward compatibility only..
293 
294  inline OSOCTET* GetMsgCopy () { return getMsgCopy(); }
295  inline const OSOCTET* GetMsgPtr() { return getMsgPtr(); }
296  inline void PrintErrorInfo() { printErrorInfo(); }
297 
298 } ;
314 class EXTRTCLASS ASN1CType {
315  protected:
323 
328  OSRTMessageBufferIF* mpMsgBuf;
329 
334  EXTRTMETHOD ASN1CType ();
335 
342  EXTRTMETHOD ASN1CType (OSRTContext& ctxt);
343 
344  EXTRTMETHOD int setMsgBuf
345  (OSRTMessageBufferIF& msgBuf, OSBOOL initBuf=FALSE);
346 
357  EXTRTMETHOD int setRunTimeKey (const OSOCTET* key, OSSIZE keylen);
358 
359  public:
369  EXTRTMETHOD ASN1CType (OSRTMessageBufferIF& msgBuf);
370 
378  EXTRTMETHOD ASN1CType (const ASN1CType& orig);
379 
384  virtual ~ASN1CType () {}
385 
394  inline void append (OSRTDList& llist, void* pdata) {
395  if (0 == rtxDListAppend (getCtxtPtr(), &llist, pdata))
396  LOG_RTERR (getCtxtPtr(), RTERR_NOMEM);
397  }
398 
406  return mpContext;
407  }
408 
413  inline OSCTXT* getCtxtPtr () {
414  return (!mpContext.isNull ()) ? mpContext->getPtr() : 0;
415  }
416 
433  char* getErrorText (char* textbuf = (char*)0, OSSIZE bufsize = 0);
434 
448  inline int getStatus () const {
449  return (!mpContext.isNull()) ? mpContext->getStatus() : 0;
450  }
451 
462  inline void* memAlloc (OSSIZE numocts) {
463  if (mpContext.isNull ()) return 0;
464  return mpContext->memAlloc (numocts);
465  }
466 
478  inline void* memAllocZ (OSSIZE numocts) {
479  if (mpContext.isNull ()) return 0;
480  return mpContext->memAllocZ (numocts);
481  }
482 
489  inline void memFreeAll () {
490  if (!mpContext.isNull ())
491  mpContext->memFreeAll ();
492  }
493 
503  inline void* memRealloc (void* ptr, OSSIZE numocts) {
504  if (mpContext.isNull ()) return 0;
505  return mpContext->memRealloc (ptr, numocts);
506  }
507 
513  inline void memReset () {
514  if (!mpContext.isNull ())
515  mpContext->memReset ();
516  }
517 
526  inline void memFreePtr (void* ptr) {
527  if (!mpContext.isNull ())
528  mpContext->memFreePtr (ptr);
529  }
530 
535  inline void printErrorInfo () {
536  if (!mpContext.isNull ())
537  mpContext->printErrorInfo ();
538  }
539 
544  inline void resetError () {
545  if (!mpContext.isNull ())
546  mpContext->resetErrorInfo ();
547  }
548 
555  inline OSBOOL setDiag (OSBOOL value) {
556  return getContext()->setDiag (value);
557  }
558 
567  virtual EXTRTMETHOD int Encode ();
568 
580  virtual EXTRTMETHOD int Decode (OSBOOL free = FALSE);
581 
592  virtual int EncodeTo (OSRTMessageBufferIF& /*msgBuf*/)
593  { return ASN_E_NOTPDU; }
594 
608  virtual int DecodeFrom (OSRTMessageBufferIF& /*msgBuf*/, OSBOOL free = TRUE)
609  { OS_UNUSED_ARG(free); return ASN_E_NOTPDU; }
610 } ;
624 struct EXTRTCLASS ASN1TDynBitStr : public ASN1DynBitStr {
628  ASN1TDynBitStr () { data = 0; numbits = 0; }
629 
637  ASN1TDynBitStr (OSUINT32 _numbits, const OSOCTET* _data) {
638  numbits = _numbits;
639  data = _data;
640  }
641 
649  numbits = _bs.numbits;
650  data = _bs.data;
651  }
652 } ;
653 
657 struct EXTRTCLASS ASN1TDynBitStr64 : public ASN1DynBitStr64 {
661  ASN1TDynBitStr64 () { data = 0; numbits = 0; }
662 
670  ASN1TDynBitStr64 (OSSIZE _numbits, const OSOCTET* _data) {
671  numbits = _numbits;
672  data = _data;
673  }
674 
682  numbits = _bs.numbits;
683  data = _bs.data;
684  }
685 } ;
686 
691 struct EXTRTCLASS ASN1TBitStr32 : public ASN1BitStr32 {
695  ASN1TBitStr32 () { numbits = 0; }
696 
704  ASN1TBitStr32 (OSUINT32 _numbits, const OSOCTET* _data) {
705  numbits = _numbits;
706  size_t sz = _numbits / 8;
707  if ( _numbits % 8 > 0 ) sz += 1;
708  OSCRTLSAFEMEMCPY (data, sizeof(data), _data, sz);
709  }
710 
718  numbits = _bs.numbits;
719  OSCRTLSAFEMEMCPY (data, sizeof(data), _bs.data, sizeof(_bs.data));
720  }
721 } ;
722 
723 /* Dynamic octet string */
724 #include "rtsrc/ASN1TOctStr.h"
725 #include "rtsrc/ASN1TOctStr64.h"
726 
731 struct EXTRTCLASS ASN1TBMPString : public ASN1BMPString {
735  inline ASN1TBMPString () {
736  nchars = 0;
737  data = 0;
738  }
739 } ;
740 
745 struct EXTRTCLASS ASN1TUniversalString : public ASN1UniversalString {
750  nchars = 0;
751  data = 0;
752  }
753 } ;
754 
759 struct EXTRTCLASS ASN1TOpenType : public ASN1OpenType {
763  inline ASN1TOpenType () {
764  numocts = 0;
765  data = 0;
766  }
767 } ;
768 
774 struct EXTRTCLASS Asn1TObject : public Asn1Object {
778  inline Asn1TObject () {
779  encoded.numocts = 0;
780  encoded.data = 0;
781  decoded = 0;
782  index =0;
783  }
784 } ;
785 
786 typedef Asn1TObject ASN1TObject;
787 
788 /* Object identifier */
789 #include "rtsrc/ASN1TObjId.h"
790 
795 struct EXTRTCLASS ASN1TSeqExt : public OSRTDList {
799  inline ASN1TSeqExt () {
800  rtxDListInit (this);
801  }
802 } ;
803 
809 struct EXTRTCLASS ASN1TPDU {
810  protected:
818 
819  public:
837  inline void setContext (OSRTContext* ctxt) {
838  if (mpContext.isNull()) mpContext = ctxt;
839  else if (ctxt == 0) mpContext = 0;
840  }
841 
846  virtual ~ASN1TPDU() {}
847 } ;
848 
853 struct EXTRTCLASS ASN1TSeqOfList : public OSRTDList {
857  inline ASN1TSeqOfList () {
858  rtxDListInit (this);
859  }
860 } ;
861 
867 struct EXTRTCLASS ASN1TPDUSeqOfList : public ASN1TSeqOfList, public ASN1TPDU {
872 } ;
873 
878 #endif
static EXTRTMETHOD void setErrorHandler(OSCTXT *pCtxt, Asn1ErrorHandler *pHandler)
Definition: asn1CppTypes.h:657
OSBOOL setDiag(OSBOOL value)
Definition: asn1CppTypes.h:555
Definition: asn1type.h:686
ASN1TBitStr32()
Definition: asn1CppTypes.h:695
ASN1TSeqExt()
Definition: asn1CppTypes.h:799
ASN1TDynBitStr()
Definition: asn1CppTypes.h:628
int setStatus(int stat)
virtual ~ASN1CType()
Definition: asn1CppTypes.h:384
static EXTRTMETHOD void removeEventHandler(OSCTXT *pCtxt, Asn1NamedEventHandler *pHandler)
void memFreeAll()
Definition: asn1CppTypes.h:489
Definition: asn1type.h:438
virtual void resetErrorInfo()
Definition: OSRTMsgBuf.h:200
ASN1TDynBitStr(ASN1DynBitStr &_bs)
Definition: asn1CppTypes.h:648
void * memAllocZ(size_t numocts)
Definition: OSRTContext.h:209
void memReset()
Definition: OSRTContext.h:252
ASN1TBitStr32(ASN1BitStr32 &_bs)
Definition: asn1CppTypes.h:717
virtual void setErrorHandler(Asn1ErrorHandler *pErrorHandler)
Definition: asn1CppTypes.h:265
virtual void printErrorInfo()
Definition: OSRTMsgBuf.h:192
Definition: asn1type.h:648
virtual OSRTCtxtPtr getContext()
Definition: OSRTMsgBuf.h:94
ASN1TBMPString()
Definition: asn1CppTypes.h:735
ASN1TOpenType()
Definition: asn1CppTypes.h:763
void rtxDListInit(OSRTDList *pList)
OSRTCtxtPtr getContext()
Definition: asn1CppTypes.h:405
Definition: rtxDList.h:64
void resetErrorInfo()
Definition: OSRTContext.h:268
int getStatus() const
Definition: asn1CppTypes.h:448
Definition: asn1CppTypes.h:867
virtual void removeEventHandler(Asn1NamedEventHandler *pEventHandler)
Definition: asn1CppTypes.h:240
void memFreePtr(void *ptr)
Definition: asn1CppTypes.h:526
OSRTCtxtPtr mpContext
Definition: asn1CppTypes.h:322
Asn1TObject()
Definition: asn1CppTypes.h:778
virtual void * getAppInfo()
Definition: asn1CppTypes.h:175
virtual int EncodeTo(OSRTMessageBufferIF &)
Definition: asn1CppTypes.h:592
Definition: asn1CppTypes.h:691
Definition: asn1CppTypes.h:102
Definition: asn1CppTypes.h:314
Definition: asn1CppTypes.h:809
virtual ~ASN1MessageBuffer()
Definition: asn1CppTypes.h:140
ASN1TUniversalString()
Definition: asn1CppTypes.h:749
virtual void resetErrorInfo()
Definition: asn1CppTypes.h:249
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:774
Definition: OSRTContext.h:310
ASN1TBitStr32(OSUINT32 _numbits, const OSOCTET *_data)
Definition: asn1CppTypes.h:704
OSCTXT * getCtxtPtr()
Definition: asn1CppTypes.h:413
void * memAlloc(OSSIZE numocts)
Definition: asn1CppTypes.h:462
void * memAllocZ(OSSIZE numocts)
Definition: asn1CppTypes.h:478
void printErrorInfo()
Definition: asn1CppTypes.h:535
#define ASN_E_NOTPDU
Definition: asn1ErrCodes.h:123
Definition: asn1CppTypes.h:731
Definition: asn1CppTypes.h:624
void memReset()
Definition: asn1CppTypes.h:513
void setContext(OSRTContext *ctxt)
Definition: asn1CppTypes.h:837
virtual int DecodeFrom(OSRTMessageBufferIF &, OSBOOL free=TRUE)
Definition: asn1CppTypes.h:608
void append(OSRTDList &llist, void *pdata)
Definition: asn1CppTypes.h:394
virtual size_t getMsgLen()
Definition: asn1CppTypes.h:180
Definition: asn1CppTypes.h:853
OSRTMessageBufferIF * mpMsgBuf
Definition: asn1CppTypes.h:328
virtual int setStatus(int stat)
Definition: asn1CppTypes.h:130
virtual const OSOCTET * getMsgPtr()
Definition: OSRTMsgBuf.h:149
ASN1TDynBitStr64(ASN1DynBitStr64 &_bs)
Definition: asn1CppTypes.h:681
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:759
#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:544
#define RTERR_NOTSUPP
Definition: rtxErrCodes.h:528
Definition: asn1CppEvtHndlr.h:547
ASN1TDynBitStr64(OSSIZE _numbits, const OSOCTET *_data)
Definition: asn1CppTypes.h:670
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:637
OSBOOL isNull() const
Definition: OSRTContext.h:394
Definition: asn1CppEvtHndlr.h:67
virtual ~ASN1TPDU()
Definition: asn1CppTypes.h:846
virtual EXTRTMETHOD int initBuffer(OSOCTET *pMsgBuf, size_t msgBufLen)
OSRTCtxtPtr mpContext
Definition: asn1CppTypes.h:817
Definition: rtxContext.h:185
Definition: asn1type.h:658
#define LOG_RTERR(pctxt, stat)
Definition: rtxError.h:79
ASN1TDynBitStr64()
Definition: asn1CppTypes.h:661
int getStatus() const
Definition: OSRTContext.h:125
virtual OSCTXT * getCtxtPtr()
Definition: OSRTMsgBuf.h:102
virtual OSBOOL isA(Type)
Definition: asn1CppTypes.h:231
void * memRealloc(void *ptr, OSSIZE numocts)
Definition: asn1CppTypes.h:503
Definition: asn1CppTypes.h:795
Definition: asn1CppTypes.h:745
ASN1TPDUSeqOfList()
Definition: asn1CppTypes.h:871
size_t getBitOffset()
Definition: asn1CppTypes.h:287
void * memRealloc(void *ptr, size_t numocts)
Definition: OSRTContext.h:244
void * memAlloc(size_t numocts)
Definition: OSRTContext.h:196
ASN1TSeqOfList()
Definition: asn1CppTypes.h:857
virtual void setAppInfo(void *)
Definition: asn1CppTypes.h:256