reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
Aor.cxx
Go to the documentation of this file.
1#include <iostream>
2
5#include "rutil/DnsUtil.hxx"
6#include "resip/stack/Uri.hxx"
7#include "resip/stack/Aor.hxx"
8
9using namespace resip;
10
12{
13}
14
15Aor::Aor(const Data& value)
16 : mOwnedBuffer(value.data(), value.size())
17{
18 ParseBuffer pb(mOwnedBuffer);
19
20 pb.skipWhitespace();
21 const char* start = pb.position();
22 pb.skipToOneOf(":@"); // make sure the colon precedes
23
24 pb.assertNotEof();
25
26 pb.data(mScheme, start);
28 mScheme.lowercase();
29
30 if (isEqualNoCase(mScheme, Symbols::Urn))
31 {
32 const char* anchor = pb.position();
33 // Unlike tel: (RFC 3966), the char ';' is a valid sub-delim inside
34 // a urn: (RFC 8141) NSS and must not be treated as a delimiter.
36 pb.data(mUser, anchor);
37 return;
38 }
39
40 if (isEqualNoCase(mScheme, Symbols::Tel))
41 {
42 const char* anchor = pb.position();
44 pb.data(mUser, anchor);
45 if (!pb.eof() && *pb.position() == Symbols::SEMI_COLON[0])
46 {
47 anchor = pb.skipChar();
49 }
50 return;
51 }
52
53 start = pb.position();
55 if (!pb.eof())
56 {
57 pb.reset(start);
58 start = pb.position();
59 pb.skipToOneOf(":@");
60 pb.data(mUser, start);
61 if (!pb.eof() && *pb.position() == Symbols::COLON[0])
62 {
63 start = pb.skipChar();
65 }
66 start = pb.skipChar();
67 }
68 else
69 {
70 pb.reset(start);
71 }
72
73 if (*start == '[')
74 {
75 start = pb.skipChar();
76 pb.skipToChar(']');
77 pb.data(mHost, start);
79 pb.skipChar();
80 }
81 else
82 {
84 pb.data(mHost, start);
85 }
86
88 if (!pb.eof() && *pb.position() == ':')
89 {
90 start = pb.skipChar();
91 mPort = pb.integer();
93 }
94 else
95 {
96 mPort = 0;
97 }
98}
99
100Aor::Aor(const Uri& uri) :
101 mScheme(uri.scheme()),
102 mUser(uri.user()),
103 mHost(uri.host()),
104 mPort(uri.port())
105{
106
107}
108
109Aor::Aor(const Aor& aor)
110{
111 *this = aor;
112}
113
114Aor&
116{
117 if (this != &aor)
118 {
119 mScheme = aor.mScheme;
120 mUser = aor.mUser;
121 mHost = aor.mHost;
122 mPort = aor.mPort;
123 }
124 return *this;
125}
126
127
128bool
129Aor::operator==(const Aor& other) const
130{
131 return value() == other.value();
132}
133
134bool
135Aor::operator!=(const Aor& other) const
136{
137 return value() != other.value();
138}
139
140bool
141Aor::operator<(const Aor& other) const
142{
143 return value() < other.value();
144}
145
146const Data&
148{
149 if (mOldScheme != mScheme ||
150 mOldUser != mUser ||
151 mOldHost != mHost ||
152 mOldPort != mPort)
153 {
154 mOldHost = mHost;
155 if (DnsUtil::isIpV6Address(mHost))
156 {
157 mCanonicalHost = DnsUtil::canonicalizeIpV6Address(mHost);
158 }
159 else
160 {
161 mCanonicalHost = mHost;
162 mCanonicalHost.lowercase();
163 }
164
165 mOldScheme = mScheme;
166 mOldUser = mUser;
167 mOldPort = mPort;
168
169 mValue.reserve(mUser.size() + mCanonicalHost.size() + 10);
170
171 DataStream strm(mValue);
172 strm << mScheme;
173 strm << Symbols::COLON;
174 strm << mUser;
175 if (!mCanonicalHost.empty())
176 {
177 strm << Symbols::AT_SIGN;
178 strm << mCanonicalHost;
179
180 if (mPort != 0)
181 {
182 strm << Symbols::COLON;
183 strm << Data(mPort);
184 }
185 }
186 }
187
188 return mValue;
189}
190
191Data&
193{
194 return mScheme;
195}
196
197const Data&
199{
200 return mScheme;
201}
202
203Data&
205{
206 return mHost;
207}
208
209const Data&
211{
212 return mHost;
213}
214
215Data&
217{
218 return mUser;
219}
220
221const Data&
223{
224 return mUser;
225}
226
227int&
229{
230 return mPort;
231}
232
233int
235{
236 return mPort;
237}
238
240Aor::operator<<(EncodeStream& str) const
241{
242 str << value();
243 return str;
244}
245
246/* ====================================================================
247 * The Vovida Software License, Version 1.0
248 *
249 * Copyright (c) 2000-2005 Vovida Networks, Inc. All rights reserved.
250 *
251 * Redistribution and use in source and binary forms, with or without
252 * modification, are permitted provided that the following conditions
253 * are met:
254 *
255 * 1. Redistributions of source code must retain the above copyright
256 * notice, this list of conditions and the following disclaimer.
257 *
258 * 2. Redistributions in binary form must reproduce the above copyright
259 * notice, this list of conditions and the following disclaimer in
260 * the documentation and/or other materials provided with the
261 * distribution.
262 *
263 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
264 * and "Vovida Open Communication Application Library (VOCAL)" must
265 * not be used to endorse or promote products derived from this
266 * software without prior written permission. For written
267 * permission, please contact vocal@vovida.org.
268 *
269 * 4. Products derived from this software may not be called "VOCAL", nor
270 * may "VOCAL" appear in their name, without prior written
271 * permission of Vovida Networks, Inc.
272 *
273 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
274 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
275 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
276 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
277 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
278 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
279 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
280 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
281 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
282 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
283 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
284 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
285 * DAMAGE.
286 *
287 * ====================================================================
288 *
289 * This software consists of voluntary contributions made by Vovida
290 * Networks, Inc. and many individuals on behalf of Vovida Networks,
291 * Inc. For more information on Vovida Networks, Inc., please see
292 * <http://www.vovida.org/>.
293 *
294 */
bool operator!=(const Aor &other) const
Definition Aor.cxx:135
EncodeStream & operator<<(EncodeStream &str) const
Definition Aor.cxx:240
Data & user()
Definition Aor.cxx:216
Data & host()
Definition Aor.cxx:204
const Data & value() const
Definition Aor.cxx:147
Aor & operator=(const Aor &aor)
Definition Aor.cxx:115
int & port()
Definition Aor.cxx:228
Data & scheme()
Definition Aor.cxx:192
bool operator==(const Aor &other) const
Definition Aor.cxx:129
bool operator<(const Aor &other) const
Definition Aor.cxx:141
An iostream that operates on an existing Data.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
bool empty() const noexcept
Checks whether the Data is empty.
Definition Data.hxx:591
Data & lowercase()
Converts this Data to lowercase.
Definition Data.cxx:1635
size_type size() const noexcept
Returns the number of bytes in this Data.
Definition Data.hxx:599
void reserve(size_type capacity)
Guarantees that the underlying buffer used by the Data is at least the number of bytes specified.
Definition Data.cxx:1049
static bool isIpV6Address(const Data &ipAddress)
Definition DnsUtil.cxx:386
static Data canonicalizeIpV6Address(const Data &ipV6Address)
Converts the printable form of an IPv6 address into consistent format so that string comparisons will...
Definition DnsUtil.cxx:427
Provides string-parsing functionality with protection from buffer overflow.
CurrentPosition skipWhitespace()
CurrentPosition skipToChar(char c)
CurrentPosition position() const
void reset(const char *pos)
void assertNotEof() const
CurrentPosition skipToOneOf(const char *cs)
CurrentPosition skipChar()
void data(Data &data, const char *start) const
make the passed in data share memory with the buffer (uses Data::Share)
static const char * Whitespace
static const char * SEMI_COLON
Definition Symbols.hxx:30
static const char * Tel
Definition Symbols.hxx:64
static const char * Urn
Definition Symbols.hxx:65
static const char * COLON
Definition Symbols.hxx:15
static const char * AT_SIGN
Definition Symbols.hxx:14
static const char * RA_QUOTE
Definition Symbols.hxx:28
Represents the "SIP-URI" and "SIPS-URI" elements in the RFC 3261 grammar.
Definition Uri.hxx:22
dcm! – add UnusedChecking(_enum) below;
bool isEqualNoCase(const Data &left, const Data &right)
Definition Data.hxx:1116
#define EncodeStream