reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
LazyParser.hxx
Go to the documentation of this file.
1#if !defined(RESIP_LAZYPARSER_HXX)
2#define RESIP_LAZYPARSER_HXX
3
4#ifdef HAVE_CONFIG_H
5#include "config.h"
6#endif
7
8#include <iosfwd>
11
12namespace resip
13{
14
15class ParseBuffer;
16class Data;
17
35{
36 public:
40 explicit LazyParser(const HeaderFieldValue& headerFieldValue);
41
45 LazyParser(const char* buf, int length);
46
50 LazyParser(const HeaderFieldValue& headerFieldValue,
52
56 LazyParser(const LazyParser& rhs);
57
62
66 LazyParser& operator=(const LazyParser& rhs);
67 virtual ~LazyParser();
68
72 virtual EncodeStream& encodeParsed(EncodeStream& str) const = 0;
73
77 virtual void parse(ParseBuffer& pb) = 0;
78
85 EncodeStream& encode(EncodeStream& str) const;
86
91 bool isParsed() const {return (mState!=NOT_PARSED);}
92
96 HeaderFieldValue& getHeaderField() { return mHeaderField; }
97
98 // call (internally) before every access
102 void checkParsed() const
103 {
104 if (mState==NOT_PARSED)
105 {
106 doParse();
107 }
108 }
110 {
111 const LazyParser* constThis = const_cast<const LazyParser*>(this);
112 constThis->checkParsed();
113 mState=DIRTY;
114 }
115 void doParse() const;
116 inline void markDirty() const {mState=DIRTY;}
117
128 bool isWellFormed() const;
129 protected:
130 LazyParser();
131
132 // called in destructor and on assignment
133 void clear();
134
135 // context for error messages
136 virtual const Data& errorContext() const = 0;
137
138 private:
139 // !dlb! bit of a hack until the dust settles
140 friend class Contents;
141
142 HeaderFieldValue mHeaderField;
143
144 typedef enum
145 {
146 NOT_PARSED,
147 WELL_FORMED, // Parsed, well-formed, but underlying buffer is still valid
148 MALFORMED, // Parsed, malformed, underlying buffer is still valid
149 DIRTY // Well-formed, and underlying buffer is invalid
150 } ParseState;
151 mutable ParseState mState;
152};
153
154#ifndef RESIP_USE_STL_STREAMS
156operator<<(EncodeStream&, const LazyParser& lp);
157#endif
158
159//need this for DigestStream
160std::ostream&
161operator<<(std::ostream&, const LazyParser& lp);
162
163}
164
165#endif
166
167/* ====================================================================
168 * The Vovida Software License, Version 1.0
169 *
170 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
171 *
172 * Redistribution and use in source and binary forms, with or without
173 * modification, are permitted provided that the following conditions
174 * are met:
175 *
176 * 1. Redistributions of source code must retain the above copyright
177 * notice, this list of conditions and the following disclaimer.
178 *
179 * 2. Redistributions in binary form must reproduce the above copyright
180 * notice, this list of conditions and the following disclaimer in
181 * the documentation and/or other materials provided with the
182 * distribution.
183 *
184 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
185 * and "Vovida Open Communication Application Library (VOCAL)" must
186 * not be used to endorse or promote products derived from this
187 * software without prior written permission. For written
188 * permission, please contact vocal@vovida.org.
189 *
190 * 4. Products derived from this software may not be called "VOCAL", nor
191 * may "VOCAL" appear in their name, without prior written
192 * permission of Vovida Networks, Inc.
193 *
194 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
195 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
196 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
197 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
198 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
199 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
200 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
201 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
202 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
203 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
204 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
205 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
206 * DAMAGE.
207 *
208 * ====================================================================
209 *
210 * This software consists of voluntary contributions made by Vovida
211 * Networks, Inc. and many individuals on behalf of Vovida Networks,
212 * Inc. For more information on Vovida Networks, Inc., please see
213 * <http://www.vovida.org/>.
214 *
215 */
Base class for all SIP body types.
Definition Contents.hxx:51
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
The base-class for all lazily-parsed SIP grammar elements.
EncodeStream & encode(EncodeStream &str) const
Encodes this element to a stream, in the fashion it should be represented on the wire.
void checkParsed() const
void doParse() const
LazyParser & operator=(const LazyParser &rhs)
virtual void parse(ParseBuffer &pb)=0
HeaderFieldValue & getHeaderField()
void markDirty() const
virtual const Data & errorContext() const =0
virtual EncodeStream & encodeParsed(EncodeStream &str) const =0
bool isWellFormed() const
Returns true iff this element was parsed successfully, according to the implementation of parse().
bool isParsed() const
Returns true iff a parse has been attempted.
virtual ~LazyParser()
Provides string-parsing functionality with protection from buffer overflow.
dcm! – add UnusedChecking(_enum) below;
EncodeStream & operator<<(EncodeStream &strm, const BaseException &e)
Replaces STL streams for general encoding purposes.
#define EncodeStream
void list()
Definition userAdmin.cxx:66