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