Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
31class TUri;
32Bool_t operator==(const TUri &u1, const TUri &u2);
33
34
35class TUri : public TObject {
36
37friend Bool_t operator==(const TUri &u1, const TUri &u2); // comparison operator
38
39private:
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
71public:
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; }
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 Bool_t
Definition RtypesCore.h:63
const Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassDef(name, id)
Definition Rtypes.h:325
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
Mother of all ROOT objects.
Definition TObject.h:41
Basic string class.
Definition TString.h:136
This class represents a RFC 3986 compatible URI.
Definition TUri.h:35
const TString GetRelativePart() const
relative-part = "//" authority path-abempty
Definition TUri.cxx:676
static Bool_t IsPath(const TString &)
Returns kTRUE if string qualifies as valid path component:
Definition TUri.cxx:854
Bool_t HasPath() const
Definition TUri.h:97
Bool_t SetScheme(const TString &scheme)
Set scheme component of URI:
Definition TUri.cxx:248
Bool_t IsRelative() const
Returns kTRUE if instance qualifies as relative-ref relative-ref = relative-part [ "?...
Definition TUri.cxx:217
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 SetFragment(const TString &fragment)
Set fragment component of URI:
Definition TUri.cxx:498
Bool_t SetPath(const TString &path)
Set path component of URI:
Definition TUri.cxx:481
static Bool_t IsPathAbempty(const TString &)
Returns kTRUE if string qualifies as valid path-abempty component:
Definition TUri.cxx:870
Bool_t fHasPort
Definition TUri.h:66
Bool_t SetRelativePart(const TString &)
Returns kTRUE is string qualifies as relative-part:
Definition TUri.cxx:777
virtual ~TUri()
Definition TUri.h:77
Bool_t IsAbsolute() const
Returns kTRUE if instance qualifies as absolute-URI absolute-URI = scheme ":" hier-part [ "?...
Definition TUri.cxx:207
Bool_t fHasFragment
Definition TUri.h:69
const TString GetHost() const
Definition TUri.h:85
Bool_t IsSortable() const
Definition TUri.h:116
static Bool_t IsFragment(const TString &)
Returns kTRUE if string qualifies as valid fragment component.
Definition TUri.cxx:516
TString fQuery
Definition TUri.h:60
Bool_t SetUserInfo(const TString &userinfo)
Set userinfo component of URI:
Definition TUri.cxx:405
static Bool_t IsQuery(const TString &)
Returns kTRUE if string qualifies as URI query:
Definition TUri.cxx:320
const TString GetPort() const
Definition TUri.h:86
TString fPort
Definition TUri.h:58
Bool_t IsUri() const
Returns kTRUE if instance qualifies as URI URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] ...
Definition TUri.cxx:227
TString fScheme
Definition TUri.h:55
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
static const TString PctNormalise(const TString &source)
Normalise the percent-encoded parts of the string i.e.
Definition TUri.cxx:1057
const TString GetPath() const
Definition TUri.h:87
const TString GetHierPart() const
Definition TUri.cxx:660
void Normalise()
Syntax based normalisation according to RFC chapter 6.2.2.
Definition TUri.cxx:985
static Bool_t IsUserInfo(const TString &)
Return kTRUE is string qualifies as valid URI userinfo:
Definition TUri.cxx:428
const TString GetUri() const
Returns the whole URI - an implementation of chapter 5.3 component recomposition.
Definition TUri.cxx:140
Bool_t fHasHost
Definition TUri.h:65
const TString GetFragment() const
Definition TUri.h:89
static Bool_t IsPathRootless(const TString &)
Returns kTRUE if string qualifies as valid path-rootless component:
Definition TUri.cxx:913
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 Bool_t IsScheme(const TString &)
Returns kTRUE if string qualifies as URI scheme:
Definition TUri.cxx:270
const TString GetQuery() const
Definition TUri.h:88
Bool_t SetAuthority(const TString &authority)
Set authority part of URI:
Definition TUri.cxx:338
void Print(Option_t *option="") const
Display function,.
Definition TUri.cxx:528
Bool_t fHasScheme
Definition TUri.h:63
Bool_t HasHost() const
Definition TUri.h:95
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
Bool_t HasPort() const
Definition TUri.h:96
TString fUserinfo
Definition TUri.h:56
void Reset()
Initialize this URI object.
Definition TUri.cxx:571
const TString GetAuthority() const
Returns the authority part of the instance:
Definition TUri.cxx:283
Bool_t HasFragment() const
Definition TUri.h:99
static Bool_t IsPort(const TString &)
Returns kTRUE if string qualifies as valid port component:
Definition TUri.cxx:937
static Bool_t IsAuthority(const TString &)
Returns kTRUE if string qualifies as valid URI authority:
Definition TUri.cxx:383
Bool_t HasRelativePart() const
Definition TUri.h:100
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
static Bool_t IsPathNoscheme(const TString &)
Returns kTRUE if string qualifies as valid path-noscheme component:
Definition TUri.cxx:900
Bool_t fHasQuery
Definition TUri.h:68
Bool_t HasQuery() const
Definition TUri.h:98
static const TString MergePaths(const TUri &reference, const TUri &base)
RFC 3986, 5.3.2.
Definition TUri.cxx:1180
static Bool_t IsPathAbsolute(const TString &)
Returns kTRUE if string qualifies as valid path-absolute component.
Definition TUri.cxx:885
static Bool_t IsUnreserved(const TString &string)
Returns kTRUE, if the given string does not contain RFC 3986 reserved characters.
Definition TUri.cxx:975
Bool_t SetPort(const TString &port)
Set port component of URI:
Definition TUri.cxx:460
TString fPath
Definition TUri.h:59
Bool_t SetQuery(const TString &path)
Set query component of URI:
Definition TUri.cxx:298
Bool_t HasScheme() const
Definition TUri.h:91
Bool_t HasHierPart() const
Definition TUri.h:92
TString fFragment
Definition TUri.h:61
static Bool_t IsHierPart(const TString &)
Returns kTRUE if string qualifies as hier-part:
Definition TUri.cxx:743
static Bool_t IsRelativePart(const TString &)
Returns kTRUE is string qualifies as relative-part:
Definition TUri.cxx:760
static Bool_t IsIpv4(const TString &)
Returns kTRUE, if string holds a valid IPv4 address currently only decimal variant supported.
Definition TUri.cxx:962
Bool_t IsReference() const
Returns kTRUE if instance qualifies as URI-reference URI-reference = URI / relative-ref cf.
Definition TUri.cxx:237
static Bool_t IsPathEmpty(const TString &)
Returns kTRUE if string qualifies as valid path-empty component:
Definition TUri.cxx:926
TUri & operator=(const TUri &rhs)
TUri assignment operator.
Definition TUri.cxx:89
Bool_t SetUri(const TString &uri)
Parse URI and set the member variables accordingly, returns kTRUE if URI validates,...
Definition TUri.cxx:601
Bool_t SetHost(const TString &host)
Set host component of URI:
Definition TUri.cxx:442
Bool_t SetHierPart(const TString &hier)
returns hier-part component of URI
Definition TUri.cxx:693
TUri()
Definition TUri.h:73
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 HasAuthority() const
Definition TUri.h:93
Bool_t fHasPath
Definition TUri.h:67
const TString GetUserInfo() const
Definition TUri.h:84
Bool_t fHasUserinfo
Definition TUri.h:64
TString fHost
Definition TUri.h:57
const TString GetScheme() const
Definition TUri.h:80
Bool_t HasUserInfo() const
Definition TUri.h:94
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
static Bool_t IsRegName(const TString &)
Returns kTRUE if string qualifies as valid reg-name:
Definition TUri.cxx:950