|
reSIProcate/stack
9694
|
00001 #if !defined(RESIP_LAZYPARSER_HXX) 00002 #define RESIP_LAZYPARSER_HXX 00003 00004 #ifdef HAVE_CONFIG_H 00005 #include "config.h" 00006 #endif 00007 00008 #include <iosfwd> 00009 #include "resip/stack/HeaderFieldValue.hxx" 00010 #include "rutil/resipfaststreams.hxx" 00011 00012 namespace resip 00013 { 00014 00015 class ParseBuffer; 00016 class Data; 00017 00034 class LazyParser 00035 { 00036 public: 00040 explicit LazyParser(const HeaderFieldValue& headerFieldValue); 00041 00045 LazyParser(const char* buf, int length); 00046 00050 LazyParser(const HeaderFieldValue& headerFieldValue, 00051 HeaderFieldValue::CopyPaddingEnum e); 00052 00056 LazyParser(const LazyParser& rhs); 00057 00061 LazyParser(const LazyParser& rhs,HeaderFieldValue::CopyPaddingEnum e); 00062 00066 LazyParser& operator=(const LazyParser& rhs); 00067 virtual ~LazyParser(); 00068 00072 virtual EncodeStream& encodeParsed(EncodeStream& str) const = 0; 00073 00077 virtual void parse(ParseBuffer& pb) = 0; 00078 00085 EncodeStream& encode(EncodeStream& str) const; 00086 00091 bool isParsed() const {return (mState!=NOT_PARSED);} 00092 00096 HeaderFieldValue& getHeaderField() { return mHeaderField; } 00097 00098 // call (internally) before every access 00102 void checkParsed() const 00103 { 00104 if (mState==NOT_PARSED) 00105 { 00106 doParse(); 00107 } 00108 } 00109 void checkParsed() 00110 { 00111 const LazyParser* constThis = const_cast<const LazyParser*>(this); 00112 constThis->checkParsed(); 00113 mState=DIRTY; 00114 } 00115 void doParse() const; 00116 inline void markDirty() const {mState=DIRTY;} 00117 00128 bool isWellFormed() const; 00129 protected: 00130 LazyParser(); 00131 00132 // called in destructor and on assignment 00133 void clear(); 00134 00135 // context for error messages 00136 virtual const Data& errorContext() const = 0; 00137 00138 private: 00139 // !dlb! bit of a hack until the dust settles 00140 friend class Contents; 00141 00142 HeaderFieldValue mHeaderField; 00143 00144 typedef enum 00145 { 00146 NOT_PARSED, 00147 WELL_FORMED, // Parsed, well-formed, but underlying buffer is still valid 00148 MALFORMED, // Parsed, malformed, underlying buffer is still valid 00149 DIRTY // Well-formed, and underlying buffer is invalid 00150 } ParseState; 00151 mutable ParseState mState; 00152 }; 00153 00154 #ifndef RESIP_USE_STL_STREAMS 00155 EncodeStream& 00156 operator<<(EncodeStream&, const LazyParser& lp); 00157 #endif 00158 00159 //need this for MD5Stream 00160 std::ostream& 00161 operator<<(std::ostream&, const LazyParser& lp); 00162 00163 } 00164 00165 #endif 00166 00167 /* ==================================================================== 00168 * The Vovida Software License, Version 1.0 00169 * 00170 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00171 * 00172 * Redistribution and use in source and binary forms, with or without 00173 * modification, are permitted provided that the following conditions 00174 * are met: 00175 * 00176 * 1. Redistributions of source code must retain the above copyright 00177 * notice, this list of conditions and the following disclaimer. 00178 * 00179 * 2. Redistributions in binary form must reproduce the above copyright 00180 * notice, this list of conditions and the following disclaimer in 00181 * the documentation and/or other materials provided with the 00182 * distribution. 00183 * 00184 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00185 * and "Vovida Open Communication Application Library (VOCAL)" must 00186 * not be used to endorse or promote products derived from this 00187 * software without prior written permission. For written 00188 * permission, please contact vocal@vovida.org. 00189 * 00190 * 4. Products derived from this software may not be called "VOCAL", nor 00191 * may "VOCAL" appear in their name, without prior written 00192 * permission of Vovida Networks, Inc. 00193 * 00194 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00195 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00196 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00197 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00198 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00199 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00200 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00201 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00202 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00203 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00204 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00205 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00206 * DAMAGE. 00207 * 00208 * ==================================================================== 00209 * 00210 * This software consists of voluntary contributions made by Vovida 00211 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00212 * Inc. For more information on Vovida Networks, Inc., please see 00213 * <http://www.vovida.org/>. 00214 * 00215 */
1.7.5.1