📄 asner.h
字号:
/* * asner.h * * Abstract Syntax Notation Encoding Rules classes * * Portable Windows Library * * Copyright (c) 1993-2002 Equivalence Pty. Ltd. * * The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. * * The Original Code is Portable Windows Library. * * The Initial Developer of the Original Code is Equivalence Pty. Ltd. * * Contributor(s): ______________________________________. * * $Log: asner.h,v $ * Revision 1.45 2005/06/07 06:25:53 csoutheren * Applied patch 1199897 to increase speed of ASN parser debugging output * Thanks to Dmitriy <ddv@abinet.com> * * Revision 1.44 2004/11/11 07:34:50 csoutheren * Added #include <ptlib.h> * * Revision 1.43 2004/04/18 04:33:35 rjongbloed * Changed all operators that return BOOL to return standard type bool. This is primarily * for improved compatibility with std STL usage removing many warnings. * * Revision 1.42 2003/12/14 10:21:29 rjongbloed * Fixed bug in length incorrectlty decoded from ASN and (apparently) rare circumstances. Thanks pangxg@hotmail.com. * Cleaned up return values to be BOOL rather than int for some functions. * * Revision 1.41 2003/08/18 23:32:22 rjongbloed * Micro optimisation suggested by Chih-Wei Huang * * Revision 1.40 2003/08/01 16:00:51 csoutheren * Changed #if to #ifdef to (maybe) avoid compiler problems with gcc 2.95.2 * * Revision 1.39 2003/08/01 02:12:34 csoutheren * Changed to allow easy isolation of PER, BER and XER encoding/decoding routines * * Revision 1.38 2003/04/22 23:39:09 craigs * Changed some functions from protected to public for MacOSX. Thanks to Hugo Santos * * Revision 1.37 2003/04/17 14:44:44 craigs * Removed MacOS specific defines to make some attributes public * Thanks to Hugo Santos and apologies to Roger Hardiman * * Revision 1.36 2003/02/26 01:57:44 robertj * Added XML encoding rules to ASN system, thanks Federico Pinna * * Revision 1.35 2003/02/01 13:25:52 robertj * Added function to add new elements directly to ASN array. * * Revision 1.34 2003/01/24 23:43:43 robertj * Fixed subtle problems with the use of MAX keyword for unsigned numbers, * should beUINT_MAX not INT_MAX, thanks Stevie Gray for pointing it out. * * Revision 1.33 2002/11/26 23:29:18 robertj * Added missing const to DecodeSubType() function. * * Revision 1.32 2002/11/06 22:47:23 robertj * Fixed header comment (copyright etc) * * Revision 1.31 2002/10/31 05:50:49 robertj * Changed to use new UTF-8/UCS-2 conversion functions on PString. * * Revision 1.30 2002/10/10 14:37:40 rogerh * In two of the PASN classes make the protected members public. This * makes OpenH323 compile in Mac OS X 10.2.1 * * Revision 1.29 2002/09/16 01:08:59 robertj * Added #define so can select if #pragma interface/implementation is used on * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. * * Revision 1.28 2002/05/29 01:22:35 robertj * Added ability to set object id from unsigned integer arrays. * * Revision 1.27 2002/05/21 04:23:40 robertj * Fixed problem with ASN encoding/decoding unsconstrained negative numbers, * * Revision 1.26 2002/05/14 06:59:31 robertj * Added more bullet proofing so a malformed PDU cannot cause teh decoder * to try and allocate huge arrays and consume all CPU and memory on a * system. A configurable limit of 100 is set for things like SEQUENCE OF. * * Revision 1.25 2001/12/13 09:13:28 robertj * Added function get get oid as a string. * Added functions to compare oid to PString. * * Revision 1.24 2001/09/14 01:59:59 robertj * Fixed problem with incorrectly initialised PASN_Choice sub-object. * * Revision 1.23 2001/08/06 01:39:02 robertj * Added assignement operator with RHS of PASN_BMPString to classes * descended from PASN_BMPString. * * Revision 1.22 2001/06/14 02:14:12 robertj * Added functions to encode and decode another ASN type that is inside * an octet string, useful for ANY or EXTERNAL types etc. * * Revision 1.21 2001/04/30 06:47:04 robertj * Fixed problem with en/decoding more than 16 extension fields in a sequence. * * Revision 1.20 2001/04/26 08:15:58 robertj * Fixed problem with ASN compile of single constraints on enumerations. * * Revision 1.19 2001/04/23 04:40:14 robertj * Added ASN standard types GeneralizedTime and UTCTime * * Revision 1.18 2001/04/12 03:25:22 robertj * Fixed PASN_Boolean cosntructor to be compatible with usage in ASN parser. * Changed all PASN_xxx types so constructor can take real type as only * parameter. eg PASN_OctetString s = "fred"; * * Revision 1.17 2001/03/21 03:32:35 robertj * Aded ability to get at the data bits buffer in a PASN_BitString * * Revision 1.16 2001/01/24 04:36:56 robertj * Added more bulletproofing to ASN structures to obey constraints. * * Revision 1.15 2000/10/26 11:09:07 robertj * More bullet proofing of PER decoder, changed bit type to be unsigned. * * Revision 1.14 2000/10/25 04:05:44 robertj * More bullet proofing of PER decoder. * * Revision 1.13 2000/07/11 18:23:03 robertj * Added ability to set/get BMP string data as PWORDArray. * * Revision 1.12 2000/04/10 17:30:42 robertj * Added [] operator for char access on ASN string classes. * * Revision 1.11 2000/02/29 06:32:12 robertj * Added ability to remove optional field in sequence, thanks Dave Harvey. * * Revision 1.10 1999/08/09 13:02:45 robertj * dded ASN compiler #defines for backward support of pre GCC 2.9 compilers. * Added ASN compiler #defines to reduce its memory footprint. * * Revision 1.9 1999/07/22 06:48:51 robertj * Added comparison operation to base ASN classes and compiled ASN code. * Added support for ANY type in ASN parser. * * Revision 1.8 1999/03/09 09:34:05 robertj * Fixed typo's. * * Revision 1.7 1999/03/09 08:01:46 robertj * Changed comments for doc++ support (more to come). * * Revision 1.6 1998/09/23 06:19:21 robertj * Added open source copyright license. * * Revision 1.5 1998/05/21 04:26:53 robertj * Fixed numerous PER problems. * * Revision 1.4 1998/05/07 05:19:28 robertj * Fixed problems with using copy constructor/assignment oeprator on PASN_Objects. * * Revision 1.3 1997/12/18 05:08:13 robertj * Added function to get choice discriminat`or name. * * Revision 1.2 1997/12/11 10:35:42 robertj * Support for new ASN file parser. * */#ifndef _ASNER_H#define _ASNER_H#ifdef P_USE_PRAGMA#pragma interface#endif// provide options to omit vertain encodings, if needed#define P_INCLUDE_PER#define P_INCLUDE_BER#define P_INCLUDE_XERclass PASN_Stream;class PBER_Stream;class PPER_Stream;#if P_EXPATclass PXER_Stream;class PXMLElement;#else#undef P_INCLUDE_XER#endif#include <ptlib.h>//////////////////////////////////////////////////////////////////////////////** Base class for ASN encoding/decoding.*/class PASN_Object : public PObject{ PCLASSINFO(PASN_Object, PObject); public: /** Return a string giving the type of the object */ virtual PString GetTypeAsString() const = 0; PINDEX GetObjectLength() const; virtual PINDEX GetDataLength() const = 0; virtual BOOL IsPrimitive() const { return TRUE; } virtual BOOL Decode(PASN_Stream &) = 0; virtual void Encode(PASN_Stream &) const = 0; BOOL IsExtendable() const { return extendable; } void SetExtendable(BOOL ext = TRUE) { extendable = ext; } enum TagClass { UniversalTagClass, ApplicationTagClass, ContextSpecificTagClass, PrivateTagClass, DefaultTagClass }; TagClass GetTagClass() const { return tagClass; } enum UniversalTags { InvalidUniversalTag, UniversalBoolean, UniversalInteger, UniversalBitString, UniversalOctetString, UniversalNull, UniversalObjectId, UniversalObjectDescriptor, UniversalExternalType, UniversalReal, UniversalEnumeration, UniversalEmbeddedPDV, UniversalSequence = 16, UniversalSet, UniversalNumericString, UniversalPrintableString, UniversalTeletexString, UniversalVideotexString, UniversalIA5String, UniversalUTCTime, UniversalGeneralisedTime, UniversalGeneralizedTime = UniversalGeneralisedTime, UniversalGraphicString, UniversalVisibleString, UniversalGeneralString, UniversalUniversalString, UniversalBMPString = 30 }; unsigned GetTag() const { return tag; } virtual void SetTag(unsigned newTag, TagClass tagClass = DefaultTagClass); enum ConstraintType { Unconstrained, PartiallyConstrained, FixedConstraint, ExtendableConstraint }; enum MinimumValueTag { MinimumValue = INT_MIN }; enum MaximumValueTag { MaximumValue = INT_MAX }; void SetConstraints(ConstraintType type, int value) { SetConstraintBounds(type, value, value); } void SetConstraints(ConstraintType, int lower, MaximumValueTag /*upper*/) { SetConstraintBounds(PartiallyConstrained, (int)lower, lower < 0 ? INT_MAX : UINT_MAX); } void SetConstraints(ConstraintType, MinimumValueTag lower, unsigned upper) { SetConstraintBounds(PartiallyConstrained, (int)lower, (unsigned)upper); } void SetConstraints(ConstraintType, MinimumValueTag lower, MaximumValueTag upper) { SetConstraintBounds(PartiallyConstrained, (int)lower, (unsigned)upper); } void SetConstraints(ConstraintType type, int lower, unsigned upper) { SetConstraintBounds(type, lower, upper); } virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper); virtual void SetCharacterSet(ConstraintType ctype, const char * charSet); virtual void SetCharacterSet(ConstraintType ctype, unsigned firstChar, unsigned lastChar); static PINDEX GetMaximumArraySize(); static void SetMaximumArraySize(PINDEX sz); static PINDEX GetMaximumStringSize(); static void SetMaximumStringSize(PINDEX sz); protected: PASN_Object(unsigned tag, TagClass tagClass, BOOL extend = FALSE); /// PER extension capability BOOL extendable; /// BER tag class TagClass tagClass; /// ASN object tag unsigned tag;};/** Base class for constrained ASN encoding/decoding.*/class PASN_ConstrainedObject : public PASN_Object{ PCLASSINFO(PASN_ConstrainedObject, PASN_Object); public: BOOL IsConstrained() const { return constraint != Unconstrained; } int GetLowerLimit() const { return lowerLimit; } unsigned GetUpperLimit() const { return upperLimit; } BOOL ConstrainedLengthDecode(PPER_Stream & strm, unsigned & length); void ConstrainedLengthEncode(PPER_Stream & strm, unsigned length) const; BOOL ConstraintEncode(PPER_Stream & strm, unsigned value) const; protected: virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper); PASN_ConstrainedObject(unsigned tag, TagClass tagClass); ConstraintType constraint; int lowerLimit; unsigned upperLimit;};/** Class for ASN Null type.*/class PASN_Null : public PASN_Object{ PCLASSINFO(PASN_Null, PASN_Object); public: PASN_Null(unsigned tag = UniversalNull, TagClass tagClass = UniversalTagClass); virtual Comparison Compare(const PObject & obj) const; virtual PObject * Clone() const; virtual void PrintOn(ostream & strm) const; virtual PString GetTypeAsString() const; virtual PINDEX GetDataLength() const; virtual BOOL Decode(PASN_Stream &); virtual void Encode(PASN_Stream &) const;};/** Class for ASN Boolean type.*/class PASN_Boolean : public PASN_Object{ PCLASSINFO(PASN_Boolean, PASN_Object); public: PASN_Boolean(BOOL val = FALSE); PASN_Boolean(unsigned tag, TagClass tagClass, BOOL val = FALSE); PASN_Boolean & operator=(BOOL v) { value = v; return *this; } operator BOOL() const { return value; } BOOL GetValue() const { return value; } void SetValue(BOOL v) { value = v; } virtual Comparison Compare(const PObject & obj) const; virtual PObject * Clone() const; virtual void PrintOn(ostream & strm) const; virtual PString GetTypeAsString() const; virtual PINDEX GetDataLength() const; virtual BOOL Decode(PASN_Stream &); virtual void Encode(PASN_Stream &) const; protected: BOOL value;};/** Class for ASN Integer type.*/class PASN_Integer : public PASN_ConstrainedObject
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -