Logo ROOT   6.12/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 #include "TObject.h"
28 #include "TString.h"
29 #include "TMap.h"
30 
31 
32 class THashList;
33 class TMap;
34 
35 class TUrl : public TObject {
36 
37 private:
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; // port through which to contact remote server
49  mutable TMap *fOptionsMap; //!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 
58 public:
59  TUrl() : fUrl(), fProtocol(), fUser(), fPasswd(), fHost(), fFile(),
60  fAnchor(), fOptions(), fFileOA(), fHostFQ(), fPort(-1), fOptionsMap(0) { }
61  TUrl(const char *url, Bool_t defaultIsFile = kFALSE);
62  TUrl(const TUrl &url);
63  TUrl &operator=(const TUrl &rhs);
64  virtual ~TUrl();
65 
66  const char *GetUrl(Bool_t withDeflt = kFALSE) const;
67  const char *GetProtocol() const { return fProtocol; }
68  const char *GetUser() const { return fUser; }
69  const char *GetPasswd() const { return fPasswd; }
70  const char *GetHost() const { return fHost; }
71  const char *GetHostFQDN() const;
72  const char *GetFile() const { return fFile; }
73  const char *GetAnchor() const { return fAnchor; }
74  const char *GetOptions() const { return fOptions; }
75  const char *GetValueFromOptions(const char *key) const;
76  Int_t GetIntValueFromOptions(const char *key) const;
77  Bool_t HasOption(const char *key) const;
78  void ParseOptions() const;
79  void CleanRelativePath();
80  const char *GetFileAndOptions() const;
81  Int_t GetPort() const { return fPort; }
82  Bool_t IsValid() const { return fPort == -1 ? kFALSE : kTRUE; }
83 
84  void SetProtocol(const char *proto, Bool_t setDefaultPort = kFALSE);
85  void SetUser(const char *user) { fUser = user; fUrl = ""; }
86  void SetPasswd(const char *pw) { fPasswd = pw; fUrl = ""; }
87  void SetHost(const char *host) { fHost = host; fUrl = ""; }
88  void SetFile(const char *file) { fFile = file; fUrl = ""; fFileOA = "";}
89  void SetAnchor(const char *anchor) { fAnchor = anchor; fUrl = ""; fFileOA = ""; }
90  void SetOptions(const char *opt) { fOptions = opt; fUrl = ""; fFileOA = ""; }
91  void SetPort(Int_t port) { fPort = port; fUrl = ""; }
92  void SetUrl(const char *url, Bool_t defaultIsFile = kFALSE);
93 
94  Bool_t IsSortable() const { return kTRUE; }
95  Int_t Compare(const TObject *obj) const;
96 
97  void Print(Option_t *option="") const;
98 
100 
101  ClassDef(TUrl,1) //Represents an URL
102 };
103 
104 #endif
void SetFile(const char *file)
Definition: TUrl.h:88
An array of TObjects.
Definition: TObjArray.h:37
void SetPort(Int_t port)
Definition: TUrl.h:91
static THashList * fgHostFQDNs
Definition: TUrl.h:52
TString fOptions
Definition: TUrl.h:45
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:49
void SetPasswd(const char *pw)
Definition: TUrl.h:86
This class represents a WWW compatible URL.
Definition: TUrl.h:35
const char * GetProtocol() const
Definition: TUrl.h:67
#define BIT(n)
Definition: Rtypes.h:78
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:125
TString fHost
Definition: TUrl.h:42
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void SetUser(const char *user)
Definition: TUrl.h:85
const char * GetOptions() const
Definition: TUrl.h:74
TString fFile
Definition: TUrl.h:43
TString fUrl
Definition: TUrl.h:38
Bool_t IsValid() const
Definition: TUrl.h:82
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:47
virtual ~TUrl()
Cleanup.
Definition: TUrl.cxx:88
TString fPasswd
Definition: TUrl.h:41
const char * GetFile() const
Definition: TUrl.h:72
const char * GetHost() const
Definition: TUrl.h:70
#define ClassDef(name, id)
Definition: Rtypes.h:320
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:34
TUrl()
Definition: TUrl.h:59
const char * GetAnchor() const
Definition: TUrl.h:73
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:68
const char * GetPasswd() const
Definition: TUrl.h:69
TUrl & operator=(const TUrl &rhs)
TUrl assignment operator.
Definition: TUrl.cxx:363
TString fProtocol
Definition: TUrl.h:39
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:40
Int_t fPort
fully qualified host name
Definition: TUrl.h:48
static TObjArray * GetSpecialProtocols()
Read the list of special protocols from the rootrc files.
Definition: TUrl.cxx:571
const Bool_t kFALSE
Definition: RtypesCore.h:88
void SetHost(const char *host)
Definition: TUrl.h:87
void SetAnchor(const char *anchor)
Definition: TUrl.h:89
EStatusBits
Definition: TObject.h:57
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Definition: TMap.h:40
TString fFileOA
Definition: TUrl.h:46
void ParseOptions() const
Parse URL options into a key/value map.
Definition: TUrl.cxx:618
Int_t GetPort() const
Definition: TUrl.h:81
Mother of all ROOT objects.
Definition: TObject.h:37
static TObjArray * fgSpecialProtocols
map containing options key/value pairs
Definition: TUrl.h:51
Definition: file.py:1
void SetOptions(const char *opt)
Definition: TUrl.h:90
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:94
const Bool_t kTRUE
Definition: RtypesCore.h:87
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:44
void CleanRelativePath()
Recompute the path removing all relative directory jumps via '..'.
Definition: TUrl.cxx:685