Logo ROOT   6.21/01
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
virtual ~TUri()
Definition: TUri.h:77
Bool_t fHasUserinfo
Definition: TUri.h:64
Bool_t IsAbsolute() const
static Bool_t IsIpv4(const TString &)
Bool_t SetPath(const TString &path)
const char Option_t
Definition: RtypesCore.h:62
void Normalise()
Bool_t HasRelativePart() const
Definition: TUri.h:100
static Bool_t IsPort(const TString &)
static Bool_t IsUserInfo(const TString &)
Bool_t SetHierPart(const TString &hier)
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 IsPathEmpty(const TString &)
Bool_t HasAuthority() const
Definition: TUri.h:93
Bool_t SetUserInfo(const TString &userinfo)
Basic string class.
Definition: TString.h:131
Bool_t SetPort(const TString &port)
static Bool_t IsPathAbsolute(const TString &)
bool Bool_t
Definition: RtypesCore.h:59
This class represents a RFC 3986 compatible URI.
Definition: TUri.h:35
static Bool_t IsHost(const TString &)
TString fPath
Definition: TUri.h:59
Bool_t fHasPort
Definition: TUri.h:66
Bool_t SetQuery(const TString &path)
const TString GetPath() const
Definition: TUri.h:87
static const TString PctEncode(const TString &source)
Bool_t SetUri(const TString &uri)
static const TString RemoveDotSegments(const TString &)
#define ClassDef(name, id)
Definition: Rtypes.h:326
TString fQuery
Definition: TUri.h:60
Bool_t IsRelative() const
static Bool_t IsRelativePart(const TString &)
static const TString PctNormalise(const TString &source)
static Bool_t IsPathRootless(const TString &)
const TString GetFragment() const
Definition: TUri.h:89
Bool_t SetAuthority(const TString &authority)
Bool_t HasFragment() const
Definition: TUri.h:99
static Bool_t IsFragment(const TString &)
static Bool_t IsPath(const TString &)
void Reset()
Bool_t fHasFragment
Definition: TUri.h:69
static Bool_t IsRegName(const TString &)
Bool_t SetScheme(const TString &scheme)
const TString GetUri() const
TString fScheme
Definition: TUri.h:55
static const TString PctDecode(const TString &source)
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)
static Bool_t IsUnreserved(const TString &string)
const TString GetHost() const
Definition: TUri.h:85
Bool_t fHasHost
Definition: TUri.h:65
TUri & operator=(const TUri &rhs)
static Bool_t IsQuery(const TString &)
static const TString PctDecodeUnreserved(const TString &source)
const TString GetUserInfo() const
Definition: TUri.h:84
static Bool_t IsScheme(const TString &)
const TString GetRelativePart() const
Bool_t IsReference() const
Bool_t HasHierPart() const
Definition: TUri.h:92
Bool_t HasScheme() const
Definition: TUri.h:91
static Bool_t IsHierPart(const TString &)
const TString GetAuthority() const
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)
Bool_t SetHost(const TString &host)
void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
TString fFragment
Definition: TUri.h:61
TString fPort
Definition: TUri.h:58
static TUri Transform(const TUri &reference, const TUri &base)
static Bool_t IsPathNoscheme(const TString &)
const TString GetHierPart() const
Bool_t HasUserInfo() const
Definition: TUri.h:94
static const TString MergePaths(const TUri &reference, const TUri &base)
static Bool_t IsPathAbempty(const TString &)
Bool_t IsSortable() const
Definition: TUri.h:116
Bool_t HasHost() const
Definition: TUri.h:95
const TString GetQuery() const
Definition: TUri.h:88
Bool_t SetRelativePart(const TString &)
const Bool_t kTRUE
Definition: RtypesCore.h:87
Bool_t operator==(const TUri &u1, const TUri &u2)
static Bool_t IsAuthority(const TString &)
Bool_t HasPath() const
Definition: TUri.h:97
const TString GetScheme() const
Definition: TUri.h:80