libzypp  17.7.0
zypp::media::MediaCurl Class Reference

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

#include <MediaCurl.h>

Inheritance diagram for zypp::media::MediaCurl:

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 Types inherited from zypp::media::MediaHandler
typedef shared_ptr< MediaHandlerPtr
 
typedef shared_ptr< const MediaHandlerconstPtr
 

Public Member Functions

 ZYPP_DECLARE_FLAGS (RequestOptions, RequestOption)
 
 MediaCurl (const Url &url_r, const Pathname &attach_point_hint_r)
 
virtual ~MediaCurl ()
 
TransferSettingssettings ()
 
- Public Member Functions inherited from zypp::media::MediaHandler
 MediaHandler (const Url &url_r, const Pathname &attach_point_r, const 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. More...
 
virtual ~MediaHandler ()
 Contolling MediaAccess takes care, that attached media is released prior to deleting this. More...
 
bool downloads () const
 Hint if files are downloaded or not. More...
 
std::string protocol () const
 Protocol hint for MediaAccess. More...
 
Url url () const
 Url used. More...
 
void attach (bool next)
 Use concrete handler to attach the media. More...
 
virtual bool isAttached () const
 True if media is attached. More...
 
Pathname localRoot () const
 Return the local directory that corresponds to medias url, no matter if media isAttached or not. More...
 
Pathname localPath (const Pathname &pathname) const
 Files provided will be available at 'localPath(filename)'. More...
 
void disconnect ()
 Use concrete handler to isconnect media. More...
 
void release (const std::string &ejectDev="")
 Use concrete handler to release the media. More...
 
void provideFile (Pathname filename, const ByteCount &expectedFileSize_r) const
 Use concrete handler to provide file denoted by path below 'localRoot'. More...
 
void provideFileCopy (Pathname srcFilename, Pathname targetFilename, const ByteCount &expectedFileSize_r) 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. More...
 
void provideDir (Pathname dirname) const
 Use concrete handler to provide directory denoted by path below 'localRoot' (not recursive!). More...
 
void provideDirTree (Pathname dirname) const
 Use concrete handler to provide directory tree denoted by path below 'localRoot' (recursive!!). More...
 
void releaseFile (const Pathname &filename) const
 Remove filename below localRoot IFF handler downloads files to the local filesystem. More...
 
void releaseDir (const Pathname &dirname) const
 Remove directory tree below localRoot IFF handler downloads files to the local filesystem. More...
 
void releasePath (Pathname pathname) const
 Remove pathname below localRoot IFF handler downloads files to the local filesystem. More...
 
void setDeltafile (const Pathname &filename=Pathname()) const
 
Pathname deltafile () const
 
void dirInfo (std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
 Return content of directory on media via retlist. More...
 
void dirInfo (filesystem::DirContent &retlist, const Pathname &dirname, bool dots=true) const
 Basically the same as dirInfo above. More...
 
bool doesFileExist (const Pathname &filename) const
 check if a file exists More...
 
virtual bool hasMoreDevices ()
 Check if the media has one more device available for attach(true). More...
 
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. More...
 

Static Public Member Functions

static void setCookieFile (const Pathname &)
 
- 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)
 

Protected Member Functions

Url clearQueryString (const Url &url) const
 
virtual void attachTo (bool next=false)
 Call concrete handler to attach the media. More...
 
virtual void releaseFrom (const std::string &ejectDev)
 Call concrete handler to release the media. More...
 
virtual void getFile (const Pathname &filename, const ByteCount &expectedFileSize_r) const override
 Call concrete handler to provide file below attach point. More...
 
virtual void getDir (const Pathname &dirname, bool recurse_r) const
 Call concrete handler to provide directory content (not recursive!) below attach point. More...
 
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. More...
 
virtual void getDirInfo (filesystem::DirContent &retlist, const Pathname &dirname, bool dots=true) const
 Basically the same as getDirInfo above. More...
 
virtual bool getDoesFileExist (const Pathname &filename) const
 Repeatedly calls doGetDoesFileExist() until it successfully returns, fails unexpectedly, or user cancels the operation. More...
 
virtual bool doGetDoesFileExist (const Pathname &filename) const
 
virtual void disconnectFrom ()
 
virtual void getFileCopy (const Pathname &srcFilename, const Pathname &targetFilename, const ByteCount &expectedFileSize_r) const override
 
virtual void doGetFileCopy (const Pathname &srcFilename, const Pathname &targetFilename, callback::SendReport< DownloadProgressReport > &_report, const ByteCount &expectedFileSize_r, 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. More...
 
void checkProtocol (const Url &url) const
 check the url is supported by the curl library More...
 
virtual void setupEasy ()
 initializes the curl easy handle with the data from the url More...
 
Url getFileUrl (const Pathname &filename) const
 concatenate the attach url and the filename to a complete download url More...
 
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. More...
 
void doGetFileCopyFile (const Pathname &srcFilename, const Pathname &dest, FILE *file, callback::SendReport< DownloadProgressReport > &_report, const ByteCount &expectedFileSize_r, RequestOptions options=OPTION_NONE) const
 
- Protected 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. More...
 
bool dependsOnParent ()
 
void resetParentId ()
 Called in case, where the media manager takes over the destruction of the parent id (e.g. More...
 
Pathname attachPoint () const
 Return the currently used attach point. More...
 
void setAttachPoint (const Pathname &path, bool temp)
 Set a new attach point. More...
 
void setAttachPoint (const AttachPointRef &ref)
 Set a (shared) attach point. More...
 
AttachPoint attachPointHint () const
 Get the actual attach point hint. More...
 
void attachPointHint (const Pathname &path, bool temp)
 Set the attach point hint as specified by the user. More...
 
Pathname createAttachPoint () const
 Try to create a default / temporary attach point. More...
 
Pathname createAttachPoint (const Pathname &attach_root) const
 Try to create a temporary attach point in specified root. More...
 
void removeAttachPoint ()
 Remove unused attach point. More...
 
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. More...
 
std::string mediaSourceName () const
 Get the media source name or an empty string. More...
 
void setMediaSource (const MediaSourceRef &ref)
 Set new media source reference. More...
 
AttachedMedia findAttachedMedia (const MediaSourceRef &media) const
 Ask the media manager if specified media source is already attached. More...
 
AttachedMedia attachedMedia () const
 Returns the attached media. More...
 
bool isSharedMedia () const
 Returns a hint if the media is shared or not. More...
 
bool checkAttached (bool matchMountFs) const
 Check actual mediaSource attachment against the current mount table of the system. More...
 
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. More...
 
void forceRelaseAllMedia (const MediaSourceRef &ref, bool matchMountFs)
 
virtual void forceEject (const std::string &device)
 Call concrete handler to physically eject the media (i.e. More...
 
void getDirectoryYast (std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
 Retrieve and if available scan dirname/directory.yast. More...
 
void getDirectoryYast (filesystem::DirContent &retlist, const Pathname &dirname, bool dots=true) const
 Retrieve and if available scan dirname/directory.yast. More...
 

Static Protected Member Functions

static int aliveCallback (void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
 Callback sending just an alive trigger to the UI, without stats (e.g. More...
 
static int progressCallback (void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
 Callback reporting download progress. More...
 
static CURL * progressCallback_getcurl (void *clientp)
 
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. More...
 
- Static Protected Member Functions inherited from zypp::media::MediaHandler
static bool checkAttachPoint (const Pathname &apoint, bool empty_dir, bool writeable)
 Verify if the specified directory as attach point (root) using requested checks. More...
 

Protected Attributes

CURL * _curl
 
char _curlError [CURL_ERROR_SIZE]
 
curl_slist * _customHeaders
 
TransferSettings _settings
 
- Protected Attributes inherited from zypp::media::MediaHandler
const Url _url
 Url to handle. More...
 
MediaAccessId _parentId
 Access Id of media handler we depend on. More...
 

Private Member Functions

std::string getAuthHint () const
 Return a comma separated list of available authentication methods supported by server. More...
 
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

◆ RequestOption

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

◆ MediaCurl()

zypp::media::MediaCurl::MediaCurl ( const Url url_r,
const Pathname attach_point_hint_r 
)

Definition at line 557 of file MediaCurl.cc.

◆ ~MediaCurl()

virtual zypp::media::MediaCurl::~MediaCurl ( )
inlinevirtual

Definition at line 102 of file MediaCurl.h.

Member Function Documentation

◆ ZYPP_DECLARE_FLAGS()

zypp::media::MediaCurl::ZYPP_DECLARE_FLAGS ( RequestOptions  ,
RequestOption   
)

◆ clearQueryString()

Url zypp::media::MediaCurl::clearQueryString ( const Url url) const
protected

Definition at line 593 of file MediaCurl.cc.

◆ attachTo()

void zypp::media::MediaCurl::attachTo ( bool  next = false)
protectedvirtual

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.

Definition at line 898 of file MediaCurl.cc.

◆ releaseFrom()

void zypp::media::MediaCurl::releaseFrom ( const std::string &  ejectDev)
protectedvirtual

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.

Definition at line 957 of file MediaCurl.cc.

◆ getFile()

void zypp::media::MediaCurl::getFile ( const Pathname filename,
const ByteCount expectedFileSize_r 
) const
overrideprotectedvirtual

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

Reimplemented from zypp::media::MediaHandler.

Definition at line 978 of file MediaCurl.cc.

◆ getDir()

void zypp::media::MediaCurl::getDir ( const Pathname dirname,
bool  recurse_r 
) const
protectedvirtual

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.

Definition at line 1605 of file MediaCurl.cc.

◆ getDirInfo() [1/2]

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

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.

Definition at line 1638 of file MediaCurl.cc.

◆ getDirInfo() [2/2]

void zypp::media::MediaCurl::getDirInfo ( filesystem::DirContent retlist,
const Pathname dirname,
bool  dots = true 
) const
protectedvirtual

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.

Definition at line 1646 of file MediaCurl.cc.

◆ getDoesFileExist()

bool zypp::media::MediaCurl::getDoesFileExist ( const Pathname filename) const
protectedvirtual

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 1033 of file MediaCurl.cc.

◆ doGetDoesFileExist()

bool zypp::media::MediaCurl::doGetDoesFileExist ( const Pathname filename) const
protectedvirtual
See also
MediaHandler::getDoesFileExist

Definition at line 1195 of file MediaCurl.cc.

◆ disconnectFrom()

void zypp::media::MediaCurl::disconnectFrom ( )
protectedvirtual
Exceptions
MediaException

Reimplemented from zypp::media::MediaHandler.

Definition at line 940 of file MediaCurl.cc.

◆ getFileCopy()

void zypp::media::MediaCurl::getFileCopy ( const Pathname srcFilename,
const Pathname targetFilename,
const ByteCount expectedFileSize_r 
) const
overrideprotectedvirtual
Exceptions
MediaException

Reimplemented from zypp::media::MediaHandler.

Definition at line 987 of file MediaCurl.cc.

◆ doGetFileCopy()

void zypp::media::MediaCurl::doGetFileCopy ( const Pathname srcFilename,
const Pathname targetFilename,
callback::SendReport< DownloadProgressReport > &  _report,
const ByteCount expectedFileSize_r,
RequestOptions  options = OPTION_NONE 
) const
protectedvirtual
Exceptions
MediaException

Reimplemented in zypp::media::MediaMultiCurl.

Definition at line 1385 of file MediaCurl.cc.

◆ checkAttachPoint()

bool zypp::media::MediaCurl::checkAttachPoint ( const Pathname apoint) const
protectedvirtual

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.

Definition at line 933 of file MediaCurl.cc.

◆ settings()

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

Definition at line 618 of file MediaCurl.cc.

◆ setCookieFile()

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

Definition at line 624 of file MediaCurl.cc.

◆ aliveCallback()

int zypp::media::MediaCurl::aliveCallback ( void *  clientp,
double  dltotal,
double  dlnow,
double  ultotal,
double  ulnow 
)
staticprotected

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

during metalink download).

Definition at line 1654 of file MediaCurl.cc.

◆ progressCallback()

int zypp::media::MediaCurl::progressCallback ( void *  clientp,
double  dltotal,
double  dlnow,
double  ultotal,
double  ulnow 
)
staticprotected

Callback reporting download progress.

Definition at line 1668 of file MediaCurl.cc.

◆ progressCallback_getcurl()

CURL * zypp::media::MediaCurl::progressCallback_getcurl ( void *  clientp)
staticprotected

Definition at line 1684 of file MediaCurl.cc.

◆ checkProtocol()

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 631 of file MediaCurl.cc.

◆ setupEasy()

void zypp::media::MediaCurl::setupEasy ( )
protectedvirtual

initializes the curl easy handle with the data from the url

Exceptions
MediaCurlSetOptExceptionif there is a problem

Force IPv4/v6

Connect timeout

Speed limits

Reimplemented in zypp::media::MediaMultiCurl.

Definition at line 656 of file MediaCurl.cc.

◆ getFileUrl()

Url zypp::media::MediaCurl::getFileUrl ( const Pathname filename) const
protected

concatenate the attach url and the filename to a complete download url

Definition at line 962 of file MediaCurl.cc.

◆ evaluateCurlCode()

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 1064 of file MediaCurl.cc.

◆ doGetFileCopyFile()

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

Definition at line 1499 of file MediaCurl.cc.

◆ resetExpectedFileSize()

void zypp::media::MediaCurl::resetExpectedFileSize ( void *  clientp,
const ByteCount expectedFileSize 
)
staticprotected

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

Definition at line 1711 of file MediaCurl.cc.

◆ getAuthHint()

string zypp::media::MediaCurl::getAuthHint ( ) const
private

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

Definition at line 1692 of file MediaCurl.cc.

◆ authenticate()

bool zypp::media::MediaCurl::authenticate ( const std::string &  availAuthTypes,
bool  firstTry 
) const
private
Todo:
need a way to pass different CredManagerOptions here
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)

Definition at line 1721 of file MediaCurl.cc.

◆ detectDirIndex()

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

Member Data Documentation

◆ _curlDebug

long zypp::media::MediaCurl::_curlDebug
private

Definition at line 168 of file MediaCurl.h.

◆ _currentCookieFile

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

Definition at line 170 of file MediaCurl.h.

◆ _cookieFile

Pathname zypp::media::MediaCurl::_cookieFile = "/var/lib/YaST2/cookies"
staticprivate

Definition at line 171 of file MediaCurl.h.

◆ _curl

CURL* zypp::media::MediaCurl::_curl
protected

Definition at line 174 of file MediaCurl.h.

◆ _curlError

char zypp::media::MediaCurl::_curlError[CURL_ERROR_SIZE]
protected

Definition at line 175 of file MediaCurl.h.

◆ _customHeaders

curl_slist* zypp::media::MediaCurl::_customHeaders
protected

Definition at line 176 of file MediaCurl.h.

◆ _settings

TransferSettings zypp::media::MediaCurl::_settings
protected

Definition at line 177 of file MediaCurl.h.


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