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, curl2, multicurl };
94 WhichHandler which = choose;
96 if (
const std::string & queryparam = url.
getQueryParam(
"mediahandler"); ! queryparam.empty() ) {
97 if ( queryparam ==
"network" || queryparam ==
"multicurl" )
99 else if ( queryparam ==
"curl" )
101 else if ( queryparam ==
"curl2" )
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;
116 if ( getenvIs(
"ZYPP_MULTICURL",
"0" ) ) {
117 WAR <<
"multicurl manually disabled." << std::endl;
121 if ( getenvIs(
"ZYPP_CURL2",
"1" ) ) {
122 WAR <<
"Curl2 manually selected." << std::endl;
128 std::unique_ptr<MediaNetworkCommonHandler> handler;
132 handler = std::make_unique<MediaMultiCurl>( url, preferred_attach_point );
135 handler = std::make_unique<MediaCurl>( url, preferred_attach_point );
138 handler = std::make_unique<MediaCurl2>( url, preferred_attach_point );
142 for (
const auto & el : custom_headers ) {
143 std::string header { el.first };
146 MIL <<
"Added custom header -> " << header << std::endl;
147 handler->settings().addHeader( std::move(header) );
167 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.