14#undef ZYPP_BASE_LOGGER_LOGGROUP
15#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::MirroredOrigin"
32 std::unordered_map<std::string, std::any>
_settings;
41 : _pimpl( new Private(
std::move(url),
std::move(settings) ) )
65 return (
_pimpl->_settings.count (key) > 0);
70 return _pimpl->_url.getScheme();
75 return _pimpl->_url.schemeIsDownloading ();
80 return _pimpl->_url.isValid();
83 void OriginEndpoint::setConfig(
const std::string &key, std::any value)
85 _pimpl->_settings.insert_or_assign ( key, std::move(value) );
88 const std::any &OriginEndpoint::getConfig(
const std::string &key)
const
90 return _pimpl->_settings.at(key);
93 std::any &OriginEndpoint::getConfig(
const std::string &key)
95 return _pimpl->_settings.at(key);
98 void OriginEndpoint::eraseConfigValue(
const std::string &key )
100 auto it =
_pimpl->_settings.find (key);
101 if ( it ==
_pimpl->_settings.end() )
103 _pimpl->_settings.erase(it);
106 const OriginEndpoint::SettingsMap &OriginEndpoint::config()
const
112 OriginEndpoint::SettingsMap &OriginEndpoint::config()
120 return str <<
url.url().asString();
165 WAR <<
"Ignoring invalid authority in constructor: " <<
authority << std::endl;
167 for(
auto &m :
mirrors ) { addMirror ( std::move(m) ); }
174 WAR <<
"Skipping authority " << newAuthority <<
", is NOT valid" << std::endl;
178 const auto &newScheme = newAuthority.
scheme();
181 _pimpl->_authorities.clear();
182 _pimpl->_authorities.push_back( std::move(newAuthority) );
184 if ( !
_pimpl->authoritiesAreValid() || !
_pimpl->_origins.size () )
188 for (
auto i =
_pimpl->_origins.begin (); i !=
_pimpl->_origins.end(); ) {
189 if ( ( newAuthIsDl && !i->schemeIsDownloading() )
190 && ( i->scheme () != newScheme )
192 MIL <<
"Dropping mirror " << *i <<
" scheme is not compatible to new authority URL ( " << i->scheme() <<
" vs " << newScheme <<
")" << std::endl;
193 i =
_pimpl->_origins.erase(i);
202 return _pimpl->_authorities;
207 if (
_pimpl->_authorities.empty()) {
211 return _pimpl->_authorities[0];
221 return _pimpl->authoritiesAreValid();
227 MIL <<
"Skipping authority " << newAuthority <<
", is NOT valid" << std::endl;
231 if (
_pimpl->authoritiesAreValid() ) {
232 const auto &authScheme =
_pimpl->_authorities[0].scheme();
233 bool authIsDl =
_pimpl->_authorities[0].schemeIsDownloading();
236 && ( authScheme != newAuthority.
scheme () )
238 MIL <<
"Ignoring authority " << newAuthority <<
" scheme is not compatible to current authority URL ( " << newAuthority.
scheme() <<
" vs " << authScheme <<
")" << std::endl;
243 if (std::find(
_pimpl->_authorities.begin(),
_pimpl->_authorities.end(), newAuthority) !=
_pimpl->_authorities.end()) {
244 MIL <<
"Ignoring authority " << newAuthority <<
" already present in authorities" << std::endl;
248 _pimpl->_authorities.push_back( std::move(newAuthority) );
255 MIL <<
"Ignoring mirror " << newMirror <<
" is not valid" << std::endl;
259 if (
_pimpl->authoritiesAreValid() ) {
260 const auto &authScheme =
_pimpl->_authorities[0].scheme();
261 bool authIsDl =
_pimpl->_authorities[0].schemeIsDownloading();
264 && ( authScheme != newMirror.
scheme () )
266 MIL <<
"Ignoring mirror " << newMirror <<
" scheme is not compatible to authority URL ( " << newMirror.
scheme() <<
" vs " << authScheme <<
")" << std::endl;
271 if (std::find(
_pimpl->_authorities.begin(),
_pimpl->_authorities.end(), newMirror) !=
_pimpl->_authorities.end()) {
272 MIL <<
"Ignoring mirror " << newMirror <<
" already present in authorities" << std::endl;
276 if (std::find(
_pimpl->_origins.begin(),
_pimpl->_origins.end(), newMirror) !=
_pimpl->_origins.end()) {
277 MIL <<
"Ignoring mirror " << newMirror <<
" already present in mirrors" << std::endl;
281 _pimpl->_origins.push_back( std::move(newMirror) );
299 if (
_pimpl->_authorities.empty() )
300 return std::string();
301 return _pimpl->_authorities[0].url().getScheme();
306 if (
_pimpl->_authorities.empty() )
308 return _pimpl->_authorities[0].schemeIsDownloading();
313 return _pimpl->_authorities.size() +
_pimpl->_origins.size();
318 return _pimpl->_authorities.size();
324 throw std::out_of_range(
"OriginEndpoint index out of range." );
326 if ( index < _pimpl->_authorities.size() ) {
327 return _pimpl->_authorities[index];
330 return _pimpl->_origins.at( index -
_pimpl->_authorities.size() );
336 throw std::out_of_range(
"OriginEndpoint index out of range." );
338 if ( index < _pimpl->_authorities.size() ) {
339 return _pimpl->_authorities[index];
342 return _pimpl->_origins.at( index -
_pimpl->_authorities.size() );
373 for(
auto &
url: urls )
380 for(
auto &
url: urls )
386 return _pimpl->_origins.at(idx);
391 return _pimpl->_origins.at(idx);
396 str <<
"MirroredOrigin { ";
405 for (
auto i =
begin(); i!=
end(); i++ ) {
406 auto epI = std::find_if( i->begin (), i->end(), [&](
const OriginEndpoint &ep){ return ep.url () == url; } );
407 if ( epI != i->end() )
415 for (
auto i =
begin(); i!=
end(); i++ ) {
416 auto epI = std::find_if( i->begin (), i->end(), [&](
const OriginEndpoint &ep){ return ep.url () == url; } );
417 if ( epI != i->end() )
431 _pimpl->_origins.at(*
_pimpl->_dlIndex).addAuthority( std::move(endpoint) );
448 _pimpl->_origins.at(*
_pimpl->_dlIndex).addMirror( std::move(endpoint) );
460 for (
auto &ep : endpoints )
466 return _pimpl->_origins.empty ();
477 return _pimpl->_origins.begin ();
483 return _pimpl->_origins.end ();
489 return _pimpl->_origins.begin ();
495 return _pimpl->_origins.end ();
500 return _pimpl->_origins.size ();
505 return (
size() == 1 &&
at( 0 ).endpointCount() > 1 ) ||
size() > 1;
510 return dumpRange(
str, origin.
begin(), origin.
end(),
"MirroredOriginSet {",
" ",
", ",
" ",
"}" );
A smart container that manages a collection of MirroredOrigin objects, automatically grouping endpoin...
bool hasFallbackUrls() const
Whether this set contains more than one Url in total (authorities or mirrors).
const_iterator findByUrl(const zypp::Url &url) const
Finds the MirroredOrigin that contains a specific URL.
const MirroredOrigin & at(size_type idx) const
Accesses the MirroredOrigin at a specific index.
size_type size() const
Returns the number of MirroredOrigin objects in the set.
iterator end()
Returns an iterator to the element following the last MirroredOrigin.
std::vector< MirroredOrigin >::const_iterator const_iterator
RWCOW_pointer< Private > _pimpl
iterator begin()
Returns an iterator to the first MirroredOrigin in insertion order.
std::vector< MirroredOrigin >::iterator iterator
void addAuthorityEndpoint(OriginEndpoint endpoint)
Adds a single endpoint as an authority, routing it to the correct MirroredOrigin.
void addEndpoints(InputIterator first, InputIterator last)
A convenience method to add multiple endpoints from a range.
void addEndpoint(OriginEndpoint endpoint)
Adds a single endpoint, routing it to the correct MirroredOrigin.
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
bool schemeIsDownloading() const
const std::vector< OriginEndpoint > & mirrors() const
const std::vector< OriginEndpoint > & authorities() const
const OriginEndpoint & at(uint index) const
void setAuthority(OriginEndpoint newAuthority)
RWCOW_pointer< Private > _pimpl
void setMirrors(std::vector< OriginEndpoint > mirrors)
bool addAuthority(OriginEndpoint newAuthority)
uint authorityCount() const
bool addMirror(OriginEndpoint newMirror)
std::string scheme() const
const OriginEndpoint & authority() const
uint endpointCount() const
Represents a single, configurable network endpoint, combining a URL with specific access settings.
bool schemeIsDownloading() const
RWCOW_pointer< Private > _pimpl
std::string scheme() const
const zypp::Url & url() const
void setUrl(const zypp::Url &newUrl)
bool hasConfig(const std::string &key) const
std::string asCompleteString() const
Returns a complete string representation of the Url object.
static bool schemeIsDownloading(const std::string &scheme_r)
http https ftp sftp tftp
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
std::ostream & dumpRange(std::ostream &str, TIterator begin, TIterator end, const std::string &intro="{", const std::string &pfx="\n ", const std::string &sep="\n ", const std::string &sfx="\n", const std::string &extro="}")
Print range defined by iterators (multiline style).
bool operator<(const Capability &lhs, const Capability &rhs)
relates: Capability Arbitrary order.
bool operator!=(const Capability &lhs, const Capability &rhs)
relates: Capability
bool operator==(const Capability &lhs, const Capability &rhs)
relates: Capability
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
std::vector< MirroredOrigin > _origins
std::optional< std::size_t > _dlIndex
std::vector< OriginEndpoint > _origins
std::vector< OriginEndpoint > _authorities
bool authoritiesAreValid() const
std::unordered_map< std::string, std::any > _settings
Private(Url &&u, OriginEndpoint::SettingsMap &&m)