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 <curl/curl.h>
00016 
00017 namespace zypp {
00018   namespace media {
00019 
00021 
00022 
00027 class AuthData
00028 {
00029 public:
00030   AuthData() : _username(), _password()
00031   {}
00032 
00033   AuthData(std::string & username, std::string & password)
00034     : _username(username), _password(password)
00035   {}
00036 
00037   virtual ~AuthData() {};
00038 
00044   virtual bool valid() const;
00045 
00046   void setUserName(std::string username) { _username = username; }
00047   void setPassword(std::string password) { _password = password; }  
00048 
00049   std::string username() const { return _username; }
00050   std::string password() const { return _password; } 
00051 
00052   virtual std::ostream & dumpOn( std::ostream & str ) const;
00053 
00054 
00055 private:
00056   std::string _username;
00057   std::string _password;
00058 };
00059 
00063 class CurlAuthData : public AuthData {
00064 public:
00069   CurlAuthData() : AuthData(), _auth_type_str(), _auth_type(CURLAUTH_NONE)
00070   {}
00071 
00072   CurlAuthData(std::string & username, std::string & password, std::string & auth_type)
00073     : AuthData(username,password), _auth_type_str(auth_type)
00074   {
00075     _auth_type = auth_type_str2long(auth_type);
00076   }
00077 
00078   CurlAuthData(std::string & username, std::string & password, long auth_type)
00079     : AuthData(username,password), _auth_type(auth_type)
00080   {
00081     _auth_type_str = auth_type_long2str(auth_type);
00082   }
00083 
00089   virtual bool valid() const;
00090 
00095   void setAuthType(std::string auth_type)
00096   {
00097     _auth_type_str = auth_type; _auth_type = auth_type_str2long(auth_type);
00098   }
00099 
00100   /*
00101    * Set HTTP authentication type(s) to use.
00102    * \param HTTP authentication type as in long ORed form.
00103    * \see curl.h for available auth types
00104    */
00105   void setAuthType(long auth_type)
00106   {
00107     _auth_type = auth_type;
00108     _auth_type_str = auth_type_long2str(auth_type);
00109   }
00110 
00111   long authType() { return _auth_type; } const
00112   std::string authTypeAsString() { return _auth_type_str; } const
00113 
00114   std::string getUserPwd() const { return username() + ":" + password(); } 
00115 
00116 
00126   static long auth_type_str2long(std::string & auth_type_str);
00127 
00132   static std::string auth_type_long2str(long auth_type);
00133 
00134   virtual std::ostream & dumpOn( std::ostream & str ) const;
00135 
00136 private:
00137   std::string _auth_type_str;
00138   long _auth_type;
00139 };
00140 
00141 
00142 std::ostream & operator << (std::ostream & str, AuthData & auth_data);
00143 std::ostream & operator << (std::ostream & str, CurlAuthData & auth_data);
00144 
00146 
00147   } // namespace media
00148 } // namespace zypp
00149 
00150 #endif // ZYPP_MEDIA_USER_AUTH_H

Generated on Tue Sep 25 19:23:02 2007 for libzypp by  doxygen 1.5.3