libzypp: zypp/media/MediaNetworkCommonHandler.h Source File

libzypp 17.38.11

MediaNetworkCommonHandler.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
11#ifndef ZYPP_MEDIA_MEDIANETWORKCOMMONHANDLER_H
12#define ZYPP_MEDIA_MEDIANETWORKCOMMONHANDLER_H
13
14#include <zypp/media/MediaHandler.h>
15#include <zypp-curl/TransferSettings>
16
18namespace zypp
19{
21 namespace media
22 {
23
24 class CredentialManager;
25
31 // to avoid duplicated code.
33 class MediaNetworkCommonHandler : public MediaHandler
34 {
35 public:
36
37 static constexpr std::string_view MIRR_SETTINGS_KEY = "_zypp_transfersettings";
38
39 MediaNetworkCommonHandler( const MirroredOrigin &origin_r,
40 const Pathname & attach_point_r,
41 const Pathname & urlpath_below_attachpoint_r,
42 const bool does_download_r );
43
44 public:
49 static zypp::Url findGeoIPRedirect ( const zypp::Url &url );
50
51 void getFile( const OnMediaLocation & file ) const override;
52 void getDir( const Pathname & dirname, bool recurse_r ) const override;
53 void getDirInfo( std::list<std::string> & retlist,
54 const Pathname & dirname, bool dots = true ) const override;
55 void getDirInfo( filesystem::DirContent & retlist,
56 const Pathname & dirname, bool dots = true ) const override;
57
58 protected:
59
60 void attachTo (bool next) override;
61
62 bool checkAttachPoint(const Pathname &apoint) const override;
63
64 Url clearQueryString(const Url &url) const;
65
66
71 Url getFileUrl( int mirrorIdx, const Pathname & filename) const;
72
73
78 void setupTransferSettings();
79 void clearTransferSettings();
80
81 bool authenticate( const Url &url, TransferSettings &settings, const std::string & availAuthTypes, bool firstTry );
82
87 virtual void checkProtocol(const Url &url) const = 0;
88
89 std::vector<unsigned> mirrorOrder( const OnMediaLocation &loc ) const;
90
94 void deprioritizeMirror( unsigned mirr ) const;
95
96 public:
97
98 // standard auth procedure, shared with CommitPackagePreloader
99 static bool authenticate( const Url &url, CredentialManager &cm, TransferSettings &settings, const std::string & availAuthTypes, bool firstTry);
100
101 static const char *anonymousIdHeader();
102
103 static const char *distributionFlavorHeader();
104
105 static const char *agentString();
106
107 template <typename Excpt>
108 static bool canTryNextMirror( const Excpt &excpt_r ) {
109 // check if we can retry on the next mirror
110 bool fatal = (
111 typeid(excpt_r) == typeid( MediaRequestCancelledException ) ||
112 typeid(excpt_r) == typeid( MediaWriteException ) ||
113 typeid(excpt_r) == typeid( MediaSystemException ) ||
114 typeid(excpt_r) == typeid( MediaCurlInitException ) ||
115 typeid(excpt_r) == typeid( MediaUnauthorizedException )
116 );
117 return !fatal;
118 }
119
120 protected:
121 std::vector<Url> _redirTargets;
122 mutable std::vector<unsigned> _mirrOrder;
123 };
124
125 } // namespace media
127} // namespace zypp
129#endif // ZYPP_MEDIA_MEDIANETWORKCOMMONHANDLER_H
MediaHandler.h
zypp::MirroredOrigin
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
Definition MirroredOrigin.h:170
zypp::OnMediaLocation
Describes a resource file located on a medium.
Definition onmedialocation.h:37
zypp::Url
Url manipulation class.
Definition Url.h:93
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
zypp::media::CredentialManager
Definition credentialmanager.h:64
zypp::media::MediaCurlInitException
Definition mediaexception.h:227
zypp::media::MediaHandler::MediaHandler
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.
Definition MediaHandler.cc:55
zypp::media::MediaHandler::url
Url url() const
Primary Url used.
Definition MediaHandler.h:507
zypp::media::MediaNetworkCommonHandler::_redirTargets
std::vector< Url > _redirTargets
Definition MediaNetworkCommonHandler.h:121
zypp::media::MediaNetworkCommonHandler::clearTransferSettings
void clearTransferSettings()
Definition MediaNetworkCommonHandler.cc:314
zypp::media::MediaNetworkCommonHandler::authenticate
bool authenticate(const Url &url, TransferSettings &settings, const std::string &availAuthTypes, bool firstTry)
Definition MediaNetworkCommonHandler.cc:322
zypp::media::MediaNetworkCommonHandler::canTryNextMirror
static bool canTryNextMirror(const Excpt &excpt_r)
Definition MediaNetworkCommonHandler.h:108
zypp::media::MediaNetworkCommonHandler::getDir
void getDir(const Pathname &dirname, bool recurse_r) const override
Call concrete handler to provide directory content (not recursive!) below attach point.
Definition MediaNetworkCommonHandler.cc:138
zypp::media::MediaNetworkCommonHandler::checkAttachPoint
bool checkAttachPoint(const Pathname &apoint) const override
Verify if the specified directory as attach point (root) as requires by the particular media handler ...
Definition MediaNetworkCommonHandler.cc:68
zypp::media::MediaNetworkCommonHandler::_mirrOrder
std::vector< unsigned > _mirrOrder
Definition MediaNetworkCommonHandler.h:122
zypp::media::MediaNetworkCommonHandler::deprioritizeMirror
void deprioritizeMirror(unsigned mirr) const
Move mirror index mirr to the end of the attempt list.
Definition MediaNetworkCommonHandler.cc:348
zypp::media::MediaNetworkCommonHandler::mirrorOrder
std::vector< unsigned > mirrorOrder(const OnMediaLocation &loc) const
Definition MediaNetworkCommonHandler.cc:329
zypp::media::MediaNetworkCommonHandler::clearQueryString
Url clearQueryString(const Url &url) const
Definition MediaNetworkCommonHandler.cc:73
zypp::media::MediaNetworkCommonHandler::getFileUrl
Url getFileUrl(int mirrorIdx, const Pathname &filename) const
concatenate the attach url and the filename to a complete download url
Definition MediaNetworkCommonHandler.cc:209
zypp::media::MediaNetworkCommonHandler::setupTransferSettings
void setupTransferSettings()
initializes the curl easy handle with the data from the url
Definition MediaNetworkCommonHandler.cc:241
zypp::media::MediaNetworkCommonHandler::MediaNetworkCommonHandler
MediaNetworkCommonHandler(const MirroredOrigin &origin_r, const Pathname &attach_point_r, const Pathname &urlpath_below_attachpoint_r, const bool does_download_r)
Definition MediaNetworkCommonHandler.cc:36
zypp::media::MediaNetworkCommonHandler::checkProtocol
virtual void checkProtocol(const Url &url) const =0
check the url is supported by the curl library
zypp::media::MediaNetworkCommonHandler::anonymousIdHeader
static const char * anonymousIdHeader()
Definition MediaNetworkCommonHandler.cc:181
zypp::media::MediaNetworkCommonHandler::attachTo
void attachTo(bool next) override
Call concrete handler to attach the media.
Definition MediaNetworkCommonHandler.cc:49
zypp::media::MediaNetworkCommonHandler::MIRR_SETTINGS_KEY
static constexpr std::string_view MIRR_SETTINGS_KEY
Definition MediaNetworkCommonHandler.h:37
zypp::media::MediaNetworkCommonHandler::getFile
void getFile(const OnMediaLocation &file) const override
Call concrete handler to provide file below attach point.
Definition MediaNetworkCommonHandler.cc:131
zypp::media::MediaNetworkCommonHandler::getDirInfo
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.
Definition MediaNetworkCommonHandler.cc:169
zypp::media::MediaNetworkCommonHandler::distributionFlavorHeader
static const char * distributionFlavorHeader()
Definition MediaNetworkCommonHandler.cc:195
zypp::media::MediaNetworkCommonHandler::findGeoIPRedirect
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 retu...
Definition MediaNetworkCommonHandler.cc:78
zypp::media::MediaNetworkCommonHandler::agentString
static const char * agentString()
Definition MediaNetworkCommonHandler.cc:228
zypp::media::MediaRequestCancelledException
Definition mediaexception.h:568
zypp::media::MediaSystemException
Definition mediaexception.h:241
zypp::media::MediaUnauthorizedException
Definition mediaexception.h:450
zypp::media::MediaWriteException
Definition mediaexception.h:185
zypp::media::TransferSettings
Holds transfer setting.
Definition transfersettings.h:34
zypp::filesystem::DirContent
std::list< DirEntry > DirContent
Returned by readdir.
Definition PathInfo.h:534
zypp::media
Definition MediaNetworkRequestExecutor.h:22
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2