libzypp 8.13.6
|
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 #include "zypp/base/Deprecated.h" 00018 00019 #include "zypp/Url.h" 00020 #include "zypp/base/PtrTypes.h" 00021 00022 namespace zypp { 00023 namespace media { 00024 00026 00027 00032 class AuthData 00033 { 00034 public: 00035 AuthData() 00036 {} 00037 00038 AuthData(const Url & url); 00039 00040 AuthData(const std::string & username, const std::string & password) 00041 : _username(username), _password(password) 00042 {} 00043 00044 virtual ~AuthData() {}; 00045 00051 virtual bool valid() const; 00052 00053 void setUrl(const Url & url) { _url = url; } 00054 void setUsername(const std::string & username) { _username = username; } 00055 void setPassword(const std::string & password) { _password = password; } 00056 00057 Url url() const { return _url; } 00058 std::string username() const { return _username; } 00059 std::string password() const { return _password; } 00060 00061 virtual std::ostream & dumpOn( std::ostream & str ) const; 00062 00063 virtual std::ostream & dumpAsIniOn( std::ostream & str ) const; 00064 00065 private: 00066 Url _url; 00067 std::string _username; 00068 std::string _password; 00069 }; 00070 00071 typedef shared_ptr<AuthData> AuthData_Ptr; 00072 00076 class CurlAuthData : public AuthData { 00077 public: 00082 CurlAuthData() : AuthData(), _auth_type_str(), _auth_type(CURLAUTH_NONE) 00083 {} 00084 00085 CurlAuthData(const AuthData & authData) 00086 : AuthData(authData) 00087 , _auth_type_str() 00088 , _auth_type(CURLAUTH_NONE) 00089 {} 00090 00091 CurlAuthData(std::string & username, std::string & password, std::string & auth_type) 00092 : AuthData(username,password), _auth_type_str(auth_type) 00093 { 00094 _auth_type = auth_type_str2long(auth_type); 00095 } 00096 00097 CurlAuthData(std::string & username, std::string & password, long auth_type) 00098 : AuthData(username,password), _auth_type(auth_type) 00099 { 00100 _auth_type_str = auth_type_long2str(auth_type); 00101 } 00102 00108 virtual bool valid() const; 00109 00114 void setAuthType(std::string auth_type) 00115 { 00116 _auth_type_str = auth_type; _auth_type = auth_type_str2long(auth_type); 00117 } 00118 00119 /* 00120 * Set HTTP authentication type(s) to use. 00121 * \param HTTP authentication type as in long ORed form. 00122 * \see curl.h for available auth types 00123 */ 00124 void setAuthType(long auth_type) 00125 { 00126 _auth_type = auth_type; 00127 _auth_type_str = auth_type_long2str(auth_type); 00128 } 00129 00130 long authType() { return _auth_type; } const 00131 std::string authTypeAsString() { return _auth_type_str; } const 00132 00133 std::string getUserPwd() const { return username() + ":" + password(); } 00134 00135 00145 static long auth_type_str2long(std::string & auth_type_str); 00146 00151 static std::string auth_type_long2str(long auth_type); 00152 00153 virtual std::ostream & dumpOn( std::ostream & str ) const; 00154 00155 private: 00156 std::string _auth_type_str; 00157 long _auth_type; 00158 }; 00159 00160 typedef shared_ptr<CurlAuthData> CurlAuthData_Ptr; 00161 00162 std::ostream & operator << (std::ostream & str, const AuthData & auth_data); 00163 std::ostream & operator << (std::ostream & str, const CurlAuthData & auth_data); 00164 00166 00167 } // namespace media 00168 } // namespace zypp 00169 00170 #endif // ZYPP_MEDIA_USER_AUTH_H