00001 // @(#)root/base:$Id: TUri.h 20877 2007-11-19 11:17:07Z rdm $ 00002 // Author: Gerhard E. Bruckner 15/07/07 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. * 00006 * All rights reserved. * 00007 * * 00008 * For the licensing terms see $ROOTSYS/LICENSE. * 00009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00010 *************************************************************************/ 00011 00012 #ifndef ROOT_TUri 00013 #define ROOT_TUri 00014 00015 00016 ////////////////////////////////////////////////////////////////////////// 00017 // // 00018 // TUri // 00019 // // 00020 // This class represents a RFC3986 compatible URI. // 00021 // See http://rfc.net/rfc3986.html. // 00022 // It provides member functions to return the different parts of // 00023 // an URI. // 00024 // // 00025 ////////////////////////////////////////////////////////////////////////// 00026 00027 #ifndef ROOT_TObject 00028 #include "TObject.h" 00029 #endif 00030 #ifndef ROOT_TString 00031 #include "TString.h" 00032 #endif 00033 00034 00035 class TUri; 00036 Bool_t operator==(const TUri &u1, const TUri &u2); 00037 00038 00039 class TUri : public TObject { 00040 00041 friend Bool_t operator==(const TUri &u1, const TUri &u2); // comparison operator 00042 00043 private: 00044 00045 // In order to represent the five basic components of an URI, 00046 // we use 7 member variables (authority gets splitted in 3 parts) 00047 // 00048 // foo://user:pass@example.com:8042/over/there?name=ferret#nose 00049 // \_/ \________________________/\_________/ \_________/ \__/ 00050 // | | | | | 00051 // scheme authority path query fragment 00052 // 00053 // In many cases we have to distinguish between empty 00054 // TString and undefined value (i.e. delimiter not found). 00055 // Therefore, we use a TString to hold the string value 00056 // and a corresponding Bool_t to store if it is defined or not. 00057 // The Bool_t has precedence. 00058 00059 TString fScheme; 00060 TString fUserinfo; // authority/userinfo: user@password, ... 00061 TString fHost; // authority/host: hostname or ip-address 00062 TString fPort; // authority/port: port number, normally 1-65535 00063 TString fPath; 00064 TString fQuery; 00065 TString fFragment; 00066 00067 Bool_t fHasScheme; 00068 Bool_t fHasUserinfo; 00069 Bool_t fHasHost; 00070 Bool_t fHasPort; 00071 Bool_t fHasPath; 00072 Bool_t fHasQuery; 00073 Bool_t fHasFragment; 00074 00075 public: 00076 TUri(const TUri &uri); 00077 TUri() { Reset(); } 00078 TUri(const TString &uri); 00079 TUri(const char *uri); 00080 TUri &operator=(const TUri &rhs); //copy ctor 00081 virtual ~TUri() { } 00082 00083 const TString GetUri() const; 00084 const TString GetScheme() const { return fScheme; } 00085 const TString GetHierPart() const; 00086 const TString GetRelativePart() const; 00087 const TString GetAuthority() const; 00088 const TString GetUserInfo() const { return fUserinfo; } 00089 const TString GetHost() const { return fHost; } 00090 const TString GetPort() const { return fPort; } 00091 const TString GetPath() const { return fPath; } 00092 const TString GetQuery() const { return fQuery; } 00093 const TString GetFragment() const { return fFragment; } 00094 00095 Bool_t HasScheme() const { return fHasScheme; } 00096 Bool_t HasHierPart() const { return IsHierPart(GetHierPart()); } 00097 Bool_t HasAuthority() const { return fHasHost; } 00098 Bool_t HasUserInfo() const { return fHasUserinfo; } 00099 Bool_t HasHost() const { return fHasHost; } 00100 Bool_t HasPort() const { return fHasPort; } 00101 Bool_t HasPath() const { return fHasPath; } 00102 Bool_t HasQuery() const { return fHasQuery; } 00103 Bool_t HasFragment() const { return fHasFragment; } 00104 Bool_t HasRelativePart() const { return IsRelativePart(GetRelativePart()); } 00105 00106 Bool_t SetUri(const TString &uri); 00107 Bool_t SetScheme(const TString &scheme); 00108 Bool_t SetHierPart(const TString &hier); 00109 Bool_t SetAuthority(const TString &authority); 00110 Bool_t SetUserInfo(const TString &userinfo); 00111 Bool_t SetHost(const TString &host); 00112 Bool_t SetPort(const TString &port); 00113 Bool_t SetPath(const TString &path); 00114 Bool_t SetQuery(const TString &path); 00115 Bool_t SetFragment(const TString &fragment); 00116 00117 Bool_t SetRelativePart(const TString&); 00118 00119 void Print(Option_t *option = "") const; 00120 Bool_t IsSortable() const { return kTRUE; } 00121 00122 void Normalise(); 00123 void Reset(); 00124 00125 Bool_t IsAbsolute() const; 00126 Bool_t IsRelative() const; 00127 Bool_t IsUri() const; 00128 Bool_t IsReference() const; 00129 00130 static Bool_t IsUnreserved(const TString &string); 00131 00132 static const TString PctEncode(const TString &source); 00133 static const TString PctDecode(const TString &source); 00134 static const TString PctDecodeUnreserved(const TString &source); 00135 static const TString PctNormalise(const TString &source); 00136 00137 static Bool_t IsScheme(const TString&); 00138 static Bool_t IsHierPart(const TString&); 00139 static Bool_t IsAuthority(const TString&); 00140 static Bool_t IsUserInfo(const TString&); 00141 static Bool_t IsHost(const TString&); 00142 static Bool_t IsIpv4(const TString&); 00143 static Bool_t IsRegName(const TString&); 00144 static Bool_t IsPort(const TString&); 00145 static Bool_t IsPath(const TString&); 00146 static Bool_t IsPathAbsolute(const TString&); 00147 static Bool_t IsPathAbempty(const TString&); 00148 static Bool_t IsPathNoscheme(const TString&); 00149 static Bool_t IsPathRootless(const TString&); 00150 static Bool_t IsPathEmpty(const TString&); 00151 static Bool_t IsQuery(const TString&); 00152 static Bool_t IsFragment(const TString&); 00153 00154 static Bool_t IsRelativePart(const TString&); 00155 00156 static const TString RemoveDotSegments(const TString&); 00157 00158 static TUri Transform(const TUri &reference, const TUri &base); 00159 static const TString MergePaths(const TUri &reference, const TUri &base); 00160 00161 ClassDef(TUri, 1) //Represents an URI 00162 }; 00163 00164 #endif