/[resiprocate]/branches/b-identity-0505/Auth.cxx
ViewVC logotype

Contents of /branches/b-identity-0505/Auth.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4598 - (show annotations) (download)
Wed May 11 22:53:07 2005 UTC (14 years, 6 months ago) by derek
File size: 9532 byte(s)
set svn:eol-style to LF
1 #if defined(HAVE_CONFIG_H)
2 #include "resiprocate/config.hxx"
3 #endif
4
5 #include "resiprocate/Auth.hxx"
6 #include "resiprocate/UnknownParameter.hxx"
7 #include "resiprocate/os/Data.hxx"
8 #include "resiprocate/os/DnsUtil.hxx"
9 #include "resiprocate/os/Logger.hxx"
10 #include "resiprocate/os/ParseBuffer.hxx"
11 #include "resiprocate/os/WinLeakCheck.hxx"
12
13 using namespace resip;
14 using namespace std;
15
16 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
17
18 //====================
19 // Auth:
20 //====================
21 Auth::Auth() :
22 ParserCategory()
23 {}
24
25 Auth::Auth(HeaderFieldValue* hfv, Headers::Type type)
26 : ParserCategory(hfv, type)
27 {}
28
29 Auth::Auth(const Auth& rhs)
30 : ParserCategory(rhs)
31 {
32 if (isParsed())
33 {
34 scheme() = rhs.scheme();
35 }
36 }
37
38 Auth&
39 Auth::operator=(const Auth& rhs)
40 {
41 if (this != &rhs)
42 {
43 ParserCategory::operator=(rhs);
44 scheme() = rhs.scheme();
45 }
46 return *this;
47 }
48
49 Data&
50 Auth::scheme()
51 {
52 checkParsed();
53 return mScheme;
54 }
55
56 const Data&
57 Auth::scheme() const
58 {
59 checkParsed();
60 return mScheme;
61 }
62
63 void
64 Auth::parse(ParseBuffer& pb)
65 {
66 const char* start;
67 start = pb.skipWhitespace();
68 pb.skipToOneOf(ParseBuffer::Whitespace, Symbols::EQUALS);
69
70 if (!pb.eof() && *pb.position() == Symbols::EQUALS[0])
71 {
72 // Authentication-Info only
73 // back up, and then parse
74 pb.reset(start);
75 parseAuthParameters(pb);
76 }
77 else
78 {
79 // everything else
80 pb.data(mScheme, start);
81
82 pb.skipWhitespace();
83 parseAuthParameters(pb);
84 }
85 }
86
87 std::ostream&
88 Auth::encodeParsed(std::ostream& str) const
89 {
90 if (!mScheme.empty())
91 {
92 str << mScheme << Symbols::SPACE;
93 }
94
95 encodeAuthParameters(str);
96
97 return str;
98 }
99
100 ParserCategory*
101 Auth::clone() const
102 {
103 return new Auth(*this);
104 }
105
106 void
107 Auth::parseAuthParameters(ParseBuffer& pb)
108 {
109 while (!pb.eof())
110 {
111 const char* keyStart = pb.position();
112 const char* keyEnd = pb.skipToOneOf(" \t\r\n=");
113 ParameterTypes::Type type = ParameterTypes::getType(keyStart, (keyEnd - keyStart));
114 if (type == ParameterTypes::UNKNOWN)
115 {
116 mUnknownParameters.push_back(new UnknownParameter(keyStart,
117 int((keyEnd - keyStart)), pb,
118 " \t\r\n,"));
119 }
120 else
121 {
122 // invoke the particular factory
123 mParameters.push_back(ParameterTypes::ParameterFactories[type](type, pb, " \t\r\n,"));
124 }
125 pb.skipWhitespace();
126 if (pb.eof() || *pb.position() != Symbols::COMMA[0])
127 {
128 break;
129 }
130 pb.skipChar();
131 pb.skipWhitespace();
132 }
133 }
134
135 ostream&
136 Auth::encodeAuthParameters(ostream& str) const
137 {
138 bool first = true;
139 for (ParameterList::iterator it = mParameters.begin();
140 it != mParameters.end(); it++)
141 {
142 if (!first)
143 {
144 str << Symbols::COMMA;
145 }
146 first = false;
147 (*it)->encode(str);
148 }
149
150 for (ParameterList::iterator it = mUnknownParameters.begin();
151 it != mUnknownParameters.end(); it++)
152 {
153 if (!first)
154 {
155 str << Symbols::COMMA;
156 }
157 first = false;
158 (*it)->encode(str);
159 }
160 return str;
161 }
162
163 #define defineParam(_enum, _name, _type, _RFC_ref_ignored) \
164 _enum##_Param::DType& \
165 Auth::param(const _enum##_Param& paramType) \
166 { \
167 checkParsed(); \
168 _enum##_Param::Type* p = static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum())); \
169 if (!p) \
170 { \
171 p = new _enum##_Param::Type(paramType.getTypeNum()); \
172 mParameters.push_back(p); \
173 } \
174 return p->value(); \
175 } \
176 const _enum##_Param::DType& \
177 Auth::param(const _enum##_Param& paramType) const \
178 { \
179 checkParsed(); \
180 _enum##_Param::Type* p = static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum())); \
181 if (!p) \
182 { \
183 InfoLog(<< "Missing parameter " << ParameterTypes::ParameterNames[paramType.getTypeNum()]); \
184 DebugLog(<< *this); \
185 throw Exception("Missing parameter", __FILE__, __LINE__); \
186 } \
187 return p->value(); \
188 }
189
190 defineParam(algorithm, "algorithm", DataParameter, "RFC ????");
191 defineParam(cnonce, "cnonce", QuotedDataParameter, "RFC ????");
192 defineParam(nonce, "nonce", QuotedDataParameter, "RFC ????");
193 defineParam(domain, "domain", QuotedDataParameter, "RFC ????");
194 defineParam(nc, "nc", DataParameter, "RFC ????");
195 defineParam(opaque, "opaque", QuotedDataParameter, "RFC ????");
196 defineParam(qop, "qop", <SPECIAL-CASE>, "RFC ????");
197 defineParam(realm, "realm", QuotedDataParameter, "RFC ????");
198 defineParam(response, "response", QuotedDataParameter, "RFC ????");
199 defineParam(stale, "stale", DataParameter, "RFC ????");
200 defineParam(uri, "uri", QuotedDataParameter, "RFC ????");
201 defineParam(username, "username", DataParameter, "RFC ????");
202
203
204 Qop_Options_Param::DType&
205 Auth::param(const Qop_Options_Param& paramType) const
206 {
207 checkParsed();
208 Qop_Options_Param::Type* p = static_cast<Qop_Options_Param::Type*>(getParameterByEnum(paramType.getTypeNum()));
209 if (!p)
210 {
211 p = new Qop_Options_Param::Type(paramType.getTypeNum());
212 mParameters.push_back(p);
213 }
214 return p->value();
215 }
216
217 /* ====================================================================
218 * The Vovida Software License, Version 1.0
219 *
220 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
221 *
222 * Redistribution and use in source and binary forms, with or without
223 * modification, are permitted provided that the following conditions
224 * are met:
225 *
226 * 1. Redistributions of source code must retain the above copyright
227 * notice, this list of conditions and the following disclaimer.
228 *
229 * 2. Redistributions in binary form must reproduce the above copyright
230 * notice, this list of conditions and the following disclaimer in
231 * the documentation and/or other materials provided with the
232 * distribution.
233 *
234 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
235 * and "Vovida Open Communication Application Library (VOCAL)" must
236 * not be used to endorse or promote products derived from this
237 * software without prior written permission. For written
238 * permission, please contact vocal@vovida.org.
239 *
240 * 4. Products derived from this software may not be called "VOCAL", nor
241 * may "VOCAL" appear in their name, without prior written
242 * permission of Vovida Networks, Inc.
243 *
244 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
245 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
246 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
247 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
248 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
249 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
250 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
251 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
252 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
253 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
254 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
255 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
256 * DAMAGE.
257 *
258 * ====================================================================
259 *
260 * This software consists of voluntary contributions made by Vovida
261 * Networks, Inc. and many individuals on behalf of Vovida Networks,
262 * Inc. For more information on Vovida Networks, Inc., please see
263 * <http://www.vovida.org/>.
264 *
265 */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27