/[resiprocate]/branches/b-identity-0505/LazyParser.cxx
ViewVC logotype

Contents of /branches/b-identity-0505/LazyParser.cxx

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27