Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

Url.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                                                                      |
00003 |                      __   __    ____ _____ ____                      |
00004 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00005 |                       \ V / _` \___ \ | |   __) |                    |
00006 |                        | | (_| |___) || |  / __/                     |
00007 |                        |_|\__,_|____/ |_| |_____|                    |
00008 |                                                                      |
00009 |                               core system                            |
00010 |                                                                      |
00011 |                                         (C) 2002, 2003 SuSE Linux AG |
00012 \----------------------------------------------------------------------/
00013 
00014    File:       Url.cc
00015    Purpose:    An URL class
00016    Authors:    Ludwig Nussel <lnussel@suse.de>
00017                Cornelius Schumacher <cschum@suse.de>
00018    Maintainer: Cornelius Schumacher <cschum@suse.de>
00019 
00020 /-*/
00021 
00022 #ifndef _Url_h_
00023 #define _Url_h_
00024 
00025 #include <iosfwd>
00026 
00027 #include <string>
00028 #include <map>
00029 
00030 
00038 class Url
00039 {
00040     public:
00041 
00042         typedef std::map<std::string,std::string> OptionMapType;
00043 
00044         enum Protocol { unknown, file, ftp, http, https, cd, dvd, nfs, dir,
00045                         hd, smb, cifs };
00046 
00047     private:
00048 
00049         class ProtocolStrings : public std::map<Protocol,std::string>
00050         {
00051           public:
00052             ProtocolStrings();
00053         };
00054 
00055         static ProtocolStrings _protocolStrings;
00056 
00057         Protocol _protocol;
00058         std::string _protocolString;
00059         std::string _username;
00060         std::string _password;
00061         std::string _host;
00062         int _port;
00063         std::string _path;
00064         OptionMapType _options;
00065 
00066         bool _valid;
00067 
00072         void clearifinvalid( bool valid );
00073 
00074     public:
00075 
00078         Url ();
00079 
00084         Url( const std::string & url );
00085 
00086         ~Url() {}
00087 
00088         bool operator==( const Url & ) const;
00089 
00090         void setProtocol( Protocol );
00091         void setProtocolString( const std::string &str );
00092         void setUsername( const std::string &str );
00093         void setPassword( const std::string &str );
00094         void setHost( const std::string &str );
00095         void setPort( int );
00096         void setPath( const std::string &path );
00097 
00098         Protocol protocol() const { return _protocol; }
00099         const std::string &protocolString() const { return _protocolString; }
00100         const std::string &username() const { return _username; }
00101         const std::string &password() const { return _password; }
00102         const std::string &host() const { return _host; }
00103         int port() const { return _port; }
00104         const std::string &path() const { return _path; }
00105         const OptionMapType &options() const { return _options; }
00106 
00113         std::string option( const std::string& key ) const;
00114 
00115         bool isLocal() const;
00116 
00117         bool isValid() const;
00118 
00125         bool set( const std::string url );
00126 
00138         std::string asString( bool path = true, bool options = true, bool plainpassword = false) const;
00139 
00143         std::string saveAsString() const { return asString(true,true,true); }
00144 
00145         friend std::ostream & operator<<( std::ostream & str, const Url & obj );
00146 
00147         static Protocol stringToProtocol( const std::string &protocolString );
00148         static std::string protocolToString( Protocol );
00149 
00150     private:
00151 
00158         static bool split( const std::string &url,
00159                            Protocol &protocol,
00160                            std::string &protocolString,
00161                            std::string &username,
00162                            std::string &password,
00163                            std::string &hostname,
00164                            int &port,
00165                            std::string &path,
00166                            OptionMapType &options );
00167 };
00168 
00169 #endif

Generated on Thu Feb 23 23:56:10 2006 for liby2util by doxygen 1.3.6