libzypp  17.31.31
providemessage_p.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \----------------------------------------------------------------------/
9 *
10 * This file contains private API, this might break at any time between releases.
11 * You have been warned!
12 *
13 *
14 */
15 #ifndef ZYPP_MEDIA_PRIVATE_PROVIDE_MESSAGE_P_H_INCLUDED
16 #define ZYPP_MEDIA_PRIVATE_PROVIDE_MESSAGE_P_H_INCLUDED
17 
18 #include <zypp-core/base/PtrTypes.h>
19 #include <zypp-core/zyppng/pipelines/Expected>
20 #include <zypp-core/zyppng/rpc/MessageStream>
21 #include <zypp-media/ng/ProvideSpec> // for FieldType
22 #include <zypp-media/ng/HeaderValueMap>
23 #include <variant>
24 #include <functional>
25 #include <zypp-proto/media/provider.pb.h>
26 
27 namespace zypp::proto {
28  class ProvideMessage;
29  class Envelope;
30 }
31 
32 namespace zyppng {
33 
34  namespace ProvideStartedMsgFields
35  {
36  constexpr std::string_view Url ("url");
37  constexpr std::string_view LocalFilename ("local_filename");
38  constexpr std::string_view StagingFilename ("staging_filename");
39  }
40 
41  namespace ProvideFinishedMsgFields
42  {
43  constexpr std::string_view LocalFilename ("local_filename");
44  constexpr std::string_view CacheHit ("cacheHit");
45  }
46 
47  namespace AuthInfoMsgFields
48  {
49  constexpr std::string_view Username ("username");
50  constexpr std::string_view Password ("password");
51  constexpr std::string_view AuthTimestamp ("auth_timestamp");
52  constexpr std::string_view AuthType ("authType");
53  }
54 
55  namespace RedirectMsgFields
56  {
57  constexpr std::string_view NewUrl ("new_url");
58  }
59 
60  namespace MetalinkRedirectMsgFields
61  {
62  constexpr std::string_view NewUrl ("new_url");
63  }
64 
65  namespace ErrMsgFields
66  {
67  constexpr std::string_view Reason ("reason");
68  constexpr std::string_view Transient ("transient");
69  constexpr std::string_view History ("history");
70  }
71 
72  namespace ProvideMsgFields
73  {
74  constexpr std::string_view Url ("url");
75  constexpr std::string_view Filename ("filename");
76  constexpr std::string_view DeltaFile ("delta_file");
77  constexpr std::string_view ExpectedFilesize ("expected_filesize");
78  constexpr std::string_view CheckExistOnly ("check_existance_only");
79  constexpr std::string_view MetalinkEnabled ("metalink_enabled");
80  }
81 
82  namespace AttachMsgFields
83  {
84  constexpr std::string_view Url ("url");
85  constexpr std::string_view AttachId ("attach_id");
86  constexpr std::string_view VerifyType ("verify_type");
87  constexpr std::string_view VerifyData ("verify_data");
88  constexpr std::string_view MediaNr ("media_nr");
89  constexpr std::string_view Device ("device");
90  constexpr std::string_view Label ("label");
91  }
92 
93  namespace DetachMsgFields
94  {
95  constexpr std::string_view Url ("url");
96  }
97 
98  namespace AuthDataRequestMsgFields
99  {
100  constexpr std::string_view EffectiveUrl ("effective_url");
101  constexpr std::string_view LastAuthTimestamp ("last_auth_timestamp");
102  constexpr std::string_view LastUser ("username");
103  constexpr std::string_view AuthHint ("authHint");
104  }
105 
106  namespace MediaChangeRequestMsgFields
107  {
108  constexpr std::string_view Label ("label");
109  constexpr std::string_view MediaNr ("media_nr");
110  constexpr std::string_view Device ("device");
111  constexpr std::string_view Desc ("desc");
112  }
113 
114  namespace EjectMsgFields
115  {
116  constexpr std::string_view device ("device");
117  }
118 
120  {
121  public:
122  using Code = zypp::proto::MessageCodes;
124 
125  static expected<ProvideMessage> create ( const zyppng::RpcMessage &message );
126  static expected<ProvideMessage> create ( const zypp::proto::ProvideMessage &message );
127  static ProvideMessage createProvideStarted ( const uint32_t reqId, const zypp::Url &url , const std::optional<std::string> &localFilename = {}, const std::optional<std::string> &stagingFilename = {} );
128  static ProvideMessage createProvideFinished ( const uint32_t reqId, const std::string &localFilename , bool cacheHit );
129  static ProvideMessage createAttachFinished ( const uint32_t reqId );
130  static ProvideMessage createDetachFinished ( const uint32_t reqId );
131  static ProvideMessage createAuthInfo ( const uint32_t reqId, const std::string &user, const std::string &pw, int64_t timestamp, const std::map<std::string, std::string> &extraValues = {} );
132  static ProvideMessage createMediaChanged ( const uint32_t reqId );
133  static ProvideMessage createRedirect ( const uint32_t reqId, const zypp::Url &newUrl );
134  static ProvideMessage createMetalinkRedir ( const uint32_t reqId, const std::vector<zypp::Url> &newUrls );
135  static ProvideMessage createErrorResponse ( const uint32_t reqId, const uint code, const std::string &reason, bool transient = false );
136 
137  static ProvideMessage createProvide ( const uint32_t reqId
138  , const zypp::Url &url
139  , const std::optional<std::string> &filename = {}
140  , const std::optional<std::string> &deltaFile = {}
141  , const std::optional<int64_t> &expFilesize = {}
142  , bool checkExistOnly = false );
143 
144  static ProvideMessage createCancel ( const uint32_t reqId );
145 
146  static ProvideMessage createAttach( const uint32_t reqId
147  , const zypp::Url &url
148  , const std::string attachId
149  , const std::string &label
150  , const std::optional<std::string> &verifyType = {}
151  , const std::optional<std::string> &verifyData = {}
152  , const std::optional<int32_t> &mediaNr = {} );
153 
154  static ProvideMessage createDetach ( const uint32_t reqId, const zypp::Url &attachUrl );
155  static ProvideMessage createAuthDataRequest ( const uint32_t reqId, const zypp::Url &effectiveUrl, const std::string &lastTriedUser ="", const std::optional<int64_t> &lastAuthTimestamp = {}, const std::map<std::string, std::string> &extraValues = {} );
156  static ProvideMessage createMediaChangeRequest ( const uint32_t reqId, const std::string &label, int32_t mediaNr, const std::vector<std::string> &devices, const std::optional<std::string> &desc );
157 
158  uint requestId () const;
159  void setRequestId ( const uint id );
160 
161  uint code () const;
162  void setCode ( const uint newCode );
163 
164  std::vector<FieldVal> values ( const std::string_view &str ) const;
165  std::vector<FieldVal> values ( const std::string &str ) const;
166  HeaderValueMap headers() const;
171  FieldVal value ( const std::string_view &str, const FieldVal &defaultVal = FieldVal() ) const;
172  FieldVal value ( const std::string &str, const FieldVal &defaultVal = FieldVal() ) const;
173  void setValue ( const std::string &name, const FieldVal &value );
174  void setValue ( const std::string_view &name, const FieldVal &value );
175  void addValue ( const std::string &name, const FieldVal &value );
176  void addValue ( const std::string_view &name, const FieldVal &value );
177  void forEachVal( const std::function<bool( const std::string &name, const FieldVal &val)> &cb ) const;
178 
179  zypp::proto::ProvideMessage &impl();
180  const zypp::proto::ProvideMessage &impl() const;
181 
182  private:
183  ProvideMessage();
185  };
186 }
187 
188 namespace zypp {
189  template<>
190  inline zypp::proto::ProvideMessage* rwcowClone<zypp::proto::ProvideMessage>( const zypp::proto::ProvideMessage * rhs )
191  { return new zypp::proto::ProvideMessage(*rhs); }
192 }
193 
194 
195 
196 #endif
static ProvideMessage createErrorResponse(const uint32_t reqId, const uint code, const std::string &reason, bool transient=false)
constexpr std::string_view Url("url")
constexpr std::string_view LocalFilename("local_filename")
constexpr std::string_view AttachId("attach_id")
zypp::RWCOW_pointer< zypp::proto::ProvideMessage > _impl
void forEachVal(const std::function< bool(const std::string &name, const FieldVal &val)> &cb) const
constexpr std::string_view VerifyData("verify_data")
static ProvideMessage createMetalinkRedir(const uint32_t reqId, const std::vector< zypp::Url > &newUrls)
static ProvideMessage createProvide(const uint32_t reqId, const zypp::Url &url, const std::optional< std::string > &filename={}, const std::optional< std::string > &deltaFile={}, const std::optional< int64_t > &expFilesize={}, bool checkExistOnly=false)
constexpr std::string_view Filename("filename")
static ProvideMessage createAuthInfo(const uint32_t reqId, const std::string &user, const std::string &pw, int64_t timestamp, const std::map< std::string, std::string > &extraValues={})
HeaderValueMap headers() const
static ProvideMessage createAttach(const uint32_t reqId, const zypp::Url &url, const std::string attachId, const std::string &label, const std::optional< std::string > &verifyType={}, const std::optional< std::string > &verifyData={}, const std::optional< int32_t > &mediaNr={})
static ProvideMessage createMediaChanged(const uint32_t reqId)
String related utilities and Regular expression matching.
constexpr std::string_view MediaNr("media_nr")
static ProvideMessage createAttachFinished(const uint32_t reqId)
constexpr std::string_view VerifyType("verify_type")
void addValue(const std::string &name, const FieldVal &value)
constexpr std::string_view Label("label")
static ProvideMessage createProvideStarted(const uint32_t reqId, const zypp::Url &url, const std::optional< std::string > &localFilename={}, const std::optional< std::string > &stagingFilename={})
constexpr std::string_view Password("password")
constexpr std::string_view Username("username")
constexpr std::string_view Device("device")
constexpr std::string_view CheckExistOnly("check_existance_only")
constexpr std::string_view NewUrl("new_url")
constexpr std::string_view LocalFilename("local_filename")
FieldVal value(const std::string_view &str, const FieldVal &defaultVal=FieldVal()) const
constexpr std::string_view LastAuthTimestamp("last_auth_timestamp")
std::vector< FieldVal > values(const std::string_view &str) const
constexpr std::string_view Device("device")
constexpr std::string_view Label("label")
constexpr std::string_view MediaNr("media_nr")
static ProvideMessage createAuthDataRequest(const uint32_t reqId, const zypp::Url &effectiveUrl, const std::string &lastTriedUser="", const std::optional< int64_t > &lastAuthTimestamp={}, const std::map< std::string, std::string > &extraValues={})
static ProvideMessage createDetach(const uint32_t reqId, const zypp::Url &attachUrl)
constexpr std::string_view AuthHint("authHint")
constexpr std::string_view Reason("reason")
static ProvideMessage createRedirect(const uint32_t reqId, const zypp::Url &newUrl)
constexpr std::string_view NewUrl("new_url")
void setValue(const std::string &name, const FieldVal &value)
constexpr std::string_view DeltaFile("delta_file")
constexpr std::string_view EffectiveUrl("effective_url")
constexpr std::string_view Transient("transient")
constexpr std::string_view AuthTimestamp("auth_timestamp")
void setCode(const uint newCode)
void setRequestId(const uint id)
static ProvideMessage createCancel(const uint32_t reqId)
constexpr std::string_view Url("url")
constexpr std::string_view AuthType("authType")
static ProvideMessage createProvideFinished(const uint32_t reqId, const std::string &localFilename, bool cacheHit)
constexpr std::string_view Url("url")
constexpr std::string_view MetalinkEnabled("metalink_enabled")
constexpr std::string_view History("history")
constexpr std::string_view device("device")
constexpr std::string_view StagingFilename("staging_filename")
constexpr std::string_view Url("url")
zypp::proto::MessageCodes Code
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::proto::ProvideMessage & impl()
static expected< ProvideMessage > create(const zyppng::RpcMessage &message)
constexpr std::string_view Desc("desc")
static ProvideMessage createDetachFinished(const uint32_t reqId)
constexpr std::string_view CacheHit("cacheHit")
constexpr std::string_view LastUser("username")
Url manipulation class.
Definition: Url.h:91
static ProvideMessage createMediaChangeRequest(const uint32_t reqId, const std::string &label, int32_t mediaNr, const std::vector< std::string > &devices, const std::optional< std::string > &desc)
constexpr std::string_view ExpectedFilesize("expected_filesize")