reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
ExpiresCategory.cxx
Go to the documentation of this file.
1#if defined(HAVE_CONFIG_H)
2#include "config.h"
3#endif
4
5#include <ctype.h>
6
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// Expires:
19//====================
24
26 Headers::Type type,
27 PoolBase* pool)
28 : ParserCategory(hfv, type, pool), mValue(0)
29{}
30
32 PoolBase* pool)
33 : ParserCategory(rhs, pool),
34 mValue(rhs.mValue)
35{}
36
39{
40 if (this != &rhs)
41 {
43 mValue = rhs.mValue;
44 }
45 return *this;
46}
47
49{
50 return new ExpiresCategory(*this);
51}
52
54{
55 return new (location) ExpiresCategory(*this);
56}
57
60{
61 return new (pool) ExpiresCategory(*this, pool);
62}
63
66{
67 checkParsed();
68 return mValue;
69}
70
73{
74 checkParsed();
75 return mValue;
76}
77
78void
80{
81 pb.skipWhitespace();
82 const char *p = pb.position();
83 if (!pb.eof() && isdigit(static_cast< unsigned char >(*p)))
84 {
85 mValue = pb.uInt32();
86 }
87 else
88 {
89 mValue = 3600;
90 }
93}
94
96ExpiresCategory::encodeParsed(EncodeStream& str) const
97{
98 str << mValue;
100 return str;
101}
102
103ParameterTypes::Factory ExpiresCategory::ParameterFactories[ParameterTypes::MAX_PARAMETER]={0};
104
105Parameter*
106ExpiresCategory::createParam(ParameterTypes::Type type, ParseBuffer& pb, const std::bitset<256>& terminators, PoolBase* pool)
107{
108 if(type > ParameterTypes::UNKNOWN && type < ParameterTypes::MAX_PARAMETER && ParameterFactories[type])
109 {
110 return ParameterFactories[type](type, pb, terminators, pool);
111 }
112 return 0;
113}
114
115bool
117{
118 checkParsed();
119 bool ret = getParameterByEnum(paramType.getTypeNum()) != NULL;
120 return ret;
121}
122
123void
129
130#define defineParam(_enum, _name, _type, _RFC_ref_ignored) \
131_enum##_Param::DType& \
132ExpiresCategory::param(const _enum##_Param& paramType) \
133{ \
134 checkParsed(); \
135 _enum##_Param::Type* p = \
136 static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum())); \
137 if (!p) \
138 { \
139 p = new _enum##_Param::Type(paramType.getTypeNum()); \
140 mParameters.push_back(p); \
141 } \
142 return p->value(); \
143} \
144 \
145const _enum##_Param::DType& \
146ExpiresCategory::param(const _enum##_Param& paramType) const \
147{ \
148 checkParsed(); \
149 _enum##_Param::Type* p = \
150 static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum())); \
151 if (!p) \
152 { \
153 InfoLog(<< "Missing parameter " _name " " << ParameterTypes::ParameterNames[paramType.getTypeNum()]); \
154 DebugLog(<< *this); \
155 throw Exception("Missing parameter " _name, __FILE__, __LINE__); \
156 } \
157 return p->value(); \
158}
159
160defineParam(refresher, "refresher", DataParameter, "RFC 4028");
161
162#undef defineParam
163
164/* ====================================================================
165 * The Vovida Software License, Version 1.0
166 *
167 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
168 *
169 * Redistribution and use in source and binary forms, with or without
170 * modification, are permitted provided that the following conditions
171 * are met:
172 *
173 * 1. Redistributions of source code must retain the above copyright
174 * notice, this list of conditions and the following disclaimer.
175 *
176 * 2. Redistributions in binary form must reproduce the above copyright
177 * notice, this list of conditions and the following disclaimer in
178 * the documentation and/or other materials provided with the
179 * distribution.
180 *
181 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
182 * and "Vovida Open Communication Application Library (VOCAL)" must
183 * not be used to endorse or promote products derived from this
184 * software without prior written permission. For written
185 * permission, please contact vocal@vovida.org.
186 *
187 * 4. Products derived from this software may not be called "VOCAL", nor
188 * may "VOCAL" appear in their name, without prior written
189 * permission of Vovida Networks, Inc.
190 *
191 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
192 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
193 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
194 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
195 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
196 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
197 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
198 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
199 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
200 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
201 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
202 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
203 * DAMAGE.
204 *
205 * ====================================================================
206 *
207 * This software consists of voluntary contributions made by Vovida
208 * Networks, Inc. and many individuals on behalf of Vovida Networks,
209 * Inc. For more information on Vovida Networks, Inc., please see
210 * <http://www.vovida.org/>.
211 *
212 */
#define defineParam(_enum, _name, _type, _RFC_ref_ignored)
Definition Auth.cxx:239
Generically represents miscellaneous parameter data.
Represents the header field value for an Expires-type header.
ExpiresCategory & operator=(const ExpiresCategory &)
virtual void parse(ParseBuffer &pb)
bool exists(const Param< ExpiresCategory > &paramType) const
virtual EncodeStream & encodeParsed(EncodeStream &str) const
virtual ParserCategory * clone() const
void remove(const Param< ExpiresCategory > &paramType)
virtual Parameter * createParam(ParameterTypes::Type type, ParseBuffer &pb, const std::bitset< 256 > &terminators, PoolBase *pool)
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.
uint32_t uInt32()
dcm! – merge these, ask about length checks
CurrentPosition skipWhitespace()
CurrentPosition skipToChar(char c)
CurrentPosition position() const
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
dcm! – add UnusedChecking(_enum) below;
unsigned int uint32_t
Definition Stun.hxx:34
#define EncodeStream