/[resiprocate]/main/sip/resiprocate/LazyParser.cxx
ViewVC logotype

Contents of /main/sip/resiprocate/LazyParser.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2778 - (show annotations) (download)
Tue May 18 01:40:48 2004 UTC (15 years, 8 months ago) by jason
File size: 4401 byte(s)
reorganize ParserCategories.hxx/cxx into separate files - one for each class

1 #if defined(HAVE_CONFIG_H)
2 #include "resiprocate/config.hxx"
3 #endif
4
5
6 #include <cassert>
7
8 #include "resiprocate/Headers.hxx"
9 #include "resiprocate/HeaderFieldValue.hxx"
10 #include "resiprocate/LazyParser.hxx"
11 #include "resiprocate/os/ParseBuffer.hxx"
12
13 using namespace resip;
14
15 LazyParser::LazyParser(HeaderFieldValue* headerFieldValue)
16 : mHeaderField(headerFieldValue),
17 mIsMine(false),
18 mIsParsed(mHeaderField->mField == 0) //although this has a hfv it is
19 //parsed, as the hfv has no content
20 {
21 }
22
23 LazyParser::LazyParser()
24 : mHeaderField(0),
25 mIsMine(true),
26 mIsParsed(true)
27 {
28 }
29
30 LazyParser::LazyParser(const LazyParser& rhs)
31 : mHeaderField(0),
32 mIsMine(true),
33 mIsParsed(rhs.mIsParsed)
34 {
35 if (!mIsParsed && rhs.mHeaderField)
36 {
37 mHeaderField = new HeaderFieldValue(*rhs.mHeaderField);
38 }
39 }
40
41 LazyParser::~LazyParser()
42 {
43 clear();
44 }
45
46 LazyParser&
47 LazyParser::operator=(const LazyParser& rhs)
48 {
49 assert( &rhs != 0 );
50
51 if (this != &rhs)
52 {
53 clear();
54 mIsParsed = rhs.mIsParsed;
55 if (rhs.mIsParsed)
56 {
57 mHeaderField = 0;
58 mIsMine = false;
59 }
60 else
61 {
62 mHeaderField = new HeaderFieldValue(*rhs.mHeaderField);
63 mIsMine = true;
64 }
65 }
66 return *this;
67 }
68
69 void
70 LazyParser::checkParsed() const
71 {
72 if (!mIsParsed)
73 {
74 LazyParser* ncThis = const_cast<LazyParser*>(this);
75 ncThis->mIsParsed = true;
76 ParseBuffer pb(mHeaderField->mField, mHeaderField->mFieldLength, errorContext());
77 ncThis->parse(pb);
78 }
79 }
80
81 void
82 LazyParser::clear()
83 {
84 if (mIsMine)
85 {
86 delete mHeaderField;
87 mHeaderField = 0;
88 }
89 }
90
91 std::ostream&
92 LazyParser::encode(std::ostream& str) const
93 {
94 if (isParsed())
95 {
96 return encodeParsed(str);
97 }
98 else
99 {
100 assert(mHeaderField);
101 mHeaderField->encode(str);
102 return str;
103 }
104 }
105
106 std::ostream&
107 resip::operator<<(std::ostream& s, const LazyParser& lp)
108 {
109 lp.encode(s);
110 return s;
111 }
112 /* ====================================================================
113 * The Vovida Software License, Version 1.0
114 *
115 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
116 *
117 * Redistribution and use in source and binary forms, with or without
118 * modification, are permitted provided that the following conditions
119 * are met:
120 *
121 * 1. Redistributions of source code must retain the above copyright
122 * notice, this list of conditions and the following disclaimer.
123 *
124 * 2. Redistributions in binary form must reproduce the above copyright
125 * notice, this list of conditions and the following disclaimer in
126 * the documentation and/or other materials provided with the
127 * distribution.
128 *
129 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
130 * and "Vovida Open Communication Application Library (VOCAL)" must
131 * not be used to endorse or promote products derived from this
132 * software without prior written permission. For written
133 * permission, please contact vocal@vovida.org.
134 *
135 * 4. Products derived from this software may not be called "VOCAL", nor
136 * may "VOCAL" appear in their name, without prior written
137 * permission of Vovida Networks, Inc.
138 *
139 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
140 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
141 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
142 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
143 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
144 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
145 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
146 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
147 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
148 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
149 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
150 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
151 * DAMAGE.
152 *
153 * ====================================================================
154 *
155 * This software consists of voluntary contributions made by Vovida
156 * Networks, Inc. and many individuals on behalf of Vovida Networks,
157 * Inc. For more information on Vovida Networks, Inc., please see
158 * <http://www.vovida.org/>.
159 *
160 */

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27