Objective Systems, Inc.  
Home
About ASN.1
Products
Free Software
Documents
Services
Resources
Resellers
Customers
Careers
About Us
Contact Us
 

Google


Objective Systems, Inc.

asn1XerCppTypes.h

Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 1997-2004 by Objective Systems, Inc. 00003 * 00004 * This software is furnished under a license and may be used and copied 00005 * only in accordance with the terms of such license and with the 00006 * inclusion of the above copyright notice. This software or any other 00007 * copies thereof may not be provided or otherwise made available to any 00008 * other person. No title to and ownership of the software is hereby 00009 * transferred. 00010 * 00011 * The information in this software is subject to change without notice 00012 * and should not be construed as a commitment by Objective Systems, Inc. 00013 * 00014 * PROPRIETARY NOTICE 00015 * 00016 * This software is an unpublished work subject to a confidentiality agreement 00017 * and is protected by copyright and trade secret law. Unauthorized copying, 00018 * redistribution or other use of this work is prohibited. 00019 * 00020 * The above notice of copyright on this source code product does not indicate 00021 * any actual or intended publication of such source code. 00022 * 00023 *****************************************************************************/ 00024 /* 00025 // CHANGE LOG 00026 // Date Init Description 00027 // 11/03/03 CZ Expand documentation comments. 00028 // 00030 */ 00031 00036 #ifndef _ASN1XERCPPTYPES_H_ 00037 #define _ASN1XERCPPTYPES_H_ 00038 00039 #include "rtxersrc/saxParser.h" 00040 #include "rtsrc/asn1CppTypes.h" 00041 #include "rtsrc/OSCInputStream.h" 00042 #include "rtxersrc/asn1xer.h" 00043 00048 #ifndef _NO_EXCEPTIONS 00049 #ifdef _TRACE 00050 00051 #define ASN1SAXTHROW(stat) throwSAXException (stat, __FILE__, __LINE__); 00052 00053 #define ASN1SAXCATCH0(toCatch,stat) \ 00054 catch (OSRTSAXException& toCatch) { \ 00055 cerr << "ASN1XERSAX ERROR: "; \ 00056 if (toCatch.getMessage()) \ 00057 cerr << StrX (toCatch.getMessage()); \ 00058 stat = toCatch.getStatus(); \ 00059 if (stat) \ 00060 cerr << "\n" << "Status: " << stat << endl; \ 00061 if (toCatch.getSrcFileName ()) {\ 00062 cerr << "File: " << StrX (toCatch.getSrcFileName ()); \ 00063 cerr << " Line: " << toCatch.getSrcLineNum () << endl; \ 00064 } \ 00065 } 00066 #else 00067 00068 #define ASN1SAXTHROW(stat) throwSAXException (stat); 00069 00070 #define ASN1SAXCATCH0(toCatch,stat) \ 00071 catch (OSRTSAXException& toCatch) { \ 00072 cerr << "ASN1XERSAX ERROR: "; \ 00073 if (toCatch.getMessage()) \ 00074 cerr << StrX (toCatch.getMessage()); \ 00075 stat = toCatch.getStatus(); \ 00076 if (stat) \ 00077 cerr << "\n" << "Status: " << stat << endl; \ 00078 } 00079 #endif 00080 00081 #define ASN1SAXCATCH(toCatch,stat) \ 00082 ASN1SAXCATCH0(toCatch,stat) \ 00083 catch (const ASN1MessageBuffer::RTLError& toCatch) { \ 00084 cerr << "ASN.1 RTL ERROR: " << toCatch.getStatus() << endl; \ 00085 stat = toCatch.getStatus(); \ 00086 } 00087 #else 00088 #define ASN1SAXTHROW(stat) { \ 00089 fprintf (stderr, "Fatal Error %i in %s at %i\n", stat, __FILE__, __LINE__); \ 00090 exit (-1); \ 00091 } 00092 #define ASN1SAXCATCH(toCatch,stat) 00093 #endif 00094 00101 // ASN.1 XER message buffer class 00102 00113 class EXTERNXER ASN1XERMessageBuffer : public ASN1MessageBuffer { 00114 protected: 00123 ASN1XERMessageBuffer (Type bufferType) : ASN1MessageBuffer(bufferType) {} 00124 public: 00125 } ; 00126 00127 // ASN.1 XER encode message buffer class 00136 class EXTERNXER ASN1XEREncodeBuffer : public ASN1XERMessageBuffer { 00137 public: 00142 ASN1XEREncodeBuffer (); 00143 00150 ASN1XEREncodeBuffer (ASN1BOOL canonical); 00151 00160 ASN1XEREncodeBuffer (ASN1BOOL canonical, ASN1CTXT* pSrcCtxt, 00161 size_t initBufSize = 0); 00162 00171 ASN1XEREncodeBuffer (ASN1OCTET* pMsgBuf, size_t msgBufLen); 00172 00185 ASN1XEREncodeBuffer (ASN1OCTET* pMsgBuf, size_t msgBufLen, 00186 ASN1BOOL canonical, ASN1BOOL openType = FALSE); 00193 inline size_t getMsgLen () { 00194 return (getCtxtPtr()->buffer.byteIndex); 00195 } 00196 00208 int init (); 00209 00219 virtual ASN1BOOL isA (Type bufferType) { 00220 return bufferType == XEREncode; 00221 } 00227 inline void setCanonical() { rtCtxtSetFlag (getCtxtPtr(), ASN1CANXER); } 00228 00236 inline void setOpenType () { rtCtxtSetFlag (getCtxtPtr(), ASN1OPENTYPE); } 00237 00248 long write (const char* filename); 00249 00258 long write (FILE* fp); 00259 } ; 00260 00261 //XER SAX decode handler base class. ASN1XERSAXDecodeHandler derived class. 00271 class EXTERNXER ASN1XERSAXDecodeHandler : 00272 public OSXMLContentHandler, public OSXMLErrorInfo 00273 { 00274 protected: 00275 ASN1XERState mCurrState; 00276 int mCurrElemID; 00277 int mLevel, mStartLevel; 00278 const char* mpTypeName; 00279 struct ErrorInfo { 00280 int stat; 00281 const char* file; 00282 int line; 00283 } errorInfo; 00284 public: 00285 00289 ASN1XERSAXDecodeHandler () : 00290 mCurrState(XERINIT), mCurrElemID(0), mLevel(0), mpTypeName(0) {} 00291 00292 virtual void startElement 00293 (const XMLCHAR* const uri, 00294 const XMLCHAR* const localname, 00295 const XMLCHAR* const qname, 00296 const XMLCHAR* const* attrs); 00297 00298 virtual void characters 00299 (const XMLCHAR* const chars, const unsigned int length); 00300 00301 virtual void endElement 00302 (const XMLCHAR* const uri, 00303 const XMLCHAR* const localname, 00304 const XMLCHAR* const qname); 00305 00306 virtual void startDocument(); 00307 virtual void endDocument (); 00308 00309 // SAX Error Info handlers 00310 virtual void resetErrorInfo (); 00311 virtual void setErrorInfo (int status, const char* file = 0, int line = 0); 00312 virtual int getErrorInfo (int* status, const char** file, int* line); 00313 00314 // SAX ErrorHandler interface 00315 00316 // void warning (const SAXParseException& exception); 00317 // void error (const SAXParseException& exception); 00318 // void fatalError (const SAXParseException& exception); 00319 // void resetErrors (); 00320 00328 inline ASN1XERState getState() { return mCurrState; } 00329 virtual void finalize() {} 00330 ASN1CTXT* finalizeMemBuf(ASN1MessageBufferIF* msgBuf, ASN1MemBuf& memBuf); 00331 virtual void init (int level = 0) { 00332 mCurrState = XERINIT; mStartLevel = mLevel = level; 00333 } 00334 00342 inline ASN1BOOL isComplete () { return mLevel == mStartLevel; } 00343 void setTypeName (const char* typeName) { 00344 mpTypeName = typeName; 00345 } 00346 virtual void throwSAXException (int stat, const char* file = 0, 00347 int line = 0); 00348 } ; 00349 00350 00351 // ASN.1 XER Decode Message Buffer Class 00363 class EXTERNXER ASN1XERDecodeBuffer : public ASN1XERMessageBuffer { 00364 protected: 00365 union { 00366 const char* fileName; 00367 OSCInputStream* pInputStream; 00368 struct { 00369 const ASN1OCTET* pMemBuf; 00370 int bufSize; 00371 } memBuf; 00372 } mInput; 00373 enum { 00374 INPUT_FILE, 00375 INPUT_STREAM, 00376 INPUT_STREAM_ATTACHED, 00377 INPUT_MEMORY 00378 } mInputId; 00379 public: 00380 00390 ASN1XERDecodeBuffer (const char* xmlFile); 00391 00404 ASN1XERDecodeBuffer (const ASN1OCTET* msgbuf, 00405 size_t numocts, 00406 ASN1BOOL openType = FALSE); 00407 00417 ASN1XERDecodeBuffer (OSCInputStream& inputStream, 00418 ASN1BOOL openType = FALSE); 00419 00420 ~ASN1XERDecodeBuffer (); 00421 00431 int decodeXML (OSXMLReader* pReader); 00432 00440 inline const char* getXmlFileName() { 00441 return (mInputId == INPUT_FILE) ? mInput.fileName : 0; 00442 } 00443 00455 int initBuffer (ASN1MemBuf& membuf) { 00456 return ASN1XERMessageBuffer::initBuffer (membuf); 00457 } 00458 00459 int initBuffer (char* str); 00460 int initBuffer (ASN116BITCHAR* str) { return ASN_E_NOTSUPP; } 00461 00462 virtual ASN1BOOL isA (Type bufferType) { 00463 return bufferType == XERDecode; 00464 } 00465 virtual void throwSAXException (int stat, const char* file = 0, 00466 int line = 0); 00467 00468 inline void setOpenType () { rtCtxtSetFlag (getCtxtPtr(), ASN1OPENTYPE); } 00469 } ; 00470 00480 #endif // _ASN1XERCPPTYPES_H_ 00481 00482 00483 00484

Copyright © 1997-2004 Objective Systems,Inc.
All Rights Reserved.
This document may be distributed in any form, electronic
or otherwise, provided that it is distributed in its entirety
and that the copyright and this notice are included.

This file was last modified on 1 Oct 2004.
ASN1C XER Runtime, ASN1C v5.7x