Logo ROOT   6.10/09
Reference Guide
TUri.h
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Gerhard E. Bruckner 15/07/07
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TUri
13 #define ROOT_TUri
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TUri //
19 // //
20 // This class represents a RFC3986 compatible URI. //
21 // See http://rfc.net/rfc3986.html. //
22 // It provides member functions to return the different parts of //
23 // an URI. //
24 // //
25 //////////////////////////////////////////////////////////////////////////
26 
27 #include "TObject.h"
28 #include "TString.h"
29 
30 
31 class TUri;
32 Bool_t operator==(const TUri &u1, const TUri &u2);
33 
34 
35 class TUri : public TObject {
36 
37 friend Bool_t operator==(const TUri &u1, const TUri &u2); // comparison operator
38 
39 private:
40 
41  // In order to represent the five basic components of an URI,
42  // we use 7 member variables (authority gets split in 3 parts)
43  //
44  // foo://user:pass@example.com:8042/over/there?name=ferret#nose
45  // \_/ \________________________/\_________/ \_________/ \__/
46  // | | | | |
47  // scheme authority path query fragment
48  //
49  // In many cases we have to distinguish between empty
50  // TString and undefined value (i.e. delimiter not found).
51  // Therefore, we use a TString to hold the string value
52  // and a corresponding Bool_t to store if it is defined or not.
53  // The Bool_t has precedence.
54 
56  TString fUserinfo; // authority/userinfo: user@password, ...
57  TString fHost; // authority/host: hostname or ip-address
58  TString fPort; // authority/port: port number, normally 1-65535
62 
70 
71 public:
72  TUri(const TUri &uri);
73  TUri() { Reset(); }
74  TUri(const TString &uri);
75  TUri(const char *uri);
76  TUri &operator=(const TUri &rhs); //copy ctor
77  virtual ~TUri() { }
78 
79  const TString GetUri() const;
80  const TString GetScheme() const { return fScheme; }
81  const TString GetHierPart() const;
82  const TString GetRelativePart() const;
83  const TString GetAuthority() const;
84  const TString GetUserInfo() const { return fUserinfo; }
85  const TString GetHost() const { return fHost; }
86  const TString GetPort() const { return fPort; }
87  const TString GetPath() const { return fPath; }
88  const TString GetQuery() const { return fQuery; }
89  const TString GetFragment() const { return fFragment; }
90 
91  Bool_t HasScheme() const { return fHasScheme; }
92  Bool_t HasHierPart() const { return IsHierPart(GetHierPart()); }
93  Bool_t HasAuthority() const { return fHasHost; }
94  Bool_t HasUserInfo() const { return fHasUserinfo; }
95  Bool_t HasHost() const { return fHasHost; }
96  Bool_t HasPort() const { return fHasPort; }
97  Bool_t HasPath() const { return fHasPath; }
98  Bool_t HasQuery() const { return fHasQuery; }
99  Bool_t HasFragment() const { return fHasFragment; }
101 
102  Bool_t SetUri(const TString &uri);
103  Bool_t SetScheme(const TString &scheme);
104  Bool_t SetHierPart(const TString &hier);
105  Bool_t SetAuthority(const TString &authority);
106  Bool_t SetUserInfo(const TString &userinfo);
107  Bool_t SetHost(const TString &host);
108  Bool_t SetPort(const TString &port);
109  Bool_t SetPath(const TString &path);
110  Bool_t SetQuery(const TString &path);
111  Bool_t SetFragment(const TString &fragment);
112 
114 
115  void Print(Option_t *option = "") const;
116  Bool_t IsSortable() const { return kTRUE; }
117 
118  void Normalise();
119  void Reset();
120 
121  Bool_t IsAbsolute() const;
122  Bool_t IsRelative() const;
123  Bool_t IsUri() const;
124  Bool_t IsReference() const;
125 
126  static Bool_t IsUnreserved(const TString &string);
127 
128  static const TString PctEncode(const TString &source);
129  static const TString PctDecode(const TString &source);
130  static const TString PctDecodeUnreserved(const TString &source);
131  static const TString PctNormalise(const TString &source);
132 
133  static Bool_t IsScheme(const TString&);
134  static Bool_t IsHierPart(const TString&);
135  static Bool_t IsAuthority(const TString&);
136  static Bool_t IsUserInfo(const TString&);
137  static Bool_t IsHost(const TString&);
138  static Bool_t IsIpv4(const TString&);
139  static Bool_t IsRegName(const TString&);
140  static Bool_t IsPort(const TString&);
141  static Bool_t IsPath(const TString&);
142  static Bool_t IsPathAbsolute(const TString&);
143  static Bool_t IsPathAbempty(const TString&);
144  static Bool_t IsPathNoscheme(const TString&);
145  static Bool_t IsPathRootless(const TString&);
146  static Bool_t IsPathEmpty(const TString&);
147  static Bool_t IsQuery(const TString&);
148  static Bool_t IsFragment(const TString&);
149 
150  static Bool_t IsRelativePart(const TString&);
151 
152  static const TString RemoveDotSegments(const TString&);
153 
154  static TUri Transform(const TUri &reference, const TUri &base);
155  static const TString MergePaths(const TUri &reference, const TUri &base);
156 
157  ClassDef(TUri, 1) //Represents an URI
158 };
159 
160 #endif
Bool_t IsUri() const
Returns kTRUE if instance qualifies as URI URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] ...
Definition: TUri.cxx:227
virtual ~TUri()
Definition: TUri.h:77
Bool_t fHasUserinfo
Definition: TUri.h:64
Bool_t IsAbsolute() const
Returns kTRUE if instance qualifies as absolute-URI absolute-URI = scheme ":" hier-part [ "...
Definition: TUri.cxx:207
static Bool_t IsIpv4(const TString &)
Returns kTRUE, if string holds a valid IPv4 address currently only decimal variant supported...
Definition: TUri.cxx:962
static Bool_t IsAuthority(const TString &)
Returns kTRUE if string qualifies as valid URI authority: authority = [ userinfo "@" ] host [ ":" p...
Definition: TUri.cxx:383
Bool_t SetPath(const TString &path)
Set path component of URI: path = path-abempty ; begins with "/" or is empty ...
Definition: TUri.cxx:481
static Bool_t IsRegName(const TString &)
Returns kTRUE if string qualifies as valid reg-name: reg-name = *( unreserved / pct-encoded / sub-...
Definition: TUri.cxx:950
const char Option_t
Definition: RtypesCore.h:62
void Normalise()
Syntax based normalisation according to RFC chapter 6.2.2.
Definition: TUri.cxx:985
Bool_t HasRelativePart() const
Definition: TUri.h:100
Bool_t SetHierPart(const TString &hier)
returns hier-part component of URI hier-part = "//" authority path-abempty / path-absol...
Definition: TUri.cxx:693
Bool_t fHasQuery
Definition: TUri.h:68
TString fUserinfo
Definition: TUri.h:56
Bool_t fHasScheme
Definition: TUri.h:63
const TString GetPort() const
Definition: TUri.h:86
static Bool_t IsUserInfo(const TString &)
Return kTRUE is string qualifies as valid URI userinfo: userinfo = *( unreserved / pct-encoded / s...
Definition: TUri.cxx:428
Bool_t HasAuthority() const
Definition: TUri.h:93
Bool_t SetUserInfo(const TString &userinfo)
Set userinfo component of URI: userinfo = *( unreserved / pct-encoded / sub-delims / ":" )...
Definition: TUri.cxx:405
Basic string class.
Definition: TString.h:129
Bool_t SetPort(const TString &port)
Set port component of URI: port = *DIGIT.
Definition: TUri.cxx:460
bool Bool_t
Definition: RtypesCore.h:59
This class represents a RFC 3986 compatible URI.
Definition: TUri.h:35
TString fPath
Definition: TUri.h:59
Bool_t fHasPort
Definition: TUri.h:66
static const TString PctDecode(const TString &source)
Percent-decode the given string according to chapter 2.1 we assume a valid pct-encoded string...
Definition: TUri.cxx:1086
Bool_t SetQuery(const TString &path)
Set query component of URI: query = *( pchar / "/" / "?" ).
Definition: TUri.cxx:298
const TString GetPath() const
Definition: TUri.h:87
TUri & operator=(const TUri &rhs)
TUri assignment operator.
Definition: TUri.cxx:89
static const TString PctDecodeUnreserved(const TString &source)
Percent-decode the given string according to chapter 2.1 we assume a valid pct-encoded string...
Definition: TUri.cxx:1012
Bool_t SetUri(const TString &uri)
Parse URI and set the member variables accordingly, returns kTRUE if URI validates, and kFALSE otherwise: URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] hier-part = "//" authority path-abempty / path-absolute / path-rootless / path-empty.
Definition: TUri.cxx:601
#define ClassDef(name, id)
Definition: Rtypes.h:297
TString fQuery
Definition: TUri.h:60
Bool_t IsRelative() const
Returns kTRUE if instance qualifies as relative-ref relative-ref = relative-part [ "...
Definition: TUri.cxx:217
const TString GetFragment() const
Definition: TUri.h:89
static const TString PctEncode(const TString &source)
Percent-encode and return the given string according to RFC 3986 in principle, this function cannot f...
Definition: TUri.cxx:815
Bool_t SetAuthority(const TString &authority)
Set authority part of URI: authority = [ userinfo "@" ] host [ ":" port ].
Definition: TUri.cxx:338
Bool_t HasFragment() const
Definition: TUri.h:99
static Bool_t IsPathNoscheme(const TString &)
Returns kTRUE if string qualifies as valid path-noscheme component: path-noscheme = segment-nz-nc *( ...
Definition: TUri.cxx:900
void Reset()
Initialize this URI object.
Definition: TUri.cxx:571
Bool_t fHasFragment
Definition: TUri.h:69
Bool_t SetScheme(const TString &scheme)
Set scheme component of URI: scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ).
Definition: TUri.cxx:248
const TString GetUri() const
Returns the whole URI - an implementation of chapter 5.3 component recomposition. ...
Definition: TUri.cxx:140
TString fScheme
Definition: TUri.h:55
static Bool_t IsPathEmpty(const TString &)
Returns kTRUE if string qualifies as valid path-empty component: path-empty = 0<pchar>.
Definition: TUri.cxx:926
Bool_t fHasPath
Definition: TUri.h:67
Bool_t HasQuery() const
Definition: TUri.h:98
TUri()
Definition: TUri.h:73
TString fHost
Definition: TUri.h:57
Bool_t SetFragment(const TString &fragment)
Set fragment component of URI: fragment = *( pchar / "/" / "?" ).
Definition: TUri.cxx:498
static TUri Transform(const TUri &reference, const TUri &base)
Transform a URI reference into its target URI using given a base URI.
Definition: TUri.cxx:1122
const TString GetHost() const
Definition: TUri.h:85
static Bool_t IsQuery(const TString &)
Returns kTRUE if string qualifies as URI query: query = *( pchar / "/" / "?" )...
Definition: TUri.cxx:320
static Bool_t IsRelativePart(const TString &)
Returns kTRUE is string qualifies as relative-part: relative-part = "//" authority path-abempty ...
Definition: TUri.cxx:760
Bool_t fHasHost
Definition: TUri.h:65
static Bool_t IsPort(const TString &)
Returns kTRUE if string qualifies as valid port component: RFC 3986: port = *DIGIT...
Definition: TUri.cxx:937
const TString GetUserInfo() const
Definition: TUri.h:84
const TString GetRelativePart() const
relative-part = "//" authority path-abempty / path-absolute / path-noscheme / path-empty ...
Definition: TUri.cxx:676
Bool_t IsReference() const
Returns kTRUE if instance qualifies as URI-reference URI-reference = URI / relative-ref cf...
Definition: TUri.cxx:237
Bool_t HasHierPart() const
Definition: TUri.h:92
Bool_t HasScheme() const
Definition: TUri.h:91
const TString GetAuthority() const
Returns the authority part of the instance: authority = [ userinfo "@" ] host [ ":" port ]...
Definition: TUri.cxx:283
Bool_t HasPort() const
Definition: TUri.h:96
Mother of all ROOT objects.
Definition: TObject.h:37
friend Bool_t operator==(const TUri &u1, const TUri &u2)
Implementation of a TUri Equivalence operator that uses syntax-based normalisation see chapter 6...
Definition: TUri.cxx:116
Bool_t SetHost(const TString &host)
Set host component of URI: RFC 3986: host = IP-literal / IPv4address / reg-name implemented: host ...
Definition: TUri.cxx:442
void Print(Option_t *option="") const
Display function,.
Definition: TUri.cxx:528
TString fFragment
Definition: TUri.h:61
static Bool_t IsPath(const TString &)
Returns kTRUE if string qualifies as valid path component: path = path-abempty ; begins w...
Definition: TUri.cxx:854
TString fPort
Definition: TUri.h:58
const TString GetHierPart() const
hier-part = "//" authority path-abempty / path-absolute / path-rootless ...
Definition: TUri.cxx:660
Bool_t HasUserInfo() const
Definition: TUri.h:94
static Bool_t IsHost(const TString &)
Returns kTRUE if string qualifies as valid host component: host = IP-literal / IPv4address / reg-name...
Definition: TUri.cxx:839
static const TString MergePaths(const TUri &reference, const TUri &base)
RFC 3986, 5.3.2.
Definition: TUri.cxx:1180
static Bool_t IsPathAbempty(const TString &)
Returns kTRUE if string qualifies as valid path-abempty component: path-abempty = *( "/" segment ) s...
Definition: TUri.cxx:870
static Bool_t IsPathAbsolute(const TString &)
Returns kTRUE if string qualifies as valid path-absolute component path-absolute = "/" [ segment-nz *...
Definition: TUri.cxx:885
Bool_t IsSortable() const
Definition: TUri.h:116
Bool_t HasHost() const
Definition: TUri.h:95
static Bool_t IsUnreserved(const TString &string)
Returns kTRUE, if the given string does not contain RFC 3986 reserved characters unreserved = ALPHA ...
Definition: TUri.cxx:975
const TString GetQuery() const
Definition: TUri.h:88
Bool_t SetRelativePart(const TString &)
Returns kTRUE is string qualifies as relative-part: relative-part = "//" authority path-abempty ...
Definition: TUri.cxx:777
static const TString PctNormalise(const TString &source)
Normalise the percent-encoded parts of the string i.e.
Definition: TUri.cxx:1057
const Bool_t kTRUE
Definition: RtypesCore.h:91
static Bool_t IsPathRootless(const TString &)
Returns kTRUE if string qualifies as valid path-rootless component: path-rootless = segment-nz *( "/"...
Definition: TUri.cxx:913
Bool_t operator==(const TUri &u1, const TUri &u2)
Implementation of a TUri Equivalence operator that uses syntax-based normalisation see chapter 6...
Definition: TUri.cxx:116
static Bool_t IsFragment(const TString &)
Returns kTRUE if string qualifies as valid fragment component fragment = *( pchar / "/" / "...
Definition: TUri.cxx:516
static const TString RemoveDotSegments(const TString &)
This functions implements the "remove_dot_segments" routine of chapter 5.2.4 "for interpreting and re...
Definition: TUri.cxx:159
Bool_t HasPath() const
Definition: TUri.h:97
static Bool_t IsHierPart(const TString &)
Returns kTRUE if string qualifies as hier-part: hier-part = "//" authority path-abempty ...
Definition: TUri.cxx:743
const TString GetScheme() const
Definition: TUri.h:80
static Bool_t IsScheme(const TString &)
Returns kTRUE if string qualifies as URI scheme: scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "...
Definition: TUri.cxx:270