3 #include <zypp-core/APIConfig.h> 7 #include <zypp-media/MediaException> 31 if (scheme ==
"cd" || scheme ==
"dvd")
33 else if (scheme ==
"nfs" || scheme ==
"nfs4")
35 else if (scheme ==
"iso")
37 else if (scheme ==
"file" || scheme ==
"dir")
39 else if (scheme ==
"hd" )
41 else if (scheme ==
"cifs" || scheme ==
"smb")
43 else if (scheme ==
"ftp" || scheme ==
"tftp" || scheme ==
"http" || scheme ==
"https")
45 else if (scheme ==
"plugin" )
52 if ( o_url.empty() ) {
53 MIL <<
"Url list is empty" << std::endl;
57 std::optional<MediaUrl> primary;
58 std::vector<MediaUrl> resolved;
59 std::optional<MediaHandlerFactory::MediaHandlerType> hdlType;
60 std::for_each( o_url.begin (), o_url.end(), [&](
const MediaUrl &u ){
62 if( !u.url().isValid() ) {
63 MIL <<
"Url is not valid" << std::endl;
68 if ( u.hasConfig(
"http-headers") )
72 MIL <<
"Trying scheme '" << url.
getScheme() <<
"'" << std::endl;
80 else if ( myHdlType != hdlType ) {
83 MIL <<
"Different handler type than primary URL, ignoring" << std::endl;
87 MediaUrl newUrl( url, u.config()) ;
88 if ( !custom_headers.empty () ) {
89 newUrl.setConfig (
"http-headers", std::move(custom_headers) );
95 resolved.push_back (std::move(newUrl));
105 ERR <<
"Got mirrors for handler type: " << *hdlType <<
" they will be ignored!" << std::endl;
107 std::unique_ptr<MediaHandler>
_handler;
110 _handler = std::make_unique<MediaCD> (*primary,preferred_attach_point);
114 _handler = std::make_unique<MediaNFS> (*primary,preferred_attach_point);
118 _handler = std::make_unique<MediaISO> (*primary,preferred_attach_point);
122 _handler = std::make_unique<MediaDIR> (*primary,preferred_attach_point);
126 _handler = std::make_unique<MediaDISK> (*primary,preferred_attach_point);
130 _handler = std::make_unique<MediaCIFS> (*primary,preferred_attach_point);
134 enum WhichHandler { choose, curl, curl2 };
135 WhichHandler which = choose;
137 if (
const std::string & queryparam = primary->url().getQueryParam(
"mediahandler"); ! queryparam.empty() ) {
138 if ( queryparam ==
"curl" )
140 else if ( queryparam ==
"curl2" )
142 else if ( queryparam ==
"network" || queryparam ==
"multicurl" )
145 WAR <<
"Unknown mediahandler='" << queryparam <<
"' in URL; Choosing the default" << std::endl;
148 if ( which == choose ) {
150 if ( indeterminate(envstate) ) {
151 #if APIConfig(LIBZYPP_CONFIG_USE_LEGACY_CURL_BACKEND_BY_DEFAULT) 157 which =
bool(envstate) ? curl2 : curl;
161 std::unique_ptr<MediaNetworkCommonHandler> handler;
165 handler = std::make_unique<MediaCurl2>( *primary, resolved, preferred_attach_point );
168 handler = std::make_unique<MediaCurl>( *primary, resolved, preferred_attach_point );
189 ERR <<
"Failed to create media handler" << std::endl;
std::string getScheme() const
Returns the scheme name of the URL.
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
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.