libzypp 8.13.6
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Static Private Attributes

zypp::media::MediaCurl Class Reference

Implementation class for FTP, HTTP and HTTPS MediaHandler. More...

#include <MediaCurl.h>

Inheritance diagram for zypp::media::MediaCurl:
Inheritance graph
[legend]

List of all members.

Classes

class  Callbacks

Public Types

enum  RequestOption {
  OPTION_NONE = 0x0, OPTION_RANGE = 0x1, OPTION_HEAD = 0x02, OPTION_NO_IFMODSINCE = 0x04,
  OPTION_NO_REPORT_START = 0x08
}

Public Member Functions

 ZYPP_DECLARE_FLAGS (RequestOptions, RequestOption)
 MediaCurl (const Url &url_r, const Pathname &attach_point_hint_r)
virtual ~MediaCurl ()
TransferSettingssettings ()

Static Public Member Functions

static void setCookieFile (const Pathname &)

Protected Member Functions

Url clearQueryString (const Url &url) const
virtual void attachTo (bool next=false)
 Call concrete handler to attach the media.
virtual void releaseFrom (const std::string &ejectDev)
 Call concrete handler to release the media.
virtual void getFile (const Pathname &filename) const
 Call concrete handler to provide file below attach point.
virtual void getDir (const Pathname &dirname, bool recurse_r) const
 Call concrete handler to provide directory content (not recursive!) below attach point.
