6 #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" )
53 MIL <<
"Url is not valid" << std::endl;
59 MIL <<
"Trying scheme '" << url.
getScheme() <<
"'" << std::endl;
66 std::unique_ptr<MediaHandler>
_handler;
69 _handler = std::make_unique<MediaCD> (url,preferred_attach_point);
73 _handler = std::make_unique<MediaNFS> (url,preferred_attach_point);
77 _handler = std::make_unique<MediaISO> (url,preferred_attach_point);
81 _handler = std::make_unique<MediaDIR> (url,preferred_attach_point);
85 _handler = std::make_unique<MediaDISK> (url,preferred_attach_point);
89 _handler = std::make_unique<MediaCIFS> (url,preferred_attach_point);
93 enum WhichHandler { choose, curl, multicurl, network };
94 WhichHandler which = choose;
96 if (
const std::string & queryparam = url.
getQueryParam(
"mediahandler"); ! queryparam.empty() ) {
97 if ( queryparam ==
"network" )
99 else if ( queryparam ==
"multicurl" )
101 else if ( queryparam ==
"curl" )
104 WAR <<
"Unknown mediahandler='" << queryparam <<
"' in URL; Choosing the default" << std::endl;
107 if ( which == choose ) {
108 auto getenvIs = []( std::string_view var, std::string_view val )->
bool {
109 const char * v = ::getenv( var.data() );
110 return v && v == val;
113 if ( getenvIs(
"ZYPP_MEDIANETWORK",
"1" ) ) {
114 WAR <<
"MediaNetwork backend enabled" << std::endl;
117 else if ( getenvIs(
"ZYPP_MULTICURL",
"0" ) ) {
118 WAR <<
"multicurl manually disabled." << std::endl;
125 std::unique_ptr<MediaNetworkCommonHandler> handler;
129 handler = std::make_unique<MediaMultiCurl>( url, preferred_attach_point );
133 handler = std::make_unique<MediaNetwork>( url, preferred_attach_point );
137 handler = std::make_unique<MediaCurl>( url, preferred_attach_point );
141 for (
const auto & el : custom_headers ) {
142 std::string header { el.first };
145 MIL <<
"Added custom header -> " << header << std::endl;
146 handler->settings().addHeader( std::move(header) );
166 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.
std::string getQueryParam(const std::string ¶m, EEncoding eflag=zypp::url::E_DECODED) const
Return the value for the specified query parameter.
bool isValid() const
Verifies the Url.