#include <ctype.h>
#include <iostream>
+#include <map>
#include "zypp/base/Logger.h"
+#include "zypp/ZConfig.h"
+#include "zypp/PluginScript.h"
#include "zypp/ExternalProgram.h"
#include "zypp/media/MediaException.h"
#include "zypp/media/MediaDISK.h"
#include "zypp/media/MediaCIFS.h"
#include "zypp/media/MediaCurl.h"
-#include "zypp/media/MediaAria2c.h"
#include "zypp/media/MediaMultiCurl.h"
#include "zypp/media/MediaISO.h"
#include "zypp/media/MediaPlugin.h"
+#include "zypp/media/UrlResolverPlugin.h"
using namespace std;
// open URL
void
-MediaAccess::open (const Url& url, const Pathname & preferred_attach_point)
+MediaAccess::open (const Url& o_url, const Pathname & preferred_attach_point)
{
- if(!url.isValid()) {
+ if(!o_url.isValid()) {
MIL << "Url is not valid" << endl;
- ZYPP_THROW(MediaBadUrlException(url));
+ ZYPP_THROW(MediaBadUrlException(o_url));
}
close();
- std::string scheme = url.getScheme();
+ UrlResolverPlugin::HeaderList custom_headers;
+ Url url = UrlResolverPlugin::resolveUrl(o_url, custom_headers);
+ std::string scheme = url.getScheme();
MIL << "Trying scheme '" << scheme << "'" << endl;
+
/*
** WARNING: Don't forget to update MediaAccess::downloads(url)
** if you are adding a new url scheme / handler!
_handler = new MediaDISK (url,preferred_attach_point);
else if (scheme == "cifs" || scheme == "smb")
_handler = new MediaCIFS (url,preferred_attach_point);
- else if (scheme == "ftp" || scheme == "http" || scheme == "https")
+ else if (scheme == "ftp" || scheme == "tftp" || scheme == "http" || scheme == "https")
{
- // Another good idea would be activate MediaAria2c handler via external var
- bool use_aria = false;
bool use_multicurl = true;
- const char *ariaenv = getenv( "ZYPP_ARIA2C" );
- const char *multicurlenv = getenv( "ZYPP_MULTICURL" );
- // if user disabled it manually
- if ( use_multicurl && multicurlenv && ( strcmp(multicurlenv, "0" ) == 0 ) )
+ string urlmediahandler ( url.getQueryParam("mediahandler") );
+ if ( urlmediahandler == "multicurl" )
{
- WAR << "multicurl manually disabled." << endl;
- use_multicurl = false;
+ use_multicurl = true;
}
- else if ( !use_multicurl && multicurlenv && ( strcmp(multicurlenv, "1" ) == 0 ) )
- {
- WAR << "multicurl manually enabled." << endl;
- use_multicurl = true;
- }
- // if user disabled it manually
- if ( use_aria && ariaenv && ( strcmp(ariaenv, "0" ) == 0 ) )
+ else if ( urlmediahandler == "curl" )
{
- WAR << "aria2c manually disabled. Falling back to curl" << endl;
- use_aria = false;
+ use_multicurl = false;
}
- else if ( !use_aria && ariaenv && ( strcmp(ariaenv, "1" ) == 0 ) )
- {
- WAR << "aria2c manually enabled." << endl;
- use_aria = true;
- }
-
- // disable if it does not exist
- if ( use_aria && ! MediaAria2c::existsAria2cmd() )
+ else
{
- WAR << "aria2c not found. Falling back to curl" << endl;
- use_aria = false;
+ if ( ! urlmediahandler.empty() )
+ {
+ WAR << "unknown mediahandler set: " << urlmediahandler << endl;
+ }
+ const char *multicurlenv = getenv( "ZYPP_MULTICURL" );
+ // if user disabled it manually
+ if ( use_multicurl && multicurlenv && ( strcmp(multicurlenv, "0" ) == 0 ) )
+ {
+ WAR << "multicurl manually disabled." << endl;
+ use_multicurl = false;
+ }
+ else if ( !use_multicurl && multicurlenv && ( strcmp(multicurlenv, "1" ) == 0 ) )
+ {
+ WAR << "multicurl manually enabled." << endl;
+ use_multicurl = true;
+ }
}
- if ( use_aria )
- _handler = new MediaAria2c (url,preferred_attach_point);
- else if ( use_multicurl )
- _handler = new MediaMultiCurl (url,preferred_attach_point);
+ MediaCurl *curl;
+
+ if ( use_multicurl )
+ curl = new MediaMultiCurl (url,preferred_attach_point);
else
- _handler = new MediaCurl (url,preferred_attach_point);
+ curl = new MediaCurl (url,preferred_attach_point);
+
+ UrlResolverPlugin::HeaderList::const_iterator it;
+ for (it = custom_headers.begin();
+ it != custom_headers.end();
+ ++it) {
+ std::string header = it->first + ": " + it->second;
+ MIL << "Added custom header -> " << header << endl;
+ curl->settings().addHeader(header);
+ }
+ _handler = curl;
}
else if (scheme == "plugin" )
_handler = new MediaPlugin (url,preferred_attach_point);