libzypp  17.23.8
MediaUserAuth.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_MEDIA_USER_AUTH_H
13 #define ZYPP_MEDIA_USER_AUTH_H
14 
15 #include <zypp/APIConfig.h>
16 
17 #include <zypp/Url.h>
18 #include <zypp/base/PtrTypes.h>
19 
20 namespace zypp {
21  namespace media {
22 
24 
25 
30 class AuthData
31 {
32 public:
34  {}
35 
36  AuthData(const Url & url);
37 
38  AuthData(const std::string & username, const std::string & password)
40  {}
41 
42  virtual ~AuthData() {};
43 
49  virtual bool valid() const;
50 
51  void setUrl(const Url & url) { _url = url; }
52  void setUsername(const std::string & username) { _username = username; }
53  void setPassword(const std::string & password) { _password = password; }
54 
55  Url url() const { return _url; }
56  std::string username() const { return _username; }
57  std::string password() const { return _password; }
58 
59  virtual std::ostream & dumpOn( std::ostream & str ) const;
60 
61  virtual std::ostream & dumpAsIniOn( std::ostream & str ) const;
62 
63 private:
65  std::string _username;
66  std::string _password;
67 };
68 
69 typedef shared_ptr<AuthData> AuthData_Ptr;
70 
74 class CurlAuthData : public AuthData {
75 public:
80  CurlAuthData();
81 
82  CurlAuthData(const AuthData & authData);
83 
84  CurlAuthData(std::string & username, std::string & password, std::string & auth_type)
86  {
87  _auth_type = auth_type_str2long(auth_type);
88  }
89 
90  CurlAuthData(std::string & username, std::string & password, long auth_type)
91  : AuthData(username,password), _auth_type(auth_type)
92  {
94  }
95 
101  virtual bool valid() const;
102 
107  void setAuthType(std::string auth_type)
108  {
109  _auth_type_str = auth_type; _auth_type = auth_type_str2long(auth_type);
110  }
111 
112  /*
113  * Set HTTP authentication type(s) to use.
114  * \param HTTP authentication type as in long ORed form.
115  * \see curl.h for available auth types
116  */
117  void setAuthType(long auth_type)
118  {
119  _auth_type = auth_type;
120  _auth_type_str = auth_type_long2str(auth_type);
121  }
122 
123  long authType() const { return _auth_type; }
124  std::string authTypeAsString() const { return _auth_type_str; }
125 
126  std::string getUserPwd() const { return username() + ":" + password(); }
127 
128 
138  static long auth_type_str2long(std::string & auth_type_str);
139 
144  static std::string auth_type_long2str(long auth_type);
145 
146  virtual std::ostream & dumpOn( std::ostream & str ) const;
147 
148 private:
149  std::string _auth_type_str;
151 };
152 
153 typedef shared_ptr<CurlAuthData> CurlAuthData_Ptr;
154 
155 std::ostream & operator << (std::ostream & str, const AuthData & auth_data);
156 std::ostream & operator << (std::ostream & str, const CurlAuthData & auth_data);
157 
159 
160  } // namespace media
161 } // namespace zypp
162 
163 #endif // ZYPP_MEDIA_USER_AUTH_H
zypp::media::AuthData
Class for handling media authentication data.
Definition: MediaUserAuth.h:30
zypp::media::CurlAuthData::setAuthType
void setAuthType(std::string auth_type)
Set HTTP authentication type(s) to use.
Definition: MediaUserAuth.h:107
zypp::media::CurlAuthData::setAuthType
void setAuthType(long auth_type)
Definition: MediaUserAuth.h:117
zypp::media::CurlAuthData::getUserPwd
std::string getUserPwd() const
Definition: MediaUserAuth.h:126
zypp::media::AuthData::valid
virtual bool valid() const
Checks validity of authentication data.
Definition: MediaUserAuth.cc:36
zypp::media::AuthData::_url
Url _url
Definition: MediaUserAuth.h:64
zypp::media::CurlAuthData::_auth_type
long _auth_type
Definition: MediaUserAuth.h:150
zypp::media::AuthData::url
Url url() const
Definition: MediaUserAuth.h:55
zypp::media::CurlAuthData::authTypeAsString
std::string authTypeAsString() const
Definition: MediaUserAuth.h:124
PtrTypes.h
zypp::media::AuthData::setUrl
void setUrl(const Url &url)
Definition: MediaUserAuth.h:51
zypp::media::operator<<
std::ostream & operator<<(std::ostream &str, const MediaAccess &obj)
Definition: MediaAccess.cc:481
Url.h
zypp::media::AuthData::_password
std::string _password
Definition: MediaUserAuth.h:66
zypp::media::CurlAuthData::CurlAuthData
CurlAuthData(std::string &username, std::string &password, std::string &auth_type)
Definition: MediaUserAuth.h:84
zypp::media::AuthData::dumpOn
virtual std::ostream & dumpOn(std::ostream &str) const
Definition: MediaUserAuth.cc:41
zypp::media::AuthData::username
std::string username() const
Definition: MediaUserAuth.h:56
zypp::media::AuthData::_username
std::string _username
Definition: MediaUserAuth.h:65
zypp::media::CurlAuthData_Ptr
shared_ptr< CurlAuthData > CurlAuthData_Ptr
Definition: MediaUserAuth.h:153
zypp::media::CurlAuthData::dumpOn
virtual std::ostream & dumpOn(std::ostream &str) const
Definition: MediaUserAuth.cc:86
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::media::AuthData::setUsername
void setUsername(const std::string &username)
Definition: MediaUserAuth.h:52
zypp::media::CurlAuthData::authType
long authType() const
Definition: MediaUserAuth.h:123
zypp::media::AuthData::setPassword
void setPassword(const std::string &password)
Definition: MediaUserAuth.h:53
zypp::media::CurlAuthData::auth_type_long2str
static std::string auth_type_long2str(long auth_type)
Converts a long of ORed CURLAUTH_* identifiers into a string of comma separated list of authenticatio...
Definition: MediaUserAuth.cc:142
zypp::media::AuthData::AuthData
AuthData(const std::string &username, const std::string &password)
Definition: MediaUserAuth.h:38
zypp::media::CurlAuthData::CurlAuthData
CurlAuthData()
Default constructor.
Definition: MediaUserAuth.cc:69
zypp::media::CurlAuthData
Curl HTTP authentication data.
Definition: MediaUserAuth.h:74
zypp::media::CurlAuthData::CurlAuthData
CurlAuthData(std::string &username, std::string &password, long auth_type)
Definition: MediaUserAuth.h:90
zypp::media::AuthData_Ptr
shared_ptr< AuthData > AuthData_Ptr
Definition: MediaUserAuth.h:69
zypp::media::AuthData::dumpAsIniOn
virtual std::ostream & dumpAsIniOn(std::ostream &str) const
Definition: MediaUserAuth.cc:52
zypp::media::AuthData::password
std::string password() const
Definition: MediaUserAuth.h:57
zypp::media::CurlAuthData::auth_type_str2long
static long auth_type_str2long(std::string &auth_type_str)
Converts a string of comma separated list of authetication type names into a long of ORed CURLAUTH_* ...
Definition: MediaUserAuth.cc:93
str
String related utilities and Regular expression matching.
zypp::media::AuthData::AuthData
AuthData()
Definition: MediaUserAuth.h:33
zypp::media::CurlAuthData::valid
virtual bool valid() const
Checks validity of authentication data.
Definition: MediaUserAuth.cc:81
zypp::Url
Url manipulation class.
Definition: Url.h:87
zypp::media::CurlAuthData::_auth_type_str
std::string _auth_type_str
Definition: MediaUserAuth.h:149
zypp::media::AuthData::~AuthData
virtual ~AuthData()
Definition: MediaUserAuth.h:42