libzypp  17.32.5
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 #ifndef ZYPP_MEDIA_PRIVATE_PROVIDE_MESSAGE_P_H_INCLUDED
14 #define ZYPP_MEDIA_PRIVATE_PROVIDE_MESSAGE_P_H_INCLUDED
15 
297 #include <zypp-core/base/PtrTypes.h>
298 #include <zypp-core/zyppng/pipelines/Expected>
299 #include <zypp-core/zyppng/rpc/MessageStream>
300 #include <zypp-media/ng/ProvideSpec> // for FieldType
301 #include <zypp-media/ng/HeaderValueMap>
302 
303 #include <boost/iterator/iterator_adaptor.hpp>
304 
305 #include <functional>
306 
307 namespace zypp::proto {
308  class Envelope;
309  class Configuration;
310  class Capabilities;
311  class ProvideMessage;
312 }
313 
314 namespace zyppng {
315 
316  enum MessageCodes : uint32_t {
317  NoCode = 0,
321 
325  AuthInfo = 202,
329 
331  Redirect = 300,
332  Metalink = 301,
334 
336  BadRequest = 400,
338  Forbidden = 402,
340  NotFound = 404,
343  Timeout = 407,
344  Cancelled = 408,
346  MountFailed = 410,
347  Jammed = 411,
350  NoAuthData = 414,
351  NotAFile = 415,
354 
359 
361  Prov = 600,
362  Cancel = 601,
363  Attach = 602,
364  Detach = 603,
366 
371  };
372 
373  class ProviderConfiguration : public std::map<std::string, std::string>, public RpcBaseType
374  {
376  public:
377 
378  using map::map;
379  };
380 
381  class WorkerCaps : public RpcBaseType
382  {
384  public:
386  enum WorkerType {
387  Invalid = 0,
391  CPUBound = 4,
392  };
393 
394  enum Flags {
395  None = 0, // Just for completeness
396  SingleInstance = 1, // If this flag is set a worker can only be started once, this is implicit in some worker types.
397  Pipeline = 2, // The worker can handle multiple requests at the same time
398  ZyppLogFormat = 4, // The worker writes messages to stderr in zypp log format
399  FileArtifacts = 8, // The results of this worker are artifacts, which means they need to be cleaned up. This is implicit for all downloading workers. For all mounting workers this is ignored.
400  // CPU bound workers can use it to signal they leave artifact files behind that need to be cleaned up
401  };
402 
403  explicit WorkerCaps();
404  ~WorkerCaps();
405 
406  WorkerCaps(const WorkerCaps &) = default;
407  WorkerCaps(WorkerCaps &&) = default;
408  WorkerCaps &operator=(const WorkerCaps &) = default;
409  WorkerCaps &operator=(WorkerCaps &&) = default;
410 
411  uint32_t protocol_version() const; // The workers should set this field to the protocol version they implement.
412  WorkerType worker_type() const;
413  Flags cfg_flags() const;
414  const std::string &worker_name() const;
415 
416  void set_protocol_version( uint32_t v );
417  void set_worker_type( WorkerType t );
418  void set_cfg_flags( Flags f );
419  void set_worker_name( std::string name );
420 
421  private:
423  };
424 
425  namespace ProvideStartedMsgFields
426  {
427  constexpr std::string_view Url ("url");
428  constexpr std::string_view LocalFilename ("local_filename");
429  constexpr std::string_view StagingFilename ("staging_filename");
430  }
431 
432  namespace ProvideFinishedMsgFields
433  {
434  constexpr std::string_view LocalFilename ("local_filename");
435  constexpr std::string_view CacheHit ("cacheHit");
436  }
437 
438  namespace AuthInfoMsgFields
439  {
440  constexpr std::string_view Username ("username");
441  constexpr std::string_view Password ("password");
442  constexpr std::string_view AuthTimestamp ("auth_timestamp");
443  constexpr std::string_view AuthType ("authType");
444  }
445 
446  namespace RedirectMsgFields
447  {
448  constexpr std::string_view NewUrl ("new_url");
449  }
450 
451  namespace MetalinkRedirectMsgFields
452  {
453  constexpr std::string_view NewUrl ("new_url");
454  }
455 
456  namespace ErrMsgFields
457  {
458  constexpr std::string_view Reason ("reason");
459  constexpr std::string_view Transient ("transient");
460  constexpr std::string_view History ("history");
461  }
462 
463  namespace ProvideMsgFields
464  {
465  constexpr std::string_view Url ("url");
466  constexpr std::string_view Filename ("filename");
467  constexpr std::string_view DeltaFile ("delta_file");
468  constexpr std::string_view ExpectedFilesize ("expected_filesize");
469  constexpr std::string_view CheckExistOnly ("check_existance_only");
470  constexpr std::string_view MetalinkEnabled ("metalink_enabled");
471  }
472 
473  namespace AttachMsgFields
474  {
475  constexpr std::string_view Url ("url");
476  constexpr std::string_view AttachId ("attach_id");
477  constexpr std::string_view VerifyType ("verify_type");
478  constexpr std::string_view VerifyData ("verify_data");
479  constexpr std::string_view MediaNr ("media_nr");
480  constexpr std::string_view Device ("device");
481  constexpr std::string_view Label ("label");
482  }
483 
484  namespace AttachFinishedMsgFields
485  {
486  constexpr std::string_view LocalMountPoint ("local_mountpoint");
487  }
488 
489  namespace DetachMsgFields
490  {
491  constexpr std::string_view Url ("url");
492  }
493 
494  namespace AuthDataRequestMsgFields
495  {
496  constexpr std::string_view EffectiveUrl ("effective_url");
497  constexpr std::string_view LastAuthTimestamp ("last_auth_timestamp");
498  constexpr std::string_view LastUser ("username");
499  constexpr std::string_view AuthHint ("authHint");
500  }
501 
502  namespace MediaChangeRequestMsgFields
503  {
504  constexpr std::string_view Label ("label");
505  constexpr std::string_view MediaNr ("media_nr");
506  constexpr std::string_view Device ("device");
507  constexpr std::string_view Desc ("desc");
508  }
509 
510  namespace EjectMsgFields
511  {
512  constexpr std::string_view device ("device");
513  }
514 
516  {
518  public:
520 
521  ProvideMessage(const ProvideMessage &) = default;
522  ProvideMessage(ProvideMessage &&) = default;
523  ProvideMessage &operator=(const ProvideMessage &) = default;
524  ProvideMessage &operator=(ProvideMessage &&) = default;
526 
527  static expected<ProvideMessage> create ( const zyppng::RpcMessage &message );
528  static expected<ProvideMessage> create ( const zypp::proto::ProvideMessage &message );
529  static ProvideMessage createProvideStarted ( const uint32_t reqId, const zypp::Url &url , const std::optional<std::string> &localFilename = {}, const std::optional<std::string> &stagingFilename = {} );
530  static ProvideMessage createProvideFinished ( const uint32_t reqId, const std::string &localFilename , bool cacheHit );
531  static ProvideMessage createAttachFinished ( const uint32_t reqId, const std::optional<std::string> &localMountPoint = {} );
532  static ProvideMessage createDetachFinished ( const uint32_t reqId );
533  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 = {} );
534  static ProvideMessage createMediaChanged ( const uint32_t reqId );
535  static ProvideMessage createRedirect ( const uint32_t reqId, const zypp::Url &newUrl );
536  static ProvideMessage createMetalinkRedir ( const uint32_t reqId, const std::vector<zypp::Url> &newUrls );
537  static ProvideMessage createErrorResponse ( const uint32_t reqId, const uint code, const std::string &reason, bool transient = false );
538 
539  static ProvideMessage createProvide ( const uint32_t reqId
540  , const zypp::Url &url
541  , const std::optional<std::string> &filename = {}
542  , const std::optional<std::string> &deltaFile = {}
543  , const std::optional<int64_t> &expFilesize = {}
544  , bool checkExistOnly = false );
545 
546  static ProvideMessage createCancel ( const uint32_t reqId );
547 
548  static ProvideMessage createAttach( const uint32_t reqId
549  , const zypp::Url &url
550  , const std::string attachId
551  , const std::string &label
552  , const std::optional<std::string> &verifyType = {}
553  , const std::optional<std::string> &verifyData = {}
554  , const std::optional<int32_t> &mediaNr = {} );
555 
556  static ProvideMessage createDetach ( const uint32_t reqId, const zypp::Url &attachUrl );
557  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 = {} );
558  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 );
559 
560  uint requestId () const;
561  void setRequestId ( const uint id );
562 
563  uint32_t code() const;
564  void setCode ( const uint32_t newCode );
565 
566  std::vector<FieldVal> values ( const std::string_view &str ) const;
567  std::vector<FieldVal> values ( const std::string &str ) const;
568  HeaderValueMap headers() const;
573  FieldVal value ( const std::string_view &str, const FieldVal &defaultVal = FieldVal() ) const;
574  FieldVal value ( const std::string &str, const FieldVal &defaultVal = FieldVal() ) const;
575  void setValue ( const std::string &name, const FieldVal &value );
576  void setValue ( const std::string_view &name, const FieldVal &value );
577  void addValue ( const std::string &name, const FieldVal &value );
578  void addValue ( const std::string_view &name, const FieldVal &value );
579  void forEachVal( const std::function<bool( const std::string &name, const FieldVal &val)> &cb ) const;
580 
581  private:
582  ProvideMessage();
584  };
585 }
586 
587 namespace zypp {
588  template<> zypp::proto::Configuration* rwcowClone<zypp::proto::Configuration>( const zypp::proto::Configuration * rhs );
589  template<> zypp::proto::Capabilities* rwcowClone<zypp::proto::Capabilities>( const zypp::proto::Capabilities * rhs );
590  template<> zypp::proto::ProvideMessage* rwcowClone<zypp::proto::ProvideMessage>( const zypp::proto::ProvideMessage * rhs );
591 }
592 
593 
594 
595 #endif
#define ZYPP_RPCBASE
static ProvideMessage createErrorResponse(const uint32_t reqId, const uint code, const std::string &reason, bool transient=false)
WorkerCaps & operator=(const WorkerCaps &)=default
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::Capabilities > _data
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
void set_cfg_flags(Flags f)
void set_protocol_version(uint32_t v)
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 expected< ProvideMessage > create(const zyppng::RpcMessage &message)
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")
void set_worker_type(WorkerType t)
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
void setCode(const uint32_t newCode)
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")
uint32_t code() const
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={})
void set_worker_name(std::string name)
static ProvideMessage createDetach(const uint32_t reqId, const zypp::Url &attachUrl)
WorkerType worker_type() const
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")
uint32_t protocol_version() const
void setValue(const std::string &name, const FieldVal &value)
constexpr std::string_view DeltaFile("delta_file")
constexpr std::string_view EffectiveUrl("effective_url")
const std::string & worker_name() const
constexpr std::string_view Transient("transient")
constexpr std::string_view AuthTimestamp("auth_timestamp")
void setRequestId(const uint id)
static ProvideMessage createCancel(const uint32_t reqId)
constexpr std::string_view Url("url")
constexpr std::string_view LocalMountPoint("local_mountpoint")
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")
zyppng::ProviderConfiguration Configuration
Definition: provideworker.h:32
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")
ProvideMessage & operator=(const ProvideMessage &)=default
Flags cfg_flags() const
constexpr std::string_view Url("url")
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
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)
static ProvideMessage createAttachFinished(const uint32_t reqId, const std::optional< std::string > &localMountPoint={})
constexpr std::string_view ExpectedFilesize("expected_filesize")