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 62 enum EStatusBits { kUrlWithDefaultPort = BIT(14), kUrlHasDefaultPort = BIT(15) }; 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 111