// @(#)root/base:$Id$
// Author: Fons Rademakers   17/01/97

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TUrl
#define ROOT_TUrl


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TUrl                                                                 //
//                                                                      //
// This class represents a WWW compatible URL.                          //
// It provides member functions to return the different parts of        //
// an URL. The supported url format is:                                 //
//  [proto://][user[:passwd]@]host[:port]/file.ext[#anchor][?options]   //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TObject
#include "TObject.h"
#endif
#ifndef ROOT_TString
#include "TString.h"
#endif
#ifndef ROOT_TMap
#include "TMap.h"
#endif


class THashList;
class TMap;

class TUrl : public TObject {

private:
   mutable TString fUrl;    // full URL
   TString fProtocol;       // protocol: http, ftp, news, root, proof, ...
   TString fUser;           // user name
   TString fPasswd;         // password
   TString fHost;           // remote host
   TString fFile;           // remote object
   TString fAnchor;         // anchor in object (after #)
   TString fOptions;        // options/search (after ?)
   mutable TString fFileOA; //!file with option and anchor
   mutable TString fHostFQ; //!fully qualified host name
   Int_t   fPort;           // port through which to contact remote server
   mutable TMap *fOptionsMap; //!map containing options key/value pairs

   static TObjArray  *fgSpecialProtocols;  // list of special protocols
   static THashList  *fgHostFQDNs;         // list of resolved host FQDNs

   void FindFile(char *u, Bool_t stripDoubleSlash = kTRUE);

   enum EStatusBits { kUrlWithDefaultPort = BIT(14), kUrlHasDefaultPort = BIT(15) };

public:
   TUrl() : fUrl(), fProtocol(), fUser(), fPasswd(), fHost(), fFile(),
            fAnchor(), fOptions(), fFileOA(), fHostFQ(), fPort(-1), fOptionsMap(0) { }
   TUrl(const char *url, Bool_t defaultIsFile = kFALSE);
   TUrl(const TUrl &url);
   TUrl &operator=(const TUrl &rhs);
   virtual ~TUrl();

   const char *GetUrl(Bool_t withDeflt = kFALSE) const;
   const char *GetProtocol() const { return fProtocol; }
   const char *GetUser() const { return fUser; }
   const char *GetPasswd() const { return fPasswd; }
   const char *GetHost() const { return fHost; }
   const char *GetHostFQDN() const;
   const char *GetFile() const { return fFile; }
   const char *GetAnchor() const { return fAnchor; }
   const char *GetOptions() const { return fOptions; }
   const char *GetValueFromOptions(const char *key) const;
   Int_t       GetIntValueFromOptions(const char *key) const;
   Bool_t      HasOption(const char *key) const;
   void        ParseOptions() const;
   void        CleanRelativePath();
   const char *GetFileAndOptions() const;
   Int_t       GetPort() const { return fPort; }
   Bool_t      IsValid() const { return fPort == -1 ? kFALSE : kTRUE; }

   void        SetProtocol(const char *proto, Bool_t setDefaultPort = kFALSE);
   void        SetUser(const char *user) { fUser = user; fUrl = ""; }
   void        SetPasswd(const char *pw) { fPasswd = pw; fUrl = ""; }
   void        SetHost(const char *host) { fHost = host; fUrl = ""; }
   void        SetFile(const char *file) { fFile = file; fUrl = ""; fFileOA = "";}
   void        SetAnchor(const char *anchor) { fAnchor = anchor; fUrl = ""; fFileOA = ""; }
   void        SetOptions(const char *opt) { fOptions = opt; fUrl = ""; fFileOA = ""; }
   void        SetPort(Int_t port) { fPort = port; fUrl = ""; }
   void        SetUrl(const char *url, Bool_t defaultIsFile = kFALSE);

   Bool_t      IsSortable() const { return kTRUE; }
   Int_t       Compare(const TObject *obj) const;

   void        Print(Option_t *option="") const;

   static TObjArray *GetSpecialProtocols();

   ClassDef(TUrl,1)  //Represents an URL
};

#endif
 TUrl.h:1
 TUrl.h:2
 TUrl.h:3
 TUrl.h:4
 TUrl.h:5
 TUrl.h:6
 TUrl.h:7
 TUrl.h:8
 TUrl.h:9
 TUrl.h:10
 TUrl.h:11
 TUrl.h:12
 TUrl.h:13
 TUrl.h:14
 TUrl.h:15
 TUrl.h:16
 TUrl.h:17
 TUrl.h:18
 TUrl.h:19
 TUrl.h:20
 TUrl.h:21
 TUrl.h:22
 TUrl.h:23
 TUrl.h:24
 TUrl.h:25
 TUrl.h:26
 TUrl.h:27
 TUrl.h:28
 TUrl.h:29
 TUrl.h:30
 TUrl.h:31
 TUrl.h:32
 TUrl.h:33
 TUrl.h:34
 TUrl.h:35
 TUrl.h:36
 TUrl.h:37
 TUrl.h:38
 TUrl.h:39
 TUrl.h:40
 TUrl.h:41
 TUrl.h:42
 TUrl.h:43
 TUrl.h:44
 TUrl.h:45
 TUrl.h:46
 TUrl.h:47
 TUrl.h:48
 TUrl.h:49
 TUrl.h:50
 TUrl.h:51
 TUrl.h:52
 TUrl.h:53
 TUrl.h:54
 TUrl.h:55
 TUrl.h:56
 TUrl.h:57
 TUrl.h:58
 TUrl.h:59
 TUrl.h:60
 TUrl.h:61
 TUrl.h:62
 TUrl.h:63
 TUrl.h:64
 TUrl.h:65
 TUrl.h:66
 TUrl.h:67
 TUrl.h:68
 TUrl.h:69
 TUrl.h:70
 TUrl.h:71
 TUrl.h:72
 TUrl.h:73
 TUrl.h:74
 TUrl.h:75
 TUrl.h:76
 TUrl.h:77
 TUrl.h:78
 TUrl.h:79
 TUrl.h:80
 TUrl.h:81
 TUrl.h:82
 TUrl.h:83
 TUrl.h:84
 TUrl.h:85
 TUrl.h:86
 TUrl.h:87
 TUrl.h:88
 TUrl.h:89
 TUrl.h:90
 TUrl.h:91
 TUrl.h:92
 TUrl.h:93
 TUrl.h:94
 TUrl.h:95
 TUrl.h:96
 TUrl.h:97
 TUrl.h:98
 TUrl.h:99
 TUrl.h:100
 TUrl.h:101
 TUrl.h:102
 TUrl.h:103
 TUrl.h:104
 TUrl.h:105
 TUrl.h:106
 TUrl.h:107
 TUrl.h:108
 TUrl.h:109
 TUrl.h:110