XrdClURL.hh

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
00003 // Author: Lukasz Janyst <ljanyst@cern.ch>
00004 //------------------------------------------------------------------------------
00005 // XRootD is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU Lesser General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // XRootD is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with XRootD.  If not, see <http://www.gnu.org/licenses/>.
00017 //------------------------------------------------------------------------------
00018 
00019 #ifndef __XRD_CL_URL_HH__
00020 #define __XRD_CL_URL_HH__
00021 
00022 #include <string>
00023 #include <map>
00024 
00025 namespace XrdCl
00026 {
00027   //----------------------------------------------------------------------------
00029   //----------------------------------------------------------------------------
00030   class URL
00031   {
00032     public:
00033       typedef std::map<std::string, std::string> ParamsMap; 
00034 
00035 
00036       //------------------------------------------------------------------------
00038       //------------------------------------------------------------------------
00039       URL();
00040 
00041       //------------------------------------------------------------------------
00046       //------------------------------------------------------------------------
00047       URL( const std::string &url );
00048 
00049       //------------------------------------------------------------------------
00051       //------------------------------------------------------------------------
00052       bool IsValid() const;
00053 
00054       //------------------------------------------------------------------------
00056       //------------------------------------------------------------------------
00057       bool IsMetalink() const;
00058 
00059       //------------------------------------------------------------------------
00061       //------------------------------------------------------------------------
00062       std::string GetURL() const
00063       {
00064         return pURL;
00065       }
00066 
00067       //------------------------------------------------------------------------
00069       //------------------------------------------------------------------------
00070       std::string GetHostId() const
00071       {
00072         return pHostId;
00073       }
00074 
00075       //------------------------------------------------------------------------
00077       //------------------------------------------------------------------------
00078       std::string GetLocation() const;
00079 
00080       //------------------------------------------------------------------------
00082       //------------------------------------------------------------------------
00083       const std::string &GetProtocol() const
00084       {
00085         return pProtocol;
00086       }
00087 
00088       //------------------------------------------------------------------------
00090       //------------------------------------------------------------------------
00091       void SetProtocol( const std::string &protocol )
00092       {
00093         pProtocol = protocol;
00094         ComputeURL();
00095       }
00096 
00097       //------------------------------------------------------------------------
00099       //------------------------------------------------------------------------
00100       const std::string &GetUserName() const
00101       {
00102         return pUserName;
00103       }
00104 
00105       //------------------------------------------------------------------------
00107       //------------------------------------------------------------------------
00108       void SetUserName( const std::string &userName )
00109       {
00110         pUserName = userName;
00111         ComputeHostId();
00112         ComputeURL();
00113       }
00114 
00115       //------------------------------------------------------------------------
00117       //------------------------------------------------------------------------
00118       const std::string &GetPassword() const
00119       {
00120         return pPassword;
00121       }
00122 
00123       //------------------------------------------------------------------------
00125       //------------------------------------------------------------------------
00126       void SetPassword( const std::string &password )
00127       {
00128         pPassword = password;
00129         ComputeURL();
00130       }
00131 
00132       //------------------------------------------------------------------------
00134       //------------------------------------------------------------------------
00135       const std::string &GetHostName() const
00136       {
00137         return pHostName;
00138       }
00139 
00140       //------------------------------------------------------------------------
00142       //------------------------------------------------------------------------
00143       void SetHostName( const std::string &hostName )
00144       {
00145         pHostName = hostName;
00146         ComputeHostId();
00147         ComputeURL();
00148       }
00149 
00150       //------------------------------------------------------------------------
00152       //------------------------------------------------------------------------
00153       int GetPort() const
00154       {
00155         return pPort;
00156       }
00157 
00158       //------------------------------------------------------------------------
00159       // Set port
00160       //------------------------------------------------------------------------
00161       void SetPort( int port )
00162       {
00163         pPort = port;
00164         ComputeHostId();
00165         ComputeURL();
00166       }
00167 
00168       //------------------------------------------------------------------------
00169       // Set host and port
00170       //------------------------------------------------------------------------
00171       void SetHostPort( const std::string &hostName, int port )
00172       {
00173         pHostName = hostName;
00174         pPort     = port;
00175         ComputeHostId();
00176         ComputeURL();
00177       }
00178 
00179       //------------------------------------------------------------------------
00181       //------------------------------------------------------------------------
00182       const std::string &GetPath() const
00183       {
00184         return pPath;
00185       }
00186 
00187       //------------------------------------------------------------------------
00189       //------------------------------------------------------------------------
00190       void SetPath( const std::string &path )
00191       {
00192         pPath = path;
00193         ComputeURL();
00194       }
00195 
00196       //------------------------------------------------------------------------
00198       //------------------------------------------------------------------------
00199       std::string GetPathWithParams() const;
00200 
00201       //------------------------------------------------------------------------
00203       //------------------------------------------------------------------------
00204       const ParamsMap &GetParams() const
00205       {
00206         return pParams;
00207       }
00208 
00209       //------------------------------------------------------------------------
00211       //------------------------------------------------------------------------
00212       std::string GetParamsAsString() const;
00213 
00214       //------------------------------------------------------------------------
00216       //------------------------------------------------------------------------
00217       void SetParams( const std::string &params );
00218 
00219       //------------------------------------------------------------------------
00221       //------------------------------------------------------------------------
00222       void SetParams( const ParamsMap &params )
00223       {
00224         pParams = params;
00225         ComputeURL();
00226       }
00227 
00228       //------------------------------------------------------------------------
00230       //------------------------------------------------------------------------
00231       bool FromString( const std::string &url );
00232 
00233       //------------------------------------------------------------------------
00235       //------------------------------------------------------------------------
00236       void Clear();
00237 
00238     private:
00239       bool ParseHostInfo( const std::string hhostInfo );
00240       bool ParsePath( const std::string &path );
00241       void ComputeHostId();
00242       void ComputeURL();
00243       bool PathEndsWith( const std::string & sufix ) const;
00244       std::string pHostId;
00245       std::string pProtocol;
00246       std::string pUserName;
00247       std::string pPassword;
00248       std::string pHostName;
00249       int         pPort;
00250       std::string pPath;
00251       ParamsMap   pParams;
00252       std::string pURL;
00253 
00254   };
00255 }
00256 
00257 #endif // __XRD_CL_URL_HH__

Generated on 5 Oct 2016 for xrootd by  doxygen 1.4.7