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#include "TMap.h"
30
31
32class THashList;
33class TMap;
34
35class TUrl : public TObject {
36
37private:
38 mutable TString fUrl; // full URL
39 TString fProtocol; // protocol: http, ftp, news, root, proof, ...
40 TString fUser; // user name
41 TString fPasswd; // password
42 TString fHost; // remote host
43 TString fFile; // remote object
44 TString fAnchor; // anchor in object (after #)
45 TString fOptions; // options/search (after ?)
46 mutable TString fFileOA; //!file with option and anchor
47 mutable TString fHostFQ; //!fully qualified host name
48 Int_t fPort{-1}; // port through which to contact remote server
49 mutable TMap *fOptionsMap{nullptr}; //!map containing options key/value pairs
50
51 static TObjArray *fgSpecialProtocols; // list of special protocols
52 static THashList *fgHostFQDNs; // list of resolved host FQDNs
53
54 void FindFile(char *u, Bool_t stripDoubleSlash = kTRUE);
55
57
58public:
59 TUrl() {} // NOLINT: not allowed to use = default because of TObject::kIsOnHeap detection, see ROOT-10300
60 TUrl(const char *url, Bool_t defaultIsFile = kFALSE);
61 TUrl(const TUrl &url);
62 TUrl &operator=(const TUrl &rhs);
63 virtual ~TUrl();
64
65 const char *GetUrl(Bool_t withDeflt = kFALSE) const;
66 const char *GetProtocol() const { return fProtocol; }
67 const char *GetUser() const { return fUser; }
68 const char *GetPasswd() const { return fPasswd; }
69 const char *GetHost() const { return fHost; }
70 const char *GetHostFQDN() const;
71 const char *GetFile() const { return fFile; }
72 const char *GetAnchor() const { return fAnchor; }
73 const char *GetOptions() const { return fOptions; }
74 const char *GetValueFromOptions(const char *key) const;
75 Int_t GetIntValueFromOptions(const char *key) const;
76 Bool_t HasOption(const char *key) const;
77 void ParseOptions() const;
78 void CleanRelativePath();
79 const char *GetFileAndOptions() const;
80 Int_t GetPort() const { return fPort; }
81 Bool_t IsValid() const { return fPort == -1 ? kFALSE : kTRUE; }
82
83 void SetProtocol(const char *proto, Bool_t setDefaultPort = kFALSE);
84 void SetUser(const char *user) { fUser = user; fUrl = ""; }
85 void SetPasswd(const char *pw) { fPasswd = pw; fUrl = ""; }
86 void SetHost(const char *host) { fHost = host; fUrl = ""; }
87 void SetFile(const char *file) { fFile = file; fUrl = ""; fFileOA = "";}
88 void SetAnchor(const char *anchor) { fAnchor = anchor; fUrl = ""; fFileOA = ""; }
89 void SetOptions(const char *opt) { fOptions = opt; fUrl = ""; fFileOA = ""; }
90 void SetPort(Int_t port) { fPort = port; fUrl = ""; }
91 void SetUrl(const char *url, Bool_t defaultIsFile = kFALSE);
92
93 Bool_t IsSortable() const { return kTRUE; }
94 Int_t Compare(const TObject *obj) const;
95
96 void Print(Option_t *option="") const;
97
99
100 ClassDef(TUrl,1) //Represents an URL
101};
102
103#endif
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
#define ClassDef(name, id)
Definition: Rtypes.h:326
#define BIT(n)
Definition: Rtypes.h:83
const char * proto
Definition: civetweb.c:16604
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:37
Mother of all ROOT objects.
Definition: TObject.h:37
EStatusBits
Definition: TObject.h:57
Basic string class.
Definition: TString.h:131
This class represents a WWW compatible URL.
Definition: TUrl.h:35
TString fUrl
Definition: TUrl.h:38
TString fAnchor
Definition: TUrl.h:44
void CleanRelativePath()
Recompute the path removing all relative directory jumps via '..'.
Definition: TUrl.cxx:682
static TObjArray * GetSpecialProtocols()
Read the list of special protocols from the rootrc files.
Definition: TUrl.cxx:569
@ kUrlWithDefaultPort
Definition: TUrl.h:56
@ kUrlHasDefaultPort
Definition: TUrl.h:56
const char * GetAnchor() const
Definition: TUrl.h:72
TUrl()
Definition: TUrl.h:59
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:385
TString fHost
Definition: TUrl.h:42
void SetAnchor(const char *anchor)
Definition: TUrl.h:88
void FindFile(char *u, Bool_t stripDoubleSlash=kTRUE)
Find file and optionally anchor and options.
Definition: TUrl.cxx:284
const char * GetFileAndOptions() const
Return the file and its options (the string specified behind the ?).
Definition: TUrl.cxx:499
const char * GetFile() const
Definition: TUrl.h:71
TString fPasswd
Definition: TUrl.h:41
void SetUser(const char *user)
Definition: TUrl.h:84
TString fFileOA
Definition: TUrl.h:46
const char * GetValueFromOptions(const char *key) const
Return a value for a given key from the URL options.
Definition: TUrl.cxx:646
void SetUrl(const char *url, Bool_t defaultIsFile=kFALSE)
Parse url character string and split in its different subcomponents.
Definition: TUrl.cxx:108
void SetProtocol(const char *proto, Bool_t setDefaultPort=kFALSE)
Set protocol and, optionally, change the port accordingly.
Definition: TUrl.cxx:518
TString fOptions
Definition: TUrl.h:45
TUrl & operator=(const TUrl &rhs)
TUrl assignment operator.
Definition: TUrl.cxx:361
Bool_t IsValid() const
Definition: TUrl.h:81
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:658
TString fProtocol
Definition: TUrl.h:39
Int_t Compare(const TObject *obj) const
Compare two urls as strings.
Definition: TUrl.cxx:545
const char * GetUser() const
Definition: TUrl.h:67
const char * GetHost() const
Definition: TUrl.h:69
TMap * fOptionsMap
Definition: TUrl.h:49
const char * GetPasswd() const
Definition: TUrl.h:68
Int_t fPort
fully qualified host name
Definition: TUrl.h:48
void SetOptions(const char *opt)
Definition: TUrl.h:89
const char * GetHostFQDN() const
Return fully qualified domain name of url host.
Definition: TUrl.cxx:467
TString fFile
Definition: TUrl.h:43
void Print(Option_t *option="") const
Print URL on stdout.
Definition: TUrl.cxx:555
static THashList * fgHostFQDNs
Definition: TUrl.h:52
void ParseOptions() const
Parse URL options into a key/value map.
Definition: TUrl.cxx:615
const char * GetOptions() const
Definition: TUrl.h:73
virtual ~TUrl()
Cleanup.
Definition: TUrl.cxx:86
TString fHostFQ
file with option and anchor
Definition: TUrl.h:47
void SetHost(const char *host)
Definition: TUrl.h:86
const char * GetProtocol() const
Definition: TUrl.h:66
void SetFile(const char *file)
Definition: TUrl.h:87
void SetPort(Int_t port)
Definition: TUrl.h:90
Int_t GetPort() const
Definition: TUrl.h:80
void SetPasswd(const char *pw)
Definition: TUrl.h:85
Bool_t IsSortable() const
Definition: TUrl.h:93
TString fUser
Definition: TUrl.h:40
Bool_t HasOption(const char *key) const
Returns true if the given key appears in the URL options list.
Definition: TUrl.cxx:669
static TObjArray * fgSpecialProtocols
map containing options key/value pairs
Definition: TUrl.h:51
Definition: file.py:1