libzypp  17.37.5
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 
15 #include <zypp-curl/TransferSettings>
16 
18 namespace zypp
19 {
21  namespace media
22  {
23 
24  class CredentialManager;
25 
31  // to avoid duplicated code.
34  {
35  public:
36  MediaNetworkCommonHandler( const MediaUrl &url_r,
37  const std::vector<MediaUrl> &mirrors_r,
38  const Pathname & attach_point_r,
39  const Pathname & urlpath_below_attachpoint_r,
40  const bool does_download_r );
41 
42  public:
47  static zypp::Url findGeoIPRedirect ( const zypp::Url &url );
48 
49  void getFile( const OnMediaLocation & file ) const override;
50  void getDir( const Pathname & dirname, bool recurse_r ) const override;
51  void getDirInfo( std::list<std::string> & retlist,
52  const Pathname & dirname, bool dots = true ) const override;
53  void getDirInfo( filesystem::DirContent & retlist,
54  const Pathname & dirname, bool dots = true ) const override;
55 
56  protected:
57 
58  void attachTo (bool next) override;
59 
60  bool checkAttachPoint(const Pathname &apoint) const override;
61 
62  Url clearQueryString(const Url &url) const;
63 
64 
69  Url getFileUrl( int mirrorIdx, const Pathname & filename) const;
70 
71 
76  void setupTransferSettings();
77 
78  bool authenticate( const Url &url, TransferSettings &settings, const std::string & availAuthTypes, bool firstTry );
79 
84  virtual void checkProtocol(const Url &url) const = 0;
85 
86  public:
87 
88  // standard auth procedure, shared with CommitPackagePreloader
89  static bool authenticate( const Url &url, CredentialManager &cm, TransferSettings &settings, const std::string & availAuthTypes, bool firstTry);
90 
91  static const char *anonymousIdHeader();
92 
93  static const char *distributionFlavorHeader();
94 
95  static const char *agentString();
96 
97  template <typename Excpt>
98  static bool canTryNextMirror( const Excpt &excpt_r ) {
99  // check if we can retry on the next mirror
100  bool fatal = (
101  typeid(excpt_r) == typeid( MediaRequestCancelledException ) ||
102  typeid(excpt_r) == typeid( MediaWriteException ) ||
103  typeid(excpt_r) == typeid( MediaSystemException ) ||
104  typeid(excpt_r) == typeid( MediaCurlInitException ) ||
105  typeid(excpt_r) == typeid( MediaUnauthorizedException )
106  );
107  return !fatal;
108  }
109 
110  protected:
111  std::vector<Url> _redirTargets;
112  std::vector<TransferSettings> _mirrorSettings;
113  };
114 
115  } // namespace media
117 } // namespace zypp
119 #endif // ZYPP_MEDIA_MEDIANETWORKCOMMONHANDLER_H
Describes a resource file located on a medium.
Holds transfer setting.
static bool canTryNextMirror(const Excpt &excpt_r)
std::vector< TransferSettings > _mirrorSettings
bool authenticate(const Url &url, TransferSettings &settings, const std::string &availAuthTypes, bool firstTry)
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:526
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 ...
Abstract base class for &#39;physical&#39; MediaHandler like MediaCD, etc.
Definition: MediaHandler.h:51
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.
MediaNetworkCommonHandler(const MediaUrl &url_r, const std::vector< MediaUrl > &mirrors_r, const Pathname &attach_point_r, const Pathname &urlpath_below_attachpoint_r, const bool does_download_r)
Url url() const
Primary Url used.
Definition: MediaHandler.h:509
Url getFileUrl(int mirrorIdx, const Pathname &filename) const
concatenate the attach url and the filename to a complete download url
virtual void checkProtocol(const Url &url) const =0
check the url is supported by the curl library
void setupTransferSettings()
initializes the curl easy handle with the data from the url
void getDir(const Pathname &dirname, bool recurse_r) const override
Call concrete handler to provide directory content (not recursive!) below attach point.
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...
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
void getFile(const OnMediaLocation &file) const override
Call concrete handler to provide file below attach point.
Url manipulation class.
Definition: Url.h:92