reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
Uri.hxx
Go to the documentation of this file.
1#if !defined(RESIP_URI_HXX)
2#define RESIP_URI_HXX
3
4#include <bitset>
5#include "rutil/ResipAssert.h"
6
11
12namespace resip
13{
14class SipMessage;
15
21class Uri : public ParserCategory
22{
23 public:
25
26 static const size_t uriEncodingTableSize = 256;
27
28 Uri(PoolBase* pool=0);
29 Uri(const HeaderFieldValue& hfv, Headers::Type type, PoolBase* pool=0);
30 Uri(const Uri& orig,
31 PoolBase* pool=0);
32 explicit Uri(const Data& data);
33
34 ~Uri();
35
36 // convert from a tel scheme to sip scheme, adds user=phone param
37 //static Uri fromTel(const Uri&, const Data& host); // deprecate...
38 static Uri fromTel(const Uri&, const Uri& hostUri);
39
41 const Data& host() const {checkParsed(); return mHost;}
42 Data& user() {checkParsed(); return mUser;}
43 const Data& user() const {checkParsed(); return mUser;}
45 const Data& userParameters() const {checkParsed(); return mUserParameters;}
46 Data& opaque() {checkParsed(); return mHost;}
47 const Data& opaque() const {checkParsed(); return mHost;}
48 Data& path() {checkParsed(); return mPath;}
49 const Data& path() const {checkParsed(); return mPath;}
50
51 // Returns user@host[:port] (no scheme)
52 Data getAor() const;
53 // Returns user@host (no scheme or port)
54 Data getAorNoPort() const;
55
56 // Actually returns the AOR; <scheme>:<user>@<host>
58 {
59 return getAOR(false);
60 }
61
62 // Returns the AOR, optionally adding the port
63 Data getAOR(bool addPort) const;
64
65 //strips all paramters - if transport type is specified (ie. not UNKNOWN_TRANSPORT),
66 //and the default port for the transport is on the Aor, then it is removed
67 Uri getAorAsUri(TransportType transportTypeToRemoveDefaultPort = UNKNOWN_TRANSPORT) const;
68
69
78 bool userIsTelephoneSubscriber() const;
79
133
140 void setUserAsTelephoneSubscriber(const Token& telephoneSubscriber);
141
142
144 const Data& scheme() const {checkParsed(); return mScheme;}
145 int& port() {checkParsed(); return mPort;}
146 int port() const {checkParsed(); return mPort;}
148 const Data& password() const {checkParsed(); return mPassword;}
149
150 Data& netNs() {return(mNetNs);}
151 const Data& netNs() const {return(mNetNs);}
152
153 Data toString() const;
154
157 bool isEnumSearchable() const;
158
160 std::vector<Data> getEnumLookups(const std::vector<Data>& suffixes) const;
161
163 static void setUriUserEncoding(unsigned char c, bool encode);
164 static void setUriPasswordEncoding(unsigned char c, bool encode);
165 static void setUriUrnEncoding(unsigned char c, bool encode);
166
167 bool hasEmbedded() const;
169 const SipMessage& embedded() const;
170
171 void removeEmbedded();
172
173 virtual void parse(ParseBuffer& pb);
174 virtual ParserCategory* clone() const;
175 virtual ParserCategory* clone(void* location) const;
176 virtual ParserCategory* clone(PoolBase* pool) const;
177 virtual EncodeStream& encodeParsed(EncodeStream& str) const;
178
179 // parse the headers into this as SipMessage
182
183 Uri& operator=(const Uri& rhs);
184 bool operator==(const Uri& other) const;
185 bool operator!=(const Uri& other) const;
186 bool operator<(const Uri& other) const;
187
188 bool aorEqual(const Uri& rhs) const;
189 void setIsBetweenAngleQuotes(bool value) { mIsBetweenAngleQuotes = value; }
190
205 void setIsBareAddrSpec(bool value) { mIsBareAddrSpec = value; }
206
213 static bool compareUriParametersEqual(Parameter* param1, Parameter* param2);
214
223 static bool compareUriParametersLessThan(Parameter* param1, Parameter* param2);
224
233 static bool isSignificantUriParameter(const ParameterTypes::Type type) noexcept;
234
243 bool isUserRelevant() const;
244
245 typedef std::bitset<Uri::uriEncodingTableSize> EncodingTable;
246
248 {
249 static EncodingTable userEncodingTable(
250 Data::toBitset("abcdefghijklmnopqrstuvwxyz"
251 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
252 "0123456789"
253 "-_.!~*\\()&=+$,;?/").flip());
254 return userEncodingTable;
255 }
256
258 {
259 static EncodingTable passwordEncodingTable(
260 Data::toBitset("abcdefghijklmnopqrstuvwxyz"
261 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
262 "0123456789"
263 "-_.!~*\\()&=+$").flip());
264 return passwordEncodingTable;
265 }
266
274 {
275 static EncodingTable urnEncodingTable(
276 Data::toBitset("abcdefghijklmnopqrstuvwxyz"
277 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
278 "0123456789"
279 "-._~" // unreserved
280 "!$&'()*+,;=" // sub-delims
281 ":@" // pchar extras
282 "/" // NSS = pchar *(pchar / "/")
283 "?#").flip()); // rq-components / fragment markers
284 return urnEncodingTable;
285 }
286
288 {
289 // ?bwc? 'p' and 'w' are allowed in 2806, but have been removed in
290 // 3966. Should we support these or not?
291 static EncodingTable localNumberTable(
292 Data::toBitset("*#-.()0123456789ABCDEFpw"));
293 return localNumberTable;
294 }
295
297 {
298 static EncodingTable globalNumberTable(
299 Data::toBitset("-.()0123456789"));
300 return globalNumberTable;
301 }
302
303 // Inform the compiler that overloads of these may be found in
304 // ParserCategory, too.
308
309 virtual Parameter* createParam(ParameterTypes::Type type, ParseBuffer& pb, const std::bitset<256>& terminators, PoolBase* pool);
310 bool exists(const Param<Uri>& paramType) const;
311 void remove(const Param<Uri>& paramType);
312
313#define defineParam(_enum, _name, _type, _RFC_ref_ignored) \
314 const _enum##_Param::DType& param(const _enum##_Param& paramType) const; \
315 _enum##_Param::DType& param(const _enum##_Param& paramType); \
316 friend class _enum##_Param
317
318 defineParam(ob,"ob",ExistsParameter,"RFC 5626");
319 defineParam(gr, "gr", ExistsOrDataParameter, "RFC 5627");
320 defineParam(comp, "comp", DataParameter, "RFC 3486");
321 defineParam(duration, "duration", UInt32Parameter, "RFC 4240");
322 defineParam(lr, "lr", ExistsParameter, "RFC 3261");
323 defineParam(maddr, "maddr", DataParameter, "RFC 3261");
324 defineParam(method, "method", DataParameter, "RFC 3261");
325 defineParam(transport, "transport", DataParameter, "RFC 3261");
326 defineParam(ttl, "ttl", UInt32Parameter, "RFC 3261");
327 defineParam(user, "user", DataParameter, "RFC 3261, 4967");
328 defineParam(extension, "ext", DataParameter, "RFC 3966"); // Token is used when ext is a user-parameter
329 defineParam(sigcompId, "sigcomp-id", QuotedDataParameter, "RFC 5049");
330 defineParam(rinstance, "rinstance", DataParameter, "proprietary (resip)");
331 defineParam(addTransport, "addTransport", ExistsParameter, "RESIP INTERNAL");
332 defineParam(wsSrcIp, "ws-src-ip", DataParameter, "RESIP INTERNAL (WebSocket)");
333 defineParam(wsSrcPort, "ws-src-port", UInt32Parameter, "RESIP INTERNAL (WebSocket)");
334
335#undef defineParam
336
337 protected:
342 int mPort;
346
347 void getAorInternal(bool dropScheme, bool addPort, Data& aor) const;
348 mutable bool mHostCanonicalized;
350
353
354 private:
355 std::unique_ptr<Data> mEmbeddedHeadersText;
356 std::unique_ptr<SipMessage> mEmbeddedHeaders;
357 // As-received user-part bytes, kept only when the user part contains a
358 // percent-escape, so that escaping is preserved verbatim on re-encode.
359 std::unique_ptr<Data> mUserRaw;
360
362
373 static const bool tablesMightBeInitialized;
374
375};
376
377}
378
379#include "rutil/HashMap.hxx"
380
382
383#endif
384
385/* ====================================================================
386 * The Vovida Software License, Version 1.0
387 *
388 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
389 *
390 * Redistribution and use in source and binary forms, with or without
391 * modification, are permitted provided that the following conditions
392 * are met:
393 *
394 * 1. Redistributions of source code must retain the above copyright
395 * notice, this list of conditions and the following disclaimer.
396 *
397 * 2. Redistributions in binary form must reproduce the above copyright
398 * notice, this list of conditions and the following disclaimer in
399 * the documentation and/or other materials provided with the
400 * distribution.
401 *
402 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
403 * and "Vovida Open Communication Application Library (VOCAL)" must
404 * not be used to endorse or promote products derived from this
405 * software without prior written permission. For written
406 * permission, please contact vocal@vovida.org.
407 *
408 * 4. Products derived from this software may not be called "VOCAL", nor
409 * may "VOCAL" appear in their name, without prior written
410 * permission of Vovida Networks, Inc.
411 *
412 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
413 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
414 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
415 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
416 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
417 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
418 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
419 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
420 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
421 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
422 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
423 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
424 * DAMAGE.
425 *
426 * ====================================================================
427 *
428 * This software consists of voluntary contributions made by Vovida
429 * Networks, Inc. and many individuals on behalf of Vovida Networks,
430 * Inc. For more information on Vovida Networks, Inc., please see
431 * <http://www.vovida.org/>.
432 *
433 */
Wraps your platform's implementation of hash_map, hash_multimap, and hash_set.
#define HashValue(type)
Definition HashMap.hxx:18
Generically represents miscellaneous parameter data.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
static std::bitset< 256 > toBitset(const resip::Data &chars)
Creates a bitset reflecting the contents of this data (as a set) ie.
Definition Data.cxx:2477
Represents various parameters that are indicated to be in effect merely by being present,...
void checkParsed() const
Parameter *(* Factory)(ParameterTypes::Type, ParseBuffer &, const std::bitset< 256 > &terminators, PoolBase *pool)
Provides string-parsing functionality with protection from buffer overflow.
Base class for all SIP grammar elements that can have parameters.
void remove(const ParamBase &paramType)
Removes a natively supported parameter, if the parameter is present.
bool exists(const ParamBase &paramType) const
Checks for the existence of a natively supported parameter.
const Data & param(const ExtensionParameter &param) const
Const accessor for non-natively-supported parameter types.
Generically represents miscellaneous parameter data that is encoded using double quotes.
Represents a SIP message.
Represents the "token" element in the RFC 3261 grammar.
Definition Token.hxx:18
Generically represents unsigned 32-bit integer values conveyed by SIP parameters.
Represents the "SIP-URI" and "SIPS-URI" elements in the RFC 3261 grammar.
Definition Uri.hxx:22
static EncodingTable & getGlobalNumberTable()
Definition Uri.hxx:296
int port() const
Definition Uri.hxx:146
virtual EncodeStream & encodeParsed(EncodeStream &str) const
Definition Uri.cxx:1496
static bool compareUriParametersEqual(Parameter *param1, Parameter *param2)
Compares two known URI parameters for equality.
Definition Uri.cxx:435
bool mHostCanonicalized
Definition Uri.hxx:348
static const size_t uriEncodingTableSize
Definition Uri.hxx:26
const Data & user() const
Definition Uri.hxx:43
defineParam(ttl, "ttl", UInt32Parameter, "RFC 3261")
bool aorEqual(const Uri &rhs) const
Definition Uri.cxx:877
const Data & password() const
Definition Uri.hxx:148
Token getUserAsTelephoneSubscriber() const
Returns the user-part as a 'telephone-subscriber' grammar element (in other words,...
Definition Uri.cxx:1060
static void setUriUrnEncoding(unsigned char c, bool encode)
Definition Uri.cxx:1489
const Data & userParameters() const
Definition Uri.hxx:45
Data getAor() const
Definition Uri.cxx:1095
bool isEnumSearchable() const
Returns true if the uri can be converted into a string that can be used as an enum lookup.
Definition Uri.cxx:265
void parseEmbeddedHeaders(ParseBuffer &pb)
Definition Uri.cxx:1611
virtual void parse(ParseBuffer &pb)
Definition Uri.cxx:1176
bool mIsBareAddrSpec
Definition Uri.hxx:352
Data mUser
Definition Uri.hxx:340
Data & password()
Definition Uri.hxx:147
defineParam(duration, "duration", UInt32Parameter, "RFC 4240")
RESIP_HeapCount(Uri)
virtual Parameter * createParam(ParameterTypes::Type type, ParseBuffer &pb, const std::bitset< 256 > &terminators, PoolBase *pool)
Definition Uri.cxx:1691
void setIsBareAddrSpec(bool value)
Tells the parser this URI is being parsed as a bare (unbracketed) addr-spec inside a header value (e....
Definition Uri.hxx:205
bool isUserRelevant() const
Checks if this URI's scheme has sip:/sips:/tel: user-part semantics, i.e.
Definition Uri.cxx:528
void setIsBetweenAngleQuotes(bool value)
Definition Uri.hxx:189
defineParam(addTransport, "addTransport", ExistsParameter, "RESIP INTERNAL")
defineParam(method, "method", DataParameter, "RFC 3261")
defineParam(gr, "gr", ExistsOrDataParameter, "RFC 5627")
defineParam(comp, "comp", DataParameter, "RFC 3486")
SipMessage & embedded()
Definition Uri.cxx:1586
std::vector< Data > getEnumLookups(const std::vector< Data > &suffixes) const
Return a vector of domains to do a NAPTR lookup for enum.
Definition Uri.cxx:318
defineParam(user, "user", DataParameter, "RFC 3261, 4967")
const Data & scheme() const
Definition Uri.hxx:144
bool mIsBetweenAngleQuotes
Definition Uri.hxx:351
static EncodingTable & getPasswordEncodingTable()
Definition Uri.hxx:257
Data mPath
Definition Uri.hxx:345
Data getAorNoPort() const
Definition Uri.cxx:1087
int & port()
Definition Uri.hxx:145
Data & scheme()
Definition Uri.hxx:143
void removeEmbedded()
Definition Uri.cxx:350
Data toString() const
Definition Uri.cxx:1678
bool operator<(const Uri &other) const
Definition Uri.cxx:708
defineParam(wsSrcPort, "ws-src-port", UInt32Parameter, "RESIP INTERNAL (WebSocket)")
bool hasEmbedded() const
Definition Uri.cxx:343
Data getAOR(bool addPort) const
Definition Uri.cxx:999
Data mCanonicalHost
cache for IPv6 host comparison
Definition Uri.hxx:349
Data mScheme
Definition Uri.hxx:338
bool exists(const Param< Uri > &paramType) const
Definition Uri.cxx:1701
Data & opaque()
Definition Uri.hxx:46
EncodeStream & encodeEmbeddedHeaders(EncodeStream &str) const
Definition Uri.cxx:1663
Data mNetNs
Net namespace name scoping host and port.
Definition Uri.hxx:344
Data getAorNoReally() const
Definition Uri.hxx:57
const Data & host() const
Definition Uri.hxx:41
static void setUriPasswordEncoding(unsigned char c, bool encode)
Definition Uri.cxx:1484
static bool compareUriParametersLessThan(Parameter *param1, Parameter *param2)
Compares two URI parameters to determine if the first is less than the second.
Definition Uri.cxx:477
Data mUserParameters
Definition Uri.hxx:341
Data & netNs()
Definition Uri.hxx:150
int mPort
Definition Uri.hxx:342
std::bitset< Uri::uriEncodingTableSize > EncodingTable
Definition Uri.hxx:245
Uri & operator=(const Uri &rhs)
Definition Uri.cxx:358
static EncodingTable & getUserEncodingTable()
Definition Uri.hxx:247
static EncodingTable & getUrnEncodingTable()
Encoding table for the NID:NSS (plus optional rq-components/fragment) of a urn: URI (RFC 8141: namest...
Definition Uri.hxx:273
defineParam(rinstance, "rinstance", DataParameter, "proprietary (resip)")
Data & user()
Definition Uri.hxx:42
defineParam(ob,"ob", ExistsParameter,"RFC 5626")
void getAorInternal(bool dropScheme, bool addPort, Data &aor) const
Definition Uri.cxx:915
static Uri fromTel(const Uri &, const Uri &hostUri)
Definition Uri.cxx:184
Data mPassword
Definition Uri.hxx:343
defineParam(extension, "ext", DataParameter, "RFC 3966")
const Data & netNs() const
Definition Uri.hxx:151
void remove(const Param< Uri > &paramType)
Definition Uri.cxx:1709
bool userIsTelephoneSubscriber() const
Returns true if the user appears to fit the BNF for the 'telephone-subscriber' element in the RFC 326...
Definition Uri.cxx:1007
Data mHost
Definition Uri.hxx:339
const Data & path() const
Definition Uri.hxx:49
static EncodingTable & getLocalNumberTable()
Definition Uri.hxx:287
Data & host()
Definition Uri.hxx:40
virtual ParserCategory * clone() const
Definition Uri.cxx:1462
static void setUriUserEncoding(unsigned char c, bool encode)
Modifies the default URI encoding character sets.
Definition Uri.cxx:1479
Data & userParameters()
Definition Uri.hxx:44
bool operator==(const Uri &other) const
Definition Uri.cxx:537
defineParam(wsSrcIp, "ws-src-ip", DataParameter, "RESIP INTERNAL (WebSocket)")
defineParam(maddr, "maddr", DataParameter, "RFC 3261")
Uri getAorAsUri(TransportType transportTypeToRemoveDefaultPort=UNKNOWN_TRANSPORT) const
Definition Uri.cxx:1103
static bool isSignificantUriParameter(const ParameterTypes::Type type) noexcept
Checks if the URI-parameter appearing in only one URI must not be ignored when comparing the URIs.
Definition Uri.cxx:519
defineParam(lr, "lr", ExistsParameter, "RFC 3261")
void setUserAsTelephoneSubscriber(const Token &telephoneSubscriber)
Sets the user-part of this URI using the dial-string and parameters stored in telephoneSubscriber.
Definition Uri.cxx:1078
defineParam(sigcompId, "sigcomp-id", QuotedDataParameter, "RFC 5049")
bool operator!=(const Uri &other) const
Definition Uri.cxx:702
const Data & opaque() const
Definition Uri.hxx:47
Data & path()
Definition Uri.hxx:48
defineParam(transport, "transport", DataParameter, "RFC 3261")
dcm! – add UnusedChecking(_enum) below;
TransportType
An enumeration of transport protocols.
@ UNKNOWN_TRANSPORT
static char * encode(char *buf, const char *data, unsigned int length)
Definition Stun.cxx:645
#define EncodeStream