libzypp: zypp-media/auth/authdata.cc Source File

libzypp 17.38.10

authdata.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12
13#include "authdata.h"
14#include <zypp-core/base/String.h>
15
16using std::endl;
17
18namespace zypp {
19 namespace media {
20
21
22 AuthData::AuthData(const Url & url)
23 : _url(url), _lastChange(0)
24{
25 _username = url.getUsername();
26 _password = url.getPassword();
27}
28
29
30 bool AuthData::valid() const
31{
32 return username().size() && password().size();
33}
34
35time_t AuthData::lastDatabaseUpdate() const
36{
37 return _lastChange;
38}
39
40 void AuthData::setLastDatabaseUpdate( time_t time )
41{
42 _lastChange = time;
43}
44
45 const std::map<std::string, std::string> &AuthData::extraValues() const
46{
47 return _extraValues;
48}
49
50std::map<std::string, std::string> &AuthData::extraValues()
51{
52 return _extraValues;
53}
54
55std::ostream & AuthData::dumpOn( std::ostream & str ) const
56{
57 if (_url.isValid())
58 str << "[" << _url.asString( url::ViewOptions() - url::ViewOptions::WITH_USERNAME - url::ViewOptions::WITH_PASSWORD ) << "]" << endl;
59 else
60 str << "[<no-url>]" << endl;
61 str << "username: '" << _username << "'" << std::endl
62 << "password: " << (_password.empty() ? "<empty>" : "<non-empty>");
63 return str;
64}
65
66std::ostream & AuthData::dumpAsIniOn( std::ostream & str ) const
67{
68 if (_url.isValid())
69 str
70 << "[" << _url.asString(
71 url::ViewOptions()
72 - url::ViewOptions::WITH_USERNAME
73 - url::ViewOptions::WITH_PASSWORD)
74 << "]" << endl;
75
76 str
77 << "username = " << _username << endl
78 << "password = " << _password << endl;
79
80 for ( const auto &v : _extraValues ) {
81 if ( v.first == "username" || v.first == "password" )
82 continue;
83 str << v.first << " = " << v.second << endl;
84 }
85
86 return str;
87}
88
89std::ostream & operator << (std::ostream & str, const AuthData & auth_data)
90{
91 auth_data.dumpOn(str);
92 return str;
93}
94
95 } // namespace media
96} // namespace zypp
String.h
zypp::Url
Url manipulation class.
Definition Url.h:93
zypp::media::AuthData
Class for handling media authentication data.
Definition authdata.h:31
zypp::media::AuthData::dumpAsIniOn
virtual std::ostream & dumpAsIniOn(std::ostream &str) const
Definition authdata.cc:66
zypp::media::AuthData::password
std::string password() const
Definition authdata.h:57
zypp::media::AuthData::lastDatabaseUpdate
time_t lastDatabaseUpdate() const
Definition authdata.cc:35
zypp::media::AuthData::_url
Url _url
Definition authdata.h:74
zypp::media::AuthData::valid
virtual bool valid() const
Checks validity of authentication data.
Definition authdata.cc:30
zypp::media::AuthData::url
Url url() const
Definition authdata.h:55
zypp::media::AuthData::setLastDatabaseUpdate
void setLastDatabaseUpdate(time_t time)
Definition authdata.cc:40
zypp::media::AuthData::_lastChange
time_t _lastChange
Definition authdata.h:77
zypp::media::AuthData::_extraValues
std::map< std::string, std::string > _extraValues
Definition authdata.h:78
zypp::media::AuthData::dumpOn
virtual std::ostream & dumpOn(std::ostream &str) const
Definition authdata.cc:55
zypp::media::AuthData::extraValues
const std::map< std::string, std::string > & extraValues() const
Definition authdata.cc:45
zypp::media::AuthData::AuthData
AuthData()
Definition authdata.h:33
zypp::media::AuthData::_username
std::string _username
Definition authdata.h:75
zypp::media::AuthData::username
std::string username() const
Definition authdata.h:56
zypp::media::AuthData::_password
std::string _password
Definition authdata.h:76
str
String related utilities and Regular expression matching.
zypp::media
Definition MediaNetworkRequestExecutor.h:22
zypp::media::operator<<
std::ostream & operator<<(std::ostream &str, const MediaHandler &obj)
Definition MediaHandler.cc:1181
zypp::url::ViewOptions
ViewOption ViewOptions
ViewOptions is just an alias for ViewOption.
Definition UrlBase.h:245
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
authdata.h