00001 // OSB library ************************************************ -*- C++ -*- 00006 /* 00007 AUTHOR(S): Stephan Broennimann (vb) 00008 00009 RCS information 00010 $Name: OSB_060808 $ 00011 $Revision: 1.1 $ 00012 00013 License 00014 OSB rating and billing library for communication networks 00015 Copyright (C) 2004, 2005, 2006 OSB systems 00016 00017 This file may be distributed and/or modify under the terms of the 00018 GNU General Public License (GPL) as published by the Free Software 00019 Foundation which is provided in the file LICENSE.GPL included in the 00020 packaging of this file. 00021 00022 The file is distributed in the hope that it will be useful, but WITHOUT 00023 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00024 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00025 for more details. 00026 00027 Holders of a OSB Commercial License may use this file under the terms 00028 and conditions of this commercial license. 00029 */ 00030 #ifndef _ASN1READER_H_ 00031 #define _ASN1READER_H_ 00032 00033 // ************************************************************************ 00034 // included header files 00035 // + standard includes 00036 #include <cstdio> 00037 00038 // + libraries 00039 00040 // + local headers 00041 #include "asn1.h" 00042 #include "osberror.h" 00043 00044 // + class declarations 00045 namespace OSB_LIB { 00046 class OsbErrors; 00047 } 00048 00049 // ************************************************************************ 00050 // namespace extensions 00051 namespace OSB_LIB { 00052 00053 // ************************************************************************ 00054 // forward declarations 00055 class Asn1Reader; 00056 00057 // ************************************************************************ 00058 // class definitions 00066 class Asn1Info { 00068 friend class Asn1Reader; 00069 public: 00071 explicit Asn1Info(long filePos = -1); 00072 public: 00078 long filePos() const; 00080 size_t tagValue() const; 00082 const Asn1Tag& tag() const; 00084 const Asn1Len& dataLen() const; 00086 const Asn1Byte* data() const; 00087 00097 size_t nextMember(Asn1Info& dest); 00098 00099 private: // Asn1Reader only 00108 size_t getTagAndLen( 00109 const Asn1Byte* data, 00110 size_t size 00111 ); 00112 00121 size_t construct( 00122 const Asn1Byte* data, 00123 size_t size 00124 ); 00125 00126 private: 00128 long filePos_; 00130 Asn1Tag tag_; 00132 Asn1Len dataLen_; 00134 size_t asn1Size_; 00135 00142 const Asn1Byte* data_; 00144 size_t curPos_; 00145 }; // class Asn1Info 00146 00150 class Asn1Reader { 00151 public: 00153 Asn1Reader(); 00155 ~Asn1Reader(); 00156 private: 00158 Asn1Reader(const Asn1Reader&); 00160 Asn1Reader& operator=(const Asn1Reader&); 00161 00162 public: 00172 void init(); 00173 00185 void init( 00186 size_t blkSize, 00187 Asn1Byte blkFiller 00188 ); 00189 00202 bool nextAsn1(FILE* input); 00203 00209 const Asn1Info& info() const; 00210 00216 Asn1Info& info(); 00217 00226 void asn1Data(Asn1Data& dest) const; 00227 00228 private: 00235 void reserve( 00236 size_t size, 00237 bool exact 00238 ); 00245 bool getFlat(FILE* input); 00252 bool getBlock(FILE* input); 00253 private: 00259 size_t blkSize_; 00261 Asn1Byte blkFiller_; 00262 00264 Asn1Byte* buffer_; 00266 size_t bufSize_; 00267 00269 size_t dataSize_; 00271 size_t curPos_; 00273 long bufFilePos_; 00274 00276 long bytesRead_; 00277 00279 Asn1Info info_; 00280 }; // class Asn1Reader 00281 } // namespace OSB_LIB 00282 00283 // ************************************************************************ 00284 // inline definitions 00285 namespace OSB_LIB { 00286 inline long Asn1Info::filePos() const 00287 { 00288 return filePos_; 00289 } 00290 00291 inline size_t Asn1Info::tagValue() const 00292 { 00293 return tag_.value(); 00294 } 00295 00296 inline const OSB_LIB::Asn1Tag& Asn1Info::tag() const 00297 { 00298 return tag_; 00299 } 00300 00301 inline const OSB_LIB::Asn1Len& Asn1Info::dataLen() const 00302 { 00303 return dataLen_; 00304 } 00305 00306 inline const Asn1Byte* Asn1Info::data() const 00307 { 00308 return data_; 00309 } 00310 } // namespace OSB_LIB 00311 #endif // #ifndef _ASN1READER_H_