3 #include <zypp-core/APIConfig.h> 9 #include <zypp-media/MediaException> 35 if (scheme ==
"cd" || scheme ==
"dvd")
37 else if (scheme ==
"nfs" || scheme ==
"nfs4")
39 else if (scheme ==
"iso")
41 else if (scheme ==
"file" || scheme ==
"dir")
43 else if (scheme ==
"hd" )
45 else if (scheme ==
"cifs" || scheme ==
"smb")
47 else if (scheme ==
"ftp" || scheme ==
"tftp" || scheme ==
"http" || scheme ==
"https")
49 else if (scheme ==
"plugin" )
59 MIL <<
"MirroredOrigin is invalid" << std::endl;
63 std::optional<MirroredOrigin> resolvedOrigin;
64 std::optional<MediaHandlerFactory::MediaHandlerType> hdlType;
68 MIL <<
"OriginEndpoint is not valid" << std::endl;
73 if ( u.hasConfig(
"http-headers") )
77 MIL <<
"Trying scheme '" << url.
getScheme() <<
"'" << std::endl;
84 if ( !custom_headers.empty () ) {
85 resolvedEndpoint.setConfig (
"http-headers", std::move(custom_headers) );
91 using zyppng::operators::operator |;
101 |
and_then([&]( std::vector<OriginEndpoint> resolvedMirrs ) {
102 std::for_each( resolvedMirrs.begin (), resolvedMirrs.end(), [&](
const OriginEndpoint &rEp ){
107 MIL <<
"Different handler type than primary URL, ignoring" << std::endl;
110 resolvedOrigin->addMirror(rEp);
120 if ( !resolvedOrigin ) {
124 if ( resolvedOrigin->endpointCount() > 1 && *hdlType !=
MediaCURLType )
125 ERR <<
"Got mirrors for handler type: " << *hdlType <<
" they will be ignored!" << std::endl;
127 std::unique_ptr<MediaHandler>
_handler;
130 _handler = std::make_unique<MediaCD> (*resolvedOrigin,preferred_attach_point);
134 _handler = std::make_unique<MediaNFS> (*resolvedOrigin,preferred_attach_point);
138 _handler = std::make_unique<MediaISO> (*resolvedOrigin,preferred_attach_point);
142 _handler = std::make_unique<MediaDIR> (*resolvedOrigin,preferred_attach_point);
146 _handler = std::make_unique<MediaDISK> (*resolvedOrigin,preferred_attach_point);
150 _handler = std::make_unique<MediaCIFS> (*resolvedOrigin,preferred_attach_point);
154 enum WhichHandler { choose, curl, curl2 };
155 WhichHandler which = choose;
157 if (
const std::string & queryparam = resolvedOrigin->authority().url().getQueryParam(
"mediahandler"); ! queryparam.empty() ) {
158 if ( queryparam ==
"curl" )
160 else if ( queryparam ==
"curl2" )
162 else if ( queryparam ==
"network" || queryparam ==
"multicurl" )
165 WAR <<
"Unknown mediahandler='" << queryparam <<
"' in URL; Choosing the default" << std::endl;
168 if ( which == choose ) {
170 if ( indeterminate(envstate) ) {
171 #if APIConfig(LIBZYPP_CONFIG_USE_LEGACY_CURL_BACKEND_BY_DEFAULT) 177 which = bool(envstate) ? curl2 : curl;
181 std::unique_ptr<MediaNetworkCommonHandler> handler;
185 handler = std::make_unique<MediaCurl2>( *resolvedOrigin, preferred_attach_point );
188 handler = std::make_unique<MediaCurl>( *resolvedOrigin, preferred_attach_point );
209 ERR <<
"Failed to create media handler" << std::endl;
std::string getScheme() const
Returns the scheme name of the URL.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
const zypp::Url & url() const
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
TriBool getenvBool(const C_Str &var_r)
If the environment variable var_r is set to a legal true or false string return bool, else indeterminate.
auto transform_collect(Container< Msg, CArgs... > &&in, Transformation &&f)
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
const std::vector< OriginEndpoint > & mirrors() const
static expected success(ConsParams &&...params)
ResultType and_then(const expected< T, E > &exp, Function &&f)
const OriginEndpoint & authority() const
Represents a single, configurable network endpoint, combining a URL with specific access settings...