libzypp: zypp/zypp_detail/urlcredentialextractor_p.h Source File

libzypp 17.38.13

urlcredentialextractor_p.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12
13#ifndef ZYPP_ZYPP_DETAIL_URLCREDENTIALEXTRACTOR_P_H
14#define ZYPP_ZYPP_DETAIL_URLCREDENTIALEXTRACTOR_P_H
15
16#include <zypp-core/Url.h>
17#include <zypp-core/MirroredOrigin.h>
18#include <zypp-media/auth/CredentialManager>
19
20namespace zypp
21{
43 class UrlCredentialExtractor
44 {
45 public:
46 UrlCredentialExtractor( const Pathname & root_r )
47 : _root( root_r )
48 {}
49
50 UrlCredentialExtractor( Pathname & root_r )
51 : _root( root_r )
52 {}
53
54 ~UrlCredentialExtractor()
55 { if ( _cmPtr ) _cmPtr->save(); }
56
58 bool collect( const Url & url_r )
59 {
60 bool ret = url_r.hasCredentialsInAuthority();
61 if ( ret )
62 {
63 if ( !_cmPtr ) _cmPtr.reset( new media::CredentialManager( _root ) );
64 _cmPtr->addUserCred( url_r );
65 }
66 return ret;
67 }
68
70 bool collect( const OriginEndpoint & url_r )
71 {
72 return collect(url_r.url());
73 }
74
76 template<class TContainer>
77 bool collect( const TContainer & urls_r )
78 { bool ret = false; for ( const Url & url : urls_r ) { if ( collect( url ) && !ret ) ret = true; } return ret; }
79
81 bool extract( Url & url_r )
82 {
83 bool ret = collect( url_r );
84 if ( ret )
85 url_r.setPassword( std::string() );
86 return ret;
87 }
88
89 template<class TContainer>
90 bool extract( TContainer & urls_r )
91 { bool ret = false; for ( Url & url : urls_r ) { if ( extract( url ) && !ret ) ret = true; } return ret; }
92
93 private:
94 const Pathname & _root;
95 scoped_ptr<media::CredentialManager> _cmPtr;
96 };
97}
98
99#endif
MirroredOrigin.h
Url.h
scoped_ptr
zypp::OriginEndpoint
Represents a single, configurable network endpoint, combining a URL with specific access settings.
Definition MirroredOrigin.h:41
zypp::OriginEndpoint::url
const zypp::Url & url() const
Definition MirroredOrigin.cc:53
zypp::UrlCredentialExtractor::extract
bool extract(Url &url_r)
Remember credentials stored in URL authority stripping the passowrd from url_r.
Definition urlcredentialextractor_p.h:81
zypp::UrlCredentialExtractor::~UrlCredentialExtractor
~UrlCredentialExtractor()
Definition urlcredentialextractor_p.h:54
zypp::UrlCredentialExtractor::extract
bool extract(TContainer &urls_r)
Definition urlcredentialextractor_p.h:90
zypp::UrlCredentialExtractor::collect
bool collect(const TContainer &urls_r)
Definition urlcredentialextractor_p.h:77
zypp::UrlCredentialExtractor::collect
bool collect(const Url &url_r)
Remember credentials stored in URL authority leaving the password in url_r.
Definition urlcredentialextractor_p.h:58
zypp::UrlCredentialExtractor::_root
const Pathname & _root
Definition urlcredentialextractor_p.h:94
zypp::UrlCredentialExtractor::collect
bool collect(const OriginEndpoint &url_r)
Remember credentials stored in OriginEndpoint authority leaving the password in url_r.
Definition urlcredentialextractor_p.h:70
zypp::UrlCredentialExtractor::_cmPtr
scoped_ptr< media::CredentialManager > _cmPtr
Definition urlcredentialextractor_p.h:95
zypp::UrlCredentialExtractor::UrlCredentialExtractor
UrlCredentialExtractor(Pathname &root_r)
Definition urlcredentialextractor_p.h:50
zypp::UrlCredentialExtractor::UrlCredentialExtractor
UrlCredentialExtractor(const Pathname &root_r)
Definition urlcredentialextractor_p.h:46
zypp::Url
Url manipulation class.
Definition Url.h:93
zypp::Url::setPassword
void setPassword(const std::string &pass, EEncoding eflag=zypp::url::E_DECODED)
Set the password in the URL authority.
Definition Url.cc:766
zypp::Url::hasCredentialsInAuthority
bool hasCredentialsInAuthority() const
Returns true if username and password are encoded in the authority component.
Definition Url.h:397
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
zypp::media::CredentialManager
Definition credentialmanager.h:64
zypp::url
Url details namespace.
Definition UrlBase.cc:58
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2