libzypp 17.28.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
20namespace zypp {
21 namespace media {
22
24
25
31{
32public:
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
63 time_t lastDatabaseUpdate () const;
64 void setLastDatabaseUpdate ( time_t time );
65
66 virtual std::ostream & dumpOn( std::ostream & str ) const;
67
68 virtual std::ostream & dumpAsIniOn( std::ostream & str ) const;
69
70private:
72 std::string _username;
73 std::string _password;
74 time_t _lastChange; //< timestamp of the last change to the database this credential is stored in
75};
76
77typedef shared_ptr<AuthData> AuthData_Ptr;
78
82class CurlAuthData : public AuthData {
83public:
89
90 CurlAuthData(const AuthData & authData);
91
92 CurlAuthData(std::string & username, std::string & password, std::string & auth_type)
94 {
95 _auth_type = auth_type_str2long(auth_type);
96 }
97
98 CurlAuthData(std::string & username, std::string & password, long auth_type)
100 {
102 }
103
109 virtual bool valid() const;
110
115 void setAuthType(std::string auth_type)
116 {
117 _auth_type_str = auth_type; _auth_type = auth_type_str2long(auth_type);
118 }
119
120 /*
121 * Set HTTP authentication type(s) to use.
122 * \param HTTP authentication type as in long ORed form.
123 * \see curl.h for available auth types
124 */
125 void setAuthType(long auth_type)
126 {
127 _auth_type = auth_type;
129 }
130
131 long authType() const { return _auth_type; }
132 std::string authTypeAsString() const { return _auth_type_str; }
133
134 std::string getUserPwd() const { return username() + ":" + password(); }
135
136
146 static long auth_type_str2long( std::string & auth_type_str );
147 static long auth_type_str2long( const std::string &auth_type_str );
148
153 static std::string auth_type_long2str(long auth_type);
154
155 virtual std::ostream & dumpOn( std::ostream & str ) const;
156
157private:
158 std::string _auth_type_str;
160};
161
162typedef shared_ptr<CurlAuthData> CurlAuthData_Ptr;
163
164std::ostream & operator << (std::ostream & str, const AuthData & auth_data);
165std::ostream & operator << (std::ostream & str, const CurlAuthData & auth_data);
166
168
169 } // namespace media
170} // namespace zypp
171
172#endif // ZYPP_MEDIA_USER_AUTH_H
Url manipulation class.
Definition: Url.h:92
Class for handling media authentication data.
Definition: MediaUserAuth.h:31
virtual std::ostream & dumpAsIniOn(std::ostream &str) const
std::string password() const
Definition: MediaUserAuth.h:57
time_t lastDatabaseUpdate() const
void setUsername(const std::string &username)
Definition: MediaUserAuth.h:52
virtual bool valid() const
Checks validity of authentication data.
void setPassword(const std::string &password)
Definition: MediaUserAuth.h:53
void setLastDatabaseUpdate(time_t time)
AuthData(const std::string &username, const std::string &password)
Definition: MediaUserAuth.h:38
virtual std::ostream & dumpOn(std::ostream &str) const
void setUrl(const Url &url)
Definition: MediaUserAuth.h:51
std::string username() const
Definition: MediaUserAuth.h:56
Curl HTTP authentication data.
Definition: MediaUserAuth.h:82
std::string authTypeAsString() const
CurlAuthData(std::string &username, std::string &password, long auth_type)
Definition: MediaUserAuth.h:98
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...
void setAuthType(long auth_type)
CurlAuthData(std::string &username, std::string &password, std::string &auth_type)
Definition: MediaUserAuth.h:92
virtual std::ostream & dumpOn(std::ostream &str) const
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_* ...
CurlAuthData()
Default constructor.
void setAuthType(std::string auth_type)
Set HTTP authentication type(s) to use.
std::string getUserPwd() const
virtual bool valid() const
Checks validity of authentication data.
String related utilities and Regular expression matching.
shared_ptr< CurlAuthData > CurlAuthData_Ptr
std::ostream & operator<<(std::ostream &str, const MediaBlockList &bl)
shared_ptr< AuthData > AuthData_Ptr
Definition: MediaUserAuth.h:77
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2