libzypp 17.37.10

zypp::media::MediaCurl Class Reference

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

`#include <zypp/media/MediaCurl.h>`

Inheritance diagram for zypp::media::MediaCurl:

## Classes
struct | RequestData

## Public Member Functions
| MediaCurl (const MirroredOrigin &origin_r, const Pathname &attach_point_hint_r)
| ~MediaCurl () override
Public Member Functions inherited from zypp::media::MediaNetworkCommonHandler
| MediaNetworkCommonHandler (const MirroredOrigin &origin_r, const Pathname &attach_point_r, const Pathname &urlpath_below_attachpoint_r, const bool does_download_r)
void | getFile (const OnMediaLocation &file) const override
| Call concrete handler to provide file below attach point.
void | getDir (const Pathname &dirname, bool recurse_r) const override
| Call concrete handler to provide directory content (not recursive!) below attach point.
void | getDirInfo (std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const override
| Call concrete handler to provide a content list of directory on media via retlist.
void | getDirInfo (filesystem::DirContent &retlist, const Pathname &dirname, bool dots=true) const override
| Basically the same as getDirInfo above.
Public Member Functions inherited from zypp::media::MediaHandler
bool | dependsOnParent (MediaAccessId parentId, bool exactIdMatch)
| Check if the current media handler depends on an another handler specified by media access id.
bool | dependsOnParent ()
void | resetParentId ()
| Called in case, where the media manager takes over the destruction of the parent id (e.g.
Pathname | attachPoint () const
| Return the currently used attach point.
void | setAttachPoint (const Pathname &path, bool temp)
| Set a new attach point.
void | setAttachPoint (const AttachPointRef &ref)
| Set a (shared) attach point.
AttachPoint | attachPointHint () const
| Get the actual attach point hint.
void | attachPointHint (const Pathname &path, bool temp)
| Set the attach point hint as specified by the user.
Pathname | createAttachPoint () const
| Try to create a default / temporary attach point.
Pathname | createAttachPoint (const Pathname &attach_root) const
| Try to create a temporary attach point in specified root.
void | removeAttachPoint ()
| Remove unused attach point.
bool | isUseableAttachPoint (const Pathname &path, bool mtab=true) const
| Ask media manager, if the specified path is already used as attach point or if there are another attach points bellow of it.
std::string | mediaSourceName () const
| Get the media source name or an empty string.
void | setMediaSource (const MediaSourceRef &ref)
| Set new media source reference.
AttachedMedia | findAttachedMedia (const MediaSourceRef &media) const
| Ask the media manager if specified media source is already attached.
AttachedMedia | attachedMedia () const
| Returns the attached media.
bool | isSharedMedia () const
| Returns a hint if the media is shared or not.
bool | checkAttached (bool matchMountFs) const
| Check actual mediaSource attachment against the current mount table of the system.
void | forceRelaseAllMedia (bool matchMountFs)
| Call to this function will try to release all media matching the currenlty attached media source, that it is able to find in the mount table.
void | forceRelaseAllMedia (const MediaSourceRef &ref, bool matchMountFs)
| MediaHandler (MirroredOrigin origin_r, const Pathname &attach_point_r, Pathname urlpath_below_attachpoint_r, const bool does_download_r)
| If the concrete media handler provides a nonempty attach_point, it must be an existing directory.
virtual | ~MediaHandler ()
| Contolling MediaAccess takes care, that attached media is released prior to deleting this.
bool | downloads () const
| Hint if files are downloaded or not.
std::string | protocol () const
| Protocol hint for MediaAccess.
Url | url () const
| Primary Url used.
OriginEndpoint | originEndpoint () const
| Primary OriginEndpoint used.
void | attach (bool next)
| Use concrete handler to attach the media.
virtual bool | isAttached () const
| True if media is attached.
Pathname | localRoot () const
| Return the local directory that corresponds to medias url, no matter if media isAttached or not.
Pathname | localPath (const Pathname &pathname) const
| Files provided will be available at 'localPath(filename)'.
void | disconnect ()
| Use concrete handler to isconnect media.
void | release (const std::string &ejectDev="")
| Use concrete handler to release the media.
void | provideFile (const OnMediaLocation &file) const
| Use concrete handler to provide file denoted by path below 'localRoot'.
void | provideFileCopy (const OnMediaLocation &srcFile, const Pathname &targetFilename) const
| Call concrete handler to provide a copy of a file under a different place in the file system (usually not under attach point) as a copy.
void | provideDir (const Pathname &dirname) const
| Use concrete handler to provide directory denoted by path below 'localRoot' (not recursive!).
void | provideDirTree (const Pathname &dirname) const
| Use concrete handler to provide directory tree denoted by path below 'localRoot' (recursive!
void | releaseFile (const Pathname &filename) const
| Remove filename below localRoot IFF handler downloads files to the local filesystem.
void | releaseDir (const Pathname &dirname) const
| Remove directory tree below localRoot IFF handler downloads files to the local filesystem.
void | releasePath (const Pathname &pathname) const
| Remove pathname below localRoot IFF handler downloads files to the local filesystem.
void | dirInfo (std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
| Return content of directory on media via retlist.
void | dirInfo (filesystem::DirContent &retlist, const Pathname &dirname, bool dots=true) const
| Basically the same as dirInfo above.
bool | doesFileExist (const Pathname &filename) const
| check if a file exists
virtual bool | hasMoreDevices ()
| Check if the media has one more device available for attach(true).
virtual void | getDetectedDevices (std::vector< std::string > &devices, unsigned int &index) const
| Fill in a vector of detected ejectable devices and the index of the currently attached device within the vector.
virtual void | precacheFiles (const std::vector< OnMediaLocation > &files)
| Tries to fetch the given files and precaches them.

## Static Public Member Functions
static void | setCookieFile (const Pathname &)
Static Public Member Functions inherited from zypp::media::MediaNetworkCommonHandler
static zypp::Url | findGeoIPRedirect (const zypp::Url &url)
| Rewrites the baseURL to the geoIP target if one is found in the metadata cache, otherwise simply returns the url again.
static bool | authenticate (const Url &url, CredentialManager &cm, TransferSettings &settings, const std::string &availAuthTypes, bool firstTry)
static const char * | anonymousIdHeader ()
static const char * | distributionFlavorHeader ()
static const char * | agentString ()
template<typename Excpt>
static bool | canTryNextMirror (const Excpt &excpt_r)
Static Public Member Functions inherited from zypp::media::MediaHandler
static bool | setAttachPrefix (const Pathname &attach_prefix)
static std::string | getRealPath (const std::string &path)
static Pathname | getRealPath (const Pathname &path)
static bool | checkAttachPoint (const Pathname &apoint, bool empty_dir, bool writeable)
| Verify if the specified directory as attach point (root) using requested checks.

## Protected Member Functions
void | releaseFrom (const std::string &ejectDev) override
| Call concrete handler to release the media.
bool | getDoesFileExist (const Pathname &filename) const override
| Repeatedly calls doGetDoesFileExist() until it successfully returns, fails unexpectedly, or user cancels the operation.
bool | doGetDoesFileExist (const int mirror, const Pathname &filename)
void | disconnectFrom () override
void | getFileCopy (const OnMediaLocation &srcFile, const Pathname &target) const override
void | getFileCopyFromMirror (const int mirror, const OnMediaLocation &srcFile, const Pathname &target)
void | checkProtocol (const Url &url) const override
| check the url is supported by the curl library
void | setupEasy (RequestData &rData, TransferSettings &settings)
| initializes the curl easy handle with the data from the url
void | evaluateCurlCode (RequestData &rData, 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.
Protected Member Functions inherited from zypp::media::MediaNetworkCommonHandler
void | attachTo (bool next) override
| Call concrete handler to attach the media.
bool | checkAttachPoint (const Pathname &apoint) const override
| Verify if the specified directory as attach point (root) as requires by the particular media handler implementation.
Url | clearQueryString (const Url &url) const
Url | getFileUrl (int mirrorIdx, const Pathname &filename) const
| concatenate the attach url and the filename to a complete download url
void | setupTransferSettings ()
| initializes the curl easy handle with the data from the url
void | clearTransferSettings ()
bool | authenticate (const Url &url, TransferSettings &settings, const std::string &availAuthTypes, bool firstTry)
std::vector< unsigned > | mirrorOrder (const OnMediaLocation &loc) const
Protected Member Functions inherited from zypp::media::MediaHandler
virtual void | forceEject (const std::string &device)
| Call concrete handler to physically eject the media (i.e.
void | getDirectoryYast (std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
| Retrieve and if available scan dirname/directory.yast.
void | getDirectoryYast (filesystem::DirContent &retlist, const Pathname &dirname, bool dots=true) const
| Retrieve and if available scan dirname/directory.yast.

## Static Protected Member Functions
static int | aliveCallback (void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
| Callback sending just an alive trigger to the UI, without stats (e.g.
static int | progressCallback (void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
| Callback reporting download progress.
static size_t | writeCallback (char *ptr, size_t size, size_t nmemb, void *userdata)
| Callback writing the data into our file.
static void | resetExpectedFileSize (void *clientp, const ByteCount &expectedFileSize)
| MediaMultiCurl needs to reset the expected filesize in case a metalink file is downloaded otherwise this function should not be called.

## Private Member Functions
CURLcode | executeCurl (RequestData &rData)
std::string | getAuthHint (CURL *curl) const
| Return a comma separated list of available authentication methods supported by server.
bool | detectDirIndex () const
const char * | curlError () const
void | setCurlError (const char *error)

## Private Attributes
std::string | _currentCookieFile
char | _curlError [CURL_ERROR_SIZE]
std::string | _lastRedirect
| to log/report redirections
curl_slist * | _customHeaders

## Static Private Attributes
static Pathname | _cookieFile = "/var/lib/YaST2/cookies"

## Additional Inherited Members
Public Types inherited from zypp::media::MediaHandler
using | Ptr = shared_ptr<MediaHandler>
using | constPtr = shared_ptr<const MediaHandler>
Public Attributes inherited from internal::CurlPollHelper::CurlPoll
CURLM * | _multi = nullptr
Static Public Attributes inherited from zypp::media::MediaNetworkCommonHandler
static constexpr std::string_view | MIRR_SETTINGS_KEY = "_zypp_transfersettings"
Protected Attributes inherited from zypp::media::MediaNetworkCommonHandler
std::vector< Url > | _redirTargets
Protected Attributes inherited from zypp::media::MediaHandler
MirroredOrigin | _origin
| Contains the authority URL and mirrors.
MediaAccessId | _parentId
| Access Id of media handler we depend on.

## Detailed Description

Implementation class for FTP, HTTP and HTTPS MediaHandler.

See also
  MediaHandler

Definition at line 32 of file MediaCurl.h.

## Constructor & Destructor Documentation

## ◆ MediaCurl()

zypp::media::MediaCurl::MediaCurl | ( | const MirroredOrigin & | origin_r,
|  | const Pathname & | attach_point_hint_r )

Definition at line 231 of file MediaCurl.cc.

## ◆ ~MediaCurl()

zypp::media::MediaCurl::~MediaCurl | ( |  | ) |
| override

Definition at line 267 of file MediaCurl.cc.

## Member Function Documentation

## ◆ releaseFrom()

void zypp::media::MediaCurl::releaseFrom | ( | const std::string & | ejectDev | ) |
| override 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

  ejectDev | Device to eject. None if empty.

Exceptions

  MediaException |

Implements zypp::media::MediaHandler.

Definition at line 548 of file MediaCurl.cc.

## ◆ getDoesFileExist()

bool zypp::media::MediaCurl::getDoesFileExist | ( | const Pathname & | filename | ) | const
| override 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.

Definition at line 846 of file MediaCurl.cc.

## ◆ doGetDoesFileExist()

bool zypp::media::MediaCurl::doGetDoesFileExist | ( | const int | mirror,
|  | const Pathname & | filename )
| protected

See also
  MediaHandler::getDoesFileExist

Definition at line 1019 of file MediaCurl.cc.

## ◆ disconnectFrom()

void zypp::media::MediaCurl::disconnectFrom | ( |  | ) |
| override protected virtual

Exceptions

  MediaException |

Reimplemented from zypp::media::MediaHandler.

Definition at line 535 of file MediaCurl.cc.

## ◆ getFileCopy()

void zypp::media::MediaCurl::getFileCopy | ( | const OnMediaLocation & | srcFile,
|  | const Pathname & | target ) const
| override protected virtual

Exceptions

  MediaException |

Reimplemented from zypp::media::MediaHandler.

Definition at line 555 of file MediaCurl.cc.

## ◆ getFileCopyFromMirror()

void zypp::media::MediaCurl::getFileCopyFromMirror | ( | const int | mirror,
|  | const OnMediaLocation & | srcFile,
|  | const Pathname & | target )
| protected

Definition at line 580 of file MediaCurl.cc.

## ◆ setCookieFile()

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

Definition at line 274 of file MediaCurl.cc.

## ◆ aliveCallback()

int zypp::media::MediaCurl::aliveCallback | ( | void * | clientp,
|  | curl_off_t | dltotal,
|  | curl_off_t | dlnow,
|  | curl_off_t | ultotal,
|  | curl_off_t | ulnow )
| static protected

Callback sending just an alive trigger to the UI, without stats (e.g.

during metalink download).

Definition at line 1124 of file MediaCurl.cc.

## ◆ progressCallback()

int zypp::media::MediaCurl::progressCallback | ( | void * | clientp,
|  | curl_off_t | dltotal,
|  | curl_off_t | dlnow,
|  | curl_off_t | ultotal,
|  | curl_off_t | ulnow )
| static protected

Callback reporting download progress.

Definition at line 1138 of file MediaCurl.cc.

## ◆ writeCallback()

size_t zypp::media::MediaCurl::writeCallback | ( | char * | ptr,
|  | size_t | size,
|  | size_t | nmemb,
|  | void * | userdata )
| static protected

Callback writing the data into our file.

Definition at line 1154 of file MediaCurl.cc.

## ◆ checkProtocol()

void zypp::media::MediaCurl::checkProtocol | ( | const Url & | url | ) | const
| override protected virtual

check the url is supported by the curl library

Exceptions

  MediaBadUrlException | if there is a problem

Implements zypp::media::MediaNetworkCommonHandler.

Definition at line 288 of file MediaCurl.cc.

## ◆ setupEasy()

void zypp::media::MediaCurl::setupEasy | ( | RequestData & | rData,
|  | TransferSettings & | settings )
| protected

initializes the curl easy handle with the data from the url

Exceptions

  MediaCurlSetOptException | if there is a problem

Force IPv4/v6

Connect timeout

Speed limits

Definition at line 313 of file MediaCurl.cc.

## ◆ evaluateCurlCode()

void zypp::media::MediaCurl::evaluateCurlCode | ( | RequestData & | rData,
|  | 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

  MediaException | If there is a problem

Definition at line 876 of file MediaCurl.cc.

## ◆ resetExpectedFileSize()

void zypp::media::MediaCurl::resetExpectedFileSize | ( | void * | clientp,
|  | const ByteCount & | expectedFileSize )
| static protected

MediaMultiCurl needs to reset the expected filesize in case a metalink file is downloaded otherwise this function should not be called.

Definition at line 1184 of file MediaCurl.cc.

## ◆ executeCurl()

CURLcode zypp::media::MediaCurl::executeCurl | ( | RequestData & | rData | ) |
| private

Executes the given curl handle in a multi context

Note
  this should not be a const function, but API forces us to do so

Definition at line 1197 of file MediaCurl.cc.

## ◆ getAuthHint()

std::string zypp::media::MediaCurl::getAuthHint | ( | CURL * | curl | ) | const
| private

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

Definition at line 1165 of file MediaCurl.cc.

## ◆ detectDirIndex()

bool zypp::media::MediaCurl::detectDirIndex | ( |  | ) | const
| private

## ◆ curlError()

const char * zypp::media::MediaCurl::curlError | ( |  | ) | const
| inline private

Definition at line 133 of file MediaCurl.h.

## ◆ setCurlError()

void zypp::media::MediaCurl::setCurlError | ( | const char * | error | ) |
| private

Definition at line 279 of file MediaCurl.cc.

## Member Data Documentation

## ◆ _currentCookieFile

std::string zypp::media::MediaCurl::_currentCookieFile
| private

Definition at line 126 of file MediaCurl.h.

## ◆ _cookieFile

Pathname zypp::media::MediaCurl::_cookieFile = "/var/lib/YaST2/cookies"
| static private

Definition at line 127 of file MediaCurl.h.

## ◆ _curlError

char zypp::media::MediaCurl::_curlError[CURL_ERROR_SIZE]
| private

Definition at line 128 of file MediaCurl.h.

## ◆ _lastRedirect

std::string zypp::media::MediaCurl::_lastRedirect
| mutable private

to log/report redirections

Definition at line 130 of file MediaCurl.h.

## ◆ _customHeaders

curl_slist* zypp::media::MediaCurl::_customHeaders
| private

Definition at line 131 of file MediaCurl.h.

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

- zypp/media/MediaCurl.h
- zypp/media/MediaCurl.cc