reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
HeaderFieldValueList.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
13
14using namespace resip;
15
17
19{
20 freeParserContainer();
21}
22
24 : mHeaders(),
25 mPool(0),
26 mParserContainer(0)
27{
28 if (rhs.mParserContainer)
29 {
30 mParserContainer = rhs.mParserContainer->clone();
31 }
32 else if(rhs.mHeaders.size())
33 {
34 mHeaders=rhs.mHeaders;
35 }
36}
37
39 : mHeaders(StlPoolAllocator<HeaderFieldValue, PoolBase>(&pool)),
40 mPool(&pool),
41 mParserContainer(0)
42{
43 if (rhs.mParserContainer)
44 {
45 mParserContainer = rhs.mParserContainer->clone();
46 }
47 else if(rhs.mHeaders.size())
48 {
49 mHeaders=rhs.mHeaders;
50 }
51}
52
55{
56 if(this!=&rhs)
57 {
58 mHeaders.clear();
59
60 freeParserContainer();
61
62 if (rhs.mParserContainer != 0)
63 {
64 mParserContainer = rhs.mParserContainer->clone();
65 }
66 else
67 {
68 mHeaders=rhs.mHeaders;
69 }
70 }
71
72 return *this;
73}
74
76HeaderFieldValueList::encode(int headerEnum, EncodeStream& str) const
77{
78 const Data& headerName = Headers::getHeaderName(static_cast<Headers::Type>(headerEnum));
79
80 if (getParserContainer() != 0)
81 {
82 getParserContainer()->encode(headerName, str);
83 }
84 else
85 {
86 if (!headerName.empty())
87 {
88 str << headerName << Symbols::COLON[0] << Symbols::SPACE[0];
89 }
90
92 j != end(); j++)
93 {
94 if (j != begin())
95 {
96 if (Headers::isCommaEncoding(static_cast<Headers::Type>(headerEnum)))
97 {
98 str << Symbols::COMMA[0] << Symbols::SPACE[0];
99 }
100 else
101 {
102 str << Symbols::CRLF << headerName << Symbols::COLON << Symbols::SPACE;
103 }
104 }
105 j->encode(str);
106 }
107 str << Symbols::CRLF;
108 }
109 return str;
110}
111
113HeaderFieldValueList::encode(const Data& headerName, EncodeStream& str) const
114{
115 if (getParserContainer() != 0)
116 {
117 getParserContainer()->encode(headerName, str);
118 }
119 else
120 {
121 if (!headerName.empty())
122 {
123 str << headerName << Symbols::COLON << Symbols::SPACE;
124 }
126 j != end(); j++)
127 {
128 if (j != begin())
129 {
130 str << Symbols::COMMA[0] << Symbols::SPACE[0];
131 }
132 j->encode(str);
133 }
134 str << Symbols::CRLF;
135 }
136 return str;
137}
138
140HeaderFieldValueList::encodeEmbedded(const Data& headerName, EncodeStream& str) const
141{
142 resip_assert(!headerName.empty());
143
144 if (getParserContainer() != 0)
145 {
146 getParserContainer()->encodeEmbedded(headerName, str);
147 }
148 else
149 {
150 bool first = true;
152 j != end(); j++)
153 {
154 if (first)
155 {
156 first = false;
157 }
158 else
159 {
160 str << Symbols::AMPERSAND;
161 }
162
163 str << headerName << Symbols::EQUALS;
164 Data buf;
165 {
166 DataStream s(buf);
167 j->encode(s);
168 }
169 str << Embedded::encode(buf);
170 }
171 }
172 return str;
173}
174
175void
177{
178 freeParserContainer();
179 mHeaders.clear();
180}
181
182bool
184{
185 if (mParserContainer)
186 {
187 return mParserContainer->empty();
188 }
189 else
190 {
191 return mHeaders.empty();
192 }
193}
194
195void
196HeaderFieldValueList::freeParserContainer()
197{
198 if(mParserContainer)
199 {
200 mParserContainer->~ParserContainerBase();
201 // The allocator will check whether this belongs to it, and if not, fall
202 // back to global operator delete.
203 if(mPool)
204 {
205 mPool->deallocate(mParserContainer);
206 }
207 else
208 {
209 ::operator delete(mParserContainer);
210 }
211 mParserContainer=0;
212 }
213}
214
215size_t
217{
218 if (mParserContainer)
219 {
220 return mParserContainer->size();
221 }
222 else
223 {
224 return mHeaders.size();
225 }
226}
227
228bool
229HeaderFieldValueList::getHeaderValueByIndex(size_t index, Data& headerValue) const
230{
231 if (mParserContainer)
232 {
233 return mParserContainer->getHeaderValueByIndex(index, headerValue);
234 }
235 else
236 {
237 if (index < mHeaders.size())
238 {
239 const HeaderFieldValue& hfv = mHeaders[index];
240 headerValue.copy(hfv.getBuffer(), hfv.getLength());
241 return true;
242 }
243 }
244 return false;
245}
246
247
248/* ====================================================================
249 * The Vovida Software License, Version 1.0
250 *
251 * Copyright (c) 2023 SIP Spectrum, Inc. www.sipspectrum.com
252 * Copyright (c) 2000 Vovida Networks, Inc.
253 * All rights reserved.
254 *
255 * Redistribution and use in source and binary forms, with or without
256 * modification, are permitted provided that the following conditions
257 * are met:
258 *
259 * 1. Redistributions of source code must retain the above copyright
260 * notice, this list of conditions and the following disclaimer.
261 *
262 * 2. Redistributions in binary form must reproduce the above copyright
263 * notice, this list of conditions and the following disclaimer in
264 * the documentation and/or other materials provided with the
265 * distribution.
266 *
267 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
268 * and "Vovida Open Communication Application Library (VOCAL)" must
269 * not be used to endorse or promote products derived from this
270 * software without prior written permission. For written
271 * permission, please contact vocal@vovida.org.
272 *
273 * 4. Products derived from this software may not be called "VOCAL", nor
274 * may "VOCAL" appear in their name, without prior written
275 * permission of Vovida Networks, Inc.
276 *
277 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
278 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
279 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
280 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
281 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
282 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
283 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
284 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
285 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
286 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
287 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
288 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
289 * DAMAGE.
290 *
291 * ====================================================================
292 *
293 * This software consists of voluntary contributions made by Vovida
294 * Networks, Inc. and many individuals on behalf of Vovida Networks,
295 * Inc. For more information on Vovida Networks, Inc., please see
296 * <http://www.vovida.org/>.
297 *
298 */
#define resip_assert(x)
This file needs to work for both C and C++ code.
An iostream that operates on an existing Data.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
bool empty() const noexcept
Checks whether the Data is empty.
Definition Data.hxx:591
Data & copy(const char *buf, size_type length)
Functional equivalent of: *this = Data(buf, length) but avoids the intermediate allocation and free.
Definition Data.cxx:701
static Data encode(const Data &input)
Definition Embedded.cxx:104
bool getHeaderValueByIndex(size_t index, Data &headerValue) const
EncodeStream & encodeEmbedded(const Data &headerName, EncodeStream &str) const
HeaderFieldValueList & operator=(const HeaderFieldValueList &rhs)
ParserContainerBase * getParserContainer() const
ListImpl::const_iterator const_iterator
EncodeStream & encode(int headerEnum, EncodeStream &str) const
static const HeaderFieldValueList Empty
const char * getBuffer() const
static const Data & getHeaderName(int)
Definition Headers.cxx:37
static bool isCommaEncoding(Type type)
Definition Headers.cxx:31
bool getHeaderValueByIndex(size_t index, Data &headerValue) const
bool empty() const
return true or false indicating whether the mParsers vector is empty or not
EncodeStream & encodeEmbedded(const Data &headerName, EncodeStream &str) const
virtual ~ParserContainerBase()
virtual destructor - empty in this class
virtual ParserContainerBase * clone() const =0
pure virtual function to be implemented in derived classes with the intention of cloning this object
size_t size() const
return the size of the mParsers vector
EncodeStream & encode(const Data &headerName, EncodeStream &str) const
virtual void deallocate(void *ptr)=0
A dirt-simple lightweight stl pool allocator meant for use in short-lifetime objects.
static const char * SPACE
Definition Symbols.hxx:34
static const char * COLON
Definition Symbols.hxx:15
static const char * COMMA
Definition Symbols.hxx:35
static const char * EQUALS
Definition Symbols.hxx:29
static const char * AMPERSAND
Definition Symbols.hxx:43
static const char * CRLF
Definition Symbols.hxx:21
dcm! – add UnusedChecking(_enum) below;
#define EncodeStream