Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
55  TString fScheme;
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
59  TString fPath;
60  TString fQuery;
61  TString fFragment;
62 
63  Bool_t fHasScheme;
64  Bool_t fHasUserinfo;
65  Bool_t fHasHost;
66  Bool_t fHasPort;
67  Bool_t fHasPath;
68  Bool_t fHasQuery;
69  Bool_t fHasFragment;
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; }
100  Bool_t HasRelativePart() const { return IsRelativePart(GetRelativePart()); }
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 
113  Bool_t SetRelativePart(const TString&);
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