/[resiprocate]/main/sip/resiprocate/Aor.cxx
ViewVC logotype

Contents of /main/sip/resiprocate/Aor.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4599 - (show annotations) (download)
Wed May 11 23:10:19 2005 UTC (14 years, 6 months ago) by derek
File size: 6286 byte(s)
set svn:eol-style to LF
1 #include <iostream>
2
3 #include "resiprocate/os/ParseBuffer.hxx"
4 #include "resiprocate/os/DataStream.hxx"
5 #include "resiprocate/os/DnsUtil.hxx"
6 #include "resiprocate/Uri.hxx"
7 #include "resiprocate/Aor.hxx"
8
9 using namespace resip;
10
11 Aor::Aor()
12 {
13 }
14
15 Aor::Aor(const Data& value)
16 {
17 ParseBuffer pb(value);
18
19 pb.skipWhitespace();
20 const char* start = pb.position();
21 pb.skipToOneOf(":@"); // make sure the colon precedes
22
23 pb.assertNotEof();
24
25 pb.data(mScheme, start);
26 pb.skipChar(Symbols::COLON[0]);
27 mScheme.lowercase();
28
29 if (isEqualNoCase(mScheme, Symbols::Tel))
30 {
31 const char* anchor = pb.position();
32 pb.skipToOneOf(ParseBuffer::Whitespace, ";>");
33 pb.data(mUser, anchor);
34 if (!pb.eof() && *pb.position() == Symbols::SEMI_COLON[0])
35 {
36 anchor = pb.skipChar();
37 pb.skipToOneOf(ParseBuffer::Whitespace, Symbols::RA_QUOTE);
38 }
39 return;
40 }
41
42 start = pb.position();
43 pb.skipToChar(Symbols::AT_SIGN[0]);
44 if (!pb.eof())
45 {
46 pb.reset(start);
47 start = pb.position();
48 pb.skipToOneOf(":@");
49 pb.data(mUser, start);
50 if (!pb.eof() && *pb.position() == Symbols::COLON[0])
51 {
52 start = pb.skipChar();
53 pb.skipToChar(Symbols::AT_SIGN[0]);
54 }
55 start = pb.skipChar();
56 }
57 else
58 {
59 pb.reset(start);
60 }
61
62 if (*start == '[')
63 {
64 start = pb.skipChar();
65 pb.skipToChar(']');
66 pb.data(mHost, start);
67 DnsUtil::canonicalizeIpV6Address(mHost);
68 pb.skipChar();
69 }
70 else
71 {
72 pb.skipToOneOf(ParseBuffer::Whitespace, ":;?>");
73 pb.data(mHost, start);
74 }
75
76 pb.skipToOneOf(ParseBuffer::Whitespace, ":;?>");
77 if (!pb.eof() && *pb.position() == ':')
78 {
79 start = pb.skipChar();
80 mPort = pb.integer();
81 pb.skipToOneOf(ParseBuffer::Whitespace, ";?>");
82 }
83 else
84 {
85 mPort = 0;
86 }
87 }
88
89 Aor::Aor(const Uri& uri) :
90 mScheme(uri.scheme()),
91 mUser(uri.user()),
92 mHost(uri.host()),
93 mPort(uri.port())
94 {
95
96 }
97
98 Aor::Aor(const Aor& aor)
99 {
100 *this = aor;
101 }
102
103 Aor&
104 Aor::operator=(const Aor& aor)
105 {
106 if (this != &aor)
107 {
108 mScheme = aor.mScheme;
109 mUser = aor.mUser;
110 mHost = aor.mHost;
111 mPort = aor.mPort;
112 }
113 return *this;
114 }
115
116
117 bool
118 Aor::operator==(const Aor& other) const
119 {
120 return value() == other.value();
121 }
122
123 bool
124 Aor::operator!=(const Aor& other) const
125 {
126 return value() != other.value();
127 }
128
129 bool
130 Aor::operator<(const Aor& other) const
131 {
132 return value() < other.value();
133 }
134
135 const Data&
136 Aor::value() const
137 {
138 if (mOldScheme != mScheme ||
139 mOldUser != mUser ||
140 mOldHost != mHost ||
141 mOldPort != mPort)
142 {
143 mOldHost = mHost;
144 if (DnsUtil::isIpV6Address(mHost))
145 {
146 mCanonicalHost = DnsUtil::canonicalizeIpV6Address(mHost);
147 }
148 else
149 {
150 mCanonicalHost = mHost;
151 mCanonicalHost.lowercase();
152 }
153
154 mOldScheme = mScheme;
155 mOldUser = mUser;
156 mOldPort = mPort;
157
158 mValue.reserve(mUser.size() + mCanonicalHost.size() + 10);
159
160 DataStream strm(mValue);
161 strm << mScheme;
162 strm << Symbols::COLON;
163 strm << mUser;
164 if (!mCanonicalHost.empty())
165 {
166 strm << Symbols::AT_SIGN;
167 strm << mCanonicalHost;
168
169 if (mPort != 0)
170 {
171 strm << Symbols::COLON;
172 strm << Data(mPort);
173 }
174 }
175 }
176
177 return mValue;
178 }
179
180 Data&
181 Aor::scheme()
182 {
183 return mScheme;
184 }
185
186 const Data&
187 Aor::scheme() const
188 {
189 return mScheme;
190 }
191
192 Data&
193 Aor::host()
194 {
195 return mHost;
196 }
197
198 const Data&
199 Aor::host() const
200 {
201 return mHost;
202 }
203
204 Data&
205 Aor::user()
206 {
207 return mUser;
208 }
209
210 const Data&
211 Aor::user() const
212 {
213 return mUser;
214 }
215
216 int&
217 Aor::port()
218 {
219 return mPort;
220 }
221
222 int
223 Aor::port() const
224 {
225 return mPort;
226 }
227
228 std::ostream&
229 Aor::operator<<(std::ostream& str) const
230 {
231 str << value();
232 return str;
233 }
234
235 /* ====================================================================
236 * The Vovida Software License, Version 1.0
237 *
238 * Copyright (c) 2000-2005 Vovida Networks, Inc. All rights reserved.
239 *
240 * Redistribution and use in source and binary forms, with or without
241 * modification, are permitted provided that the following conditions
242 * are met:
243 *
244 * 1. Redistributions of source code must retain the above copyright
245 * notice, this list of conditions and the following disclaimer.
246 *
247 * 2. Redistributions in binary form must reproduce the above copyright
248 * notice, this list of conditions and the following disclaimer in
249 * the documentation and/or other materials provided with the
250 * distribution.
251 *
252 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
253 * and "Vovida Open Communication Application Library (VOCAL)" must
254 * not be used to endorse or promote products derived from this
255 * software without prior written permission. For written
256 * permission, please contact vocal@vovida.org.
257 *
258 * 4. Products derived from this software may not be called "VOCAL", nor
259 * may "VOCAL" appear in their name, without prior written
260 * permission of Vovida Networks, Inc.
261 *
262 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
263 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
264 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
265 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
266 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
267 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
268 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
269 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
270 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
271 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
272 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
273 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
274 * DAMAGE.
275 *
276 * ====================================================================
277 *
278 * This software consists of voluntary contributions made by Vovida
279 * Networks, Inc. and many individuals on behalf of Vovida Networks,
280 * Inc. For more information on Vovida Networks, Inc., please see
281 * <http://www.vovida.org/>.
282 *
283 */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27