reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
TokenOrQuotedStringCategory.cxx
Go to the documentation of this file.
1#if defined(HAVE_CONFIG_H)
2#include "config.h"
3#endif
4
6#include "rutil/Logger.hxx"
8
9using namespace resip;
10using namespace std;
11
12#define RESIPROCATE_SUBSYSTEM Subsystem::SIP
13
14//============================
15// TokenOrQuotedStringCategory
16//============================
22
24 bool quoted)
26 mValue(value),
27 mQuoted(quoted)
28{}
29
31 Headers::Type type,
32 PoolBase* pool)
33 : ParserCategory(hfv, type, pool),
34 mValue(),
35 mQuoted(false)
36{}
37
39 PoolBase* pool)
40 : ParserCategory(rhs, pool),
41 mValue(rhs.mValue),
42 mQuoted(rhs.mQuoted)
43{}
44
47{
48 if (this != &rhs)
49 {
51 mValue = rhs.mValue;
52 mQuoted = rhs.mQuoted;
53 }
54 return *this;
55}
56
62
65{
66 return new (location) TokenOrQuotedStringCategory(*this);
67}
68
71{
72 return new (pool) TokenOrQuotedStringCategory(*this, pool);
73}
74
75bool
77{
78 return ((value() == rhs.value()) && (isQuoted() == rhs.isQuoted()));
79}
80
81bool
83{
84 return ((value() == rhs.value()) && (isQuoted() == rhs.isQuoted()));
85}
86
87bool
89{
90 return ((value() != rhs.value()) || (isQuoted() != rhs.isQuoted()));
91}
92
93bool
95{
96 // don't use mQuoted for operator <
97 return (value() < rhs.value());
98}
99
100void
102{
103 const char* startMark = pb.skipWhitespace();
104 if (*pb.position() == Symbols::DOUBLE_QUOTE[0])
105 {
106 setQuoted(true);
107 pb.skipChar();
108 startMark = pb.position();
109 pb.skipToEndQuote();
110 }
111 else
112 {
113 setQuoted(false);
115 }
116 pb.data(mValue, startMark);
118 parseParameters(pb);
119}
120
123{
124 str << quotedValue();
125 encodeParameters(str);
126 return str;
127}
128
130{
131 checkParsed();
132 return mValue;
133}
134
136{
137 checkParsed();
138 return mValue;
139}
140
142{
143 checkParsed();
144 Data tokenValue;
145 if (mQuoted)
146 {
147 tokenValue += Symbols::DOUBLE_QUOTE;
148 }
149 // mValue does not contain quoted string
150 tokenValue += mValue;
151 if (mQuoted)
152 {
153 tokenValue += Symbols::DOUBLE_QUOTE;
154 }
155 return tokenValue;
156}
157
158ParameterTypes::Factory TokenOrQuotedStringCategory::ParameterFactories[ParameterTypes::MAX_PARAMETER] = { 0 };
159
162 ParseBuffer& pb,
163 const std::bitset<256>& terminators,
164 PoolBase* pool)
165{
166 if ((type > ParameterTypes::UNKNOWN) && (type < ParameterTypes::MAX_PARAMETER) && ParameterFactories[type])
167 {
168 return ParameterFactories[type](type, pb, terminators, pool);
169 }
170 return 0;
171}
172
173bool
175{
176 checkParsed();
177 bool ret = (getParameterByEnum(paramType.getTypeNum()) != NULL);
178 return ret;
179}
180
181void
187
188#define defineParam(_enum, _name, _type, _RFC_ref_ignored) \
189_enum##_Param::DType& \
190TokenOrQuotedStringCategory::param(const _enum##_Param& paramType) \
191{ \
192 checkParsed(); \
193 _enum##_Param::Type* p = \
194 static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum())); \
195 if (!p) \
196 { \
197 p = new _enum##_Param::Type(paramType.getTypeNum()); \
198 mParameters.push_back(p); \
199 } \
200 return p->value(); \
201} \
202 \
203const _enum##_Param::DType& \
204TokenOrQuotedStringCategory::param(const _enum##_Param& paramType) const \
205{ \
206 checkParsed(); \
207 _enum##_Param::Type* p = \
208 static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum())); \
209 if (!p) \
210 { \
211 InfoLog(<< "Missing parameter " _name " " << ParameterTypes::ParameterNames[paramType.getTypeNum()]); \
212 DebugLog(<< *this); \
213 throw Exception("Missing parameter " _name, __FILE__, __LINE__); \
214 } \
215 return p->value(); \
216}
217
218defineParam(purpose, "purpose", DataParameter, "draft-ietf-cuss-sip-uui-17"); // User-to-User
219defineParam(content, "content", DataParameter, "draft-ietf-cuss-sip-uui-17"); // User-to-User
220defineParam(encoding, "encoding", DataParameter, "draft-ietf-cuss-sip-uui-17"); // User-to-User
221
222#undef defineParam
223
224/* ====================================================================
225 * The Vovida Software License, Version 1.0
226 *
227 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
228 *
229 * Redistribution and use in source and binary forms, with or without
230 * modification, are permitted provided that the following conditions
231 * are met:
232 *
233 * 1. Redistributions of source code must retain the above copyright
234 * notice, this list of conditions and the following disclaimer.
235 *
236 * 2. Redistributions in binary form must reproduce the above copyright
237 * notice, this list of conditions and the following disclaimer in
238 * the documentation and/or other materials provided with the
239 * distribution.
240 *
241 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
242 * and "Vovida Open Communication Application Library (VOCAL)" must
243 * not be used to endorse or promote products derived from this
244 * software without prior written permission. For written
245 * permission, please contact vocal@vovida.org.
246 *
247 * 4. Products derived from this software may not be called "VOCAL", nor
248 * may "VOCAL" appear in their name, without prior written
249 * permission of Vovida Networks, Inc.
250 *
251 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
252 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
253 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
254 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
255 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
256 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
257 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
258 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
259 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
260 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
261 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
262 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
263 * DAMAGE.
264 *
265 * ====================================================================
266 *
267 * This software consists of voluntary contributions made by Vovida
268 * Networks, Inc. and many individuals on behalf of Vovida Networks,
269 * Inc. For more information on Vovida Networks, Inc., please see
270 * <http://www.vovida.org/>.
271 *
272 */
#define defineParam(_enum, _name, _type, _RFC_ref_ignored)
Definition Auth.cxx:239
Generically represents miscellaneous parameter data.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
void checkParsed() const
virtual ParameterTypes::Type getTypeNum() const =0
Parameter *(* Factory)(ParameterTypes::Type, ParseBuffer &, const std::bitset< 256 > &terminators, PoolBase *pool)
Provides string-parsing functionality with protection from buffer overflow.
CurrentPosition skipWhitespace()
CurrentPosition skipToChar(char c)
CurrentPosition position() const
CurrentPosition skipToOneOf(const char *cs)
CurrentPosition skipChar()
void data(Data &data, const char *start) const
make the passed in data share memory with the buffer (uses Data::Share)
const char * skipToEndQuote(char quote='"')
static const char * Whitespace
Base class for all SIP grammar elements that can have parameters.
Parameter * getParameterByEnum(ParameterTypes::Type type) const
ParserCategory & operator=(const ParserCategory &rhs)
void removeParameterByEnum(ParameterTypes::Type type)
void parseParameters(ParseBuffer &pb)
EncodeStream & encodeParameters(EncodeStream &str) const
Encodes parameters as they should appear on the wire.
static const char * SEMI_COLON
Definition Symbols.hxx:30
static const char * DOUBLE_QUOTE
Definition Symbols.hxx:26
Generically represents a token whose value can be wrapped and encoded using double quotes.
bool isEqual(const TokenOrQuotedStringCategory &rhs) const
virtual EncodeStream & encodeParsed(EncodeStream &str) const
bool operator==(const TokenOrQuotedStringCategory &rhs) const
bool operator!=(const TokenOrQuotedStringCategory &rhs) const
virtual Parameter * createParam(ParameterTypes::Type type, ParseBuffer &pb, const std::bitset< 256 > &terminators, PoolBase *pool)
TokenOrQuotedStringCategory & operator=(const TokenOrQuotedStringCategory &rhs)
bool operator<(const TokenOrQuotedStringCategory &rhs) const
void remove(const Param< TokenOrQuotedStringCategory > &paramType)
bool exists(const Param< TokenOrQuotedStringCategory > &paramType) const
dcm! – add UnusedChecking(_enum) below;
#define EncodeStream