virtual void getDirInfo (std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
 Call concrete handler to provide a content list of directory on media via retlist.
virtual void getDirInfo (filesystem::DirContent &retlist, const Pathname &dirname, bool dots=true) const
 Basically the same as getDirInfo above.
virtual bool getDoesFileExist (const Pathname &filename) const
 Repeatedly calls doGetDoesFileExist() until it successfully returns, fails unexpectedly, or user cancels the operation.
virtual bool doGetDoesFileExist (const Pathname &filename) const
virtual void disconnectFrom ()
virtual void getFileCopy (const Pathname &srcFilename, const Pathname &targetFilename) const
virtual void doGetFileCopy (const Pathname &srcFilename, const Pathname &targetFilename, callback::SendReport< DownloadProgressReport > &_report, RequestOptions options=OPTION_NONE) const
virtual bool checkAttachPoint (const Pathname &apoint) const
 Verify if the specified directory as attach point (root) as requires by the particular media handler implementation.
void checkProtocol (const Url &url) const
 check the url is supported by the curl library
virtual void setupEasy ()
 initializes the curl easy handle with the data from the url
Url getFileUrl (const Pathname &filename) const
 concatenate the attach url and the filename to a complete download url
void evaluateCurlCode (const zypp::Pathname &filename, CURLcode code, bool timeout) const
 Evaluates a curl return code and throws the right MediaException filename Filename being downloaded code Code curl returnes timeout Whether we reached timeout, which we need to differentiate in case the codes aborted-by-callback or timeout are returned by curl Otherwise we can't differentiate abort from timeout.
void doGetFileCopyFile (const Pathname &srcFilename, const Pathname &dest, FILE *file, callback::SendReport< DownloadProgressReport > &_report, RequestOptions options=OPTION_NONE) const

Static Protected Member Functions

static int progressCallback (void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)

Protected Attributes

CURL * _curl
char _curlError [CURL_ERROR_SIZE]
curl_slist * _customHeaders
TransferSettings _settings

Private Member Functions

std::string getAuthHint () const
 Return a comma separated list of available authentication methods supported by server.
bool authenticate (const std::string &availAuthTypes, bool firstTry) const
bool detectDirIndex () const

Private Attributes

long _curlDebug
std::string _currentCookieFile

Static Private Attributes

static Pathname _cookieFile = "/var/lib/YaST2/cookies"

Detailed Description

Implementation class for FTP, HTTP and HTTPS MediaHandler.

See also:
MediaHandler

Definition at line 32 of file MediaCurl.h.


Member Enumeration Documentation

Enumerator:
OPTION_NONE 

Defaults.

OPTION_RANGE 

retrieve only a range of the file

OPTION_HEAD 

only issue a HEAD (or equivalent) request

OPTION_NO_IFMODSINCE 

to not add a IFMODSINCE header if target exists

OPTION_NO_REPORT_START 

do not send a start ProgressReport

Definition at line 35 of file MediaCurl.h.


Constructor & Destructor Documentation

zypp::media::MediaCurl::MediaCurl ( const Url url_r,
const Pathname &  attach_point_hint_r 
)
virtual zypp::media::MediaCurl::~MediaCurl ( ) [inline, virtual]

Definition at line 102 of file MediaCurl.h.

References zypp::media::MediaHandler::release().


Member Function Documentation

zypp::media::MediaCurl::ZYPP_DECLARE_FLAGS ( RequestOptions  ,
RequestOption   
)
Url zypp::media::MediaCurl::clearQueryString ( const Url url) const [protected]
void zypp::media::MediaCurl::attachTo ( bool  next = false) [protected, virtual]

Call concrete handler to attach the media.

Asserted that not already attached, and attachPoint is a directory.

Parameters:
nexttry next available device in turn until end of device list is reached (for media which are accessible through multiple devices like cdroms).
Exceptions:
MediaException

Implements zypp::media::MediaHandler.

Reimplemented in zypp::media::MediaAria2c.

Definition at line 714 of file MediaCurl.cc.

References _curl, zypp::media::MediaHandler::_url, zypp::Url::asString(), zypp::media::MediaHandler::attachPoint(), checkProtocol(), zypp::media::MediaHandler::createAttachPoint(), disconnectFrom(), zypp::Url::getScheme(), zypp::media::MediaHandler::isUseableAttachPoint(), zypp::Url::isValid(), zypp::media::MediaHandler::setAttachPoint(), zypp::media::MediaHandler::setMediaSource(), setupEasy(), zypp::media::MediaHandler::url(), ZYPP_RETHROW, and ZYPP_THROW.

void zypp::media::MediaCurl::releaseFrom ( const std::string &  ejectDev) [protected, virtual]

Call concrete handler to release the media.

If eject is true, and the media is used in one handler instance only, physically eject the media (i.e. CD-ROM).

Asserted that media is attached.

Parameters:
ejectDevDevice to eject. None if empty.
Exceptions:
MediaException

Implements zypp::media::MediaHandler.

Reimplemented in zypp::media::MediaAria2c.

Definition at line 778 of file MediaCurl.cc.

References zypp::media::MediaHandler::disconnect().

void zypp::media::MediaCurl::getFile ( const Pathname &  filename) const [protected, virtual]

Call concrete handler to provide file below attach point.

Default implementation provided, that returns whether a file is located at 'localRoot + filename'.

Asserted that media is attached.

Exceptions:
MediaException

Implements zypp::media::MediaHandler.

Reimplemented in zypp::media::MediaAria2c.

Definition at line 813 of file MediaCurl.cc.

References getFileCopy(), and zypp::media::MediaHandler::localPath().

Referenced by getDir().

void zypp::media::MediaCurl::getDir ( const Pathname &  dirname,
bool  recurse_r 
) const [protected, virtual]

Call concrete handler to provide directory content (not recursive!) below attach point.

Return E_not_supported_by_media if media does not support retrieval of directory content.

Default implementation provided, that returns whether a directory is located at 'localRoot + dirname'.

Asserted that media is attached.

Exceptions:
MediaException

Implements zypp::media::MediaHandler.

Reimplemented in zypp::media::MediaAria2c.

Definition at line 1430 of file MediaCurl.cc.

References zypp::filesystem::assert_dir(), zypp::filesystem::FT_DIR, zypp::filesystem::FT_FILE, zypp::filesystem::FT_NOT_AVAIL, getDirInfo(), getFile(), zypp::media::MediaHandler::localPath(), and WAR.

void zypp::media::MediaCurl::getDirInfo ( std::list< std::string > &  retlist,
const Pathname &  dirname,
bool  dots = true 
) const [protected, virtual]

Call concrete handler to provide a content list of directory on media via retlist.

If dots is false entries starting with '.' are not reported.

Return E_not_supported_by_media if media does not support retrieval of directory content.

Default implementation provided, that returns the content of a directory at 'localRoot + dirnname' retrieved via 'readdir'.

Asserted that media is attached and retlist is empty.

Exceptions:
MediaException

Implements zypp::media::MediaHandler.

Reimplemented in zypp::media::MediaAria2c.

Definition at line 1463 of file MediaCurl.cc.

References zypp::media::MediaHandler::getDirectoryYast().

Referenced by getDir().

void zypp::media::MediaCurl::getDirInfo ( filesystem::DirContent retlist,
const Pathname &  dirname,
bool  dots = true 
) const [protected, virtual]

Basically the same as getDirInfo above.

The content list is returned as filesystem::DirContent, which includes name and filetype of each directory entry. Retrieving the filetype usg. requires an additional ::stat call for each entry, thus it's more expensive than a simple readdir.

Asserted that media is attached and retlist is empty.

Exceptions:
MediaException

Implements zypp::media::MediaHandler.

Reimplemented in zypp::media::MediaAria2c.

Definition at line 1471 of file MediaCurl.cc.

References zypp::media::MediaHandler::getDirectoryYast().

bool zypp::media::MediaCurl::getDoesFileExist ( const Pathname &  filename) const [protected, virtual]

Repeatedly calls doGetDoesFileExist() until it successfully returns, fails unexpectedly, or user cancels the operation.

This is used to handle authentication or similar retry scenarios on media level.

Implements zypp::media::MediaHandler.

Reimplemented in zypp::media::MediaAria2c.

Definition at line 863 of file MediaCurl.cc.

References authenticate(), doGetDoesFileExist(), zypp::media::MediaUnauthorizedException::hint(), and ZYPP_RETHROW.

bool zypp::media::MediaCurl::doGetDoesFileExist ( const Pathname &  filename) const [protected, virtual]
void zypp::media::MediaCurl::disconnectFrom ( ) [protected, virtual]
Exceptions:
MediaException

Reimplemented from zypp::media::MediaHandler.

Reimplemented in zypp::media::MediaAria2c.

Definition at line 761 of file MediaCurl.cc.

References _curl, and _customHeaders.

Referenced by attachTo(), setupEasy(), and zypp::media::multifetchworker::~multifetchworker().

void zypp::media::MediaCurl::getFileCopy ( const Pathname &  srcFilename,
const Pathname &  targetFilename 
) const [protected, virtual]
void zypp::media::MediaCurl::doGetFileCopy ( const Pathname &  srcFilename,
const Pathname &  targetFilename,
callback::SendReport< DownloadProgressReport > &  _report,
RequestOptions  options = OPTION_NONE 
) const [protected, virtual]
bool zypp::media::MediaCurl::checkAttachPoint ( const Pathname &  apoint) const [protected, virtual]

Verify if the specified directory as attach point (root) as requires by the particular media handler implementation.

Parameters:
apointThe directory to check.
Returns:
True, if the directory checks succeeded.

Reimplemented from zypp::media::MediaHandler.

Reimplemented in zypp::media::MediaAria2c.

Definition at line 754 of file MediaCurl.cc.

TransferSettings & zypp::media::MediaCurl::settings ( )

Definition at line 477 of file MediaCurl.cc.

References _settings.

Referenced by zypp::media::MediaAccess::open().

void zypp::media::MediaCurl::setCookieFile ( const Pathname &  fileName) [static]

Definition at line 483 of file MediaCurl.cc.

References _cookieFile.

int zypp::media::MediaCurl::progressCallback ( void *  clientp,
double  dltotal,
double  dlnow,
double  ultotal,
double  ulnow 
) [static, protected]

Todo:
more accurate download rate computationn, e.g. compute average value from last 5 seconds, or work with milliseconds instead of seconds

Definition at line 1479 of file MediaCurl.cc.

Referenced by setupEasy().

void zypp::media::MediaCurl::checkProtocol ( const Url url) const [protected]

check the url is supported by the curl library

Exceptions:
MediaBadUrlExceptionif there is a problem

Definition at line 490 of file MediaCurl.cc.

References zypp::media::MediaHandler::_url, zypp::Url::getScheme(), and ZYPP_THROW.

Referenced by attachTo(), and zypp::media::MediaMultiCurl::multifetch().

void zypp::media::MediaCurl::setupEasy ( ) [protected, virtual]

initializes the curl easy handle with the data from the url

Exceptions:
MediaCurlSetOptExceptionif there is a problem

Connect timeout

Speed limits

Reimplemented in zypp::media::MediaMultiCurl.

Definition at line 515 of file MediaCurl.cc.

References _cookieFile, _curl, _curlDebug, _curlError, _currentCookieFile, _customHeaders, _settings, zypp::media::MediaHandler::_url, zypp::media::TransferSettings::addHeader(), zypp::media::agentString(), zypp::media::anonymousIdHeader(), zypp::media::CurlAuthData::auth_type_str2long(), zypp::media::TransferSettings::authType(), zypp::media::TransferSettings::certificateAuthoritiesPath(), CONNECT_TIMEOUT, zypp::media::TransferSettings::connectTimeout(), DBG, disconnectFrom(), zypp::media::distributionFlavorHeader(), zypp::media::fillSettingsFromUrl(), zypp::media::fillSettingsSystemProxy(), zypp::Url::getQueryParam(), zypp::Url::getScheme(), zypp::media::TransferSettings::headersBegin(), zypp::media::TransferSettings::headersEnd(), zypp::media::TransferSettings::maxDownloadSpeed(), MIL, zypp::media::TransferSettings::minDownloadSpeed(), zypp::media::CurlConfig::parseConfig(), progressCallback(), zypp::media::TransferSettings::proxy(), zypp::media::TransferSettings::proxyEnabled(), zypp::media::TransferSettings::proxyUserPassword(), zypp::media::CurlConfig::proxyuserpwd, SET_OPTION, SET_OPTION_OFFT, zypp::media::TransferSettings::setConnectTimeout(), zypp::media::TransferSettings::setTimeout(), zypp::media::TransferSettings::setUserAgentString(), zypp::str::strToBool(), TRANSFER_TIMEOUT, zypp::media::TransferSettings::userAgentString(), zypp::media::TransferSettings::userPassword(), zypp::media::TransferSettings::verifyHostEnabled(), zypp::media::TransferSettings::verifyPeerEnabled(), ZYPP_RETHROW, and ZYPP_THROW.

Referenced by attachTo(), and zypp::media::multifetchworker::multifetchworker().

Url zypp::media::MediaCurl::getFileUrl ( const Pathname &  filename) const [protected]
void zypp::media::MediaCurl::evaluateCurlCode ( const zypp::Pathname &  filename,
CURLcode  code,
bool  timeout 
) const [protected]

Evaluates a curl return code and throws the right MediaException filename Filename being downloaded code Code curl returnes timeout Whether we reached timeout, which we need to differentiate in case the codes aborted-by-callback or timeout are returned by curl Otherwise we can't differentiate abort from timeout.

Here you may want to pass the progress data object timeout-reached value, or just true if you are not doing user interaction.

Exceptions:
MediaExceptionIf there is a problem

Definition at line 894 of file MediaCurl.cc.

References _, _curl, _curlError, zypp::media::MediaHandler::_url, zypp::Url::asString(), DBG, getAuthHint(), getFileUrl(), zypp::str::numstring(), zypp::media::MediaHandler::url(), ZYPP_RETHROW, and ZYPP_THROW.

Referenced by doGetDoesFileExist(), doGetFileCopyFile(), and zypp::media::multifetchrequest::run().

void zypp::media::MediaCurl::doGetFileCopyFile ( const Pathname &  srcFilename,
const Pathname &  dest,
FILE *  file,
callback::SendReport< DownloadProgressReport > &  _report,
RequestOptions  options = OPTION_NONE 
) const [protected]
string zypp::media::MediaCurl::getAuthHint ( ) const [private]

Return a comma separated list of available authentication methods supported by server.

Definition at line 1570 of file MediaCurl.cc.

References _curl, and zypp::media::CurlAuthData::auth_type_long2str().

Referenced by evaluateCurlCode().

bool zypp::media::MediaCurl::authenticate ( const std::string &  availAuthTypes,
bool  firstTry 
) const [private]

Todo:
need a way to pass different CredManagerOptions here
Todo:
add comma to the message for the next release
Todo:
find a way to save the url with changed username back to repoinfo or dont store urls with username (and either forbid more repos with the same url and different user, or return a set of credentials from CM and try them one by one)

Reimplemented in zypp::media::MediaAria2c.

Definition at line 1587 of file MediaCurl.cc.

References _, _curl, _curlError, _settings, zypp::media::MediaHandler::_url, zypp::media::CredentialManager::addCred(), zypp::Url::asString(), DBG, zypp::media::CredentialManager::getCred(), zypp::Url::getUsername(), zypp::media::CredentialManager::save(), zypp::media::TransferSettings::setAuthType(), zypp::media::TransferSettings::setPassword(), zypp::media::TransferSettings::setUsername(), zypp::media::TransferSettings::userPassword(), and ZYPP_THROW.

Referenced by getDoesFileExist(), and getFileCopy().

bool zypp::media::MediaCurl::detectDirIndex ( ) const [private]

Referenced by doGetFileCopyFile().


Member Data Documentation

Definition at line 164 of file MediaCurl.h.

Referenced by MediaCurl(), and setupEasy().

Reimplemented in zypp::media::MediaAria2c.

Definition at line 166 of file MediaCurl.h.

Referenced by setupEasy().

Pathname zypp::media::MediaCurl::_cookieFile = "/var/lib/YaST2/cookies" [static, private]

Reimplemented in zypp::media::MediaAria2c.

Definition at line 167 of file MediaCurl.h.

Referenced by setCookieFile(), and setupEasy().

CURL* zypp::media::MediaCurl::_curl [protected]
char zypp::media::MediaCurl::_curlError[CURL_ERROR_SIZE] [protected]
curl_slist* zypp::media::MediaCurl::_customHeaders [protected]

The documentation for this class was generated from the following files: