reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
ParserContainerBase.cxx
Go to the documentation of this file.
1#include "rutil/ResipAssert.h"
2
5
6using namespace resip;
7using namespace std;;
8
10
12 : mType(type),
13 mPool(0)
14{}
15
17 : mType(rhs.mType),
18 mParsers(),
19 mPool(0)
20{
22}
23
25 PoolBase& pool)
26 : mType(type),
27 mParsers(StlPoolAllocator<HeaderKit, PoolBase>(&pool)),
28 mPool(&pool)
29{}
30
32 PoolBase& pool)
33 : mType(rhs.mType),
34 mParsers(StlPoolAllocator<HeaderKit, PoolBase>(&pool)),
35 mPool(&pool)
36{
38}
39
44
47{
48 if (this != &rhs)
49 {
51 mParsers.clear();
53 }
54 return *this;
55}
56
57void
59{
60 resip_assert(!mParsers.empty());
61 freeParser(mParsers.front());
62 mParsers.erase(mParsers.begin());
63}
64
65void
67{
68 resip_assert(!mParsers.empty());
69 freeParser(mParsers.back());
70 mParsers.pop_back();
71}
72
73void
78
81 EncodeStream& str) const
82{
83 // !jf! this is not strictly correct since some headers are allowed to
84 // be empty: Supported, Accept-Encoding, Allow-Events, Allow,
85 // Accept,Accept-Language
86 if (!mParsers.empty())
87 {
88 if (!headerName.empty())
89 {
90 str << headerName << Symbols::COLON[0] << Symbols::SPACE[0];
91 }
92
93 for (Parsers::const_iterator i = mParsers.begin();
94 i != mParsers.end(); ++i)
95 {
96 if (i != mParsers.begin())
97 {
99 {
100 str << Symbols::COMMA[0] << Symbols::SPACE[0];
101 }
102 else
103 {
104 str << Symbols::CRLF << headerName << Symbols::COLON[0] << Symbols::SPACE[0];
105 }
106 }
107
108 i->encode(str);
109 }
110
111 str << Symbols::CRLF;
112 }
113
114 return str;
115}
116
119 EncodeStream& str) const
120{
121 resip_assert(!headerName.empty());
122
123 if (!mParsers.empty())
124 {
125
126 bool first = true;
127 for (Parsers::const_iterator i = mParsers.begin();
128 i != mParsers.end(); ++i)
129 {
130 if (first)
131 {
132 first = false;
133 }
134 else
135 {
136 str << Symbols::AMPERSAND;
137 }
138
139 str << headerName << Symbols::EQUALS;
140 Data buf;
141 {
142 DataStream s(buf);
143 i->encode(s);
144 }
145 str << Embedded::encode(buf);
146 }
147 }
148 return str;
149}
150
151void
153{
154 mParsers.reserve(mParsers.size() + parsers.size());
155 for(Parsers::const_iterator p=parsers.begin(); p!=parsers.end(); ++p)
156 {
157 // Copy c'tor and assignment operator for HeaderKit are actually poor
158 // man's move semantics, so we have to implement real copy semantics here.
159 mParsers.push_back(HeaderKit::Empty);
160
161 HeaderKit& kit(mParsers.back());
162 if(p->pc)
163 {
164 kit.pc = makeParser(*(p->pc));
165 }
166 else
167 {
168 kit.hfv = p->hfv;
169 }
170 }
171}
172
173void
175{
176 for(Parsers::iterator p=mParsers.begin(); p!=mParsers.end(); ++p)
177 {
178 freeParser(*p);
179 }
180}
181
182bool
183ParserContainerBase::getHeaderValueByIndex(size_t index, Data& headerValue) const
184{
185 if (index < mParsers.size())
186 {
187 const HeaderKit& hk = mParsers[index];
188 headerValue.clear();
189 DataStream ds(headerValue);
190 hk.encode(ds);
191 return true;
192 }
193 return false;
194}
195
196
197/* ====================================================================
198 * The Vovida Software License, Version 1.0
199 *
200 * Copyright (c) 2023 SIP Spectrum, Inc. www.sipspectrum.com
201 * Copyright (c) 2005
202 *
203 * Redistribution and use in source and binary forms, with or without
204 * modification, are permitted provided that the following conditions
205 * are met:
206 *
207 * 1. Redistributions of source code must retain the above copyright
208 * notice, this list of conditions and the following disclaimer.
209 *
210 * 2. Redistributions in binary form must reproduce the above copyright
211 * notice, this list of conditions and the following disclaimer in
212 * the documentation and/or other materials provided with the
213 * distribution.
214 *
215 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
216 * and "Vovida Open Communication Application Library (VOCAL)" must
217 * not be used to endorse or promote products derived from this
218 * software without prior written permission. For written
219 * permission, please contact vocal@vovida.org.
220 *
221 * 4. Products derived from this software may not be called "VOCAL", nor
222 * may "VOCAL" appear in their name, without prior written
223 * permission of Vovida Networks, Inc.
224 *
225 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
226 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
227 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
228 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
229 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
230 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
231 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
232 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
233 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
234 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
235 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
236 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
237 * DAMAGE.
238 *
239 * ====================================================================
240 *
241 * This software consists of voluntary contributions made by Vovida
242 * Networks, Inc. and many individuals on behalf of Vovida Networks,
243 * Inc. For more information on Vovida Networks, Inc., please see
244 * <http://www.vovida.org/>.
245 *
246 */
#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 & clear()
Clears the contents of this Data.
Definition Data.hxx:800
static Data encode(const Data &input)
Definition Embedded.cxx:104
static bool isCommaEncoding(Type type)
Definition Headers.cxx:31
EncodeStream & encode(EncodeStream &str) const
Abstract Base class implemented in derived class ParserContainer.
bool getHeaderValueByIndex(size_t index, Data &headerValue) const
std::vector< HeaderKit, StlPoolAllocator< HeaderKit, PoolBase > > Parsers
ParserCategory * makeParser(const ParserCategory &orig)
EncodeStream & encodeEmbedded(const Data &headerName, EncodeStream &str) const
virtual ~ParserContainerBase()
virtual destructor - empty in this class
ParserContainerBase & operator=(const ParserContainerBase &rhs)
assignment operator copies the mParsers from the rhs
Parsers mParsers
the actual list (vector) of parsers on which encoding is done
ParserContainerBase(Headers::Type type=Headers::UNKNOWN)
constructor; sets the type only
void append(const ParserContainerBase &rhs)
append the vector to the mParsers vector held locally
void pop_back()
if mParsers vector is not empty, erase the first element
void freeParsers()
free parser containers
void pop_front()
if mParsers vector is not empty, erase the first element
EncodeStream & encode(const Data &headerName, EncodeStream &str) const
void copyParsers(const Parsers &parsers)
copy header kits
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