/src/resiprocate/resip/stack/ExpiresCategory.cxx
Line | Count | Source |
1 | | #if defined(HAVE_CONFIG_H) |
2 | | #include "config.h" |
3 | | #endif |
4 | | |
5 | | #include <ctype.h> |
6 | | |
7 | | #include "resip/stack/ExpiresCategory.hxx" |
8 | | #include "rutil/Logger.hxx" |
9 | | #include "rutil/ParseBuffer.hxx" |
10 | | //#include "rutil/WinLeakCheck.hxx" // not compatible with placement new used below |
11 | | |
12 | | using namespace resip; |
13 | | using namespace std; |
14 | | |
15 | | #define RESIPROCATE_SUBSYSTEM Subsystem::SIP |
16 | | |
17 | | //==================== |
18 | | // Expires: |
19 | | //==================== |
20 | | ExpiresCategory:: ExpiresCategory() |
21 | 0 | : ParserCategory(), |
22 | 0 | mValue(0) |
23 | 0 | {} |
24 | | |
25 | | ExpiresCategory::ExpiresCategory(const HeaderFieldValue& hfv, |
26 | | Headers::Type type, |
27 | | PoolBase* pool) |
28 | 6.22k | : ParserCategory(hfv, type, pool), mValue(0) |
29 | 6.22k | {} |
30 | | |
31 | | ExpiresCategory::ExpiresCategory(const ExpiresCategory& rhs, |
32 | | PoolBase* pool) |
33 | 0 | : ParserCategory(rhs, pool), |
34 | 0 | mValue(rhs.mValue) |
35 | 0 | {} |
36 | | |
37 | | ExpiresCategory& |
38 | | ExpiresCategory::operator=(const ExpiresCategory& rhs) |
39 | 0 | { |
40 | 0 | if (this != &rhs) |
41 | 0 | { |
42 | 0 | ParserCategory::operator=(rhs); |
43 | 0 | mValue = rhs.mValue; |
44 | 0 | } |
45 | 0 | return *this; |
46 | 0 | } |
47 | | |
48 | | ParserCategory* ExpiresCategory::clone() const |
49 | 0 | { |
50 | 0 | return new ExpiresCategory(*this); |
51 | 0 | } |
52 | | |
53 | | ParserCategory* ExpiresCategory::clone(void* location) const |
54 | 0 | { |
55 | 0 | return new (location) ExpiresCategory(*this); |
56 | 0 | } |
57 | | |
58 | | ParserCategory* |
59 | | ExpiresCategory::clone(PoolBase* pool) const |
60 | 0 | { |
61 | 0 | return new (pool) ExpiresCategory(*this, pool); |
62 | 0 | } |
63 | | |
64 | | uint32_t& |
65 | | ExpiresCategory::value() |
66 | 0 | { |
67 | 0 | checkParsed(); |
68 | 0 | return mValue; |
69 | 0 | } |
70 | | |
71 | | uint32_t |
72 | | ExpiresCategory::value() const |
73 | 0 | { |
74 | 0 | checkParsed(); |
75 | 0 | return mValue; |
76 | 0 | } |
77 | | |
78 | | void |
79 | | ExpiresCategory::parse(ParseBuffer& pb) |
80 | 6.22k | { |
81 | 6.22k | pb.skipWhitespace(); |
82 | 6.22k | const char *p = pb.position(); |
83 | 6.22k | if (!pb.eof() && isdigit(static_cast< unsigned char >(*p))) |
84 | 473 | { |
85 | 473 | mValue = pb.uInt32(); |
86 | 473 | } |
87 | 5.75k | else |
88 | 5.75k | { |
89 | 5.75k | mValue = 3600; |
90 | 5.75k | } |
91 | 6.22k | pb.skipToChar(Symbols::SEMI_COLON[0]); |
92 | 6.22k | parseParameters(pb); |
93 | 6.22k | } |
94 | | |
95 | | EncodeStream& |
96 | | ExpiresCategory::encodeParsed(EncodeStream& str) const |
97 | 0 | { |
98 | 0 | str << mValue; |
99 | 0 | encodeParameters(str); |
100 | 0 | return str; |
101 | 0 | } |
102 | | |
103 | | ParameterTypes::Factory ExpiresCategory::ParameterFactories[ParameterTypes::MAX_PARAMETER]={0}; |
104 | | |
105 | | Parameter* |
106 | | ExpiresCategory::createParam(ParameterTypes::Type type, ParseBuffer& pb, const std::bitset<256>& terminators, PoolBase* pool) |
107 | 22.6k | { |
108 | 22.6k | if(type > ParameterTypes::UNKNOWN && type < ParameterTypes::MAX_PARAMETER && ParameterFactories[type]) |
109 | 0 | { |
110 | 0 | return ParameterFactories[type](type, pb, terminators, pool); |
111 | 0 | } |
112 | 22.6k | return 0; |
113 | 22.6k | } |
114 | | |
115 | | bool |
116 | | ExpiresCategory::exists(const Param<ExpiresCategory>& paramType) const |
117 | 0 | { |
118 | 0 | checkParsed(); |
119 | 0 | bool ret = getParameterByEnum(paramType.getTypeNum()) != NULL; |
120 | 0 | return ret; |
121 | 0 | } |
122 | | |
123 | | void |
124 | | ExpiresCategory::remove(const Param<ExpiresCategory>& paramType) |
125 | 0 | { |
126 | 0 | checkParsed(); |
127 | 0 | removeParameterByEnum(paramType.getTypeNum()); |
128 | 0 | } |
129 | | |
130 | | #define defineParam(_enum, _name, _type, _RFC_ref_ignored) \ |
131 | | _enum##_Param::DType& \ |
132 | 0 | ExpiresCategory::param(const _enum##_Param& paramType) \ |
133 | 0 | { \ |
134 | 0 | checkParsed(); \ |
135 | 0 | _enum##_Param::Type* p = \ |
136 | 0 | static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum())); \ |
137 | 0 | if (!p) \ |
138 | 0 | { \ |
139 | 0 | p = new _enum##_Param::Type(paramType.getTypeNum()); \ |
140 | 0 | mParameters.push_back(p); \ |
141 | 0 | } \ |
142 | 0 | return p->value(); \ |
143 | 0 | } \ |
144 | | \ |
145 | | const _enum##_Param::DType& \ |
146 | 0 | ExpiresCategory::param(const _enum##_Param& paramType) const \ |
147 | 0 | { \ |
148 | 0 | checkParsed(); \ |
149 | 0 | _enum##_Param::Type* p = \ |
150 | 0 | static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum())); \ |
151 | 0 | if (!p) \ |
152 | 0 | { \ |
153 | 0 | InfoLog(<< "Missing parameter " _name " " << ParameterTypes::ParameterNames[paramType.getTypeNum()]); \ |
154 | 0 | DebugLog(<< *this); \ |
155 | 0 | throw Exception("Missing parameter " _name, __FILE__, __LINE__); \ |
156 | 0 | } \ |
157 | 0 | return p->value(); \ |
158 | 0 | } |
159 | | |
160 | | defineParam(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 | | */ |