libzypp  10.5.0
MediaUserAuth.h
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_MEDIA_USER_AUTH_H
00013 #define ZYPP_MEDIA_USER_AUTH_H
00014 
00015 #include "zypp/base/Deprecated.h"
00016 
00017 #include "zypp/Url.h"
00018 #include "zypp/base/PtrTypes.h"
00019 
00020 namespace zypp {
00021   namespace media {
00022 
00024 
00025 
00030 class AuthData
00031 {
00032 public:
00033   AuthData()
00034   {}
00035 
00036   AuthData(const Url & url);
00037 
00038   AuthData(const std::string & username, const std::string & password)
00039     : _username(username), _password(password)
00040   {}
00041 
00042   virtual ~AuthData() {};
00043 
00049   virtual bool valid() const;
00050 
00051   void setUrl(const Url & url) { _url = url; }
00052   void setUsername(const std::string & username) { _username = username; }
00053   void setPassword(const std::string & password) { _password = password; }
00054 
00055   Url url() const { return _url; }
00056   std::string username() const { return _username; }
00057   std::string password() const { return _password; }
00058 
00059   virtual std::ostream & dumpOn( std::ostream & str ) const;
00060 
00061   virtual std::ostream & dumpAsIniOn( std::ostream & str ) const;
00062 
00063 private:
00064   Url _url;
00065   std::string _username;
00066   std::string _password;
00067 };
00068 
00069 typedef shared_ptr<AuthData> AuthData_Ptr;
00070 
00074 class CurlAuthData : public AuthData {
00075 public:
00080   CurlAuthData();
00081 
00082   CurlAuthData(const AuthData & authData);
00083 
00084   CurlAuthData(std::string & username, std::string & password, std::string & auth_type)
00085     : AuthData(username,password), _auth_type_str(auth_type)
00086   {
00087     _auth_type = auth_type_str2long(auth_type);
00088   }
00089 
00090   CurlAuthData(std::string & username, std::string & password, long auth_type)
00091     : AuthData(username,password), _auth_type(auth_type)
00092   {
00093     _auth_type_str = auth_type_long2str(auth_type);
00094   }
00095 
00101   virtual bool valid() const;
00102 
00107   void setAuthType(std::string auth_type)
00108   {
00109     _auth_type_str = auth_type; _auth_type = auth_type_str2long(auth_type);
00110   }
00111 
00112   /*
00113    * Set HTTP authentication type(s) to use.
00114    * \param HTTP authentication type as in long ORed form.
00115    * \see curl.h for available auth types
00116    */
00117   void setAuthType(long auth_type)
00118   {
00119     _auth_type = auth_type;
00120     _auth_type_str = auth_type_long2str(auth_type);
00121   }
00122 
00123   long authType() { return _auth_type; } const
00124   std::string authTypeAsString() { return _auth_type_str; } const
00125 
00126   std::string getUserPwd() const { return username() + ":" + password(); }
00127 
00128 
00138   static long auth_type_str2long(std::string & auth_type_str);
00139 
00144   static std::string auth_type_long2str(long auth_type);
00145 
00146   virtual std::ostream & dumpOn( std::ostream & str ) const;
00147 
00148 private:
00149   std::string _auth_type_str;
00150   long _auth_type;
00151 };
00152 
00153 typedef shared_ptr<CurlAuthData> CurlAuthData_Ptr;
00154 
00155 std::ostream & operator << (std::ostream & str, const AuthData & auth_data);
00156 std::ostream & operator << (std::ostream & str, const CurlAuthData & auth_data);
00157 
00159 
00160   } // namespace media
00161 } // namespace zypp
00162 
00163 #endif // ZYPP_MEDIA_USER_AUTH_H