Implementation class for FTP, HTTP and HTTPS MediaHandler. More...
#include <MediaCurl.h>
Classes | |
class | Callbacks |
Public Types | |
enum | RequestOption { OPTION_NONE = 0x0, OPTION_RANGE = 0x1, OPTION_HEAD = 0x02 } |
Public Member Functions | |
ZYPP_DECLARE_FLAGS (RequestOptions, RequestOption) | |
MediaCurl (const Url &url_r, const Pathname &attach_point_hint_r) | |
virtual | ~MediaCurl () |
Static Public Member Functions | |
static void | setCookieFile (const Pathname &) |
Protected Member Functions | |
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. | |
Static Protected Member Functions | |
static int | progressCallback (void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) |
Protected Attributes | |
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 |
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. | |
Private Attributes | |
CURL * | _curl |
char | _curlError [CURL_ERROR_SIZE] |
long | _curlDebug |
curl_slist * | _customHeaders |
std::string | _currentCookieFile |
Static Private Attributes | |
static Pathname | _cookieFile = "/var/lib/YaST2/cookies" |
Implementation class for FTP, HTTP and HTTPS MediaHandler.
Definition at line 32 of file MediaCurl.h.
OPTION_NONE |
Defaults. |
OPTION_RANGE |
retrieve only a range of the file |
OPTION_HEAD |
only issue a HEAD (or equivalent) request |
Definition at line 35 of file MediaCurl.h.
zypp::media::MediaCurl::MediaCurl | ( | const Url & | url_r, | |
const Pathname & | attach_point_hint_r | |||
) |
Definition at line 383 of file MediaCurl.cc.
References _curlDebug, _curlError, zypp::media::MediaHandler::attachPoint(), zypp::Url::getScheme(), MIL, zypp::filesystem::rmdir(), zypp::media::MediaHandler::setAttachPoint(), and WAR.
virtual zypp::media::MediaCurl::~MediaCurl | ( | ) | [inline, virtual] |
Definition at line 96 of file MediaCurl.h.
References zypp::media::MediaHandler::release().
zypp::media::MediaCurl::ZYPP_DECLARE_FLAGS | ( | RequestOptions | , | |
RequestOption | ||||
) |
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.
next | try next available device in turn until end of device list is reached (for media which are accessible through multiple devices like cdroms). |
MediaException |
Connect timeout
Speed limits
Implements zypp::media::MediaHandler.
Reimplemented in zypp::media::MediaAria2c.
Definition at line 426 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::Url::asString(), zypp::media::MediaHandler::attachPoint(), zypp::media::CurlAuthData::auth_type_str2long(), zypp::media::TransferSettings::certificateAuthoritiesPath(), CONNECT_TIMEOUT, zypp::media::TransferSettings::connectTimeout(), zypp::media::MediaHandler::createAttachPoint(), DBG, disconnectFrom(), zypp::media::distributionFlavorHeader(), zypp::media::fillSettingsFromUrl(), zypp::media::fillSettingsSystemProxy(), getAuthHint(), zypp::Url::getQueryParam(), zypp::Url::getScheme(), zypp::media::TransferSettings::headersBegin(), zypp::media::TransferSettings::headersEnd(), zypp::media::MediaHandler::isUseableAttachPoint(), zypp::Url::isValid(), zypp::media::TransferSettings::maxDownloadSpeed(), MIL, zypp::media::TransferSettings::minDownloadSpeed(), zypp::Exception::msg(), zypp::media::CurlConfig::parseConfig(), progressCallback(), zypp::media::TransferSettings::proxy(), zypp::media::TransferSettings::proxyEnabled(), zypp::media::TransferSettings::proxyUserPassword(), zypp::media::CurlConfig::proxyuserpwd, zypp::media::TransferSettings::reset(), SET_OPTION, SET_OPTION_OFFT, zypp::media::MediaHandler::setAttachPoint(), zypp::media::TransferSettings::setConnectTimeout(), zypp::media::MediaHandler::setMediaSource(), zypp::media::TransferSettings::setTimeout(), zypp::media::TransferSettings::setUserAgentString(), zypp::str::strToBool(), TRANSFER_TIMEOUT, zypp::media::MediaHandler::url(), zypp::media::TransferSettings::userAgentString(), zypp::media::TransferSettings::userPassword(), zypp::media::TransferSettings::verifyHostEnabled(), zypp::media::TransferSettings::verifyPeerEnabled(), 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.
ejectDev | Device to eject. None if empty. |
MediaException |
Implements zypp::media::MediaHandler.
Reimplemented in zypp::media::MediaAria2c.
Definition at line 704 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.
MediaException |
Implements zypp::media::MediaHandler.
Reimplemented in zypp::media::MediaAria2c.
Definition at line 739 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.
MediaException |
Implements zypp::media::MediaHandler.
Reimplemented in zypp::media::MediaAria2c.
Definition at line 1324 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.
MediaException |
Implements zypp::media::MediaHandler.
Reimplemented in zypp::media::MediaAria2c.
Definition at line 1357 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.
MediaException |
Implements zypp::media::MediaHandler.
Reimplemented in zypp::media::MediaAria2c.
Definition at line 1365 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 789 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] |
Reimplemented in zypp::media::MediaAria2c.
Definition at line 945 of file MediaCurl.cc.
References _curl, _curlError, zypp::media::MediaHandler::_url, zypp::Url::asString(), DBG, ERR, evaluateCurlCode(), zypp::media::getFileUrl(), zypp::Url::getHost(), zypp::Url::getScheme(), zypp::Url::isValid(), MIL, zypp::Url::setFragment(), zypp::Url::setPassword(), zypp::Url::setPathParams(), zypp::Url::setQueryString(), zypp::Url::setUsername(), zypp::media::MediaHandler::url(), ZYPP_RETHROW, and ZYPP_THROW.
Referenced by getDoesFileExist().
void zypp::media::MediaCurl::disconnectFrom | ( | ) | [protected, virtual] |
MediaException |
Reimplemented from zypp::media::MediaHandler.
Reimplemented in zypp::media::MediaAria2c.
Definition at line 687 of file MediaCurl.cc.
References _curl, and _customHeaders.
Referenced by attachTo().
void zypp::media::MediaCurl::getFileCopy | ( | const Pathname & | srcFilename, | |
const Pathname & | targetFilename | |||
) | const [protected, virtual] |
MediaException |
Reimplemented from zypp::media::MediaHandler.
Reimplemented in zypp::media::MediaAria2c.
Definition at line 748 of file MediaCurl.cc.
References zypp::media::MediaHandler::_url, zypp::media::DownloadProgressReport::ACCESS_DENIED, zypp::Exception::asUserHistory(), authenticate(), doGetFileCopy(), zypp::media::DownloadProgressReport::ERROR, zypp::media::getFileUrl(), zypp::media::MediaUnauthorizedException::hint(), zypp::media::DownloadProgressReport::NO_ERROR, report, and ZYPP_RETHROW.
Referenced by getFile().
void zypp::media::MediaCurl::doGetFileCopy | ( | const Pathname & | srcFilename, | |
const Pathname & | targetFilename, | |||
callback::SendReport< DownloadProgressReport > & | _report, | |||
RequestOptions | options = OPTION_NONE | |||
) | const [protected, virtual] |
MediaException |
Definition at line 1098 of file MediaCurl.cc.
References _curl, _curlError, _settings, zypp::media::MediaHandler::_url, zypp::filesystem::applyUmaskTo(), zypp::filesystem::assert_dir(), zypp::Url::asString(), DBG, ERR, evaluateCurlCode(), zypp::media::getFileUrl(), zypp::Url::getHost(), zypp::Url::getPathName(), zypp::Url::getScheme(), zypp::Url::isValid(), zypp::str::numstring(), zypp::filesystem::rename(), zypp::Url::setFragment(), zypp::Url::setPassword(), zypp::Url::setPathParams(), zypp::Url::setQueryString(), zypp::Url::setUsername(), zypp::media::TransferSettings::timeout(), zypp::filesystem::unlink(), zypp::media::MediaHandler::url(), WAR, ZYPP_RETHROW, and ZYPP_THROW.
Referenced by getFileCopy().
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.
apoint | The directory to check. |
Reimplemented from zypp::media::MediaHandler.
Reimplemented in zypp::media::MediaAria2c.
Definition at line 680 of file MediaCurl.cc.
void zypp::media::MediaCurl::setCookieFile | ( | const Pathname & | fileName | ) | [static] |
Definition at line 419 of file MediaCurl.cc.
References _cookieFile.
int zypp::media::MediaCurl::progressCallback | ( | void * | clientp, | |
double | dltotal, | |||
double | dlnow, | |||
double | ultotal, | |||
double | ulnow | |||
) | [static, protected] |
Definition at line 1373 of file MediaCurl.cc.
Referenced by attachTo().
string zypp::media::MediaCurl::getAuthHint | ( | ) | const [private] |
Return a comma separated list of available authentication methods supported by server.
Definition at line 1464 of file MediaCurl.cc.
References _curl, and zypp::media::CurlAuthData::auth_type_long2str().
Referenced by attachTo(), and evaluateCurlCode().
bool zypp::media::MediaCurl::authenticate | ( | const std::string & | availAuthTypes, | |
bool | firstTry | |||
) | const [private] |
Reimplemented in zypp::media::MediaAria2c.
Referenced by getDoesFileExist(), and getFileCopy().
void zypp::media::MediaCurl::evaluateCurlCode | ( | const zypp::Pathname & | filename, | |
CURLcode | code, | |||
bool | timeout | |||
) | const [private] |
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.
MediaException | If there is a problem |
Definition at line 820 of file MediaCurl.cc.
References _, _curl, _curlError, zypp::media::MediaHandler::_url, zypp::Url::asString(), DBG, getAuthHint(), zypp::media::getFileUrl(), zypp::str::numstring(), zypp::media::MediaHandler::url(), ZYPP_RETHROW, and ZYPP_THROW.
Referenced by doGetDoesFileExist(), and doGetFileCopy().
CURL* zypp::media::MediaCurl::_curl [private] |
Definition at line 136 of file MediaCurl.h.
Referenced by attachTo(), disconnectFrom(), doGetDoesFileExist(), doGetFileCopy(), evaluateCurlCode(), and getAuthHint().
char zypp::media::MediaCurl::_curlError[CURL_ERROR_SIZE] [private] |
Definition at line 137 of file MediaCurl.h.
Referenced by attachTo(), doGetDoesFileExist(), doGetFileCopy(), evaluateCurlCode(), and MediaCurl().
long zypp::media::MediaCurl::_curlDebug [private] |
Definition at line 138 of file MediaCurl.h.
Referenced by attachTo(), and MediaCurl().
curl_slist* zypp::media::MediaCurl::_customHeaders [private] |
Definition at line 139 of file MediaCurl.h.
Referenced by attachTo(), and disconnectFrom().
std::string zypp::media::MediaCurl::_currentCookieFile [private] |
Reimplemented in zypp::media::MediaAria2c.
Definition at line 141 of file MediaCurl.h.
Referenced by attachTo().
Pathname zypp::media::MediaCurl::_cookieFile = "/var/lib/YaST2/cookies" [static, private] |
Reimplemented in zypp::media::MediaAria2c.
Definition at line 142 of file MediaCurl.h.
Referenced by attachTo(), and setCookieFile().
TransferSettings zypp::media::MediaCurl::_settings [protected] |
Definition at line 144 of file MediaCurl.h.
Referenced by attachTo(), zypp::media::MediaAria2c::attachTo(), doGetFileCopy(), and zypp::media::MediaAria2c::getFileCopy().