reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
UInt32Category.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//#include "rutil/WinLeakCheck.hxx" // not compatible with placement new used below
9
10using namespace resip;
11using namespace std;
12
13#define RESIPROCATE_SUBSYSTEM Subsystem::SIP
14
15//====================
16// UInt32:
17//====================
19 : ParserCategory(),
20 mValue(0),
21 mComment()
22{}
23
25 Headers::Type type,
26 PoolBase* pool)
27 : ParserCategory(hfv, type, pool),
28 mValue(0),
29 mComment()
30{}
31
33 PoolBase* pool)
34 : ParserCategory(rhs, pool),
35 mValue(rhs.mValue),
36 mComment(rhs.mComment)
37{}
38
41{
42 if (this != &rhs)
43 {
45 mValue = rhs.mValue;
46 mComment = rhs.mComment;
47 }
48 return *this;
49}
50
52{
53 return new UInt32Category(*this);
54}
55
57{
58 return new (location) UInt32Category(*this);
59}
60
63{
64 return new (pool) UInt32Category(*this, pool);
65}
66
67const uint32_t&
69{
70 checkParsed();
71 return mValue;
72}
73
74const Data&
76{
77 checkParsed();
78 return mComment;
79}
80
83{
84 checkParsed();
85 return mValue;
86}
87
88Data&
90{
91 checkParsed();
92 return mComment;
93}
94
95void
97{
98 const char* start = pb.skipWhitespace();
99 mValue = pb.uInt32();
100 pb.skipToChar('(');
101 if (!pb.eof())
102 {
103 start = pb.skipChar();
104 pb.skipToEndQuote(')');
105 pb.data(mComment, start);
106 pb.skipChar();
107 }
108 else
109 {
110 pb.reset(start);
111 start = pb.skipNonWhitespace();
112 }
113
114 parseParameters(pb);
115}
116
118UInt32Category::encodeParsed(EncodeStream& str) const
119{
120 str << mValue;
121
122 if (!mComment.empty())
123 {
124 str << "(" << mComment << ")";
125 }
126
127 encodeParameters(str);
128 return str;
129}
130
131ParameterTypes::Factory UInt32Category::ParameterFactories[ParameterTypes::MAX_PARAMETER]={0};
132
133Parameter*
134UInt32Category::createParam(ParameterTypes::Type type, ParseBuffer& pb, const std::bitset<256>& terminators, PoolBase* pool)
135{
136 if(type > ParameterTypes::UNKNOWN && type < ParameterTypes::MAX_PARAMETER && ParameterFactories[type])
137 {
138 return ParameterFactories[type](type, pb, terminators, pool);
139 }
140 return 0;
141}
142
143bool
145{
146 checkParsed();
147 bool ret = getParameterByEnum(paramType.getTypeNum()) != NULL;
148 return ret;
149}
150
151void
157
158#define defineParam(_enum, _name, _type, _RFC_ref_ignored) \
159_enum##_Param::DType& \
160UInt32Category::param(const _enum##_Param& paramType) \
161{ \
162 checkParsed(); \
163 _enum##_Param::Type* p = \
164 static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum())); \
165 if (!p) \
166 { \
167 p = new _enum##_Param::Type(paramType.getTypeNum()); \
168 mParameters.push_back(p); \
169 } \
170 return p->value(); \
171} \
172 \
173const _enum##_Param::DType& \
174UInt32Category::param(const _enum##_Param& paramType) const \
175{ \
176 checkParsed(); \
177 _enum##_Param::Type* p = \
178 static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum())); \
179 if (!p) \
180 { \
181 InfoLog(<< "Missing parameter " _name " " << ParameterTypes::ParameterNames[paramType.getTypeNum()]); \
182 DebugLog(<< *this); \
183 throw Exception("Missing parameter " _name, __FILE__, __LINE__); \
184 } \
185 return p->value(); \
186}
187
188defineParam(duration, "duration", UInt32Parameter, "RFC 3261");
189
190#undef defineParam
191
192/* ====================================================================
193 * The Vovida Software License, Version 1.0
194 *
195 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
196 *
197 * Redistribution and use in source and binary forms, with or without
198 * modification, are permitted provided that the following conditions
199 * are met:
200 *
201 * 1. Redistributions of source code must retain the above copyright
202 * notice, this list of conditions and the following disclaimer.
203 *
204 * 2. Redistributions in binary form must reproduce the above copyright
205 * notice, this list of conditions and the following disclaimer in
206 * the documentation and/or other materials provided with the
207 * distribution.
208 *
209 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
210 * and "Vovida Open Communication Application Library (VOCAL)" must
211 * not be used to endorse or promote products derived from this
212 * software without prior written permission. For written
213 * permission, please contact vocal@vovida.org.
214 *
215 * 4. Products derived from this software may not be called "VOCAL", nor
216 * may "VOCAL" appear in their name, without prior written
217 * permission of Vovida Networks, Inc.
218 *
219 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
220 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
221 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
222 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
223 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
224 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
225 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
226 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
227 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
228 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
229 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
230 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
231 * DAMAGE.
232 *
233 * ====================================================================
234 *
235 * This software consists of voluntary contributions made by Vovida
236 * Networks, Inc. and many individuals on behalf of Vovida Networks,
237 * Inc. For more information on Vovida Networks, Inc., please see
238 * <http://www.vovida.org/>.
239 *
240 */
#define defineParam(_enum, _name, _type, _RFC_ref_ignored)
Definition Auth.cxx:239
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
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 skipNonWhitespace()
uint32_t uInt32()
dcm! – merge these, ask about length checks
CurrentPosition skipWhitespace()
CurrentPosition skipToChar(char c)
void reset(const char *pos)
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='"')
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 a numeric-with-comment header field value.
virtual ParserCategory * clone() const
virtual Parameter * createParam(ParameterTypes::Type type, ParseBuffer &pb, const std::bitset< 256 > &terminators, PoolBase *pool)
const Data & comment() const
void remove(const Param< UInt32Category > &paramType)
UInt32Category & operator=(const UInt32Category &)
const uint32_t & value() const
virtual void parse(ParseBuffer &pb)
virtual EncodeStream & encodeParsed(EncodeStream &str) const
bool exists(const Param< UInt32Category > &paramType) const
Generically represents unsigned 32-bit integer values conveyed by SIP parameters.
dcm! – add UnusedChecking(_enum) below;
unsigned int uint32_t
Definition Stun.hxx:34
#define EncodeStream