Logo ROOT  
Reference Guide
Go to the documentation of this file.
1// @(#)root/base:$Id$
2// Author: Fons Rademakers 17/01/97
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 *************************************************************************/
12#ifndef ROOT_TUrl
13#define ROOT_TUrl
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// //
27#include "TObject.h"
28#include "TString.h"
30class THashList;
31class TMap;
33class TUrl : public TObject {
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
49 static TObjArray *fgSpecialProtocols; // list of special protocols
50 static THashList *fgHostFQDNs; // list of resolved host FQDNs
52 void FindFile(char *u, Bool_t stripDoubleSlash = kTRUE);
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();
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; }
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);
91 Bool_t IsSortable() const override { return kTRUE; }
92 Int_t Compare(const TObject *obj) const override;
94 void Print(Option_t *option="") const override;
98 ClassDefOverride(TUrl,1) //Represents an URL
bool Bool_t
Definition: RtypesCore.h:63
int Int_t
Definition: RtypesCore.h:45
const Bool_t kFALSE
Definition: RtypesCore.h:101
const Bool_t kTRUE
Definition: RtypesCore.h:100
const char Option_t
Definition: RtypesCore.h:66
#define BIT(n)
Definition: Rtypes.h:85
#define ClassDefOverride(name, id)
Definition: Rtypes.h:339
Option_t Option_t option
const char * proto
Definition: civetweb.c:17502
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:34
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Definition: TMap.h:40
An array of TObjects.
Definition: TObjArray.h:31
Mother of all ROOT objects.
Definition: TObject.h:41
Definition: TObject.h:61
Basic string class.
Definition: TString.h:136
This class represents a WWW compatible URL.
Definition: TUrl.h:33
TString fUrl
Definition: TUrl.h:36
TString fAnchor
Definition: TUrl.h:42
void CleanRelativePath()
Recompute the path removing all relative directory jumps via '..'.
Definition: TUrl.cxx:694
static TObjArray * GetSpecialProtocols()
Read the list of special protocols from the rootrc files.
Definition: TUrl.cxx:574
@ kUrlWithDefaultPort
Definition: TUrl.h:54
@ kUrlHasDefaultPort
Definition: TUrl.h:54
const char * GetAnchor() const
Definition: TUrl.h:70
Definition: TUrl.h:57
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:390
TString fHost
Definition: TUrl.h:40
void SetAnchor(const char *anchor)
Definition: TUrl.h:86
void FindFile(char *u, Bool_t stripDoubleSlash=kTRUE)
Find file and optionally anchor and options.
Definition: TUrl.cxx:288
const char * GetFileAndOptions() const
Return the file and its options (the string specified behind the ?).
Definition: TUrl.cxx:504
const char * GetFile() const
Definition: TUrl.h:69
TString fPasswd
Definition: TUrl.h:39
void SetUser(const char *user)
Definition: TUrl.h:82
TString fFileOA
Definition: TUrl.h:44
const char * GetValueFromOptions(const char *key) const
Return a value for a given key from the URL options.
Definition: TUrl.cxx:660
void SetUrl(const char *url, Bool_t defaultIsFile=kFALSE)
Parse url character string and split in its different subcomponents.
Definition: TUrl.cxx:110
Bool_t IsSortable() const override
Definition: TUrl.h:91
void SetProtocol(const char *proto, Bool_t setDefaultPort=kFALSE)
Set protocol and, optionally, change the port accordingly.
Definition: TUrl.cxx:523
TString fOptions
Definition: TUrl.h:43
TUrl & operator=(const TUrl &rhs)
TUrl assignment operator.
Definition: TUrl.cxx:365
Bool_t IsValid() const
Definition: TUrl.h:79
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:672
TString fProtocol
Definition: TUrl.h:37
const char * GetUser() const
Definition: TUrl.h:65
const char * GetHost() const
Definition: TUrl.h:67
TMap * fOptionsMap
Definition: TUrl.h:47
const char * GetPasswd() const
Definition: TUrl.h:66
Int_t fPort
fully qualified host name
Definition: TUrl.h:46
void SetOptions(const char *opt)
Definition: TUrl.h:87
const char * GetHostFQDN() const
Return fully qualified domain name of url host.
Definition: TUrl.cxx:472
void Print(Option_t *option="") const override
Print URL on stdout.
Definition: TUrl.cxx:560
TString fFile
Definition: TUrl.h:41
static THashList * fgHostFQDNs
Definition: TUrl.h:50
void ParseOptions() const
Parse URL options into a key/value map.
Definition: TUrl.cxx:626
const char * GetOptions() const
Definition: TUrl.h:71
virtual ~TUrl()
Definition: TUrl.cxx:88
TString fHostFQ
file with option and anchor
Definition: TUrl.h:45
void SetHost(const char *host)
Definition: TUrl.h:84
const char * GetProtocol() const
Definition: TUrl.h:64
void SetFile(const char *file)
Definition: TUrl.h:85
void SetPort(Int_t port)
Definition: TUrl.h:88
Int_t GetPort() const
Definition: TUrl.h:78
void SetPasswd(const char *pw)
Definition: TUrl.h:83
TString fUser
Definition: TUrl.h:38
Bool_t HasOption(const char *key) const
Returns true if the given key appears in the URL options list.
Definition: TUrl.cxx:683
static TObjArray * fgSpecialProtocols
map containing options key/value pairs
Definition: TUrl.h:49
Int_t Compare(const TObject *obj) const override
Compare two urls as strings.
Definition: TUrl.cxx:550
Definition: file.py:1