Logo ROOT  
Reference Guide
TUrl.h
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Fons Rademakers 17/01/97
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, 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_TUrl
13 #define ROOT_TUrl
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TUrl //
19 // //
20 // This class represents a WWW compatible URL. //
21 // It provides member functions to return the different parts of //
22 // an URL. The supported url format is: //
23 // [proto://][user[:passwd]@]host[:port]/file.ext[#anchor][?options] //
24 // //
25 //////////////////////////////////////////////////////////////////////////
26 
27 #include "TObject.h"
28 #include "TString.h"
29 
30 class THashList;
31 class TMap;
32 
33 class TUrl : public TObject {
34 
35 private:
36  mutable TString fUrl; // full URL
37  TString fProtocol; // protocol: http, ftp, news, root, proof, ...
38  TString fUser; // user name
39  TString fPasswd; // password
40  TString fHost; // remote host
41  TString fFile; // remote object
42  TString fAnchor; // anchor in object (after #)
43  TString fOptions; // options/search (after ?)
44  mutable TString fFileOA; //!file with option and anchor
45  mutable TString fHostFQ; //!fully qualified host name
46  Int_t fPort{-1}; // port through which to contact remote server
47  mutable TMap *fOptionsMap{nullptr}; //!map containing options key/value pairs
48 
49  static TObjArray *fgSpecialProtocols; // list of special protocols
50  static THashList *fgHostFQDNs; // list of resolved host FQDNs
51 
52  void FindFile(char *u, Bool_t stripDoubleSlash = kTRUE);
53 
55 
56 public:
57  TUrl() {} // NOLINT: not allowed to use = default because of TObject::kIsOnHeap detection, see ROOT-10300
58  TUrl(const char *url, Bool_t defaultIsFile = kFALSE);
59  TUrl(const TUrl &url);
60  TUrl &operator=(const TUrl &rhs);
61  virtual ~TUrl();
62 
63  const char *GetUrl(Bool_t withDeflt = kFALSE) const;
64  const char *GetProtocol() const { return fProtocol; }
65  const char *GetUser() const { return fUser; }
66  const char *GetPasswd() const { return fPasswd; }
67  const char *GetHost() const { return fHost; }
68  const char *GetHostFQDN() const;
69  const char *GetFile() const { return fFile; }
70  const char *GetAnchor() const { return fAnchor; }
71  const char *GetOptions() const { return fOptions; }
72  const char *GetValueFromOptions(const char *key) const;
73  Int_t GetIntValueFromOptions(const char *key) const;
74  Bool_t HasOption(const char *key) const;
75  void ParseOptions() const;
76  void CleanRelativePath();
77  const char *GetFileAndOptions() const;
78  Int_t GetPort() const { return fPort; }
79  Bool_t IsValid() const { return fPort == -1 ? kFALSE : kTRUE; }
80 
81  void SetProtocol(const char *proto, Bool_t setDefaultPort = kFALSE);
82  void SetUser(const char *user) { fUser = user; fUrl = ""; }
83  void SetPasswd(const char *pw) { fPasswd = pw; fUrl = ""; }
84  void SetHost(const char *host) { fHost = host; fUrl = ""; }
85  void SetFile(const char *file) { fFile = file; fUrl = ""; fFileOA = "";}
86  void SetAnchor(const char *anchor) { fAnchor = anchor; fUrl = ""; fFileOA = ""; }
87  void SetOptions(const char *opt) { fOptions = opt; fUrl = ""; fFileOA = ""; }
88  void SetPort(Int_t port) { fPort = port; fUrl = ""; }
89  void SetUrl(const char *url, Bool_t defaultIsFile = kFALSE);
90 
91  Bool_t IsSortable() const { return kTRUE; }
92  Int_t Compare(const TObject *obj) const;
93 
94  void Print(Option_t *option="") const;
95 
97 
98  ClassDef(TUrl,1) //Represents an URL
99 };
100 
101 #endif
TUrl::fUser
TString fUser
Definition: TUrl.h:38
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TUrl::fPort
Int_t fPort
fully qualified host name
Definition: TUrl.h:46
TObjArray
Definition: TObjArray.h:37
TUrl::GetValueFromOptions
const char * GetValueFromOptions(const char *key) const
Return a value for a given key from the URL options.
Definition: TUrl.cxx:651
TUrl::fFileOA
TString fFileOA
Definition: TUrl.h:44
TUrl::fgSpecialProtocols
static TObjArray * fgSpecialProtocols
map containing options key/value pairs
Definition: TUrl.h:49
TUrl::Compare
Int_t Compare(const TObject *obj) const
Compare two urls as strings.
Definition: TUrl.cxx:547
TUrl::GetPort
Int_t GetPort() const
Definition: TUrl.h:78
TUrl::fProtocol
TString fProtocol
Definition: TUrl.h:37
TUrl::SetAnchor
void SetAnchor(const char *anchor)
Definition: TUrl.h:86
TUrl::SetHost
void SetHost(const char *host)
Definition: TUrl.h:84
Int_t
int Int_t
Definition: RtypesCore.h:45
TUrl::SetOptions
void SetOptions(const char *opt)
Definition: TUrl.h:87
TUrl::ParseOptions
void ParseOptions() const
Parse URL options into a key/value map.
Definition: TUrl.cxx:617
TString
Definition: TString.h:136
TUrl::CleanRelativePath
void CleanRelativePath()
Recompute the path removing all relative directory jumps via '..'.
Definition: TUrl.cxx:685
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TUrl::FindFile
void FindFile(char *u, Bool_t stripDoubleSlash=kTRUE)
Find file and optionally anchor and options.
Definition: TUrl.cxx:285
TString.h
bool
TUrl::HasOption
Bool_t HasOption(const char *key) const
Returns true if the given key appears in the URL options list.
Definition: TUrl.cxx:674
TUrl::fAnchor
TString fAnchor
Definition: TUrl.h:42
TUrl::kUrlWithDefaultPort
@ kUrlWithDefaultPort
Definition: TUrl.h:54
TUrl::fgHostFQDNs
static THashList * fgHostFQDNs
Definition: TUrl.h:50
TUrl::fOptions
TString fOptions
Definition: TUrl.h:43
TUrl::GetIntValueFromOptions
Int_t GetIntValueFromOptions(const char *key) const
Return a value for a given key from the URL options as an Int_t, a missing key returns -1.
Definition: TUrl.cxx:663
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
THashList
Definition: THashList.h:34
TUrl::IsSortable
Bool_t IsSortable() const
Definition: TUrl.h:91
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TUrl::SetFile
void SetFile(const char *file)
Definition: TUrl.h:85
TUrl::SetUser
void SetUser(const char *user)
Definition: TUrl.h:82
TUrl::fOptionsMap
TMap * fOptionsMap
Definition: TUrl.h:47
BIT
#define BIT(n)
Definition: Rtypes.h:85
TUrl::fFile
TString fFile
Definition: TUrl.h:41
TUrl::SetUrl
void SetUrl(const char *url, Bool_t defaultIsFile=kFALSE)
Parse url character string and split in its different subcomponents.
Definition: TUrl.cxx:108
TUrl::SetProtocol
void SetProtocol(const char *proto, Bool_t setDefaultPort=kFALSE)
Set protocol and, optionally, change the port accordingly.
Definition: TUrl.cxx:520
TUrl::GetUrl
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:387
TUrl
Definition: TUrl.h:33
TUrl::SetPasswd
void SetPasswd(const char *pw)
Definition: TUrl.h:83
TUrl::GetFile
const char * GetFile() const
Definition: TUrl.h:69
TUrl::GetProtocol
const char * GetProtocol() const
Definition: TUrl.h:64
TUrl::SetPort
void SetPort(Int_t port)
Definition: TUrl.h:88
proto
const char * proto
Definition: civetweb.c:16604
TUrl::IsValid
Bool_t IsValid() const
Definition: TUrl.h:79
TUrl::fUrl
TString fUrl
Definition: TUrl.h:36
TObject.h
TUrl::fHost
TString fHost
Definition: TUrl.h:40
file
Definition: file.py:1
TUrl::GetAnchor
const char * GetAnchor() const
Definition: TUrl.h:70
TUrl::GetHost
const char * GetHost() const
Definition: TUrl.h:67
TObject
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TUrl::TUrl
TUrl()
Definition: TUrl.h:57
TUrl::kUrlHasDefaultPort
@ kUrlHasDefaultPort
Definition: TUrl.h:54
TUrl::GetFileAndOptions
const char * GetFileAndOptions() const
Return the file and its options (the string specified behind the ?).
Definition: TUrl.cxx:501
TUrl::GetPasswd
const char * GetPasswd() const
Definition: TUrl.h:66
TUrl::GetOptions
const char * GetOptions() const
Definition: TUrl.h:71
TUrl::operator=
TUrl & operator=(const TUrl &rhs)
TUrl assignment operator.
Definition: TUrl.cxx:362
TUrl::GetUser
const char * GetUser() const
Definition: TUrl.h:65
TUrl::Print
void Print(Option_t *option="") const
Print URL on stdout.
Definition: TUrl.cxx:557
TUrl::GetHostFQDN
const char * GetHostFQDN() const
Return fully qualified domain name of url host.
Definition: TUrl.cxx:469
TUrl::fHostFQ
TString fHostFQ
file with option and anchor
Definition: TUrl.h:45
TUrl::fPasswd
TString fPasswd
Definition: TUrl.h:39
TUrl::~TUrl
virtual ~TUrl()
Cleanup.
Definition: TUrl.cxx:86
TObject::EStatusBits
EStatusBits
Definition: TObject.h:57
TUrl::GetSpecialProtocols
static TObjArray * GetSpecialProtocols()
Read the list of special protocols from the rootrc files.
Definition: TUrl.cxx:571
int
TMap
Definition: TMap.h:40