ref: refs/heads/master
commit 4f63cf8d0e70dfc345d61103f22e2a0f3e6e1fcc
Author: Duncan Mac-Vicar P
Date: Wed Feb 18 18:33:24 2009 +0100
make TransferProgram actually a data transfer class to keep transfer
settings and share them across curl and aria.
Integrate for first time curl into aria
add a new test case for media set access doesFileExist (which does not
pass, because when it does, I am done :-) )
---
tests/zypp/MediaSetAccess_test.cc | 28 +++
zypp/CMakeLists.txt | 4 +-
zypp/media/MediaAria2c.cc | 466 ++++++++++++++++++++++++-------------
zypp/media/MediaAria2c.h | 3 +-
zypp/media/TransferProgram.cc | 206 ----------------
zypp/media/TransferProgram.h | 135 -----------
zypp/media/TransferSettings.cc | 176 ++++++++++++++
zypp/media/TransferSettings.h | 151 ++++++++++++
8 files changed, 658 insertions(+), 511 deletions(-)
diff --git a/tests/zypp/MediaSetAccess_test.cc b/tests/zypp/MediaSetAccess_test.cc
index 608ce3f..c8f1b26 100644
--- a/tests/zypp/MediaSetAccess_test.cc
+++ b/tests/zypp/MediaSetAccess_test.cc
@@ -7,6 +7,8 @@
#include "zypp/MediaSetAccess.h"
#include "zypp/Url.h"
+#include "WebServer.h"
+
using std::cout;
using std::endl;
using std::string;
@@ -247,4 +249,30 @@ BOOST_AUTO_TEST_CASE(msa_provide_optional_file)
//! \todo test provideOptionalFile with not desired media
}
+/*
+ * file exists local
+ */
+BOOST_AUTO_TEST_CASE(msa_file_exist_local)
+{
+ MediaSetAccess setaccess(Url(DATADIR + "/src1/cd1"));
+
+ BOOST_CHECK(setaccess.doesFileExist("/test.txt"));
+ BOOST_CHECK(!setaccess.doesFileExist("/testBADNAME.txt"));
+}
+
+/*
+ * file exists remote
+ */
+BOOST_AUTO_TEST_CASE(msa_file_exist_remote)
+{
+ WebServer web( Pathname(DATADIR) / "/src1/cd1", 10001 );
+ web.start();
+ MediaSetAccess setaccess( web.url(), "/" );
+
+ BOOST_CHECK(setaccess.doesFileExist("/test.txt"));
+ BOOST_CHECK(!setaccess.doesFileExist("/testBADNAME.txt"));
+ web.stop();
+}
+
+
// vim: set ts=2 sts=2 sw=2 ai et:
diff --git a/zypp/CMakeLists.txt b/zypp/CMakeLists.txt
index 6eb2f37..7a7f27f 100644
--- a/zypp/CMakeLists.txt
+++ b/zypp/CMakeLists.txt
@@ -270,7 +270,7 @@ SET( zypp_media_SRCS
media/CredentialFileReader.cc
media/CredentialManager.cc
media/CurlConfig.cc
- media/TransferProgram.cc
+ media/TransferSettings.cc
)
SET( zypp_media_HEADERS
@@ -294,7 +294,7 @@ SET( zypp_media_HEADERS
media/CredentialFileReader.h
media/CredentialManager.h
media/CurlConfig.h
- media/TransferProgram.h
+ media/TransferSettings.h
)
INSTALL( FILES
diff --git a/zypp/media/MediaAria2c.cc b/zypp/media/MediaAria2c.cc
index 3ae518e..a5de650 100644
--- a/zypp/media/MediaAria2c.cc
+++ b/zypp/media/MediaAria2c.cc
@@ -72,6 +72,225 @@ MediaAria2c::existsAria2cmd()
return ( aria.close() == 0 );
}
+void fillSettingsFromUrl( const Url &url, TransferSettings &s )
+{
+ std::string param(url.getQueryParam("timeout"));
+ if( !param.empty())
+ {
+ long num = str::strtonum<long>(param);
+ if( num >= 0 && num <= TRANSFER_TIMEOUT_MAX)
+ s.setTimeout(num);
+ }
+
+ if ( ! url.getUsername().empty() )
+ {
+ s.setUsername(url.getUsername());
+ if ( url.getPassword().size() )
+ {
+ s.setPassword(url.getPassword());
+ }
+ }
+
+ string proxy = url.getQueryParam( "proxy" );
+
+ if ( ! proxy.empty() )
+ {
+ string proxyport( url.getQueryParam( "proxyport" ) );
+ if ( ! proxyport.empty() ) {
+ proxy += ":" + proxyport;
+ }
+ s.setProxy(proxy);
+ s.setProxyEnabled(true);
+ }
+}
+
+void fillSettingsSystemProxy( const Url&url, TransferSettings &s )
+{
+ ProxyInfo proxy_info (ProxyInfo::ImplPtr(new ProxyInfoSysconfig("proxy")));
+
+ if ( proxy_info.enabled())
+ {
+ s.setProxyEnabled(true);
+ std::liststd::string nope = proxy_info.noProxy();
+ for (ProxyInfo::NoProxyIterator it = proxy_info.noProxyBegin();
+ it != proxy_info.noProxyEnd();
+ it++)
+ {
+ std::string host( str::toLower(url.getHost()));
+ std::string temp( str::toLower(*it));
+
+ // no proxy if it points to a suffix
+ // preceeded by a '.', that maches
+ // the trailing portion of the host.
+ if( temp.size() > 1 && temp.at(0) == '.')
+ {
+ if(host.size() > temp.size() &&
+ host.compare(host.size() - temp.size(), temp.size(), temp) == 0)
+ {
+ DBG << "NO_PROXY: '" << *it << "' matches host '"
+ << host << "'" << endl;
+ s.setProxyEnabled(false);
+ break;
+ }
+ }
+ else
+ // no proxy if we have an exact match
+ if( host == temp)
+ {
+ DBG << "NO_PROXY: '" << *it << "' matches host '"
+ << host << "'" << endl;
+ s.setProxyEnabled(false);
+ break;
+ }
+ }
+
+ if ( s.proxyEnabled() )
+ s.setProxy(proxy_info.proxy(url.getScheme()));
+ }
+
+}
+
+/**
+ * comannd line for aria.
+ * The argument list gets passed as reference
+ * and it is filled.
+ */
+void fillAriaCmdLine( const Pathname &ariapath,
+ const TransferSettings &s,
+ const Url &url,
+ const Pathname &destination,
+ ExternalProgram::Arguments &args )
+{
+ args.push_back(ariapath.c_str());
+ args.push_back(str::form("--user-agent=%s", s.userAgentString().c_str()));
+ args.push_back("--summary-interval=1");
+ args.push_back("--follow-metalink=mem");
+ args.push_back("--check-integrity=true");
+
+ // add the anonymous id.
+ for ( TransferSettings::Headers::const_iterator it = s.headersBegin();
+ it != s.headersEnd();
+ ++it )
+ args.push_back(str::form("--header=%s", it->c_str() ));
+
+ args.push_back( str::form("--connect-timeout=%ld", s.timeout()));
+
+ if ( s.username().empty() )
+ {
+ if ( url.getScheme() == "ftp" )
+ {
+ // set anonymous ftp
+ args.push_back(str::form("--ftp-user=%s", "suseuser" ));
+ args.push_back(str::form("--ftp-passwd=%s", VERSION ));
+
+ string id = "yast2";
+ id += VERSION;
+ DBG << "Anonymous FTP identification: '" << id << "'" << endl;
+ }
+ }
+ else
+ {
+ if ( url.getScheme() == "ftp" )
+ args.push_back(str::form("--ftp-user=%s", s.username().c_str() ));
+ else if ( url.getScheme() == "http" ||
+ url.getScheme() == "https" )
+ args.push_back(str::form("--http-user=%s", s.username().c_str() ));
+
+ if ( s.password().size() )
+ {
+ if ( url.getScheme() == "ftp" )
+ args.push_back(str::form("--ftp-passwd=%s", s.password().c_str() ));
+ else if ( url.getScheme() == "http" ||
+ url.getScheme() == "https" )
+ args.push_back(str::form("--http-passwd=%s", s.password().c_str() ));
+ }
+ }
+
+ if ( s.proxyEnabled() )
+ {
+ args.push_back(str::form("--http-proxy=%s", s.proxy().c_str() ));
+ if ( ! s.proxyUsername().empty() )
+ {
+ args.push_back(str::form("--http-proxy-user=%s", s.proxyUsername().c_str() ));
+ if ( ! s.proxyPassword().empty() )
+ args.push_back(str::form("--http-proxy-passwd=%s", s.proxyPassword().c_str() ));
+ }
+ }
+
+ if ( ! destination.empty() )
+ args.push_back(str::form("--dir=%s", destination.c_str()));
+
+ args.push_back(url.asString().c_str());
+}
+
+/**
+ * comannd line for curl.
+ * The argument list gets passed as reference
+ * and it is filled.
+ */
+void fillCurlCmdLine( const Pathname &curlpath,
+ const TransferSettings &s,
+ const Url &url,
+ ExternalProgram::Arguments &args )
+{
+ args.push_back(curlpath.c_str());
+ // only do a head request
+ args.push_back("-I");
+ args.push_back("-A"); args.push_back(s.userAgentString());
+
+ // headers.
+ for ( TransferSettings::Headers::const_iterator it = s.headersBegin();
+ it != s.headersEnd();
+ ++it )
+ {
+ args.push_back("-H");
+ args.push_back(it->c_str());
+ }
+
+ args.push_back("--connect-timeout");
+ args.push_back(str::numstring(s.timeout()));
+
+ if ( s.username().empty() )
+ {
+ if ( url.getScheme() == "ftp" )
+ {
+ string id = "yast2:";
+ id += VERSION;
+ args.push_back("--user");
+ args.push_back(id);
+ DBG << "Anonymous FTP identification: '" << id << "'" << endl;
+ }
+ }
+ else
+ {
+ string userpass = s.username();
+
+ if ( s.password().size() )
+ userpass += (":" + s.password());
+ args.push_back("--user");
+ args.push_back(userpass);
+ }
+
+ if ( s.proxyEnabled() )
+ {
+ args.push_back("--proxy");
+ args.push_back(s.proxy());
+ if ( ! s.proxyUsername().empty() )
+ {
+ string userpass = s.proxyUsername();
+
+ if ( s.proxyPassword().size() )
+ userpass += (":" + s.proxyPassword());
+ args.push_back("--proxy-user");
+ args.push_back(userpass);
+ }
+ }
+
+ args.push_back("--url");
+ args.push_back(url.asString().c_str());
+}
+
+
static const char *const anonymousIdHeader()
{
// we need to add the release and identifier to the
@@ -124,6 +343,7 @@ const char *const MediaAria2c::agentString()
}
+
MediaAria2c::MediaAria2c( const Url & url_r,
const Pathname & attach_point_hint_r )
: MediaHandler( url_r, attach_point_hint_r,
@@ -162,8 +382,6 @@ MediaAria2c::MediaAria2c( const Url & url_r,
void MediaAria2c::attachTo (bool next)
{
// clear last arguments
- _args.clear();
-
if ( next )
ZYPP_THROW(MediaNotSupportedException(_url));
@@ -182,173 +400,25 @@ void MediaAria2c::attachTo (bool next)
disconnectFrom();
- // Build the aria command.
- _args.push_back(_aria2cPath.asString());
- _args.push_back(str::form("--user-agent=%s", agentString()));
- _args.push_back("--summary-interval=1");
- _args.push_back("--follow-metalink=mem");
- _args.push_back( "--check-integrity=true");
-
- // add the anonymous id.
- _args.push_back(str::form("--header=%s", anonymousIdHeader() ));
- _args.push_back(str::form("--header=%s", distributionFlavorHeader() ));
- // TODO add debug option
-
- // Transfer timeout
- {
- _xfer_timeout = TRANSFER_TIMEOUT;
-
- std::string param(_url.getQueryParam("timeout"));
- if( !param.empty())
- {
- long num = str::strtonum<long>( param);
- if( num >= 0 && num <= TRANSFER_TIMEOUT_MAX)
- _xfer_timeout = num;
- }
- }
-
- _args.push_back( str::form("--connect-timeout=%d", CONNECT_TIMEOUT));
-
- // TODO limit redirections
- // TODO Implement certificate validation
+ _settings.setUserAgentString(agentString());
+ _settings.addHeader(anonymousIdHeader());
+ _settings.addHeader(distributionFlavorHeader());
- // FTP defaults to anonymous
+ _settings.setTimeout(TRANSFER_TIMEOUT);
+ _settings.setConnectTimeout(CONNECT_TIMEOUT);
+ // fill some settings from url query parameters
+ fillSettingsFromUrl(_url, _settings);
- if ( _url.getUsername().empty() )
+ // if the proxy was not set by url, then look
+ if ( _settings.proxy().empty() )
{
- if ( _url.getScheme() == "ftp" )
- {
- string id = "yast2@";
- id += VERSION;
- DBG << "Anonymous FTP identification: '" << id << "'" << endl;
- _userpwd = "anonymous:" + id;
- }
+ // at the system proxy settings
+ fillSettingsSystemProxy(_url, _settings);
}
- else
- {
- if ( _url.getScheme() == "ftp" )
- {
- _args.push_back(str::form("--ftp-user=%s", _url.getUsername().c_str() ));
- }
- else if ( _url.getScheme() == "http" ||
- _url.getScheme() == "https" )
- {
- _args.push_back(str::form("--http-user=%s", _url.getUsername().c_str() ));
- }
- if ( _url.getPassword().size() )
- {
- if ( _url.getScheme() == "ftp" )
- {
- _args.push_back(str::form("--ftp-passwd=%s", _url.getPassword().c_str() ));
- }
- else if ( _url.getScheme() == "http" ||
- _url.getScheme() == "https" )
- {
- _args.push_back(str::form("--http-passwd=%s", _url.getPassword().c_str() ));
- }
- }
- }
-
- // note, aria2c does not support setting the auth type with
- // (basic, digest yet)
-
-
- /*---------------------------------------------------------------*
- CURLOPT_PROXY: host[:port]
-
- Url::option(proxy and proxyport)
- If not provided, /etc/sysconfig/proxy is evaluated
- *---------------------------------------------------------------*/
-
- _proxy = _url.getQueryParam( "proxy" );
-
- if ( ! _proxy.empty() )
- {
- string proxyport( _url.getQueryParam( "proxyport" ) );
- if ( ! proxyport.empty() ) {
- _proxy += ":" + proxyport;
- }
- }
- else
- {
-
- ProxyInfo proxy_info (ProxyInfo::ImplPtr(new ProxyInfoSysconfig("proxy")));
-
- if ( proxy_info.enabled())
- {
- bool useproxy = true;
-
- std::liststd::string nope = proxy_info.noProxy();
- for (ProxyInfo::NoProxyIterator it = proxy_info.noProxyBegin();
- it != proxy_info.noProxyEnd();
- it++)
- {
- std::string host( str::toLower(_url.getHost()));
- std::string temp( str::toLower(*it));
-
- // no proxy if it points to a suffix
- // preceeded by a '.', that maches
- // the trailing portion of the host.
- if( temp.size() > 1 && temp.at(0) == '.')
- {
- if(host.size() > temp.size() &&
- host.compare(host.size() - temp.size(), temp.size(), temp) == 0)
- {
- DBG << "NO_PROXY: '" << *it << "' matches host '"
- << host << "'" << endl;
- useproxy = false;
- break;
- }
- }
- else
- // no proxy if we have an exact match
- if( host == temp)
- {
- DBG << "NO_PROXY: '" << *it << "' matches host '"
- << host << "'" << endl;
- useproxy = false;
- break;
- }
- }
-
- if ( useproxy ) {
- _proxy = proxy_info.proxy(_url.getScheme());
- }
- }
- }
-
- DBG << "Proxy: " << (_proxy.empty() ? "-none-" : _proxy) << endl;
-
- if ( ! _proxy.empty() )
- {
- _args.push_back(str::form("--http-proxy=%s", _proxy.c_str() ));
-
- /*---------------------------------------------------------------*
- CURLOPT_PROXYUSERPWD: [user name]:[password]
+ DBG << "Proxy: " << (_settings.proxy().empty() ? "-none-" : _settings.proxy()) << endl;
- Url::option(proxyuser and proxypassword) -> CURLOPT_PROXYUSERPWD
- If not provided, $HOME/.curlrc is evaluated
- *---------------------------------------------------------------*/
-
- _proxyuserpwd = _url.getQueryParam( "proxyuser" );
-
- if ( ! _proxyuserpwd.empty() ) {
- _args.push_back(str::form("--http-proxy-user=%s", _proxyuserpwd.c_str() ));
-
- string proxypassword( _url.getQueryParam( "proxypassword" ) );
- if ( ! proxypassword.empty() ) {
- _args.push_back(str::form("--http-proxy-passwd=%s", proxypassword.c_str() ));
- }
- }
- }
-
- //_currentCookieFile = _cookieFile.asString();
- //_args.push_back(str::form("--load-cookies=%s", _currentCookieFile.c_str()));
- //NOTE cookie jar?
-
- // FIXME: need a derived class to propelly compare url's
MediaSourceRef media( new MediaSource(_url.getScheme(), _url.asString()));
setMediaSource(media);
@@ -412,11 +482,10 @@ void MediaAria2c::getFileCopy( const Pathname & filename , const Pathname & targ
bool retry = false;
- ExternalProgram::Arguments args = _args;
- args.push_back(str::form("--dir=%s", target.dirname().c_str()));
-
- args.push_back(fileurl.asString());
+ ExternalProgram::Arguments args;
+ fillAriaCmdLine(_aria2cPath, _settings, fileurl, target.dirname(), args);
+
do
{
try
@@ -525,8 +594,71 @@ bool MediaAria2c::getDoesFileExist( const Pathname & filename ) const
bool MediaAria2c::doGetDoesFileExist( const Pathname & filename ) const
{
-
DBG << filename.asString() << endl;
+ callback::SendReport<DownloadProgressReport> report;
+
+ Url fileurl(getFileUrl(_url, filename));
+ bool retry = false;
+
+ ExternalProgram::Arguments args;
+
+ fillCurlCmdLine("/usr/bin/curl", _settings, fileurl, args);
+
+ do
+ {
+ try
+ {
+ report->start(_url, fileurl.asString() );
+
+ ExternalProgram curl(args, ExternalProgram::Stderr_To_Stdout);
+ //Process response
+ for(std::string curlResponse( curl.receiveLine());
+ curlResponse.length();
+ curlResponse = curl.receiveLine())
+ {
+
+ if ( str::contains(curlResponse, "401 Authorization Required") )
+ {
+ ZYPP_THROW(MediaUnauthorizedException(
+ _url, "Login failed.", "Login failed", "auth hint"
+ ));
+ }
+
+ if ( str::contains(curlResponse, "404 Not Found") )
+ return false;
+
+ if ( str::contains(curlResponse, "200 OK") )
+ return false;
+ }
+
+ int code = curl.close();
+
+ report->finish( _url , zypp::media::DownloadProgressReport::NO_ERROR, "");
+ retry = false;
+ }
+ // retry with proper authentication data
+ catch (MediaUnauthorizedException & ex_r)
+ {
+ if(authenticate(ex_r.hint(), !retry))
+ retry = true;
+ else
+ {
+ report->finish(fileurl, zypp::media::DownloadProgressReport::ACCESS_DENIED, ex_r.asUserHistory());
+ ZYPP_RETHROW(ex_r);
+ }
+
+ }
+ // unexpected exception
+ catch (MediaException & excpt_r)
+ {
+ // FIXME: error number fix
+ report->finish(fileurl, zypp::media::DownloadProgressReport::ERROR, excpt_r.asUserHistory());
+ ZYPP_RETHROW(excpt_r);
+ }
+ }
+ while (retry);
+
+ report->finish(fileurl, zypp::media::DownloadProgressReport::NO_ERROR, "");
return true;
}
diff --git a/zypp/media/MediaAria2c.h b/zypp/media/MediaAria2c.h
index 4b83552..1020ea5 100644
--- a/zypp/media/MediaAria2c.h
+++ b/zypp/media/MediaAria2c.h
@@ -13,6 +13,7 @@
#define ZYPP_MEDIA_MEDIAARIA2C_H
#include "zypp/media/MediaHandler.h"
+#include "zypp/media/TransferSettings.h"
#include "zypp/ZYppCallbacks.h"
namespace zypp {
@@ -111,7 +112,7 @@ class MediaAria2c : public MediaHandler {
std::string getAria2cVersion();
static std::string _aria2cVersion;
- ExternalProgram::Arguments _args;
+ TransferSettings _settings;
};
///////////////////////////////////////////////////////////////////
diff --git a/zypp/media/TransferProgram.cc b/zypp/media/TransferProgram.cc
deleted file mode 100644
index 2542fed..0000000
--- a/zypp/media/TransferProgram.cc
+++ /dev/null
@@ -1,206 +0,0 @@
-#include <iostream>
-#include <vector>
-#include <sstream>
-
-#include "zypp/base/String.h"
-#include "zypp/base/Logger.h"
-#include "zypp/base/WatchFile.h"
-#include "zypp/base/ReferenceCounted.h"
-#include "zypp/base/NonCopyable.h"
-#include "zypp/ExternalProgram.h"
-#include "zypp/media/TransferProgram.h"
-
-using namespace std;
-
-#define ARIA2C_BINARY "/usr/bin/aria2c"
-#define CURL_BINARY "/usr/bin/curl"
-
-namespace zypp
-{
-namespace media
-{
-
-class TransferProgram::Impl
-{
-public:
- Impl()
- : _useproxy(false)
- , _timeout(0)
- {}
-
- virtual ~Impl()
- {}
-
- virtual void execute()
- {
- ERR << "not implemented." << endl;
- ZYPP_THROW(Exception("not implemented"));
- }
-
- /** Offer default Impl. */
- static shared_ptr<Impl> nullimpl()
- {
- static shared_ptr<Impl> _nullimpl( new Impl );
- return _nullimpl;
- }
-
-private:
- friend Impl * rwcowClone<Impl>( const Impl * rhs );
- /** clone for RWCOW_pointer */
- Impl * clone() const
- { return new Impl( *this ); }
-
-public:
- vector<string> _headers;
- string _useragent;
- string _username;
- string _password;
- bool _useproxy;
- string _proxy_username;
- string _proxy_password;
- int _timeout;
- Url _url;
-
- TransferProgram::OutputLines _output;
- ErrorFlags _errorFlags;
- int _exitCode;
-};
-
-class Aria2cProgram : public TransferProgram::Impl
-{
-public:
- virtual void execute()
- {
- ExternalProgram::Arguments args;
-
- args.push_back(ARIA2C_BINARY);
- args.push_back(str::form("--user-agent=%s", _useragent.c_str()));
- args.push_back("--summary-interval=1");
- args.push_back("--follow-metalink=mem");
- args.push_back("--check-integrity=true");
-
- // add the anonymous id.
- for ( vector<string>::const_iterator it = _headers.begin();
- it != _headers.end();
- ++it )
- args.push_back(str::form("--header=%s", it->c_str() ));
-
- args.push_back( str::form("--connect-timeout=%d", _timeout));
-
- ExternalProgram prog(args,ExternalProgram::Discard_Stderr, false, -1, true);
- string line;
- int count;
- for(line = prog.receiveLine(), count=0;
- !line.empty();
- line = prog.receiveLine(), count++ )
- {
- // save the line
- _output.push_back(line);
-
- // trim trailing NL.
- if ( line.empty() )
- continue;
- // make sure no \n is at the end
- line = str::rtrim(line);
-
- // process lines
- }
- _exitCode = prog.close();
-
- // clear previous argument
- args.clear();
- }
-};
-
-class CurlProgram : public TransferProgram::Impl
-{
-public:
- virtual void execute()
- {
- }
-};
-
-
-TransferProgram::TransferProgram()
- : _impl()
-{
-
-}
-
-TransferProgram::OutputLines::const_iterator TransferProgram::outputLinesBegin() const
-{
- return _impl->_output.begin();
-}
-
-TransferProgram::OutputLines::const_iterator TransferProgram::outputLinesEnd() const
-{
- return _impl->_output.end();
-}
-
-string TransferProgram::output() const
-{
- stringstream str;
- OutputLines::const_iterator it;
- for ( it = outputLinesBegin();
- it != outputLinesEnd();
- ++it )
- {
- str << *it;
- }
- return str.str();
-}
-
-void TransferProgram::execute()
-{
- _impl->execute();
-}
-
-void TransferProgram::addHeader( const std::string &header )
-{
- _impl->_headers.push_back(header);
-}
-
-void TransferProgram::setUserAgentString( const std::string &agent )
-{
- _impl->_useragent = agent;
-}
-
-void TransferProgram::setUsername( const std::string &username )
-{
- _impl->_username = username;
-}
-
-void TransferProgram::setPassword( const std::string &password )
-{
- _impl->_password = password;
-}
-
-void TransferProgram::setProxyEnabled( bool enabled )
-{
- _impl->_useproxy = enabled;
-}
-
-void TransferProgram::setProxyUsername( const std::string &proxyuser )
-{
- _impl->_proxy_username = proxyuser;
-}
-
-void TransferProgram::setProxyPassword( const std::string &proxypass )
-{
- _impl->_proxy_password = proxypass;
-}
-
-void TransferProgram::setTimeout( int t )
-{
- _impl->_timeout = t;
-}
-
-void TransferProgram::setUrl( const zypp::Url &url)
-{
- _impl->_url = url;
-}
-
-
-} // ns media
-} // ns zypp
-
diff --git a/zypp/media/TransferProgram.h b/zypp/media/TransferProgram.h
deleted file mode 100644
index 4441c62..0000000
--- a/zypp/media/TransferProgram.h
+++ /dev/null
@@ -1,135 +0,0 @@
-
-#ifndef TRANSFER_PROGRAM_H_
-#define TRANSFER_PROGRAM_H_
-
-#include <functional>
-#include <list>
-#include <string>
-#include <vector>
-#include "zypp/base/Flags.h"
-#include "zypp/base/PtrTypes.h"
-#include "zypp/Pathname.h"
-#include "zypp/Url.h"
-
-namespace zypp
-{
-namespace media
-{
-
-/**
- * Easy access to the transfer command line program
- *
- */
-class TransferProgram
-{
-public:
-
- typedef std::vectorstd::string OutputLines;
-
- /**
- * After calling the program, one or more error flags can
- * be set according to the result.
- */
- enum ErrorFlag
- {
- /** Operation ended successfully */
- NO_ERROR = 0x0,
- };
- ZYPP_DECLARE_FLAGS(ErrorFlags,ErrorFlag);
-
- /**
- * Constructs a gpg cmd line access.
- * \p home is the home directory where keyrings are created.
- *
- * Gpg has one pubkeyring and one secret keyring in its home.
- *
- */
- TransferProgram();
-
- /**
- * Executes command with a given argument
- */
- void execute();
-
- /**
- * Contains the error flags from the last command execution
- */
- ErrorFlags errorFlags() const;
-
- /**
- * contains the last command execution exit code
- */
- int exitCode() const;
-
- /**
- * begin iterator over output lines available after
- * execute
- */
- OutputLines::const_iterator outputLinesBegin() const;
-
- /**
- * end iterator over output lines available after
- * execute
- */
- OutputLines::const_iterator outputLinesEnd() const;
-
- /**
- * returns the full output for convenience
- */
- std::string output() const;
-
- /**
- * add a header, on the form "Foo: Bar"
- */
- void addHeader( const std::string &header );
-
- /**
- * sets the user agent ie: "Mozilla v3"
- */
- void setUserAgentString( const std::string &agent );
-
- /**
- * sets the auth username
- */
- void setUsername( const std::string &username );
-
- /**
- * sets the auth password
- */
- void setPassword( const std::string &password );
-
- /**
- * whether the proxy is used or not
- */
- void setProxyEnabled( bool enabled );
-
- /**
- * sets the proxy user
- */
- void setProxyUsername( const std::string &proxyuser );
-
- /**
- * sets the proxy password
- */
- void setProxyPassword( const std::string &proxypass );
-
- /**
- * set the connection timeout
- */
- void setTimeout( int t );
-
- /**
- * set url to download
- */
- void setUrl( const zypp::Url &url);
-
- class Impl;
-protected:
- RWCOW_pointer<Impl> _impl;
-};
-ZYPP_DECLARE_OPERATORS_FOR_FLAGS(TransferProgram::ErrorFlags);
-
-} // ns media
-} // ns zypp
-
-#endif
diff --git a/zypp/media/TransferSettings.cc b/zypp/media/TransferSettings.cc
new file mode 100644
index 0000000..e50a3a5
--- /dev/null
+++ b/zypp/media/TransferSettings.cc
@@ -0,0 +1,176 @@
+#include <iostream>
+#include <vector>
+#include <sstream>
+
+#include "zypp/base/String.h"
+#include "zypp/base/Logger.h"
+#include "zypp/base/WatchFile.h"
+#include "zypp/base/ReferenceCounted.h"
+#include "zypp/base/NonCopyable.h"
+#include "zypp/ExternalProgram.h"
+#include "zypp/media/TransferSettings.h"
+
+using namespace std;
+
+#define ARIA2C_BINARY "/usr/bin/aria2c"
+#define CURL_BINARY "/usr/bin/curl"
+
+namespace zypp
+{
+namespace media
+{
+
+class TransferSettings::Impl
+{
+public:
+ Impl()
+ : _useproxy(false)
+ , _timeout(0)
+ , _connect_timeout(0)
+ {}
+
+ virtual ~Impl()
+ {}
+
+ /** Offer default Impl. */
+ static shared_ptr<Impl> nullimpl()
+ {
+ static shared_ptr<Impl> _nullimpl( new Impl );
+ return _nullimpl;
+ }
+
+private:
+ friend Impl * rwcowClone<Impl>( const Impl * rhs );
+ /** clone for RWCOW_pointer */
+ Impl * clone() const
+ { return new Impl( *this ); }
+
+public:
+ vector<string> _headers;
+ string _useragent;
+ string _username;
+ string _password;
+ bool _useproxy;
+ string _proxy;
+ string _proxy_username;
+ string _proxy_password;
+ long _timeout;
+ long _connect_timeout;
+ Url _url;
+ Pathname _targetdir;
+};
+
+TransferSettings::TransferSettings()
+ : _impl(new TransferSettings::Impl())
+{
+
+}
+
+void TransferSettings::addHeader( const std::string &header )
+{
+ _impl->_headers.push_back(header);
+}
+
+TransferSettings::Headers::const_iterator TransferSettings::headersBegin() const
+{
+ return _impl->_headers.begin();
+}
+
+TransferSettings::Headers::const_iterator TransferSettings::headersEnd() const
+{
+ return _impl->_headers.end();
+}
+
+void TransferSettings::setUserAgentString( const std::string &agent )
+{
+ _impl->_useragent = agent;
+}
+
+std::string TransferSettings::userAgentString() const
+{
+ return _impl->_useragent;
+}
+
+void TransferSettings::setUsername( const std::string &username )
+{
+ _impl->_username = username;
+}
+
+std::string TransferSettings::username() const
+{
+ return _impl->_username;
+}
+
+void TransferSettings::setPassword( const std::string &password )
+{
+ _impl->_password = password;
+}
+
+std::string TransferSettings::password() const
+{
+ return _impl->_password;
+}
+
+void TransferSettings::setProxyEnabled( bool enabled )
+{
+ _impl->_useproxy = enabled;
+}
+
+bool TransferSettings::proxyEnabled() const
+{
+ return _impl->_useproxy;
+}
+
+void TransferSettings::setProxy( const std::string &proxy )
+{
+ _impl->_proxy = proxy;
+}
+
+std::string TransferSettings::proxy() const
+{
+ return _impl->_proxy;
+}
+
+void TransferSettings::setProxyUsername( const std::string &proxyuser )
+{
+ _impl->_proxy_username = proxyuser;
+}
+
+std::string TransferSettings::proxyUsername() const
+{
+ return _impl->_proxy_username;
+}
+
+void TransferSettings::setProxyPassword( const std::string &proxypass )
+{
+ _impl->_proxy_password = proxypass;
+}
+
+std::string TransferSettings::proxyPassword() const
+{
+ return _impl->_proxy_password;
+}
+
+void TransferSettings::setTimeout( long t )
+{
+ _impl->_timeout = t;
+}
+
+long TransferSettings::timeout() const
+{
+ return _impl->_timeout;
+}
+
+void TransferSettings::setConnectTimeout( long t )
+{
+ _impl->_connect_timeout = t;
+}
+
+long TransferSettings::connectTimeout() const
+{
+ return _impl->_connect_timeout;
+}
+
+} // ns media
+} // ns zypp
+
diff --git a/zypp/media/TransferSettings.h b/zypp/media/TransferSettings.h
new file mode 100644
index 0000000..3a513f0
--- /dev/null
+++ b/zypp/media/TransferSettings.h
@@ -0,0 +1,151 @@
+
+#ifndef TRANSFER_PROGRAM_H_
+#define TRANSFER_PROGRAM_H_
+
+#include <string>
+#include <vector>
+#include "zypp/base/Flags.h"
+#include "zypp/base/PtrTypes.h"
+#include "zypp/Pathname.h"
+#include "zypp/Url.h"
+
+namespace zypp
+{
+namespace media
+{
+
+/**
+ * Easy access to the transfer command line program no matter
+ * which one it is
+ *
+ */
+class TransferSettings
+{
+public:
+ /**
+ * Constructs a transfer program cmd line access.
+ */
+ TransferSettings();
+
+ /**
+ * Constructs the settings from a url object where.
+ * authentication/proxy information can be extracted
+ * from the url
+ */
+ TransferSettings( const zypp::Url &url );
+
+ typedef std::vectorstd::string Headers;
+ /**
+ * add a header, on the form "Foo: Bar"
+ */
+ void addHeader( const std::string &header );
+
+ /**
+ * begin iterators to additional headers
+ */
+ Headers::const_iterator headersBegin() const;
+
+ /**
+ * end iterators to additional headers
+ */
+ Headers::const_iterator headersEnd() const;
+
+ /**
+ * sets the user agent ie: "Mozilla v3"
+ */
+ void setUserAgentString( const std::string &agent );
+
+ /**
+ * user agent string
+ */
+ std::string userAgentString() const;
+
+ /**
+ * sets the auth username
+ */
+ void setUsername( const std::string &username );
+
+ /**
+ * auth username
+ */
+ std::string username() const;
+
+ /**
+ * sets the auth password
+ */
+ void setPassword( const std::string &password );
+
+ /**
+ * auth password
+ */
+ std::string password() const;
+
+ /**
+ * whether the proxy is used or not
+ */
+ void setProxyEnabled( bool enabled );
+
+ /**
+ * proxy is enabled
+ */
+ bool proxyEnabled() const;
+
+ /**
+ * proxy to use if it is enabled
+ */
+ void setProxy( const std::string &proxyhost );
+
+ /**
+ * proxy host
+ */
+ std::string proxy() const;
+
+ /**
+ * sets the proxy user
+ */
+ void setProxyUsername( const std::string &proxyuser );
+
+ /**
+ * proxy auth username
+ */
+ std::string proxyUsername() const;
+
+ /**
+ * sets the proxy password
+ */
+ void setProxyPassword( const std::string &proxypass );
+
+ /**
+ * proxy auth password
+ */
+ std::string proxyPassword() const;
+
+ /**
+ * set the connect timeout
+ */
+ void setConnectTimeout( long t );
+
+ /**
+ * connection timeout
+ */
+ long connectTimeout() const;
+
+ /**
+ * set the transfer timeout
+ */
+ void setTimeout( long t );
+
+ /**
+ * transfer timeout
+ */
+ long timeout() const;
+
+protected:
+ class Impl;
+ RWCOW_pointer<Impl> _impl;
+};
+
+} // ns media
+} // ns zypp
+
+#endif
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org