libzypp 17.37.17
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>
19
20namespace zypp
21{
44 {
45 public:
47 : _root( root_r )
48 {}
49
51 : _root( root_r )
52 {}
53
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;
96 };
97}
98
99#endif
Represents a single, configurable network endpoint, combining a URL with specific access settings.
const zypp::Url & url() const
bool extract(Url &url_r)
Remember credentials stored in URL authority stripping the passowrd from url_r.
bool collect(const TContainer &urls_r)
bool collect(const Url &url_r)
Remember credentials stored in URL authority leaving the password in url_r.
bool collect(const OriginEndpoint &url_r)
Remember credentials stored in OriginEndpoint authority leaving the password in url_r.
scoped_ptr< media::CredentialManager > _cmPtr
UrlCredentialExtractor(const Pathname &root_r)
Url manipulation class.
Definition Url.h:93
void setPassword(const std::string &pass, EEncoding eflag=zypp::url::E_DECODED)
Set the password in the URL authority.
Definition Url.cc:757
bool hasCredentialsInAuthority() const
Returns true if username and password are encoded in the authority component.
Definition Url.h:393
Url details namespace.
Definition UrlBase.cc:58
Easy-to use interface to the ZYPP dependency resolver.