sipxtacklib  Version 3.3
Url.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006-2013 SIPez LLC. All rights reserved.
3 //
4 // Copyright (C) 2004-2006 SIPfoundry Inc.
5 // Licensed by SIPfoundry under the LGPL license.
6 //
7 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
8 // Licensed to SIPfoundry under a Contributor Agreement.
9 //
10 // $$
12 
13 
14 #ifndef _Url_h_
15 #define _Url_h_
16 
17 // SYSTEM INCLUDES
18 //#include <...>
19 
20 // APPLICATION INCLUDES
21 #include "utl/UtlDefs.h"
22 #include "utl/UtlString.h"
23 #include "utl/UtlRegex.h"
24 class UtlDList;
25 
26 // DEFINES
27 // MACROS
28 // EXTERNAL FUNCTIONS
29 // EXTERNAL VARIABLES
30 // CONSTANTS
31 // STRUCTS
32 // TYPEDEFS
33 // FORWARD DECLARATIONS
34 class NameValuePair ;
35 
37 
90 class Url
91 {
92 /* //////////////////////////// PUBLIC //////////////////////////////////// */
93 public:
94 
96  typedef enum
97  {
108  } Scheme;
118 /* ============================ CREATORS ================================== */
119 
121  Url(const char* urlString = NULL,
122  UtlBoolean isAddrSpec = FALSE
124  );
125 
127  Url(const Url& rUrl);
128 
130  virtual
131  ~Url();
132 
133 /* ============================ MANIPULATORS ============================== */
134 
136  Url& operator=(const Url& rhs);
137 
139 
142  Url& operator=(const char* urlString);
143 
145  void fromString(const UtlString& urlString,
146  UtlBoolean isAddrSpec = FALSE
147  );
149 
151  // as a field in a header.
152  void toString(UtlString& urlString) const;
153 
155  // as a field in a header.
156  UtlString toString() const;
157 
159  void dump();
160 
162  void reset();
163 
165  void removeParameters();
166 
167 /* ============================ ACCESSORS ================================= */
168 
170  void getIdentity(UtlString& identity) const;
179  void getUrlType(UtlString& urlProtocol) const;
187  void setUrlType(const char* urlProtocol);
190 
192  void getDisplayName(UtlString& displayName) const;
193 
195  void setDisplayName(const char* displayName);
196 
198  void getUserId(UtlString& userId) const;
199 
201  void setUserId(const char* userId);
202 
204  UtlBoolean getPassword(UtlString& userId) const;
205 
207  void setPassword(const char* userId);
220  void getHostAddress(UtlString& address) const;
222 
224  void getHostWithPort(UtlString& domain) const;
225 
227  void setHostAddress(const char* address);
228 
230  int getHostPort() const;
231 
233  void setHostPort(int port);
234 
236  UtlBoolean getPath(UtlString& path,
237  UtlBoolean getStyle = FALSE
243  );
244 
245 
247  void setPath(const char* path);
250  UtlBoolean getUrlParameter(const char* name,
252  UtlString& value,
253  int index = 0
254  );
261  UtlBoolean getUrlParameter(int urlIndex,
264  UtlString& name,
265  UtlString& value
266  );
269 
275  void setUrlParameter(const char* name, const char* value);
276 
278  void removeUrlParameters();
279 
281  void removeUrlParameter(const char* name);
282 
284 
296  UtlBoolean getUrlParameters(int iMaxReturn,
297  UtlString *pNames,
298  UtlString *pValues,
299  int& iActualReturn);
300 
302 
308  UtlBoolean getHeaderParameter(const char* name,
309  UtlString& value,
310  int index = 0);
311 
313 
319  UtlBoolean getHeaderParameter(int headerIndex,
320  UtlString& headerName,
321  UtlString& headerValue);
322 
324  void setHeaderParameter(const char* name,
325  const char* value
326  );
337  void removeHeaderParameters();
339 
341  void removeHeaderParameter(const char* name);
342 
344 
356  UtlBoolean getHeaderParameters(int iMaxReturn, UtlString *pNames, UtlString *pValues, int& iActualReturn);
357 
358 
360 
366  UtlBoolean getFieldParameter(const char* name,
367  UtlString& value,
368  int index = 0) const;
369 
372 
378  UtlBoolean getFieldParameter(int fieldIndex,
379  UtlString& name,
380  UtlString& value);
381 
383 
388  void setFieldParameter(const char* name,
389  const char* value);
390 
392  void removeFieldParameters();
393 
395  void removeFieldParameter(const char* name);
396 
398 
409  UtlBoolean getFieldParameters(int iMaxReturn,
410  UtlString *pNames,
411  UtlString *pValues,
412  int& iActualReturn);
413 
416  void includeAngleBrackets();
417 
419  void removeAngleBrackets();
426  static void gen_value_escape(UtlString& escapedText);
428 
430  static void gen_value_unescape(UtlString& escapedText);
431 
433  void getUri(UtlString& Uri);
434 
435 /* ============================ INQUIRY =================================== */
436 
438 
442  static UtlBoolean isDigitString(const char* dialedCharacters);
443 
445  UtlBoolean isUserHostPortEqual(const Url& uri,
446  int impliedPort = PORT_NONE
447  ) const ;
482  UtlBoolean isUserHostEqual(const Url& uri) const ;
489  UtlBoolean isIncludeAngleBracketsSet() const ;
498  Scheme scheme( const UtlString& schemeName );
500 
502  const char* schemeName( Scheme scheme );
503 
505  Scheme getScheme() const;
506 
508  void setScheme(Scheme scheme);
509 
510 
511 /* //////////////////////////// PROTECTED ///////////////////////////////// */
512 protected:
513 
514 /* //////////////////////////// PRIVATE /////////////////////////////////// */
515 private:
517  void parseString(const char* urlString,
518  UtlBoolean isAddrSpec = FALSE
521  );
522 
523  Scheme mScheme;
524 
525  UtlString mDisplayName;
526  UtlString mUserId;
527  UtlString mPassword;
528  UtlBoolean mPasswordSet;
529  UtlString mHostAddress;
530  int mHostPort;
531  UtlString mPath;
532 
533  UtlString mRawUrlParameters;
534  bool parseUrlParameters();//< lazy parser for url parameters
535  UtlDList* mpUrlParameters;
536 
537  UtlString mRawHeaderOrQueryParameters;
538  bool parseHeaderOrQueryParameters();//< lazy parser for header or query parameters
539  UtlDList* mpHeaderOrQueryParameters;
540 
541  UtlString mRawFieldParameters;
542  bool parseFieldParameters(); //< lazy parser for field parameters
543  UtlDList* mpFieldParameters;
544 
545  UtlBoolean mAngleBracketsIncluded;
546 };
547 
548 /* ============================ INLINE METHODS ============================ */
549 
550 #endif // _Url_h_
Scheme getScheme() const
Get the enumerator for the URL scheme type (more convenient than getUrlType).
Definition: Url.cpp:351
https: (RFC 2818)
Definition: Url.h:102
void includeAngleBrackets()
Forces the presence of angle brackets (i.e. <>) in the URL when serialized.
Definition: Url.cpp:1075
void reset()
Clear the contents of this URL.
Definition: Url.cpp:250
void removeFieldParameter(const char *name)
Removes all of the field parameters with the given name.
Definition: Url.cpp:1059
UtlBoolean getPassword(UtlString &userId) const
Get the users password if present in the URL.
Definition: Url.cpp:434
void setScheme(Scheme scheme)
Set the scheme to be used (also see setUrlType).
Definition: Url.cpp:361
Url(const char *urlString=NULL, UtlBoolean isAddrSpec=FALSE)
Default constructor from string.
Definition: Url.cpp:206
void getHostWithPort(UtlString &domain) const
Get the host and port together as a string "host:port".
Definition: Url.cpp:459
UtlBoolean getUrlParameters(int iMaxReturn, UtlString *pNames, UtlString *pValues, int &iActualReturn)
Gets all of the URL parameters and values.
Definition: Url.cpp:598
UtlBoolean getFieldParameter(const char *name, UtlString &value, int index=0) const
Get the named field parameter value.
Definition: Url.cpp:943
UtlBoolean isUserHostPortEqual(const Url &uri, int impliedPort=PORT_NONE) const
Compare two URLs to see if the have the same user, host and port.
Definition: Url.cpp:1562
void removeHeaderParameters()
Removes all of the header parameters.
Definition: Url.cpp:916
void dump()
Debug dump to STDOUT.
Definition: Url.cpp:1168
mailto: (RFC 2368)
Definition: Url.h:105
Url & operator=(const Url &rhs)
Assignment operator.
Definition: Url.cpp:268
void setPath(const char *path)
Set the file path.
Definition: Url.cpp:470
void getDisplayName(UtlString &displayName) const
Get the URL display name if present.
Definition: Url.cpp:390
UtlBoolean isIncludeAngleBracketsSet() const
Are angle brackets explicitly included.
Definition: Url.cpp:1234
void setHostPort(int port)
Set the URL host port.
Definition: Url.cpp:542
const char * schemeName(Scheme scheme)
Get the canonical (lowercase) name constant for a supported Scheme.
Definition: Url.cpp:1629
static UtlBoolean isDigitString(const char *dialedCharacters)
Is string all digits.
Definition: Url.cpp:1226
void removeParameters()
Remove all of the URL, header and field parameters and values.
Definition: Url.cpp:243
void setPassword(const char *userId)
Set the users password in the URL.
Definition: Url.cpp:440
void fromString(const UtlString &urlString, UtlBoolean isAddrSpec=FALSE)
set the value of this url by parsing the given string.
Definition: Url.cpp:218
Definition: Url.h:107
void setHeaderParameter(const char *name, const char *value)
Set the named header parameter to the given value.
Definition: Url.cpp:869
UtlBoolean getUrlParameter(const char *name, UtlString &value, int index=0)
Get the named URL parameter value.
Definition: Url.cpp:547
void setUrlType(const char *urlProtocol)
Set the URL application layer protocol using the scheme name string.
Definition: Url.cpp:366
void setHostAddress(const char *address)
Set the URL host name or IP address.
Definition: Url.cpp:529
UtlBoolean getFieldParameters(int iMaxReturn, UtlString *pNames, UtlString *pValues, int &iActualReturn)
Gets all of the Header parameters.
Definition: Url.cpp:994
invalid or unset scheme
Definition: Url.h:98
void setDisplayName(const char *displayName)
Set the URL display name.
Definition: Url.cpp:399
void removeHeaderParameter(const char *name)
Removes all of the header parameters with the given name.
Definition: Url.cpp:927
void removeAngleBrackets()
Remove the angle brackets (i.e. <>) from the URL.
Definition: Url.cpp:1080
Definition: NameValuePair.h:35
rtsp: (RFC 2326)
Definition: Url.h:106
UtlBoolean isUserHostEqual(const Url &uri) const
Compare two URLs to see if the have the same user and host.
Definition: Url.cpp:1584
Scheme
Identifiers for all supported URI schemes.
Definition: Url.h:96
UtlString toString() const
Serialize this URL to a string in name-addr format, suitable for use.
Definition: Url.cpp:1085
UtlBoolean getHeaderParameter(const char *name, UtlString &value, int index=0)
Get the named header parameter value.
Definition: Url.cpp:650
static void gen_value_unescape(UtlString &escapedText)
Un-escape a string as a gen_value, which is what field-parameters use for values. ...
Definition: Url.cpp:1695
void getUri(UtlString &Uri)
Gets the serialized URL as a string (with no display name or field parameters)
Definition: Url.cpp:739
sip: (RFC 3261)
Definition: Url.h:99
void getUserId(UtlString &userId) const
Get the URL user identity if present.
Definition: Url.cpp:417
void setUserId(const char *userId)
Set the URL user identity.
Definition: Url.cpp:422
void removeUrlParameter(const char *name)
Removes all of the URL parameters with the given name.
Definition: Url.cpp:723
void removeFieldParameters()
Removes all of the field parameters.
Definition: Url.cpp:1048
void getIdentity(UtlString &identity) const
Construct the cannonical identity.
Definition: Url.cpp:1592
void setFieldParameter(const char *name, const char *value)
Set the named field parameter to the given value.
Definition: Url.cpp:1024
UtlBoolean getHeaderParameters(int iMaxReturn, UtlString *pNames, UtlString *pValues, int &iActualReturn)
Gets all of the Header parameters.
Definition: Url.cpp:680
virtual ~Url()
Destructor.
Definition: Url.cpp:238
ftp: (RFC 1738)
Definition: Url.h:103
void removeUrlParameters()
Removes all of the URL parameters.
Definition: Url.cpp:709
file: (RFC 1738)
Definition: Url.h:104
http: (RFC 2616)
Definition: Url.h:101
Scheme scheme(const UtlString &schemeName)
Translate a scheme string (not including the terminating colon) to a Scheme enum. ...
Definition: Url.cpp:1611
static void gen_value_escape(UtlString &escapedText)
Escape a string as a gen_value, which is what field-parameters use for values.
Definition: Url.cpp:1782
URL parser and constructor.
Definition: Url.h:90
void getHostAddress(UtlString &address) const
Get the URL host name or IP address.
Definition: Url.cpp:454
void setUrlParameter(const char *name, const char *value)
Set the named URL parameter to the given value.
Definition: Url.cpp:626
int getHostPort() const
Get the URL host port.
Definition: Url.cpp:537
void getUrlType(UtlString &urlProtocol) const
Get the URL application layer protocol scheme string.
Definition: Url.cpp:356
sips: (RFC 3261)
Definition: Url.h:100
UtlBoolean getPath(UtlString &path, UtlBoolean getStyle=FALSE)
Get the file path from the URL.
Definition: Url.cpp:482

sipXtackLib home page