Logo ROOT   6.08/07
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 #ifndef ROOT_TObject
28 #include "TObject.h"
29 #endif
30 #ifndef ROOT_TString
31 #include "TString.h"
32 #endif
33 #ifndef ROOT_TMap
34 #include "TMap.h"
35 #endif
36 
37 
38 class THashList;
39 class TMap;
40 
41 class TUrl : public TObject {
42 
43 private:
44  mutable TString fUrl; // full URL
45  TString fProtocol; // protocol: http, ftp, news, root, proof, ...
46  TString fUser; // user name
47  TString fPasswd; // password
48  TString fHost; // remote host
49  TString fFile; // remote object
50  TString fAnchor; // anchor in object (after #)
51  TString fOptions; // options/search (after ?)
52  mutable TString fFileOA; //!file with option and anchor
53  mutable TString fHostFQ; //!fully qualified host name
54  Int_t fPort; // port through which to contact remote server
55  mutable TMap *fOptionsMap; //!map containing options key/value pairs
56 
57  static TObjArray *fgSpecialProtocols; // list of special protocols
58  static THashList *fgHostFQDNs; // list of resolved host FQDNs
59 
60  void FindFile(char *u, Bool_t stripDoubleSlash = kTRUE);
61 
63 
64 public:
65  TUrl() : fUrl(), fProtocol(), fUser(), fPasswd(), fHost(), fFile(),
66  fAnchor(), fOptions(), fFileOA(), fHostFQ(), fPort(-1), fOptionsMap(0) { }
67  TUrl(const char *url, Bool_t defaultIsFile = kFALSE);
68  TUrl(const TUrl &url);
69  TUrl &operator=(const TUrl &rhs);
70  virtual ~TUrl();
71 
72  const char *GetUrl(Bool_t withDeflt = kFALSE) const;
73  const char *GetProtocol() const { return fProtocol; }
74  const char *GetUser() const { return fUser; }
75  const char *GetPasswd() const { return fPasswd; }
76  const char *GetHost() const { return fHost; }
77  const char *GetHostFQDN() const;
78  const char *GetFile() const { return fFile; }
79  const char *GetAnchor() const { return fAnchor; }
80  const char *GetOptions() const { return fOptions; }
81  const char *GetValueFromOptions(const char *key) const;
82  Int_t GetIntValueFromOptions(const char *key) const;
83  Bool_t HasOption(const char *key) const;
84  void ParseOptions() const;
85  void CleanRelativePath();
86  const char *GetFileAndOptions() const;
87  Int_t GetPort() const { return fPort; }
88  Bool_t IsValid() const { return fPort == -1 ? kFALSE : kTRUE; }
89 
90  void SetProtocol(const char *proto, Bool_t setDefaultPort = kFALSE);
91  void SetUser(const char *user) { fUser = user; fUrl = ""; }
92  void SetPasswd(const char *pw) { fPasswd = pw; fUrl = ""; }
93  void SetHost(const char *host) { fHost = host; fUrl = ""; }
94  void SetFile(const char *file) { fFile = file; fUrl = ""; fFileOA = "";}
95  void SetAnchor(const char *anchor) { fAnchor = anchor; fUrl = ""; fFileOA = ""; }
96  void SetOptions(const char *opt) { fOptions = opt; fUrl = ""; fFileOA = ""; }
97  void SetPort(Int_t port) { fPort = port; fUrl = ""; }
98  void SetUrl(const char *url, Bool_t defaultIsFile = kFALSE);
99 
100  Bool_t IsSortable() const { return kTRUE; }
101  Int_t Compare(const TObject *obj) const;
102 
103  void Print(Option_t *option="") const;
104 
105  static TObjArray *GetSpecialProtocols();
106 
107  ClassDef(TUrl,1) //Represents an URL
108 };
109 
110 #endif
void SetFile(const char *file)
Definition: TUrl.h:94
An array of TObjects.
Definition: TObjArray.h:39
void SetPort(Int_t port)
Definition: TUrl.h:97
static THashList * fgHostFQDNs
Definition: TUrl.h:58
TString fOptions
Definition: TUrl.h:51
void SetProtocol(const char *proto, Bool_t setDefaultPort=kFALSE)
Set protocol and, optionally, change the port accordingly.
Definition: TUrl.cxx:520
const char Option_t
Definition: RtypesCore.h:62
TMap * fOptionsMap
Definition: TUrl.h:55
void SetPasswd(const char *pw)
Definition: TUrl.h:92
This class represents a WWW compatible URL.
Definition: TUrl.h:41
const char * GetProtocol() const
Definition: TUrl.h:73
#define BIT(n)
Definition: Rtypes.h:120
void SetUrl(const char *url, Bool_t defaultIsFile=kFALSE)
Parse url character string and split in its different subcomponents.
Definition: TUrl.cxx:110
const char * GetFileAndOptions() const
Return the file and its options (the string specified behind the ?).
Definition: TUrl.cxx:501
Basic string class.
Definition: TString.h:137
TString fHost
Definition: TUrl.h:48
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
void SetUser(const char *user)
Definition: TUrl.h:91
const char * GetOptions() const
Definition: TUrl.h:80
TString fFile
Definition: TUrl.h:49
TString fUrl
Definition: TUrl.h:44
Bool_t IsValid() const
Definition: TUrl.h:88
const char * GetHostFQDN() const
Return fully qualified domain name of url host.
Definition: TUrl.cxx:469
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:387
TString fHostFQ
file with option and anchor
Definition: TUrl.h:53
virtual ~TUrl()
Cleanup.
Definition: TUrl.cxx:88
TString fPasswd
Definition: TUrl.h:47
const char * GetFile() const
Definition: TUrl.h:78
const char * GetHost() const
Definition: TUrl.h:76
#define ClassDef(name, id)
Definition: Rtypes.h:254
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:36
TUrl()
Definition: TUrl.h:65
const char * GetAnchor() const
Definition: TUrl.h:79
const char * GetValueFromOptions(const char *key) const
Return a value for a given key from the URL options.
Definition: TUrl.cxx:649
const char * GetUser() const
Definition: TUrl.h:74
const char * GetPasswd() const
Definition: TUrl.h:75
TUrl & operator=(const TUrl &rhs)
TUrl assignment operator.
Definition: TUrl.cxx:363
TString fProtocol
Definition: TUrl.h:45
void Print(Option_t *option="") const
Print URL on stdout.
Definition: TUrl.cxx:557
Int_t Compare(const TObject *obj) const
Compare two urls as strings.
Definition: TUrl.cxx:547
TString fUser
Definition: TUrl.h:46
Int_t fPort
fully qualified host name
Definition: TUrl.h:54
static TObjArray * GetSpecialProtocols()
Read the list of special protocols from the rootrc files.
Definition: TUrl.cxx:571
void SetHost(const char *host)
Definition: TUrl.h:93
void SetAnchor(const char *anchor)
Definition: TUrl.h:95
EStatusBits
Definition: TObject.h:55
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Definition: TMap.h:44
TString fFileOA
Definition: TUrl.h:52
void ParseOptions() const
Parse URL options into a key/value map.
Definition: TUrl.cxx:618
Int_t GetPort() const
Definition: TUrl.h:87
Mother of all ROOT objects.
Definition: TObject.h:37
static TObjArray * fgSpecialProtocols
map containing options key/value pairs
Definition: TUrl.h:57
Definition: file.py:1
void SetOptions(const char *opt)
Definition: TUrl.h:96
const char * proto
Definition: civetweb.c:11652
void FindFile(char *u, Bool_t stripDoubleSlash=kTRUE)
Find file and optionally anchor and options.
Definition: TUrl.cxx:286
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:661
Bool_t IsSortable() const
Definition: TUrl.h:100
const Bool_t kTRUE
Definition: Rtypes.h:91
Bool_t HasOption(const char *key) const
Returns true if the given key appears in the URL options list.
Definition: TUrl.cxx:672
TString fAnchor
Definition: TUrl.h:50
void CleanRelativePath()
Recompute the path removing all relative directory jumps via '..'.
Definition: TUrl.cxx:685