libzypp 17.31.23
authdata.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
13#include "authdata.h"
14#include <zypp-core/base/String.h>
15
16using std::endl;
17
18namespace zypp {
19 namespace media {
20
21
23 : _url(url), _lastChange(0)
24{
27}
28
29
30bool AuthData::valid() const
31{
32 return username().size() && password().size();
33}
34
36{
37 return _lastChange;
38}
39
41{
42 _lastChange = time;
43}
44
45const 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())
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(
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
Url manipulation class.
Definition: Url.h:92
std::string asString() const
Returns a default string representation of the Url object.
Definition: Url.cc:497
std::string getUsername(EEncoding eflag=zypp::url::E_DECODED) const
Returns the username from the URL authority.
Definition: Url.cc:572
bool isValid() const
Verifies the Url.
Definition: Url.cc:489
std::string getPassword(EEncoding eflag=zypp::url::E_DECODED) const
Returns the password from the URL authority.
Definition: Url.cc:580
Class for handling media authentication data.
Definition: authdata.h:29
virtual std::ostream & dumpAsIniOn(std::ostream &str) const
Definition: authdata.cc:66
std::string password() const
Definition: authdata.h:55
time_t lastDatabaseUpdate() const
Definition: authdata.cc:35
virtual bool valid() const
Checks validity of authentication data.
Definition: authdata.cc:30
Url url() const
Definition: authdata.h:53
void setLastDatabaseUpdate(time_t time)
Definition: authdata.cc:40
std::map< std::string, std::string > _extraValues
Definition: authdata.h:76
virtual std::ostream & dumpOn(std::ostream &str) const
Definition: authdata.cc:55
const std::map< std::string, std::string > & extraValues() const
Definition: authdata.cc:45
std::string _username
Definition: authdata.h:73
std::string username() const
Definition: authdata.h:54
std::string _password
Definition: authdata.h:74
time_t _lastChange
String related utilities and Regular expression matching.
std::ostream & operator<<(std::ostream &str, const MediaHandler &obj)
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
Url::asString() view options.
Definition: UrlBase.h:40
static const ViewOption WITH_PASSWORD
Option to include password in the URL string.
Definition: UrlBase.h:67
static const ViewOption WITH_USERNAME
Option to include username in the URL string.
Definition: UrlBase.h:58