/[resiprocate]/main/resip/stack/Uri.hxx
ViewVC logotype

Contents of /main/resip/stack/Uri.hxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11153 - (show annotations) (download)
Wed Apr 23 17:25:02 2014 UTC (5 years, 9 months ago) by dpetrie
File MIME type: text/plain
File size: 14060 byte(s)
added netns scope/context to Uri and Tuple

1 #if !defined(RESIP_URI_HXX)
2 #define RESIP_URI_HXX
3
4 #include <bitset>
5 #include <cassert>
6
7 #include "resip/stack/ParserCategory.hxx"
8 #include "resip/stack/Token.hxx"
9 #include "rutil/TransportType.hxx"
10 #include "rutil/HeapInstanceCounter.hxx"
11
12 namespace resip
13 {
14 class SipMessage;
15
16 /**
17 @ingroup sip_grammar
18 @brief Represents the "SIP-URI" and "SIPS-URI" elements in the RFC 3261
19 grammar. Also can be made to represent other URI types (like tel URIs)
20 */
21 class Uri : public ParserCategory
22 {
23 public:
24 RESIP_HeapCount(Uri);
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
40 Data& host() {checkParsed(); mHostCanonicalized=false; return mHost;}
41 const Data& host() const {checkParsed(); return mHost;}
42 Data& user() {checkParsed(); return mUser;}
43 const Data& user() const {checkParsed(); return mUser;}
44 Data& userParameters() {checkParsed(); return mUserParameters;}
45 const Data& userParameters() const {checkParsed(); return mUserParameters;}
46 Data& opaque() {checkParsed(); return mHost;}
47 const Data& opaque() const {checkParsed(); return mHost;}
48
49 // Returns user@host[:port] (no scheme)
50 Data getAor() const;
51 // Returns user@host (no scheme or port)
52 Data getAorNoPort() const;
53
54 // Actually returns the AOR; <scheme>:<user>@<host>
55 Data getAorNoReally() const
56 {
57 return getAOR(false);
58 }
59
60 // Returns the AOR, optionally adding the port
61 Data getAOR(bool addPort) const;
62
63 //strips all paramters - if transport type is specified (ie. not UNKNOWN_TRANSPORT),
64 //and the default port for the transport is on the Aor, then it is removed
65 Uri getAorAsUri(TransportType transportTypeToRemoveDefaultPort = UNKNOWN_TRANSPORT) const;
66
67
68 /**
69 Returns true if the user appears to fit the BNF for the
70 'telephone-subscriber' element in the RFC 3261 (and by extension, RFC
71 3966) grammar. This is important because 'telephone-subscriber' can
72 have parameters, which you could then access easily through the
73 getUserAsTelephoneSubscriber() and setUserAsTelephoneSubscriber()
74 calls.
75 */
76 bool userIsTelephoneSubscriber() const;
77
78 /**
79 Returns the user-part as a 'telephone-subscriber' grammar element (in
80 other words, this parses the user-part into a dial string and
81 parameters, with the dial-string accessible with Token::value(), and
82 the parameters accessible with the various Token::param() and
83 Token::exists() interfaces).
84
85 For example, suppose the following is in the Request-URI:
86
87 sip:5555551234;phone-context=+86\@example.com;user=dialstring
88
89 The user-part of this SIP URI is "5555551234;phone-context=+86", and it
90 fits the BNF for the 'telephone-subscriber' grammar element. To access
91 the 'phone-context' parameter, do something like the following:
92
93 @code
94 Uri& reqUri(sip.header(h_RequestLine).uri());
95
96 // !bwc! May add native support for this param later
97 static ExtensionParameter p_phoneContext("phone-context");
98 Data phoneContextValue;
99
100 if(reqUri.isWellFormed())
101 {
102 if(reqUri.exists(p_phoneContext))
103 {
104 // Phone context as URI param
105 phoneContextValue=reqUri.param(p_phoneContext);
106 }
107 else if(reqUri.scheme()=="sip" || reqUri.scheme()=="sips")
108 {
109 // Might have phone-context as a user param (only happens
110 // in a sip or sips URI)
111 // Technically, this userIsTelephoneSubscriber() check is
112 // required:
113 // sip:bob;phone-context=+86@example.com doesn't have a
114 // phone-context param according to the BNF in 3261. But,
115 // interop may require you to parse this as if it did have
116 // such a param.
117 if(reqUri.userIsTelephoneSubscriber())
118 {
119 Token telSub(reqUri.getUserAsTelephoneSubscriber());
120 if(telSub.isWellFormed() && telSub.exists(p_phoneContext))
121 {
122 // Phone context as user param
123 phoneContextValue=telSub.param(p_phoneContext);
124 }
125 }
126 }
127 }
128 @endcode
129 */
130 Token getUserAsTelephoneSubscriber() const;
131
132 /**
133 Sets the user-part of this URI using the dial-string and parameters
134 stored in telephoneSubscriber.
135 @param telephoneSubscriber The user-part, as a 'telephone-subscriber'
136 grammar element.
137 */
138 void setUserAsTelephoneSubscriber(const Token& telephoneSubscriber);
139
140
141 Data& scheme() {checkParsed(); return mScheme;}
142 const Data& scheme() const {checkParsed(); return mScheme;}
143 int& port() {checkParsed(); return mPort;}
144 int port() const {checkParsed(); return mPort;}
145 Data& password() {checkParsed(); return mPassword;}
146 const Data& password() const {checkParsed(); return mPassword;}
147
148 Data& netNs() {return(mNetNs);}
149 const Data& netNs() const {return(mNetNs);}
150
151 Data toString() const;
152
153 /** Returns true if the uri can be converted into a string that can be
154 used as an enum lookup */
155 bool isEnumSearchable() const;
156
157 /** Return a vector of domains to do a NAPTR lookup for enum */
158 std::vector<Data> getEnumLookups(const std::vector<Data>& suffixes) const;
159
160 /** Modifies the default URI encoding character sets */
161 static void setUriUserEncoding(unsigned char c, bool encode);
162 static void setUriPasswordEncoding(unsigned char c, bool encode);
163
164 bool hasEmbedded() const;
165 SipMessage& embedded();
166 const SipMessage& embedded() const;
167
168 void removeEmbedded();
169
170 virtual void parse(ParseBuffer& pb);
171 virtual ParserCategory* clone() const;
172 virtual ParserCategory* clone(void* location) const;
173 virtual ParserCategory* clone(PoolBase* pool) const;
174 virtual EncodeStream& encodeParsed(EncodeStream& str) const;
175
176 // parse the headers into this as SipMessage
177 void parseEmbeddedHeaders(ParseBuffer& pb);
178 EncodeStream& encodeEmbeddedHeaders(EncodeStream& str) const;
179
180 Uri& operator=(const Uri& rhs);
181 bool operator==(const Uri& other) const;
182 bool operator!=(const Uri& other) const;
183 bool operator<(const Uri& other) const;
184
185 bool aorEqual(const Uri& rhs) const;
186
187 typedef std::bitset<Uri::uriEncodingTableSize> EncodingTable;
188
189 static EncodingTable& getUserEncodingTable()
190 {
191 static EncodingTable userEncodingTable(
192 Data::toBitset("abcdefghijklmnopqrstuvwxyz"
193 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
194 "0123456789"
195 "-_.!~*\\()&=+$,;?/").flip());
196 return userEncodingTable;
197 }
198
199 static EncodingTable& getPasswordEncodingTable()
200 {
201 static EncodingTable passwordEncodingTable(
202 Data::toBitset("abcdefghijklmnopqrstuvwxyz"
203 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
204 "0123456789"
205 "-_.!~*\\()&=+$").flip());
206 return passwordEncodingTable;
207 }
208
209 static EncodingTable& getLocalNumberTable()
210 {
211 // ?bwc? 'p' and 'w' are allowed in 2806, but have been removed in
212 // 3966. Should we support these or not?
213 static EncodingTable localNumberTable(
214 Data::toBitset("*#-.()0123456789ABCDEFpw"));
215 return localNumberTable;
216 }
217
218 static EncodingTable& getGlobalNumberTable()
219 {
220 static EncodingTable globalNumberTable(
221 Data::toBitset("-.()0123456789"));
222 return globalNumberTable;
223 }
224
225 // Inform the compiler that overloads of these may be found in
226 // ParserCategory, too.
227 using ParserCategory::exists;
228 using ParserCategory::remove;
229 using ParserCategory::param;
230
231 virtual Parameter* createParam(ParameterTypes::Type type, ParseBuffer& pb, const std::bitset<256>& terminators, PoolBase* pool);
232 bool exists(const Param<Uri>& paramType) const;
233 void remove(const Param<Uri>& paramType);
234
235 #define defineParam(_enum, _name, _type, _RFC_ref_ignored) \
236 const _enum##_Param::DType& param(const _enum##_Param& paramType) const; \
237 _enum##_Param::DType& param(const _enum##_Param& paramType); \
238 friend class _enum##_Param
239
240 defineParam(ob,"ob",ExistsParameter,"RFC 5626");
241 defineParam(gr, "gr", ExistsOrDataParameter, "RFC 5627");
242 defineParam(comp, "comp", DataParameter, "RFC 3486");
243 defineParam(duration, "duration", UInt32Parameter, "RFC 4240");
244 defineParam(lr, "lr", ExistsParameter, "RFC 3261");
245 defineParam(maddr, "maddr", DataParameter, "RFC 3261");
246 defineParam(method, "method", DataParameter, "RFC 3261");
247 defineParam(transport, "transport", DataParameter, "RFC 3261");
248 defineParam(ttl, "ttl", UInt32Parameter, "RFC 3261");
249 defineParam(user, "user", DataParameter, "RFC 3261, 4967");
250 defineParam(extension, "ext", DataParameter, "RFC 3966"); // Token is used when ext is a user-parameter
251 defineParam(sigcompId, "sigcomp-id", QuotedDataParameter, "RFC 5049");
252 defineParam(rinstance, "rinstance", DataParameter, "proprietary (resip)");
253 defineParam(addTransport, "addTransport", ExistsParameter, "RESIP INTERNAL");
254 defineParam(wsSrcIp, "ws-src-ip", DataParameter, "RESIP INTERNAL (WebSocket)");
255 defineParam(wsSrcPort, "ws-src-port", UInt32Parameter, "RESIP INTERNAL (WebSocket)");
256
257 #undef defineParam
258
259 protected:
260 Data mScheme;
261 // .bwc. I don't like this.
262 mutable Data mHost;
263 Data mUser;
264 Data mUserParameters;
265 int mPort;
266 Data mPassword;
267 Data mNetNs; ///< Net namespace name scoping host and port
268
269 void getAorInternal(bool dropScheme, bool addPort, Data& aor) const;
270 mutable bool mHostCanonicalized;
271
272 private:
273 std::auto_ptr<Data> mEmbeddedHeadersText;
274 std::auto_ptr<SipMessage> mEmbeddedHeaders;
275
276 static ParameterTypes::Factory ParameterFactories[ParameterTypes::MAX_PARAMETER];
277
278 /**
279 Dummy static initialization variable, for ensuring that the encoding
280 tables are initialized sometime during static initialization,
281 preventing the scenario where multiple threads try to runtime init the
282 same table at the same time.
283 @note Prior to static initialization of this bool, it could be either
284 true or false; you should not be using this variable to check
285 whether the tables are initialized. Just call the getXTable()
286 accessor function; it will init the table if it is not already.
287 */
288 static const bool tablesMightBeInitialized;
289
290 };
291
292 }
293
294 #include "rutil/HashMap.hxx"
295
296 HashValue(resip::Uri);
297
298 #endif
299
300 /* ====================================================================
301 * The Vovida Software License, Version 1.0
302 *
303 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
304 *
305 * Redistribution and use in source and binary forms, with or without
306 * modification, are permitted provided that the following conditions
307 * are met:
308 *
309 * 1. Redistributions of source code must retain the above copyright
310 * notice, this list of conditions and the following disclaimer.
311 *
312 * 2. Redistributions in binary form must reproduce the above copyright
313 * notice, this list of conditions and the following disclaimer in
314 * the documentation and/or other materials provided with the
315 * distribution.
316 *
317 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
318 * and "Vovida Open Communication Application Library (VOCAL)" must
319 * not be used to endorse or promote products derived from this
320 * software without prior written permission. For written
321 * permission, please contact vocal@vovida.org.
322 *
323 * 4. Products derived from this software may not be called "VOCAL", nor
324 * may "VOCAL" appear in their name, without prior written
325 * permission of Vovida Networks, Inc.
326 *
327 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
328 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
329 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
330 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
331 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
332 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
333 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
334 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
335 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
336 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
337 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
338 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
339 * DAMAGE.
340 *
341 * ====================================================================
342 *
343 * This software consists of voluntary contributions made by Vovida
344 * Networks, Inc. and many individuals on behalf of Vovida Networks,
345 * Inc. For more information on Vovida Networks, Inc., please see
346 * <http://www.vovida.org/>.
347 *
348 */

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27