reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
LazyParser.cxx
Go to the documentation of this file.
1#if defined(HAVE_CONFIG_H)
2#include "config.h"
3#endif
4
5
6#include "rutil/ResipAssert.h"
7
11#include "rutil/ParseBuffer.hxx"
13
14using namespace resip;
15
17 : mHeaderField(headerFieldValue, HeaderFieldValue::NoOwnership),
18 mState(mHeaderField.getBuffer() == 0 ? DIRTY : NOT_PARSED)
19{
20}
21
24 : mHeaderField(headerFieldValue, e), // Causes ownership to be taken. Oh well
25 mState(mHeaderField.getBuffer() == 0 ? DIRTY : NOT_PARSED)
26{}
27
28LazyParser::LazyParser(const char* buf, int length) :
29 mHeaderField(buf, length),
30 mState(buf == 0 ? DIRTY : NOT_PARSED)
31{}
32
34 : mHeaderField(),
35 mState(DIRTY)
36{
37}
38
40 : mHeaderField((rhs.mState==DIRTY ? HeaderFieldValue::Empty : rhs.mHeaderField)), // Pretty cheap when rhs is DIRTY
41 mState(rhs.mState)
42{}
43
45 : mHeaderField((rhs.mState==DIRTY ? HeaderFieldValue::Empty : rhs.mHeaderField), e), // Pretty cheap when rhs is DIRTY
46 mState(rhs.mState)
47{}
48
49
54
57{
59
60 if (this != &rhs)
61 {
62 clear();
63 mState = rhs.mState;
64 if (rhs.mState!=DIRTY)
65 {
66 mHeaderField=rhs.mHeaderField;
67 }
68 }
69 return *this;
70}
71
72void
74{
75 LazyParser* ncThis = const_cast<LazyParser*>(this);
76 // .bwc. We assume the worst, and if the parse succeeds, we update.
77 ncThis->mState = MALFORMED;
78 ParseBuffer pb(mHeaderField.getBuffer(), mHeaderField.getLength(), errorContext());
79 ncThis->parse(pb);
80 // .bwc. If we get this far without throwing, the parse has succeeded.
81 ncThis->mState = WELL_FORMED;
82}
83
84bool
86{
87 try
88 {
90 }
92 {
93 }
94
95 return (mState!=MALFORMED);
96}
97
98void
100{
101 mHeaderField.clear();
102}
103
105LazyParser::encode(EncodeStream& str) const
106{
107 if (mState == DIRTY)
108 {
109 return encodeParsed(str);
110 }
111 else
112 {
113 mHeaderField.encode(str);
114 return str;
115 }
116}
117
118#ifndef RESIP_USE_STL_STREAMS
120resip::operator<<(EncodeStream&s, const LazyParser& lp)
121{
122 lp.encode(s);
123 return s;
124}
125#endif
126
127std::ostream&
128resip::operator<<(std::ostream &s, const LazyParser& lp)
129{
130#ifdef RESIP_USE_STL_STREAMS
131 lp.encode(s);
132#else
133 //this should only be called for things like cout,cerr, or other streams not supporting
134 //other stream encoders, aka DigestStream
135 Data data;
136 DataStream stream(data);
137
138 lp.encode(stream);
139 stream.flush();
140 s << data.c_str();
141#endif
142 return s;
143}
144/* ====================================================================
145 * The Vovida Software License, Version 1.0
146 *
147 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
148 *
149 * Redistribution and use in source and binary forms, with or without
150 * modification, are permitted provided that the following conditions
151 * are met:
152 *
153 * 1. Redistributions of source code must retain the above copyright
154 * notice, this list of conditions and the following disclaimer.
155 *
156 * 2. Redistributions in binary form must reproduce the above copyright
157 * notice, this list of conditions and the following disclaimer in
158 * the documentation and/or other materials provided with the
159 * distribution.
160 *
161 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
162 * and "Vovida Open Communication Application Library (VOCAL)" must
163 * not be used to endorse or promote products derived from this
164 * software without prior written permission. For written
165 * permission, please contact vocal@vovida.org.
166 *
167 * 4. Products derived from this software may not be called "VOCAL", nor
168 * may "VOCAL" appear in their name, without prior written
169 * permission of Vovida Networks, Inc.
170 *
171 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
172 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
173 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
174 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
175 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
176 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
177 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
178 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
179 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
180 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
181 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
182 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
183 * DAMAGE.
184 *
185 * ====================================================================
186 *
187 * This software consists of voluntary contributions made by Vovida
188 * Networks, Inc. and many individuals on behalf of Vovida Networks,
189 * Inc. For more information on Vovida Networks, Inc., please see
190 * <http://www.vovida.org/>.
191 *
192 */
#define resip_assert_not_null(x)
An iostream that operates on an existing Data.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
const char * c_str() const
Returns a null-terminated string representing.
Definition Data.cxx:1097
EncodeStream & encode(EncodeStream &str) const
const char * getBuffer() const
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
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().
virtual ~LazyParser()
Provides string-parsing functionality with protection from buffer overflow.
BaseException used to indicate parse failures.
dcm! – add UnusedChecking(_enum) below;
EncodeStream & operator<<(EncodeStream &strm, const BaseException &e)
#define EncodeStream