/src/resiprocate/resip/stack/Token.cxx
Line | Count | Source |
1 | | #if defined(HAVE_CONFIG_H) |
2 | | #include "config.h" |
3 | | #endif |
4 | | |
5 | | #include "resip/stack/Token.hxx" |
6 | | #include "rutil/Data.hxx" |
7 | | #include "rutil/DnsUtil.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 | | //==================== |
19 | | // Token |
20 | | //=================== |
21 | | Token::Token() |
22 | 0 | : ParserCategory(), |
23 | 0 | mValue() |
24 | 0 | {} |
25 | | |
26 | | Token::Token(const Data& d) |
27 | 0 | : ParserCategory(), |
28 | 0 | mValue(d) |
29 | 0 | {} |
30 | | |
31 | | Token::Token(const HeaderFieldValue& hfv, Headers::Type type, PoolBase* pool) |
32 | 0 | : ParserCategory(hfv, type, pool), |
33 | 0 | mValue() |
34 | 0 | {} |
35 | | |
36 | | Token::Token(const Token& rhs, PoolBase* pool) |
37 | 0 | : ParserCategory(rhs, pool), |
38 | 0 | mValue(rhs.mValue) |
39 | 0 | {} |
40 | | |
41 | | Token& |
42 | | Token::operator=(const Token& rhs) |
43 | 0 | { |
44 | 0 | if (this != &rhs) |
45 | 0 | { |
46 | 0 | ParserCategory::operator=(rhs); |
47 | 0 | mValue = rhs.mValue; |
48 | 0 | } |
49 | 0 | return *this; |
50 | 0 | } |
51 | | |
52 | | bool |
53 | | Token::isEqual(const Token& rhs) const |
54 | 0 | { |
55 | 0 | return (value() == rhs.value()); |
56 | 0 | } |
57 | | |
58 | | bool |
59 | | Token::operator==(const Token& rhs) const |
60 | 0 | { |
61 | 0 | return (value() == rhs.value()); |
62 | 0 | } |
63 | | |
64 | | bool |
65 | | Token::operator!=(const Token& rhs) const |
66 | 0 | { |
67 | 0 | return (value() != rhs.value()); |
68 | 0 | } |
69 | | |
70 | | bool |
71 | | Token::operator<(const Token& rhs) const |
72 | 0 | { |
73 | 0 | return (value() < rhs.value()); |
74 | 0 | } |
75 | | |
76 | | const Data& |
77 | | Token::value() const |
78 | 0 | { |
79 | 0 | checkParsed(); |
80 | 0 | return mValue; |
81 | 0 | } |
82 | | |
83 | | Data& |
84 | | Token::value() |
85 | 0 | { |
86 | 0 | checkParsed(); |
87 | 0 | return mValue; |
88 | 0 | } |
89 | | |
90 | | void |
91 | | Token::parse(ParseBuffer& pb) |
92 | 0 | { |
93 | 0 | const char* startMark = pb.skipWhitespace(); |
94 | 0 | pb.skipToOneOf(ParseBuffer::Whitespace, Symbols::SEMI_COLON); |
95 | 0 | pb.data(mValue, startMark); |
96 | 0 | pb.skipToChar(Symbols::SEMI_COLON[0]); |
97 | 0 | parseParameters(pb); |
98 | 0 | } |
99 | | |
100 | | ParserCategory* |
101 | | Token::clone() const |
102 | 0 | { |
103 | 0 | return new Token(*this); |
104 | 0 | } |
105 | | |
106 | | ParserCategory* |
107 | | Token::clone(void* location) const |
108 | 0 | { |
109 | 0 | return new (location) Token(*this); |
110 | 0 | } |
111 | | |
112 | | ParserCategory* |
113 | | Token::clone(PoolBase* pool) const |
114 | 0 | { |
115 | 0 | return new (pool) Token(*this, pool); |
116 | 0 | } |
117 | | |
118 | | EncodeStream& |
119 | | Token::encodeParsed(EncodeStream& str) const |
120 | 0 | { |
121 | 0 | str << mValue; |
122 | 0 | encodeParameters(str); |
123 | 0 | return str; |
124 | 0 | } |
125 | | |
126 | | ParameterTypes::Factory Token::ParameterFactories[ParameterTypes::MAX_PARAMETER]={0}; |
127 | | |
128 | | Parameter* |
129 | | Token::createParam(ParameterTypes::Type type, ParseBuffer& pb, const std::bitset<256>& terminators, PoolBase* pool) |
130 | 0 | { |
131 | 0 | if(type > ParameterTypes::UNKNOWN && type < ParameterTypes::MAX_PARAMETER && ParameterFactories[type]) |
132 | 0 | { |
133 | 0 | return ParameterFactories[type](type, pb, terminators, pool); |
134 | 0 | } |
135 | 0 | return 0; |
136 | 0 | } |
137 | | |
138 | | bool |
139 | | Token::exists(const Param<Token>& paramType) const |
140 | 0 | { |
141 | 0 | checkParsed(); |
142 | 0 | bool ret = getParameterByEnum(paramType.getTypeNum()) != NULL; |
143 | 0 | return ret; |
144 | 0 | } |
145 | | |
146 | | void |
147 | | Token::remove(const Param<Token>& paramType) |
148 | 0 | { |
149 | 0 | checkParsed(); |
150 | 0 | removeParameterByEnum(paramType.getTypeNum()); |
151 | 0 | } |
152 | | |
153 | | #define defineParam(_enum, _name, _type, _RFC_ref_ignored) \ |
154 | | _enum##_Param::DType& \ |
155 | 0 | Token::param(const _enum##_Param& paramType) \ |
156 | 0 | { \ |
157 | 0 | checkParsed(); \ |
158 | 0 | _enum##_Param::Type* p = \ |
159 | 0 | static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum())); \ |
160 | 0 | if (!p) \ |
161 | 0 | { \ |
162 | 0 | p = new _enum##_Param::Type(paramType.getTypeNum()); \ |
163 | 0 | mParameters.push_back(p); \ |
164 | 0 | } \ |
165 | 0 | return p->value(); \ |
166 | 0 | } \ Unexecuted instantiation: resip::Token::param(resip::text_Param const&) Unexecuted instantiation: resip::Token::param(resip::cause_Param const&) Unexecuted instantiation: resip::Token::param(resip::dAlg_Param const&) Unexecuted instantiation: resip::Token::param(resip::dQop_Param const&) Unexecuted instantiation: resip::Token::param(resip::dVer_Param const&) Unexecuted instantiation: resip::Token::param(resip::expires_Param const&) Unexecuted instantiation: resip::Token::param(resip::filename_Param const&) Unexecuted instantiation: resip::Token::param(resip::fromTag_Param const&) Unexecuted instantiation: resip::Token::param(resip::handling_Param const&) Unexecuted instantiation: resip::Token::param(resip::id_Param const&) Unexecuted instantiation: resip::Token::param(resip::q_Param const&) Unexecuted instantiation: resip::Token::param(resip::reason_Param const&) Unexecuted instantiation: resip::Token::param(resip::retryAfter_Param const&) Unexecuted instantiation: resip::Token::param(resip::toTag_Param const&) Unexecuted instantiation: resip::Token::param(resip::extension_Param const&) Unexecuted instantiation: resip::Token::param(resip::profileType_Param const&) Unexecuted instantiation: resip::Token::param(resip::vendor_Param const&) Unexecuted instantiation: resip::Token::param(resip::model_Param const&) Unexecuted instantiation: resip::Token::param(resip::version_Param const&) Unexecuted instantiation: resip::Token::param(resip::effectiveBy_Param const&) Unexecuted instantiation: resip::Token::param(resip::document_Param const&) Unexecuted instantiation: resip::Token::param(resip::appId_Param const&) Unexecuted instantiation: resip::Token::param(resip::networkUser_Param const&) Unexecuted instantiation: resip::Token::param(resip::require_Param const&) Unexecuted instantiation: resip::Token::param(resip::utranCellId3gpp_Param const&) Unexecuted instantiation: resip::Token::param(resip::cgi3gpp_Param const&) Unexecuted instantiation: resip::Token::param(resip::ccf_Param const&) Unexecuted instantiation: resip::Token::param(resip::ecf_Param const&) Unexecuted instantiation: resip::Token::param(resip::icidValue_Param const&) Unexecuted instantiation: resip::Token::param(resip::icidGeneratedAt_Param const&) Unexecuted instantiation: resip::Token::param(resip::origIoi_Param const&) Unexecuted instantiation: resip::Token::param(resip::termIoi_Param const&) |
167 | | \ |
168 | | const _enum##_Param::DType& \ |
169 | 0 | Token::param(const _enum##_Param& paramType) const \ |
170 | 0 | { \ |
171 | 0 | checkParsed(); \ |
172 | 0 | _enum##_Param::Type* p = \ |
173 | 0 | static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum())); \ |
174 | 0 | if (!p) \ |
175 | 0 | { \ |
176 | 0 | InfoLog(<< "Missing parameter " _name " " << ParameterTypes::ParameterNames[paramType.getTypeNum()]); \ |
177 | 0 | DebugLog(<< *this); \ |
178 | 0 | throw Exception("Missing parameter " _name, __FILE__, __LINE__); \ |
179 | 0 | } \ |
180 | 0 | return p->value(); \ |
181 | 0 | } Unexecuted instantiation: resip::Token::param(resip::text_Param const&) const Unexecuted instantiation: resip::Token::param(resip::cause_Param const&) const Unexecuted instantiation: resip::Token::param(resip::dAlg_Param const&) const Unexecuted instantiation: resip::Token::param(resip::dQop_Param const&) const Unexecuted instantiation: resip::Token::param(resip::dVer_Param const&) const Unexecuted instantiation: resip::Token::param(resip::expires_Param const&) const Unexecuted instantiation: resip::Token::param(resip::filename_Param const&) const Unexecuted instantiation: resip::Token::param(resip::fromTag_Param const&) const Unexecuted instantiation: resip::Token::param(resip::handling_Param const&) const Unexecuted instantiation: resip::Token::param(resip::id_Param const&) const Unexecuted instantiation: resip::Token::param(resip::q_Param const&) const Unexecuted instantiation: resip::Token::param(resip::reason_Param const&) const Unexecuted instantiation: resip::Token::param(resip::retryAfter_Param const&) const Unexecuted instantiation: resip::Token::param(resip::toTag_Param const&) const Unexecuted instantiation: resip::Token::param(resip::extension_Param const&) const Unexecuted instantiation: resip::Token::param(resip::profileType_Param const&) const Unexecuted instantiation: resip::Token::param(resip::vendor_Param const&) const Unexecuted instantiation: resip::Token::param(resip::model_Param const&) const Unexecuted instantiation: resip::Token::param(resip::version_Param const&) const Unexecuted instantiation: resip::Token::param(resip::effectiveBy_Param const&) const Unexecuted instantiation: resip::Token::param(resip::document_Param const&) const Unexecuted instantiation: resip::Token::param(resip::appId_Param const&) const Unexecuted instantiation: resip::Token::param(resip::networkUser_Param const&) const Unexecuted instantiation: resip::Token::param(resip::require_Param const&) const Unexecuted instantiation: resip::Token::param(resip::utranCellId3gpp_Param const&) const Unexecuted instantiation: resip::Token::param(resip::cgi3gpp_Param const&) const Unexecuted instantiation: resip::Token::param(resip::ccf_Param const&) const Unexecuted instantiation: resip::Token::param(resip::ecf_Param const&) const Unexecuted instantiation: resip::Token::param(resip::icidValue_Param const&) const Unexecuted instantiation: resip::Token::param(resip::icidGeneratedAt_Param const&) const Unexecuted instantiation: resip::Token::param(resip::origIoi_Param const&) const Unexecuted instantiation: resip::Token::param(resip::termIoi_Param const&) const |
182 | | |
183 | | defineParam(text, "text", ExistsOrDataParameter, "RFC 3840"); |
184 | | defineParam(cause, "cause", UInt32Parameter, "RFC 3326"); |
185 | | defineParam(dAlg, "d-alg", DataParameter, "RFC 3329"); |
186 | | defineParam(dQop, "d-qop", DataParameter, "RFC 3329"); |
187 | | defineParam(dVer, "d-ver", QuotedDataParameter, "RFC 3329"); |
188 | | defineParam(expires, "expires", UInt32Parameter, "RFC 3261"); |
189 | | defineParam(filename, "filename", DataParameter, "RFC 2183"); |
190 | | defineParam(fromTag, "from-tag", DataParameter, "RFC 4235"); |
191 | | defineParam(handling, "handling", DataParameter, "RFC 3261"); |
192 | | defineParam(id, "id", DataParameter, "RFC 3265"); |
193 | | defineParam(q, "q", QValueParameter, "RFC 3261"); |
194 | | defineParam(reason, "reason", DataParameter, "RFC 3265"); |
195 | | defineParam(retryAfter, "retry-after", UInt32Parameter, "RFC 3265"); |
196 | | defineParam(toTag, "to-tag", DataParameter, "RFC 4235"); |
197 | | defineParam(extension, "ext", DataParameter, "RFC 3966"); // Token is used when ext is a user-parameter |
198 | | defineParam(profileType, "profile-type", DataParameter, "RFC 6080"); |
199 | | defineParam(vendor, "vendor", QuotedDataParameter, "RFC 6080"); |
200 | | defineParam(model, "model", QuotedDataParameter, "RFC 6080"); |
201 | | defineParam(version, "version", QuotedDataParameter, "RFC 6080"); |
202 | | defineParam(effectiveBy, "effective-by", UInt32Parameter, "RFC 6080"); |
203 | | defineParam(document, "document", DataParameter, "draft-ietf-sipping-config-framework-07 (removed in 08)"); |
204 | | defineParam(appId, "app-id", DataParameter, "draft-ietf-sipping-config-framework-05 (renamed to auid in 06, which was then removed in 08)"); |
205 | | defineParam(networkUser, "network-user", DataParameter, "draft-ietf-sipping-config-framework-11 (removed in 12)"); |
206 | | defineParam(require, "require", ExistsParameter, "RFC 5373"); |
207 | | |
208 | | defineParam(utranCellId3gpp, "utran-cell-id-3gpp", DataParameter, "RFC 3455"); // P-Access-Network-Info |
209 | | defineParam(cgi3gpp, "cgi-3gpp", DataParameter, "RFC 3455"); // P-Access-Network-Info |
210 | | defineParam(ccf, "ccf", DataParameter, "RFC 3455"); // P-Charging-Function-Addresses |
211 | | defineParam(ecf, "ecf", DataParameter, "RFC 3455"); // P-Charging-Function-Addresses |
212 | | defineParam(icidValue, "icid-value", DataParameter, "RFC 3455"); // P-Charging-Vector |
213 | | defineParam(icidGeneratedAt, "icid-generated-at", DataParameter, "RFC 3455"); // P-Charging-Vector |
214 | | defineParam(origIoi, "orig-ioi", DataParameter, "RFC 3455"); // P-Charging-Vector |
215 | | defineParam(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 | | */ |