4#include <zypp/base/Logger.h>
6#include <zypp-media/MediaException>
31 MIL <<
"Url is not valid" << std::endl;
35 std::unique_ptr<MediaHandler>
_handler;
41 MIL <<
"Trying scheme '" << scheme <<
"'" << std::endl;
47 if (scheme ==
"cd" || scheme ==
"dvd")
48 _handler = std::make_unique<MediaCD> (url,preferred_attach_point);
49 else if (scheme ==
"nfs" || scheme ==
"nfs4")
50 _handler = std::make_unique<MediaNFS> (url,preferred_attach_point);
51 else if (scheme ==
"iso")
52 _handler = std::make_unique<MediaISO> (url,preferred_attach_point);
53 else if (scheme ==
"file" || scheme ==
"dir")
54 _handler = std::make_unique<MediaDIR> (url,preferred_attach_point);
55 else if (scheme ==
"hd")
56 _handler = std::make_unique<MediaDISK> (url,preferred_attach_point);
57 else if (scheme ==
"cifs" || scheme ==
"smb")
58 _handler = std::make_unique<MediaCIFS> (url,preferred_attach_point);
59 else if (scheme ==
"ftp" || scheme ==
"tftp" || scheme ==
"http" || scheme ==
"https")
61 enum WhichHandler { choose, curl, multicurl, network };
62 WhichHandler which = choose;
64 if (
const std::string & queryparam = url.
getQueryParam(
"mediahandler"); ! queryparam.empty() ) {
65 if ( queryparam ==
"network" )
67 else if ( queryparam ==
"multicurl" )
69 else if ( queryparam ==
"curl" )
72 WAR <<
"Unknown mediahandler='" << queryparam <<
"' in URL; Choosing the default" << std::endl;
75 if ( which == choose ) {
76 auto getenvIs = []( std::string_view var, std::string_view val )->
bool {
77 const char * v = ::getenv( var.data() );
81 if ( getenvIs(
"ZYPP_MEDIANETWORK",
"1" ) ) {
82 WAR <<
"MediaNetwork backend enabled" << std::endl;
85 else if ( getenvIs(
"ZYPP_MULTICURL",
"0" ) ) {
86 WAR <<
"multicurl manually disabled." << std::endl;
93 std::unique_ptr<MediaNetworkCommonHandler> handler;
97 handler = std::make_unique<MediaMultiCurl>( url, preferred_attach_point );
101 handler = std::make_unique<MediaNetwork>( url, preferred_attach_point );
105 handler = std::make_unique<MediaCurl>( url, preferred_attach_point );
109 for (
const auto & el : custom_headers ) {
110 std::string header { el.first };
113 MIL <<
"Added custom header -> " << header << std::endl;
114 handler->settings().addHeader( std::move(header) );
119 else if (scheme ==
"plugin" )
120 _handler = std::make_unique<MediaPlugin> (url,preferred_attach_point);
128 ERR <<
"Failed to create media handler" << std::endl;
std::string getScheme() const
Returns the scheme name of the URL.
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.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.