Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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{-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 
56  enum EStatusBits { kUrlWithDefaultPort = BIT(14), kUrlHasDefaultPort = BIT(15) };
57 
58 public:
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 
98  static TObjArray *GetSpecialProtocols();
99 
100  ClassDef(TUrl,1) //Represents an URL
101 };
102 
103 #endif