reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
Token.cxx
Go to the documentation of this file.
1#if defined(HAVE_CONFIG_H)
2#include "config.h"
3#endif
4
6#include "rutil/Data.hxx"
7#include "rutil/DnsUtil.hxx"
8#include "rutil/Logger.hxx"
10//#include "rutil/WinLeakCheck.hxx" // not compatible with placement new used below
11
12using namespace resip;
13using namespace std;
14
15#define RESIPROCATE_SUBSYSTEM Subsystem::SIP
16
17
18//====================
19// Token
20//===================
22 : ParserCategory(),
23 mValue()
24{}
25
28 mValue(d)
29{}
30
32 : ParserCategory(hfv, type, pool),
33 mValue()
34{}
35
36Token::Token(const Token& rhs, PoolBase* pool)
37 : ParserCategory(rhs, pool),
38 mValue(rhs.mValue)
39{}
40
41Token&
43{
44 if (this != &rhs)
45 {
47 mValue = rhs.mValue;
48 }
49 return *this;
50}
51
52bool
53Token::isEqual(const Token& rhs) const
54{
55 return (value() == rhs.value());
56}
57
58bool
59Token::operator==(const Token& rhs) const
60{
61 return (value() == rhs.value());
62}
63
64bool
65Token::operator!=(const Token& rhs) const
66{
67 return (value() != rhs.value());
68}
69
70bool
71Token::operator<(const Token& rhs) const
72{
73 return (value() < rhs.value());
74}
75
76const Data&
78{
79 checkParsed();
80 return mValue;
81}
82
83Data&
85{
86 checkParsed();
87 return mValue;
88}
89
90void
92{
93 const char* startMark = pb.skipWhitespace();
95 pb.data(mValue, startMark);
98}
99
102{
103 return new Token(*this);
104}
105
107Token::clone(void* location) const
108{
109 return new (location) Token(*this);
110}
111
114{
115 return new (pool) Token(*this, pool);
116}
117
119Token::encodeParsed(EncodeStream& str) const
120{
121 str << mValue;
122 encodeParameters(str);
123 return str;
124}
125
126ParameterTypes::Factory Token::ParameterFactories[ParameterTypes::MAX_PARAMETER]={0};
127
128Parameter*
129Token::createParam(ParameterTypes::Type type, ParseBuffer& pb, const std::bitset<256>& terminators, PoolBase* pool)
130{
131 if(type > ParameterTypes::UNKNOWN && type < ParameterTypes::MAX_PARAMETER && ParameterFactories[type])
132 {
133 return ParameterFactories[type](type, pb, terminators, pool);
134 }
135 return 0;
136}
137
138bool
139Token::exists(const Param<Token>& paramType) const
140{
141 checkParsed();
142 bool ret = getParameterByEnum(paramType.getTypeNum()) != NULL;
143 return ret;
144}
145
146void
148{
149 checkParsed();
151}
152
153#define defineParam(_enum, _name, _type, _RFC_ref_ignored) \
154_enum##_Param::DType& \
155Token::param(const _enum##_Param& paramType) \
156{ \
157 checkParsed(); \
158 _enum##_Param::Type* p = \
159 static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum())); \
160 if (!p) \
161 { \
162 p = new _enum##_Param::Type(paramType.getTypeNum()); \
163 mParameters.push_back(p); \
164 } \
165 return p->value(); \
166} \
167 \
168const _enum##_Param::DType& \
169Token::param(const _enum##_Param& paramType) const \
170{ \
171 checkParsed(); \
172 _enum##_Param::Type* p = \
173 static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum())); \
174 if (!p) \
175 { \
176 InfoLog(<< "Missing parameter " _name " " << ParameterTypes::ParameterNames[paramType.getTypeNum()]); \
177 DebugLog(<< *this); \
178 throw Exception("Missing parameter " _name, __FILE__, __LINE__); \
179 } \
180 return p->value(); \
181}
182
183defineParam(text, "text", ExistsOrDataParameter, "RFC 3840");
184defineParam(cause, "cause", UInt32Parameter, "RFC 3326");
185defineParam(dAlg, "d-alg", DataParameter, "RFC 3329");
186defineParam(dQop, "d-qop", DataParameter, "RFC 3329");
187defineParam(dVer, "d-ver", QuotedDataParameter, "RFC 3329");
188defineParam(expires, "expires", UInt32Parameter, "RFC 3261");
189defineParam(filename, "filename", DataParameter, "RFC 2183");
190defineParam(fromTag, "from-tag", DataParameter, "RFC 4235");
191defineParam(handling, "handling", DataParameter, "RFC 3261");
192defineParam(id, "id", DataParameter, "RFC 3265");
193defineParam(q, "q", QValueParameter, "RFC 3261");
194defineParam(reason, "reason", DataParameter, "RFC 3265");
195defineParam(retryAfter, "retry-after", UInt32Parameter, "RFC 3265");
196defineParam(toTag, "to-tag", DataParameter, "RFC 4235");
197defineParam(extension, "ext", DataParameter, "RFC 3966"); // Token is used when ext is a user-parameter
198defineParam(profileType, "profile-type", DataParameter, "RFC 6080");
199defineParam(vendor, "vendor", QuotedDataParameter, "RFC 6080");
200defineParam(model, "model", QuotedDataParameter, "RFC 6080");
201defineParam(version, "version", QuotedDataParameter, "RFC 6080");
202defineParam(effectiveBy, "effective-by", UInt32Parameter, "RFC 6080");
203defineParam(document, "document", DataParameter, "draft-ietf-sipping-config-framework-07 (removed in 08)");
204defineParam(appId, "app-id", DataParameter, "draft-ietf-sipping-config-framework-05 (renamed to auid in 06, which was then removed in 08)");
205defineParam(networkUser, "network-user", DataParameter, "draft-ietf-sipping-config-framework-11 (removed in 12)");
206defineParam(require, "require", ExistsParameter, "RFC 5373");
207
208defineParam(utranCellId3gpp, "utran-cell-id-3gpp", DataParameter, "RFC 3455"); // P-Access-Network-Info
209defineParam(cgi3gpp, "cgi-3gpp", DataParameter, "RFC 3455"); // P-Access-Network-Info
210defineParam(ccf, "ccf", DataParameter, "RFC 3455"); // P-Charging-Function-Addresses
211defineParam(ecf, "ecf", DataParameter, "RFC 3455"); // P-Charging-Function-Addresses
212defineParam(icidValue, "icid-value", DataParameter, "RFC 3455"); // P-Charging-Vector
213defineParam(icidGeneratedAt, "icid-generated-at", DataParameter, "RFC 3455"); // P-Charging-Vector
214defineParam(origIoi, "orig-ioi", DataParameter, "RFC 3455"); // P-Charging-Vector
215defineParam(termIoi, "term-ioi", DataParameter, "RFC 3455"); // P-Charging-Vector
216
217#undef defineParam
218
219/* ====================================================================
220 * The Vovida Software License, Version 1.0
221 *
222 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
223 *
224 * Redistribution and use in source and binary forms, with or without
225 * modification, are permitted provided that the following conditions
226 * are met:
227 *
228 * 1. Redistributions of source code must retain the above copyright
229 * notice, this list of conditions and the following disclaimer.
230 *
231 * 2. Redistributions in binary form must reproduce the above copyright
232 * notice, this list of conditions and the following disclaimer in
233 * the documentation and/or other materials provided with the
234 * distribution.
235 *
236 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
237 * and "Vovida Open Communication Application Library (VOCAL)" must
238 * not be used to endorse or promote products derived from this
239 * software without prior written permission. For written
240 * permission, please contact vocal@vovida.org.
241 *
242 * 4. Products derived from this software may not be called "VOCAL", nor
243 * may "VOCAL" appear in their name, without prior written
244 * permission of Vovida Networks, Inc.
245 *
246 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
247 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
248 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
249 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
250 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
251 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
252 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
253 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
254 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
255 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
257 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
258 * DAMAGE.
259 *
260 * ====================================================================
261 *
262 * This software consists of voluntary contributions made by Vovida
263 * Networks, Inc. and many individuals on behalf of Vovida Networks,
264 * Inc. For more information on Vovida Networks, Inc., please see
265 * <http://www.vovida.org/>.
266 *
267 */
#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
Represents various parameters that are indicated to be in effect merely by being present,...
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 skipToOneOf(const char *cs)
void data(Data &data, const char *start) const
make the passed in data share memory with the buffer (uses Data::Share)
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.
Represents the "q" parameter value of the RFC 3261 grammar.
Generically represents miscellaneous parameter data that is encoded using double quotes.
static const char * SEMI_COLON
Definition Symbols.hxx:30
Represents the "token" element in the RFC 3261 grammar.
Definition Token.hxx:18
bool operator!=(const Token &rhs) const
Definition Token.cxx:65
bool exists(const Param< Token > &paramType) const
Definition Token.cxx:139
virtual Parameter * createParam(ParameterTypes::Type type, ParseBuffer &pb, const std::bitset< 256 > &terminators, PoolBase *pool)
Definition Token.cxx:129
const Data & value() const
Gets the value (ie; no parameters) of this Token as a Data&.
Definition Token.cxx:77
virtual ParserCategory * clone() const
Definition Token.cxx:101
bool isEqual(const Token &rhs) const
Definition Token.cxx:53
virtual EncodeStream & encodeParsed(EncodeStream &str) const
Definition Token.cxx:119
bool operator<(const Token &rhs) const
Definition Token.cxx:71
void remove(const Param< Token > &paramType)
Definition Token.cxx:147
Token & operator=(const Token &)
Definition Token.cxx:42
virtual void parse(ParseBuffer &pb)
Definition Token.cxx:91
bool operator==(const Token &rhs) const
Definition Token.cxx:59
Generically represents unsigned 32-bit integer values conveyed by SIP parameters.
dcm! – add UnusedChecking(_enum) below;
#define EncodeStream