libzypp  17.31.31
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 
16 using std::endl;
17 
18 namespace zypp {
19  namespace media {
20 
21 
22 AuthData::AuthData(const Url & url)
23  : _url(url), _lastChange(0)
24 {
27 }
28 
29 
30 bool AuthData::valid() const
31 {
32  return username().size() && password().size();
33 }
34 
36 {
37  return _lastChange;
38 }
39 
41 {
42  _lastChange = time;
43 }
44 
45 const std::map<std::string, std::string> &AuthData::extraValues() const
46 {
47  return _extraValues;
48 }
49 
50 std::map<std::string, std::string> &AuthData::extraValues()
51 {
52  return _extraValues;
53 }
54 
55 std::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 
66 std::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 
89 std::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
void setLastDatabaseUpdate(time_t time)
Definition: authdata.cc:40
static const ViewOption WITH_USERNAME
Option to include username in the URL string.
Definition: UrlBase.h:58
std::string password() const
Definition: authdata.h:55
std::ostream & operator<<(std::ostream &str, const MediaHandler &obj)
std::map< std::string, std::string > _extraValues
Definition: authdata.h:76
std::string _username
Definition: authdata.h:73
String related utilities and Regular expression matching.
time_t lastDatabaseUpdate() const
Definition: authdata.cc:35
Url::asString() view options.
Definition: UrlBase.h:39
virtual std::ostream & dumpOn(std::ostream &str) const
Definition: authdata.cc:55
std::string asString() const
Returns a default string representation of the Url object.
Definition: Url.cc:497
std::string username() const
Definition: authdata.h:54
Url url() const
Definition: authdata.h:53
bool isValid() const
Verifies the Url.
Definition: Url.cc:489
Class for handling media authentication data.
Definition: authdata.h:28
virtual bool valid() const
Checks validity of authentication data.
Definition: authdata.cc:30
virtual std::ostream & dumpAsIniOn(std::ostream &str) const
Definition: authdata.cc:66
static const ViewOption WITH_PASSWORD
Option to include password in the URL string.
Definition: UrlBase.h:67
const std::map< std::string, std::string > & extraValues() const
Definition: authdata.cc:45
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
time_t _lastChange
std::string _password
Definition: authdata.h:74
std::string getPassword(EEncoding eflag=zypp::url::E_DECODED) const
Returns the password from the URL authority.
Definition: Url.cc:580
Url manipulation class.
Definition: Url.h:91
std::string getUsername(EEncoding eflag=zypp::url::E_DECODED) const
Returns the username from the URL authority.
Definition: Url.cc:572